fix: use yaml.safe_dump for virtual package apm.yml generation#707
Open
edenfunf wants to merge 2 commits intomicrosoft:mainfrom
Open
fix: use yaml.safe_dump for virtual package apm.yml generation#707edenfunf wants to merge 2 commits intomicrosoft:mainfrom
edenfunf wants to merge 2 commits intomicrosoft:mainfrom
Conversation
When a virtual file or collection package has a `:` in its description, name, or tag values, the f-string interpolation produced invalid YAML (e.g. `description: tasks: feature development` triggers a mapping-values error on load). Replace both f-string blocks in `download_virtual_file_package` and `download_collection_package` with `yaml_to_str()` (backed by `yaml.safe_dump`), which correctly quotes strings containing special YAML characters. Fixes microsoft#703
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.
Problem
When a virtual file or collection dependency (e.g. a single
.agent.md) has a:in itsdescriptionfield,apm installfails with:Root cause:
download_virtual_file_packageanddownload_collection_packageingithub_downloader.pygeneratedapm.ymlby string interpolation (f"""name: {name}\ndescription: {description}\n"""). Any:in a value produces syntactically invalid YAML.Concrete example from the issue — swe-subagent frontmatter:
After stripping the surrounding quotes and dropping into the f-string, the
:after "tasks" is parsed as a YAML mapping separator, causing the error.Fix
Replace both f-string blocks with
yaml_to_str()(backed byyaml.safe_dump), which correctly quotes strings that contain:,#,[, or other YAML special characters.yaml_to_stralready exists inapm_cli/utils/yaml_io.pyand is the established helper for this purpose throughout the codebase.Tests
Three new unit tests in
TestVirtualFilePackageYamlGeneration:test_yaml_with_colon_in_descriptiontest_yaml_with_colon_in_nametest_yaml_without_special_characters_still_validChecklist
yaml.safe_loadon generatedapm.ymlsucceeds after changedownload_virtual_file_packageanddownload_collection_package)Closes #703