From 79e468874472c6312810f347fdd1f9933ad28867 Mon Sep 17 00:00:00 2001 From: jochen Date: Fri, 20 Nov 2026 03:52:03 +0100 Subject: [PATCH] R16: a take-in.taken of the old form is refused by the strict decode MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The runner's take-in handler decodes take-in.taken strictly by the seat's contract: an event missing a field its new form requires (branch, source, call) is refused, said in one journal line naming the subject and what it lacks, and ended. The cancel reads no old pipeline (they are dropped at the clean state). Unit tests 84 to 85. Builds: design 47 H §765; lead answers H-A-58, H-A-98 Claude-Session: https://claude.ai/code/session_01JG73KHUnBze48rdua8u2sy --- .../cmd/mesh-delivery-pipeline/start.go | 9 ++++---- .../internal/pipeline/start.go | 21 +++++++++++++++++++ .../internal/pipeline/start_test.go | 13 ++++++++++++ 3 files changed, 39 insertions(+), 4 deletions(-) diff --git a/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/start.go b/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/start.go index 9b63d931..008b8d4d 100644 --- a/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/start.go +++ b/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/start.go @@ -56,10 +56,11 @@ func hearPublished(hub handlers, starter *pipeline.Starter, v *pipeline.Views, l // once it is written, and heard again when a write failed, so the key already written starts nothing twice. func hearTakenIn(hub handlers, starter *pipeline.Starter, v *pipeline.Views, logf func(string, ...any)) error { return hub.Handle(pipeline.TakenInSubject, func(m jetstream.Msg) { - var ev catalog.TakeInTaken - if err := json.Unmarshal(m.Data(), &ev); err != nil { - logf("%s is no take-in.taken: %v", m.Subject(), err) - _ = m.Ack() + // An event of the old form is refused by the contract's strict decode, said in one journal line and ended (§765, H-A-98). + ev, err := pipeline.DecodeTakenIn(m.Data()) + if err != nil { + logf("%s is refused: %v", m.Subject(), err) + _ = m.Term() return } n, err := starter.TakenIn(ev, v.View) diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/start.go b/modules/mesh-delivery-pipeline/internal/pipeline/start.go index d0e46489..6ba88aae 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/start.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/start.go @@ -656,6 +656,27 @@ func (s *Starter) logf(format string, args ...any) { // module (§7), so the bus's grant from the manifest's `consumes` says which one it hears (§54). const TakenInSubject = "mesh.mod.*.event.take-in.taken" +// DecodeTakenIn decodes a take-in.taken strictly by its contract (design 47 H §765, H-A-58, H-A-98): an event of the old +// form, one missing a field its new form requires (branch, source, call), is refused, naming what it lacks. +func DecodeTakenIn(raw []byte) (catalog.TakeInTaken, error) { + var fields map[string]json.RawMessage + if err := json.Unmarshal(raw, &fields); err != nil { + return catalog.TakeInTaken{}, err + } + var missing []string + for _, f := range []string{"branch", "source", "call"} { + if v, ok := fields[f]; !ok || string(v) == "null" || string(v) == `""` { + missing = append(missing, f) + } + } + if len(missing) > 0 { + return catalog.TakeInTaken{}, fmt.Errorf("a take-in.taken of the old form: it names no %s", strings.Join(missing, ", ")) + } + var ev catalog.TakeInTaken + err := json.Unmarshal(raw, &ev) + return ev, err +} + // TakenIn starts, for a take-in.taken with entries, exactly one pipeline keyed `.` by compare-and-set on its // absence, whose movers are the event's entries, each with its tier (design 47 H §746). A take-in with no entries, or a // skip, starts nothing; a second hearing writes nothing. view is the catalog half of the event's branch, read for the diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/start_test.go b/modules/mesh-delivery-pipeline/internal/pipeline/start_test.go index 21f7ad93..edb8d2fa 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/start_test.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/start_test.go @@ -303,3 +303,16 @@ func TestTakenInStartsOnlyItsEntries(t *testing.T) { t.Errorf("main.9 = %+v (%v), want the one mover moved: batched is not named by the take-in", p, err) } } + +// R16/AC1 (design 47 H §765, H-A-58, H-A-98): a take-in.taken of the old form, with no call (or no branch or source), is +// refused by the strict decode, naming what it lacks; one of the new form is read whole. +func TestATakeInOfTheOldFormIsRefused(t *testing.T) { + old := `{"key":"m.1","kind":"taken","branch":"main","source":3,"entries":[{"module":"app","commit":"c1","fingerprint":"src2:aa","pull":7}]}` + if _, err := DecodeTakenIn([]byte(old)); err == nil || !strings.Contains(err.Error(), "call") { + t.Errorf("the old form decoded (%v), want refused naming call", err) + } + ev, err := DecodeTakenIn([]byte(`{"branch":"main","source":3,"call":"0123456789abcdef","revision":4,"entries":[{"module":"app","commit":"c1","fingerprint":"src2:aa","repository":"o/app"}]}`)) + if err != nil || ev.Call != "0123456789abcdef" || len(ev.Entries) != 1 { + t.Errorf("the new form = %+v (%v)", ev, err) + } +}