From 419bf9734a177487a5e2a7fada908063b564a404 Mon Sep 17 00:00:00 2001 From: jochen Date: Wed, 25 Nov 2026 18:50:19 +0100 Subject: [PATCH] DC2 step-runner-delivery-forms: the readers of mover-added and place-unfinished refuse a body naming none or two of from, caller and take-in, or both key and all Builds: design 47 H2 H-A-645, H-A-644 (AC-DC2c, AC-DC2d; review round 1) --- .../seats/meshpipelinerunner/contract_test.go | 16 +++++++ .../go/seats/meshpipelinerunner/readers.go | 42 +++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 modules/mesh-delivery-contracts/go/seats/meshpipelinerunner/readers.go diff --git a/modules/mesh-delivery-contracts/go/seats/meshpipelinerunner/contract_test.go b/modules/mesh-delivery-contracts/go/seats/meshpipelinerunner/contract_test.go index 25aef886c..993780cf8 100644 --- a/modules/mesh-delivery-contracts/go/seats/meshpipelinerunner/contract_test.go +++ b/modules/mesh-delivery-contracts/go/seats/meshpipelinerunner/contract_test.go @@ -183,4 +183,20 @@ func TestFixtures(t *testing.T) { t.Errorf("%s: subject %q is not the contract's %s", c.name, c.subject, c.subjectIs) } } + + // readers refuse a body naming none or two of the exclusive fields (H-A-645, H-A-644) + for _, r := range []struct { + name, given string + decode func([]byte) error + }{ + {"a mover added naming none of from, caller and take-in", `{"fingerprint":"fp","module":"m","pipeline":"main.1","revision":1}`, func(b []byte) error { _, _, err := DecodeMoverAddedEvent(b); return err }}, + {"a mover added naming from and take-in", `{"fingerprint":"fp","from":"main.0","module":"m","pipeline":"main.1","revision":1,"take-in":2}`, func(b []byte) error { _, _, err := DecodeMoverAddedEvent(b); return err }}, + {"a mover added naming caller and from", `{"caller":"x","fingerprint":"fp","from":"main.0","module":"m","pipeline":"main.1","revision":1}`, func(b []byte) error { _, _, err := DecodeMoverAddedEvent(b); return err }}, + {"a mover added naming all three", `{"caller":"x","fingerprint":"fp","from":"main.0","module":"m","pipeline":"main.1","revision":1,"take-in":2}`, func(b []byte) error { var v MoverAdded; return json.Unmarshal(b, &v) }}, + {"place-unfinished naming key and all", `{"all":true,"key":"main.m","why":"x"}`, func(b []byte) error { var v PlaceUnfinishedInput; return json.Unmarshal(b, &v) }}, + } { + if err := r.decode([]byte(r.given)); err == nil { + t.Errorf("%s: read, want refused", r.name) + } + } } diff --git a/modules/mesh-delivery-contracts/go/seats/meshpipelinerunner/readers.go b/modules/mesh-delivery-contracts/go/seats/meshpipelinerunner/readers.go new file mode 100644 index 000000000..da5825901 --- /dev/null +++ b/modules/mesh-delivery-contracts/go/seats/meshpipelinerunner/readers.go @@ -0,0 +1,42 @@ +package meshpipelinerunner + +import ( + "encoding/json" + "errors" +) + +// UnmarshalJSON reads a mover-added body and refuses one naming none or two of from, caller and take-in +// (design 47 H2 H-A-594 (4), H-A-609 (3), H-A-645). +func (m *MoverAdded) UnmarshalJSON(raw []byte) error { + type plain MoverAdded + var v plain + if err := json.Unmarshal(raw, &v); err != nil { + return err + } + named := 0 + for _, set := range []bool{v.From != "", v.Caller != "", v.TakeIn != 0} { + if set { + named++ + } + } + if named != 1 { + return errors.New("mover-added names exactly one of from, caller and take-in") + } + *m = MoverAdded(v) + return nil +} + +// UnmarshalJSON reads a place-unfinished input and refuses one naming both key and all +// (design 47 H2 H-A-644). +func (p *PlaceUnfinishedInput) UnmarshalJSON(raw []byte) error { + type plain PlaceUnfinishedInput + var v plain + if err := json.Unmarshal(raw, &v); err != nil { + return err + } + if v.All && v.Key != "" { + return errors.New("place-unfinished names exactly one of key and all") + } + *p = PlaceUnfinishedInput(v) + return nil +}