fix(integrations): strip UTF-8 BOM when reading agent context files#2283
Merged
mnriem merged 4 commits intogithub:mainfrom Apr 20, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a Windows/PowerShell UTF-8 BOM round-tripping issue that could introduce a visible \ufeff artifact at the top of agent context files (e.g., CLAUDE.md) when updating managed sections.
Changes:
- Read agent context files with
encoding="utf-8-sig"inupsert_context_sectionandremove_context_sectionto strip a UTF-8 BOM on input. - Add regression tests ensuring BOM is removed after both upsert and remove operations for the Claude integration.
- Stabilize workflow-related tests by mocking
shutil.which(...)so results don’t depend on whether an integration CLI is installed on the test machine.
Show a summary per file
| File | Description |
|---|---|
src/specify_cli/integrations/base.py |
Switch context file reads to utf-8-sig to strip BOM during section upsert/removal. |
tests/integrations/test_integration_claude.py |
Add BOM regression tests for upsert/remove behavior. |
tests/test_workflows.py |
Mock CLI presence checks (shutil.which) to make dispatch-related tests environment-independent. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 3/3 changed files
- Comments generated: 0
mnriem
approved these changes
Apr 20, 2026
Collaborator
|
Thank you! |
elTorres
pushed a commit
to elTorres/spec-kit
that referenced
this pull request
Apr 22, 2026
…ithub#2283) * fix(integrations): strip UTF-8 BOM when reading agent context files * test(integrations): add BOM regression tests for context file read/write * test(workflows): mock shutil.which in tests that assume CLI is absent * test(integrations): remove unused manifest variable in BOM test
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
Fixes #2234 —
specify init --integration claudecorruptsCLAUDE.mdwhen the file was previously written by PowerShell 5.1 (which emits a UTF-8 BOM by default).Root cause:
IntegrationBase.upsert_context_sectionandremove_context_sectionboth callpath.read_text(encoding="utf-8"). Python's"utf-8"codec preserves the BOM byte sequence (\xef\xbb\xbf) as\ufeffin the returned string. When the content is re-encoded and written back, that\ufeffbecomes a visible artifact at the top of the file.Fix: Change both
read_textcalls toencoding="utf-8-sig". The"utf-8-sig"codec strips the BOM on read and never adds one on write, so files authored on Windows round-trip cleanly.Files changed:
src/specify_cli/integrations/base.py— two one-line changes (lines 485 and 550)tests/integrations/test_integration_claude.py— two regression teststests/test_workflows.py— mockshutil.whichin four tests that assumed the CLI was absentTesting
Test selection reasoning:
tests/integrations/test_integration_claude.pyupsert_context_sectionandremove_context_sectiontests/test_workflows.pyshutil.which("claude")found the binary in the dev environment; mocked to be environment-independentManual test results:
python -c "open('CLAUDE.md','wb').write(b'\xef\xbb\xbf# CLAUDE.md\n')"uv run specify init --integration claudexxd CLAUDE.md | head -1ef bb bfprefix — BOM strippeduv run python -m pytest -quv run specify --helpuv sync && uv run pytest