From 82b0a0f26cfe299b51ad5c485fafb22edc1d6aed Mon Sep 17 00:00:00 2001 From: jochen Date: Wed, 25 Nov 2026 19:49:57 +0100 Subject: [PATCH] P3/P4/P5 whole steps: the tie, the carry once the failed mover passes and the tie's end (AC-P3), a kept revision gone and a key found at neither (AC-P4), a group placed with its failed mover ending failed again (AC-P5b), start adding to a running head (AC-P5c); the queue's whole test holds the view at its take-ins' revisions Builds: design 47 H2 H-A-619, H-A-594 (2), H-A-646, H-A-610, H-A-608, H-A-623, H-A-643, H-A-759 --- .../queue_integration_test.go | 28 +- .../unfinished_integration_test.go | 252 +++++++++++++++++- 2 files changed, 271 insertions(+), 9 deletions(-) diff --git a/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/queue_integration_test.go b/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/queue_integration_test.go index 28195f2d5..fe4ccce08 100644 --- a/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/queue_integration_test.go +++ b/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/queue_integration_test.go @@ -12,6 +12,7 @@ import ( "slices" "strings" "sync" + "sync/atomic" "testing" "time" @@ -102,7 +103,21 @@ func testTheQueueRunsPipelinesInTurn(t *testing.T) { } } answer("mesh.seat.mesh-catalog.call.registrations.*", catalog.RegistrationsAnswer{Registrations: regs}) - answer("mesh.seat.mesh-catalog.call.revision.*", catalog.RevisionAnswer{Revision: &catalog.CatalogRevision{Revision: 100, Kind: "trunk", Branch: "main", Source: 2}, Entries: entries}) + // The view holds the revision of the newest take-in (the head, H-A-594 (1), H-A-759); take says each revision before its take-in. + var newest atomic.Int64 + newest.Store(1) + if _, err := nc.Subscribe("mesh.seat.mesh-catalog.call.revision.*", func(m *nats.Msg) { + var q catalog.RevisionInput + _ = json.Unmarshal(m.Data, &q) + n := q.Revision + if n == 0 { + n = newest.Load() + } + raw, _ := json.Marshal(map[string]any{"result": catalog.RevisionAnswer{Revision: &catalog.CatalogRevision{Revision: n, Kind: "trunk", Branch: "main", Source: n}, Entries: entries}}) + _ = m.Respond(raw) + }); err != nil { + t.Fatal(err) + } answer("mesh.seat.mesh-hand-acts.call.hand-act.*", map[string]any{}) // The router of the operator's asks holds the seat operator-channel; its record of each ask is in its state asks. const router = "operator-router" @@ -227,6 +242,11 @@ func testTheQueueRunsPipelinesInTurn(t *testing.T) { for _, m := range movers { ev.Entries = append(ev.Entries, catalog.TakeInEntry{Module: m, Commit: "c1", Fingerprint: "src2:" + m}) } + newest.Store(source) + rev, _ := json.Marshal(catalog.CatalogRevisionEvent{V: 1, Revision: source, Kind: "trunk", Branch: "main", Source: source, CallKind: catalog.CatalogRevisionEventCallKindTakeIn}) + if _, err := js.Publish(ctx, catalog.SubjectCatalogRevision("main"), rev); err != nil { + t.Fatal(err) + } body, _ := json.Marshal(ev) if _, err := js.Publish(ctx, "mesh.mod.mesh-delivery-indexer.event.take-in.taken", body); err != nil { t.Fatal(err) @@ -429,8 +449,10 @@ func testTheQueueRunsPipelinesInTurn(t *testing.T) { if s.Outcome != seat.StepResultOutcomeCouldNotRun || s.Why != pipeline.UntakenWhy(builds.Seat) || s.Ended == nil || s.Ended.Sub(*build.Started) < time.Second { t.Fatalf("main.10's build = %+v, want could not run, its ask not taken, at its bound of 1s", s) } - if strings.Contains(logs.String(), "asked once more") { - t.Fatal("the untaken build's ask was asked once more for its bound") + for _, line := range strings.Split(logs.String(), "\n") { // the catalog view's own retries, as its revision moves, are no ask of a build + if strings.Contains(line, "asked once more") && !strings.Contains(line, catalog.VerbRevision) { + t.Fatalf("the untaken build's ask was asked once more for its bound: %s", line) + } } waitFor(t, ctx, logs, func() bool { e, err := findings.Get(ctx, "call."+build.Ask+".call-unanswered") diff --git a/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/unfinished_integration_test.go b/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/unfinished_integration_test.go index 80cfcaf55..813ae883a 100644 --- a/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/unfinished_integration_test.go +++ b/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/unfinished_integration_test.go @@ -30,7 +30,10 @@ func TestAMoverLeftUnfinishedIsPutInTheNextPipelineAndWanted(t *testing.T) { steps := catalog.StepStatuses{Lint: "bypass", Unit: "required", Integration: "bypass", Validate: "required", Composition: "required", Review: "bypass", Approval: "bypass"} regs := []catalog.Registration{{Module: "app", Branches: []string{"main"}, Origin: "o/app", Policy: catalog.Policy{Steps: steps}}, - {Module: "lib", Branches: []string{"main"}, Origin: "o/lib", Policy: catalog.Policy{Steps: steps}}} + {Module: "lib", Branches: []string{"main"}, Origin: "o/lib", Policy: catalog.Policy{Steps: steps}}, + {Module: "engine", Branches: []string{"main"}, Origin: "o/engine", Policy: catalog.Policy{Steps: steps}}, + {Module: "gitea", Branches: []string{"main"}, Origin: "o/gitea", Policy: catalog.Policy{Steps: steps}}, + {Module: "free", Branches: []string{"main"}, Origin: "o/free", Policy: catalog.Policy{Steps: steps}}} var newest atomic.Int64 newest.Store(1) w := startWhole(t, ctx, regs, func(in []byte) catalog.RevisionAnswer { @@ -40,15 +43,48 @@ func TestAMoverLeftUnfinishedIsPutInTheNextPipelineAndWanted(t *testing.T) { if n == 0 { n = newest.Load() } + if n == 99 { // a revision the catalog keeps no more + return catalog.RevisionAnswer{} + } lib := "l1" if n == 2 { lib = "l2" } - return catalog.RevisionAnswer{Revision: &catalog.CatalogRevision{Revision: n, Kind: "trunk", Branch: "main", Source: n + 2}, - Entries: []catalog.CatalogEntry{{Module: "app", Commit: "c1", Fp: "src2:aa"}, - {Module: "lib", Commit: lib, Fp: "src2:" + lib, Artifacts: []catalog.Artifact{{Ref: "lib:lib", Language: "go", Kind: "program"}}}, - {Module: "mesh-build-go", Commit: "c0", Fp: "src2:go", Acts: []catalog.ActingRule{{Step: "build", On: "go", Seat: nodebuildgo.Seat}}}}} + entries := []catalog.CatalogEntry{{Module: "app", Commit: "c1", Fp: "src2:aa"}, + {Module: "lib", Commit: lib, Fp: "src2:" + lib, Artifacts: []catalog.Artifact{{Ref: "lib:lib", Language: "go", Kind: "program"}}}, + {Module: "mesh-build-go", Commit: "c0", Fp: "src2:go", Acts: []catalog.ActingRule{{Step: "build", On: "go", Seat: nodebuildgo.Seat}}}} + if n >= 4 { + // engine, the module gitea's build waits for (an edge of kind 3): its fingerprint is e1 at 4 and 5, e2 at 6, e3 from 7. + engine, gitea, free := "e1", "g1", "f1" + switch { + case n >= 7: + engine, gitea = "e3", "g2" + case n == 6: + engine = "e2" + } + if n >= 8 { + free = "f2" + } + app := catalog.CatalogEntry{Module: "app", Commit: "c1", Fp: "src2:aa"} + if n >= 9 { + app.Fp = "src2:a9" + } + entries[0] = app + entries = append(entries, + catalog.CatalogEntry{Module: "engine", Commit: engine, Fp: "src2:" + engine, Artifacts: []catalog.Artifact{{Ref: "engine:engine", Language: "go", Kind: "program"}}}, + catalog.CatalogEntry{Module: "gitea", Commit: gitea, Fp: "src2:" + gitea, Edges: []catalog.Edge{{From: catalog.ArtifactRef("engine:engine"), Kind: 3}}}, + catalog.CatalogEntry{Module: "free", Commit: free, Fp: "src2:" + free}) + } + return catalog.RevisionAnswer{Revision: &catalog.CatalogRevision{Revision: n, Kind: "trunk", Branch: "main", Source: n + 2}, Entries: entries} }) + // The builds seat's published answers that nothing is published: gitea's wait on engine (an edge of kind 3) is met by engine's + // build step passing, as the runner hears it. + if _, err := w.nc.Subscribe("mesh.seat."+builds.Seat+".call."+builds.VerbPublished+".*", func(m *nats.Msg) { + raw, _ := json.Marshal(map[string]any{"result": builds.PublishedAnswer{}}) + _ = m.Respond(raw) + }); err != nil { + t.Fatal(err) + } ended := make(chan seat.PipelineEnded, 4) if _, err := w.nc.Subscribe("mesh.seat.mesh-pipeline-runner.event.pipeline-ended.>", func(m *nats.Msg) { var pe seat.PipelineEnded @@ -70,6 +106,7 @@ func TestAMoverLeftUnfinishedIsPutInTheNextPipelineAndWanted(t *testing.T) { } // answer ends every running step of key once, as its seat's holder says it: lib's unit fails when fail says so. answered := map[string]bool{} + failing, failStep := "lib", seat.StepResultStepUnit // the step that fails where answer is told to fail answer := func(key string, fail bool) func() bool { return func() bool { var p seat.Pipeline @@ -84,7 +121,7 @@ func TestAMoverLeftUnfinishedIsPutInTheNextPipelineAndWanted(t *testing.T) { answered[s.Ask+s.Module] = true m, _ := pipeline.MoverOf(p, s.Module) outcome := "passed" - if fail && s.Module == "lib" && s.Step == seat.StepResultStepUnit { + if fail && s.Module == failing && s.Step == failStep { outcome = "failed" } body := map[string]any{"v": 1, "id": s.Ask, "pipeline": key, "step": s.Step, "module": s.Module, "commit": m.Commit, @@ -119,6 +156,12 @@ func TestAMoverLeftUnfinishedIsPutInTheNextPipelineAndWanted(t *testing.T) { t.Fatalf("the state unfinished holds no main.app: %v", err) } + // design 47 H2 H-A-607 (2), H-A-619 (AC-P4): with no pipeline running, nothing starts to carry app; main.2 is started by the next + // take-in alone. + var none seat.Pipeline + if readPipeline(ctx, w.pipelines, "main.2", &none) { + t.Fatalf("main.2 was started with no take-in: the runner starts nothing to carry a mover\n%s", w.logs.String()) + } // The next take-in moves lib alone, at a new fingerprint: its pipeline carries app, whose composition is asked and passes. newest.Store(2) rev, _ := json.Marshal(catalog.CatalogRevisionEvent{V: 1, Revision: 2, Kind: "trunk", Branch: "main", Source: 4, CallKind: catalog.CatalogRevisionEventCallKindTakeIn}) @@ -182,4 +225,201 @@ func TestAMoverLeftUnfinishedIsPutInTheNextPipelineAndWanted(t *testing.T) { if !readPipeline(ctx, w.pipelines, "main.3", &third) || third.EndCount != 2 || len(ended) != 0 { t.Errorf("main.3 ended %d times and %d ends wait, want its second end and no third", third.EndCount, len(ended)) } + + // reach makes revision n the one the view holds, as the indexer's catalog-revision says it, then takes in its entries. + reach := func(n int64, entries ...catalog.TakeInEntry) { + newest.Store(n) + rev, _ := json.Marshal(catalog.CatalogRevisionEvent{V: 1, Revision: n, Kind: "trunk", Branch: "main", Source: n + 2, CallKind: catalog.CatalogRevisionEventCallKindTakeIn}) + if _, err := w.js.Publish(ctx, catalog.SubjectCatalogRevision("main"), rev); err != nil { + t.Fatal(err) + } + takeIn(n+2, n, entries...) + } + unfinishedEntry := func(key string) (pipeline.UnfinishedEntry, bool) { + var e pipeline.UnfinishedEntry + raw, err := unfinished.Get(ctx, key) + if err != nil || json.Unmarshal(raw.Value(), &e) != nil { + return e, false + } + return e, true + } + moves := func(key string, modules ...string) bool { + var p seat.Pipeline + if !readPipeline(ctx, w.pipelines, key, &p) { + return false + } + for _, m := range modules { + if !pipeline.Moves(p, m) { + return false + } + } + return true + } + + // design 47 H2 H-A-594 (2), H-A-646, H-A-610 (AC-P3), whole: engine fails in main.4 and gitea, whose build waits for engine's + // build step (an edge of kind 3), passes its steps; gitea is left unfinished and tied to engine. A take-in that moves free alone + // carries nothing: main.5 moves free, gitea stays in unfinished. + failing = "engine" + reach(4, catalog.TakeInEntry{Module: "engine", Commit: "e1", Fingerprint: "src2:e1"}, catalog.TakeInEntry{Module: "gitea", Commit: "g1", Fingerprint: "src2:g1"}) + waitFor(t, ctx, w.logs, answer("main.4", true)) + if pe := endOf(); pe.Pipeline != "main.4" || pe.Outcome != seat.PipelineEndedOutcomeFailed || !slices.Equal(pe.Unfinished, []string{"gitea"}) { + t.Fatalf("pipeline-ended = %s %s unfinished %v, want main.4 failed leaving gitea unfinished\n%s", pe.Pipeline, pe.Outcome, pe.Unfinished, w.logs.String()) + } + reach(5, catalog.TakeInEntry{Module: "free", Commit: "f1", Fingerprint: "src2:f1"}) + waitFor(t, ctx, w.logs, answer("main.5", false)) + if e, ok := unfinishedEntry("main.gitea"); !ok || e.Pipeline != "main.4" || e.CarriedBy != "" || !moves("main.5", "free") || moves("main.5", "gitea") { + t.Fatalf("main.gitea = %+v (held %t), main.5 moves gitea %t: want gitea tied to engine, kept in unfinished and not carried by main.5\n%s", e, ok, moves("main.5", "gitea"), w.logs.String()) + } + if pe := endOf(); pe.Pipeline != "main.5" || pe.Outcome != seat.PipelineEndedOutcomePassed { + t.Fatalf("main.5 ended %s %s, want passed\n%s", pe.Pipeline, pe.Outcome, w.logs.String()) + } + + // AC-P3: once engine passes, in the pipeline of its newer fingerprint, gitea is carried with it and wanted; its key goes. + failing = "" + reach(6, catalog.TakeInEntry{Module: "engine", Commit: "e2", Fingerprint: "src2:e2"}) + waitFor(t, ctx, w.logs, answer("main.6", false)) + if pe := endOf(); pe.Pipeline != "main.6" || pe.Outcome != seat.PipelineEndedOutcomePassed || !moves("main.6", "engine", "gitea") { + t.Fatalf("main.6 ended %s %s, moving gitea %t: want engine passed and gitea carried with it\n%s", pe.Pipeline, pe.Outcome, moves("main.6", "gitea"), w.logs.String()) + } + if _, ok := unfinishedEntry("main.gitea"); ok { + t.Error("main.gitea is still unfinished after main.6 passed") + } + + // design 47 H2 H-A-623 (AC-P5b), whole: engine fails again in main.7, leaving gitea tied to it; place-unfinished of gitea's key + // reopens main.7 for gitea with its failed engine, whose step fails again: main.7 ends failed a second time, leaving gitea. + placeKey := func(key string) seat.PlaceUnfinishedAnswer { + var placed seat.PlaceUnfinishedAnswer + waitFor(t, ctx, w.logs, func() bool { + raw, _ := json.Marshal(seat.PlaceUnfinishedInput{Key: key, Why: "the whole test"}) + m, err := w.nc.Request("mesh.seat."+seat.Seat+".call.place-unfinished.agent~dev", raw, 15*time.Second) + var reply struct { + Result json.RawMessage `json:"result"` + Error string `json:"error"` + } + if err != nil || json.Unmarshal(m.Data, &reply) != nil || strings.Contains(reply.Error, "not yet read") { + return false + } + if reply.Error != "" { + t.Fatalf("place-unfinished %s: %s", key, reply.Error) + } + return json.Unmarshal(reply.Result, &placed) == nil + }) + return placed + } + failing, failStep = "engine", seat.StepResultStepBuild // a build step is asked again by a plain ask; a test step joins a run of its own + reach(7, catalog.TakeInEntry{Module: "engine", Commit: "e3", Fingerprint: "src2:e3"}, catalog.TakeInEntry{Module: "gitea", Commit: "g2", Fingerprint: "src2:g2"}) + waitFor(t, ctx, w.logs, answer("main.7", true)) + if pe := endOf(); pe.Pipeline != "main.7" || pe.Outcome != seat.PipelineEndedOutcomeFailed || !slices.Equal(pe.Unfinished, []string{"gitea"}) { + t.Fatalf("pipeline-ended = %s %s unfinished %v, want main.7 failed leaving gitea unfinished\n%s", pe.Pipeline, pe.Outcome, pe.Unfinished, w.logs.String()) + } + if placed := placeKey("main.gitea"); len(placed.Placed) != 1 || placed.Placed[0].Pipeline != "main.7" { + t.Fatalf("place-unfinished of main.gitea = %+v, want it placed in main.7", placed) + } + waitFor(t, ctx, w.logs, answer("main.7", true)) + var seventh seat.Pipeline + if pe := endOf(); pe.Pipeline != "main.7" || pe.Outcome != seat.PipelineEndedOutcomeFailed || !slices.Equal(pe.Unfinished, []string{"gitea"}) || + !readPipeline(ctx, w.pipelines, "main.7", &seventh) || seventh.EndCount != 2 || !pipeline.Moves(seventh, "engine") { + t.Fatalf("main.7 ended again %s unfinished %v after %d ends, want failed with engine in its group, leaving gitea\n%s", pe.Outcome, pe.Unfinished, seventh.EndCount, w.logs.String()) + } + + // AC-P3, the tie's end: engine leaves the registrations (its registration-changed heard, the first view asked again); the next + // take-in's pipeline, main.8, carries gitea although engine failed and is not moved by it. + regs[2] = regs[4] // engine, the third registration, is replaced by a copy of free's: the answer no longer names it + gone, _ := json.Marshal(catalog.RegistrationChangedEvent{V: 1, Module: "engine", Version: 9, Moved: []string{}, Warrant: "the whole test"}) + if _, err := w.js.Publish(ctx, "mesh.seat.mesh-catalog.event.registration-changed.engine", gone); err != nil { + t.Fatal(err) + } + waitFor(t, ctx, w.logs, func() bool { // the registrations' picture holds four keys once the first view is asked again + kv, err := w.js.KeyValue(ctx, "mesh-delivery-pipeline_first-views") + if err != nil { + return false + } + e, err := kv.Get(ctx, "mesh-catalog.registrations") + var view struct { + Keys int `json:"keys"` + } + return err == nil && json.Unmarshal(e.Value(), &view) == nil && view.Keys == len(regs)-1 + }) + failing, failStep = "", "" + reach(8, catalog.TakeInEntry{Module: "free", Commit: "f2", Fingerprint: "src2:f2"}) + waitFor(t, ctx, w.logs, answer("main.8", false)) + if pe := endOf(); pe.Pipeline != "main.8" || pe.Outcome != seat.PipelineEndedOutcomePassed || !moves("main.8", "free", "gitea") { + t.Fatalf("main.8 ended %s %s, moving gitea %t: want gitea carried although engine failed and left the registrations\n%s", pe.Pipeline, pe.Outcome, moves("main.8", "gitea"), w.logs.String()) + } + if _, ok := unfinishedEntry("main.gitea"); ok { + t.Error("main.gitea is still unfinished after main.8 passed") + } + + // design 47 H2 H-A-608 (AC-P4), whole: free's key names revision 99, which the catalog keeps no more; the take-in of revision 9 + // reads it at the head's revision, where free holds the key's fingerprint, and carries it; ghost's fingerprint is held at neither + // revision, so its key is dropped and the journal names the fingerprint and the revisions looked at. + for key, entry := range map[string]string{ + "main.free": `{"fingerprint":"src2:f2","revision":99,"pipeline":"main.99","outcome":"failed"}`, + "main.ghost": `{"fingerprint":"src2:zz","revision":99,"pipeline":"main.99","outcome":"failed"}`, + } { + if _, err := unfinished.Put(ctx, key, []byte(entry)); err != nil { + t.Fatal(err) + } + } + reach(9, catalog.TakeInEntry{Module: "app", Commit: "c1", Fingerprint: "src2:a9"}) + waitFor(t, ctx, w.logs, answer("main.9", false)) + if pe := endOf(); pe.Pipeline != "main.9" || pe.Outcome != seat.PipelineEndedOutcomePassed || !moves("main.9", "app", "free") { + t.Fatalf("main.9 ended %s %s, moving free %t: want free read at the head's revision and carried\n%s", pe.Pipeline, pe.Outcome, moves("main.9", "free"), w.logs.String()) + } + if _, ok := unfinishedEntry("main.ghost"); ok || !strings.Contains(w.logs.String(), "ghost is no longer unfinished at fingerprint src2:zz: its kept revision 99 is gone, the head's revision 9 of main holds it at") { + t.Errorf("main.ghost is kept, or the journal does not name its fingerprint and the revisions looked at:\n%s", w.logs.String()) + } + + // design 47 H2 H-A-571, H-A-643 (AC-P5c), whole: while the head's pipeline main.10 runs, start of free and lib, which it does not + // carry, adds both to it, each said by mover-added with the caller; no `.again.` pipeline is keyed. + added := make(chan seat.MoverAdded, 4) + if _, err := w.nc.Subscribe("mesh.seat.mesh-pipeline-runner.event.mover-added.>", func(m *nats.Msg) { + var ev seat.MoverAdded + if json.Unmarshal(m.Data, &ev) == nil { + added <- ev + } + }); err != nil { + t.Fatal(err) + } + reach(10, catalog.TakeInEntry{Module: "app", Commit: "c1", Fingerprint: "src2:a9"}) + waitFor(t, ctx, w.logs, func() bool { // its steps are placed once the view holds revision 10, the head start reads + return strings.Contains(w.logs.String(), "main.10 app build asked") + }) + var started seat.StartAnswer + waitFor(t, ctx, w.logs, func() bool { + raw, _ := json.Marshal(seat.StartInput{Branch: "main", Modules: []string{"free", "lib"}, Why: "the whole test"}) + m, err := w.nc.Request("mesh.seat."+seat.Seat+".call.start.agent~dev", raw, 15*time.Second) + var reply struct { + Result json.RawMessage `json:"result"` + Error string `json:"error"` + } + if err != nil || json.Unmarshal(m.Data, &reply) != nil || strings.Contains(reply.Error, "not yet") { + return false + } + if reply.Error != "" { + t.Fatalf("start: %s", reply.Error) + } + return json.Unmarshal(reply.Result, &started) == nil + }) + if started.Pipeline != "main.10" || !moves("main.10", "app", "free", "lib") || len(added) != 2 { + t.Fatalf("start = %+v, main.10 moves free and lib %t, %d mover-added said, want both added to main.10 and said\n%s", started, moves("main.10", "free", "lib"), len(added), w.logs.String()) + } + for range 2 { + if ev := <-added; ev.Pipeline != "main.10" || ev.Caller == "" || ev.From != "" { + t.Errorf("mover-added = %+v, want main.10 with the caller of start", ev) + } + } + keysOf, err := w.pipelines.Keys(ctx) + if err != nil { + t.Fatal(err) + } + for _, k := range keysOf { + if strings.Contains(k, ".again.") { + t.Errorf("start keyed the pipeline %s", k) + } + } + waitFor(t, ctx, w.logs, answer("main.10", false)) + if pe := endOf(); pe.Pipeline != "main.10" || pe.Outcome != seat.PipelineEndedOutcomePassed { + t.Errorf("main.10 ended %s %s, want passed with its added movers\n%s", pe.Pipeline, pe.Outcome, w.logs.String()) + } }