Skip to content

fix(scripts): accept UTF-8 BOM in feature.json in Python readers - #5665

Open
grokbotmath wants to merge 3 commits into
github:mainfrom
grokbotmath:fix/feature-json-utf8-bom
Open

grokbotmath wants to merge 3 commits into
github:mainfrom
grokbotmath:fix/feature-json-utf8-bom

Conversation

@grokbotmath

@grokbotmath grokbotmath commented Dec 2, 2026 •

Copy link
Copy Markdown

Description

The Python script variants reject a .specify/feature.json that 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.json itself. On Windows, PowerShell 5.1's Set-Content -Encoding UTF8 (and Notepad) write a BOM. read_feature_json_feature_directory decoded the file as utf-8, so json.loads failed on the leading U+FEFF, the reader returned "", and the Python check-prerequisites, setup-plan, setup-tasks and the github extension's resolve-tasks stopped with:

ERROR: Feature directory not found. Set SPECIFY_FEATURE_DIRECTORY or ensure .specify/feature.json contains feature_directory.

For the same file, bash resolves the directory through its grep/sed fallback, and PowerShell resolves it through ReadAllText with UTF-8, which strips the BOM.

Repro on main (eab9f16), with feature.json = EF BB BF + {"feature_directory": "specs/001-my-feature"}:

script bash python (before) python (after)
check-prerequisites --json --paths-only exit 0 exit 1 (error above) exit 0, identical JSON
setup-plan --json exit 0 exit 1 exit 0
setup-tasks --json resolves dir (then spec.md not found in repro) exit 1, Feature directory not found same as bash

Fix: decode with utf-8-sig in core scripts/python/common.py and in the github extension's vendored copy of the same function (extensions/github/scripts/python/resolve_tasks.py). utf-8-sig decodes BOM-less UTF-8 the same way utf-8 does, 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_context also 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 on main, 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 to specs/002-bom. Fails on main, 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 -q gave 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 --help

  • Ran relevant existing tests with .venv/bin/python -m pytest tests -q

  • Tested with a sample project (if applicable). The scripts were run against temporary projects by the tests above and a standalone repro; no full specify init project.

AI Disclosure

  • I did not use AI assistance for this contribution
  • I did use AI assistance (fill in the disclosure below)

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).

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)
@grokbotmath
grokbotmath requested a review from mnriem as a code owner December 2, 2026 04:20
Copilot AI adaptive review requested due to automatic review settings December 2, 2026 04:20

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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-sig in 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)

@mnriem mnriem added the triage-must-have Verdict: high-value, important work for Spec Kit — do first label Dec 2, 2026
@mnriem
mnriem requested a balanced review from Copilot December 2, 2026 12:38

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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"))
@mnriem

mnriem commented Dec 2, 2026

Copy link
Copy Markdown
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)
Copilot AI balanced review requested due to automatic review settings December 2, 2026 14:10

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are identified for the BOM-handling update.

1 open issue
1 resolved since last review

Review effort: Balanced

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

triage-must-have Verdict: high-value, important work for Spec Kit — do first

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants