Repository navigation
fix(scripts): accept UTF-8 BOM in feature.json in Python readers - #5665
Open
grokbotmath wants to merge 3 commits into
Open
grokbotmath wants to merge 3 commits into
grokbotmath wants to merge 3 commits into
Conversation
The /speckit-specify command asks the agent to write .specify/feature.json itself. On Windows PowerShell 5.1, Set-Content -Encoding UTF8 (and Notepad) prefix a UTF-8 BOM. The bash (grep/sed fallback) and PowerShell (ReadAllText) readers accept such a file, but the Python readers decoded it with utf-8, json.loads rejected the leading U+FEFF, and check-prerequisites, setup-plan, setup-tasks and the github extension's resolve-tasks failed with "Feature directory not found". Decode with utf-8-sig in core common.py and the github extension's vendored copy of read_feature_json_feature_directory. Assisted-by: Grok Bot (model: unknown, autonomous)
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The review records no active issues, with BOM-compatibility updates and regression coverage across both shared and GitHub readers.
No open issues 🎉
What changed in this PR
Adds UTF-8 BOM support to Python readers for .specify/feature.json, preserving invalid-JSON behavior.
Changes:
- Uses
utf-8-sigin core and GitHub readers. - Adds BOM compatibility regression tests.
| File | Description |
|---|---|
| tests/test_check_prerequisites_python_parity.py | Tests core reader parity for BOM-prefixed and invalid feature metadata. |
| tests/extensions/github/test_github_extension.py | Tests BOM-prefixed feature resolution in the GitHub extension. |
| scripts/python/common.py | Updates the shared reader to decode UTF-8 BOM-prefixed feature files. |
| extensions/github/scripts/python/resolve_tasks.py | Updates the GitHub resolver's vendored reader to support UTF-8 BOMs. |
Review effort: Lite (adaptive)
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Missing extension version bumps prevent existing installations from receiving the fix and fail the version guard, while path comparisons make the regression test fail on Windows with Git Bash.
2 open issues
Review effort: Balanced
| return "" | ||
| try: | ||
| data = json.loads(feature_json.read_text(encoding="utf-8")) | ||
| data = json.loads(feature_json.read_text(encoding="utf-8-sig")) |
Collaborator
|
Please address Copilot feedback and fix CI/CD errors |
Assisted-by: Grok Bot (model: unknown, autonomous)
… parity test Bump the bundled GitHub extension to 1.0.8 in extension.yml and extensions/catalog.json so installed copies are offered the resolve_tasks.py BOM fix and the extension-version guard passes. Compare the BOM regression test's bash and Python payloads key by key, accepting Git Bash's MSYS path shape (/c/...) for Python's native Windows paths, and check FEATURE_DIR via Path instead of a forward-slash suffix. Assisted-by: Grok Bot (model: unknown, autonomous)
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Description
The Python script variants reject a
.specify/feature.jsonthat starts with a UTF-8 BOM, while the bash and PowerShell variants accept the same file./speckit-specify(templates/commands/specify.md) asks the agent to write.specify/feature.jsonitself. On Windows, PowerShell 5.1'sSet-Content -Encoding UTF8(and Notepad) write a BOM.read_feature_json_feature_directorydecoded the file asutf-8, sojson.loadsfailed on the leading U+FEFF, the reader returned"", and the Pythoncheck-prerequisites,setup-plan,setup-tasksand the github extension'sresolve-tasksstopped with:For the same file, bash resolves the directory through its grep/sed fallback, and PowerShell resolves it through
ReadAllTextwith UTF-8, which strips the BOM.Repro on
main(eab9f16), with feature.json =EF BB BF+{"feature_directory": "specs/001-my-feature"}:--json --paths-only--json--jsonspec.md not foundin repro)Feature directory not foundFix: decode with
utf-8-sigin corescripts/python/common.pyand in the github extension's vendored copy of the same function (extensions/github/scripts/python/resolve_tasks.py).utf-8-sigdecodes BOM-less UTF-8 the same wayutf-8does, so existing files behave as before. Invalid JSON and non-string values still fall back to"".Out of scope: the agent-context extension's
update_agent_contextalso ignores a BOM-prefixed feature.json. There the bash twin does too (both fall back to the mtime scan), so that isn't a Python-only parity gap. I've left it for a separate change.Testing
New
tests/test_check_prerequisites_python_parity.py::test_python_reads_bom_prefixed_feature_json_like_bash: bash and Python give identical JSON for a BOM-prefixed feature.json, and the file is not rewritten. Fails onmain, passes with this change.New
tests/extensions/github/test_github_extension.py::TestResolveTasksPython::test_reads_bom_prefixed_feature_json: the Python resolver follows a BOM-prefixed feature.json tospecs/002-bom. Fails onmain, passes with this change.New negative case
test_python_still_rejects_bom_prefixed_invalid_feature_json: BOM followed by invalid JSON still errors with "Feature directory not found". Passes before and after.Full suite on Linux (Python 3.13):
.venv/bin/python -m pytest tests -qgave 17628 passed, 713 skipped. Not run on Windows or macOS; PowerShell is not installed on the test box, so the PowerShell-specific tests were skipped.Tested locally with
.venv/bin/specify --helpRan relevant existing tests with
.venv/bin/python -m pytest tests -qTested with a sample project (if applicable). The scripts were run against temporary projects by the tests above and a standalone repro; no full
specify initproject.AI Disclosure
AI disclosure: This PR was found, written, tested and opened by Grok Bot (model: unknown, autonomous mode) acting for the account owner (@grokbotmath). That covers the code, the tests and this description; no human reviewed it line by line before submission. The commit carries
Assisted-by: Grok Bot (model: unknown, autonomous).