Skip to content

fix(artifacts): read artifact descriptions after a UTF-8 BOM - #5577

Open
leninworld wants to merge 2 commits into
github:mainfrom
leninworld:fix/artifact-description-bom
Open

leninworld wants to merge 2 commits into
github:mainfrom
leninworld:fix/artifact-description-bom

Conversation

@leninworld

Copy link
Copy Markdown
Contributor

Description

ArtifactCatalog falls back to on-disk metadata (_describe_artifact_file) when a layer has no manifest description, for example a project override under .specify/templates/overrides/. It decoded the file as UTF-8 but kept a leading UTF-8 BOM, so every extractor missed the metadata: the frontmatter check saw --- instead of ---, the <# ... #> and """ regexes are anchored at the start, and the comment-line scan saw # .... A BOM-saved override (Windows PowerShell 5.1, Notepad) therefore reported no description, and specify artifact list showed the hidden core layer's description instead of the override's.

Reproduction on main: specify init --here --integration claude --ignore-agent-tools --script sh, then save .specify/templates/overrides/speckit.constitution.md as ---\ndescription: Override description\n---\nbody\n and .specify/templates/overrides/scripts/local-sh.sh as # Override bash description\necho hi\n. specify artifact list --json reported:

  • command:speckit.constitution: the core description (Create or update the project constitution ...)
  • template:speckit.constitution: ""
  • script:local-sh: ""

The same files without the BOM, and these files with this change, report Override description, Override description and Override bash description.

The fix strips one leading BOM after decoding, as CommandRegistrar.parse_frontmatter already does (#5562) for the script-reference scan in the same module. The extractors are unchanged.

Testing

Set up this checkout's .venv and 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 and LC_ALL=en_US.UTF-8 on macOS

  • Tested with a sample project (if applicable)

  • New tests in tests/specify_cli/artifacts/test_catalog.py: BOM-saved project overrides (command frontmatter with LF and CRLF, shell comment) report their own description through list_artifacts(), and _describe_artifact_file reads a PowerShell block, a Python docstring and template frontmatter after a BOM. These 6 cases fail on main and pass with the fix. Guards that pass on both: the same files without a BOM, and a BOM-saved override with no metadata still falls back to the core description.

  • Full suite with -n auto on macOS: 17290 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. pre-commit hooks pass on the changed files.

  • Sample project: the specify init / specify artifact list --json reproduction above, before and after.

AI Disclosure

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

AI disclosure: Claude Code (model: Claude Opus 5.5, autonomous) found the bug while reviewing artifacts/catalog.py, reproduced it end to end, reviewed and adjusted the tests, ran the tests, lint and hooks, and wrote this description. OpenAI Codex CLI (model: gpt-5.6-sol, autonomous) wrote the fix and tests (code generation) from Claude's task description. The commit carries Assisted-by: trailers.

_describe_artifact_file decoded the file as UTF-8 but kept a leading
BOM, so the frontmatter, PowerShell block, Python docstring and comment
extractors all missed the metadata of a BOM-saved file. A project
override saved with a BOM (Windows PowerShell 5.1, Notepad) then
reported no description, and `specify artifact list` showed the hidden
core layer's description instead of the override's.

Strip one leading BOM after decoding, as CommandRegistrar.parse_frontmatter
already does for the script-reference scan in the same module.

Assisted-by: OpenAI Codex CLI (model: gpt-5.6-sol, autonomous)
Assisted-by: Claude Code (model: Claude Opus 5.5, autonomous)
@leninworld
leninworld requested a review from mnriem as a code owner November 25, 2026 19:12
Copilot AI adaptive review requested due to automatic review settings November 25, 2026 19:12

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 narrowly scoped BOM-handling change includes regression coverage for all supported artifact formats and preserves metadata fallback behavior.

No open issues 🎉

What changed in this PR

This pull request fixes artifact description extraction for files saved with a leading UTF-8 BOM, allowing project overrides to report their own metadata while preserving fallback behavior.

Changes:

  • Strip one leading BOM before artifact description extraction.
  • Add regression coverage for BOM-prefixed command, template, shell, PowerShell, and Python artifacts.
  • Verify metadata-free BOM-prefixed overrides still fall back to the hidden layer description.
File Description
tests/​specify_cli/​artifacts/​test_catalog.py Adds regression tests covering BOM-prefixed metadata extraction across supported artifact formats and fallback behavior.
src/​specify_cli/​artifacts/​catalog.py Removes one leading UTF-8 BOM before extracting descriptions from on-disk artifact files.

Review effort: Lite (adaptive)

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 were identified.

No open issues 🎉

Review effort: Balanced

@mnriem

mnriem commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator

Please address CI/CD errors

Strip the BOM after the read so the existing read_text call stays unchanged and the FileHelper migration check sees no new direct I/O.

Assisted-by: Claude Code (model: Claude Opus 5.5, autonomous)

Assisted-by: OpenAI Codex CLI (model: gpt-5.6-sol, autonomous)
@leninworld

Copy link
Copy Markdown
Contributor Author

Thanks. The FileHelper migration check flagged the read_text line because my fix edited it. In 4948f2a I left that line exactly as on main and strip the BOM on the next line instead, so no new direct I/O is added and the behaviour is unchanged. The check script passes locally against the merge base, and the artifacts tests pass (360). The Windows pytest job was still pending when I looked.

Copilot AI balanced review requested due to automatic review settings November 25, 2026 19:31

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 were identified for the BOM-handling change, though tests were not independently run during review.

No open issues 🎉

Review effort: Balanced

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 were identified for the BOM-prefixed artifact description fix.

No open issues 🎉

Review effort: Balanced

@mnriem mnriem added the triage-can-wait Verdict: valid and in-scope but deprioritized; held behind the evidence gate label Nov 25, 2026

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-can-wait Verdict: valid and in-scope but deprioritized; held behind the evidence gate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants