GT1 fix: a wanted with no want-revision keeps the held revision; rows for a repeated wanted and an again pipeline's running

Fixes review r1 part 4 items 2 and 3 (H-A-865, AC-832g, AC-824m).
Builds: design 47 H2b §832 5.
This commit is contained in:
2026-11-27 03:51:43 +01:00
parent 254fc645fd
commit 4d2f1ea1f3
2 changed files with 32 additions and 3 deletions
@@ -326,12 +326,20 @@ func (h *Holder) wantWritten(w wants.WantedEvent) error {
if r == nil || r.Ended != nil {
return nil
}
// A body with no want-revision is the earlier form: it is applied and leaves the held revision as it is (H-A-865).
held := w.WantRevision
for _, e := range r.Entries {
if e.Module == w.Module && e.Node == w.Node && w.WantRevision > 0 && e.WantRevision > w.WantRevision {
if e.Module != w.Module || e.Node != w.Node {
continue
}
if w.WantRevision > 0 && e.WantRevision > w.WantRevision {
return nil
}
if w.WantRevision == 0 && e.WantRevision > held {
held = e.WantRevision
}
}
if err := h.Records.AddEntry(r, RecordEntry{Module: w.Module, Fingerprint: w.Fp, Node: w.Node, WantRevision: w.WantRevision}); err != nil {
if err := h.Records.AddEntry(r, RecordEntry{Module: w.Module, Fingerprint: w.Fp, Node: w.Node, WantRevision: held}); err != nil {
return err
}
at := h.Now().UTC()
@@ -118,12 +118,33 @@ func TestARecordFollowsItsPipelineToTheMachines(t *testing.T) {
if _, ok := r.Entries[EntryKey("app", "f2", "ace")]; ok {
t.Fatal("a want at want-revision 8, below the 9 held, is an entry")
}
// A wanted of the earlier form (no want-revision) leaves the held 9 as it is, so a wanted at 8 changes nothing still
// (H-A-865); and a body said again under a new id adds no ledger operation (1984/AC-832g).
ledger := h.Records.Ledger.(*ledgerFake)
hear(t, c, "mesh-wants.wanted.x.app", "", `{"v":1,"node":"ace","module":"app","fp":"f","pipeline":"main.1","source":1,"revision":12}`)
hear(t, c, "mesh-wants.wanted.x.app", "", `{"v":1,"node":"ace","module":"app","fp":"f3","pipeline":"main.1","source":1,"revision":12,"want-revision":8}`)
if e := r.Entries[EntryKey("app", "f", "ace")]; e.WantRevision != 9 {
t.Fatalf("the entry is %+v: a wanted with no want-revision keeps the 9 held", e)
}
if _, ok := r.Entries[EntryKey("app", "f3", "ace")]; ok {
t.Fatal("a want at want-revision 8 is an entry after a wanted of the earlier form")
}
before := len(ledger.history)
again := `{"v":1,"node":"ace","module":"app","fp":"f","pipeline":"main.1","source":1,"revision":12,"want-revision":9}`
for _, id := range []string{"id-1", "id-2"} {
if err := c.Hear(stdio.Envelope{Key: "mesh-wants.wanted.x.app", Body: json.RawMessage(again), Headers: map[string]string{"Nats-Msg-Id": id}}); err != nil {
t.Fatal(err)
}
}
if len(ledger.history) != before {
t.Fatalf("a repeated wanted wrote %v", ledger.history[before:])
}
hear(t, c, "node-engine.running.ace.app", "ace", `{"v":1,"at":"2026-11-20T03:05:00Z","module":"app","node":"ace","fingerprint":"f","healthy":true}`)
hear(t, c, "node-engine.running.g14.app", "g14", `{"v":1,"at":"2026-11-20T03:05:00Z","module":"app","node":"g14","fingerprint":"f","healthy":true}`)
if o := r.Outcomes[OutcomeKey("app", "f", "g14", StepRunning)]; o.Outcome != OutcomeRunning || r.Ended != nil || len(*ended) != 0 {
t.Fatalf("running is %+v and the record ended %+v: running ends nothing", o, r.Ended)
}
hear(t, c, "mesh-wants.pipeline-wanted.main.1", "", `{"v":1,"pipeline":"main.1","branch":"main","source":1,"outcome":"running"}`)
hear(t, c, "mesh-wants.pipeline-wanted.main.1", "", `{"v":1,"pipeline":"main.1.again.2","branch":"main","source":1,"outcome":"running"}`) // an again pipeline's, on its source's subject (AC-824m)
if r.Ended == nil || r.Ended.Why != WhyAllRun || len(*ended) != 1 {
t.Fatalf("the record ended %+v, said %v", r.Ended, *ended)
}