R16: a take-in.taken of the old form is refused by the strict decode

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
This commit is contained in:
2026-11-20 04:56:31 +01:00
parent c9fd571e8e
commit 79e4688744
3 changed files with 39 additions and 4 deletions
@@ -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)
@@ -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 `<branch>.<source>` 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
@@ -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)
}
}