Skip to content

fix(scripts): fall through to grep/sed when python3 is a broken stub in feature.json parser#3312

Open
Quratulain-bilal wants to merge 1 commit into
github:mainfrom
Quratulain-bilal:fix/json-parser-fallthrough-python3-stub
Open

fix(scripts): fall through to grep/sed when python3 is a broken stub in feature.json parser#3312
Quratulain-bilal wants to merge 1 commit into
github:mainfrom
Quratulain-bilal:fix/json-parser-fallthrough-python3-stub

Conversation

@Quratulain-bilal

@Quratulain-bilal Quratulain-bilal commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

fixes #3304

what

read_feature_json_feature_directory in scripts/bash/common.sh chose its JSON parser by availability:

if command -v jq ...; then ...
elif command -v python3 ...; then ...   # stub passes this
else grep/sed fallback fi               # unreachable once python3 exists

on windows python3 usually resolves to the microsoft store app execution alias stub. it satisfies command -v python3 but fails at runtime (exit 49, "Python was not found..."). the elif selected it, the failure was swallowed to _fd='', and the grep/sed last resort was never reached. so a valid .specify/feature.json read as empty, and every script that resolves a feature this way (setup-plan.sh, setup-tasks.sh, check-prerequisites.sh, ...) errored with Feature directory not found right after a successful specify init --script sh — as reported.

how

select by parse success, not availability: try jq, then python3 only if the result is still empty, then grep/sed only if still empty. a parser that exists but yields nothing now falls through instead of ending the chain.

the write path (_persist_feature_json) already uses jq-or-printf with no python3, so it wasn't affected; only the read path needed this.

verified

reproduced end-to-end with git-for-windows bash, a stub python3 (exit 49) first on PATH, and no jq:

  • before: bash setup-plan.sh --jsonERROR: Feature directory not found (exit 1)
  • after: same command → resolves the feature and writes plan.md (exit 0), emits the expected JSON paths

added test_setup_plan_survives_broken_python3_stub: writes a python3 stub that exits 49, prepends it to PATH, and asserts setup-plan.sh still succeeds via the grep/sed fallback. it uses the same @requires_bash harness as the existing tests in that file (skips where a suitable bash isn't present).

…in feature.json parser

read_feature_json_feature_directory picked its json parser by availability
(if jq / elif python3 / else grep-sed). on windows `python3` usually resolves
to the microsoft store app execution alias stub: it satisfies `command -v` but
fails at runtime (exit 49). the elif selected it, the runtime failure was
swallowed to _fd='', and the grep/sed last resort was never reached - so a
valid .specify/feature.json read as empty and every setup-plan / setup-tasks /
check-prerequisites call errored with "Feature directory not found" right after
a successful `specify init --script sh`.

change selection from availability to parse success: try jq, then python3 only
if still empty, then grep/sed only if still empty. a parser that exists but
produces nothing now falls through instead of terminating the chain.

the write path (_persist_feature_json) already uses jq-or-printf with no
python3, so it was unaffected; only the read path needed this.

add a regression test that puts a python3 stub (exit 49, like the store alias)
first on PATH and asserts setup-plan.sh still resolves the feature via the
grep/sed fallback.

fixes github#3304
@Quratulain-bilal Quratulain-bilal requested a review from mnriem as a code owner July 2, 2026 20:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Windows/Git Bash: python3 App Execution Alias stub defeats feature.json parser fallback in common.sh (sh variant)

1 participant