diff --git a/modules/mesh-delivery-builder/internal/build/revisionwait.go b/modules/mesh-delivery-builder/internal/build/revisionwait.go index 0c4ec3d4..9e166228 100644 --- a/modules/mesh-delivery-builder/internal/build/revisionwait.go +++ b/modules/mesh-delivery-builder/internal/build/revisionwait.go @@ -25,6 +25,12 @@ import ( // below the newest the picture holds, whose entries the picture no longer names, asks the catalog seat's verb revision for // its catalog revision by number, once, and is built when that kept revision is of its source and names every entry it // asks; it never waits, since the picture only moves on. Only a revision above the newest is waited for. +// +// **An ask naming a revision is held by its number** (design 47 H H-A-222): when the picture does not name the ask's +// entries, the ask's catalog revision is read by number, and the ask is built when the catalog keeps it and it names every +// fingerprint asked, whatever the source the picture holds says (a re-pin keeps a later revision of the same source, H-A-211, +// H-A-213, so the source alone cannot say it). The source is compared only for an ask naming no revision; an ask whose +// revision the catalog does not answer and whose source is not below the picture's waits as before. // DefaultRevisionWait is the bound of a step ask's wait for its revision, its setting revision-wait-minutes' default (H-A-156). const DefaultRevisionWait = 2 * time.Minute @@ -73,21 +79,21 @@ func (b *Builder) holdsRevision(branch string, source int64, entries []meshbuild return true } -// keptRevisionHolds answers no outcome when the catalog keeps the ask's revision (its catalog revision by number, of its -// source revision) and that revision names every entry of the ask; else failed or could not run, with its words. +// keptRevisionHolds answers no outcome when the catalog keeps the ask's revision (its catalog revision by number) and that +// revision names every entry of the ask (H-A-205, H-A-222); else failed or could not run, with its words. func (b *Builder) keptRevisionHolds(ctx context.Context, run meshbuilds.StepRun, held int64) (outcome, said string) { - below := fmt.Sprintf("revision %d of %s is below the %d the builder's picture holds", run.Source, run.Branch, held) + below := fmt.Sprintf("revision %d of %s is not named by the builder's picture, which holds source revision %d", run.Source, run.Branch, held) + if run.Source < held { + below = fmt.Sprintf("revision %d of %s is below the %d the builder's picture holds", run.Source, run.Branch, held) + } if b.KeptRevision == nil || run.Revision <= 0 { return meshbuilds.StepEndedOutcomeFailed, below + ", and the ask names no catalog revision to read it by" } - source, fps, err := b.KeptRevision(ctx, run.Branch, run.Revision) + _, fps, err := b.KeptRevision(ctx, run.Branch, run.Revision) if err != nil { b.logf("%s: %s, and the catalog's revision %d cannot be read: %v", run.Pipeline, below, run.Revision, err) return meshbuilds.StepEndedOutcomeCouldNotRun, fmt.Sprintf("%s, and the catalog's revision %d cannot be read: %v", below, run.Revision, err) } - if source != run.Source { - return meshbuilds.StepEndedOutcomeFailed, fmt.Sprintf("%s, and the catalog's revision %d is of source revision %d", below, run.Revision, source) - } for _, e := range run.Entries { if fps[e.Module] != e.Fingerprint { return meshbuilds.StepEndedOutcomeFailed, fmt.Sprintf("%s, and the catalog's revision %d names %s at %q, not %s", below, run.Revision, e.Module, fps[e.Module], e.Fingerprint) @@ -116,8 +122,15 @@ func (b *Builder) awaitRevision(ctx context.Context, run meshbuilds.StepRun) (ou if b.Picture == nil || run.Source <= 0 || run.Branch == "" { return "", "" } - if held, ok := b.Picture(run.Branch); ok && run.Source < held && !b.holdsRevision(run.Branch, run.Source, run.Entries) { - return b.keptRevisionHolds(ctx, run, held) + if held, ok := b.Picture(run.Branch); !b.holdsRevision(run.Branch, run.Source, run.Entries) { + below := ok && run.Source < held + if run.Revision > 0 || below { + // By its number (H-A-222), whatever the source; for an ask naming none, only below the picture (H-A-205). + outcome, said := b.keptRevisionHolds(ctx, run, held) + if outcome == "" || below { + return outcome, said + } + } } bound := b.revisionWait() notHeld := fmt.Sprintf("revision %d of %s not in the builder's picture", run.Source, run.Branch) diff --git a/modules/mesh-delivery-builder/internal/build/step_test.go b/modules/mesh-delivery-builder/internal/build/step_test.go index 4b63b05a..0eaee147 100644 --- a/modules/mesh-delivery-builder/internal/build/step_test.go +++ b/modules/mesh-delivery-builder/internal/build/step_test.go @@ -356,7 +356,7 @@ func aStepAskWaitsForItsRevision(t *testing.T) { held.Store(40) asked := make(chan struct{}, 1) r, res, entry := revisionRig(t, &held, asked) - var keptReads atomic.Int64 // H-A-205: a revision above the newest is waited for, never read by number + var keptReads atomic.Int64 // H-A-205, H-A-222: a revision above the newest is read by number once; not answered, it is waited for r.b.KeptRevision = func(context.Context, string, int64) (int64, map[string]string, error) { keptReads.Add(1) return 0, nil, errors.New("not asked") @@ -385,8 +385,8 @@ func aStepAskWaitsForItsRevision(t *testing.T) { t.Fatal("the ask was not woken by the entry the picture took in") } r.b.Wait() - if end.Outcome != meshbuilds.StepEndedOutcomePassed || len(res.sources) != 1 || res.sources[0].Revision != 41 || keptReads.Load() != 0 { - t.Errorf("end = %+v, reserved from %+v, kept revisions read %d; want passed with one version reserved from revision 41, none read", end, res.sources, keptReads.Load()) + if end.Outcome != meshbuilds.StepEndedOutcomePassed || len(res.sources) != 1 || res.sources[0].Revision != 41 || keptReads.Load() != 1 { + t.Errorf("end = %+v, reserved from %+v, kept revisions read %d; want passed with one version reserved from revision 41, read by number once", end, res.sources, keptReads.Load()) } } @@ -425,6 +425,23 @@ func anOlderKeptRevisionIsReadByNumber(t *testing.T) { if end := r2.b.BuildStep(t.Context(), 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 + // of the same source 46 and the picture took its entries in), is held by its revision read by number, never waited for. + r3, res3, _ := revisionRig(t, &held, make(chan struct{}, 1)) + r3.b.RevisionWait = time.Nanosecond + r3.b.FirstBranch = func(branch, module string) bool { return branch == "main" && module == "m" } + var read3 []string + r3.b.KeptRevision = func(_ context.Context, branch string, revision int64) (int64, map[string]string, error) { + read3 = append(read3, fmt.Sprintf("%s %d", branch, revision)) + return 46, map[string]string{"m": fp1}, nil + } + 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) + 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) + } } func aStepAskPastItsRevisionBoundFails(t *testing.T) {