From 3213fb7d28224122d00f64a06ba03b5960435204 Mon Sep 17 00:00:00 2001 From: Lenin Mookiah <2639584+leninworld@users.noreply.github.com> Date: Wed, 25 Nov 2026 11:06:37 -0800 Subject: [PATCH 1/2] fix(artifacts): read artifact descriptions after a UTF-8 BOM _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) --- src/specify_cli/artifacts/catalog.py | 3 +- tests/specify_cli/artifacts/test_catalog.py | 123 ++++++++++++++++++++ 2 files changed, 125 insertions(+), 1 deletion(-) diff --git a/src/specify_cli/artifacts/catalog.py b/src/specify_cli/artifacts/catalog.py index 2780201cbf..4e898cafcd 100644 --- a/src/specify_cli/artifacts/catalog.py +++ b/src/specify_cli/artifacts/catalog.py @@ -182,7 +182,8 @@ def _describe_artifact_file(path: Path, kind: ArtifactKind) -> str: of the core/preset layer it hides. """ try: - text = path.read_text(encoding="utf-8") + # A UTF-8 BOM is an encoding marker, not artifact content. + text = path.read_text(encoding="utf-8").removeprefix("\ufeff") except (OSError, UnicodeDecodeError): return "" if kind == "script": diff --git a/tests/specify_cli/artifacts/test_catalog.py b/tests/specify_cli/artifacts/test_catalog.py index c3fa25eab8..781dd42433 100644 --- a/tests/specify_cli/artifacts/test_catalog.py +++ b/tests/specify_cli/artifacts/test_catalog.py @@ -22,6 +22,7 @@ HookArtifact, NotASpecKitProjectError, ) +from specify_cli.artifacts.catalog import _describe_artifact_file from specify_cli.artifacts.resolution import _preset_display_name from specify_cli.extensions import CORE_COMMAND_NAMES, ExtensionRegistry from specify_cli.presets import PresetRegistry, PresetResolver @@ -1457,6 +1458,107 @@ def test_project_override_reports_its_own_description(self, spec_kit_project: Pa assert rows["command:speckit.constitution"] == "Override description" assert rows["script:local-script"] == "Override script description" + @pytest.mark.parametrize( + ( + "core_path", + "override_path", + "artifact_id", + "core_content", + "override_content", + ), + [ + pytest.param( + "commands/speckit.constitution.md", + "speckit.constitution.md", + "command:speckit.constitution", + "---\ndescription: Core description\n---\n", + "\ufeff---\ndescription: Override description\n---\n", + id="command-lf", + ), + pytest.param( + "commands/speckit.constitution.md", + "speckit.constitution.md", + "command:speckit.constitution", + "---\ndescription: Core description\n---\n", + "\ufeff---\r\ndescription: Override description\r\n---\r\n", + id="command-crlf", + ), + pytest.param( + "scripts/local-script.sh", + "scripts/local-script.sh", + "script:local-script", + "# Core description\n", + "\ufeff# Override description\n", + id="shell-comment", + ), + ], + ) + def test_bom_project_override_reports_its_own_description( + self, + spec_kit_project: Path, + core_path: str, + override_path: str, + artifact_id: str, + core_content: str, + override_content: str, + ): + templates = spec_kit_project / ".specify" / "templates" + core = templates / core_path + core.parent.mkdir(parents=True, exist_ok=True) + core.write_text(core_content, encoding="utf-8") + override = templates / "overrides" / override_path + override.parent.mkdir(parents=True, exist_ok=True) + override.write_text(override_content, encoding="utf-8") + + rows = { + row.id: row.description + for row in ArtifactCatalog(spec_kit_project).list_artifacts() + } + + assert rows[artifact_id] == "Override description" + + @pytest.mark.parametrize("with_bom", [False, True], ids=["plain", "bom"]) + @pytest.mark.parametrize( + ("suffix", "kind", "content", "expected"), + [ + pytest.param( + ".ps1", + "script", + "<#\nPS description\n#>\n", + "PS description", + id="powershell-block", + ), + pytest.param( + ".py", + "script", + '"""Python description\nMore details.\n"""\n', + "Python description", + id="python-docstring", + ), + pytest.param( + ".md", + "template", + "---\ndescription: Template description\n---\nbody\n", + "Template description", + id="template-frontmatter", + ), + ], + ) + def test_describe_artifact_file_handles_optional_bom( + self, + tmp_path: Path, + with_bom: bool, + suffix: str, + kind: ArtifactKind, + content: str, + expected: str, + ): + path = tmp_path / f"artifact{suffix}" + prefix = "\ufeff" if with_bom else "" + path.write_text(prefix + content, encoding="utf-8") + + assert _describe_artifact_file(path, kind) == expected + def test_project_override_without_metadata_falls_back(self, spec_kit_project: Path): """A metadata-free override still reports the hidden layer's description.""" commands_dir = spec_kit_project / ".specify" / "templates" / "commands" @@ -1472,6 +1574,27 @@ def test_project_override_without_metadata_falls_back(self, spec_kit_project: Pa rows = {row.id: row.description for row in catalog.list_artifacts()} assert rows["command:speckit.constitution"] == "Core description" + def test_bom_project_override_without_metadata_falls_back( + self, spec_kit_project: Path + ): + commands_dir = spec_kit_project / ".specify" / "templates" / "commands" + commands_dir.mkdir(parents=True) + (commands_dir / "speckit.constitution.md").write_text( + "---\ndescription: Core description\n---\n", encoding="utf-8" + ) + overrides = spec_kit_project / ".specify" / "templates" / "overrides" + overrides.mkdir(parents=True) + (overrides / "speckit.constitution.md").write_text( + "\ufeffbody\n", encoding="utf-8" + ) + + rows = { + row.id: row.description + for row in ArtifactCatalog(spec_kit_project).list_artifacts() + } + + assert rows["command:speckit.constitution"] == "Core description" + def test_project_override_describes_both_backed_kinds(self, spec_kit_project: Path): commands_dir = spec_kit_project / ".specify" / "templates" / "commands" commands_dir.mkdir(parents=True) From 4948f2afa2e72ede04911d10633ff4e4cf252a96 Mon Sep 17 00:00:00 2001 From: Lenin Mookiah <2639584+leninworld@users.noreply.github.com> Date: Wed, 25 Nov 2026 11:29:56 -0800 Subject: [PATCH 2/2] fix(artifacts): keep BOM stripping off the read_text line 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) --- src/specify_cli/artifacts/catalog.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/specify_cli/artifacts/catalog.py b/src/specify_cli/artifacts/catalog.py index 4e898cafcd..237eba9173 100644 --- a/src/specify_cli/artifacts/catalog.py +++ b/src/specify_cli/artifacts/catalog.py @@ -182,10 +182,11 @@ def _describe_artifact_file(path: Path, kind: ArtifactKind) -> str: of the core/preset layer it hides. """ try: - # A UTF-8 BOM is an encoding marker, not artifact content. - text = path.read_text(encoding="utf-8").removeprefix("\ufeff") + text = path.read_text(encoding="utf-8") except (OSError, UnicodeDecodeError): return "" + # A UTF-8 BOM is an encoding marker, not artifact content. + text = text.removeprefix("\ufeff") if kind == "script": return _extract_script_description(text) return _extract_frontmatter_description(text)