fix(presets): treat an unreadable core template as missing - #3961
Open
marcelsafin wants to merge 2 commits into
Open
fix(presets): treat an unreadable core template as missing#3961marcelsafin wants to merge 2 commits into
marcelsafin wants to merge 2 commits into
Conversation
_substitute_core_template() read the resolved core template with a bare read_text(), so one corrupted project-owned override in .specify/templates/commands/ crashed the whole wrap-strategy command registration with a raw UnicodeDecodeError. Both callers (CommandRegistrar.register_pack and _register_commands) are unguarded here, even though register_pack already skips an unreadable preset source with a warning a few lines above the call. Treat an unreadable core template like a missing one — warn and return the body unchanged with empty frontmatter — matching the function's documented no-core contract. Assisted-by: GitHub Copilot (model: claude-fable-5, autonomous) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Handles unreadable core templates without crashing preset command registration.
Changes:
- Warns and falls back when core templates cannot be read or decoded.
- Adds regression coverage and updates the function contract.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/specify_cli/presets/__init__.py |
Handles unreadable core templates safely. |
tests/test_presets.py |
Tests invalid UTF-8 fallback behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Review follow-up: use pytest.warns so removing or changing the promised warning fails the test. Assisted-by: GitHub Copilot (model: claude-fable-5, autonomous) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
Suppressed comments (2)
src/specify_cli/presets/init.py:214
CommandRegistrarhas noregister_packmethod; the guarded caller isregister_commands, while the other direct caller isPresetManager._register_skills. Referencing the nonexistent method makes this rationale difficult to verify.
# the wrap-strategy callers already skip an unreadable preset source with
# a warning (CommandRegistrar.register_pack).
tests/test_presets.py:10732
- This rationale names nonexistent
CommandRegistrar.register_packand says both callers skip unreadable preset sources. The actual call sites areregister_commands(guarded) and_register_skills(whose source read is unguarded), so the regression explanation is inaccurate.
The wrap-strategy callers (``CommandRegistrar.register_pack`` and
``_register_commands``) skip an unreadable preset source with a
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
_substitute_core_template()reads the resolved core template with a bareread_text(), so one corrupted project-owned override in.specify/templates/commands/crashes the whole wrap-strategy command registration with a rawUnicodeDecodeError. Both callers (CommandRegistrar.register_packand_register_commands) are unguarded here — even thoughregister_packalready skips an unreadable preset source with a warning a few lines above the call.Fix: treat an unreadable core template like a missing one — warn and return the body unchanged with empty frontmatter — matching the function's documented no-core contract ("Both are unchanged / empty when … the core template file does not exist").
Testing
uv run specify --helpuv sync && uv run pytest(6,310 passed, 176 skipped)test_substitute_core_template_unreadable_core_treated_as_missing(fails on main, passes with fix)ruff check src testscleanAI Disclosure
Implemented autonomously by GitHub Copilot CLI (model: Claude Fable 5) under human direction; TDD (failing test first), full suite and lint verified locally. Commit includes
Assisted-by/Co-authored-bytrailers.