Repository navigation
fix(presets): detect command frontmatter after a UTF-8 BOM - #5568
Merged
mnriem merged 2 commits intoNov 25, 2026
Merged
Conversation
PresetResolver only recognised command frontmatter when the first line was exactly "---". A preset command saved as UTF-8 with BOM therefore had its frontmatter `strategy:` ignored (an append/prepend/wrap command replaced the core command), and with a manifest strategy the BOM and the raw frontmatter block were composed into the command body. Ignore one leading BOM when looking for the opening delimiter in the legacy strategy fallback and in resolve_content's frontmatter split, as github#5562 did for CommandRegistrar.parse_frontmatter. Content without a complete frontmatter block is still composed unchanged. Assisted-by: OpenAI Codex CLI (model: gpt-5.6-sol, autonomous) Assisted-by: Claude Code (model: Claude Opus 5.5, autonomous)
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The new BOM tests use a helper that omits an explicit UTF-8 encoding when writing command files, causing UnicodeEncodeError on Windows configurations such as cp1252 before the resolver is exercised.
1 open issue
What changed in this PR
Extends the BOM handling from #5562 to preset command composition, allowing UTF-8 BOM-prefixed frontmatter to be recognized without changing incomplete or absent frontmatter.
Changes:
- Recognizes one leading BOM during legacy strategy detection and frontmatter splitting.
- Adds regression coverage for composition, prohibited frontmatter strategies, and unchanged fallback content.
| File | Description |
|---|---|
tests/specify_cli/presets/test_resolver.py |
Adds BOM regression tests and preservation checks. |
src/specify_cli/presets/_resolver.py |
Handles a leading BOM at both frontmatter detection sites. |
Review effort: Balanced (adaptive)
_create_pack wrote command files with the platform default encoding, so the new BOM cases raised UnicodeEncodeError before reaching the resolver where the default is cp1252 (e.g. Windows). Assisted-by: Claude Code (model: Claude Opus 5.5, autonomous) Assisted-by: OpenAI Codex CLI (model: gpt-5.6-sol, autonomous)
Collaborator
|
Thank you! |
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
PresetResolveronly recognizes command frontmatter when the first line is exactly---. Preset command files are read withread_text(encoding="utf-8"), which keeps a UTF-8 BOM, so a command saved as "UTF-8 with BOM" (for example by Windows PowerShell 5.1Set-Content -Encoding UTF8, or an editor set to that encoding) breaks composition in two places insrc/specify_cli/presets/_resolver.py:collect_all_layers, legacy fallback when the manifest entry has nostrategy):strategy: append(orprepend/wrap) is not seen, so the layer is treated asreplaceand the core command is dropped. The check that rejectsstrategy: replace-sectionin command frontmatter is skipped the same way.resolve_content, frontmatter split for command composition): withstrategy: appendinpreset.yml, the BOM and the raw---/description/strategy/---block are appended into the composed command.Reproduction on main:
specify init --here --integration claude --ignore-agent-tools, thenspecify preset add --dev ./presetwherecommands/speckit.specify.mdis---\ndescription: Appended by preset\nstrategy: append\n---\n\nAPPENDED-BY-PRESET\nandpreset.ymllists it as acommandtemplate:.claude/skills/speckit-specify/SKILL.mdstrategy: appendinpreset.ymlThe fix ignores one leading U+FEFF when looking for the opening
---at both sites, the same approach as #5562 forCommandRegistrar.parse_frontmatter. When no complete frontmatter follows (BOM without frontmatter, unterminated frontmatter), the layer is composed unchanged, BOM included, as before. A U+FEFF anywhere else is left alone.Testing
Set up this checkout's
.venvand editable install using the local development guide. Run commands from the checkout root.Tested locally with
.venv/bin/specify --help(Windows PowerShell:.\.venv\Scripts\specify.exe --help)Ran relevant existing tests with
.venv/bin/python -m pytest tests -q(Windows PowerShell:.\.venv\Scripts\python.exe -m pytest tests -q); use affected test paths for focused checks andLC_ALL=en_US.UTF-8on macOSTested with a sample project (if applicable)
New tests in
tests/specify_cli/presets/test_resolver.py: frontmatterstrategy: appendafter a BOM (LF and CRLF) is honoured; a BOM-prefixed layer with a manifestappendstrategy composes without the BOM or its frontmatter;strategy: replace-sectionin command frontmatter is rejected with and without a BOM; and two negative cases (BOM without frontmatter, BOM with unterminated frontmatter) that must be appended unchanged. On main the 4 BOM positive cases fail and the 3 others pass; with the fix all 7 pass.tests/specify_cli/presets: 856 passed, 1 skipped. Full suite with-n autoon macOS: 17255 passed, 635 skipped, 1 failed:test_version_execution.py::TestWindowsUvToolEnvironment::test_non_windows_uv_tool_dry_run_still_previews_installer, which fails on main in my environment too.uvx ruff@0.15.0 check src tests: all checks passed.Sample project: the
specify init/specify preset add --devreproduction above, before and after.AI Disclosure
AI disclosure: Claude Code (model: Claude Opus 5.5, autonomous) found these sites while checking the rest of the BOM class after #5562. OpenAI Codex CLI (model: gpt-5.6-sol, medium reasoning, autonomous) wrote the fix and tests (code generation); Claude Code made small test edits (docstrings, an unused variable), reproduced the bug end to end, reviewed the change, ran the tests and lint, and wrote this description. The commit carries
Assisted-by:trailers.