Repository navigation
fix(presets): treat non-mapping command frontmatter as empty - #5125
Open
xubenqiang wants to merge 2 commits into
Open
xubenqiang wants to merge 2 commits into
xubenqiang wants to merge 2 commits into
Conversation
_parse_fm_yaml returned whatever yaml.safe_load produced, and resolve_content
then called .pop on it, so a composing command whose frontmatter was valid YAML
but not a mapping crashed preset add with AttributeError. Fall back to {} like
CommandRegistrar.parse_frontmatter already does.
Collaborator
|
Please address Copilot feedback |
Addresses the Copilot review note: the test would have passed even if non-mapping frontmatter had dropped the base layer, so assert its body is still in the resolved content.
Author
|
Added the assertion Copilot suggested in 0b25a4e: �ssert "CORE BODY" in content, so the test now fails if the base command is dropped during composition. |
This branch has not been deployed
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
PresetResolver.resolve_contentparses the winning command layer's frontmatter with_parse_fm_yaml, which returned whateveryaml.safe_loadproduced. A composing command (append/prepend/wrap) whose frontmatter is valid YAML but not a mapping therefore reachedtop_fm.pop("strategy", None)as astrandpreset addsurfaced a rawAttributeError: 'str' object has no attribute 'pop'instead of a preset error.CommandRegistrar.parse_frontmatteralready treats a non-dict result as{}, and this resolver already does the same foryaml.YAMLError._parse_fm_yamlnow applies the same guard, so non-mapping frontmatter is treated as empty and composition continues.Fixes #5085
Testing
pytest tests/specify_cli/presets/test_resolver.py -q-> 74 passed, 1 faileduv run specify --helpThe one failure is
TestPresetResolver::test_resolve_fails_closed_when_registry_is_broken_symlink, which fails the same way on an unmodified checkout on this Windows machine (OSError: [WinError 1314], symlink creation needs a privilege this shell does not hold), so it is environmental, not caused by this change.The new test installs a preset whose command layer has
---\njust a note\n---frontmatter over a core command. With the fix it resolves and contains the appended body without the invalid frontmatter; with_resolver.pyreverted it fails withAttributeError: 'str' object has no attribute 'pop'.AI Disclosure
AI disclosure: DeepSeek Harness coding agent (model
deepseek-flash), running autonomously under a human-directed task. Extent: read the referenced code, wrote theisinstanceguard in_resolver.py, the regression test, and ran the suite locally; the human operator reviewed the submitted diff.