fix(integrations): escape control characters in goose recipe YAML renderer
Description
Fixes #3382
YamlIntegration._render_yaml writes the command body verbatim into a |2 literal block scalar. YAML forbids C0 control characters (except tab and newline) and DEL in every scalar form, and a bare CR acts as a line break inside a block scalar, so a body containing any of these produced a goose recipe the YAML parser rejects (unacceptable character #x0008: special characters are not allowed).
Root cause: the block-scalar path has no escaping mechanism at all; there is no string form in YAML that carries these bytes raw.
Fix: detect block-scalar-unsafe characters with a precompiled character class and fall back to an escaped double-quoted scalar rendered by yaml.safe_dump, which escapes them as \b, \r, \x7F and so on. Bodies without such characters keep the existing readable block-scalar output byte for byte. This mirrors the fallback strategy #3341 gives the TOML renderers for the same bug class (#3340).
Testing
- [x] Tested locally with
uv run specify --help - [x] Ran existing tests with
uv sync && uv run pytest— 3776 passed, 105 skipped - [ ] Tested with a sample project (if applicable)
Two regression tests in the shared YamlIntegrationTests mixin (exercised via the goose integration): control characters (\x08, \x0c, \x1b, \x7f) and a bare CR, both asserting the rendered recipe parses and the prompt round-trips. Both fail on main.
AI Disclosure
- [ ] I did not use AI assistance for this contribution
- [x] I did use AI assistance (describe below)
Bug found, patch and tests written with GitHub Copilot CLI; reproduction and full test suite run and verified locally by me.
@copilot review
Thank you!