Files
mesh-delivery/modules/mesh-delivery-checker/internal/check/pins_test.go
T
jschoubben 84bcdb687a BL18: build modules found through their build seats' holders on the seat list
The builder finds a build module as the indexer's seed does: the build seat whose acting rule
`build` has an `on` matching the artifact's language or kind:image, and that seat's holder, read
from the seat list's definitions and the claims of the catalog half's manifests. Task.Module, every
lane key, the unpublished modules, the toolchain sources, the ends watched, the sayer and
builder_stuck (through `<seat>.steps`) derive from it; the floor's sources are the holders of the
seats git and mesh-catalog. buildrun.GoBuildModule, NodeBuildModule, LanguageOf,
buildstep.BuildModuleOf use, build.ImageBuildModule and StuckBuildModules are gone from the builder
(the checker keeps its own names in two small files until its part reads them from the list).

Builds: design 47 G §7, §428, §704, §204, A-82
Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h
2026-11-12 00:04:34 +01:00

302 lines
16 KiB
Go

package check
import (
"context"
"maps"
"slices"
"strings"
"testing"
"git.novox.be/novox/mesh-delivery/contracts/go/clients/meshdeliverycheckerclient"
"git.novox.be/novox/mesh-delivery/contracts/go/seats/meshcatalog"
"git.novox.be/novox/mesh-delivery/sdk/buildstep"
"git.novox.be/novox/mesh-delivery/sdk/grouppackages"
"git.novox.be/novox/mesh-sdk/go/catalogue"
)
// published is the latest published version of each mesh package, as the indexer's modules say (Examiner.Published).
type published buildstep.PackageVersions
func (p published) LatestPackages() buildstep.PackageVersions {
return maps.Clone(buildstep.PackageVersions(p))
}
// packagesOfFetch is the package versions the fetch of repository was handed (buildstep.StepAsk.Packages, issue 1585).
func packagesOfFetch(t *testing.T, b *bench, repository string) buildstep.PackageVersions {
t.Helper()
for _, f := range b.steps.tool("fetch") {
if f.args["repository"] == repository {
p, err := buildstep.PackagesArg(f.args["packages"])
if err != nil {
t.Fatal(err)
}
return p
}
}
t.Fatalf("%s was not fetched", repository)
return nil
}
// ADR 0573 §4 (issue 1585 S14): a group's Go member is built against the head of the group's mesh-sdk member, whatever its
// go.mod names (an older head of it included, which issue 1624's pin check refused), and never refused for its pin; a
// pull request alone is built against the latest published version of each package, and its own repository's packages
// come with its tree.
func TestAGroupMemberIsBuiltAgainstTheSDKMembersHeadWhateverItsGoModNames(t *testing.T) { // 1624/AC2, AC4 as ADR 0573 §4 changes them
const contract = "git.novox.be/novox/mesh-delivery/contract"
b := newBench(t)
b.fetch.Modules = []string{"modules/m"}
b.ex.Published = published{SDKModulePath: trunkS, contract: trunkA}
v := b.judge(t, caseOf(t, pullOf(repoA, 7, head1), pullOf(repoSDK, 12, head2))).Verdict
if v.State != meshdeliverycheckerclient.VerdictPass {
t.Fatalf("verdict = %+v", v)
}
if got := packagesOfFetch(t, b, repoA); len(got) != 1 || got[SDKModulePath] != head2 {
t.Errorf("the member's packages = %v, want mesh-sdk at the group's head %s alone (its own contract comes with its tree)", got, head2)
}
if s := besideOf(t, b, repoA)[repoSDK]; s.Commit != head2 {
t.Error("mesh-delivery's tests were not given the SDK member at its head")
}
b = newBench(t)
b.ex.Published = published{SDKModulePath: trunkS, contract: trunkA}
if v := b.judge(t, caseOf(t, pullOf("novox/mesh-catalog", 7, head1))).Verdict; v.State != meshdeliverycheckerclient.VerdictPass {
t.Fatalf("a pull request alone: verdict = %+v", v)
}
if got := packagesOfFetch(t, b, "novox/mesh-catalog"); len(got) != 2 || got[SDKModulePath] != trunkS || got[contract] != trunkA {
t.Errorf("a pull request alone is built against %v, want every package at its latest published version", got)
}
// A member that publishes no package yet is still named, by its root module path, at its head (issue 1921).
b = newBench(t)
b.ex.Published = published{}
if v := b.judge(t, caseOf(t, pullOf(repoA, 7, head1), pullOf("novox/mesh-host", 8, head2))).Verdict; v.State != meshdeliverycheckerclient.VerdictPass {
t.Fatalf("an unpublished member: verdict = %+v", v)
}
if got := packagesOfFetch(t, b, repoA); len(got) != 1 || got["git.novox.be/novox/mesh-host"] != head2 {
t.Errorf("the member's packages = %v, want the unpublished member's root at its head %s alone", got, head2)
}
// The function every producer takes the versions from (issue 1921): rows for what a build at a group's heads is asked.
h := func(c string) string { return strings.Repeat(c, 40) }
const (
contractsPkg = "git.novox.be/novox/mesh-contracts/go/clients/assignerclient"
toolsPkg = "git.novox.be/novox/mesh-tools/go/x"
)
for _, tc := range []struct {
name string
latest buildstep.PackageVersions
heads map[string]string
own string
want buildstep.PackageVersions
}{
{"none", nil, nil, "novox/mesh-host", nil},
{"trunk latest alone", buildstep.PackageVersions{toolsPkg: h("a")}, nil, "novox/mesh-host", buildstep.PackageVersions{toolsPkg: h("a")}},
{"a member at its head replaces the latest", buildstep.PackageVersions{SDKModulePath: h("a")}, map[string]string{SDKRepository: h("b")}, "novox/mesh-host",
buildstep.PackageVersions{SDKModulePath: h("b")}},
{"a member that publishes no package yet is named by its root module", buildstep.PackageVersions{SDKModulePath: h("a")},
map[string]string{"novox/mesh-contracts": h("c")}, "novox/mesh-host",
buildstep.PackageVersions{SDKModulePath: h("a"), "git.novox.be/novox/mesh-contracts": h("c")}},
{"mesh-sdk is named by its go module before any package of it is known", nil, map[string]string{SDKRepository: h("b")}, "novox/mesh-host",
buildstep.PackageVersions{SDKModulePath: h("b")}},
{"a member whose packages are known gets no root", buildstep.PackageVersions{contractsPkg: h("a")},
map[string]string{"novox/mesh-contracts": h("c")}, "novox/mesh-host", buildstep.PackageVersions{contractsPkg: h("c")}},
{"the build's own repository is left out", buildstep.PackageVersions{contractsPkg: h("a")},
map[string]string{"novox/mesh-contracts": h("c")}, "novox/mesh-contracts", nil},
{"a head that is no full commit names nothing", nil, map[string]string{"novox/mesh-contracts": "abc"}, "novox/mesh-host", nil},
} {
got := grouppackages.Heads(tc.latest, tc.heads, tc.own)
if !maps.Equal(got, tc.want) {
t.Errorf("%s: got %v, want %v", tc.name, got, tc.want)
}
}
// Design 47 G §528: a group's check asks no tagged version and waits on none; it builds its members at once, each Go
// build against the group's heads.
sdk := catalogue.Manifest{Module: "mesh-sdk", Build: &catalogue.Build{Artifacts: []catalogue.Artifact{
{Name: "go", Kind: catalogue.ArtifactPackage, Language: "go", Paths: []string{"go"}}, {Name: "lib", Kind: catalogue.ArtifactPackage, Language: "typescript"}}}}
digest := strings.Repeat("c", 64)
sdkPull := pullOf(repoSDK, 12, head2)
sdkPull.Modules = []string{"mesh-sdk"}
sdkPull.Fps = map[string]meshcatalog.CandidatesByGroupValuePullsItemFpsValue{"mesh-sdk": {Fp2: "src2:" + strings.Repeat("f", 64), Manifest: digest}}
b = newBench(t)
b.fetch.Modules = []string{"modules/m"}
b.ex.Read = fixedManifests{digest: sdk}
b.ex.Modules = langs{repoA: {goBuildModule, nodeBuildModule}}
if v := b.judge(t, caseOf(t, pullOf(repoA, 7, head1), sdkPull)).Verdict; v.State != meshdeliverycheckerclient.VerdictPass {
t.Errorf("a group's verdict = %+v", v)
}
if got := packagesOfFetch(t, b, repoA); got[SDKModulePath] != head2 {
t.Errorf("mesh-delivery is built against mesh-sdk %q, want the group's head %s (all: %v)", got[SDKModulePath], head2, got)
}
}
// headFiles are the forge's files by "<repository> <path> <ref>"; any other is not found.
type headFiles map[string]string
func (h headFiles) File(_ context.Context, repository, path, ref string) (string, error) {
if text, ok := h[repository+" "+path+" "+ref]; ok {
return text, nil
}
return "", ErrNotFound
}
type runsAt map[string]string
func (r runsAt) CommitOf(module string) string { return r[module] }
func besideOf(t *testing.T, b *bench, repository string) map[string]BesideRef {
t.Helper()
out := map[string]BesideRef{}
for _, f := range b.steps.tool("fetch") {
if f.args["repository"] == repository {
refs, _ := refsOf(f.args["beside"]), true
for _, r := range refs {
out[r.Repository] = r
}
}
}
return out
}
func TestTheSiblingsAreWhereTheTestsStateThem(t *testing.T) { // review D2, ADR 0484 clause 4
const catalogue, host, controller, networking = "novox/mesh-catalog", "novox/mesh-host", "novox/mesh-controller", "novox/mesh-networking"
hostRuns := strings.Repeat("7", 40)
b := newBench(t)
b.ex.Trunks = trunksOf(t, map[string]string{SDKRepository: trunkS, catalogue: trunkA, host: trunkA2})
b.ex.Runs = runsAt{"mesh-host": hostRuns}
// A group of mesh-sdk and the catalogue: mesh-sdk's tests read the group's catalogue head, the heads the group merges
// (ADR 0482 §2, ADR 0573 §4; issue 1126: a judge in the group was judged against the catalogue's trunk).
out := b.judge(t, caseOf(t, pullOf(SDKRepository, 7, head1), pullOf(catalogue, 12, head2)))
// ADR 0548 §6, issue 568's own example: the verdict names the node-engine at the commit the mesh runs; the catalogue,
// a member here, is not named.
if out.Beside[host] != hostRuns || out.Beside[catalogue] != "" {
t.Errorf("the siblings named for the verdict = %v, want the node-engine at %s", out.Beside, hostRuns[:12])
}
got := besideOf(t, b, SDKRepository)
if c := got[catalogue]; c.Commit != head2 {
t.Errorf("the catalogue beside mesh-sdk in a group = %+v, want the member's head %s", c, head2)
}
if h := got[host]; h.Commit != hostRuns {
t.Errorf("the node-engine beside mesh-sdk = %+v, want the commit the mesh runs %s", h, hostRuns)
}
// ADR 0593: route-proxy's proofs of a composition moved into the node-engine's tests, which read its manifest in
// mesh-networking: beside a node-engine change, at the group's head when the group holds one, else at its trunk.
b = newBench(t)
b.ex.Trunks = trunksOf(t, map[string]string{SDKRepository: trunkS, catalogue: trunkA, host: trunkA2, networking: trunkA2})
b.judge(t, caseOf(t, pullOf(host, 8, head1), pullOf(networking, 3, head2)))
if n := besideOf(t, b, host)[networking]; n.Commit != head2 {
t.Errorf("mesh-networking beside the node-engine in a group = %+v, want the member's head %s", n, head2)
}
// Alone, mesh-sdk's tests read the catalogue's trunk, and the verdict names it.
b = newBench(t)
const contracts = "novox/mesh-contracts"
b.ex.Trunks = trunksOf(t, map[string]string{SDKRepository: trunkS, catalogue: trunkA, host: trunkA2, contracts: trunkA, DeliveryRepository: trunkA2})
if out := b.judge(t, caseOf(t, pullOf(SDKRepository, 7, head1))); out.Beside[catalogue] != trunkA {
t.Errorf("the siblings named for the verdict alone = %v, want the catalogue at its trunk %s", out.Beside, trunkA)
}
// mesh-sdk's tests compare its bootstrapped seats with their contracts files, read beside it: mesh-contracts and
// mesh-delivery, at their trunks alone (a group try is placed by the same besideFor, so it lays them out the same way).
if got := besideOf(t, b, SDKRepository); got[contracts].Commit != trunkA || got[DeliveryRepository].Commit != trunkA2 {
t.Errorf("beside mesh-sdk alone = %+v, want mesh-contracts at %s and mesh-delivery at %s", got, trunkA, trunkA2)
}
if c := besideOf(t, b, SDKRepository)[catalogue]; c.Commit != trunkA || c.Ref != "" {
t.Errorf("the catalogue beside mesh-sdk alone = %+v, want its trunk %s", c, trunkA)
}
// 1126/B8 (novox/hq ADR 0590, ADR 0593 §11): the controller's repository is emptied and archived, so no repository's
// tests read it and it has no siblings of its own: a pull request of it has only its own trunk beside it.
b = newBench(t)
b.ex.Trunks = trunksOf(t, map[string]string{controller: trunkA, catalogue: trunkS, host: trunkA2, SDKRepository: trunkS})
b.judge(t, caseOf(t, pullOf(controller, 9, head2)))
if got := besideOf(t, b, controller); len(got) != 1 || got[controller].Commit != trunkA {
t.Errorf("beside the controller's own change = %+v, want its own trunk alone", got)
}
for repo, siblings := range besideRules {
if repo == controller || slices.Contains(siblings, controller) {
t.Errorf("the tests of %s read the controller, or it has siblings", repo)
}
}
}
// 1887/A12: the change's own repository is placed beside it at the trunk it is merged onto, for every repository, so a
// shrink-only list test reads the trunk's copy at $MESH_CHECK_BESIDE/<name>.
func TestTheChangesOwnRepositoryIsBesideItAtItsTrunk(t *testing.T) {
b := newBench(t)
b.judge(t, caseOf(t, pullOf(repoA, 7, head1)))
got := besideOf(t, b, repoA)
if own := got[repoA]; own.Commit != trunkA || own.Ref != "" {
t.Fatalf("the repository beside its own change = %+v, want its trunk %s", own, trunkA)
}
}
// 1887/A12: a catalogue change's siblings hold the catalogue itself at the trunk it is merged onto, beside mesh-sdk, so
// the catalogue's shrink-only list tests read $MESH_CHECK_BESIDE/mesh-catalog. And the node-engine at the commit the mesh
// runs (ADR 0593 §7): mesh-build-go's composer test builds the node-engine's composer command from it.
func TestACatalogueChangeHasTheCatalogueBesideItAtItsTrunk(t *testing.T) {
hostRuns := strings.Repeat("7", 40)
b := newBench(t)
b.ex.Trunks = trunksOf(t, map[string]string{catalogueRepository: trunkA, SDKRepository: trunkS, "novox/mesh-controller": trunkA2, nodeEngineRepo: trunkA2,
contractsRepository: trunkA2, deliveryRepository: trunkA2, networkingRepository: trunkA2, "novox/mesh-tools": trunkA2})
b.ex.Runs = runsAt{nodeEngineModule: hostRuns}
// The node-engine's go.mod at the commit the mesh runs: what it requires at the zero version is placed beside too,
// derived, not named in a rule (issue 1921); a version a build wrote, or a package outside the forge, is not.
b.ex.Forge = headFiles{nodeEngineRepo + " go.mod " + hostRuns: "module github.com/novox/mesh-host\n\ngo 1.26\n\nrequire (\n" +
"\tgit.novox.be/novox/mesh-contracts/go/clients/meshmoduleassignerclient v0.0.0-00010101000000-000000000000\n" +
"\tgit.novox.be/novox/mesh-delivery/sdk v0.0.0-00010101000000-000000000000 // indirect\n" +
"\tgit.novox.be/novox/mesh-tools/go v0.1.2\n\tgithub.com/nats-io/nats.go v1.40.0\n)\n\n" +
"require git.novox.be/novox/mesh-networking/modules/mesh-wireguard/go v0.0.0-00010101000000-000000000000\n"}
out := b.judge(t, caseOf(t, pullOf(catalogueRepository, 12, head1)))
// ADR 0548 §6: the outcome names the siblings read at their trunk's head or the commit the mesh runs, never the
// repository it merges.
if out.Beside[SDKRepository] != trunkS || out.Beside[nodeEngineRepo] != hostRuns || out.Beside["novox/mesh-controller"] != "" || out.Beside[catalogueRepository] != "" {
t.Errorf("the siblings named for the verdict = %v, want mesh-sdk at its trunk, the node-engine at the commit the mesh runs, and neither the controller nor the catalogue", out.Beside)
}
got := besideOf(t, b, catalogueRepository)
if c := got[catalogueRepository]; c.Commit != trunkA || c.Ref != "" {
t.Fatalf("the catalogue beside its own change = %+v, want its trunk %s", c, trunkA)
}
// Issue 1921: and every repository the node-engine's composer requires at the zero version, which mesh-build-go's
// composer test builds from what lies beside, with nothing fetched.
for _, repo := range []string{SDKRepository, contractsRepository, deliveryRepository, networkingRepository} {
if _, ok := got[repo]; !ok {
t.Errorf("%s is not beside a catalogue change: %v", repo, got)
}
}
if _, ok := got["novox/mesh-tools"]; ok {
t.Errorf("mesh-tools, required at a version a build wrote, is beside a catalogue change: %v", got)
}
if h := got[nodeEngineRepo]; h.Commit != hostRuns {
t.Errorf("the node-engine beside a catalogue change = %+v, want the commit the mesh runs %s", h, hostRuns)
}
// A group that holds the node-engine is judged against its head, which is what runs after its merge, never the commit
// the mesh runs now; the verdict names it in no carry (it is a member, not read at a trunk or a running commit).
b = newBench(t)
b.ex.Trunks = trunksOf(t, map[string]string{catalogueRepository: trunkA, SDKRepository: trunkS, nodeEngineRepo: trunkA2})
b.ex.Runs = runsAt{nodeEngineModule: hostRuns}
out = b.judge(t, caseOf(t, pullOf(catalogueRepository, 12, head1), pullOf(nodeEngineRepo, 8, head2)))
if h := besideOf(t, b, catalogueRepository)[nodeEngineRepo]; h.Commit != head2 {
t.Errorf("the node-engine beside a catalogue change in a group holding it = %+v, want the member's head %s", h, head2)
}
if out.Beside[nodeEngineRepo] != "" {
t.Errorf("the verdict names the member node-engine in its carry: %v", out.Beside)
}
}
// 1887/A12: a mesh-lab head gets a check: with its trunk known it is judged like any repository, its Go fetch finding
// the nested modules itself.
func TestAMeshLabHeadGetsACheck(t *testing.T) {
const lab = "novox/mesh-lab"
raw := candidateOf(t, "fix/x", pullOf(lab, 3, head1))
c, err := meshcatalog.DecodeCandidatesByGroupValue(raw)
if err != nil {
t.Fatal(err)
}
cs := CaseOf(c, map[string]string{lab: trunkA})
if cs == nil || len(cs.Pulls) != 1 || cs.Pulls[0].Repository != lab || len(cs.Left) != 0 {
t.Fatalf("the case = %+v, want mesh-lab#3 judged", cs)
}
b := newBench(t)
if v := b.judge(t, cs).Verdict; v.State != meshdeliverycheckerclient.VerdictPass {
t.Fatalf("verdict = %+v", v)
}
if fetched := b.steps.tool("fetch"); len(fetched) == 0 || fetched[0].args["repository"] != lab {
t.Fatalf("mesh-lab was not fetched: %+v", fetched)
}
}