Skip to content

fix(matcher): decode the authored operator-map through yaml.v3 - #459

Merged
github-actions[bot] merged 1 commit into
mainfrom
fix/matcher-unmarshal-yaml
Nov 30, 2026
Merged

github-actions[bot] merged 1 commit into
mainfrom
fix/matcher-unmarshal-yaml

Conversation

@aitrawog

Copy link
Copy Markdown
Contributor

Summary

Matcher carried only json tags, so yaml.v3 decoded its struct field names op/value and silently dropped the authored operator-map form — expect: {equals: "yes"} lowered to a zero matcher, never an error. An authored #Answer.expect (D-FLOW-3) therefore arrived empty and the pipeline lowering's refusal never fired.

This adds Matcher.UnmarshalYAML mirroring the existing UnmarshalJSON: the canonical {op, value} mapping, an operator-map ({equals: X}), a bare scalar (implicit equality), and null/empty to the zero matcher. It also adds the regression test that decodes the authored #Answer shape from YAML and round-trips the matcher.

The diff is spec/union_types.go (the hand-written #Matcher Go type) and its new test file spec/union_types_matcher_yaml_test.go. No CUE schema, generated type or wire shape changes.

Closes #457

How tested

Head c6967fd5cca92eb0d6373f271eb4fb35e1e69dfd (git rev-parse HEAD).

Spike

RCA claim: Matcher carries only json tags, so yaml.v3 decodes the struct's op/value fields and silently drops the authored operator-map ({equals: X}), leaving Op/Value zero.

Candidates spiked:

  • (a) add Matcher.UnmarshalYAML mirroring UnmarshalJSON — WORKS, and it is the candidate the diff implements; the transcripts below are its spike.
  • (b) decode the raw YAML node into a local matcher at the consumer — rejected: re-decoding a shared spec type inside one consumer is the R3 workaround the type exists to prevent, and every other #Matcher decoded through yaml.v3 would still drop its operator.
  • (c) make #Answer.expect a string — rejected: it loses the single-operator matcher vocabulary (#Matcher / #MatchOpMap), and #Answer is not the only matcher-shaped field.

Winner: (a) add Matcher.UnmarshalYAML mirroring UnmarshalJSON — it gives the type's two read paths one vocabulary (R2) and fixes every YAML consumer rather than one.

RCA verdict: confirmed — candidate (a) works; the regression test fails on the unmodified tree and passes with the implementation.

Fails-before — the regression test on a clean worktree of the parent commit 31f96dc with only the test file added (no implementation):

$ GOTOOLCHAIN=go1.26.8 go test -count=1 -run 'TestMatcher(UnmarshalYAML|YAMLRoundTrip)' -v ./spec/
=== RUN   TestMatcherUnmarshalYAML_OperatorMap
    union_types_matcher_yaml_test.go:27: expect = {Op:"" Value:<nil>}, want {Op:"equals" Value:"yes"}
--- FAIL: TestMatcherUnmarshalYAML_OperatorMap (0.00s)
=== RUN   TestMatcherUnmarshalYAML_Forms
=== RUN   TestMatcherUnmarshalYAML_Forms/operator-map
    union_types_matcher_yaml_test.go:55: expect = {Op:"" Value:<nil>}, want {Op:"equals" Value:"yes"}
=== RUN   TestMatcherUnmarshalYAML_Forms/operator-map_contains
    union_types_matcher_yaml_test.go:55: expect = {Op:"" Value:<nil>}, want {Op:"contains" Value:"needle"}
=== RUN   TestMatcherUnmarshalYAML_Forms/canonical_struct
=== RUN   TestMatcherUnmarshalYAML_Forms/bare_scalar
    union_types_matcher_yaml_test.go:52: decode "expect: PONG\n": yaml: unmarshal errors:
          line 1: cannot unmarshal !!str `PONG` into spec.Matcher
=== RUN   TestMatcherUnmarshalYAML_Forms/null
=== RUN   TestMatcherUnmarshalYAML_Forms/empty
--- FAIL: TestMatcherUnmarshalYAML_Forms (0.00s)
    --- FAIL: TestMatcherUnmarshalYAML_Forms/operator-map (0.00s)
    --- FAIL: TestMatcherUnmarshalYAML_Forms/operator-map_contains (0.00s)
    --- PASS: TestMatcherUnmarshalYAML_Forms/canonical_struct (0.00s)
    --- FAIL: TestMatcherUnmarshalYAML_Forms/bare_scalar (0.00s)
    --- PASS: TestMatcherUnmarshalYAML_Forms/null (0.00s)
    --- PASS: TestMatcherUnmarshalYAML_Forms/empty (0.00s)
=== RUN   TestMatcherYAMLRoundTrip
    union_types_matcher_yaml_test.go:79: unmarshal "expect: \"yes\"\n": yaml: unmarshal errors:
          line 1: cannot unmarshal !!str `yes` into spec.Matcher
--- FAIL: TestMatcherYAMLRoundTrip (0.00s)
FAIL
FAIL	github.com/opencharly/spec/spec	0.003s
FAIL
EXIT=1

Passes-after — the same test on the head this PR pushes:

$ git rev-parse HEAD
c6967fd5cca92eb0d6373f271eb4fb35e1e69dfd
$ GOTOOLCHAIN=go1.26.8 go test -count=1 -run 'TestMatcher(UnmarshalYAML|YAMLRoundTrip)' -v ./spec/
=== RUN   TestMatcherUnmarshalYAML_OperatorMap
--- PASS: TestMatcherUnmarshalYAML_OperatorMap (0.00s)
=== RUN   TestMatcherUnmarshalYAML_Forms
=== RUN   TestMatcherUnmarshalYAML_Forms/operator-map
=== RUN   TestMatcherUnmarshalYAML_Forms/operator-map_contains
=== RUN   TestMatcherUnmarshalYAML_Forms/canonical_struct
=== RUN   TestMatcherUnmarshalYAML_Forms/bare_scalar
=== RUN   TestMatcherUnmarshalYAML_Forms/null
=== RUN   TestMatcherUnmarshalYAML_Forms/empty
--- PASS: TestMatcherUnmarshalYAML_Forms (0.00s)
    --- PASS: TestMatcherUnmarshalYAML_Forms/operator-map (0.00s)
    --- PASS: TestMatcherUnmarshalYAML_Forms/operator-map_contains (0.00s)
    --- PASS: TestMatcherUnmarshalYAML_Forms/canonical_struct (0.00s)
    --- PASS: TestMatcherUnmarshalYAML_Forms/bare_scalar (0.00s)
    --- PASS: TestMatcherUnmarshalYAML_Forms/null (0.00s)
    --- PASS: TestMatcherUnmarshalYAML_Forms/empty (0.00s)
=== RUN   TestMatcherYAMLRoundTrip
--- PASS: TestMatcherYAMLRoundTrip (0.00s)
PASS
ok  	github.com/opencharly/spec/spec	0.003s
EXIT=0

Gate

The module gate spec's CI runs (.github/workflows/ci.yml), on the committed tree:

$ git rev-parse HEAD
c6967fd5cca92eb0d6373f271eb4fb35e1e69dfd
$ go build ./...
EXIT=0
$ go vet ./...
EXIT=0
$ test -z "$(gofmt -l .)"
EXIT=0
$ go test -count=1 ./...
ok  	github.com/opencharly/spec	0.009s
ok  	github.com/opencharly/spec/cache	0.221s
ok  	github.com/opencharly/spec/calver	0.006s
?   	github.com/opencharly/spec/capability	[no test files]
?   	github.com/opencharly/spec/checkhost	[no test files]
ok  	github.com/opencharly/spec/checkstep	0.007s
ok  	github.com/opencharly/spec/climodel	0.124s
?   	github.com/opencharly/spec/clireflect	[no test files]
ok  	github.com/opencharly/spec/container	0.999s
ok  	github.com/opencharly/spec/cuetoolchain	1.202s
ok  	github.com/opencharly/spec/deploy	0.005s
ok  	github.com/opencharly/spec/exec	8.051s
ok  	github.com/opencharly/spec/exitcode	0.003s
ok  	github.com/opencharly/spec/hostenv	0.010s
?   	github.com/opencharly/spec/http	[no test files]
?   	github.com/opencharly/spec/internal/cuesetup	[no test files]
ok  	github.com/opencharly/spec/internal/wiregen	0.045s
?   	github.com/opencharly/spec/loader	[no test files]
ok  	github.com/opencharly/spec/lock	0.990s
ok  	github.com/opencharly/spec/matchers	0.004s
ok  	github.com/opencharly/spec/merge	0.004s
ok  	github.com/opencharly/spec/needsolver	0.002s
ok  	github.com/opencharly/spec/ops	0.010s
ok  	github.com/opencharly/spec/perhost	0.915s
ok  	github.com/opencharly/spec/phase	0.004s
ok  	github.com/opencharly/spec/poll	0.207s
ok  	github.com/opencharly/spec/proc	3.258s
ok  	github.com/opencharly/spec/proto	0.396s
ok  	github.com/opencharly/spec/refs	10.604s
ok  	github.com/opencharly/spec/report	0.014s
ok  	github.com/opencharly/spec/retired	0.090s
?   	github.com/opencharly/spec/retired/cmd/retired-sweep	[no test files]
ok  	github.com/opencharly/spec/schema	10.510s
ok  	github.com/opencharly/spec/schemacompose	0.324s
ok  	github.com/opencharly/spec/schemaconcat	0.003s
?   	github.com/opencharly/spec/schemagen	[no test files]
ok  	github.com/opencharly/spec/schemaparams	0.424s
ok  	github.com/opencharly/spec/schemaretag	0.002s
?   	github.com/opencharly/spec/shellquote	[no test files]
ok  	github.com/opencharly/spec/spec	1.444s
?   	github.com/opencharly/spec/sshx	[no test files]
ok  	github.com/opencharly/spec/storeroot	0.013s
?   	github.com/opencharly/spec/testkit	[no test files]
ok  	github.com/opencharly/spec/transport	0.211s
EXIT=0

The lint spec's AGENTS.md names, under the toolchain go.mod declares:

$ GOTOOLCHAIN=go1.26.8 golangci-lint run ./...
0 issues.
EXIT=0

Consumer proof

The end-to-end lowering proof is the consumer's, not this repo's: opencharly/plugin-pipeline#69 owns the bed that runs charly pipeline run --dry-run through the real plugin against the tag this change lands. This repo's boundary — that an authored #Answer.expect reaches spec.Matcher with its operator and value populated — is the decode, and the regression test above exercises it.

Rulebook compliance

  • R0: loaded git-workflow (with its pre-validator self-audit), strict-policy, root-cause-analyzer, design, go, plugin and install-plan from the live umbrella and spec trees, and spec's AGENTS.md, before the first edit.
  • R1: Matcher has no UnmarshalYAML — yaml.v3 silently drops the authored operator-map form #457 is the RCA's output; the one further finding this work surfaced (MatcherList has the same missing YAML read path, hard-erroring instead of silently dropping) is filed as MatcherList has no UnmarshalYAML — its scalar/single-map shorthand fails through yaml.v3 #458 and listed under ## Filed issues. The gate leaves no warning.
  • R2: UnmarshalYAML mirrors the existing UnmarshalJSON on the same type, so both read paths accept one vocabulary; candidate (b) was rejected because it would add a second decode of the shared type.
  • R3: no workaround — no sleep, retry, fallback or consumer-side shim; the fix is in the type.
  • R4: no documented command or prose is routed around the defect; the fix is in the product.
  • R5: nothing is renamed or deleted, so no legacy identifier remains; the added doc comment states the decode forms the type now accepts.
  • R6: the work ran in a session worktree outside the submodule (.worktrees/pr-sweep/spec, branch fix/matcher-unmarshal-yaml off origin/main); the submodule checkout is untouched; no force-push and no direct push.
  • R7: the regression test fails on the unmodified tree and passes with the change (transcripts above); the changed path is the decode itself.
  • R8: no real-service boundary is exercised; nothing is mocked.
  • R9: this is a library change — no charly binary is built or deployed, and the tests run the worktree source.
  • R10: change class is a Go library change; the gate is the module's go build, go vet, gofmt and go test plus the golangci-lint run that spec's CI performs, on the committed tree, with zero findings. spec declares no disposable: target; the consumer's live bed is plugin-pipeline#69's.
  • R11: the map below; no DESIGN surface is edited, so this carries no design change and needs no sign-off.
  • R12: the spike round is above, and the winner is the implementation.

Plan conformance

Winning candidate: (a) add Matcher.UnmarshalYAML mirroring UnmarshalJSON — the same candidate the ### Spike round names as its winner.

Planned change DESIGN requirement Disposition
Matcher.UnmarshalYAML, the YAML read path of the hand-written #Matcher Go type D-FLOW-3 (#StageAsk to #Answer): the response contract expect: is a matcher a response must satisfy to be granted conforms — the authored expect matcher arrives populated, so a granted settlement can evaluate the response
The accepted YAML forms (canonical {op, value} mapping, single-operator map, bare scalar, null) D-VERB-3: a matcher is exactly one comparison; DESIGN.cue's #Matcher and #MatcherAlt conforms — exactly one operator key is accepted, a multi-key map is an error, and a bare scalar is implicit equality
The YAML regression and round-trip test D-FLOW-3 / #Answer: the ask's response contract conforms — it decodes the authored #Answer shape through yaml.v3, asserts Op and Value, and round-trips
No new field, shape, kind, verb, capability, mechanism, config key or emitted artifact §1.1 / D-LAW-4: authored and wire shapes are defined once in CUE conforms — schema/*.cue and spec/cue_types_gen.go are untouched; #Matcher stays the hand-written @go(-) type and a clean regeneration stays a no-op

Change classification

  • Class: Go library behaviour fix in the spec contract module — no authored or wire shape change, no schema or generated-code change.
  • Breaking change + rollback: none — the YAML read path gains the forms the JSON read path already accepted; every value that decoded before still decodes, and an authoring document that is CUE-valid is unaffected. Rollback is a revert of the squash commit.
  • Consumer leg: producer-first — a consumer pins this tag after it lands; the consumer's live bed is opencharly/plugin-pipeline#69's.

Filed issues

Agent: pr-sweep · Claude Code session 8df24173-9dbe-4357-a454-8faee0703dea
Assisted-by: Claude Code deepseek-v4.1-flash:cloud (fully tested and validated)

Matcher carried only json tags, so yaml.v3 decoded its struct field names
`op`/`value` and silently dropped the authored operator-map form
(`expect: {equals: "yes"}`), leaving Op/Value zero with no error. An authored
#Answer.expect (D-FLOW-3) therefore arrived empty and the pipeline lowering's
refusal never fired.

UnmarshalYAML mirrors UnmarshalJSON: the canonical `{op, value}` mapping, an
operator-map, a bare scalar (implicit equality), and null/empty to the zero
matcher. A regression test decodes the authored #Answer shape from YAML and
round-trips the matcher.

Closes #457.

Agent: pr-sweep · Claude Code session 8df24173-9dbe-4357-a454-8faee0703dea
Assisted-by: Claude Code deepseek-v4.1-flash:cloud (fully tested and validated)
@github-actions

Copy link
Copy Markdown

Review — PASS

Head SHA: c6967fd5cca92eb0d6373f271eb4fb35e1e69dfd (branch: fix/matcher-unmarshal-yaml)

Security screen: PASS
Checklist: All applicable rules PASS or NA. (No comments to disposition; diff is a spec-module Go library fix — new Matcher.UnmarshalYAML mirroring the existing UnmarshalJSON, with a regression test proven fails-before/passes-after; gate output internally consistent; separable MatcherList finding filed as #458.)

Verdict: PASS


ollama-cloud/deepseek-v4.1-flash — action-review.

View action run

@github-actions
github-actions Bot enabled auto-merge (squash) November 30, 2026 08:05
@github-actions
github-actions Bot merged commit f1e7f5f into main Nov 30, 2026
4 checks passed
charly-auto-merge Bot added a commit that referenced this pull request Nov 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Matcher has no UnmarshalYAML — yaml.v3 silently drops the authored operator-map form

1 participant