fix(modify): quote --set-field values so a colon-space no longer corrupts the file (#687)#691
Open
avrabe wants to merge 1 commit into
Open
fix(modify): quote --set-field values so a colon-space no longer corrupts the file (#687)#691avrabe wants to merge 1 commit into
avrabe wants to merge 1 commit into
Conversation
…upts the file (#687) `rivet modify --set-field key=value` used to write the value RAW under a block-style `fields:` sub-map — every sibling setter (`--set-title`, `--set-status`, `--set-release`, `--set-description`) already routes through `yaml_quote_inline_scalar`, but the `set_fields` loop skipped it. A value containing `: ` (or any other plain-scalar indicator — `#`, leading `-`/`?`/`[`/`{`, YAML booleans, …) then produced invalid YAML: rationale: CURVE-AGILE: Ed25519 preferred, ECDSA-P256 fallback ... The second `: ` reads as a mapping value → parse error on the whole source file → rivet WARN-and-skips the file → every artifact in it silently vanishes from the loaded store. Same data-loss shape as #573/#613/#618 (invalid YAML from a mutation drops the file), just via the one setter that never got the quoting treatment. Fix: route each `set_fields` value through the existing `yaml_quote_inline_scalar` helper before formatting. Applied at all three block-style write sites (replace-existing sub-key, insert new sub-key, create new `fields:` section). The flow-style branch already went through `serde_yaml`, which quotes correctly — left alone. Confirmed end-to-end: `rivet modify DD-1 --set-field 'rationale=CURVE-AGILE: Ed25519 preferred'` now writes `rationale: "CURVE-AGILE: Ed25519 preferred"`, the file stays parseable, both artifacts round-trip through `rivet get`, and the hostile value survives verbatim. Three regression tests cover the insert branch, the create-fields-section branch, and the replace-existing branch. Fixes: REQ-034 Verifies: REQ-034
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
📐 Rivet artifact deltaNo artifact changes in this PR. Code-only changes (renderer, CLI wiring, tests) don't touch the artifact graph. |
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.
Closes #687.
Bug
rivet modify --set-field key=valueused to write the value RAW under ablock-style
fields:sub-map — every sibling setter (--set-title,--set-status,--set-release,--set-description) already routesthrough
yaml_quote_inline_scalar, but theset_fieldsloop skipped it.A value containing
:(or any other plain-scalar indicator —#,leading
-/?/[/{, YAML booleans, …) then produced invalid YAML:The second
:reads as a mapping value → parse error on the wholesource file → rivet WARN-and-skips the file → every artifact in it
silently vanishes from the loaded store. Same data-loss shape as
#573/#613/#618 (invalid YAML from a mutation drops the file), just via
the one setter that never got the quoting treatment.
Fix
Route each
set_fieldsvalue through the existingyaml_quote_inline_scalarhelper before formatting — the fix the issue asked for, one line. Applied at
all three block-style write sites (replace-existing sub-key, insert new sub-key,
create new
fields:section). The flow-style branch already went throughserde_yaml, which quotes correctly — left alone.Acceptance criteria (from the issue's "Suggested fix")
set_field's value throughyaml_quote_inline_scalar.Applied at all three block-style write sites in
rivet-core/src/yaml_edit.rs.validate/get/list. The issue explicitly framed this as "Separately,consider" — decoupling it keeps this PR to a single-file bug fix; the
silent-skip behavior is orthogonal and warrants its own design/PR (it
affects the error UX of several commands, not just the mutation path).
Verification
set_field_quotes_value_with_colon_space_and_preserves_siblings—insert branch (existing
fields:, new sub-key), sibling artifact survives.set_field_creating_fields_section_quotes_hostile_value— create-fieldsbranch (no pre-existing
fields:).set_field_updating_existing_key_quotes_hostile_value— replace branch(existing sub-key overwritten).
yaml_edittests pass; nothing else in the module was touched.cargo fmt --all -- --check,cargo clippy --all-targets -- -D warnings,rivet validate(PASS).Generated by Claude Code