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) + } +}