Commit Graph
3 Commits
Author SHA1 Message Date
Zhizhen He 6d7bd11d07 edit: validate nested YAML input and output (#591)
Reject duplicate keys and multiple documents instead of silently editing
them. Validate rendered output before writing so edits cannot leave
dangling aliases or introduce duplicate keys. Errors leave files untouched.
Apply the same validation to YAMLText.

JSONToYAML now rejects duplicate keys without creating or replacing the
target, including omp's models.json conversion. Treat a document containing
only --- as empty, matching the top-level YAML editor.

Add regression tests for document loss, dangling aliases and duplicate
keys, alongside existing-behavior coverage for malformed input.
2026-10-03 01:15:14 +08:00
Zhizhen He de2530826d edit: preserve YAML entries when updating top-level keys (#452)
Changing Goose's model or effort could insert a key inside a multiline flow
collection or append a duplicate when the existing key was quoted. Locate
entries through parsed keys, keep complete values together, and validate the
result before writing it. Read and delete use decoded key names too.

Keep other entries, document markers, comments and block-scalar blank lines
in place. Reject invalid input, multiple documents and layouts that cannot
be edited safely as whole lines, with the file path in the error.

Regression tests reproduce the flow-value and quoted-key failures and cover
multiline values, unchanged surrounding content and failed writes.
2026-10-02 00:57:49 +08:00
yetone 37ba4deb3d goose: a key magpie adds to config.yaml goes after the whole last entry, never between extensions: and its children (found reviewing #431) — SetYAMLTop put a new top-level key right after the last top-level key line, so on a config.yaml ending in an extensions: block, magpie goose effort off wrote GOOSE_THINKING_EFFORT between extensions: and its indented children and Goose's config no longer parsed. A top-level entry is now its key line plus its indented lines, a sequence written at column 0 under it, and blank or column-0 comment lines between them (and the trailing blank lines of a |+ block scalar); a new key goes after the last such entry, before any trailing blank lines and comments. Setting or removing a key whose value ran over several lines now replaces or removes those lines too. Every other line stays byte for byte. TestYAMLTopAfterBlockEntry (block mapping, sequences, block scalars, no trailing newline, empty file, a block value replaced) fails without the change and checks each result parses with yaml.v3 and keeps the other keys' values. go vet, go build -tags nogui (darwin, GOOS=linux), GOOS=windows go build, go test -tags nogui ./... pass; the reviewer's goose431.sh repro in a sandbox HOME now yields a config.yaml that parses. 2026-10-01 22:23:41 +08:00