mesh-delivery-indexer, mesh-delivery-pipeline: a release re-pins an import-form entry's packages; a reopened mover reads the head's entry (design 47 H2 H-A-763 to H-A-765; issue 1984) #367

Merged
mesh-tools merged 5 commits from fix/47-H2-763-repin-import-form into main 2026-11-25 22:18:42 +00:00
11 changed files with 334 additions and 89 deletions
@@ -4,6 +4,7 @@ import (
"context"
"errors"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/graph"
"slices"
"strings"
"testing"
@@ -58,6 +59,7 @@ func TestImportsReportedMoveTheFingerprintOnlyWithAnImportedPackage(t *testing.T
t.Run("an unread packages state writes no fingerprint, and they are computed again by hand (issue 1966)", anUnreadPackagesStateWritesNoFingerprintAndFingerprintsAreComputedAgain)
t.Run("an accepted series' newest published version pins it, by that version's contents", anAcceptedSeriesPinsItsNewest)
t.Run("only the version line's fingerprint takes a release's pin", onlyTheVersionLineTakesAPin)
t.Run("a release re-pins an import-form entry's packages, never its fingerprint, and keeps a revision with no movers", aReleaseRepinsAnImportFormEntryWithNoMovers)
t.Run("a reported set is a key of the state imports, an empty one too, or a set held before it", aReportedSetIsAKeyOrAHeldSet)
ctx := context.Background()
ix, mods := newFormIndexer(t, mod{"avahi", catalogueManifest(t, "avahi")})
@@ -192,6 +194,79 @@ func TestImportsReportedMoveTheFingerprintOnlyWithAnImportedPackage(t *testing.T
}
}
// Design 47 H2 H-A-763 (1), (2), H-A-765 (3), H-A-530, H-A-204: a release (or a recompute, which keeps it as a re-pin does) re-pins the packages of an entry on the import form pinned
// below the series' newest (repinned names it), its fingerprint stays, and the branch's next revision is kept all the same,
// its call the release and no mover.
func aReleaseRepinsAnImportFormEntryWithNoMovers(t *testing.T) {
ctx := context.Background()
for _, how := range []string{"re-pin", "recompute"} {
ix, mods := newFormIndexer(t, mod{"avahi", catalogueManifest(t, "avahi")})
reportToolchain(t, ix, "mesh-build-go", "novox", "go", "go1.27.1")
ix.Packages, ix.Files, ix.Imports, ix.Revisions = newMem(), forge{c1: sdkFiles("a1", "b1")}.files, newMem(), newMemObjects(1<<20)
setPackages(t, mods, "avahi", []string{meshSDK})
meshSDKPublished(t, ix, mods)
held, _ := ix.heldModules(ctx)
if err := ix.publish(ctx, "novox/mesh-sdk", c1, held, false, TrunkBranch); err != nil {
t.Fatal(err)
}
if err := ix.Recompute(ctx); err != nil {
t.Fatal(err)
}
before, _ := moduleOf(t, mods, "avahi")
if err := ix.HearImportsReported(ctx, buildEnd(t, "avahi", before.Fp2, meshSDK, meshSDK+"/announce")); err != nil {
t.Fatal(err)
}
if err := ix.Recompute(ctx); err != nil {
t.Fatal(err)
}
old, _ := moduleOf(t, mods, "avahi")
if old.Inputs2 == nil || old.Inputs2.ImportForm == "" {
t.Fatalf("no import form kept from the report: %+v", old.Inputs2)
}
old.Fp2, old.Packages = old.Inputs2.ImportForm, map[string]string{meshSDK: "v0.1.19"}
raw, err := meshcatalogclient.EncodeModule(old)
if err != nil {
t.Fatal(err)
}
mods.put("avahi", raw)
if err := ix.Recompute(ctx); err != nil { // the held fingerprint stands (H-A-529): the graph and the value agree
t.Fatal(err)
}
entries, err := ix.viewEntries(ctx)
if err != nil {
t.Fatal(err)
}
if err := ix.KeepBranchEntries(ctx, TrunkBranch, 5, entries, nil); err != nil {
t.Fatal(err)
}
if _, err := hearReleased(ctx, ix, HeardVersion{Package: "mesh-sdk/go", Seat: "go-package-registry", Version: "0.1.20", Commit: c1, GoModule: meshSDK, Published: true}, "mesh-sdk", "go"); err != nil {
t.Fatal(err)
}
if only, err := ix.repinned(ctx, "mesh-sdk"); err != nil || !only["avahi"] {
t.Fatalf("a re-pin of mesh-sdk names %v (%v), want avahi, on the import form", only, err)
}
if how == "re-pin" {
if n, err := ix.Repin(ctx, "mesh-sdk", "0.1.20"); err != nil || n != 1 {
t.Fatalf("a release re-pinned %d modules (%v), want avahi", n, err)
}
} else if err := ix.RecomputeKept(ctx, "the packages moved"); err != nil { // H-A-765 (3): a recompute keeps it as a re-pin does
t.Fatal(err)
}
now, _ := moduleOf(t, mods, "avahi")
if now.Fp2 != old.Fp2 || now.Packages[meshSDK] != "v0.1.20" {
t.Fatalf("avahi after the re-pin: fp2 %q (was %q), packages %v; want the fingerprint as it was, pinned to v0.1.20", now.Fp2, old.Fp2, now.Packages)
}
rev, kept, found, err := readNewestOf(ctx, ix.Revisions, TrunkBranch)
if err != nil || !found || rev.Revision != 2 || rev.Source != 5 || (how == "re-pin" && rev.CallKind != meshcatalog.CatalogRevisionCallKindRelease) || len(rev.Movers) != 0 {
t.Fatalf("main's newest = %+v (%v), want revision 2 of source 5, its call the release (a re-pin), no movers", rev, err)
}
if i := slices.IndexFunc(kept, func(e meshcatalog.CatalogEntry) bool { return e.Module == "avahi" }); i < 0 || kept[i].Packages[meshSDK] != "v0.1.20" || kept[i].Fp != old.Fp2 {
t.Fatalf("the kept entries hold %+v for avahi, want it at %s pinned to v0.1.20", kept, old.Fp2)
}
}
}
// Design 47 H2 H-A-530: only the version line's fingerprint takes a release's pin, so a release moves a module with no
// reported import set (I4/AC2, H-A-167 for the version line); a held fingerprint made with a pin from before stands
// while the import form computes to the one its build reported (I4/AC3, ADR 0593 §4, H-A-529).
@@ -80,16 +80,8 @@ func TestAReleaseRepinsAnEntryNamingItsPackageWithNoPin(t *testing.T) {
if _, err := hearReleased(ctx, ix, HeardVersion{Package: "mesh-sdk/go", GoModule: "git.novox.be/novox/mesh-sdk/go", Version: "0.1.27", Published: true}, "mesh-sdk", "go"); err != nil {
t.Fatal(err)
}
// I5/AC1 (design 47 H2 H-A-530): a module on the import form (its import form set, H-A-538) is named by no re-pin;
// I5/AC2: on the version line, as g is, it is.
onImports := g
in := *g.Inputs2
in.Imports, in.ImportForm = []string{"git.novox.be/novox/mesh-sdk/go"}, "src2:"+strings.Repeat("a", 64)
onImports.Inputs2 = &in
mods.put("g", mustEncode(t, onImports))
if only, err := ix.repinned(ctx, "mesh-sdk"); err != nil || only["g"] {
t.Errorf("a re-pin of mesh-sdk names %v (%v), want no module on the import form", only, err)
}
// I5/AC1 (design 47 H2 H-A-530, narrowed by H-A-763 (1)): a module on the import form is named as well, in imports_test.go's
// row aReleaseRepinsAnImportFormEntryWithNoMovers; I5/AC2: on the version line, as g is, it is.
mods.put("g", mustEncode(t, g))
if only, err := ix.repinned(ctx, "mesh-sdk"); err != nil || !only["g"] {
t.Errorf("a re-pin of mesh-sdk names %v (%v), want g, on the version line", only, err)
@@ -717,9 +717,9 @@ func (ix *Indexer) repinModules(ctx context.Context, branch string, modules []st
}
// repinned are the modules the indexer's modules state holds whose packages name a package of module: by their pins, and
// by their kept requirements, which name a package they hold no pin of yet (design 47 H-A-204, H-A-165, H-A-167). Only a
// module on the version line is named: one on the import form (its import form set, H2 H-A-538) takes no pin into its
// fingerprint, so a release never moves it (H-A-530).
// by their kept requirements, which name a package they hold no pin of yet (design 47 H-A-204, H-A-165, H-A-167). A module
// on the import form is named as one on the version line: its packages take the release, its fingerprint stays (H-A-530,
// H-A-763 (1)).
func (ix *Indexer) repinned(ctx context.Context, module string) (map[string]bool, error) {
held, err := ix.heldModules(ctx)
if err != nil {
@@ -727,9 +727,6 @@ func (ix *Indexer) repinned(ctx context.Context, module string) (map[string]bool
}
only := map[string]bool{}
for key, m := range held {
if m.Inputs2 != nil && m.Inputs2.ImportForm != "" {
continue
}
names := slices.Collect(maps.Keys(m.Packages))
if m.Inputs2 != nil {
names = append(names, m.Inputs2.Packages...)
@@ -763,9 +760,11 @@ func (ix *Indexer) keepRepinned(ctx context.Context, x *Indexer, branch string,
return err
}
was := make(map[string]string, len(before))
wasPkgs := make(map[string]map[string]string, len(before))
for _, e := range before {
was[e.Module] = e.Fp
was[e.Module], wasPkgs[e.Module] = e.Fp, e.Packages
}
pinsMoved := false // an entry whose packages moved with no fingerprint (an import-form entry, H-A-530) is kept with no mover (H-A-763 (2))
var movers []meshcatalog.TakeInEntry
moved := slices.Sorted(maps.Keys(only))
if only == nil { // a take-in again or a recompute: every module whose fingerprint moved (H-A-212, H-A-217)
@@ -773,13 +772,18 @@ func (ix *Indexer) keepRepinned(ctx context.Context, x *Indexer, branch string,
}
for _, key := range moved {
e, ok := entries[key]
if ok && e.Fp != "" && was[e.Module] == e.Fp && !maps.Equal(wasPkgs[e.Module], e.Packages) {
if _, had := was[e.Module]; had {
pinsMoved = true
}
}
if !ok || e.Fp == "" || was[e.Module] == e.Fp {
continue
}
movers = append(movers, meshcatalog.TakeInEntry{Module: e.Module, Commit: e.Commit, Fingerprint: e.Fp, Repository: e.Repository})
}
if len(movers) == 0 {
ix.logf("re-pin (%s): no fingerprint of %s moved, so no revision is kept", call.Call, branch)
if len(movers) == 0 && !pinsMoved {
ix.logf("re-pin (%s): no fingerprint or pin of %s moved, so no revision is kept", call.Call, branch)
return nil
}
number, err := ix.keepBranchEntries(ctx, branch, newest.Source, call, entries, movers)
@@ -209,13 +209,8 @@ func (v Verbs) ownFailedPipelines(branch, key string, movers []seat.Mover, headE
}
at := slices.IndexFunc(out, func(o ownPipeline) bool { return o.from.Pipeline == best.Pipeline })
if at < 0 {
entries := headEntries
if s.Revision != nil {
if h, err := s.Revision(branch, best.Revision); err == nil && h.Entries != nil {
entries = h.Entries
}
}
out = append(out, ownPipeline{from: best, entries: entries})
// Its movers are read at the head's revision, whose entries are the newest (design 47 H2 H-A-763 (3)).
out = append(out, ownPipeline{from: best, entries: headEntries})
at = len(out) - 1
}
out[at].group = appendNew(out[at].group, v.closedGroup(best, m.Module, out[at].entries)...)
@@ -396,53 +391,24 @@ func (v Verbs) planUnfinished(key string) (handPlan, error) {
if err != nil || !Moves(from, module) {
return handPlan{}, fmt.Errorf("its pipeline %s is not read or moves %s no more", e.Pipeline, module)
}
if s.Revision == nil && v.View == nil {
if v.View == nil {
return handPlan{}, errors.New("the runner reads no catalog revision")
}
// The entry is read at its kept revision, else at the head's when the entry there has the same fingerprint (design 47 H2 H-A-608).
readAt := func(rev int64) (Half, error) {
if s.Revision != nil {
h, err := s.Revision(branch, rev)
if err != nil {
return Half{}, fmt.Errorf("the revision %d of %s is not read: %w", rev, branch, err)
}
return h, nil
}
if h, ok := v.View(branch); ok && h.Revision == rev {
return h, nil
}
return Half{}, fmt.Errorf("the revision %d of %s is not held", rev, branch)
}
// The entry is read at the head's revision, which holds the module at the key's fingerprint (design 47 H2 H-A-763 (3), H-A-761);
// the kept revision H-A-608 names stays the revision the record pins, and is only said.
kept := s.Unfinished.keptRevision(e, module)
half, rerr := readAt(kept)
entry, has := half.Entries[module]
if rerr != nil || !has || entry.Fp != e.Fingerprint || half.Source <= 0 {
looked := fmt.Sprintf("its kept revision %d holds it at %q", kept, entry.Fp)
if rerr != nil {
looked = rerr.Error()
}
head, hok := Half{}, false
if v.View != nil {
head, hok = v.View(branch)
}
he, hhas := head.Entries[module]
if !hok || !hhas || he.Fp != e.Fingerprint || head.Source <= 0 {
return handPlan{}, fmt.Errorf("%s at fingerprint %s is read at neither revision: %s; the head's revision %d of %s holds it at %q", module, e.Fingerprint, looked, head.Revision, branch, he.Fp)
}
half = head
}
// H-A-761: the key goes on only when the head's revision holds its module at the key's fingerprint; otherwise it is dropped and said.
if head, ok := v.View(branch); !ok || head.Entries[module].Fp != e.Fingerprint {
he := head.Entries[module]
why := fmt.Sprintf("the head's revision %d of %s holds it at %q, not at the key's %q; its entry was read at revision %d", head.Revision, branch, he.Fp, e.Fingerprint, kept)
head, hok := v.View(branch)
if he := head.Entries[module]; !hok || he.Fp != e.Fingerprint {
why := fmt.Sprintf("the head's revision %d of %s holds it at %q, not at the key's %q; its kept revision %d", head.Revision, branch, he.Fp, e.Fingerprint, kept)
s.Unfinished.dropMoved(key, module, e.Fingerprint, why)
return handPlan{}, fmt.Errorf("%s is no longer unfinished at fingerprint %s: %s", module, e.Fingerprint, why)
}
if head.Source <= 0 {
return handPlan{}, fmt.Errorf("%s at fingerprint %s is read at the head's revision %d of %s, which has no source", module, e.Fingerprint, head.Revision, branch)
}
half := head
group := v.closedGroup(from, module, half.Entries)
plan := handPlan{from: from, group: group, entries: half.Entries}
if head, ok := v.View(branch); ok && head.Entries != nil {
plan.entries = head.Entries
}
for _, g := range group {
mv, _ := MoverOf(from, g)
plan.movers = append(plan.movers, mv)
@@ -48,7 +48,7 @@ func placeFixture() (catalog.Registration, map[string]catalog.CatalogEntry) {
Artifacts: map[string]catalog.StepStatuses{"tools": {Lint: "bypass"}},
}}
return reg, map[string]catalog.CatalogEntry{
"app": {Module: "app", Path: "modules/app", Packages: map[string]string{"git.novox.be/novox/mesh-sdk/go": "v0.1.25"}, Artifacts: []catalog.Artifact{{Ref: "app:program", Language: "go"}, {Ref: "app:tools", Language: "go"},
"app": {Module: "app", Fp: "src2:aa", Path: "modules/app", Packages: map[string]string{"git.novox.be/novox/mesh-sdk/go": "v0.1.25"}, Artifacts: []catalog.Artifact{{Ref: "app:program", Language: "go"}, {Ref: "app:tools", Language: "go"},
{Ref: "app:web", Language: "rust"}}, Inputs: &catalog.EntryInputs{Paths: map[string][]string{"app:program": {"cmd/app"}}}},
"mesh-build-go": {Module: "mesh-build-go", Acts: []catalog.ActingRule{{Seat: "node-build-go", Step: "build", On: "go"}}},
}
@@ -150,6 +150,53 @@ func TestASameSourceRepinKeepsTheMoverInItsPipeline(t *testing.T) {
if last.Step.Fingerprint != "src2:ab" || last.Step.Fetch.Packages["git.novox.be/novox/x/go"] != "v0.1.1" {
t.Errorf("a held step asked = %+v", last.Step)
}
// design 47 H2 H-A-763 (3): a rerun of the kept mover's step reads its entry at the head's revision when that holds the mover
// at the same fingerprint, so its build is asked with the head's newer pins; the kept revision stays in the id.
_, _, repinnedEntries, _ := repinFixture()
headApp := repinnedEntries["app"]
headApp.Packages = map[string]string{"git.novox.be/novox/mesh-sdk/go": "v0.1.27", "git.novox.be/novox/x/go": "v0.1.1"}
headEntries := map[string]catalog.CatalogEntry{}
for k, e := range repinnedEntries {
headEntries[k] = e
}
headEntries["app"] = headApp
head := Half{Revision: 13, Source: 41, Entries: headEntries}
rv := Verbs{Starter: s, View: func(string) (Half, bool) { return head, true }, Hearer: h}
cur, _, _ := store.Get(key)
unit := stepNamed(cur, "app:program", "unit")
a, err := rv.askOf(cur, unit, "op@shanks", time.Unix(100, 0))
if err != nil {
t.Fatal(err)
}
if b, ok := a.Ask.(nodebuildgo.StepAsk); !ok || b.Step.Fetch.Packages["git.novox.be/novox/mesh-sdk/go"] != "v0.1.27" {
t.Errorf("the rerun with the head holding app at its fingerprint asked %+v, want mesh-sdk pinned to the head's v0.1.27", a.Ask)
}
// H-A-764 (1): a pipeline that ended and goes on again places its never-asked kept mover from the head's entry too, its ids still
// mixing in the kept revision; a running pipeline's kept mover is placed at its kept revision (H-A-286).
for ends, want := range map[int64]string{1: "v0.1.27", 0: "v0.1.26"} {
again := cur
again.EndCount, again.Steps = ends, nil
again.Movers = slices.Clone(cur.Movers)
asked, _, _, _ := s.placeMovers(&again, func(string) (catalog.Registration, bool) { return reg, true }, headEntries, time.Unix(100, 0))
var got string
for _, a := range asked {
if b, ok := a.Ask.(nodebuildgo.StepAsk); ok && b.Step != nil && b.Step.Step == "unit" {
got = b.Step.Fetch.Packages["git.novox.be/novox/mesh-sdk/go"]
}
}
if ends == 0 {
want = "" // revision 11 leaves a package unpinned: a running pipeline's unit step waits on the publish
}
if got != want {
t.Errorf("placing with %d ends asked the unit step with mesh-sdk %q, want %q", ends, got, want)
}
}
// H-A-764 (2): a rerun of a mover the head holds at another fingerprint is refused naming both fingerprints, and asks nothing.
headEntries["app"] = func() catalog.CatalogEntry { e := headApp; e.Fp = "src2:zz"; return e }()
if _, err := rv.askOf(cur, unit, "op@shanks", time.Unix(101, 0)); err == nil || !strings.Contains(err.Error(), "src2:ab") || !strings.Contains(err.Error(), "src2:zz") {
t.Errorf("the rerun with the head at another fingerprint = %v, want it refused naming src2:ab and src2:zz", err)
}
headEntries["app"] = headApp
// A revision of a new source starts its own pipeline and moves the mover out (H-A-223).
if n, err := s.Revised(ev(12), read); n != 1 || err != nil {
t.Fatalf("a new source's revision started %d (%v)", n, err)
@@ -375,3 +422,162 @@ func (k rawKept) Value(key string) (json.RawMessage, error) {
v, _, err := k.r.Get(key)
return v, err
}
// design 47 H2 H-A-763 (3), H-A-764: a mover of a failed pipeline whose kept revision holds older pins than the head's entry at the same
// fingerprint is asked again with the head's pins, by start's reopen (ownFailedPipelines) and by runner_unfinished_place's plan; a declined
// step's ask of a running pipeline still reads the kept revision (H-A-286, H-A-445).
func TestAMoverReopenedIsAskedWithTheHeadsPins(t *testing.T) {
const sdk = "git.novox.be/novox/mesh-sdk/go"
reg, entries := placeFixture()
pin := func(v string) catalog.CatalogEntry {
e := entries["app"]
e.Fp, e.Packages, e.Commit, e.Repository = "src2:ab", map[string]string{sdk: v}, "c1", "o/app"
return e
}
keptHalf := Half{Revision: 11, Source: 41, Entries: map[string]catalog.CatalogEntry{"app": pin("v0.1.26"), "mesh-build-go": entries["mesh-build-go"]}}
head := Half{Revision: 13, Source: 41, Entries: map[string]catalog.CatalogEntry{"app": pin("v0.1.27"), "mesh-build-go": entries["mesh-build-go"]}}
for _, how := range []string{"start", "place-unfinished", "declined step of a running pipeline"} {
store := &MoverStore{Raw: newMemRaw()}
asks := &stepAsks{}
u := memUnfinished{}
s := &Starter{Pipelines: store, Store: store, Steps: asks, Name: "the-runner", Now: ticking(), Say: func(string, any) error { return nil },
Revision: func(_ string, r int64) (Half, error) { return keptHalf, nil },
Registration: func(m string) (catalog.Registration, bool) { return reg, m == "app" }}
s.Unfinished = &Unfinished{Store: u, Kept: func(string) map[string]int64 { return map[string]int64{"app": 11} }}
key := Key("main", 10)
if ok, err := s.Start(Begin{Branch: "main", Source: 41, Revision: 10, Entries: map[string]catalog.CatalogEntry{"app": pin("v0.1.26"), "mesh-build-go": entries["mesh-build-go"]},
Movers: []seat.Mover{{Module: "app", Commit: "c1", Fingerprint: "src2:ab", Repository: "o/app"}}}); !ok || err != nil {
t.Fatalf("%s: start = %v, %v", how, ok, err)
}
p, rev, _ := store.Get(key)
end := time.Unix(50, 0)
for i := range p.Steps {
if how == "place-unfinished" { // its steps never ran: the mover is left unfinished, placed again from the head's entry
p.Steps[i].Outcome, p.Steps[i].Ask = seat.StepResultOutcomeNotAsked, ""
} else if p.Steps[i].Step == seat.StepResultStepLint && p.Steps[i].Artifact == "app:program" {
p.Steps[i].Outcome, p.Steps[i].Ended = seat.StepResultOutcomeFailed, &end
}
}
if how != "declined step of a running pipeline" {
p.Outcome, p.Ended, p.EndCount = seat.PipelineOutcomeFailed, &end, 1
}
if _, err := store.UpdateKept(key, p, rev, map[string]int64{"app": 11}); err != nil {
t.Fatal(err)
}
v := Verbs{Starter: s, Hearer: &Hearer{Store: store, Unfinished: s.Unfinished, Say: func(string, any) error { return nil }}, View: func(string) (Half, bool) { return head, true }, Acts: &actLog{}}
before := len(asks.asks)
switch how {
case "start":
if _, err := v.Start("op@shanks", seat.StartInput{Branch: "main", Module: "app", Why: "again"}); err != nil {
t.Fatalf("%s: %v", how, err)
}
case "place-unfinished":
u["main.app"] = `{"fingerprint":"src2:ab","revision":10,"pipeline":"` + key + `","outcome":"failed"}`
if a, err := v.PlaceUnfinished("op@shanks", seat.PlaceUnfinishedInput{Key: "main.app", Why: "again"}); err != nil {
t.Fatalf("%s: %v (%+v)", how, err, a)
} else if len(a.Placed) != 1 {
t.Fatalf("%s: placed %+v", how, a)
}
default:
cur, _, _ := store.Get(key)
a, err := v.DeclinedAsk(cur, stepNamed(cur, "app:program", "lint"), time.Unix(60, 0))
if err != nil {
t.Fatalf("%s: %v", how, err)
}
asks.asks = append(asks.asks, a.Ask)
}
if len(asks.asks) == before {
t.Fatalf("%s: nothing was asked", how)
}
want := "v0.1.27"
if how != "start" && how != "place-unfinished" {
want = "v0.1.26"
}
seen := 0
for _, ask := range asks.asks[before:] {
if b, ok := ask.(nodebuildgo.StepAsk); ok && b.Step != nil && b.Step.Fetch.Packages != nil {
if seen++; b.Step.Fetch.Packages[sdk] != want {
t.Errorf("%s: asked %+v, want mesh-sdk pinned to %s", how, b.Step, want)
}
}
}
if seen == 0 {
t.Errorf("%s: no step was asked with pins", how)
}
}
}
// design 47 H2 H-A-763 (3): the group a hand place or start's reopen closes is read over the head's entries, whose edges are the newest:
// an edge the head's entry of lib has and its kept revision's has not puts app, which lib waits for, in the group.
func TestAReopenedGroupIsClosedOverTheHeadsEdges(t *testing.T) {
reg, entries := placeFixture()
mk := func(module, fp string, edges []catalog.Edge) catalog.CatalogEntry {
return catalog.CatalogEntry{Module: module, Fp: fp, Commit: "c1", Repository: "o/" + module, Path: "modules/" + module, Edges: edges,
Artifacts: []catalog.Artifact{{Ref: catalog.ArtifactRef(module + ":program"), Language: "go"}}}
}
view := func(edges []catalog.Edge) map[string]catalog.CatalogEntry {
return map[string]catalog.CatalogEntry{"app": mk("app", "src2:aa", nil), "lib": mk("lib", "src2:bb", edges), "mesh-build-go": entries["mesh-build-go"]}
}
kept := Half{Revision: 10, Source: 41, Entries: view(nil)}
head := Half{Revision: 13, Source: 41, Entries: view([]catalog.Edge{{From: "app:program", Kind: 2}})}
for _, how := range []string{"start", "place-unfinished"} {
store := &MoverStore{Raw: newMemRaw()}
asks := &stepAsks{}
u := memUnfinished{}
s := &Starter{Pipelines: store, Store: store, Steps: asks, Name: "the-runner", Now: ticking(), Say: func(string, any) error { return nil },
Revision: func(string, int64) (Half, error) { return kept, nil },
Registration: func(string) (catalog.Registration, bool) { return reg, true }, Unfinished: &Unfinished{Store: u}}
key := Key("main", 10)
if ok, err := s.Start(Begin{Branch: "main", Source: 41, Revision: 10, Entries: kept.Entries, Movers: []seat.Mover{
{Module: "app", Commit: "c1", Fingerprint: "src2:aa", Repository: "o/app"}, {Module: "lib", Commit: "c1", Fingerprint: "src2:bb", Repository: "o/lib"}}}); !ok || err != nil {
t.Fatalf("%s: start = %v, %v", how, ok, err)
}
p, rev, _ := store.Get(key)
end := time.Unix(50, 0)
for i := range p.Steps {
switch {
case how == "place-unfinished":
p.Steps[i].Outcome, p.Steps[i].Ask = seat.StepResultOutcomeNotAsked, ""
case p.Steps[i].Step == seat.StepResultStepLint && p.Steps[i].Artifact != "":
p.Steps[i].Outcome, p.Steps[i].Ended = seat.StepResultOutcomeFailed, &end
}
}
p.Outcome, p.Ended, p.EndCount = seat.PipelineOutcomeFailed, &end, 1
if _, err := store.Update(key, p, rev); err != nil {
t.Fatal(err)
}
v := Verbs{Starter: s, Hearer: &Hearer{Store: store, Unfinished: s.Unfinished, Say: func(string, any) error { return nil }}, View: func(string) (Half, bool) { return head, true }, Acts: &actLog{}}
var group []string
switch how {
case "start":
before := len(asks.asks)
if _, err := v.Start("op@shanks", seat.StartInput{Branch: "main", Module: "lib", Why: "again"}); err != nil {
t.Fatalf("%s: %v", how, err)
}
for _, a := range asks.asks[before:] {
if b, ok := a.(nodebuildgo.StepAsk); ok && b.Step != nil && !slices.Contains(group, b.Step.Module) {
group = append(group, b.Step.Module)
}
}
default:
u["main.app"] = `{"fingerprint":"src2:aa","revision":10,"pipeline":"` + key + `","outcome":"failed"}`
u["main.lib"] = `{"fingerprint":"src2:bb","revision":10,"pipeline":"` + key + `","outcome":"failed"}`
a, err := v.PlaceUnfinished("op@shanks", seat.PlaceUnfinishedInput{Key: "main.lib", Why: "again"})
if err != nil {
t.Fatalf("%s: %v", how, err)
}
for _, pl := range a.Placed {
group = append(group, pl.Key)
}
slices.Sort(group)
group = []string{strings.Join(group, ",")}
if group[0] == "main.app,main.lib" {
group = []string{"app", "lib"}
}
}
slices.Sort(group)
if !slices.Equal(group, []string{"app", "lib"}) {
t.Errorf("%s: the group reopened = %v, want app and lib (lib's head edge from app)", how, group)
}
}
}
@@ -511,7 +511,9 @@ func (s *Starter) placeMovers(p *seat.Pipeline, reg func(module string) (catalog
}
// A mover a same-source re-pin kept is placed from the revision it is kept at, its ids its own (H-A-286).
entries := all
if rev := kept[m.Module]; rev > 0 {
// A mover of a pipeline that ended and goes on again reads the head's entry when it holds the mover at its fingerprint
// (design 47 H2 H-A-764 (1), H-A-763 (3)); its ids still mix in the kept revision.
if rev := kept[m.Module]; rev > 0 && !(p.EndCount > 0 && all[m.Module].Fp == m.Fingerprint) {
var err error
if entries, err = s.keptEntries(p.Branch, rev); errors.Is(err, ErrRevisionGone) {
// A kept revision the catalog no longer holds is never read: the pipeline ends failed (H-A-496).
@@ -830,7 +832,7 @@ func (s *Starter) Resume(store Updater, branch string, half Half) (int, error) {
}
// A kept mover's steps are found by the ids its kept revision gives, from that revision's entries (H-A-286).
entries, rev := half.Entries, kept[m.Module]
if rev > 0 {
if rev > 0 && !(p.EndCount > 0 && half.Entries[m.Module].Fp == m.Fingerprint) { // H-A-764 (1)
var err error
if entries, err = s.keptEntries(p.Branch, rev); err != nil {
s.logf("%s: revision %d of %s, which %s is kept at, is not read (%v): its steps are asked again once it is", key, rev, p.Branch, m.Module, err)
@@ -573,8 +573,8 @@ func TestTakenInStartsOnlyItsEntries(t *testing.T) {
}, Logf: func(f string, a ...any) { said = append(said, fmt.Sprintf(f, a...)) },
Entries: func(_ string, r int64) (map[string]catalog.CatalogEntry, bool) { e, ok := held[r]; return e, ok }}
got := cu.Carry("main", 20, map[string]catalog.CatalogEntry{"back": {Commit: "c20", Fp: "src2:b1"}, "old": {Commit: "c20", Fp: "src2:o1"}, "newer": {Commit: "c20", Fp: "src2:x2"}}, nil)
if len(got) != 2 || got[0].Module != "back" || got[0].Commit != "c20" || got[1].Module != "old" || got[1].Commit != "c3" {
t.Errorf("the carry = %+v, want back read at the head's revision (its kept revision 2 gone) and old at its kept revision 3, the head holding it at the same fingerprint, and newer not carried at x1", got)
if len(got) != 2 || got[0].Module != "back" || got[0].Commit != "c20" || got[1].Module != "old" || got[1].Commit != "c20" {
t.Errorf("the carry = %+v, want back and old read at the head's revision (H-A-763 (3): old's kept revision 3 still holds it, the head's entry is read), and newer not carried at x1", got)
}
if j := strings.Join(said, "\n"); !strings.Contains(j, "far is no longer unfinished at fingerprint src2:f1") || !strings.Contains(j, "kept revision 2 is gone") || !strings.Contains(j, "head's revision 20") ||
!strings.Contains(j, "newer is no longer unfinished at fingerprint src2:x1") || !strings.Contains(j, `holds it at "src2:x2", not at the key's "src2:x1"`) || cu.Store.(memUnfinished)["main.newer"] != "" {
@@ -157,7 +157,7 @@ func newRunFixture() *runFixture {
func (f *runFixture) start(t *testing.T, source, revision int64) seat.Pipeline {
t.Helper()
entries := map[string]catalog.CatalogEntry{
"app": {Module: "app", Path: "modules/app", Artifacts: []catalog.Artifact{{Ref: "app:program", Language: "go"}, {Ref: "app:tools", Language: "go"}}},
"app": {Module: "app", Fp: "src2:aa", Path: "modules/app", Artifacts: []catalog.Artifact{{Ref: "app:program", Language: "go"}, {Ref: "app:tools", Language: "go"}}},
"mesh-build-go": {Module: "mesh-build-go", Acts: []catalog.ActingRule{{Seat: "node-build-go", Step: "build", On: "go"}}},
}
if ok, err := f.s.Start(Begin{Branch: "main", Source: source, Revision: revision, Key: Key("main", source), Entries: entries, Movers: []seat.Mover{{Module: "app", Commit: "c1", Fingerprint: "src2:aa"}}}); !ok || err != nil {
@@ -547,7 +547,7 @@ func TestARerunOfATestRunMovesEveryReaderThatDidNotPass(t *testing.T) {
}
v := Verbs{Hearer: f.h, Starter: f.s, View: func(string) (Half, bool) {
return Half{Entries: map[string]catalog.CatalogEntry{
"app": {Module: "app", Path: "modules/app", Artifacts: []catalog.Artifact{{Ref: "app:program", Language: "go"}, {Ref: "app:tools", Language: "go"}}},
"app": {Module: "app", Fp: "src2:aa", Path: "modules/app", Artifacts: []catalog.Artifact{{Ref: "app:program", Language: "go"}, {Ref: "app:tools", Language: "go"}}},
"mesh-build-go": {Module: "mesh-build-go", Acts: []catalog.ActingRule{{Seat: "node-build-go", Step: "build", On: "go"}}}}}, true
}, Acts: &actLog{}}
a, err := v.Rerun("op@shanks", seat.RerunInput{Pipeline: p.Pipeline, Step: "unit", Artifact: "app:tools", Why: "flaky"})
@@ -874,7 +874,7 @@ func TestNoWriteOfATestRunActsOnAReadBeforeItsLatestChange(t *testing.T) {
}
v := Verbs{Hearer: f.h, Starter: f.s, View: func(string) (Half, bool) {
return Half{Entries: map[string]catalog.CatalogEntry{
"app": {Module: "app", Path: "modules/app", Artifacts: []catalog.Artifact{{Ref: "app:program", Language: "go"}, {Ref: "app:tools", Language: "go"}}},
"app": {Module: "app", Fp: "src2:aa", Path: "modules/app", Artifacts: []catalog.Artifact{{Ref: "app:program", Language: "go"}, {Ref: "app:tools", Language: "go"}}},
"mesh-build-go": {Module: "mesh-build-go", Acts: []catalog.ActingRule{{Seat: "node-build-go", Step: "build", On: "go"}}}}}, true
}, Acts: &actLog{}, RevisionHeld: func(string, int64) error { return nil }}
a, err := v.Rerun("op@shanks", seat.RerunInput{Pipeline: p.Pipeline, Step: "unit", Artifact: "app:program", Why: "fixed"})
@@ -907,7 +907,7 @@ func TestNoWriteOfATestRunActsOnAReadBeforeItsLatestChange(t *testing.T) {
}}
v := Verbs{Hearer: f.h, Starter: f.s, View: func(string) (Half, bool) {
return Half{Entries: map[string]catalog.CatalogEntry{
"app": {Module: "app", Path: "modules/app", Artifacts: []catalog.Artifact{{Ref: "app:program", Language: "go"}, {Ref: "app:tools", Language: "go"}}},
"app": {Module: "app", Fp: "src2:aa", Path: "modules/app", Artifacts: []catalog.Artifact{{Ref: "app:program", Language: "go"}, {Ref: "app:tools", Language: "go"}}},
"mesh-build-go": {Module: "mesh-build-go", Acts: []catalog.ActingRule{{Seat: "node-build-go", Step: "build", On: "go"}}}}}, true
}, Acts: &actLog{}}
a, err := v.Rerun("op@shanks", seat.RerunInput{Pipeline: p.Pipeline, Step: "unit", Artifact: "app:program", Why: "fixed"})
@@ -454,8 +454,8 @@ func (u *Unfinished) keptRevision(e UnfinishedEntry, module string) int64 {
// entryOf reads module's entry for the carry (design 47 H2 H-A-608, H-A-761): the module goes on only when the head's revision's
// entry (entries) holds the key's fingerprint, so an older fingerprint is never delivered after a newer one; its contents are
// read at its kept revision when that is still read and holds it at the key's fingerprint, else at the head's. Neither says why,
// naming both fingerprints and each revision looked at.
// the head's entry's, whose pins are the newest (design 47 H2 H-A-763 (3), replacing H-A-761's reading at the kept revision,
// which stays the revision the record pins, H-A-608). Else it says why, naming both fingerprints and each revision looked at.
func (u *Unfinished) entryOf(branch string, head int64, entries map[string]catalog.CatalogEntry, module string, e UnfinishedEntry) (catalog.CatalogEntry, string, bool) {
hentry, ok := entries[module]
if !ok || hentry.Fp != e.Fingerprint {
@@ -469,13 +469,6 @@ func (u *Unfinished) entryOf(branch string, head int64, entries map[string]catal
}
return catalog.CatalogEntry{}, fmt.Sprintf("%sthe head's revision %d of %s holds it at %q, not at the key's %q, so a newer revision moved it or its entry is gone (H-A-761)", kept, head, branch, hentry.Fp, e.Fingerprint), false
}
if kept := u.keptRevision(e, module); kept > 0 && kept != head && u.Entries != nil {
if kents, ok := u.Entries(branch, kept); ok {
if entry, ok := kents[module]; ok && entry.Fp == e.Fingerprint {
return entry, "", true
}
}
}
return hentry, "", true
}
@@ -647,7 +647,7 @@ func (v Verbs) askOf(p seat.Pipeline, s seat.StepResult, caller string, now time
if s.Seat == wants.Seat && s.Step == seat.StepResultStepValidate {
id = keptAskID(now, p.Pipeline, "", "", seat.StepResultStepValidate, rev)
}
a, err := v.placedAsk(p, s, id, now)
a, err := v.placedAsk(p, s, id, now, true)
if err != nil {
return nil, err
}
@@ -659,7 +659,7 @@ func (v Verbs) askOf(p seat.Pipeline, s seat.StepResult, caller string, now time
// rerun's is (a kept mover's kept revision mixed in), naming s's not-on.
func (v Verbs) DeclinedAsk(p seat.Pipeline, s seat.StepResult, now time.Time) (*Asked, error) {
id := keptAskID(now, p.Pipeline, s.Module, s.Artifact, s.Step+" not on "+strings.Join(s.NotOn, ","), v.keptOf(p.Pipeline)[s.Module])
a, err := v.placedAsk(p, s, id, now)
a, err := v.placedAsk(p, s, id, now, p.EndCount > 0)
if err != nil {
return nil, err
}
@@ -670,9 +670,9 @@ func (v Verbs) DeclinedAsk(p seat.Pipeline, s seat.StepResult, now time.Time) (*
return a, nil
}
// placedAsk is the ask of step s under id: a validate or composition step of the seat mesh-wants built directly for its
// placedAsk is the ask of step s under id (atHead: a rerun, or a mover of an ended pipeline, read at the head and refused where the head no longer holds its fingerprint, design 47 H2 H-A-763 (3), H-A-764; otherwise a kept mover reads its kept revision, H-A-286): a validate or composition step of the seat mesh-wants built directly for its
// mover (H-A-236), any other the one Place makes for it.
func (v Verbs) placedAsk(p seat.Pipeline, s seat.StepResult, id string, now time.Time) (*Asked, error) {
func (v Verbs) placedAsk(p seat.Pipeline, s seat.StepResult, id string, now time.Time, atHead bool) (*Asked, error) {
if v.Starter == nil || v.Starter.Registration == nil || v.Starter.Steps == nil || (v.View == nil && p.Run == "") {
return nil, errors.New("the runner cannot ask a step: it holds no registration or no ask")
}
@@ -708,9 +708,16 @@ func (v Verbs) placedAsk(p seat.Pipeline, s seat.StepResult, id string, now time
} else {
return nil, fmt.Errorf("the catalog half of %s is not held yet: the step is asked when it is", p.Branch)
}
// A kept mover's step is the one placed from the revision it is kept at, under its kept ids (H-A-286).
// A kept mover's step is placed under its kept ids (H-A-286), from the head's entry when that holds the mover at its
// fingerprint, so its build is asked with the newest pins (design 47 H2 H-A-763 (3)); else from the revision it is kept at.
entries, rev := half.Entries, v.keptOf(p.Pipeline)[m.Module]
if rev > 0 {
atHead = atHead && p.Run == ""
if atHead && half.Entries[m.Module].Fp != m.Fingerprint {
// An older fingerprint is never built again after a newer one (design 47 H2 H-A-764 (2), as H-A-761).
return nil, fmt.Errorf("%s of %s is asked again at fingerprint %s, which the head's revision %d of %s no longer holds (it holds %q); its pipeline's revision is %d and its kept revision %d: nothing was asked",
s.Step, m.Module, m.Fingerprint, half.Revision, p.Branch, half.Entries[m.Module].Fp, p.Revision, rev)
}
if rev > 0 && !atHead {
var err error
if entries, err = v.Starter.keptEntries(p.Branch, rev); err != nil {
return nil, fmt.Errorf("revision %d of %s, which %s is kept at, is not read (%v): the step is asked when it is", rev, p.Branch, m.Module, err)