Review round 2. The siblings watched main, which is also the default branch, so no test held the alike rule; they now watch stable and the entering module is asserted to watch it. Builds: design 47 H H-A-265, H-A-266
165 lines
9.0 KiB
Go
165 lines
9.0 KiB
Go
package index
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"errors"
|
|
"slices"
|
|
"testing"
|
|
|
|
mcc "git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshconditionsclient"
|
|
mcseat "git.novox.be/novox/mesh-contracts/health-and-repair/go/seats/meshconditions"
|
|
gitseat "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/git"
|
|
|
|
oc "git.novox.be/novox/mesh-contracts/operator-and-conversation/go/seats/operatorchannel"
|
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
|
)
|
|
|
|
// Design 47 H H-A-262, H-A-263, H-A-264 (ADR 0666 §2 read with the operator's rule of 2026-11-14): a module that enters a
|
|
// watched trunk's module graph is registered as the revision is kept, before it is said, with no ask: origin its repository,
|
|
// path its manifest's, the branch its repository's modules watch first alike (else its default branch), the module-wide steps its repository's other modules hold alike (else the
|
|
// seed's) and a per-artifact status only where every sibling naming that artifact holds it identically, said
|
|
// registration-changed. A module registered already is untouched; one with a register proposal pending, one the seed left out
|
|
// and one whose default branch is not read are skipped (H-A-265, H-A-266); a branch that is not the trunk registers none, an indexer
|
|
// holding no registration leaves the first to the seed, and the start registers the current trunk graph's unregistered ones.
|
|
func TestAModuleEnteringTheTrunkGraphIsRegistered(t *testing.T) {
|
|
ctx := context.Background()
|
|
g := newRegRig()
|
|
var order []string
|
|
say := g.r.Say
|
|
g.r.Say = func(ctx context.Context, e meshcatalog.RegistrationChangedEvent) error {
|
|
order = append(order, "registration-changed "+e.Module)
|
|
return say(ctx, e)
|
|
}
|
|
ix := &Indexer{Module: testSelf, Revisions: newMemObjects(1 << 20), Findings: newFindings(), Now: g.r.Now}
|
|
// The seat git's default branches: novox/new's is develop, novox/mixed's trunk, novox/broken's not read (H-A-266).
|
|
g.r.Branch = func(repo, branch string) (gitseat.BranchAnswer, error) {
|
|
switch repo {
|
|
case "novox/new":
|
|
return gitseat.BranchAnswer{Branch: "develop", Repository: repo}, nil
|
|
case "novox/mixed":
|
|
return gitseat.BranchAnswer{Branch: "trunk", Repository: repo}, nil
|
|
case "novox/broken":
|
|
return gitseat.BranchAnswer{}, errors.New("the forge does not answer")
|
|
}
|
|
return gitseat.BranchAnswer{Branch: "main", Repository: repo}, nil
|
|
}
|
|
ix.SayCatalogRevision = func(_ context.Context, e meshcatalog.CatalogRevisionEvent) error {
|
|
order = append(order, "catalog-revision "+e.Branch)
|
|
return nil
|
|
}
|
|
entry := func(module, repo, dir string, artifacts ...string) meshcatalog.CatalogEntry {
|
|
e := meshcatalog.CatalogEntry{Module: module, Repository: repo, Path: dir, Commit: "c1", Manifest: map[string]any{}}
|
|
for _, a := range artifacts {
|
|
e.Artifacts = append(e.Artifacts, meshcatalog.Artifact{Ref: module + ":" + a})
|
|
}
|
|
return e
|
|
}
|
|
keep := func(branch string, src int64, entries ...meshcatalog.CatalogEntry) {
|
|
t.Helper()
|
|
m := map[string]meshcatalog.CatalogEntry{}
|
|
for _, e := range entries {
|
|
m[e.Module] = e
|
|
}
|
|
if err := ix.KeepBranchEntries(ctx, branch, src, m, nil); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
// No registration held: the seed is the first writer, so a kept trunk revision registers nothing (H-A-264 (2)).
|
|
ix.Registry = g.r
|
|
keep("main", 1, entry("core", "novox/c", "go/core", "lib"))
|
|
if regs, _ := g.r.RegistrationsAnswer(ctx, meshcatalog.RegistrationsInput{}); len(regs.Registrations) != 0 {
|
|
t.Fatalf("with no registration held a trunk revision registered %v, want none: the seed writes the first", regs.Registrations)
|
|
}
|
|
|
|
steps := meshcatalog.StepStatuses{Lint: "required", Unit: "required", Integration: "required", Composition: "required", Review: "optional", Approval: "bypass"}
|
|
other := steps
|
|
other.Lint = "optional"
|
|
held := []meshcatalog.Registration{
|
|
{Module: "core", Origin: "novox/c", Path: "go/core/module.json", Branches: []string{"stable"}, Policy: meshcatalog.Policy{Steps: steps,
|
|
Artifacts: map[string]meshcatalog.StepStatuses{"lib": {Integration: "bypass"}, "files": {Lint: "bypass", Unit: "bypass"}}}},
|
|
{Module: "tools", Origin: "novox/c", Path: "go/tools/module.json", Branches: []string{"stable"}, Policy: meshcatalog.Policy{Steps: steps,
|
|
Artifacts: map[string]meshcatalog.StepStatuses{"lib": {Integration: "bypass"}, "files": {Unit: "bypass"}}}},
|
|
{Module: "x1", Origin: "novox/mixed", Path: "x1/module.json", Branches: []string{"main"}, Policy: meshcatalog.Policy{Steps: steps}},
|
|
{Module: "x2", Origin: "novox/mixed", Path: "x2/module.json", Branches: []string{"beta"}, Policy: meshcatalog.Policy{Steps: other}},
|
|
}
|
|
for _, reg := range held {
|
|
if err := g.r.write(ctx, "", Proposal{V: 1, Verb: verbRegister, Module: reg.Module, Caller: "test", State: ProposalOpen}, reg, oc.Warrant{Ask: "test"}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
g.events, order = nil, nil
|
|
// pend has a register proposal pending (H-A-265 (1)); left was left out by the seed (A-324, H-A-265 (2)).
|
|
pending, _ := json.Marshal(Proposal{V: 1, Verb: verbRegister, Module: "pend", Ask: "reg-1", State: ProposalOpen})
|
|
if err := g.r.Proposals.Create(ctx, ProposalKey(verbRegister, "pend", ""), pending); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := ix.Findings.Write(ctx, mcseat.Finding{Scope: mcc.ScopeModule, ID: keyID("left"), Kind: SeedLeftOutKind, Summary: "no build seat builds left:app"}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
// A take-in that lists new modules beside a registered one.
|
|
keep("main", 2, entry("core", "novox/c", "go/core", "lib"), entry("lib2", "novox/c", "go/lib2", "lib", "files", "bin"),
|
|
entry("solo", "novox/new", "solo", "app"), entry("x3", "novox/mixed", "x3"), entry("pend", "novox/c", "go/pend"),
|
|
entry("left", "novox/c", "go/left", "app"), entry("lost", "novox/broken", "lost"))
|
|
got := func(module string) meshcatalog.Registration {
|
|
t.Helper()
|
|
r, found, err := g.r.Registration(ctx, module)
|
|
if err != nil || !found {
|
|
t.Fatalf("%s is not registered (%v)", module, err)
|
|
}
|
|
return r
|
|
}
|
|
lib2 := got("lib2")
|
|
if lib2.Version != 1 || lib2.Origin != "novox/c" || lib2.Path != "go/lib2/module.json" || !slices.Equal(lib2.Branches, []string{"stable"}) {
|
|
t.Errorf("lib2 registered as %+v, want version 1 from novox/c, go/lib2/module.json, watching stable, the branch its siblings watch first alike (H-A-266), not its default branch main", lib2)
|
|
}
|
|
if lib2.Policy.Steps != steps {
|
|
t.Errorf("lib2's steps %+v, want its repository's modules' alike steps %+v (H-A-263)", lib2.Policy.Steps, steps)
|
|
}
|
|
if a := lib2.Policy.Artifacts; len(a) != 1 || a["lib"] != (meshcatalog.StepStatuses{Integration: "bypass"}) {
|
|
t.Errorf("lib2's artifacts %+v, want lib alone, the one status its siblings hold identically (files differs, bin none)", a)
|
|
}
|
|
if solo := got("solo"); solo.Policy.Steps != seedSteps() || len(solo.Policy.Artifacts) != 0 || !slices.Equal(solo.Branches, []string{"develop"}) {
|
|
t.Errorf("solo, alone in its repository, has %+v watching %v, want the seed's default, watching its default branch develop", solo.Policy, solo.Branches)
|
|
}
|
|
if x3 := got("x3"); x3.Policy.Steps != seedSteps() || !slices.Equal(x3.Branches, []string{"trunk"}) {
|
|
t.Errorf("x3, whose siblings' steps and branches differ, has %+v watching %v, want the seed's default, watching the default branch trunk", x3.Policy.Steps, x3.Branches)
|
|
}
|
|
for _, m := range []string{"pend", "left", "lost"} {
|
|
if _, found, _ := g.r.Registration(ctx, m); found {
|
|
t.Errorf("%s was registered, want it skipped: a pending proposal, the seed's left-out, a default branch not read", m)
|
|
}
|
|
}
|
|
if core := got("core"); core.Version != 1 || core.By != "test" {
|
|
t.Errorf("core, registered already, became %+v, want it untouched", core)
|
|
}
|
|
if len(g.asks) != 0 {
|
|
t.Errorf("registering modules entering the graph asked %v, want no ask", g.asks)
|
|
}
|
|
wantOrder := []string{"registration-changed lib2", "registration-changed solo", "registration-changed x3", "catalog-revision main"}
|
|
if !slices.Equal(order, wantOrder) {
|
|
t.Errorf("said %v, want %v: each registration said before the revision", order, wantOrder)
|
|
}
|
|
|
|
// A branch that is not the trunk registers none (H-A-264 (3)); a module that leaves the graph keeps its registration.
|
|
keep("feature", 3, entry("feat", "novox/c", "go/feat", "lib"))
|
|
keep("main", 4, entry("core", "novox/c", "go/core", "lib"))
|
|
if _, found, _ := g.r.Registration(ctx, "feat"); found {
|
|
t.Error("a revision of the branch feature registered feat, want only the trunk's")
|
|
}
|
|
got("lib2")
|
|
|
|
// At the start, a module of the current trunk graph with no registration is registered (H-A-264 (1)); again, none.
|
|
ix.Registry = nil
|
|
keep("main", 5, entry("core", "novox/c", "go/core", "lib"), entry("late", "novox/c", "go/late"))
|
|
ix.Registry = g.r
|
|
if written, err := ix.RegisterTrunkGraph(ctx); err != nil || !slices.Equal(written, []string{"late"}) {
|
|
t.Fatalf("the start registered %v (%v), want late", written, err)
|
|
}
|
|
if written, err := ix.RegisterTrunkGraph(ctx); err != nil || len(written) != 0 {
|
|
t.Errorf("a second start registered %v (%v), want none", written, err)
|
|
}
|
|
}
|