From 3a647a8e2d900768c2c05d8cfb09ecabcd83f763 Mon Sep 17 00:00:00 2001 From: jochen Date: Sun, 22 Nov 2026 00:52:34 +0100 Subject: [PATCH] B3: an answered build ask is one journal line naming its ask MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The line a build step's finish wrote named no ask, so an answer could not be matched to the ask the runner put. BuildStep now takes the ask's id and its finish writes "answered ". Builds: design 47 H2 §792 --- .../cmd/mesh-delivery-builder/stepqueue.go | 5 +-- .../internal/build/step.go | 20 ++++----- .../internal/build/step_test.go | 43 ++++++++++--------- 3 files changed, 32 insertions(+), 36 deletions(-) diff --git a/modules/mesh-delivery-builder/cmd/mesh-delivery-builder/stepqueue.go b/modules/mesh-delivery-builder/cmd/mesh-delivery-builder/stepqueue.go index 7186ba673..9b1640d1f 100644 --- a/modules/mesh-delivery-builder/cmd/mesh-delivery-builder/stepqueue.go +++ b/modules/mesh-delivery-builder/cmd/mesh-delivery-builder/stepqueue.go @@ -39,7 +39,7 @@ type askTaker interface { // stepBuilder is build.Builder's BuildStep. type stepBuilder interface { - BuildStep(ctx context.Context, run meshbuilds.StepRun) meshbuilds.StepEnded + BuildStep(ctx context.Context, ask string, run meshbuilds.StepRun) meshbuilds.StepEnded } // queueMsg is what the queue reads of a message pulled from the seat's work queue (jetstream.Msg). @@ -141,7 +141,7 @@ func (q *stepQueue) build(ctx context.Context, m queueMsg, id string, ra *runnin tick = t.C } done := make(chan meshbuilds.StepEnded, 1) - go func() { done <- q.builder.BuildStep(ctx, ra.run) }() + go func() { done <- q.builder.BuildStep(ctx, id, ra.run) }() var end meshbuilds.StepEnded for waiting := true; waiting; { select { @@ -151,7 +151,6 @@ func (q *stepQueue) build(ctx context.Context, m queueMsg, id string, ra *runnin _ = m.InProgress() } } - end.ID = id if err := q.say(context.WithoutCancel(ctx), meshbuilds.SubjectStepEnded(q.node), id, end); err != nil { q.logf("saying the end of the build step %s: %v; the ask is handed again", id, err) _ = m.Nak() diff --git a/modules/mesh-delivery-builder/internal/build/step.go b/modules/mesh-delivery-builder/internal/build/step.go index dd3df76ec..8002e4712 100644 --- a/modules/mesh-delivery-builder/internal/build/step.go +++ b/modules/mesh-delivery-builder/internal/build/step.go @@ -17,15 +17,15 @@ import ( // fingerprint (the existing claim, plan and lanes) and answers the step's end. A build is per fingerprint, so no pull request // number is needed, and the builder follows no candidate. -// BuildStep builds the entries of one step ask and answers its end: passed when every entry's build is done, failed when one -// failed (said), could not run when an entry could not be read, nothing to run for an ask naming none. The ask's id and the node -// are the caller's to set. -func (b *Builder) BuildStep(ctx context.Context, run meshbuilds.StepRun) meshbuilds.StepEnded { +// BuildStep builds the entries of the step ask ask and answers its end: passed when every entry's build is done, failed when +// one failed (said), could not run when an entry could not be read, nothing to run for an ask naming none. The node is the +// caller's to set. +func (b *Builder) BuildStep(ctx context.Context, ask string, run meshbuilds.StepRun) meshbuilds.StepEnded { b.init() started := b.now() - end := meshbuilds.StepEnded{V: 1, Pipeline: run.Pipeline, Step: meshbuilds.StepEndedStepBuild, Rerun: run.Rerun, By: run.By, Entries: run.Entries, Node: b.Node, Started: &started} - // finish is the one place the ask is answered: its line names the pipeline, the movers, the step and the outcome, with - // the words of an end that did not pass (H-A-320 (1), H-A-333). + end := meshbuilds.StepEnded{V: 1, ID: ask, Pipeline: run.Pipeline, Step: meshbuilds.StepEndedStepBuild, Rerun: run.Rerun, By: run.By, Entries: run.Entries, Node: b.Node, Started: &started} + // finish is the one place the ask is answered: one journal line, "answered " + // (design 47 H2 §792; H-A-320 (1), H-A-333). finish := func(outcome, said string) meshbuilds.StepEnded { at := b.now() end.Ended, end.Outcome, end.Said = &at, outcome, said @@ -37,11 +37,7 @@ func (b *Builder) BuildStep(ctx context.Context, run meshbuilds.StepRun) meshbui if mv == "" { mv = "-" } - if said != "" { - b.logf("%s %s %s step answered %s: %s", run.Pipeline, mv, end.Step, outcome, said) - } else { - b.logf("%s %s %s step answered %s", run.Pipeline, mv, end.Step, outcome) - } + b.logf("answered %s %s %s %s %s", ask, run.Pipeline, mv, end.Step, outcome) return end } if len(run.Entries) == 0 { diff --git a/modules/mesh-delivery-builder/internal/build/step_test.go b/modules/mesh-delivery-builder/internal/build/step_test.go index 9c54fb55e..2025f3988 100644 --- a/modules/mesh-delivery-builder/internal/build/step_test.go +++ b/modules/mesh-delivery-builder/internal/build/step_test.go @@ -34,13 +34,15 @@ func TestABuildStepAnswersItsEnd(t *testing.T) { } return meshcatalog.CatalogEntry{}, errors.New("not found") } + asked := 0 ask := func(entries ...meshbuilds.BuildEntry) meshbuilds.StepEnded { - return r.b.BuildStep(t.Context(), meshbuilds.StepRun{Pipeline: "main.1.m", Step: meshbuilds.StepRunStepBuild, Entries: entries}) + asked++ + return r.b.BuildStep(t.Context(), fmt.Sprintf("ask%d", asked), meshbuilds.StepRun{Pipeline: "main.1.m", Step: meshbuilds.StepRunStepBuild, Entries: entries}) } - // Every answer is one journal line naming the pipeline, the movers, the step and the outcome (H-A-320 (1), H-A-333). + // Every answer is one journal line, "answered " (§792; H-A-320 (1), H-A-333). var answers []string r.b.Logf = func(f string, a ...any) { - if l := fmt.Sprintf(f, a...); strings.Contains(l, " step answered ") { + if l := fmt.Sprintf(f, a...); strings.HasPrefix(l, "answered ") { answers = append(answers, l) } } @@ -50,8 +52,7 @@ func TestABuildStepAnswersItsEnd(t *testing.T) { if end := ask(meshbuilds.BuildEntry{Module: "m", Fingerprint: "src2:" + strings.Repeat("2", 64)}); end.Outcome != meshbuilds.StepEndedOutcomeCouldNotRun || !strings.Contains(end.Said, "cannot be read") { t.Errorf("an entry the seat does not hold: %+v", end) } - if len(answers) != 2 || answers[0] != "main.1.m - build step answered nothing to run: the ask names no entry" || - !strings.HasPrefix(answers[1], "main.1.m m build step answered could not run: the entry m at ") { + if want := []string{"answered ask1 main.1.m - build nothing to run", "answered ask2 main.1.m m build could not run"}; !reflect.DeepEqual(answers, want) { t.Errorf("the answers journaled %q, want one line per answer", answers) } if end := ask(meshbuilds.BuildEntry{Module: "m", Fingerprint: fp1, Commit: "other"}); end.Outcome != meshbuilds.StepEndedOutcomeCouldNotRun { @@ -128,7 +129,7 @@ func TestABuildStepPassesAReservingBuildOnlyWithItsReservedVersion(t *testing.T) r.b.StepEntry = func(context.Context, string) (meshcatalog.CatalogEntry, error) { return meshcatalog.CatalogEntry{Module: "m", Repository: "novox/m", Commit: "c1", Fp: fp1, ManifestDigest: digestOf(c.unreadable), Path: "modules/m"}, nil } - end := r.b.BuildStep(t.Context(), meshbuilds.StepRun{Pipeline: "main.1.m", Step: meshbuilds.StepRunStepBuild, Entries: []meshbuilds.BuildEntry{{Module: "m", Fingerprint: fp1}}}) + end := r.b.BuildStep(t.Context(), "a1", meshbuilds.StepRun{Pipeline: "main.1.m", Step: meshbuilds.StepRunStepBuild, Entries: []meshbuilds.BuildEntry{{Module: "m", Fingerprint: fp1}}}) if end.Outcome != c.want || !strings.Contains(end.Said, c.said) || (c.want == meshbuilds.StepEndedOutcomeFailed && strings.Contains(end.Said, "builder_reserve_done") == c.takenOver) { t.Errorf("end = %+v, want %s saying %q", end, c.want, c.said) } @@ -199,7 +200,7 @@ func aPackageWithNoPinWaitsForItsRelease(t *testing.T) { r.b.PackagePublished(unpinnedX, "0.1.4-feat-x.2") // a group's tagged version: no pin ended := make(chan meshbuilds.StepEnded, 1) go func() { - ended <- r.b.BuildStep(t.Context(), meshbuilds.StepRun{Pipeline: "main.9.m", Step: meshbuilds.StepRunStepBuild, Branch: "main", Source: 41, + ended <- r.b.BuildStep(t.Context(), "a1", meshbuilds.StepRun{Pipeline: "main.9.m", Step: meshbuilds.StepRunStepBuild, Branch: "main", Source: 41, Entries: []meshbuilds.BuildEntry{{Module: "m", Fingerprint: fp1}}}) }() awaitWaiting(t, waiting, ended) @@ -225,7 +226,7 @@ func aPackageWithNoPinWaitsForItsRelease(t *testing.T) { } // A done key reports the pins it keeps it was built with, never the newer one a publish gives now (H-A-207). r.b.PackagePublished(unpinnedX, "v0.1.5") - again := r.b.BuildStep(t.Context(), meshbuilds.StepRun{Pipeline: "main.9.m", Step: meshbuilds.StepRunStepBuild, Branch: "main", Source: 41, + again := r.b.BuildStep(t.Context(), "a1", meshbuilds.StepRun{Pipeline: "main.9.m", Step: meshbuilds.StepRunStepBuild, Branch: "main", Source: 41, Entries: []meshbuilds.BuildEntry{{Module: "m", Fingerprint: fp1}}}) if again.Outcome != meshbuilds.StepEndedOutcomePassed || again.Packages[unpinnedX] != "v0.1.3" { t.Errorf("the done key's end = %+v; want passed reporting x at v0.1.3, as built", again) @@ -247,7 +248,7 @@ func aPackageWithNoPinWaitsForItsRelease(t *testing.T) { t.Fatal(err) } r.st.vals[r.key] = raw - if bare := r.b.BuildStep(t.Context(), meshbuilds.StepRun{Pipeline: "main.9.m", Step: meshbuilds.StepRunStepBuild, Branch: "main", Source: 41, + if bare := r.b.BuildStep(t.Context(), "a1", meshbuilds.StepRun{Pipeline: "main.9.m", Step: meshbuilds.StepRunStepBuild, Branch: "main", Source: 41, Entries: []meshbuilds.BuildEntry{{Module: "m", Fingerprint: fp1}}}); len(bare.Packages) != 0 { t.Errorf("a done key keeping no pins reported %v; want none", bare.Packages) } @@ -256,7 +257,7 @@ func aPackageWithNoPinWaitsForItsRelease(t *testing.T) { func aPackageWithNoReleaseFailsPastItsBound(t *testing.T) { r, _, _ := unpinnedRig(t) r.b.PackageWait = time.Nanosecond - end := r.b.BuildStep(t.Context(), meshbuilds.StepRun{Pipeline: "main.9.m", Step: meshbuilds.StepRunStepBuild, Branch: "main", Source: 41, + end := r.b.BuildStep(t.Context(), "a1", meshbuilds.StepRun{Pipeline: "main.9.m", Step: meshbuilds.StepRunStepBuild, Branch: "main", Source: 41, Entries: []meshbuilds.BuildEntry{{Module: "m", Fingerprint: fp1}}}) r.b.Wait() if _, built := r.st.vals[r.key]; end.Outcome != meshbuilds.StepEndedOutcomeFailed || built || @@ -265,7 +266,7 @@ func aPackageWithNoReleaseFailsPastItsBound(t *testing.T) { } // A publish heard before gives the pin at once. r.b.PackagePublished(unpinnedX, "v0.1.2") - if end := r.b.BuildStep(t.Context(), meshbuilds.StepRun{Pipeline: "main.9.m", Step: meshbuilds.StepRunStepBuild, Branch: "main", Source: 41, + if end := r.b.BuildStep(t.Context(), "a1", meshbuilds.StepRun{Pipeline: "main.9.m", Step: meshbuilds.StepRunStepBuild, Branch: "main", Source: 41, Entries: []meshbuilds.BuildEntry{{Module: "m", Fingerprint: fp1}}}); strings.Contains(end.Said, "no released version") { t.Errorf("a publish heard did not pin the package: %+v", end) } @@ -281,7 +282,7 @@ func theSeatsVersionsPinBeforeTheWait(t *testing.T) { read = append(read, path) return []string{"0.2.1", "0.1.9", "0.1.8"}, nil // newest first } - end := r.b.BuildStep(t.Context(), meshbuilds.StepRun{Pipeline: "main.9.m", Step: meshbuilds.StepRunStepBuild, Branch: "main", Source: 41, + end := r.b.BuildStep(t.Context(), "a1", meshbuilds.StepRun{Pipeline: "main.9.m", Step: meshbuilds.StepRunStepBuild, Branch: "main", Source: 41, Entries: []meshbuilds.BuildEntry{{Module: "m", Fingerprint: fp1}}}) r.b.Wait() asks := r.asks.Asks() @@ -292,7 +293,7 @@ func theSeatsVersionsPinBeforeTheWait(t *testing.T) { r2.b.PublishedVersions = func(context.Context, string) ([]string, error) { return []string{"0.2.1"}, nil } ended := make(chan meshbuilds.StepEnded, 1) go func() { - ended <- r2.b.BuildStep(t.Context(), meshbuilds.StepRun{Pipeline: "main.9.m", Step: meshbuilds.StepRunStepBuild, Branch: "main", Source: 41, + ended <- r2.b.BuildStep(t.Context(), "a1", meshbuilds.StepRun{Pipeline: "main.9.m", Step: meshbuilds.StepRunStepBuild, Branch: "main", Source: 41, Entries: []meshbuilds.BuildEntry{{Module: "m", Fingerprint: fp1}}}) }() awaitWaiting(t, waiting, ended) @@ -345,7 +346,7 @@ func aRevisionHeldWakesTheAsk(t *testing.T) { r.b.Wait() ended := make(chan meshbuilds.StepEnded, 1) go func() { - ended <- r.b.BuildStep(t.Context(), meshbuilds.StepRun{Pipeline: "main.8.m", Step: meshbuilds.StepRunStepBuild, Branch: "main", Revision: 8, Source: 41, + ended <- r.b.BuildStep(t.Context(), "a1", meshbuilds.StepRun{Pipeline: "main.8.m", Step: meshbuilds.StepRunStepBuild, Branch: "main", Revision: 8, Source: 41, Entries: []meshbuilds.BuildEntry{{Module: "m", Fingerprint: fp1}}}) }() select { @@ -398,7 +399,7 @@ func aStepAskWaitsForItsRevision(t *testing.T) { } ended := make(chan meshbuilds.StepEnded, 1) go func() { - ended <- r.b.BuildStep(t.Context(), meshbuilds.StepRun{Pipeline: "main.7.m", Step: meshbuilds.StepRunStepBuild, Branch: "main", Revision: 7, Source: 41, + ended <- r.b.BuildStep(t.Context(), "a1", meshbuilds.StepRun{Pipeline: "main.7.m", Step: meshbuilds.StepRunStepBuild, Branch: "main", Revision: 7, Source: 41, Entries: []meshbuilds.BuildEntry{{Module: "m", Fingerprint: fp1}}}) }() select { @@ -442,7 +443,7 @@ func anOlderKeptRevisionIsReadByNumber(t *testing.T) { } run := meshbuilds.StepRun{Pipeline: "main.47.m", Step: meshbuilds.StepRunStepBuild, Branch: "main", Revision: 47, Source: 45, Entries: []meshbuilds.BuildEntry{{Module: "m", Fingerprint: fp1}}} - end := r.b.BuildStep(t.Context(), run) + end := r.b.BuildStep(t.Context(), "a1", run) r.b.Wait() if end.Outcome != meshbuilds.StepEndedOutcomePassed || !slices.Equal(read, []string{"main 47"}) { t.Errorf("end = %+v, kept revisions read %v; want passed, revision 47 of main read once", end, read) @@ -457,7 +458,7 @@ func anOlderKeptRevisionIsReadByNumber(t *testing.T) { r2.b.KeptRevision = func(context.Context, string, int64) (int64, map[string]string, error) { return 45, map[string]string{"m": "src2:other"}, nil } - if end := r2.b.BuildStep(t.Context(), run); end.Outcome != meshbuilds.StepEndedOutcomeFailed || !strings.Contains(end.Said, "names m at \"src2:other\"") { + if end := r2.b.BuildStep(t.Context(), "a1", run); end.Outcome != meshbuilds.StepEndedOutcomeFailed || !strings.Contains(end.Said, "names m at \"src2:other\"") { t.Errorf("end = %+v; want failed naming the fingerprint the kept revision names", end) } // H-A-222: an ask of the very source the picture holds, whose entries the picture no longer names (a re-pin kept revision 48 @@ -472,7 +473,7 @@ func anOlderKeptRevisionIsReadByNumber(t *testing.T) { } same := meshbuilds.StepRun{Pipeline: "main.48.m", Step: meshbuilds.StepRunStepBuild, Branch: "main", Revision: 48, Source: 46, Entries: []meshbuilds.BuildEntry{{Module: "m", Fingerprint: fp1}}} - end3 := r3.b.BuildStep(t.Context(), same) + end3 := r3.b.BuildStep(t.Context(), "a1", same) r3.b.Wait() if end3.Outcome != meshbuilds.StepEndedOutcomePassed || !slices.Equal(read3, []string{"main 48"}) || len(res3.sources) != 1 || res3.sources[0].CatalogRevision != 48 { t.Errorf("end = %+v, kept revisions read %v, reserved %+v; want passed, revision 48 of main read once and reserved at it", end3, read3, res3.sources) @@ -493,7 +494,7 @@ func anOlderKeptRevisionIsReadByNumber(t *testing.T) { rc.b.KeptRevision = func(context.Context, string, int64) (int64, map[string]string, error) { return c.source, map[string]string{"m": c.fp}, nil } - end := rc.b.BuildStep(t.Context(), same) + end := rc.b.BuildStep(t.Context(), "a1", same) rc.b.Wait() if end.Outcome != meshbuilds.StepEndedOutcomeFailed || !strings.Contains(end.Said, c.said) || len(resc.sources) != 0 { t.Errorf("%s: end = %+v, reserved %+v; want failed at once saying %q, nothing reserved", c.name, end, resc.sources, c.said) @@ -506,14 +507,14 @@ func aStepAskPastItsRevisionBoundFails(t *testing.T) { held.Store(40) r, res, _ := revisionRig(t, &held, make(chan struct{}, 1)) r.b.RevisionWait = time.Nanosecond - end := r.b.BuildStep(t.Context(), meshbuilds.StepRun{Pipeline: "main.7.m", Step: meshbuilds.StepRunStepBuild, Branch: "main", Revision: 7, Source: 41, + end := r.b.BuildStep(t.Context(), "a1", meshbuilds.StepRun{Pipeline: "main.7.m", Step: meshbuilds.StepRunStepBuild, Branch: "main", Revision: 7, Source: 41, Entries: []meshbuilds.BuildEntry{{Module: "m", Fingerprint: fp1}}}) r.b.Wait() if _, built := r.st.vals[r.key]; end.Outcome != meshbuilds.StepEndedOutcomeFailed || !strings.Contains(end.Said, "revision 41 of main not in the builder's picture") || built || len(res.sources) != 0 { t.Errorf("end = %+v, built %v, reserved %+v; want failed naming revision 41 of main, nothing built", end, built, res.sources) } // A step ask with no source (a run on request) does not wait (H-A-156). - end = r.b.BuildStep(t.Context(), meshbuilds.StepRun{Pipeline: "run.1.m", Step: meshbuilds.StepRunStepBuild, Branch: "main", Entries: []meshbuilds.BuildEntry{{Module: "m", Fingerprint: fp1}}}) + end = r.b.BuildStep(t.Context(), "a1", meshbuilds.StepRun{Pipeline: "run.1.m", Step: meshbuilds.StepRunStepBuild, Branch: "main", Entries: []meshbuilds.BuildEntry{{Module: "m", Fingerprint: fp1}}}) if strings.Contains(end.Said, "not in the builder's picture") { t.Errorf("an ask with no source waited: %+v", end) }