Files
mesh-delivery/modules/mesh-delivery-indexer/internal/index/seed_steps_test.go
T
jschoubben e5bb4fa9bc indexer seed: an unanswering build seat is called once per seed
Later artifacts of a seat that did not answer stay unanswered without a call; one log line says so when the seat first goes unanswered. Per lead answer A-392.

Builds: design 47 G §704, lead answer A-392

Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h
2026-11-14 11:25:20 +01:00

214 lines
10 KiB
Go

package index
import (
"context"
"errors"
"strings"
"testing"
"time"
mcc "git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshconditionsclient"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/nodebuildgo"
"git.novox.be/novox/mesh-sdk/go/seatdef"
)
// Design 47 G §704: the seed asks `steps` of the build seat whose `build` rule matches each artifact, with {module,
// artifact, fingerprint, fetch} from the newest trunk entry; a seat that does not answer holds the seed and, after five
// minutes, is the finding call-unanswered (scope call, id <seat>.steps), cleared when it answers.
func TestTheSeedAsksStepsOfTheBuildSeatsOfTheTrunkEntries(t *testing.T) {
ctx := context.Background()
now := time.Date(2026, 11, 1, 3, 0, 0, 0, time.UTC)
w := newFindings()
ix := &Indexer{Module: testSelf, Findings: w, Heard: newMem(), Revisions: newMemObjects(1 << 20), Now: func() time.Time { return now }}
fp := "src2:" + strings.Repeat("a", 64)
entries := map[string]meshcatalog.CatalogEntry{"avahi": {Module: "avahi", Repository: "novox/r", Commit: "c1", Path: "mods/avahi", Fp: fp, Manifest: map[string]any{},
Artifacts: []meshcatalog.Artifact{{Ref: "avahi:program", Language: "go"}, {Ref: "avahi:image", Language: "go", Kind: "image"}},
Packages: map[string]string{"git.novox.be/novox/mesh-sdk": "c9"},
Inputs: &meshcatalog.EntryInputs{Paths: map[string][]string{"program": {"cmd"}}}}}
rev, objects, err := CatalogRevisionOf(meshcatalog.CatalogRevision{Revision: 3, Kind: "trunk"}, entries)
if err != nil {
t.Fatal(err)
}
if err := KeepRevision(ctx, ix.Revisions, rev, objects); err != nil {
t.Fatal(err)
}
defs := map[string]seatdef.Definition{
"node-build-go": {Acts: []seatdef.ActingRule{{Step: seatdef.StepBuild, On: "go"}}},
"node-build-image": {Acts: []seatdef.ActingRule{{Step: seatdef.StepBuild, On: seatdef.OnKindImage}}},
}
// the image artifact is built by both rules: the language's and the kind's
if _, err := ix.SeedModulesFrom(ctx, defs, nil); err == nil || !strings.Contains(err.Error(), "each build") {
t.Fatalf("two seats building one artifact: %v", err)
}
e := entries["avahi"]
e.Artifacts[1].Language = "dockerfile"
entries["avahi"] = e
rev, objects, _ = CatalogRevisionOf(meshcatalog.CatalogRevision{Revision: 4, Kind: "trunk"}, entries)
if err := KeepRevision(ctx, ix.Revisions, rev, objects); err != nil {
t.Fatal(err)
}
var got []nodebuildgo.StepsInput
goUp := false
call := func(_ context.Context, seat string, in nodebuildgo.StepsInput) (nodebuildgo.StepsAnswer, error) {
got = append(got, in)
if seat == "node-build-go" && !goUp {
return nodebuildgo.StepsAnswer{}, errors.New("no responders")
}
return nodebuildgo.StepsAnswer{Steps: []nodebuildgo.DetectedStep{{Step: "unit"}}}, nil
}
mods, err := ix.SeedModulesFrom(ctx, defs, call)
if err != nil {
t.Fatal(err)
}
if len(mods) != 1 || mods[0].Module != "avahi" || mods[0].Origin != "novox/r" || mods[0].Path != "mods/avahi/module.json" || len(mods[0].Artifacts) != 2 {
t.Fatalf("the seed's modules: %+v", mods)
}
if a := mods[0].Artifacts[0]; a.Answered || a.Seat != "node-build-go" {
t.Errorf("the go artifact is %+v, want unanswered by node-build-go", a)
}
if a := mods[0].Artifacts[1]; !a.Answered || a.Seat != "node-build-image" || len(a.Steps) != 1 {
t.Errorf("the image artifact is %+v", a)
}
in := got[0]
if in.Module != "avahi" || in.Artifact != "avahi.program" || in.Fingerprint != fp || in.Fetch == nil || in.Fetch.Repository != "novox/r" || in.Fetch.Commit != "c1" || in.Fetch.Dir != "mods/avahi" || len(in.Fetch.Paths) != 1 || in.Fetch.Packages["git.novox.be/novox/mesh-sdk"] != "c9" {
t.Errorf("the steps input is %+v", in)
}
if len(w.Held()) != 0 {
t.Fatal("a call unanswered for no time wrote its finding")
}
now = now.Add(5 * time.Minute)
ix = &Indexer{Module: testSelf, Findings: w, Heard: ix.Heard, Revisions: ix.Revisions, Now: func() time.Time { return now }} // a restart keeps the time
if _, err := ix.SeedModulesFrom(ctx, defs, call); err != nil {
t.Fatal(err)
}
if h := w.Held(); len(h) != 1 || h[0].Scope != mcc.ScopeCall || h[0].ID != "node-build-go.steps" || h[0].Kind != mcc.KindCallUnanswered {
t.Fatalf("the findings after five minutes: %+v", h)
}
goUp = true
if _, err := ix.SeedModulesFrom(ctx, defs, call); err != nil {
t.Fatal(err)
}
if len(w.Held()) != 0 {
t.Errorf("the finding stands after the seat answered: %+v", w.Held())
}
}
// Design 47 G A-324, A-329: an archive and an upstream artifact, which the builder packs or fetches, are called of no build
// seat and seeded with lint, unit and integration bypass; a module with an artifact no build seat builds is left out of
// the seed, named in its ask, with the finding seed-left-out naming the artifact and its language, never the whole seed;
// the finding clears only once a build seat builds every artifact of it, or once it left the catalogue.
func TestTheSeedBypassesWhatTheBuilderPacksAndLeavesOutAModuleNoSeatBuilds(t *testing.T) {
ctx := context.Background()
w := newFindings()
ix := &Indexer{Module: testSelf, Findings: w, Heard: newMem(), Revisions: newMemObjects(1 << 20), Now: time.Now}
entries := map[string]meshcatalog.CatalogEntry{
"a": {Module: "a", Repository: "novox/a", Path: "a", Manifest: map[string]any{}, Artifacts: []meshcatalog.Artifact{{Ref: "a:files", Kind: "archive"}}},
"nats": {Module: "nats", Repository: "novox/n", Path: "n", Manifest: map[string]any{}, Artifacts: []meshcatalog.Artifact{{Ref: "nats:server", Kind: "upstream"}, {Ref: "nats:tools", Language: "go"}}},
"odd": {Module: "odd", Repository: "novox/o", Path: "o", Manifest: map[string]any{}, Artifacts: []meshcatalog.Artifact{{Ref: "odd:web", Language: "rust"}}},
}
keep := func(n int64) {
rev, objects, err := CatalogRevisionOf(meshcatalog.CatalogRevision{Revision: n, Kind: "trunk"}, entries)
if err != nil {
t.Fatal(err)
}
if err := KeepRevision(ctx, ix.Revisions, rev, objects); err != nil {
t.Fatal(err)
}
}
keep(1)
defs := map[string]seatdef.Definition{"node-build-go": {Acts: []seatdef.ActingRule{{Step: seatdef.StepBuild, On: "go"}}}}
var called []string
call := func(_ context.Context, seat string, in nodebuildgo.StepsInput) (nodebuildgo.StepsAnswer, error) {
called = append(called, seat+" "+in.Artifact)
return nodebuildgo.StepsAnswer{Steps: []nodebuildgo.DetectedStep{{Step: "unit"}}}, nil
}
mods, err := ix.SeedModulesFrom(ctx, defs, call)
if err != nil {
t.Fatal(err)
}
if strings.Join(called, "|") != "node-build-go nats.tools" {
t.Errorf("steps was called %q, want only of the go artifact", called)
}
if h := w.Held(); len(h) != 1 || h[0].Kind != SeedLeftOutKind || h[0].Scope != mcc.ScopeModule || h[0].ID != "odd" || !strings.Contains(h[0].Summary, "odd:web (language rust)") {
t.Fatalf("the findings: %+v", h)
}
seed, err := newRegRig().r.ComposeSeed(mods)
if err != nil || len(seed.Unanswered) != 0 || len(seed.Registrations) != 2 || len(seed.Left) != 1 || !strings.Contains(seed.Left[0], "odd (no build seat builds odd:web (language rust))") {
t.Fatalf("the seed: %+v, %v", seed, err)
}
bypass := meshcatalog.StepStatuses{Lint: "bypass", Unit: "bypass", Integration: "bypass"}
if a := seed.Registrations[0].Policy.Artifacts["files"]; seed.Registrations[0].Module != "a" || a != bypass {
t.Errorf("the archive's statuses are %+v in %s, want all three bypass", a, seed.Registrations[0].Module)
}
if p := seed.Registrations[1].Policy.Artifacts; p["server"] != bypass || p["tools"] != (meshcatalog.StepStatuses{Lint: "bypass", Integration: "bypass"}) {
t.Errorf("nats's statuses are %+v", p)
}
// A seed again with the language still unserved keeps the finding; once a seat builds it, it clears.
if _, err := ix.SeedModulesFrom(ctx, defs, call); err != nil || len(w.Held()) != 1 {
t.Fatalf("a second seed: %v, %+v", err, w.Held())
}
defs["node-build-rust"] = seatdef.Definition{Acts: []seatdef.ActingRule{{Step: seatdef.StepBuild, On: "rust"}}}
if _, err := ix.SeedModulesFrom(ctx, defs, call); err != nil || len(w.Held()) != 0 {
t.Fatalf("the seed with a rust build seat: %v, the findings %+v", err, w.Held())
}
// A module left out that leaves the catalogue clears its finding too.
delete(defs, "node-build-rust")
if _, err := ix.SeedModulesFrom(ctx, defs, call); err != nil || len(w.Held()) != 1 {
t.Fatalf("the seed without the rust seat again: %v, %+v", err, w.Held())
}
delete(entries, "odd")
keep(2)
if _, err := ix.SeedModulesFrom(ctx, defs, call); err != nil || len(w.Held()) != 0 {
t.Fatalf("the seed after odd left the catalogue: %v, the findings %+v", err, w.Held())
}
}
// Lead answer A-392: a seat that did not answer steps is called once in a seed; its later artifacts stay unanswered
// without a call, and an answering seat is called per artifact.
func TestTheSeedCallsAnUnansweringSeatOnce(t *testing.T) {
for _, tc := range []struct {
name string
up bool
wantCalls int
}{{"a seat that does not answer", false, 1}, {"a seat that answers", true, 3}} {
t.Run(tc.name, func(t *testing.T) {
ctx := context.Background()
ix := &Indexer{Module: testSelf, Findings: newFindings(), Heard: newMem(), Revisions: newMemObjects(1 << 20), Now: time.Now}
entries := map[string]meshcatalog.CatalogEntry{}
for _, m := range []string{"a", "b", "c"} {
entries[m] = meshcatalog.CatalogEntry{Module: m, Repository: "novox/r", Commit: "c1", Path: "mods/" + m, Fp: "src2:" + strings.Repeat("a", 64),
Manifest: map[string]any{}, Artifacts: []meshcatalog.Artifact{{Ref: m + ":program", Language: "go"}}}
}
rev, objects, err := CatalogRevisionOf(meshcatalog.CatalogRevision{Revision: 1, Kind: "trunk"}, entries)
if err != nil {
t.Fatal(err)
}
if err := KeepRevision(ctx, ix.Revisions, rev, objects); err != nil {
t.Fatal(err)
}
defs := map[string]seatdef.Definition{"node-build-go": {Acts: []seatdef.ActingRule{{Step: seatdef.StepBuild, On: "go"}}}}
calls := 0
call := func(context.Context, string, nodebuildgo.StepsInput) (nodebuildgo.StepsAnswer, error) {
calls++
if !tc.up {
return nodebuildgo.StepsAnswer{}, errors.New("no responders")
}
return nodebuildgo.StepsAnswer{}, nil
}
mods, err := ix.SeedModulesFrom(ctx, defs, call)
if err != nil {
t.Fatal(err)
}
if calls != tc.wantCalls {
t.Errorf("calls = %d, want %d", calls, tc.wantCalls)
}
for _, m := range mods {
if a := m.Artifacts[0]; a.Answered != tc.up || a.Seat != "node-build-go" {
t.Errorf("%s: %+v", m.Module, a)
}
}
})
}
}