ADR 0593 §11: the controller's repository holds nothing that builds once route-proxy moves, so its sibling rule goes; its tests fold into the sibling test, which now uses mesh-sdk's rule. Claude-Session: https://claude.ai/code/session_01NcbgfJ9Gum47zkFKWRaovL
179 lines
8.2 KiB
Go
179 lines
8.2 KiB
Go
package check
|
|
|
|
import (
|
|
"maps"
|
|
"slices"
|
|
"strings"
|
|
"testing"
|
|
|
|
"git.novox.be/novox/mesh-sdk/go/buildstep"
|
|
"git.novox.be/novox/mesh-sdk/go/delivery"
|
|
)
|
|
|
|
// published is the latest published version of each mesh package, as the indexer's modules say (Examiner.Published).
|
|
type published delivery.PackageVersions
|
|
|
|
func (p published) LatestPackages() delivery.PackageVersions {
|
|
return maps.Clone(delivery.PackageVersions(p))
|
|
}
|
|
|
|
// packagesOfFetch is the package versions the fetch of repository was handed (delivery.StepAsk.Packages, issue 1585).
|
|
func packagesOfFetch(t *testing.T, b *bench, repository string) delivery.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 != delivery.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 != delivery.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)
|
|
}
|
|
}
|
|
|
|
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 = "novox/mesh-catalog", "novox/mesh-host", "novox/mesh-controller"
|
|
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 || c.Ref != "refs/pull/12/head" {
|
|
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)
|
|
}
|
|
// Alone, mesh-sdk's tests read the catalogue's trunk, and the verdict names it.
|
|
b = newBench(t)
|
|
b.ex.Trunks = trunksOf(t, map[string]string{SDKRepository: trunkS, catalogue: trunkA, host: 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)
|
|
}
|
|
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.
|
|
func TestACatalogueChangeHasTheCatalogueBesideItAtItsTrunk(t *testing.T) {
|
|
b := newBench(t)
|
|
b.ex.Trunks = trunksOf(t, map[string]string{catalogueRepository: trunkA, SDKRepository: trunkS, "novox/mesh-controller": trunkA2})
|
|
out := b.judge(t, caseOf(t, pullOf(catalogueRepository, 12, head1)))
|
|
// ADR 0548 §6: the outcome names the siblings read at their trunk's head, never the repository it merges.
|
|
if out.Beside[SDKRepository] != trunkS || out.Beside["novox/mesh-controller"] != "" || out.Beside[catalogueRepository] != "" {
|
|
t.Errorf("the siblings named for the verdict = %v, want mesh-sdk at its trunk 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)
|
|
}
|
|
if _, ok := got[SDKRepository]; !ok {
|
|
t.Errorf("mesh-sdk is no longer beside a catalogue change: %v", got)
|
|
}
|
|
}
|
|
|
|
// 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 := delivery.DecodeCandidate(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 != delivery.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)
|
|
}
|
|
}
|