diff --git a/modules/mesh-delivery-checker/checkermsg/checkermsg.go b/modules/mesh-delivery-checker/checkermsg/checkermsg.go deleted file mode 100644 index 978f52f2..00000000 --- a/modules/mesh-delivery-checker/checkermsg/checkermsg.go +++ /dev/null @@ -1,56 +0,0 @@ -// Package checkermsg is the checker's own published layouts (as forgemsg is the forge bridge's): the bodies of its events on the -// stream checks and the answer of its tool checker_tries. It is what the checker says on its stream checks when a whole try (a try of a delivery group, not narrowed -// to a level or to some tests) starts and ends (issue 1921), and what the indexer, which hears it, reads: a try has no pull -// request, so the indexer writes the candidate of its group from the members at their commits, and deletes it at the end. -// The events carry the members, so no part reads the checker's state. -package checkermsg - -import ( - "encoding/json" - "fmt" - - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient" -) - -// The events of the checker's stream checks. -const ( - Started = "try.started" - Ended = "try.ended" -) - -// Member is one repository of the try: the exact commit and the trunk commit it is merged onto. -type Member struct { - Repository string `json:"repository"` - Head string `json:"head"` - Trunk string `json:"trunk"` -} - -// Event is the body of both events: the try, and for Started its members; for Ended the state it ended in. -type Event struct { - ID string `json:"id"` - Members []Member `json:"members,omitempty"` - State string `json:"state,omitempty"` -} - -// Decode reads an event body; a started event names its members. -func Decode(event string, body []byte) (Event, error) { - var e Event - if err := json.Unmarshal(body, &e); err != nil { - return e, err - } - if !meshcatalogclient.IsTryGroup(e.ID) { - return e, fmt.Errorf("%q is not a try's id, try-", e.ID) - } - if event == Started && len(e.Members) == 0 { - return e, fmt.Errorf("the try %s starts with no member", e.ID) - } - return e, nil -} - -// Open is one try that waits or runs, as the checker's tool checker_tries answers it. -type Open struct { - ID string `json:"id"` - State string `json:"state"` - Whole bool `json:"whole"` - Members []Member `json:"members"` -} diff --git a/modules/mesh-delivery-checker/checkermsg/go.mod b/modules/mesh-delivery-checker/checkermsg/go.mod deleted file mode 100644 index 48e0db10..00000000 --- a/modules/mesh-delivery-checker/checkermsg/go.mod +++ /dev/null @@ -1,22 +0,0 @@ -module git.novox.be/novox/mesh-delivery/modules/mesh-delivery-checker/checkermsg - -go 1.26.0 - -require git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient v0.0.0-00010101000000-000000000000 - -require ( - git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog v0.0.0-00010101000000-000000000000 // indirect - git.novox.be/novox/mesh-sdk/go v0.0.0-00010101000000-000000000000 // indirect -) - -require git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshdelivery v0.0.0-00010101000000-000000000000 // indirect - -require ( - git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk v0.0.0-00010101000000-000000000000 // indirect - github.com/klauspost/compress v1.20.1 // indirect - github.com/nats-io/nats.go v1.54.0 // indirect - github.com/nats-io/nkeys v0.4.16 // indirect - github.com/nats-io/nuid v1.0.1 // indirect - golang.org/x/crypto v0.57.0 // indirect - golang.org/x/sys v0.48.0 // indirect -) diff --git a/modules/mesh-delivery-checker/checkermsg/go.sum b/modules/mesh-delivery-checker/checkermsg/go.sum deleted file mode 100644 index 0daef11f..00000000 --- a/modules/mesh-delivery-checker/checkermsg/go.sum +++ /dev/null @@ -1,12 +0,0 @@ -github.com/klauspost/compress v1.20.1 h1:T7kKElXUMXrUJ2E9QhQhxFtcK5rPyLdsGZvdbLMPdiQ= -github.com/klauspost/compress v1.20.1/go.mod h1:LUdAzn7YLVvxLpc7y3V1m40wESHTgc1422pwwBSKYuI= -github.com/nats-io/nats.go v1.54.0 h1:vsXoOxjHp/GmPUN+EcI7uOf/uB+iAP+kEsAFNQN0yzA= -github.com/nats-io/nats.go v1.54.0/go.mod h1:y+DZoD1oBOYfZTU681eTUiUjI0vbqYGixNVFHcjHJ0k= -github.com/nats-io/nkeys v0.4.16 h1:rd5oAuLOb8mnAycB0xleuEBNS1pVVnN0fv/FF34Eypg= -github.com/nats-io/nkeys v0.4.16/go.mod h1:llLgWoI0o4z/Q57q2R1kHfmocyhGV6VG/U18Glg1Afs= -github.com/nats-io/nuid v1.0.1 h1:5iA8DT8V7q8WK2EScv2padNa/rTESc1KdnPw4TC2paw= -github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c= -golang.org/x/crypto v0.57.0 h1:3ZVCjf8Ggz7zneR/EHRVx68Ctf+2pmIMP2UFhh9cC6M= -golang.org/x/crypto v0.57.0/go.mod h1:Fdz0i5U6CoizGwLda9DttjSk6qlZo25zYNtR+ycvuZA= -golang.org/x/sys v0.48.0 h1:bbX/i/6MgT9BVLM9RT1thmxL04yeTAhbEz4SyadbXoo= -golang.org/x/sys v0.48.0/go.mod h1:hNLxWAXmnKAxqDtdwIYC4bM9oQPEecfsnNMuSxOs3og= diff --git a/modules/mesh-delivery-checker/cmd/mesh-checking-program/main.go b/modules/mesh-delivery-checker/cmd/mesh-checking-program/main.go deleted file mode 100644 index fc829bc8..00000000 --- a/modules/mesh-delivery-checker/cmd/mesh-checking-program/main.go +++ /dev/null @@ -1,52 +0,0 @@ -// Command mesh-checking-program is the checker's checking program (novox/hq ADR 0644, ADR 0656; design 47's bootstrap -// delivery): built from a check's heads and run in the build seat's sandbox through the seat node-build-go's ask run, -// with no network and no bus account, it reads the check's facts from the file MESH_RUN_INPUT names and answers the -// verdict the judging rules give them, as one JSON line on its standard output (rules.Answer). -// -// mesh-checking-program -verdict -// mesh-checking-program -seats -// -// Asked -seats, it answers the seat list of the heads laid in the directory MESH_RUN_HEADS names (rules.SeatsAnswer). -// It refuses facts of a version it does not read, naming it, with exit 2. -package main - -import ( - "fmt" - "io" - "io/fs" - "os" - "slices" - - "mesh-delivery-checker/rules" - - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep" -) - -func main() { - os.Exit(run(os.Args[1:], os.Getenv, os.Stdout, os.Stderr)) -} - -// run is the command over its arguments, environment and outputs, answering its exit. -func run(args []string, getenv func(string) string, stdout, stderr io.Writer) int { - var heads fs.FS - if dir := getenv(buildstep.RunHeadsEnv); dir != "" { - heads = os.DirFS(dir) - } - input := func() ([]byte, error) { - file := getenv(buildstep.RunInputEnv) - if file == "" { - return nil, fmt.Errorf("%s names no file", buildstep.RunInputEnv) - } - return os.ReadFile(file) - } - line, err := rules.Program(args, input, heads) - if err != nil { - if heads == nil && slices.Contains(args, "-seats") { - err = fmt.Errorf("no heads: %s names no directory", buildstep.RunHeadsEnv) - } - fmt.Fprintf(stderr, "mesh-checking-program: %v\n", err) - return 2 - } - fmt.Fprintf(stdout, "%s\n", line) - return 0 -} diff --git a/modules/mesh-delivery-checker/cmd/mesh-checking-program/main_test.go b/modules/mesh-delivery-checker/cmd/mesh-checking-program/main_test.go deleted file mode 100644 index 972fa7d8..00000000 --- a/modules/mesh-delivery-checker/cmd/mesh-checking-program/main_test.go +++ /dev/null @@ -1,342 +0,0 @@ -package main - -import ( - "bytes" - "context" - "encoding/json" - "errors" - "io/fs" - "os" - "path" - "path/filepath" - "reflect" - "strings" - "testing" - - "mesh-delivery-checker/rules" - - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshdeliverycheckerclient" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/seatdefs" - "git.novox.be/novox/mesh-sdk/go/seatdef" -) - -// 1921 (B0, D2): the checking program answers, on its last line, the verdict the rules give the facts in its input, and -// refuses facts of a version it does not read, an input it is not given, and a question it is not asked, naming each. -// 1921 (B0, D3): asked -seats, it answers the seat list of the heads laid for it: a definition a head adds, resolved with -// the parts it includes; what it left out, and why; and an empty list for heads with no definition. -func TestTheCheckingProgramAnswersTheVerdictOfItsFacts(t *testing.T) { - failing, _ := json.Marshal(rules.Tested{Level: buildstep.LevelUnit, Tests: 3, Failed: []rules.Failure{{Package: "x/a", Test: "TestA", Cause: "a_test.go:9: boom"}}}) - facts := rules.Facts{V: rules.FactsVersion, Group: "feat/x", Heads: "0123456789ab", Members: []rules.Member{{Repository: "novox/x", Number: 3, Head: "h"}}, - Steps: []rules.Step{ - {Repository: "novox/x", Number: 3, Module: "mesh-build-go", Node: "laptop", Level: &buildstep.LevelAnswer{Level: buildstep.LevelUnit, Tests: []json.RawMessage{failing}}}, - {Repository: "novox/x", Number: 3, Failed: &rules.FailedFirst{Machine: "laptop", Words: "novox/x#3 has files in conflict: go.mod"}}, - }} - dir := t.TempDir() - write := func(name string, v any) string { - data, _ := json.Marshal(v) - p := filepath.Join(dir, name) - if err := os.WriteFile(p, data, 0o600); err != nil { - t.Fatal(err) - } - return p - } - v1 := write("v1.json", facts) - later := facts - later.V = rules.FactsVersion + 1 - v2 := write("v2.json", later) - // The heads as the build node lays them, each at its repository's path: a contracts module of its own defining a seat - // with a part, and the mesh's own contracts module defining a seat of a domain that is not its (ADR 0636 §5). - lay := func(name string, files map[string]string) string { - root := filepath.Join(dir, name) - for p, body := range files { - if err := os.MkdirAll(filepath.Dir(filepath.Join(root, p)), 0o755); err != nil { - t.Fatal(err) - } - if err := os.WriteFile(filepath.Join(root, p), []byte(body), 0o600); err != nil { - t.Fatal(err) - } - } - return root - } - contracts := func(module string) string { - return `{"module": "` + module + `", "build": {"artifacts": [{"name": "go", "kind": "package", "language": "go", "generated-from": "."}]}}` - } - heads := lay("heads", map[string]string{ - "novox/x/x-contracts/module.json": contracts("x-contracts"), - "novox/x/x-contracts/seats/node-build-x/seat.json": `{"format":1,"seat":"node-build-x","scope":"node","grain":"whole","domain":"Delivery","decision":"ADR 1","description":"kept","includes":["build"],"verbs":[{"name":"own","input":{"type":"object","properties":{"credentials":{"$ref":"#/defs/Sealed"}}},"answer":{"type":"object"}}],"defs":{"Sealed":{"type":"object"}}}`, - "novox/x/x-contracts/parts/build.json": `{"format":1,"part":"build","verbs":[{"name":"current","input":{"type":"object"},"answer":{"type":"object"}}],"events":[{"name":"ended","body":{"type":"object"}}]}`, - "novox/x/contracts/module.json": contracts("mesh-contracts"), - "novox/x/contracts/seats/mesh-catalog/seat.json": `{"format":1,"seat":"mesh-catalog","scope":"mesh","grain":"whole","domain":"Delivery","decision":"ADR 1"}`, - }) - broken := lay("broken", map[string]string{ - "novox/x/x-contracts/module.json": contracts("x-contracts"), - "novox/x/x-contracts/seats/broken/seat.json": `{"format":1,"seat":"broken","scope":"nowhere"}`, - }) - none := filepath.Join(dir, "no-heads") - if err := os.MkdirAll(filepath.Join(none, "novox/x"), 0o755); err != nil { - t.Fatal(err) - } - for name, c := range map[string]struct { - args []string - input, heads string - exit int - said string - }{ - "the seats": {args: []string{"-seats"}, input: v1, heads: heads}, - "no seats": {args: []string{"-seats"}, input: v1, heads: none}, - "a seat unparsed": {args: []string{"-seats"}, input: v1, heads: broken, exit: 2, said: "the seat definition of broken (module x-contracts) at the head of novox/x is not taken"}, - "no heads laid": {args: []string{"-seats"}, exit: 2, said: buildstep.RunHeadsEnv + " names no directory"}, - "the facts": {args: []string{"-verdict"}, input: v1}, - "a later version": {args: []string{"-verdict"}, input: v2, exit: 2, said: "facts of version 2, this checking program reads version 1"}, - "no input": {args: []string{"-verdict"}, exit: 2, said: buildstep.RunInputEnv + " names no file"}, - "nothing asked": {input: v1, exit: 2, said: "nothing asked"}, - "an unknown asking": {args: []string{"-judge"}, input: v1, exit: 2, said: "-judge"}, - } { - var out, errs bytes.Buffer - exit := run(c.args, func(k string) string { - switch k { - case buildstep.RunInputEnv: - return c.input - case buildstep.RunHeadsEnv: - return c.heads - } - return "" - }, &out, &errs) - if exit != c.exit || !strings.Contains(errs.String(), c.said) { - t.Errorf("%s: exit %d, said %q; want %d and %q", name, exit, errs.String(), c.exit, c.said) - continue - } - if c.exit != 0 { - continue - } - lines := strings.Split(strings.TrimSpace(out.String()), "\n") - if c.heads != "" { - var sa rules.SeatsAnswer - if err := json.Unmarshal([]byte(lines[len(lines)-1]), &sa); err != nil || sa.V != rules.SeatsVersion || sa.Seats == nil { - t.Fatalf("%s: the last line %q: %v", name, lines[len(lines)-1], err) - } - if c.heads == none { - if len(sa.Seats) != 0 || len(sa.Left) != 0 { - t.Errorf("%s: %+v, want an empty list", name, sa) - } - continue - } - var d struct { - Seat string `json:"seat"` - Verbs []struct { - Name string `json:"name"` - } `json:"verbs"` - } - if len(sa.Seats) == 1 { - _ = json.Unmarshal(sa.Seats[0], &d) - } - if d.Seat != "node-build-x" || len(d.Verbs) != 2 || len(sa.Left) != 1 || !strings.Contains(sa.Left[0].Why, "whose seats mesh-delivery-contracts defines") { - t.Errorf("%s: seats %s, left %+v; want node-build-x with its part's verb, and mesh-catalog left out", name, sa.Seats, sa.Left) - } - // The group check of 616c42434ac2: a checker from before G (no digests in these facts) writes the answer into the - // build seat's step state, whose writer refuses a value with a field named like a credential, here a schema's - // property name; the answer carries no verb's or message's schema and no type only they referred to. - if len(sa.Seats) == 1 && (bytes.Contains(sa.Seats[0], []byte("credentials")) || bytes.Contains(sa.Seats[0], []byte("Sealed"))) { - t.Errorf("%s: %s carries a verb's schema to a checker that hands no digests", name, sa.Seats[0]) - } - continue - } - var a rules.Answer - if err := json.Unmarshal([]byte(lines[len(lines)-1]), &a); err != nil || a.V != rules.AnswerVersion { - t.Fatalf("%s: the last line %q: %v", name, lines[len(lines)-1], err) - } - if want := rules.Judge(facts); !reflect.DeepEqual(a.Verdict, want) || a.Verdict.State != meshdeliverycheckerclient.VerdictFail || len(a.Verdict.Failures) != 2 || - a.Verdict.Failures[1].Words != "novox/x#3 has files in conflict: go.mod" || a.Verdict.Machines[0] != "laptop" || a.Verdict.Levels[buildstep.LevelUnit].Run != 3 { - t.Errorf("%s: the verdict %+v, want %+v", name, a.Verdict, want) - } - } - // Review finding 3 of milestone 47/G: the heads of a real group carry every seat definition the reader holds, unchanged - // (this repository's own contracts, laid as its head): the answer leaves them all to the checker's list and stays - // far below the whole list. - t.Run("heads carrying every definition the reader holds unchanged answer none of them", func(t *testing.T) { - real := under{prefix: "novox/mesh-delivery", fs: os.DirFS("../../../..")} - group := rules.Facts{V: rules.FactsVersion, Members: []rules.Member{{Repository: "novox/mesh-delivery", Head: "h"}}} - // An empty list of digests answers every definition whole (a checker that hands its list's digests, holding none). - whole, err := rules.SeatsOf(real, rules.Facts{V: rules.FactsVersion, Members: group.Members, SeatDigests: map[string]string{}}) - if err != nil || len(whole.Seats) < 10 { - t.Fatalf("the repository's own definitions: %d, %v", len(whole.Seats), err) - } - // The reader's digests are of each definition whole, as the seat mesh-catalog answers it; the answer is its judging view. - group.SeatDigests = wholeDigests(t, real, "novox/mesh-delivery") - same, err := rules.SeatsOf(real, group) - answer, _ := json.Marshal(same) - if err != nil || len(same.Seats) != 0 || same.Same != len(whole.Seats) { - t.Errorf("unchanged heads answer %d definitions (%d the same), %d bytes; want none, all %d the same: %v", - len(same.Seats), same.Same, len(answer), len(whole.Seats), err) - } - // Review round 2 of G: a checker from before G (B0's, which makes G's own check) hands no digests, and the answer - // then keeps each seat's own description only, so a group's whole list stays within the bound; each still parses. - b0, err := rules.SeatsOf(real, rules.Facts{V: rules.FactsVersion, Members: group.Members}) - if err != nil || len(b0.Seats) != len(whole.Seats) { - t.Fatalf("B0-shaped facts: %d definitions, %v", len(b0.Seats), err) - } - for i, raw := range b0.Seats { - var own struct { - Description string `json:"description"` - } - _ = json.Unmarshal(whole.Seats[i], &own) - var d struct { - Description string `json:"description"` - Verbs []json.RawMessage `json:"verbs"` - Events []json.RawMessage `json:"events"` - } - _ = json.Unmarshal(raw, &d) - inner := 0 - for _, m := range append(d.Verbs, d.Events...) { - inner += strings.Count(string(m), `"description":"`) - } - parsed, perr := seatdef.Parse(raw) - for _, v := range parsed.Verbs { - if len(v.Input) != 0 || len(v.Answer) != 0 { - t.Errorf("B0-shaped facts answer %s's verb %s with its schemas; want none", parsed.Seat, v.Name) - } - } - for name := range parsed.Defs { - if !bytes.Contains(raw, []byte(`"#/defs/`+name+`"`)) { - t.Errorf("B0-shaped facts answer %s with the type %s, which nothing it keeps refers to", parsed.Seat, name) - } - } - if inner > 0 || d.Description != own.Description || perr != nil { - t.Errorf("B0-shaped facts answer %s with %d inner descriptions, its own %q: %v; want only its own", raw[:min(len(raw), 80)], inner, d.Description, perr) - } - } - if answer, _ := json.Marshal(b0); len(answer) >= len(mustJSON(t, whole))*3/4 { - t.Errorf("B0-shaped facts answer %d bytes (whole %d), want far below the whole", len(answer), len(mustJSON(t, whole))) - } - // One definition the heads change is answered alone. - for seat := range group.SeatDigests { - group.SeatDigests[seat] = "changed" - break - } - if one, err := rules.SeatsOf(real, group); err != nil || len(one.Seats) != 1 { - t.Errorf("one changed definition: answered %d, %v", len(one.Seats), err) - } - }) - // The lead's ruling after G's group check of 616c42434ac2: with digests given too, a changed definition whose verb input - // has a property named credentials is answered as the validator and the composer read it, with no such field. - changed, err := rules.SeatsOf(os.DirFS(heads), rules.Facts{V: rules.FactsVersion, Members: facts.Members, - SeatDigests: map[string]string{"node-build-x": "changed"}}) - if err != nil || len(changed.Seats) != 1 || bytes.Contains(changed.Seats[0], []byte("credentials")) || bytes.Contains(changed.Seats[0], []byte("Sealed")) { - t.Errorf("a changed definition with digests given: %d answered, %s, %v; want it alone, with no verb's schema", len(changed.Seats), changed.Seats, err) - } - // Review round 1 of milestone 47/B0: the module graph's cycle rule is the program's (ADR 0603 §2, ADR 0656 §5), over the - // edges the running checker gathers. A cycle the change makes fails; one the trunk has among the same modules is noted. - web, mail := rules.Edge{From: "web", To: "mail", Kind: rules.EdgeAwaits}, rules.Edge{From: "mail", To: "web", Kind: rules.EdgeAwaits} - only := func(e rules.Edge, where string) rules.Edge { e.Only = where; return e } - for _, row := range []struct { - name string - graph rules.Graph - fails string - note string - }{ - {name: "no cycle", graph: rules.Graph{Trunk: true, Edges: []rules.Edge{web}}, note: "has no cycle"}, - {name: "a cycle the change makes", graph: rules.Graph{Trunk: true, Edges: []rules.Edge{mail, only(web, rules.EdgeChange)}}, fails: "has the cycle mail -> web -> mail"}, - {name: "a cycle the trunk has", graph: rules.Graph{Trunk: true, Edges: []rules.Edge{mail, web}}, note: "which the trunk already has"}, - {name: "the trunk unread", graph: rules.Graph{Edges: []rules.Edge{mail, web}}, fails: "has the cycle mail -> web -> mail"}, - {name: "a base on itself", graph: rules.Graph{Trunk: true, Edges: []rules.Edge{only(rules.Edge{From: "web", To: "web", Kind: rules.EdgeBase}, rules.EdgeChange)}}, fails: "has the cycle web -> web"}, - {name: "an edge only the trunk has", graph: rules.Graph{Trunk: true, Edges: []rules.Edge{mail, only(web, rules.EdgeTrunk)}}, note: "has no cycle"}, - } { - g := row.graph - a := rules.Judged(rules.Facts{V: rules.FactsVersion, Steps: []rules.Step{{Graph: &g}}}) - if row.fails != "" && (a.Verdict.State != meshdeliverycheckerclient.VerdictFail || !strings.Contains(a.Verdict.Failed.Words, row.fails)) { - t.Errorf("%s: verdict %+v, want a fail saying %q", row.name, a.Verdict, row.fails) - } - if row.note != "" && (a.Verdict.State != meshdeliverycheckerclient.VerdictPass || !strings.Contains(strings.Join(a.Notes, "\n"), row.note)) { - t.Errorf("%s: verdict %s, notes %q, want a pass noting %q", row.name, a.Verdict.State, a.Notes, row.note) - } - } -} - -// under is a directory laid at a repository's path of the heads, as the build node lays a head. -type under struct { - prefix string - fs fs.FS -} - -func (u under) Open(name string) (fs.File, error) { - if name == u.prefix { - return u.fs.Open(".") - } - if rest, ok := strings.CutPrefix(name, u.prefix+"/"); ok { - return u.fs.Open(rest) - } - return nil, &fs.PathError{Op: "open", Path: name, Err: fs.ErrNotExist} -} - -func mustJSON(t *testing.T, v any) []byte { - t.Helper() - out, err := json.Marshal(v) - if err != nil { - t.Fatal(err) - } - return out -} - -// wholeDigests are the digests of a head's seat definitions whole (rules.SeatDigest), read by the domain SDK as the -// indexer reads them: what a checker's reader holds for heads that change none. -func wholeDigests(t *testing.T, root fs.FS, repository string) map[string]string { - t.Helper() - head, err := fs.Sub(root, repository) - if err != nil { - t.Fatal(err) - } - manifests := map[string]string{} - _ = fs.WalkDir(head, ".", func(p string, d fs.DirEntry, err error) error { - if err != nil { - return err - } - if d.IsDir() && (d.Name() == ".git" || d.Name() == "testdata" || d.Name() == "node_modules") { - return fs.SkipDir - } - if !d.IsDir() && d.Name() == "module.json" { - raw, _ := fs.ReadFile(head, p) - manifests[path.Dir(p)] = string(raw) - } - return nil - }) - forge := seatdefs.Forge{ - Files: func(_ context.Context, _, _ string, dirs []string) (map[string]map[string]string, error) { - out := map[string]map[string]string{} - for _, dir := range dirs { - files := map[string]string{} - if err := fs.WalkDir(head, dir, func(p string, d fs.DirEntry, err error) error { - if err == nil && !d.IsDir() { - files[strings.TrimPrefix(p, dir+"/")] = "" - } - return err - }); err == nil { - out[dir] = files - } - } - return out, nil - }, - File: func(_ context.Context, _, _, file string) ([]byte, error) { - raw, err := fs.ReadFile(head, file) - if errors.Is(err, fs.ErrNotExist) { - return nil, nil - } - return raw, err - }, - } - out := map[string]string{} - if len(manifests) == 0 { - t.Fatalf("no manifest at the head of %s", repository) - } - for _, c := range seatdefs.ContractsModules(manifests) { - defs, _, err := forge.Read(context.Background(), repository, "h", c) - if err != nil { - t.Fatal(err) - } - for seat, d := range defs { - raw, _ := json.Marshal(d) - out[seat] = rules.SeatDigest(raw) - } - } - return out -} diff --git a/modules/mesh-delivery-checker/cmd/mesh-delivery-checker-tools/main.go b/modules/mesh-delivery-checker/cmd/mesh-delivery-checker-tools/main.go deleted file mode 100644 index eceea22b..00000000 --- a/modules/mesh-delivery-checker/cmd/mesh-delivery-checker-tools/main.go +++ /dev/null @@ -1,575 +0,0 @@ -// Command mesh-delivery-checker-tools serves the checker's read tools (novox/hq ADR 0484 clause 13, issue 1686): the runtime -// launches it for a call, it reads the checker's verdicts and kept states through the checker's state and reads, and the -// indexer's candidates and modules through the indexer's read tools. It writes only the tries (the try's tools) and, asking a check again by hand, one verdict. The checker is the other program: it serves no tool (ADR 0437 §4). -package main - -import ( - "encoding/json" - "fmt" - "os" - "strings" - "sync/atomic" - "time" - - "mesh-delivery-checker/internal/check" - - "git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshhandactsclient" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-builder/buildrun" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient" - "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/meshdeliverychecker" - stdio "git.novox.be/novox/mesh-sdk/go" - "git.novox.be/novox/mesh-sdk/go/buscalls" - "git.novox.be/novox/mesh-sdk/go/seatdef" - "git.novox.be/novox/mesh-sdk/go/seatlist" - "git.novox.be/novox/mesh-sdk/go/views" -) - -// reads counts the values this call read from the bus: the runtime launches the tools for one call, so the count is the call's. -var reads atomic.Int64 - -// cutAnswer says in the answer that it was cut, and how to narrow it. -func cutAnswer(answer map[string]any, cut string) map[string]any { - if cut != "" { - answer["cut"], answer["note"] = true, cut - } - return answer -} - -// logged runs every tool with one line to stderr per call: the tool, the values it read and the time it took. -func logged(tools []stdio.Tool) []stdio.Tool { - for i := range tools { - name, run := tools[i].Name, tools[i].Run - tools[i].Run = func(args map[string]any) (any, error) { - reads.Store(0) - start := time.Now() - out, err := run(args) - fmt.Fprintf(os.Stderr, "[mesh-delivery-checker-tools] %s read %d values in %s (error: %v)\n", name, reads.Load(), time.Since(start).Round(time.Millisecond), err) - return out, err - } - } - return tools -} - -func read(s stdio.KeptState) check.StateRead { - return check.StateRead{Keys: s.Keys, Get: func(key string) (json.RawMessage, error) { - reads.Add(1) - e, err := s.Get(key) - if err != nil || e == nil { - return nil, err - } - return e.Value, nil - }} -} - -// ownerRead is a state of another module read through that module's ordinary read tool (views.ReadTool), asked through ask -// (stdio.Ask, or a test's): its keys with no argument, one key's value with key. Another module's data is asked through its -// tools, never read from its bus state (novox/hq ADR 0596); the manifest invokes the tool, and the owner answers every reader -// that invokes it. Each read is asked when it is read: the owner's state is the truth, and the tools keep no copy. -func ownerRead(ask func(string, any) (json.RawMessage, error), tool string) check.StateRead { - call := func(args map[string]any, into any) error { - reads.Add(1) - raw, err := ask(tool, args) - if err != nil { - return fmt.Errorf("%s does not answer: %w", tool, err) - } - answer, said, ok := buscalls.Unwrap(raw) - if !ok { - return fmt.Errorf("%s answered: %s", tool, said) - } - if err := json.Unmarshal(answer, into); err != nil { - return fmt.Errorf("%s answered what does not decode: %w", tool, err) - } - return nil - } - return check.StateRead{ - Keys: func() ([]string, error) { - var a views.ReadAnswer - if err := call(map[string]any{}, &a); err != nil { - return nil, err - } - return a.Keys, nil - }, - Get: func(key string) (json.RawMessage, error) { - var a views.KeyAnswer - if err := call(map[string]any{"key": key}, &a); err != nil { - return nil, err - } - if !a.Found { - return nil, nil - } - return a.Value, nil - }} -} - -// The indexer's read tools the tools ask for its candidates and modules (the manifest's invokes name them under the indexer's -// module; the call goes to the holder of the seat mesh-catalog, atHolder). -const ( - indexerCandidatesTool = "indexer_read_candidates" - indexerModulesTool = "indexer_read_modules" -) - -// atHolder asks a tool of the module that holds the seat when it is asked (design 47 G A-210, §428), as the view's tools do: -// the holder is found by the seat list for each call, and a seat with no holder is an error that says so. -func atHolder(ask func(string, any) (json.RawMessage, error), holder func(seat string) (string, bool), seat string) func(string, any) (json.RawMessage, error) { - return func(tool string, body any) (json.RawMessage, error) { - module, ok := holder(seat) - if !ok { - return nil, fmt.Errorf("the holder of %s is not found, so %s is not asked", seat, tool) - } - return ask(module+"."+tool, body) - } -} - -// runsOf says which commit the mesh runs of a module from the indexer's modules state, as the checker's own record of it does -// (the commit the module's record was computed at); "" when the record is not readable. -type runsOf struct{ modules check.StateRead } - -func (r runsOf) CommitOf(module string) string { - if r.modules.Get == nil { - return "" - } - raw, err := r.modules.Get(module) - if err != nil || len(raw) == 0 { - return "" - } - m, err := meshcatalogclient.DecodeModule(raw) - if err != nil { - return "" - } - return m.Commit -} - -// stateStore is a state the tools write: the tries. -type stateStore struct { - check.StateRead - create func(key string, value []byte) error - entry func(key string) (json.RawMessage, uint64, error) - update func(key string, value []byte, revision uint64) error -} - -func (s stateStore) Entry(key string) (json.RawMessage, uint64, error) { return s.entry(key) } -func (s stateStore) Update(key string, value []byte, revision uint64) error { - return s.update(key, value, revision) -} - -func (s stateStore) Keys() ([]string, error) { return s.StateRead.Keys() } -func (s stateStore) Get(key string) (json.RawMessage, error) { return s.StateRead.Get(key) } -func (s stateStore) Create(key string, value []byte) error { return s.create(key, value) } - -// Trying is what the try's tools work on: the tries, and the gate's trunk heads. -type Trying struct { - Tries check.TryStore - Ender check.TryEnder - Trunks func() (map[string]string, error) - Now func() time.Time -} - -// TryTools are the try's tools (ADR 0501 §5): ask one, read one, and end one by hand (issue 734). mesh-controller's try calls them. -func TryTools(tr Trying) []stdio.Tool { - str := func(args map[string]any, k string) string { s, _ := args[k].(string); return s } - return []stdio.Tool{ - {Name: check.TryTool, - Description: "Try a delivery group, or one pushed head, before its pull requests are opened (try a group, group try, try several repositories): " + - "name the members, each a repository and the exact commit asked (never the branch's head now, so a push after the ask changes nothing of what is tried), " + - "or one repository and its head for a try of one member (the seat verb try of mesh-delivery-checker takes the same members, ADR 0637 §6). The checker judges it by the code a group's pull-request check runs, so the two cannot drift: " + - "each member merged onto its trunk's head, the unit and the integration level of every member through the build modules, the manifest validator over " + - "the members' manifests, the module graph, and the composition on every placed node. Every failure is named (each member, level, test, manifest and node), not " + - "the first. A try owes the forge nothing (no status, no Approve asked) and writes no verdict of a pull request; what its passing levels prove is kept, so a pull request's " + - "check of the same heads on the same trunk runs only what the try did not pass. A try narrowed to a level or to some tests judges only those, no manifest and no composition, and keeps nothing of tests. " + - "Answers the try's id at once; " + check.TryReadTool + " reads where it stands, " + check.TryEndTool + " ends it by hand. A try of the same commits that waits or runs is the answer to a second ask " + - "(whatever the order of the members); at most 4 run on a build node, and 8 wait for one, mesh-wide. A repository the checker checks no level of (one whose trunk the gate does not name) " + - "is refused. A try whose ask no build node took within the step bound ends as error; its ask stays in the build seat's stream and may still run later, judged by nobody (issue 734).", - Input: map[string]any{"type": "object", "properties": map[string]any{ - "members": map[string]any{"type": "array", "description": "the group: one repository at most once, each at the exact commit asked and the trunk commit it is merged onto", - "items": map[string]any{"type": "object", "required": []string{"repository", "head"}, "properties": map[string]any{ - "repository": map[string]any{"type": "string", "description": "/"}, - "head": map[string]any{"type": "string", "description": "the full commit to try, 40 or 64 hex digits"}, - "trunk": map[string]any{"type": "string", "description": "the trunk commit to merge it onto, or the trunk's branch for its head now; the trunk's head when absent"}}}}, - "repository": map[string]any{"type": "string", "description": "/, for a try of one member (instead of members)"}, - "head": map[string]any{"type": "string", "description": "the full commit to try, 40 or 64 hex digits (with repository)"}, - "trunk": map[string]any{"type": "string", "description": "the trunk commit to merge it onto, or the trunk's branch for its head now; the trunk's head when absent (with repository)"}, - "tests": map[string]any{"type": "string", "description": "a go test -run pattern: only those tests run, and nothing is kept"}, - "level": map[string]any{"type": "string", "enum": []string{"unit", "integration"}, "description": "only this level; both when absent"}}}, - Run: func(args map[string]any) (any, error) { - if tr.Tries == nil || tr.Trunks == nil { - return nil, fmt.Errorf("the tries state cannot be written here") - } - trunks, err := tr.Trunks() - if err != nil { - return nil, fmt.Errorf("the trunk heads cannot be read: %w", err) - } - now := time.Now - if tr.Now != nil { - now = tr.Now - } - var members []check.TryAskMember - if raw, ok := args["members"]; ok { - list, isList := raw.([]any) - if !isList { - return nil, fmt.Errorf("members is a list of {repository, head, trunk}") - } - for _, item := range list { - m, isMap := item.(map[string]any) - if !isMap { - return nil, fmt.Errorf("a member is {repository, head, trunk}") - } - members = append(members, check.TryAskMember{Repository: str(m, "repository"), Head: str(m, "head"), Trunk: str(m, "trunk")}) - } - } - id, err := check.AskTry(tr.Tries, trunks, check.TryAsk{Repository: str(args, "repository"), Head: str(args, "head"), - Trunk: str(args, "trunk"), Tests: str(args, "tests"), Level: str(args, "level"), Members: members}, now()) - if err != nil { - return nil, err - } - return map[string]any{"id": id}, nil - }}, - {Name: check.TryReadTool, - Description: "Where a try (of a group or of one head) stands, read whole, as stored: queued, running, or its end (pass, fail, or error when it could not run, or " + - "when its manifests and composition could not be judged), with what was said of it, every member's commit and the trunk commit it was merged onto, the time it took, " + - "every failure one line each (members, levels, tests, manifests, the composition per node), the levels' tests run and kept, the composition on every placed node, " + - "the notes of the check (manifests judged, module graph, kept verdicts); while it runs, each ask it put as soon as it is put, " + - "with the node that took it, its state and the phase its step says (fetch and merge, a level's digest, lint, tests) and since when. Read-only.", - Input: map[string]any{"type": "object", "required": []string{"id"}, "properties": map[string]any{ - "id": map[string]any{"type": "string", "description": "the try's id, try-"}}}, - Run: func(args map[string]any) (any, error) { - if tr.Tries == nil { - return nil, fmt.Errorf("the tries state cannot be read here") - } - return check.ReadTry(tr.Tries, str(args, "id")) - }}, - {Name: check.TryEndTool, - Description: "End a try of a group (or of one head) that waits or runs, as error, by hand: say why (kept in what it says). Its place among the 4 is free at once, " + - "the checker stops waiting for its asks, and the next " + check.TryTool + " of its head asks anew with a new id. For a try whose ask " + - "was lost (no step runs for it in checker_status); the checker ends one by itself when the build seat gives its ask up, or no node " + - "takes it within the step bound. A try that ended already is refused.", - Input: map[string]any{"type": "object", "required": []string{"id", "why"}, "properties": map[string]any{ - "id": map[string]any{"type": "string", "description": "the try's id, try-"}, - "why": map[string]any{"type": "string", "description": "why it is ended, in words"}}}, - Run: func(args map[string]any) (any, error) { - if tr.Ender == nil { - return nil, fmt.Errorf("the tries state cannot be written here") - } - now := time.Now - if tr.Now != nil { - now = tr.Now - } - t, err := check.EndTry(tr.Ender, str(args, "id"), str(args, "why"), now()) - if err != nil { - return nil, err - } - return map[string]any{"id": t.ID, "state": t.State, "said": t.Said}, nil - }}, - } -} - -// OpenTriesTools is the tool that lists the tries that wait or run, each with its members at their commits, and whether it is -// a whole try (the indexer writes the candidate of a whole try's group): the read a part uses at its start to find the tries -// whose start event it missed, instead of reading the checker's state. -func OpenTriesTools(tr Trying) []stdio.Tool { - return []stdio.Tool{{Name: check.TriesTool, - Description: "The tries that wait or run now (a try of a group or of one head; try.started and try.ended on the checker's stream say the same), each with its id, state, its members at their exact commits and " + - "trunk commits, and whether it is a whole try (not narrowed to a level or to tests, so it is composed and its manifests judged). For a part that " + - "missed the checker's try.started or try.ended event (the indexer at its start); checker_try_read reads one try whole. Read-only.", - Input: map[string]any{"type": "object", "properties": map[string]any{}}, - Run: func(map[string]any) (any, error) { - if tr.Tries == nil { - return nil, fmt.Errorf("the tries state cannot be read here") - } - open, err := check.OpenTries(tr.Tries) - return map[string]any{"tries": open}, err - }}} -} - -// Seat is the seat the checker holds (novox/hq ADR 0547 §10, issue 774); its verbs are served as tools named .. -const Seat = "mesh-delivery-checker" - -// SeatTryTools are the try's tools as the seat's verbs: try, try-read and try-end, run by the same code as checker_try, -// checker_try_read and checker_try_end, so the answer is the same. The module tools stay beside them. -func SeatTryTools(tr Trying) []stdio.Tool { - verbs := map[string]string{check.TryTool: "try", check.TryReadTool: "try-read", check.TryEndTool: "try-end"} - var out []stdio.Tool - for _, t := range TryTools(tr) { - t.Name = Seat + "." + verbs[t.Name] - out = append(out, t) - } - return out -} - -// SeatInputTools are the seat's verb input (check.InputVerb): a checking program's input as the checker keeps it, asked by -// the Go build module that runs the program (buildstep.RunInput.Read), never read from the checker's state by it. -func SeatInputTools(r check.Reader) []stdio.Tool { - return []stdio.Tool{{Name: Seat + "." + meshdeliverychecker.VerbInput, - Description: "A checking program's input the checker keeps, by the sha256 of its exact bytes, as a run ask names it: the digest " + - "and the bytes, base64. A digest it keeps no input of, or bytes that read back as another digest, is an error. Read-only.", - Input: map[string]any{"type": "object", "required": []string{"digest"}, "properties": map[string]any{ - "digest": map[string]any{"type": "string", "description": "the input's sha256, 64 lowercase hex digits"}}}, - Run: func(args map[string]any) (any, error) { - digest, _ := args["digest"].(string) - return r.Input(digest) - }}} -} - -// Tools are the read tools over the checker's states. -func Tools(r check.Reader) []stdio.Tool { - return []stdio.Tool{ - {Name: check.VerdictsReadTool, - Description: "The verdicts the checker holds, each as stored under verdicts..: its state, every failure it names one line each (every member's failed tests, refused steps and conflicts, the manifests' refusals and the composition), the tests run, kept and skipped per level, the time of each part, the trunk heads it judged against, the composition and which checking program judged it (judged: its build and the heads it read), with the full " + - "report of the status each pull request carries (the line the forge shows is cut at 140 characters, this is not). With a group, that group's only. Read-only.", - Input: map[string]any{"type": "object", "properties": map[string]any{ - "group": map[string]any{"type": "string", "description": "the delivery group's branch name"}}}, - Run: func(args map[string]any) (any, error) { - group, _ := args["group"].(string) - vs, cut, err := r.Verdicts(group) - return cutAnswer(map[string]any{"verdicts": vs}, cut), err - }}, - {Name: check.PullReadTool, - Description: "The verdict that judges one pull request, every failure it names one line each (all of them, not only the first the status line shows), which checking program judged it (judged: its build, its key and the heads it read), and the full report of its status mesh/check. Read-only.", - Input: map[string]any{"type": "object", "required": []string{"repository", "number"}, "properties": map[string]any{ - "repository": map[string]any{"type": "string", "description": "/"}, - "number": map[string]any{"type": "integer", "description": "the pull request's number"}}}, - Run: func(args map[string]any) (any, error) { - repository, _ := args["repository"].(string) - n, _ := args["number"].(float64) - return r.Pull(repository, int(n)) - }}, - {Name: check.KeptReadTool, - Description: "The kept verdicts of passing packages, each as stored under kept..: the package, its tests, the time they took, the toolchain " + - "and when it was kept. With a level, that level's; with a level and a digest, that one. Read-only.", - Input: map[string]any{"type": "object", "properties": map[string]any{ - "level": map[string]any{"type": "string", "enum": []string{"unit", "integration"}, "description": "the level"}, - "digest": map[string]any{"type": "string", "description": "the package's digest, with a level"}}}, - Run: func(args map[string]any) (any, error) { - level, _ := args["level"].(string) - digest, _ := args["digest"].(string) - kept, cut, err := r.Kept(level, digest) - return cutAnswer(map[string]any{"kept": kept}, cut), err - }}, - {Name: check.InputsReadTool, - Description: "The checking program's inputs the checker keeps, each under the sha256 of its exact bytes (inputs., kept a day): " + - "the facts of a check its verdict is asked of, or the heads its seat list is asked of. With a digest, that input as kept; " + - "without, every digest and its size. Read-only.", - Input: map[string]any{"type": "object", "properties": map[string]any{ - "digest": map[string]any{"type": "string", "description": "the input's sha256, as a run ask names it"}}}, - Run: func(args map[string]any) (any, error) { - digest, _ := args["digest"].(string) - inputs, cut, err := r.Inputs(digest) - return cutAnswer(map[string]any{"inputs": inputs}, cut), err - }}, - {Name: check.PreviewsReadTool, - Description: "The merge previews the checker holds, each as stored under previews...: the merge commit, per module directory " + - "its tree, manifest digest and lock hashes, or the files in conflict. With a repository, that repository's; with a head (7 or more characters) " + - "only that head's. Keys that are no preview key are listed as unreadable. Read-only.", - Input: map[string]any{"type": "object", "properties": map[string]any{ - "repository": map[string]any{"type": "string", "description": "/"}, - "head": map[string]any{"type": "string", "description": "a pull request head commit, or a prefix of at least 7 characters"}}}, - Run: func(args map[string]any) (any, error) { - repository, _ := args["repository"].(string) - head, _ := args["head"].(string) - if head != "" && len(head) < 7 { - return nil, fmt.Errorf("the head %q is too short: give at least 7 characters", head) - } - ps, bad, cut, err := r.Previews(repository, head) - return cutAnswer(map[string]any{"previews": ps, "unreadable": bad}, cut), err - }}, - {Name: check.StatusReadTool, - Description: "What runs: the steps in flight on the build modules by node, the candidates without a verdict for their heads, " + - "and the candidates whose check is owed by kind (waiting_by_kind: new, nodes, and trunk, a re-judge pulled after the other two). A key a " + - "build module left running (started past the step bound, or its build module not running on its node) is listed apart under " + - "left_running with why, and not counted. Nothing holds the checker and it has no capacity of its own: a check is an ask on the " + - "build seats' streams, whose backlog the delivery view shows (novox/hq ADR 0525). No merge holds a check off (novox/hq ADR 0661). could_not_run names each check " + - "that could not run because a part of the mesh was not heard: the part, since when, the running that asked it again, and whether it " + - "is the finding check-could-not-run (an hour unasked); it is asked again when that part runs. " + - "dead_letters says whether the checker hears the asks the build seats give up on (issue 734), and why not: " + - "deaf, a try or check whose ask is given up waits until its bound. builds_not_ended names, of each running check, the builder's builds of " + - "its candidate's changed modules that are neither done nor failed: the check waits on them before it composes, within its build-wait-bound " + - "(novox/hq ADR 0603 §10); a failed one fails the check: rebuild it with the builder's builder_build_again, and the check asks itself again when the build is done. Read-only.", - Input: map[string]any{"type": "object", "properties": map[string]any{}}, - Run: func(map[string]any) (any, error) { return r.Status() }}, - } -} - -// RequestTools is the tool that reads the composition requests the checker sent to nodes (issue 1921). -func RequestTools(r check.StateRead) []stdio.Tool { - return []stdio.Tool{{Name: check.RequestsReadTool, - Description: "The composition request a check sent to a node: the composer's whole input for that node (the node-engine's composition input, the case's " + - "manifests and verdicts, the seat list), kept exactly as sent so a session reproduces the check's composition (the composer run by hand over the same " + - "request gives the check's answer). Kept in the checker's state compositions, per check key (group.heads, the 12-digit heads hash) and node, " + - "0.7 to 0.8 MB each (kept compressed, in pieces that each fit the state's 256 KiB value), for 3 days (the state's ttl-seconds), the state holding at most 256 MiB (max-mib, which mesh-grants raises a held bucket to). With a check and a node, that request whole; with a check, " + - "the nodes it kept one for; with neither, every kept request, each with its size, digest and when it was kept. Read-only; " + check.RequestsDropTool + " drops a check's.", - Input: map[string]any{"type": "object", "properties": map[string]any{ - "check": map[string]any{"type": "string", "description": "the check's key, ., as the verdict and composition name it"}, - "node": map[string]any{"type": "string", "description": "the node the request was sent for, with a check"}}}, - Run: func(args map[string]any) (any, error) { - key, _ := args["check"].(string) - node, _ := args["node"].(string) - return check.ReadRequests(r, key, node) - }}} -} - -// RequestDropTools is the tool that drops a check's kept composition requests by hand, which frees the state when it is -// full (tools-are-how-a-module-is-spoken-to): it records the hand act through the seat mesh-hand-acts first. -func RequestDropTools(s check.StateDrop, acts views.HandActs) []stdio.Tool { - return []stdio.Tool{{Name: check.RequestsDropTool, - Description: "Drop the composition requests the checker kept for one check (" + check.RequestsReadTool + " lists them): every node's, and the pieces " + - "no other kept request names. The hand act is recorded through the seat mesh-hand-acts first, and a drop whose act could not be recorded is not made. " + - "Answers the nodes and pieces dropped. Use it when a check's words say its request could not be kept in the state compositions because it is full; " + - "the state itself drops a request 3 days after it was kept.", - Input: map[string]any{"type": "object", "required": []string{"check", "why"}, "properties": map[string]any{ - "check": map[string]any{"type": "string", "description": "the check's key, ., whose kept requests are dropped"}, - "why": map[string]any{"type": "string", "description": "why they are dropped, in words; recorded as the hand act"}}}, - Run: func(args map[string]any) (any, error) { - key, _ := args["check"].(string) - why, _ := args["why"].(string) - return check.DropRequests(s, key, why, func(what string) error { - return acts.RecordHandAct(views.HandAct{What: what, Why: why, Cause: "requests-drop", Verb: check.RequestsDropTool}) - }) - }}} -} - -// RecoveryTools are the tools that steer a check by hand (tools-are-how-a-module-is-spoken-to): ask a check again whose -// wait judged nothing (the lost check of 2026-10-28). They write the checker's verdicts through w. -func RecoveryTools(r check.Reader, w check.VerdictEntry) []stdio.Tool { - str := func(args map[string]any, k string) string { s, _ := args[k].(string); return s } - return []stdio.Tool{{Name: check.AskAgainTool, - Description: "Ask a candidate's check again by hand, whose verdict stays running while nothing runs for it (" + check.StatusReadTool + " names it " + - "under lost): its verdict is ended as asked again, saying why, and the checker, which hears its verdicts, stops the wait that judged nothing " + - "and asks the check anew, whole. Refused for a group with no candidate, a verdict that is not running or a failure whose failing steps did not all end on a transport fault (a pass, or any other failure, stands until a push or " + - "a trunk move), and while a step of its pull requests can still run on a build module (its end judges it). The checker reads a step that " + - "ended while its watch was deaf by itself at the next step end of its build module; this is for what that does not reach.", - Input: map[string]any{"type": "object", "required": []string{"group", "why"}, "properties": map[string]any{ - "group": map[string]any{"type": "string", "description": "the delivery group's branch name"}, - "why": map[string]any{"type": "string", "description": "why it is asked again, in words; kept in the verdict it ends"}}}, - Run: func(args map[string]any) (any, error) { - return r.AskAgain(w, str(args, "group"), str(args, "why")) - }}} -} - -// stepBound is the checker's step bound as the checker reads it (MESH_CHECKER_STEP_BOUND), its default when unset or not a -// duration. -func stepBound() time.Duration { - if d, err := time.ParseDuration(os.Getenv("MESH_CHECKER_STEP_BOUND")); err == nil && d > 0 { - return d - } - return check.DefaultStepBound -} - -// seatListAgainCallers are who may ask the seat list again by hand (design 47 G §204). -var seatListAgainCallers = []string{stdio.AnyPerson, "node-tools", "mesh-healers"} - -// holderOf is a seat's holder as the seat that places modules answers it (seatlist.HolderOf, design 47 G A-126): false while the -// seat has none or the answer cannot be read. -func holderOf(seat string) (string, bool) { - module, err := seatlist.HolderOf(stdio.Ask, seat) - return module, err == nil -} - -func main() { - // The build modules are no names (design 47 G A-82): the build seats on the seat list, each held by the module the seat - // that places modules names for it; the seat list and its two tools are wired once by mesh-sdk (§204). - gate := seatlist.NewPart("checker", seatListAgainCallers) - go func() { - <-stdio.Served() - gate.Follow(seatlist.StdioBus(), nil, func(f string, a ...any) { fmt.Fprintf(os.Stderr, "[mesh-delivery-checker-tools] "+f+"\n", a...) }) - }() - seats := buildrun.NewBuildSeats(func() map[string]seatdef.Definition { - if rd := gate.Reader(); rd != nil { - return rd.Definitions() - } - return nil - }, holderOf) - r := check.Reader{VerdictState: read(stdio.State("verdicts")), KeptState: read(stdio.State("kept")), CandidateState: ownerRead(atHolder(stdio.Ask, holderOf, meshcatalog.Seat), indexerCandidatesTool), - PreviewState: read(stdio.State("previews")), InputState: read(stdio.State(check.InputsStateName)), - StepStates: func() map[string]check.StateRead { - out := map[string]check.StateRead{} - for _, m := range seats.All() { - if m.Module != "" && m.Toolchain != "" { - out[m.Module] = read(stdio.State(m.Module + ".steps")) - } - } - return out - }, - HaveState: read(stdio.State("node-engine.have")), StepBound: stepBound(), - CouldNotRunState: read(stdio.State(check.CouldNotRunState)), HearingState: read(stdio.State(buildrun.HearingState)), - AskState: read(stdio.State(check.AsksState)), BuildState: read(stdio.State("mesh-delivery-builder.builds"))} - r.Runs = runsOf{ownerRead(atHolder(stdio.Ask, holderOf, meshcatalog.Seat), indexerModulesTool)} // the node-engine at the commit the mesh runs, as the checker reads it - tries := stdio.State(check.TriesState) - trunks := func() (map[string]string, error) { - raw, err := stdio.Ask(check.TrunkVerb, meshcatalog.RevisionInput{}) - if err != nil { - return nil, err - } - return check.TrunkHeads(raw) - } - r.Trunks = trunks - store := stateStore{StateRead: read(tries), create: func(key string, value []byte) error { - _, err := tries.Create(key, json.RawMessage(value)) - return err - }, entry: func(key string) (json.RawMessage, uint64, error) { - reads.Add(1) - e, err := tries.Get(key) - if err != nil || e == nil { - return nil, 0, err - } - return e.Value, e.Revision, nil - }, update: func(key string, value []byte, revision uint64) error { - _, err := tries.Update(key, json.RawMessage(value), revision) - return err - }} - trying := Trying{Tries: store, Ender: store, Trunks: trunks} - r.Backlog = backlogOf(stdio.Ask) // the build seats' streams, for checker_ask_again (issue 1373) - verdicts := stdio.State("verdicts") - written := stateStore{entry: func(key string) (json.RawMessage, uint64, error) { - reads.Add(1) - e, err := verdicts.Get(key) - if err != nil || e == nil { - return nil, 0, err - } - return e.Value, e.Revision, nil - }, update: func(key string, value []byte, revision uint64) error { - _, err := verdicts.Update(key, json.RawMessage(value), revision) - return err - }} - tools := append(append(append(append(Tools(r), TryTools(trying)...), OpenTriesTools(trying)...), SeatTryTools(trying)...), RecoveryTools(r, written)...) - // checker_first_views and checker_first_view_again: where the checker's first views of the indexer's and the assigner's - // states stand, and asking one again by hand (ADR 0615, DLV-M2). - tools = append(tools, views.StatusTools(os.Getenv(stdio.ServedAs), "checker_first_views", "checker_first_view_again", stdio.State(views.StatusState), meshhandactsclient.Recorder{Ask: stdio.Ask}, time.Now)...) - tools = append(tools, gate.Tools()...) - tools = append(tools, SeatInputTools(r)...) - tools = append(tools, RequestTools(read(stdio.State(check.RequestsStateName)))...) - requests := stdio.State(check.RequestsStateName) - tools = append(tools, RequestDropTools(check.StateDrop{StateRead: read(requests), Delete: requests.Delete}, meshhandactsclient.Recorder{Ask: stdio.Ask})...) - if err := stdio.Serve("", logged(tools)); err != nil { - fmt.Fprintf(os.Stderr, "[mesh-delivery-checker-tools] %v\n", err) - os.Exit(1) - } -} - -// buildUsageTool is the delivery view's tool of the build nodes' use, whose backlog is the build seats' streams (issue 1373). -const buildUsageTool = "mesh-delivery-view.build_usage" - -// backlogOf reads the build seats' backlog through the view's tool, asked through ask (stdio.Ask, or a test's). -func backlogOf(ask func(string, any) (json.RawMessage, error)) func() ([]check.BacklogRow, error) { - return func() ([]check.BacklogRow, error) { - reads.Add(1) - raw, err := ask(buildUsageTool, map[string]any{}) - if err != nil { - return nil, fmt.Errorf("%s does not answer: %w", buildUsageTool, err) - } - answer, said, ok := buscalls.Unwrap(raw) - if !ok { - return nil, fmt.Errorf("%s answered: %s", buildUsageTool, said) - } - var a struct { - Backlog []check.BacklogRow `json:"backlog"` - Notes []string `json:"notes"` - } - if err := json.Unmarshal(answer, &a); err != nil { - return nil, fmt.Errorf("%s answered what does not decode: %w", buildUsageTool, err) - } - if len(a.Notes) > 0 { // the backlog was not read: unread is never empty - return nil, fmt.Errorf("%s did not read the backlog: %s", buildUsageTool, strings.Join(a.Notes, "; ")) - } - return a.Backlog, nil - } -} diff --git a/modules/mesh-delivery-checker/cmd/mesh-delivery-checker-tools/main_test.go b/modules/mesh-delivery-checker/cmd/mesh-delivery-checker-tools/main_test.go deleted file mode 100644 index b42ad7e3..00000000 --- a/modules/mesh-delivery-checker/cmd/mesh-delivery-checker-tools/main_test.go +++ /dev/null @@ -1,366 +0,0 @@ -package main - -import ( - "context" - "encoding/base64" - "encoding/json" - "errors" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog" - "math/rand" - "os" - "regexp" - "slices" - "strings" - "testing" - "time" - - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-checker/checkermsg" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshdeliverychecker" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep" - - "mesh-delivery-checker/internal/check" -) - -func TestTheToolsServedAreTheFiveReadTools(t *testing.T) { - var names []string - for _, tl := range Tools(check.Reader{}) { - names = append(names, tl.Name) - if tl.Description == "" || tl.Run == nil { - t.Errorf("%s has no description or no run", tl.Name) - } - } - want := []string{check.VerdictsReadTool, check.PullReadTool, check.KeptReadTool, check.InputsReadTool, check.PreviewsReadTool, check.StatusReadTool} - if !slices.Equal(names, want) { - t.Errorf("tools = %v, want %v", names, want) - } - // The recovery tool beside them asks a lost check again; with nothing to write it refuses. - recovery := RecoveryTools(check.Reader{}, nil) - if len(recovery) != 1 || recovery[0].Name != check.AskAgainTool || recovery[0].Description == "" { - t.Errorf("recovery tools = %+v", recovery) - } - if _, err := recovery[0].Run(map[string]any{"group": "feat/x", "why": "lost"}); err == nil { - t.Errorf("%s answered with no state to write", check.AskAgainTool) - } - // Issue 1921: the composition requests kept by the checker are read by check and node; the tool refuses a node with no check - // and a state it cannot read, and lists a check's nodes without their bodies. - store := &memStore{vals: map[string]json.RawMessage{}} - keeper := check.RequestKeeper{Store: memPut{store}} - for _, k := range [][2]string{{"g.0123456789ab", "anchor"}, {"g.0123456789ab", "ace"}, {"h.0123456789ab", "ace"}} { - if err := keeper.Keep(context.Background(), k[0], k[1], []byte(`{"input":{"nodes":[]}}`)); err != nil { - t.Fatal(err) - } - } - // Issue 1966: a request whose compressed bytes pass the state's value limit is kept in pieces and read back whole; the - // pieces are no requests in the list. - rnd := make([]byte, 600<<10) - _, _ = rand.New(rand.NewSource(1)).Read(rnd) - big := []byte(`{"input":"` + base64.StdEncoding.EncodeToString(rnd) + `"}`) - if err := keeper.Keep(context.Background(), "big.0123456789ab", "anchor", big); err != nil { - t.Fatalf("a request of %d bytes: %v", len(big), err) - } - rt := RequestTools(check.StateRead{Keys: store.Keys, Get: store.Get}) - if one, err := rt[0].Run(map[string]any{"check": "big.0123456789ab", "node": "anchor"}); err != nil || !strings.Contains(func() string { b, _ := json.Marshal(one); return string(b) }(), base64.StdEncoding.EncodeToString(rnd)[:64]) { - t.Errorf("the big request read back: %v", err) - } - // Listing reads no piece, and a request of another version is refused by name. - store.vals["v1.0123456789ab/anchor"] = json.RawMessage(`{"v":1,"check":"v1.0123456789ab","node":"anchor","gzip":"x"}`) - noPieces := check.StateRead{Keys: store.Keys, Get: func(k string) (json.RawMessage, error) { - if strings.HasPrefix(k, "pieces/") { - return nil, errors.New("a piece was read") - } - return store.Get(k) - }} - if _, err := RequestTools(noPieces)[0].Run(map[string]any{}); err != nil { - t.Errorf("listing: %v", err) - } - if _, err := rt[0].Run(map[string]any{"check": "v1.0123456789ab", "node": "anchor"}); err == nil || !strings.Contains(err.Error(), "version 1") { - t.Errorf("a version 1 request: %v", err) - } - delete(store.vals, "v1.0123456789ab/anchor") - if all, _ := rt[0].Run(map[string]any{}); strings.Count(func() string { b, _ := json.Marshal(all); return string(b) }(), `"node"`) != 4 { - t.Errorf("the list holds a piece as a request: %v", all) - } - if len(rt) != 1 || rt[0].Name != check.RequestsReadTool || !strings.Contains(rt[0].Description, "composition request a check sent to a node") { - t.Fatalf("request tools = %+v", rt) - } - one, err := rt[0].Run(map[string]any{"check": "g.0123456789ab", "node": "anchor"}) - if b, _ := json.Marshal(one); err != nil || !strings.Contains(string(b), `"request":{"input":{"nodes":[]}}`) { - t.Errorf("one request = %s, %v", b, err) - } - list, _ := rt[0].Run(map[string]any{"check": "g.0123456789ab"}) - if b, _ := json.Marshal(list); strings.Count(string(b), `"node"`) != 2 || strings.Contains(string(b), "h.0123") || strings.Contains(string(b), `"request"`) { - t.Errorf("list of a check = %s", b) - } - for _, args := range []map[string]any{{"node": "anchor"}, {"check": "g.0123456789ab", "node": "gone"}} { - if _, err := rt[0].Run(args); err == nil { - t.Errorf("%v answered", args) - } - } - if _, err := RequestTools(check.StateRead{})[0].Run(map[string]any{}); err == nil { - t.Errorf("answered with no state to read") - } - // Issue 1966: another module's state is asked of its read tool, never read from its bus state (ADR 0596). Every - // stdio.State this program names of another module is one its manifest declares under reads, which the runtime grants; - // the indexer's candidates and modules are asked of indexer_read_candidates and indexer_read_modules, which it invokes. - t.Run("1966: another module's state is read only where the manifest declares it", func(t *testing.T) { - raw, err := os.ReadFile("../../module.json") - if err != nil { - t.Fatal(err) - } - var man struct { - Reads []string `json:"reads"` - Invokes []string `json:"invokes"` - } - if err := json.Unmarshal(raw, &man); err != nil { - t.Fatal(err) - } - src, err := os.ReadFile("main.go") - if err != nil { - t.Fatal(err) - } - for _, m := range regexp.MustCompile(`stdio\.State\("([^"]+\.[^"]+)"\)`).FindAllStringSubmatch(string(src), -1) { - if !slices.Contains(man.Reads, m[1]) { - t.Errorf("main.go reads %s, which the manifest does not declare under reads: the runtime refuses it", m[1]) - } - } - for _, tool := range []string{indexerCandidatesTool, indexerModulesTool} { - if !slices.Contains(man.Invokes, check.IndexerModule+"."+tool) { - t.Errorf("the manifest does not invoke %s", tool) - } - } - }) - for _, c := range []struct { - name, key, answer, want string - failed bool - }{ - {name: "the keys", answer: `{"owner":"mesh-delivery-indexer","state":"candidates","keys":["a","b"]}`, want: "[a b]"}, - {name: "one key, wrapped as the tool runner hands it", key: "a", - answer: `{"content":[{"type":"text","text":"{\"key\":\"a\",\"found\":true,\"value\":{\"commit\":\"c\"}}"}]}`, want: `{"commit":"c"}`}, - {name: "a key the indexer does not hold", key: "gone", answer: `{"key":"gone","found":false}`, want: ""}, - {name: "the tool refused", key: "a", answer: `{"content":[{"type":"text","text":"refused"}],"isError":true}`, failed: true}, - } { - t.Run("1966: the indexer's read tool, "+c.name, func(t *testing.T) { - var asked []string - holder := func(seat string) (string, bool) { return "acme-indexer", seat == meshcatalog.Seat } // found at the seat list's holder - r := ownerRead(atHolder(func(key string, body any) (json.RawMessage, error) { - b, _ := json.Marshal(body) - asked = append(asked, key+" "+string(b)) - return json.RawMessage(c.answer), nil - }, holder, meshcatalog.Seat), indexerCandidatesTool) - var got string - var err error - if c.key == "" { - var keys []string - keys, err = r.Keys() - got = strings.Trim(strings.Join([]string{"[", strings.Join(keys, " "), "]"}, ""), " ") - } else { - var raw json.RawMessage - raw, err = r.Get(c.key) - got = string(raw) - } - want := []string{"acme-indexer." + indexerCandidatesTool + " {}"} - if c.key != "" { - want = []string{"acme-indexer." + indexerCandidatesTool + ` {"key":"` + c.key + `"}`} - } - if (err != nil) != c.failed || (!c.failed && got != c.want) || !slices.Equal(asked, want) { - t.Errorf("read %q, %v, asking %v; want %q, failed %v, asking %v", got, err, asked, c.want, c.failed, want) - } - }) - } - // 1373: the build seats' backlog is read through build_usage; one it says it did not read is never taken for empty. - for _, c := range []struct { - name, answer string - rows int - failed bool - }{ - {name: "a backlog read", answer: `{"backlog":[{"language":"go","kind":"check","waiting":2}]}`, rows: 1}, - {name: "a backlog with a note says it was not read", answer: `{"backlog":[],"notes":["the seats' streams cannot be read here"]}`, failed: true}, - } { - rows, err := backlogOf(func(string, any) (json.RawMessage, error) { return json.RawMessage(c.answer), nil })() - if (err != nil) != c.failed || len(rows) != c.rows || (c.failed && !strings.Contains(err.Error(), "cannot be read here")) { - t.Errorf("1373 backlog, %s: %v, %v", c.name, rows, err) - } - } - // With nothing to read from a tool says so and changes nothing. - for _, tl := range Tools(check.Reader{}) { - if tl.Name == check.StatusReadTool { - continue // it answers from what it can read, and says what it could not - } - if _, err := tl.Run(map[string]any{"repository": "novox/x", "number": float64(1)}); err == nil { - t.Errorf("%s answered with no state to read", tl.Name) - } - } -} - -// memStore is a tries state in memory. -type memStore struct{ vals map[string]json.RawMessage } - -func (m *memStore) Keys() ([]string, error) { - var out []string - for k := range m.vals { - out = append(out, k) - } - return out, nil -} -func (m *memStore) Get(key string) (json.RawMessage, error) { return m.vals[key], nil } -func (m *memStore) Create(key string, value []byte) error { - if _, ok := m.vals[key]; ok { - return errors.New("exists") - } - m.vals[key] = value - return nil -} - -func (m *memStore) Entry(key string) (json.RawMessage, uint64, error) { return m.vals[key], 1, nil } -func (m *memStore) Update(key string, value []byte, revision uint64) error { - m.vals[key] = value - return nil -} - -func TestTheTryToolsAskAndReadATry(t *testing.T) { // ADR 0501 §5, the agreed interface with mesh-controller's try - store := &memStore{vals: map[string]json.RawMessage{}} - tools := TryTools(Trying{Tries: store, Ender: store, Now: func() time.Time { return time.Unix(1, 5) }, - Trunks: func() (map[string]string, error) { - return map[string]string{"novox/mesh-delivery": strings.Repeat("a", 40)}, nil - }}) - if len(tools) != 3 || tools[0].Name != "checker_try" || tools[1].Name != "checker_try_read" || tools[2].Name != "checker_try_end" { - t.Fatalf("tools = %+v", tools) - } - out, err := tools[0].Run(map[string]any{"repository": "novox/mesh-delivery", "head": strings.Repeat("1", 40), "trunk": "main"}) - if err != nil { - t.Fatal(err) - } - id := out.(map[string]any)["id"].(string) - if id != "try-1000000005" { - t.Errorf("id = %q", id) - } - raw, err := tools[1].Run(map[string]any{"id": id}) - if err != nil || !strings.Contains(string(raw.(json.RawMessage)), `"state":"queued"`) { - t.Errorf("read = %s, %v", raw, err) - } - // The seat's verbs answer as the tools do (ADR 0547 §10, issue 774): the same ask is the same try, and the read is alike. - verbs := SeatTryTools(Trying{Tries: store, Ender: store, Now: func() time.Time { return time.Unix(1, 5) }, - Trunks: func() (map[string]string, error) { - return map[string]string{"novox/mesh-delivery": strings.Repeat("a", 40)}, nil - }}) - if len(verbs) != 3 || verbs[0].Name != Seat+".try" || verbs[1].Name != Seat+".try-read" || verbs[2].Name != Seat+".try-end" { - t.Fatalf("verbs = %+v", verbs) - } - again, err := verbs[0].Run(map[string]any{"repository": "novox/mesh-delivery", "head": strings.Repeat("1", 40), "trunk": "main"}) - if err != nil || again.(map[string]any)["id"] != id { - t.Errorf("verb try = %v, %v, want the waiting try %s", again, err, id) - } - if viaVerb, err := verbs[1].Run(map[string]any{"id": id}); err != nil || string(viaVerb.(json.RawMessage)) != string(raw.(json.RawMessage)) { - t.Errorf("verb try-read = %s, %v; tool = %s", viaVerb, err, raw) - } - if _, err := verbs[0].Run(map[string]any{"repository": "novox/hq", "head": strings.Repeat("1", 40)}); err == nil { - t.Error("the verb tried a repository nothing checks") - } - // The seat's definition of the verb try gives the members the verb serves (ADR 0637 §6), as the tool takes them, and says so. - def, err := os.ReadFile("../../../mesh-delivery-contracts/seats/mesh-delivery-checker/seat.json") - if err != nil { - t.Fatal(err) - } - var seat struct { - Verbs []struct { - Name string `json:"name"` - Description string `json:"description"` - Input struct { - Properties map[string]any `json:"properties"` - Required []string `json:"required"` - } `json:"input"` - } `json:"verbs"` - } - if err := json.Unmarshal(def, &seat); err != nil { - t.Fatal(err) - } - for _, v := range seat.Verbs { - if v.Name != "try" { - continue - } - toolProps := verbs[0].Input["properties"].(map[string]any) - for name := range toolProps { - if _, ok := v.Input.Properties[name]; !ok { - t.Errorf("the verb try serves no %q, which the tool takes", name) - } - } - const limit = "at most 4 run on a build node, and 8 wait for one, mesh-wide" - if !strings.Contains(v.Description, limit) || !strings.Contains(verbs[0].Description, limit) { - t.Errorf("the verb and the tool state one limit %q", limit) - } - if len(v.Input.Required) != 0 || !strings.Contains(v.Description, "members") { - t.Errorf("the verb try requires %v and says %q: want members as an alternative to one repository and head", v.Input.Required, v.Description) - } - } - // The seat's verb input (issue 1921, ADR 0596 §2): a checking program's input as kept, which the Go build module asks. - body := []byte(`{"v":1}`) - in, _ := buildstep.RunInputOf(check.InputVerb, body) - inputs := SeatInputTools(check.Reader{InputState: check.StateRead{Get: func(key string) (json.RawMessage, error) { - if key == in.Digest { - return body, nil - } - return nil, nil - }}}) - if len(inputs) != 1 || inputs[0].Name != Seat+".input" { - t.Fatalf("input verbs = %+v", inputs) - } - if a, err := inputs[0].Run(map[string]any{"digest": in.Digest}); err != nil || a.(meshdeliverychecker.InputAnswer).Input != base64.StdEncoding.EncodeToString(body) { - t.Errorf("verb input = %+v, %v", a, err) - } - // A group try (issue 1921): the members, each an exact commit; members and one repository together are refused; the - // description says what it does in the words a search for "try a group" finds. - later := TryTools(Trying{Tries: store, Ender: store, Now: func() time.Time { return time.Unix(2, 5) }, - Trunks: func() (map[string]string, error) { - return map[string]string{"novox/mesh-delivery": strings.Repeat("a", 40)}, nil - }}) - g, err := later[0].Run(map[string]any{"members": []any{map[string]any{"repository": "novox/mesh-delivery", "head": strings.Repeat("2", 40)}}}) - if err != nil || g.(map[string]any)["id"] == id { - t.Errorf("a group try = %v, %v, want a try of its own", g, err) - } - if _, err := tools[0].Run(map[string]any{"members": []any{map[string]any{"repository": "novox/mesh-delivery", "head": strings.Repeat("2", 40)}}, - "repository": "novox/mesh-delivery", "head": strings.Repeat("1", 40)}); err == nil { - t.Error("members and a repository were both taken") - } - if _, err := tools[0].Run(map[string]any{"members": "novox/mesh-delivery"}); err == nil { - t.Error("members that are no list were taken") - } - for _, tl := range tools { - for _, words := range []string{"group"} { - if !strings.Contains(strings.ToLower(tl.Description), words) { - t.Errorf("%s says nothing of a %s: %q", tl.Name, words, tl.Description) - } - } - } - if d := strings.ToLower(tools[0].Description); !strings.Contains(d, "try a group") || !strings.Contains(d, "exact commit") || !strings.Contains(d, "every failure") || - !strings.Contains(d, "composition on every placed node") || !strings.Contains(d, "owes the forge nothing") || !strings.Contains(d, "kept") { - t.Errorf("the try's description does not say what a group try does: %q", d) - } - if open := OpenTriesTools(Trying{Tries: store}); len(open) != 1 || open[0].Name != check.TriesTool || !strings.Contains(open[0].Description, "try.started") { - t.Errorf("open tries tool = %+v", open) - } else if out, err := open[0].Run(nil); err != nil || len(out.(map[string]any)["tries"].([]checkermsg.Open)) != 2 { - t.Errorf("open tries = %v, %v, want the two tries asked", out, err) - } - // Issue 734: a try whose ask was lost is ended by hand with why, and its head is asked anew. - ended, err := tools[2].Run(map[string]any{"id": id, "why": "its ask was lost"}) - if err != nil || ended.(map[string]any)["state"] != "error" { - t.Errorf("end = %v, %v", ended, err) - } - if _, err := tools[2].Run(map[string]any{"id": id, "why": "again"}); err == nil { - t.Error("an ended try was ended again") - } - if _, err := tools[0].Run(map[string]any{"repository": "novox/hq", "head": strings.Repeat("1", 40)}); err == nil || - err.Error() != "no level of novox/hq is checked by the checker" { - t.Errorf("hq: %v", err) - } -} - -// memPut writes a memStore as the checker's kept-request state is written. -type memPut struct{ m *memStore } - -func (p memPut) Put(_ context.Context, key string, value []byte) (uint64, error) { - if len(value) > 262144 { // the state's value limit, headers included (issue 1966) - return 0, errors.New("the value is over the 262144 bytes the bucket takes") - } - p.m.vals[key] = value - return 1, nil -} diff --git a/modules/mesh-delivery-checker/cmd/mesh-delivery-checker/bus.go b/modules/mesh-delivery-checker/cmd/mesh-delivery-checker/bus.go deleted file mode 100644 index 4342f010..00000000 --- a/modules/mesh-delivery-checker/cmd/mesh-delivery-checker/bus.go +++ /dev/null @@ -1,197 +0,0 @@ -package main - -import ( - "context" - "errors" - "fmt" - - "github.com/nats-io/nats.go/jetstream" - - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient" - "git.novox.be/novox/mesh-sdk/go/catalogue" - "git.novox.be/novox/mesh-sdk/go/process" - - "mesh-delivery-checker/internal/check" -) - -// bucketOpener is the part of the bus the watches use. -type bucketOpener interface { - KeyValue(ctx context.Context, bucket string) (jetstream.KeyValue, error) -} - -// kvStore is the builds bucket as the builder's store: create and compare-and-set. -type kvStore struct{ kv jetstream.KeyValue } - -func conflict(err error) error { - if errors.Is(err, jetstream.ErrKeyExists) || errors.Is(err, jetstream.ErrKeyRevisionMismatch) { - return check.ErrConflict - } - return err -} - -func (s kvStore) Get(ctx context.Context, key string) ([]byte, uint64, bool, error) { - e, err := s.kv.Get(ctx, key) - if errors.Is(err, jetstream.ErrKeyNotFound) { - return nil, 0, false, nil - } - if err != nil { - return nil, 0, false, err - } - return e.Value(), e.Revision(), true, nil -} - -func (s kvStore) Create(ctx context.Context, key string, value []byte) (uint64, error) { - rev, err := s.kv.Create(ctx, key, value) - return rev, conflict(err) -} - -func (s kvStore) Update(ctx context.Context, key string, value []byte, revision uint64) (uint64, error) { - rev, err := s.kv.Update(ctx, key, value, revision) - return rev, conflict(err) -} - -func (s kvStore) Keys(ctx context.Context) ([]string, error) { - keys, err := s.kv.Keys(ctx) - if errors.Is(err, jetstream.ErrNoKeysFound) { - return nil, nil - } - return keys, err -} - -// Delete removes a key (an ended try past its keeping). -func (s kvStore) Delete(ctx context.Context, key string) error { return s.kv.Delete(ctx, key) } - -func opOf(e jetstream.KeyValueEntry) bool { return e.Operation() == jetstream.KeyValuePut } - -// settle reads the entries a watcher holds now, up to its mark of the last values, and returns the watcher for the -// changes that follow. -func settle(ctx context.Context, kv jetstream.KeyValue, each func(jetstream.KeyValueEntry)) (jetstream.KeyWatcher, error) { - w, err := kv.WatchAll(ctx) - if err != nil { - return nil, err - } - for { - select { - case <-ctx.Done(): - w.Stop() - return nil, ctx.Err() - case e, ok := <-w.Updates(): - if !ok { - return nil, errors.New("the watch ended") - } - if e == nil { - return w, nil - } - each(e) - } - } -} - -// follow hands each change of a watcher to each until ctx ends; a watch that ends is an error, and the process manager -// starts the program again. -func follow(ctx context.Context, w jetstream.KeyWatcher, each func(jetstream.KeyValueEntry)) error { - defer w.Stop() - for { - select { - case <-ctx.Done(): - return nil - case e, ok := <-w.Updates(): - if !ok { - return errors.New("a watch ended") - } - if e != nil { - each(e) - } - } - } -} - -// manifestReader reads manifests. of the indexer and parses the manifest it holds. -type manifestReader struct{ kv jetstream.KeyValue } - -func (m manifestReader) Manifest(ctx context.Context, digest string) (catalogue.Manifest, error) { - key, err := meshcatalogclient.ManifestsKey(digest) - if err != nil { - return catalogue.Manifest{}, err - } - e, err := m.kv.Get(ctx, key) - if err != nil { - return catalogue.Manifest{}, fmt.Errorf("manifests.%s: %w", key, err) - } - kept, err := meshcatalogclient.DecodeManifest(e.Value()) - if err != nil { - return catalogue.Manifest{}, err - } - return parseManifest(kept.Manifest) -} - -// parseManifest decodes a manifest the indexer kept, as every reader does (novox/hq ADR 0578 §3): judged by nothing here, -// a field it does not know set aside. The checker judges a change's manifests with the indexer's judge, run as a step -// (judge.go). -func parseManifest(raw string) (catalogue.Manifest, error) { - return catalogue.Decode([]byte(raw)) -} - -// awaitedKV is a bucket that may appear after the start (process.AwaitBucket) as a check.KV: a call while it is not on the -// bus fails saying so. -type awaitedKV struct{ b *process.AwaitedBucket } - -func (a awaitedKV) kv() (kvStore, error) { - kv := a.b.KV() - if kv == nil { - return kvStore{}, errors.New("the bucket is not on the bus yet") - } - return kvStore{kv}, nil -} - -func (a awaitedKV) Get(ctx context.Context, key string) ([]byte, uint64, bool, error) { - s, err := a.kv() - if err != nil { - return nil, 0, false, err - } - return s.Get(ctx, key) -} - -func (a awaitedKV) Create(ctx context.Context, key string, value []byte) (uint64, error) { - s, err := a.kv() - if err != nil { - return 0, err - } - return s.Create(ctx, key, value) -} - -func (a awaitedKV) Update(ctx context.Context, key string, value []byte, revision uint64) (uint64, error) { - s, err := a.kv() - if err != nil { - return 0, err - } - return s.Update(ctx, key, value, revision) -} - -func (a awaitedKV) Keys(ctx context.Context) ([]string, error) { - s, err := a.kv() - if err != nil { - return nil, err - } - return s.Keys(ctx) -} - -func (a awaitedKV) Delete(ctx context.Context, key string) error { - s, err := a.kv() - if err != nil { - return err - } - return s.Delete(ctx, key) -} - -// runInputs keeps the checking program's inputs in the checker's state inputs (check.InputsBucket), each under the -// sha256 of its exact bytes: an input already kept under its digest is the same bytes, so a second keep is no error. -type runInputs struct{ a awaitedKV } - -func (r runInputs) Keep(ctx context.Context, digest string, body []byte) error { - _, err := r.a.Create(ctx, digest, body) - if errors.Is(err, check.ErrConflict) { - return nil - } - return err -} diff --git a/modules/mesh-delivery-checker/cmd/mesh-delivery-checker/couldnotrun.go b/modules/mesh-delivery-checker/cmd/mesh-delivery-checker/couldnotrun.go deleted file mode 100644 index e747f8dd..00000000 --- a/modules/mesh-delivery-checker/cmd/mesh-delivery-checker/couldnotrun.go +++ /dev/null @@ -1,47 +0,0 @@ -package main - -import ( - "context" - "encoding/json" - "time" - - "git.novox.be/novox/mesh-contracts/go/seats/nodeengine" - - "mesh-delivery-checker/internal/check" -) - -// waitCouldNotRun raises each check that could not run as the finding check-could-not-run once its bound passed -// (check.CouldNotRunBound): it waits for the next one due, read from the checker's state could-not-run, and reads again -// each time one is kept. The bound is the only wait: a check is asked again on its part's running, never here. -func waitCouldNotRun(ctx context.Context, ch *check.Checker, kept <-chan struct{}) { - for ctx.Err() == nil { - // The wait is a context's bound (ADR 0437 §8): none while no check waits for its bound. - wait, done := ctx, func() {} - if next := ch.CouldNotRunDue(ctx, time.Now()); !next.IsZero() { - wait, done = context.WithDeadline(ctx, next) - } - select { - case <-wait.Done(): - case <-kept: - } - done() - } -} - -// partRunner is what a `running` is handed to: check.Checker's PartRunning. -type partRunner interface { - PartRunning(ctx context.Context, node, module, fingerprint string) -} - -// heardRunning takes one node-engine seat's `running..` in, as the checker's durable consumer of its stream -// hands it (module.json consumes node-engine.running): the part named runs at its fingerprint, so every check that could not -// run for want of it is asked again once (check.Checker.PartRunning). A body that names no node, module or fingerprint asks -// nothing, said in the log. -func heardRunning(ctx context.Context, ch partRunner, body []byte, logf func(string, ...any)) { - var r nodeengine.RunningEvent - if err := json.Unmarshal(body, &r); err != nil || r.Node == "" || r.Module == "" || r.Fingerprint == "" { - logf("a running of the node-engine seat that names no node, module or fingerprint asks no check again: %s (%v)", body, err) - return - } - ch.PartRunning(ctx, r.Node, r.Module, r.Fingerprint) -} diff --git a/modules/mesh-delivery-checker/cmd/mesh-delivery-checker/engines.go b/modules/mesh-delivery-checker/cmd/mesh-delivery-checker/engines.go deleted file mode 100644 index 64932370..00000000 --- a/modules/mesh-delivery-checker/cmd/mesh-delivery-checker/engines.go +++ /dev/null @@ -1,167 +0,0 @@ -package main - -import ( - "context" - "encoding/json" - "errors" - "fmt" - "sort" - "sync" - "sync/atomic" - "time" - - nodeengineseat "git.novox.be/novox/mesh-contracts/go/seats/nodeengine" - - "github.com/nats-io/nats.go/jetstream" - - "git.novox.be/novox/mesh-contracts/go/clients/meshmoduleassignerclient" - nec "git.novox.be/novox/mesh-contracts/go/clients/nodeengineclient" - ne "git.novox.be/novox/mesh-contracts/go/seats/nodeengine" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-builder/buildrun" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/composer" - "git.novox.be/novox/mesh-sdk/go/views" -) - -// The checker's composition of a check on the bus (novox/hq ADR 0593 §7, §9; check.EngineCompositions): each placed -// node's engine asked `node-engine.compose-candidate` on that node, and, for a group that changes the node-engine's -// composition code, the composer built from its head run on the Go build seat. - -// composeCandidateKey is the seat verb's call key, asked of one node (process.Conn.CallOn). -var composeCandidateKey = "seat:" + nodeengineseat.Seat + "." + ne.VerbComposeCandidate - -// engineAsks asks one node's engine over the bus, its answer waited for at most ctx's deadline (the answer bound). -type engineAsks struct { - call func(node, key string, body any) (json.RawMessage, error) -} - -func (e engineAsks) ComposeCandidate(ctx context.Context, node string, ask ne.ComposeCandidateInput) (ne.ComposeCandidateAnswer, error) { - type answer struct { - raw json.RawMessage - err error - } - got := make(chan answer, 1) - go func() { - raw, err := e.call(node, composeCandidateKey, ask) - got <- answer{raw, err} - }() - select { - case <-ctx.Done(): - return ne.ComposeCandidateAnswer{}, fmt.Errorf("no answer within its bound: %w", ctx.Err()) - case a := <-got: - if a.err != nil { - return ne.ComposeCandidateAnswer{}, a.err - } - return nec.DecodeAnswer(a.raw) - } -} - -// assignedNodes is the placedNodes' read of the assignments' picture, which is followed once the holder of the seat mesh-module-assigner -// is known: an error says so until then, so a check never passes with no node asked. -func assignedNodes(p *atomic.Pointer[views.Picture]) func(context.Context) (jetstream.KeyValue, error) { - return func(context.Context) (jetstream.KeyValue, error) { - pic := p.Load() - if pic == nil { - return nil, errors.New("the seat that places modules has no holder known yet") - } - return pic, nil - } -} - -// placedNodes names every node the seat mesh-module-assigner places now, read from its state when a check composes (no -// watch: a check reads it once). A state that cannot be read is an error, so the check says its composition was not -// made rather than passing with no node asked (review finding 4). -type placedNodes struct { - kv func(ctx context.Context) (jetstream.KeyValue, error) -} - -func (p placedNodes) Placed() ([]string, error) { - ctx, cancel := context.WithTimeout(context.Background(), nec.AnswerBound) - defer cancel() - kv, err := p.kv(ctx) - if err != nil { - return nil, fmt.Errorf("the assignments cannot be read: %w", err) - } - lister, err := kv.ListKeys(ctx) - if errors.Is(err, jetstream.ErrNoKeysFound) { - return nil, nil // assignments that places nothing - } - if err != nil { - return nil, fmt.Errorf("the assignments cannot be listed: %w", err) - } - seen := map[string]bool{} - for key := range lister.Keys() { - if node, _, _, err := meshmoduleassignerclient.ParseKey(key); err == nil { - seen[node] = true - } - } - out := make([]string, 0, len(seen)) - for n := range seen { - out = append(out, n) - } - sort.Strings(out) - return out, nil -} - -// seatSandbox runs a compose job on the Go build seat's check stream, as the checker's own ask, and answers the -// composer's verdict from the step's result (buildstep.ComposeAnswer). -type seatSandbox struct { - // module is the checker's own, the credential's: the asker of the compose ask. - module string - asker buildrun.Asker -} - -func (s seatSandbox) Compose(ctx context.Context, job buildstep.ComposeJob) (composer.Verdict, error) { - ask := buildstep.StepAsk{ID: buildstep.NewID(), Kind: buildstep.AskCheck, Language: buildstep.AskGo, Asker: s.module, - At: time.Now().UTC(), Compose: &job} - step, err := s.asker.Ask(ctx, ask) - if err != nil { - return composer.Verdict{}, err - } - if step.State != buildstep.StepPassed { - return composer.Verdict{}, fmt.Errorf("the compose ask %s ended %s: %s", ask.ID, step.State, step.Reason) - } - var a buildstep.ComposeAnswer - if err := json.Unmarshal(step.Result, &a); err != nil { - return composer.Verdict{}, fmt.Errorf("the compose ask %s answered no compose answer: %w", ask.ID, err) - } - var v composer.Verdict - if err := json.Unmarshal(a.Verdict, &v); err != nil || v.V != composer.Version { - return composer.Verdict{}, fmt.Errorf("the compose ask %s answered no composer verdict of version %d (%v)", ask.ID, composer.Version, err) - } - return v, nil -} - -// manifestVerdicts are the indexer's refusals of the trunk's manifests, by module, from its modules' values -// (meshcatalog.ModulesByModuleValue.VerdictOf, ADR 0578 §3): what the sandbox's composer holds a refused module by. -type manifestVerdicts struct { - mu sync.Mutex - by map[string]meshcatalog.VerdictsByDigestValue -} - -func (m *manifestVerdicts) put(module string, v *meshcatalog.VerdictsByDigestValue) { - m.mu.Lock() - defer m.mu.Unlock() - if m.by == nil { - m.by = map[string]meshcatalog.VerdictsByDigestValue{} - } - if v == nil { - delete(m.by, module) - return - } - // The sandbox's composer may be the node-engine of an older delivery, which does not know the verdict waits: it is handed a - // wait as the refusal it is held as. - m.by[module] = meshcatalogclient.VerdictAsRefused(*v) -} - -func (m *manifestVerdicts) all() map[string]meshcatalog.VerdictsByDigestValue { - m.mu.Lock() - defer m.mu.Unlock() - out := make(map[string]meshcatalog.VerdictsByDigestValue, len(m.by)) - for k, v := range m.by { - out[k] = v - } - return out -} diff --git a/modules/mesh-delivery-checker/cmd/mesh-delivery-checker/findingwriter.go b/modules/mesh-delivery-checker/cmd/mesh-delivery-checker/findingwriter.go deleted file mode 100644 index 996b94c8..00000000 --- a/modules/mesh-delivery-checker/cmd/mesh-delivery-checker/findingwriter.go +++ /dev/null @@ -1,77 +0,0 @@ -package main - -import ( - "context" - - "github.com/nats-io/nats.go" - "github.com/nats-io/nats.go/jetstream" - - condseat "git.novox.be/novox/mesh-contracts/health-and-repair/go/seats/meshconditions" - "git.novox.be/novox/mesh-sdk/go/keys" - "git.novox.be/novox/mesh-sdk/go/process" - "git.novox.be/novox/mesh-sdk/go/views" - - "mesh-delivery-checker/internal/check" -) - -type findingWriterOf = views.Writer[condseat.Finding, condseat.FindingCleared, condseat.FindingsStated, condseat.FindingsAskedEvent] - -// checkerFindings is the checker's finding writer (design 47 G §461, §689): it owns the finding check-could-not-run beside -// its views reader's, observes the raised ones of its kept checks, and writes both as the generated contract type. The -// writer forms its subjects itself (A-13). -type checkerFindings struct { - w *findingWriterOf - node string -} - -// newCheckerFindings makes and starts the writer; observe says the checks that could not run and whose finding is -// written (check.Checker.RaisedCouldNotRun). -func newCheckerFindings(ctx context.Context, cred process.Account, conn *nats.Conn, js jetstream.JetStream, state process.State, - observe func(context.Context) ([]check.Finding, error), logf func(string, ...any)) (*checkerFindings, error) { - c := &checkerFindings{node: cred.Node} - w, err := views.NewWriter(views.WriterConfig[condseat.Finding, condseat.FindingCleared, condseat.FindingsStated, condseat.FindingsAskedEvent]{ - Module: cred.Module, State: state, Node: cred.Node, Asked: condseat.SubjectFindingsAsked, JS: js, Conn: conn, Logf: logf, - Kinds: []string{check.CouldNotRunKind}, - Observe: func(ctx context.Context) (views.Observed[condseat.Finding], error) { - found, err := observe(ctx) - if err != nil { - return views.Observed[condseat.Finding]{}, err - } - var out views.Observed[condseat.Finding] - for _, f := range found { - out.Findings = append(out.Findings, c.body(f)) - } - return out, nil - }, - }) - if err != nil { - return nil, err - } - c.w = w - // A writer that cannot start (the stream of its asks is not there yet) is said; its findings are then kept in the - // state alone and said by the next start (as the node-engine's is). - if err := w.Start(ctx); err != nil { - logf("the finding writer cannot start, its findings are kept in the state alone: %v", err) - } - return c, nil -} - -// body lays the checker's finding out as the seat's contract type: a finding of the module, about the module on its node. -func (c *checkerFindings) body(f check.Finding) condseat.Finding { - module, _ := c.w.ModuleNode() - return condseat.Finding{Kind: f.Kind, Scope: views.FindingScope, ID: keys.EscapeName(f.ID), At: f.At, Since: f.At, - Severity: condseat.FindingSeverityWarning, Source: f.Kind, Summary: f.Summary, Headline: f.Headline, Explanation: f.Explanation, - Subject: condseat.Subject{Scope: views.FindingScope, ID: module, Machine: c.node}} -} - -// Put writes one finding; its `since` stays where its key exists. -func (c *checkerFindings) Put(f check.Finding) error { - return c.w.Write(context.Background(), c.body(f)) -} - -// Delete clears one finding. -func (c *checkerFindings) Delete(f check.Finding) error { - return c.w.Clear(context.Background(), views.FindingScope, keys.EscapeName(f.ID), f.Kind, "the checker no longer observes it") -} - -var _ check.FindingWriter = (*checkerFindings)(nil) diff --git a/modules/mesh-delivery-checker/cmd/mesh-delivery-checker/forge.go b/modules/mesh-delivery-checker/cmd/mesh-delivery-checker/forge.go deleted file mode 100644 index e00b1958..00000000 --- a/modules/mesh-delivery-checker/cmd/mesh-delivery-checker/forge.go +++ /dev/null @@ -1,59 +0,0 @@ -package main - -import ( - "context" - "encoding/json" - "errors" - "fmt" - - "github.com/nats-io/nats.go" - - gitseat "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/git" - - "mesh-delivery-checker/internal/check" -) - -// The checker reads the forge through the seat git's read verbs (design 47 *The seat git*; milestone 47/G W6.14), as its -// manifest's invokes names them, never by a module's tool: whichever module holds the seat answers. It writes nothing to -// the forge: what the checker owes the forge is the forge bridge's to perform (ADR 0484 clause 2). - -// fileVerb is the seat git's verb file, as invokes names it. -var fileVerb = "seat:" + gitseat.Seat + "." + gitseat.VerbFile - -// forgeReads reads the forge through call (mesh-sdk process.Conn.Call as the checker's own account). -type forgeReads struct { - call func(key string, body any) (json.RawMessage, error) -} - -// ask calls a verb of the seat git; a call that reached nobody (no responders: the holder's tool runner re-serving, or the -// forge down) is marked Unheard, so the check says it could not run and is asked again when the part it could not hear -// runs (issue 1373, issue 1624). -func (f forgeReads) ask(key string, body any) (json.RawMessage, error) { - raw, err := f.call(key, body) - if errors.Is(err, nats.ErrNoResponders) || errors.Is(err, nats.ErrTimeout) || errors.Is(err, context.DeadlineExceeded) { - return nil, &check.Unheard{Err: err} - } - return raw, err -} - -// File is the text of a file of a repository at a ref. A file the forge says the ref does not hold wraps -// check.ErrNotFound (issue 1845); the seat's error is a failure, never an absent file. -func (f forgeReads) File(_ context.Context, repository, path, ref string) (string, error) { - raw, err := f.ask(fileVerb, gitseat.FileInput{Repository: repository, Path: path, Ref: ref}) - if err != nil { - return "", err - } - var a gitseat.FileAnswer - if err := json.Unmarshal(raw, &a); err != nil { - return "", fmt.Errorf("the answer of %s is not its answer: %v", fileVerb, err) - } - switch { - case a.Error != "": - return "", fmt.Errorf("%s of %s at %s: %s", fileVerb, path, ref, a.Error) - case a.Absent: - return "", fmt.Errorf("%w: %s holds no %s at %s", check.ErrNotFound, repository, path, ref) - case a.Path == "" && a.Blob == "" && a.Content == "": - return "", fmt.Errorf("the answer of %s names no file and no error", fileVerb) - } - return a.Content, nil -} diff --git a/modules/mesh-delivery-checker/cmd/mesh-delivery-checker/forge_test.go b/modules/mesh-delivery-checker/cmd/mesh-delivery-checker/forge_test.go deleted file mode 100644 index 1803122e..00000000 --- a/modules/mesh-delivery-checker/cmd/mesh-delivery-checker/forge_test.go +++ /dev/null @@ -1,109 +0,0 @@ -package main - -import ( - "context" - "encoding/json" - "errors" - "os" - "path/filepath" - "strings" - "testing" - - "github.com/nats-io/nats.go" - - "mesh-delivery-checker/internal/check" -) - -// seatAnswer is an answer of the seat git's verb file as its fixtures give it (modules/mesh-delivery-contracts/seats/git/fixtures/verbs.json). -func seatAnswer(t *testing.T, name string) json.RawMessage { - t.Helper() - raw, err := os.ReadFile(filepath.Join("..", "..", "..", "mesh-delivery-contracts", "seats", "git", "fixtures", "verbs.json")) - if err != nil { - t.Fatal(err) - } - var fixtures []struct { - Name string `json:"name"` - Of string `json:"of"` - Given json.RawMessage `json:"given"` - } - if err := json.Unmarshal(raw, &fixtures); err != nil { - t.Fatal(err) - } - for _, f := range fixtures { - if f.Of == "verb:file.answer" && strings.Contains(string(f.Given), name) { - return f.Given - } - } - t.Fatalf("no file answer of the seat git's fixtures holds %q", name) - return nil -} - -func TestTheForgeReadsParseWhatTheForgeAnswered(t *testing.T) { // 1624/AC4; milestone 47/G W6.14: through the seat git - var asked []string - f := forgeReads{call: func(key string, body any) (json.RawMessage, error) { - b, _ := json.Marshal(body) - asked = append(asked, key+" "+string(b)) - return seatAnswer(t, "seats/index.json"), nil - }} - text, err := f.File(context.Background(), "novox/mesh-contracts", "seats/index.json", "main") - if err != nil || text != `{"format":1,"seats":["mesh-broker"]}` { - t.Errorf("file = %q, %v", text, err) - } - if want := `seat:git.file {"path":"seats/index.json","ref":"main","repository":"novox/mesh-contracts"}`; len(asked) != 1 || asked[0] != want { - t.Errorf("asked %v, want %s", asked, want) - } - bad := forgeReads{call: func(string, any) (json.RawMessage, error) { return json.RawMessage(`{}`), nil }} - if _, err := bad.File(context.Background(), "novox/x", "go.mod", "main"); err == nil { - t.Error("an answer with no file was taken") - } -} - -func TestAFileTheRefDoesNotHoldIsNotFoundAndOtherFailuresAreNot(t *testing.T) { // 1845/AC1, AC4 - f := forgeReads{call: func(string, any) (json.RawMessage, error) { return seatAnswer(t, "seats/gone.json"), nil }} - if _, err := f.File(context.Background(), "novox/mesh-contracts", "seats/gone.json", "aaaa"); !errors.Is(err, check.ErrNotFound) { - t.Errorf("an absent file is %v, want ErrNotFound", err) - } - f = forgeReads{call: func(string, any) (json.RawMessage, error) { return seatAnswer(t, "over 512 KiB"), nil }} - if _, err := f.File(context.Background(), "novox/mesh-contracts", "seats/big.json", "main"); err == nil || errors.Is(err, check.ErrNotFound) { - t.Errorf("the seat's error is %v, want a failure that is not ErrNotFound", err) - } - f = forgeReads{call: func(string, any) (json.RawMessage, error) { return nil, errors.New("the holder failed") }} - if _, err := f.File(context.Background(), "novox/mesh-catalog", "go.mod", "main"); err == nil || errors.Is(err, check.ErrNotFound) { - t.Errorf("a failed call is %v, want a failure that is not ErrNotFound", err) - } -} - -func TestAForgeReadThatReachesNobodyIsUnheard(t *testing.T) { // 1624 C7: "nats: no responders" on mesh-catalog #293 - f := forgeReads{call: func(string, any) (json.RawMessage, error) { return nil, nats.ErrNoResponders }} - _, err := f.File(context.Background(), "novox/mesh-catalog", "checks/agenthome/go.mod", "950e37a46e8d") - var u *check.Unheard - if !errors.As(err, &u) { - t.Errorf("err = %v, want it marked as reaching nobody", err) - } - // Issue 1373, milestone 47/G W6.9: the check that could not run is asked again when the part runs, heard as the - // node-engine seat's running.. on the checker's consumer; a running that names no part asks nothing. - t.Run("asked again on running", func(t *testing.T) { - for _, c := range []struct { - body string - want []string - }{ - {`{"v":1,"node":"novox","module":"gitea","fingerprint":"src2:ab","manifest":"sha256:cd","at":"2026-11-09T20:00:00Z"}`, []string{"novox gitea src2:ab"}}, - {`{"v":1,"node":"novox","module":"gitea"}`, nil}, - {`not json`, nil}, - } { - var got []string - heardRunning(context.Background(), runnerFunc(func(_ context.Context, node, module, fp string) { - got = append(got, node+" "+module+" "+fp) - }), []byte(c.body), t.Logf) - if strings.Join(got, ",") != strings.Join(c.want, ",") { - t.Errorf("%s asked %v, want %v", c.body, got, c.want) - } - } - }) -} - -type runnerFunc func(ctx context.Context, node, module, fingerprint string) - -func (f runnerFunc) PartRunning(ctx context.Context, node, module, fingerprint string) { - f(ctx, node, module, fingerprint) -} diff --git a/modules/mesh-delivery-checker/cmd/mesh-delivery-checker/integration_test.go b/modules/mesh-delivery-checker/cmd/mesh-delivery-checker/integration_test.go deleted file mode 100644 index 546fef66..00000000 --- a/modules/mesh-delivery-checker/cmd/mesh-delivery-checker/integration_test.go +++ /dev/null @@ -1,1373 +0,0 @@ -//go:build integration - -package main - -import ( - "bytes" - "context" - "crypto/sha256" - "encoding/json" - "errors" - "fmt" - "maps" - "os" - "path/filepath" - "slices" - "sort" - "strings" - "sync" - "sync/atomic" - "testing" - "testing/fstest" - "time" - - "github.com/nats-io/nats-server/v2/server" - "github.com/nats-io/nats.go" - "github.com/nats-io/nats.go/jetstream" - - "mesh-delivery-checker/internal/check" - - "git.novox.be/novox/mesh-contracts/go/clients/meshmoduleassignerclient" - "git.novox.be/novox/mesh-contracts/go/clients/nodeengineclient" - nec "git.novox.be/novox/mesh-contracts/go/clients/nodeengineclient" - "git.novox.be/novox/mesh-contracts/go/seats/meshmoduleassigner" - "git.novox.be/novox/mesh-contracts/go/seats/nodeengine" - ne "git.novox.be/novox/mesh-contracts/go/seats/nodeengine" - "git.novox.be/novox/mesh-contracts/health-and-repair/go/seats/meshwatchdogs" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-builder/buildrun" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-builder/builds" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-checker/checkermsg" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshdeliverycheckerclient" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshdeliveryclient" - gitseat "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/git" - "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/meshdeliverychecker" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep" - gobuild "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/steprun" - "git.novox.be/novox/mesh-sdk/go/announce" - "git.novox.be/novox/mesh-sdk/go/catalogue" - "git.novox.be/novox/mesh-sdk/go/keys" - "git.novox.be/novox/mesh-sdk/go/process" - "git.novox.be/novox/mesh-sdk/go/seatdef" - "git.novox.be/novox/mesh-sdk/go/seatlist" - "git.novox.be/novox/mesh-sdk/go/seatlist/seatlisttest" - "git.novox.be/novox/mesh-sdk/go/views/viewstest" - - "mesh-delivery-checker/rules" -) - -// busConf is the shape of the composed accounts file (mesh-controller internal/broker): one account with JetStream, the -// controller's user and the checker's own principal .. It carries no per-principal permissions: the grants -// the controller composes from the manifest's state and reads (only the checker writes its buckets) are the controller's, -// and are proved by its own module check, not here. -const busConf = ` -listen: 127.0.0.1:-1 -jetstream { store_dir: %q } -accounts { - MESH { - jetstream: enabled - users = [ - { user: "ctl", password: "pw" } - { user: "n1.mesh-delivery-checker", password: "pw" } - ] - } -} -` - -const ( - repo = "novox/mesh-delivery" - head1 = "1111111111111111111111111111111111111111" - head2 = "2222222222222222222222222222222222222222" - trunk = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" - merged = "fedcba9876543210fedcba9876543210fedcba98" // the merge commit of the captured fetch answer - digU = "aa11aa11aa11aa11aa11aa11aa11aa11aa11aa11aa11aa11aa11aa11aa11aa11" - digI = "bb22bb22bb22bb22bb22bb22bb22bb22bb22bb22bb22bb22bb22bb22bb22bb22" -) - -var captured = filepath.Join("..", "..", "internal", "check", "testdata", "captured") - -func readCaptured(t *testing.T, name string) map[string]any { - t.Helper() - raw, err := os.ReadFile(filepath.Join(captured, name+".json")) - if err != nil { - t.Fatal(err) - } - var v map[string]any - if err := json.Unmarshal(raw, &v); err != nil { - t.Fatal(err) - } - return v -} - -// fakeBuildModules serve the tools of mesh-build-go and mesh-build-node as the real ones do (ADR 0469 clause 2): a call on -// mesh.mod..call... answers at once with the step and its key, and the step's end is written to -// the key . of the module's steps bucket. What the steps end with are the results the build modules' own code -// marshalled (internal/check/testdata/captured, README). -type fakeBuildModules struct { - js jetstream.JetStream - ctx context.Context - conflict atomic.Bool - // hold is a commit whose fetch never answers: its ask stays taken, as one lost in a bus reload (issue 734). - hold atomic.Value - mu sync.Mutex - calls map[string]int // by `.` - testTool *testing.T - // beside is, by workspace, the siblings the fetch placed in it as ` `, sorted: a digest echoes them - // (1929/AC2; mesh-build-go buildstep.besideOf), or the level runs whole and keeps nothing. - beside map[string][]string - // names are the nodes' names the last check ask carried, for the names check (ADR 0567 §12). - names []string - // packages are, by repository, the package versions the last Go check ask of it carried (StepAsk.Packages). - packages map[string]buildstep.PackageVersions - // runs counts the run asks answered, and broken, when set, is why the checking program does not build (issue 1921). - runs atomic.Int32 - broken atomic.Value - // drop, when set, drops every run ask unanswered and counts it in dropped, as a build module that does not know the job - // run (the lead's ruling on milestone 47/B0). - drop atomic.Bool - dropped atomic.Int32 -} - -// droppingAsks is the seat's asks as a build module that does not know the job run takes them: a run ask is acknowledged and -// never begun while the fake drops them. -type droppingAsks struct { - gobuild.AskSource - f *fakeBuildModules -} - -func (d droppingAsks) Next(ctx context.Context, kind string, wait time.Duration) (*gobuild.Pulled, error) { - msg, err := d.AskSource.Next(ctx, kind, wait) - if err != nil || msg == nil || !d.f.drop.Load() { - return msg, err - } - var a buildstep.StepAsk - if json.Unmarshal(msg.Data, &a) == nil && a.Run != nil { - d.f.dropped.Add(1) - return nil, msg.Ack() - } - return msg, nil -} - -// run answers a run ask as mesh-build-go does: the checking program's work (rules.Program) over the input the ask names, -// asked of the seat verb it names on the bus and checked against its digest (buildstep.RunInput.Read, as mesh-build-go -// reads it), with no heads of its own laid. -func (f *fakeBuildModules) run(ctx context.Context, a buildstep.StepAsk) (any, error) { - f.runs.Add(1) - if why, _ := f.broken.Load().(string); why != "" { - return nil, errors.New(why) - } - answer := buildstep.RunAnswer{Built: true, Key: "program-0123456789abcdef"} - // As mesh-build-go does, the input is asked before the program runs, and a step whose input cannot be had fails. - body, err := meshdeliverycheckerclient.ReadInput(func(key string, body any) (json.RawMessage, error) { return askVerb(f.js.Conn(), key, body) }, a.Run.Input.Digest) - if err == nil { - err = a.Run.Input.Verify(body) - } - if err != nil { - return nil, err - } - out, err := rules.Program(a.Run.Args, func() ([]byte, error) { return body, nil }, fstest.MapFS{}) - if err != nil { - answer.Exit, answer.Said = 2, err.Error() - } - answer.Output = out - return answer, nil -} - -// askVerb asks a seat verb on the subject that names no caller and reads the runtime's reply, {result, error}. -func askVerb(nc *nats.Conn, key string, body any) (json.RawMessage, error) { - seat, verb, ok := strings.Cut(strings.TrimPrefix(key, "seat:"), ".") - if !ok || !strings.HasPrefix(key, "seat:") { - return nil, fmt.Errorf("%q names no seat verb", key) - } - data, err := json.Marshal(body) - if err != nil { - return nil, err - } - msg, err := nc.Request("mesh.seat."+seat+".tool."+verb, data, 5*time.Second) - if err != nil { - return nil, err - } - var r struct { - Result json.RawMessage `json:"result"` - Error string `json:"error"` - } - if err := json.Unmarshal(msg.Data, &r); err != nil { - return nil, err - } - if r.Error != "" { - return nil, errors.New(r.Error) - } - return r.Result, nil -} - -// serveInputVerb answers the checker seat's verb input on the bus as the checker's tools do (check.Reader.Input over the -// checker's state inputs), and counts what it answered (issue 1921, ADR 0596 §2). -func (b *bed) serveInputVerb(t *testing.T, nc *nats.Conn) { - t.Helper() - kv := b.buckets[testBucket(check.InputsStateName)] - r := check.Reader{InputState: check.StateRead{Get: func(key string) (json.RawMessage, error) { - e, err := kv.Get(b.ctx, key) - if errors.Is(err, jetstream.ErrKeyNotFound) { - return nil, nil - } - if err != nil { - return nil, err - } - return e.Value(), nil - }}} - if _, err := nc.Subscribe("mesh.seat.mesh-delivery-checker.tool."+meshdeliverychecker.VerbInput, func(m *nats.Msg) { - var ask meshdeliverychecker.InputInput - reply := map[string]any{} - if err := json.Unmarshal(m.Data, &ask); err != nil { - reply["error"] = err.Error() - } else if a, err := r.Input(ask.Digest); err != nil { - reply["error"] = err.Error() - } else { - reply["result"] = a - b.inputsAnswered.Add(1) - } - data, _ := json.Marshal(reply) - _ = m.Respond(data) - }); err != nil { - t.Fatal(err) - } -} - -func (f *fakeBuildModules) count(tool string) int { - f.mu.Lock() - defer f.mu.Unlock() - return f.calls[tool] -} - -func (f *fakeBuildModules) result(t *testing.T, tool string, args map[string]any) json.RawMessage { - level, _ := args["level"].(string) - var v any - switch { - case strings.HasSuffix(tool, "_fetch"): - if h, _ := f.hold.Load().(string); h != "" && args["commit"] == h { - <-f.ctx.Done() - } - name := "go-fetch-clean" - if f.conflict.Load() { - name = "go-fetch-conflict" - } - fetched := readCaptured(t, name) - fetched["commit"], fetched["base"] = args["commit"], args["base"] - var refs []struct { - Repository string `json:"repository"` - Commit string `json:"commit"` - } - raw, _ := json.Marshal(args["beside"]) - _ = json.Unmarshal(raw, &refs) - var lines []string - for _, r := range refs { - lines = append(lines, r.Repository+" "+r.Commit) - } - sort.Strings(lines) - f.mu.Lock() - if f.beside == nil { - f.beside = map[string][]string{} - } - f.beside[fmt.Sprint(fetched["workspace"])] = lines - f.mu.Unlock() - v = fetched - case strings.HasSuffix(tool, "_digest"): - d := map[string]string{"unit": digU, "integration": digI}[level] - f.mu.Lock() - beside := f.beside[fmt.Sprint(args["workspace"])] - f.mu.Unlock() - v = map[string]any{"level": level, "packages": map[string]string{"fixture/slow": d}, "beside": beside} - case strings.HasSuffix(tool, "_test"): - r := readCaptured(t, "go-test-slow") - r["level"] = level - v = r - } - data, _ := json.Marshal(v) - return data -} - -// serve makes module's steps bucket and its build seat's stream and workers, and pulls its asks on n1 as the real module -// does since R4g (ADR 0525; issue 1887 A5): each ask's job runs with step bodies answering the captured results, and a -// check takes the kept verdicts of the checker's kept bucket by their digests. -func (f *fakeBuildModules) serve(t *testing.T, module string, kept jetstream.KeyValue) { - kv, err := f.js.CreateKeyValue(f.ctx, jetstream.KeyValueConfig{Bucket: buildrun.StepsBucket(module), History: 1}) - if err != nil { - t.Fatal(err) - } - language := strings.TrimPrefix(module, "mesh-build-") - if err := gobuild.DeclareAskWorkers(f.ctx, f.js, language, 30*time.Second); err != nil { - t.Fatal(err) - } - prefix := map[string]string{goBuildModule: "build_go_", nodeBuildModule: "build_node_"}[module] - call := func(name string) gobuild.StepFunc { - return func(ctx context.Context, args map[string]any) (any, error) { - tool := prefix + name - f.mu.Lock() - f.calls[module+"."+tool]++ - f.mu.Unlock() - return f.result(t, tool, args), nil - } - } - steps := gobuild.AskSteps{Fetch: call("fetch"), Test: call("test"), - Kept: func(ctx context.Context, level, digest string) (int, bool, error) { - key, err := meshdeliverycheckerclient.KeptKey(level, digest) - if err != nil { - return 0, false, err - } - e, err := kept.Get(ctx, key) - if errors.Is(err, jetstream.ErrKeyNotFound) { - return 0, false, nil - } - if err != nil { - return 0, false, err - } - v, err := meshdeliverycheckerclient.DecodeKept(e.Value()) - return int(v.Tests), err == nil, err - }} - if module == goBuildModule { - steps.Digest = call("digest") - } - put := func(key string, value any) (uint64, error) { - raw, _ := value.(json.RawMessage) - return kv.Put(f.ctx, key, raw) - } - p := &gobuild.Puller{Source: droppingAsks{&gobuild.JetStreamAsks{JS: f.js, Language: language}, f}, Language: language, Node: "n1", Put: put, - Capacity: func() int { return 2 }, PullWait: 200 * time.Millisecond, - Run: func(ctx context.Context, a buildstep.StepAsk) (any, error) { - if a.Check != nil { - f.mu.Lock() - f.names = a.Check.NodeNames - if repository := a.Check.Fetch.Repository; a.Language == buildstep.AskGo { - if f.packages == nil { - f.packages = map[string]buildstep.PackageVersions{} - } - f.packages[repository] = a.Packages - } - f.mu.Unlock() - } - if a.Run != nil { - return f.run(ctx, a) - } - return gobuild.RunAsk(ctx, steps, a) - }} - go func() { _ = p.Pull(f.ctx) }() -} - -// serveForge answers the seat git's verb file as its holder does (milestone 47/G W6.14), with the go.mod the forge gave -// (internal/check/testdata/captured), whose mesh-sdk pin is cb54756c3865 unless the test set it as stale, and a member's -// manifest at its head as the bed holds it, else absent. -func (b *bed) serveForge(t *testing.T, nc *nats.Conn) { - var captured struct { - File struct { - Content string `json:"content"` - } `json:"file"` - } - if err := json.Unmarshal(mustRead(t, "forge-get-file-go-mod"), &captured); err != nil { - t.Fatal(err) - } - respond := func(m *nats.Msg, a gitseat.FileAnswer) { - answer, _ := json.Marshal(map[string]any{"result": a, "node": "n0"}) - _ = m.Respond(answer) - } - for _, subject := range []string{"mesh.seat.git.call.file", "mesh.seat.git.call.file.>"} { - sub, err := nc.Subscribe(subject, func(m *nats.Msg) { - var in gitseat.FileInput - _ = json.Unmarshal(m.Data, &in) - switch { - case strings.HasSuffix(in.Path, "module.json"): - // A manifest at a member's head (design 51 *Tagged versions*): the bed's own, else absent. - if content, ok := b.heads.Load(in.Repository + " " + in.Path + " " + in.Ref); ok { - respond(m, gitseat.FileAnswer{Path: in.Path, Ref: in.Ref, Content: content.(string)}) - return - } - respond(m, gitseat.FileAnswer{Path: in.Path, Ref: in.Ref, Absent: true}) - case b.stalePin.Load(): - respond(m, gitseat.FileAnswer{Path: in.Path, Ref: in.Ref, Content: strings.Replace(captured.File.Content, "cb54756c3865", "9aaa5c80ac5c", 1)}) - default: - respond(m, gitseat.FileAnswer{Path: in.Path, Ref: in.Ref, Content: captured.File.Content}) - } - }) - if err != nil { - t.Fatal(err) - } - t.Cleanup(func() { _ = sub.Unsubscribe() }) - } -} - -func mustRead(t *testing.T, name string) []byte { - t.Helper() - raw, err := os.ReadFile(filepath.Join(captured, name+".json")) - if err != nil { - t.Fatal(err) - } - return raw -} - -type bed struct { - stalePin atomic.Bool - // heads are the manifests the forge holds at a member's head, by " ". - heads sync.Map - ctx context.Context - js jetstream.JetStream - buckets map[string]jetstream.KeyValue - tools map[string]jetstream.KeyValue - // inputsAnswered counts the inputs the seat's verb input answered (issue 1921). - inputsAnswered atomic.Int32 - fake *fakeBuildModules - srvURL string - // trunk is the catalog half's trunk revision the bed's seat answers `revision` with (design 47 G section 197). - trunkNow *atomic.Value - announce []string - mu sync.Mutex - logs saidLog -} - -// saidLog is what the program said, safe for its goroutines and the test's. -type saidLog struct { - mu sync.Mutex - b strings.Builder -} - -func (l *saidLog) Write(p []byte) (int, error) { l.mu.Lock(); defer l.mu.Unlock(); return l.b.Write(p) } -func (l *saidLog) String() string { l.mu.Lock(); defer l.mu.Unlock(); return l.b.String() } - -// said waits until the program said words, within 20 s: an event to wait on, not a pause a loaded machine can outlast. -func (b *bed) said(t *testing.T, words string) { - t.Helper() - for deadline := time.Now().Add(20 * time.Second); !strings.Contains(b.logs.String(), words); time.Sleep(10 * time.Millisecond) { - if time.Now().After(deadline) { - t.Fatalf("the checker did not say %q within 20 s:\n%s", words, b.logs.String()) - } - } -} - -// engine places each node and serves compose-candidate for the first one, as its node-engine does on the bus (answered on -// the seat verb's caller-named and plain subjects); the others never answer. It answers what it was asked. -func (b *bed) engine(t *testing.T, nodes ...string) func() []ne.ComposeCandidateInput { - t.Helper() - kv, err := b.js.CreateKeyValue(b.ctx, jetstream.KeyValueConfig{Bucket: testAssigner + "_assignments", History: 1}) - if err != nil { - t.Fatal(err) - } - for _, n := range nodes { - pk, _ := meshmoduleassignerclient.NodeKey(n) - raw, _ := meshmoduleassignerclient.EncodeNode(meshmoduleassigner.AssignmentsByNodeNodeValue{Node: n}) - if _, err := kv.Put(b.ctx, pk, raw); err != nil { - t.Fatal(err) - } - } - nc, err := nats.Connect(b.srvURL, nats.UserInfo("ctl", "pw")) - if err != nil { - t.Fatal(err) - } - t.Cleanup(nc.Close) - var mu sync.Mutex - var asked []ne.ComposeCandidateInput - answer := func(m *nats.Msg) { - ask, err := nec.DecodeAsk(m.Data) - if err != nil { - _ = m.Respond([]byte(`{"error":"` + err.Error() + `"}`)) - return - } - mu.Lock() - asked = append(asked, ask) - mu.Unlock() - a := ne.ComposeCandidateAnswer{Node: nodes[0], Candidate: ask.Candidate, Verdict: nec.Composed, - Own: ne.Module{Module: nec.Own, State: nec.ModuleComposed, Digest: "sha256:" + strings.Repeat("b", 64)}} - raw, err := nec.EncodeAnswer(a) - if err != nil { - t.Error(err) - } - out, _ := json.Marshal(map[string]any{"result": json.RawMessage(raw), "node": nodes[0]}) - _ = m.Respond(out) - } - for _, subject := range []string{"mesh.seat.node-engine.call.compose-candidate." + nodes[0] + ".>", "mesh.seat.node-engine.tool.compose-candidate." + nodes[0]} { - if _, err := nc.Subscribe(subject, answer); err != nil { - t.Fatal(err) - } - } - return func() []ne.ComposeCandidateInput { - mu.Lock() - defer mu.Unlock() - return slices.Clone(asked) - } -} - -// startBed starts the bus, the buckets the controller makes from the checker's and the other parts' manifests, the build -// modules' streams and the checker's durable consumers on them, one node's toolchains, the gate's source naming the trunk, and -// the fake build modules. It runs no checker. -func startBed(t *testing.T) *bed { - dir, err := os.MkdirTemp(os.Getenv("TMPDIR"), "c") - if err != nil { - t.Fatal(err) - } - t.Cleanup(func() { os.RemoveAll(dir) }) - conf := filepath.Join(dir, "bus.conf") - if err := os.WriteFile(conf, []byte(fmt.Sprintf(busConf, filepath.Join(dir, "js"))), 0o600); err != nil { - t.Fatal(err) - } - opts, err := server.ProcessConfigFile(conf) - if err != nil { - t.Fatal(err) - } - opts.NoLog, opts.NoSigs = true, true - srv, err := server.NewServer(opts) - if err != nil { - t.Fatal(err) - } - go srv.Start() - if !srv.ReadyForConnections(10 * time.Second) { - t.Fatal("the bus did not come up") - } - t.Cleanup(srv.Shutdown) - ctl, err := nats.Connect(srv.ClientURL(), nats.UserInfo("ctl", "pw")) - if err != nil { - t.Fatal(err) - } - t.Cleanup(ctl.Close) - js, err := jetstream.New(ctl) - if err != nil { - t.Fatal(err) - } - // The seat mesh-catalog's holder answers the seat list with no trunk seat named: the checker's reader has then heard the seat - // and holds the bootstrapped definitions, which the judge is handed (ADR 0636 §1). - // It lists the build seats (design 47 G A-82): the seat whose acting rule builds Go and the one that builds TypeScript, from - // which the checker finds its build modules. - for _, subject := range []string{"mesh.seat.mesh-catalog.call.seat-definitions", "mesh.seat.mesh-catalog.call.seat-definitions.>"} { - if _, err := ctl.Subscribe(subject, func(m *nats.Msg) { _ = m.Respond(seatDefinitionsAnswer(m.Data)) }); err != nil { - t.Fatal(err) - } - } - trunkView := &atomic.Value{} - trunkView.Store(map[string]string{}) - for _, subject := range []string{"mesh.seat.mesh-catalog.call.revision", "mesh.seat.mesh-catalog.call.revision.>"} { - if _, err := ctl.Subscribe(subject, func(m *nats.Msg) { - var heads []meshcatalog.Head - for repo, commit := range trunkView.Load().(map[string]string) { - heads = append(heads, meshcatalog.Head{Repository: repo, Commit: commit}) - } - // Design 47 G §717, A-298: the trunk's entry of testAssigner claims mesh-module-assigner, so the catalog half names it - // the claimant whose seat-holders view the checker follows. - body, _ := json.Marshal(meshcatalog.RevisionAnswer{Revision: &meshcatalog.CatalogRevision{Kind: "trunk", Branch: "main", Revision: 1, Trunk: heads}, - Entries: []meshcatalog.CatalogEntry{{Module: testAssigner, ManifestDigest: "sha256:" + strings.Repeat("a", 64), - Manifest: map[string]any{"module": testAssigner, "claims": []any{map[string]any{"name": meshmoduleassigner.Seat}}}}}}) - reply, _ := json.Marshal(map[string]any{"result": json.RawMessage(body), "node": "ctl"}) - _ = m.Respond(reply) - }); err != nil { - t.Fatal(err) - } - } - ctx, cancel := context.WithTimeout(context.Background(), 90*time.Second) - t.Cleanup(cancel) - b := &bed{trunkNow: trunkView, ctx: ctx, js: js, buckets: map[string]jetstream.KeyValue{}, tools: map[string]jetstream.KeyValue{}, srvURL: srv.ClientURL()} - for _, module := range []string{goBuildModule, nodeBuildModule} { - kv, err := js.CreateKeyValue(ctx, jetstream.KeyValueConfig{Bucket: buildrun.ToolchainsBucket(module), History: 1}) - if err != nil { - t.Fatal(err) - } - b.tools[module] = kv - } - // What the controller keeps of the messages a consumer gave up on (issue 734). - if _, err := js.CreateStream(ctx, jetstream.StreamConfig{Name: buildrun.DeadLettersStream, Subjects: []string{"mesh.events.dead.>"}}); err != nil { - t.Fatal(err) - } - // The checker's streams as its manifest declares them (ADR 0619, ADR 0620), read from it so the bed holds every event - // it declares: checks, which the indexer and the forge bridge hear (preview, owed and a whole try's start and end, whose - // say would otherwise wait out its retries on a subject no stream holds), and asks, with verdict and tag-wanted. - raw, err := os.ReadFile("../../module.json") - if err != nil { - t.Fatal(err) - } - m, err := catalogue.Decode(raw) - if err != nil { - t.Fatal(err) - } - for _, s := range m.Streams { - var subjects []string - for _, e := range s.Events { - subjects = append(subjects, process.ModuleStreamSubject(testChecker, strings.ReplaceAll(e, "**", ">"))) - } - if _, err := js.CreateStream(ctx, jetstream.StreamConfig{Name: s.BusName(), Subjects: subjects}); err != nil { - t.Fatal(err) - } - } - if !slices.ContainsFunc(m.Streams, func(s catalogue.StreamDeclaration) bool { return s.Name == "checks" }) || - meshdeliverychecker.HolderSubjectVerdict(testChecker) != process.ModuleStreamSubject(testChecker, "verdict") { - t.Fatalf("the checker's manifest declares the streams %+v, want checks, and asks at the definition's subjects", m.Streams) - } - // The shared events stream with the seats' and modules' events (the package registry seats' published among them), and the checker's durable consumer of it. - if _, err := js.CreateOrUpdateStream(ctx, jetstream.StreamConfig{Name: process.EventsStream, Subjects: []string{"mesh.mod.*.event.>", "mesh.seat.*.event.>"}}); err != nil { - t.Fatal(err) - } - if _, err := js.CreateOrUpdateConsumer(ctx, process.EventsStream, jetstream.ConsumerConfig{Durable: "n1_mesh-delivery-checker", AckPolicy: jetstream.AckExplicitPolicy}); err != nil { - t.Fatal(err) - } - for name, history := range map[string]int{testBucket(meshdeliverychecker.StateVerdicts): 5, testBucket(meshdeliverychecker.StateKept): 1, - testBucket(meshdeliverychecker.StateOwed): 5, testBucket(meshdeliverychecker.StatePreviews): 5, check.CandidatesBucket: 10, - check.ModulesBucket: 20, check.ManifestsBucket: 1, - check.PresenceBucket: 20, check.HaveBucket: 20, testBucket(check.TriesState): 1, - builds.BuildsBucket(builds.BuilderModule): 1, testBucket(check.InputsStateName): 1} { - kv, err := js.CreateKeyValue(ctx, jetstream.KeyValueConfig{Bucket: name, History: uint8(history)}) - if err != nil { - t.Fatal(err) - } - b.buckets[name] = kv - } - // The indexer and the assigner as the owners of the states the checker follows: their read tools and views families - // (ADR 0615, DLV-M2). - for _, st := range []string{candidatesState, modulesState, manifestsState, meshcatalog.StatePackages, check.IndexerPredefinedState, seatDefinitionsState} { - viewstest.Serve(t, ctx, js, ctl, check.IndexerModule, st, check.IndexerModule+".indexer_read_"+strings.ReplaceAll(st, "-", "_"), "n1_"+testChecker) - } - // The catalog half's registrations and the gate's source branch (design 47 G §614), and the claimant's seat-holders view naming - // testAssigner the holder of mesh-module-assigner (§717): nothing answers the seat's verb assignments. - for subject, result := range map[string]any{"mesh.seat.mesh-catalog.call.registrations": meshcatalog.RegistrationsAnswer{Registrations: []meshcatalog.Registration{}}, - "mesh.seat.mesh-delivery.call.source": map[string]any{"branches": []string{"main"}}} { - reply, _ := json.Marshal(map[string]any{"result": result, "node": "ctl"}) - for _, s := range []string{subject, subject + ".>"} { - if _, err := ctl.Subscribe(s, func(m *nats.Msg) { _ = m.Respond(reply) }); err != nil { - t.Fatal(err) - } - } - } - seatHolders := viewstest.Serve(t, ctx, js, ctl, testAssigner, meshmoduleassigner.StateSeatHolders, testAssigner+"."+meshmoduleassigner.StateSeatHolders, "n1_"+testChecker) - if _, err := seatHolders.Put(ctx, meshmoduleassigner.Seat, []byte(`{"seat":"`+meshmoduleassigner.Seat+`","holders":[{"module":"`+testAssigner+`","node":"n1"}]}`)); err != nil { - t.Fatal(err) - } - viewstest.Serve(t, ctx, js, ctl, testAssigner, meshmoduleassigner.StateAssignments, testAssigner+"."+meshmoduleassigner.StateAssignments, "n1_"+testChecker) - // 1929/AC1: the indexer's value of the repository's module, with no TypeScript manifest, so the Go build module alone - // judges the repository (an unknown repository is judged by both, issue 1887 A12). - known, err := meshcatalogclient.EncodeModule(meshcatalog.ModulesByModuleValue{Repository: repo, Commit: trunk, Path: "modules/m", None2: "the fingerprint is computed with its chain"}) - if err != nil { - t.Fatal(err) - } - if _, err := b.buckets[check.ModulesBucket].Put(ctx, "m", known); err != nil { - t.Fatal(err) - } - b.setOnline(t, "n1", true) - b.setNode(t, "n1") - // The indexer's modules name the holders of the build seats, by the seats their manifests claim. - b.putBuildModule(t, goBuildModule, "node-build-go") - b.putBuildModule(t, nodeBuildModule, "node-build-node") - for _, module := range []string{goBuildModule, nodeBuildModule} { - b.setHealth(t, "n1", module) - } - b.serveForge(t, ctl) - b.serveInputVerb(t, ctl) - b.fake = &fakeBuildModules{js: js, ctx: ctx, calls: map[string]int{}} - b.fake.serve(t, goBuildModule, b.buckets[testBucket(meshdeliverychecker.StateKept)]) - b.fake.serve(t, nodeBuildModule, b.buckets[testBucket(meshdeliverychecker.StateKept)]) - b.report(t, goBuildModule, "n1", "go", "go1.27.1", "1") - b.report(t, nodeBuildModule, "n1", "typescript", "tsc5", "1") - b.setTrunk(t, map[string]string{repo: trunk}) - return b -} - -func (b *bed) setTrunk(t *testing.T, heads map[string]string) { - t.Helper() - b.trunkNow.Store(heads) - body, _ := json.Marshal(meshcatalog.CatalogRevisionEvent{Kind: "trunk", Branch: "main", Revision: 1, V: 1}) - if _, err := b.js.Publish(b.ctx, meshcatalog.SubjectCatalogRevision("main"), body); err != nil { - t.Fatal(err) - } -} - -func (b *bed) setOnline(t *testing.T, node string, online bool) { - t.Helper() - data, _ := json.Marshal(meshwatchdogs.PresenceByNodeValue{V: keys.Version, Online: online}) - if _, err := b.buckets[check.PresenceBucket].Put(b.ctx, node, data); err != nil { - t.Fatal(err) - } -} - -// setNode writes the node's record in the node-engine's have, as the node-engine does, so the checker names it in each -// check ask (ADR 0567 §12); with no record the checker asks no check. -func (b *bed) setNode(t *testing.T, node string) { - t.Helper() - data, err := nodeengineclient.EncodeHaveNode(nodeengine.HaveByNodeNodeValue{Record: &nodeengine.NodeRecord{Node: node}}) - if err != nil { - t.Fatal(err) - } - key, _ := nodeengineclient.HaveNodeKey(node) - if _, err := b.buckets[check.HaveBucket].Put(b.ctx, key, data); err != nil { - t.Fatal(err) - } -} - -func (b *bed) setHealth(t *testing.T, node, module string) { - t.Helper() - data, err := nodeengineclient.EncodeHave(nodeengine.HaveByNodeModuleValue{Phase: nodeengineclient.PhaseRunning, Health: nodeengineclient.HealthOK}) - if err != nil { - t.Fatal(err) - } - key, _ := nodeengineclient.HaveKey(node, module) - if _, err := b.buckets[check.HaveBucket].Put(b.ctx, key, data); err != nil { - t.Fatal(err) - } -} - -func (b *bed) report(t *testing.T, module, node, language, version, recipe string) { - t.Helper() - data, err := buildstep.EncodeToolchain(buildstep.Toolchain{Language: language, Version: version, Recipe: recipe, At: time.Now().UTC()}) - if err != nil { - t.Fatal(err) - } - key, _ := buildstep.ToolchainKey(node, language) - if _, err := b.tools[module].Put(b.ctx, key, data); err != nil { - t.Fatal(err) - } - seat := "node-build-go" - if module == nodeBuildModule { - seat = "node-build-node" - } - if _, err := b.js.Publish(b.ctx, "mesh.seat."+seat+".event.toolchain-reported."+node, []byte(`{}`)); err != nil { - t.Fatal(err) - } -} - -// candidate writes candidates. as the indexer does (the SDK's EncodeCandidate is the indexer's own encoder). -func (b *bed) candidate(t *testing.T, group string, pulls ...meshcatalog.CandidatesByGroupValuePullsItem) string { - t.Helper() - heads := make([]meshdeliveryclient.Head, len(pulls)) - for i, p := range pulls { - heads[i] = meshdeliveryclient.Head{Repository: p.Repository, Number: int(p.Number), Head: p.Head} - } - hash, err := meshdeliveryclient.HeadsHash(heads) - if err != nil { - t.Fatal(err) - } - data, err := json.Marshal(meshcatalog.CandidatesByGroupValue{V: keys.Version, Group: group, Heads: hash, Pulls: pulls, Fpset: meshcatalogclient.FingerprintSet(pulls)}) - if err != nil { - t.Fatal(err) - } - key, _ := meshcatalogclient.CandidatesKey(group) - if _, err := b.buckets[check.CandidatesBucket].Put(b.ctx, key, data); err != nil { - t.Fatal(err) - } - vk, _ := meshdeliverycheckerclient.VerdictKey(group, hash) - return vk -} - -func pull(repository string, number int, head string) meshcatalog.CandidatesByGroupValuePullsItem { - return meshcatalog.CandidatesByGroupValuePullsItem{Repository: repository, Number: int64(number), Head: head, Modules: []string{}} -} - -// start runs the program as the checker of a node. -func (b *bed) start(t *testing.T, env map[string]string) { - t.Helper() - broker := filepath.Join(t.TempDir(), "broker") - cred, _ := json.Marshal(process.Account{URL: b.srvURL, Node: "n1", Module: "mesh-delivery-checker", User: "n1.mesh-delivery-checker", Password: "pw"}) - if err := os.WriteFile(broker, cred, 0o600); err != nil { - t.Fatal(err) - } - // The settle window of a group's heads (check.DefaultSettle) is cut short: each bed's candidate is written whole. - e := map[string]string{"MESH_BROKER_FILE": broker, "MESH_CHECKER_SETTLE": "10ms"} - for k, v := range env { - e[k] = v - } - runCtx, stop := context.WithCancel(b.ctx) - done := make(chan error, 1) - go func() { done <- run(runCtx, func(k string) string { return e[k] }, &b.logs) }() - t.Cleanup(func() { stop(); <-done }) -} - -// verdict reads the verdict key until pred holds of it, within 20 s. -func (b *bed) verdict(t *testing.T, key string, pred func(meshdeliverychecker.VerdictsByGroupHeadsValue) bool) meshdeliverychecker.VerdictsByGroupHeadsValue { - t.Helper() - var last meshdeliverychecker.VerdictsByGroupHeadsValue - for deadline := time.Now().Add(20 * time.Second); time.Now().Before(deadline); time.Sleep(50 * time.Millisecond) { - e, err := b.buckets[testBucket(meshdeliverychecker.StateVerdicts)].Get(b.ctx, key) - if err != nil { - continue - } - if last, err = meshdeliverycheckerclient.DecodeVerdict(e.Value()); err == nil && pred(last) { - return last - } - } - t.Fatalf("verdicts.%s = %+v within 20 s", key, last) - return last -} - -func ended(v meshdeliverychecker.VerdictsByGroupHeadsValue) bool { - return v.State != meshdeliverycheckerclient.VerdictRunning -} - -// owed reads the status the checker owes on a head. -func (b *bed) owed(t *testing.T, number int, head, state string) meshdeliverychecker.OwedByRepositoryNumberHeadActValue { - t.Helper() - key, err := check.CheckerOwedKey(repo, number, head) - if err != nil { - t.Fatal(err) - } - var last meshdeliverychecker.OwedByRepositoryNumberHeadActValue - for deadline := time.Now().Add(20 * time.Second); time.Now().Before(deadline); time.Sleep(50 * time.Millisecond) { - e, err := b.buckets[testBucket(meshdeliverychecker.StateOwed)].Get(b.ctx, key) - if err != nil { - continue - } - if last, err = check.DecodeCheckerOwed(e.Value()); err == nil && last.State == state { - return last - } - } - t.Fatalf("owed.%s = %+v within 20 s, want the state %s", key, last, state) - return last -} - -// TestCheckerJudgesACandidateAndOwesItsStatus: a candidate the indexer wrote, one pull request of mesh-delivery, is fetched -// merged onto the trunk the gate names, digested and tested at both levels on the node, kept, previewed; the verdict passes -// with the counts of both levels and the composition not run, and the status mesh/check is owed on the head as success. -func TestCheckerJudgesACandidateAndOwesItsStatus(t *testing.T) { // N6/AC5, 1300/AC5, 1445/AC1, 1929/AC1, ADR 0603 §10 - b := startBed(t) - // ADR 0603 §10: the candidate changes the module m, whose manifest the trunk holds; the builder has not built m's - // candidate fingerprint yet, so the check waits on the builder's key before it composes. - manifest := `{"module":"m"}` - digest := meshcatalogclient.ManifestDigest([]byte(manifest)) - stored, err := meshcatalogclient.EncodeManifest(meshcatalog.ManifestsByDigestValue{Module: "m", Manifest: manifest}) - if err != nil { - t.Fatal(err) - } - mkey, _ := meshcatalogclient.ManifestsKey(digest) - if _, err := b.buckets[check.ManifestsBucket].Put(b.ctx, mkey, stored); err != nil { - t.Fatal(err) - } - known, err := meshcatalogclient.EncodeModule(meshcatalog.ModulesByModuleValue{Repository: repo, Commit: trunk, Path: "modules/m", Manifest: digest, None2: "the fingerprint is computed with its chain"}) - if err != nil { - t.Fatal(err) - } - if _, err := b.buckets[check.ModulesBucket].Put(b.ctx, "m", known); err != nil { - t.Fatal(err) - } - fp := "src2:" + strings.Repeat("f", 64) - p := pull(repo, 7, head1) - p.Modules, p.Fps = []string{"m"}, map[string]meshcatalog.CandidatesByGroupValuePullsItemFpsValue{"m": {Fp2: fp, Manifest: digest}} - key := b.candidate(t, "feat/x", p) - // ADR 0593 §7, §9 (D12): n1 and n2 are placed; n1's engine answers compose-candidate on the bus, n2's never does. - asked := b.engine(t, "n1", "n2") - b.start(t, nil) - b.said(t, "waits on the builder's builds of m before it composes") - if got := asked(); len(got) != 0 { - t.Fatalf("the engines were asked %+v before m's build ended", got) - } - bkey, _ := builds.BuilderBuildKey("m", fp) - building, _ := json.Marshal(builds.BuilderBuild{V: 1, State: builds.BuildBuilding}) - if _, err := b.buckets[builds.BuildsBucket(builds.BuilderModule)].Put(b.ctx, bkey, building); err != nil { - t.Fatal(err) - } - if v := b.verdict(t, key, func(meshdeliverychecker.VerdictsByGroupHeadsValue) bool { return true }); v.State != meshdeliverycheckerclient.VerdictRunning || len(asked()) != 0 { - t.Fatalf("verdict %s and %d asks while m builds: the check composes only once its build ended", v.State, len(asked())) - } - // m's build fails: the check fails naming it. Built again (builder_build_again writes the key done), the check asks - // itself again for the same heads, with no recheck, and passes. - failedBuild, _ := json.Marshal(builds.BuilderBuild{V: 1, State: builds.BuildFailed, Error: "go build: undefined: x"}) - if _, err := b.buckets[builds.BuildsBucket(builds.BuilderModule)].Put(b.ctx, bkey, failedBuild); err != nil { - t.Fatal(err) - } - if v := b.verdict(t, key, ended); v.State != meshdeliverycheckerclient.VerdictFail || v.Failed.Test != check.BuildFailedTest+"m" { - t.Fatalf("verdict %+v, want it failed on m's build", v) - } - built, _ := json.Marshal(builds.BuilderBuild{V: 1, State: builds.BuildDone, Manifest: digest}) - if _, err := b.buckets[builds.BuildsBucket(builds.BuilderModule)].Put(b.ctx, bkey, built); err != nil { - t.Fatal(err) - } - b.said(t, "the builds of m it failed on are done again, so it is checked again") - v := b.verdict(t, key, func(v meshdeliverychecker.VerdictsByGroupHeadsValue) bool { - return v.State == meshdeliverycheckerclient.VerdictPass - }) - // The check asked again takes the packages the failed check ran from their kept verdicts. - if v.State != meshdeliverycheckerclient.VerdictPass || v.Levels[buildstep.LevelUnit].Kept != 2 || v.Levels[buildstep.LevelIntegration].Kept != 2 || v.Trunk[repo] != trunk { - t.Fatalf("verdict = %+v", v) - } - if c := v.Composition; c == nil || c.State != meshdeliverycheckerclient.CompositionPass || !slices.Equal(c.Machines, []string{"n1"}) || - !strings.Contains(c.Words, "n2: "+nec.NoAnswer) || len(v.Machines) != 1 || v.Machines[0] != "n1" { - t.Errorf("composition %+v machines %v", v.Composition, v.Machines) - } - if v.Composition != nil && strings.Contains(v.Composition.Words, "did not end") { - t.Errorf("the composition says %q: m's build ended within the bound", v.Composition.Words) - } - if got := asked(); len(got) == 0 || got[0].Candidate != key { - t.Errorf("n1's engine was asked %+v, want the check's candidate %s", got, key) - } - // Issue 1921 (B0): the verdict is the checking program's, built at the group's mesh-delivery head over its input kept in - // the state inputs and asked of the seat's verb input, two run asks a check (the seat list, the verdict); the verdict names the program's build. - if by := v.JudgedBy; by == nil || by.Program.Commit != head1 || by.Program.Package != check.CheckingProgramPackage || - by.Key != "program-0123456789abcdef" || len(by.Heads) != 1 || by.Heads[0].Commit != head1 { - t.Errorf("judged by %+v, want the checking program at the head %s", v.JudgedBy, head1) - } - if n := b.fake.runs.Load(); n != 4 { - t.Errorf("%d run asks, want two for each of the two checks", n) - } - // The operator's answer on B0: each run's input reached the build module through the seat's verb input on the bus. - if n := b.inputsAnswered.Load(); n != 4 { - t.Errorf("the verb input answered %d inputs, want one for each run ask", n) - } - b.fake.mu.Lock() - names := b.fake.names - b.fake.mu.Unlock() - if len(names) != 1 || names[0] != "n1" { - t.Errorf("the check ask named the nodes %v, want [n1] from the have's node record", names) - } - o := b.owed(t, 7, head1, "success") - if o.Context != meshdeliveryclient.StatusContextCheck || !strings.HasPrefix(o.Text, "pass 111111111111 on aaaaaaaaaaaa") || !strings.Contains(o.Text, "unit 0 run, 2 kept") { - t.Errorf("owed = %+v", o) - } - // Two checks of the same heads: the one failed on m's build and the one it asked itself again; the second runs no test. - for tool, want := range map[string]int{goBuildModule + ".build_go_fetch": 2, goBuildModule + ".build_go_digest": 4, goBuildModule + ".build_go_test": 2} { - if got := b.fake.count(tool); got != want { - t.Errorf("%s called %d times, want %d", tool, got, want) - } - } - // What passed is kept once under each level's digest. - for _, k := range []string{"unit." + digU, "integration." + digI} { - if _, err := b.buckets[testBucket(meshdeliverychecker.StateKept)].Get(b.ctx, k); err != nil { - t.Errorf("kept.%s: %v", k, err) - } - } - // The preview of the head merged onto the trunk, with the tree and the manifest digest the fetch named. - pk, _ := meshdeliverycheckerclient.PreviewKey(repo, head1, trunk) - e, err := b.buckets[testBucket(meshdeliverychecker.StatePreviews)].Get(b.ctx, pk) - if err != nil { - t.Fatalf("previews.%s: %v", pk, err) - } - pv, err := meshdeliverycheckerclient.DecodePreview(e.Value()) - if err != nil || pv.Merge != merged || pv.Modules["modules/m"].Tree != "1111111111111111111111111111111111111111" { - t.Errorf("preview = %+v, %v", pv, err) - } -} - -// TestACheckOrACarryOfEqualInputsRunsNothing: a second candidate (another head, the same digests) is checked with every -// package taken from the first's kept verdicts: no test step runs and no second kept key appears. Then, through the real bus -// (novox/hq ADR 0548 §3, §5): a third candidate is not claimed while the gate's merge turn on its repository stands, and is -// claimed when the turn's key is deleted; and a move of the trunk carries the first verdict on the recheck stream by its -// unchanged digests, running no test, the verdict naming the trunk it was carried from. -func TestACheckOrACarryOfEqualInputsRunsNothing(t *testing.T) { // 1287/AC5, 1288/AC6, 1929/AC2, ADR 0548 §3, §5 - b := startBed(t) - first := b.candidate(t, "feat/x", pull(repo, 7, head1)) - b.start(t, nil) - b.verdict(t, first, ended) - tests, kept := b.fake.count(goBuildModule+".build_go_test"), keptCount(t, b) - second := b.candidate(t, "feat/y", pull(repo, 8, head2)) - v := b.verdict(t, second, ended) - if v.State != meshdeliverycheckerclient.VerdictPass || v.Levels[buildstep.LevelUnit].Run != 0 || v.Levels[buildstep.LevelUnit].Kept != 2 || v.Levels[buildstep.LevelIntegration].Run != 0 { - t.Fatalf("verdict = %+v, want everything taken from the kept verdicts", v) - } - if got := b.fake.count(goBuildModule + ".build_go_test"); got != tests { - t.Errorf("build_go_test called %d times, was %d: a test ran for equal inputs", got, tests) - } - if got := keptCount(t, b); got != kept { - t.Errorf("%d kept keys, was %d", got, kept) - } - - // Design 47 G §278 (test 52): a new check is claimed at once, with no state of the gate granted to the checker. - third := b.candidate(t, "feat/z", pull(repo, 9, "3333333333333333333333333333333333333333")) - b.verdict(t, third, ended) - - // §5: the trunk moves; the first verdict is carried by its digests, nothing runs. - tests = b.fake.count(goBuildModule + ".build_go_test") - const moved = "abababababababababababababababababababab" - b.setTrunk(t, map[string]string{repo: moved}) - c := b.verdict(t, first, func(v meshdeliverychecker.VerdictsByGroupHeadsValue) bool { return ended(v) && v.Trunk[repo] == moved }) - if c.State != meshdeliverycheckerclient.VerdictPass || c.CarriedFrom[repo] != trunk || c.Levels[buildstep.LevelUnit].Run != 0 || c.Levels[buildstep.LevelIntegration].Run != 0 { - t.Fatalf("the carried verdict = %+v, want a pass carried from %s with no test run", c, trunk[:12]) - } - if got := b.fake.count(goBuildModule + ".build_go_test"); got != tests { - t.Errorf("build_go_test called %d times on the carry, was %d: a carry of unchanged digests runs nothing", got, tests) - } - if o := b.owed(t, 7, head1, "success"); !strings.HasPrefix(o.Text, "pass 111111111111 on abababababab | carried from aaaaaaaaaaaa") { - t.Errorf("the carried status says %q", o.Text) - } -} - -func keptCount(t *testing.T, b *bed) int { - t.Helper() - keys, err := b.buckets[testBucket(meshdeliverychecker.StateKept)].Keys(b.ctx) - if err != nil { - return 0 - } - return len(keys) -} - -// TestACheckThatCannotBeJudgedFailsNamingWhy: a head that does not merge fails naming the files in conflict and runs no -// test (1289/AC4); a checking program whose run asks no build node begins, and one that does not build, fail the check -// naming the checking program, never judged by the running rules (issue 1921, the lead's ruling on milestone 47/B0: the -// begin bound is the checker's setting, shortened here). -func TestACheckThatCannotBeJudgedFailsNamingWhy(t *testing.T) { // 1289/AC4, 1921 - for _, row := range []struct { - name string - set func(f *fakeBuildModules) - env map[string]string - words string - tests bool // the digest and test steps ran - dropped int32 // the run asks dropped: the seat list's, put twice, and no verdict asked after it - program bool // the checking program judged it - }{ - {name: "a head that does not merge", set: func(f *fakeBuildModules) { f.conflict.Store(true) }, words: "files in conflict: a.go, sub/b.go", program: true}, - {name: "a run ask no build node begins", set: func(f *fakeBuildModules) { f.drop.Store(true) }, env: map[string]string{"MESH_CHECKER_BEGIN_BOUND": "500ms"}, - words: "no build node began the job run of the asks", tests: true, dropped: 2}, - {name: "a program that does not build", set: func(f *fakeBuildModules) { f.broken.Store("go build: undefined: rules.Nothing") }, - words: "by the checking program: its run ask", tests: true}, - } { - t.Run(row.name, func(t *testing.T) { - b := startBed(t) - row.set(b.fake) - key := b.candidate(t, "feat/x", pull(repo, 7, head1)) - b.start(t, row.env) - v := b.verdict(t, key, ended) - if v.State != meshdeliverycheckerclient.VerdictFail || !strings.Contains(v.Failed.Words, row.words) || (v.JudgedBy != nil) != row.program { - t.Fatalf("verdict = %+v, want a fail saying %q, judged by the program %v", v, row.words, row.program) - } - if o := b.owed(t, 7, head1, "failure"); !strings.HasPrefix(o.Text, "failed") || - !strings.Contains(o.Text, map[bool]string{true: row.words, false: "the checking program"}[row.program]) { - t.Errorf("owed = %+v", o) - } - if n := b.fake.count(goBuildModule+".build_go_digest") + b.fake.count(goBuildModule+".build_go_test"); (n != 0) != row.tests { - t.Errorf("%d digest and test steps ran, want them run %v", n, row.tests) - } - if n := b.fake.dropped.Load(); n != row.dropped { - t.Errorf("%d run asks dropped, want %d", n, row.dropped) - } - if !row.tests { - pk, _ := meshdeliverycheckerclient.PreviewKey(repo, head1, trunk) - if e, err := b.buckets[testBucket(meshdeliverychecker.StatePreviews)].Get(b.ctx, pk); err != nil { - t.Errorf("previews.%s: %v", pk, err) - } else if pv, err := meshdeliverycheckerclient.DecodePreview(e.Value()); err != nil || strings.Join(pv.Conflicts, ",") != "a.go,sub/b.go" || pv.Merge != "" { - t.Errorf("preview = %+v, %v, want the files in conflict alone", pv, err) - } - } - }) - } -} - -// TestAnHqPullRequestGetsNoVerdictAndAnotherDoes: hq's pull request is judged by no one (ADR 0484 clause 8), the other one in -// the same run is. -// 1887/A10, ADR 0527 §2: a pull request into hq gets a verdict and a mesh/check from the checker, as any repository's. -func TestAnHqPullRequestGetsAVerdictAndAStatus(t *testing.T) { - b := startBed(t) - b.setTrunk(t, map[string]string{repo: trunk, "novox/hq": trunk}) - hq := b.candidate(t, "feat/hq", pull("novox/hq", 3, head1)) - b.start(t, nil) - if v := b.verdict(t, hq, ended); v.State != meshdeliverycheckerclient.VerdictPass { - t.Fatalf("hq's verdict = %+v", v) - } - key, _ := check.CheckerOwedKey("novox/hq", 3, head1) - for deadline := time.Now().Add(20 * time.Second); ; time.Sleep(50 * time.Millisecond) { - if e, err := b.buckets[testBucket(meshdeliverychecker.StateOwed)].Get(b.ctx, key); err == nil { - if o, err := check.DecodeCheckerOwed(e.Value()); err == nil && o.State == "success" { - return - } - } - if time.Now().After(deadline) { - t.Fatalf("hq#3 owes no success within 20 s") - } - } -} - -// TestACheckLeftRunningIsTakenOverWhenTheCheckerStarts: the verdict key holds running, left by a checker that stopped; the -// started checker judges it again and ends it (ADR 0478 clause 6, as the builder's). -func TestACheckLeftRunningIsTakenOverWhenTheCheckerStarts(t *testing.T) { // N6/AC2 - b := startBed(t) - key := b.candidate(t, "feat/x", pull(repo, 7, head1)) - group, heads, _ := meshdeliverycheckerclient.ParseVerdictKey(key) - left, err := meshdeliverycheckerclient.EncodeVerdict(meshdeliverychecker.VerdictsByGroupHeadsValue{Group: group, Heads: heads, Trunk: map[string]string{repo: trunk}, State: meshdeliverycheckerclient.VerdictRunning}) - if err != nil { - t.Fatal(err) - } - if _, err := b.buckets[testBucket(meshdeliverychecker.StateVerdicts)].Create(b.ctx, key, left); err != nil { - t.Fatal(err) - } - b.start(t, nil) - if v := b.verdict(t, key, ended); v.State != meshdeliverycheckerclient.VerdictPass { - t.Errorf("verdict = %+v", v) - } -} - -// TestAMemberNamingAMeshSDKCommitOffTheTrunkIsJudgedAndNotRefused: the go.mod the forge answers names a commit that main does -// not hold; the check is not refused for it, since the build takes the latest published mesh-sdk whatever go.mod names -// (novox/hq ADR 0573 §2, §4; issue 1585 S14, which retires issue 1624's pin check). -func TestAMemberNamingAMeshSDKCommitOffTheTrunkIsJudgedAndNotRefused(t *testing.T) { // 1624/AC2 as ADR 0573 §4 changes it - b := startBed(t) - b.stalePin.Store(true) - key := b.candidate(t, "feat/x", pull(repo, 7, head1)) - b.start(t, nil) - if v := b.verdict(t, key, ended); v.State != meshdeliverycheckerclient.VerdictPass { - t.Fatalf("verdict = %+v", v) - } - - // Design 47 G §528: a group whose mesh-sdk member declares a Go package is judged at once, with no tagged version asked - // or waited for, and its other member is built against the group's head. - const sdkRepo = "novox/mesh-sdk" - b.setTrunk(t, map[string]string{repo: trunk, sdkRepo: trunk}) - b.heads.Store(sdkRepo+" module.json "+head2, `{"module":"mesh-sdk","build":{"artifacts":[{"name":"go","kind":"package","language":"go","paths":["go"]}]}}`) - sdk := pull(sdkRepo, 12, head2) - sdk.Modules, sdk.Fps = []string{"mesh-sdk"}, map[string]meshcatalog.CandidatesByGroupValuePullsItemFpsValue{"mesh-sdk": {Fp2: "src2:" + strings.Repeat("e", 64)}} - key = b.candidate(t, "feat/x", pull(repo, 8, head1), sdk) - if v := b.verdict(t, key, ended); v.State != meshdeliverycheckerclient.VerdictPass { - t.Fatalf("the group's verdict = %+v", v) - } - b.fake.mu.Lock() - got := b.fake.packages[repo] - b.fake.mu.Unlock() - if got[check.SDKModulePath] != head2 { - t.Errorf("mesh-delivery was built against %v, want mesh-sdk's Go module at the group's head %s", got, head2) - } - - // DLV-C2, DLV-C6 (design 26 *Out of step*, ADR 0620): each check's end says one verdict per pull request on the stream - // asks, at the definition's subject and in its body (decoded strictly): the lone pull request's, then the group's two. - verdicts, err := b.js.OrderedConsumer(b.ctx, "ASKS", jetstream.OrderedConsumerConfig{FilterSubjects: []string{meshdeliverychecker.HolderSubjectVerdict(testChecker)}}) - if err != nil { - t.Fatal(err) - } - said := map[int64]meshdeliverychecker.VerdictHolderEvent{} - for len(said) < 3 { - msg, err := verdicts.Next(jetstream.FetchMaxWait(20 * time.Second)) - if err != nil { - t.Fatalf("verdicts said %+v, then none: %v", said, err) - } - var e meshdeliverychecker.VerdictHolderEvent - dec := json.NewDecoder(bytes.NewReader(msg.Data())) - dec.DisallowUnknownFields() - if err := dec.Decode(&e); err != nil { - t.Fatalf("verdict %s is not the definition's body: %v", msg.Data(), err) - } - if _, twice := said[e.Pull]; twice { - t.Errorf("a second verdict of pull %d: %+v", e.Pull, e) - } - said[e.Pull] = e - } - for pull, want := range map[int64]meshdeliverychecker.VerdictHolderEvent{7: {Repository: repo, Pull: 7, Head: head1, Verdict: meshdeliverycheckerclient.VerdictPass}, - 8: {Repository: repo, Pull: 8, Head: head1, Verdict: meshdeliverycheckerclient.VerdictPass}, 12: {Repository: sdkRepo, Pull: 12, Head: head2, Verdict: meshdeliverycheckerclient.VerdictPass}} { - if got := said[pull]; got.Repository != want.Repository || got.Head != want.Head || got.Verdict != want.Verdict || len(got.OutOfStep) != 0 { - t.Errorf("verdict of pull %d = %+v, want %+v", pull, got, want) - } - } -} - -// triesStore is the tries bucket as the tools write it. -type triesStore struct { - kv jetstream.KeyValue - ctx context.Context -} - -func (s triesStore) Keys() ([]string, error) { - keys, err := s.kv.Keys(s.ctx) - if err == jetstream.ErrNoKeysFound { - return nil, nil - } - return keys, err -} -func (s triesStore) Get(key string) (json.RawMessage, error) { - e, err := s.kv.Get(s.ctx, key) - if err == jetstream.ErrKeyNotFound { - return nil, nil - } - if err != nil { - return nil, err - } - return e.Value(), nil -} -func (s triesStore) Create(key string, value []byte) error { - _, err := s.kv.Create(s.ctx, key, value) - return err -} - -// TestATryIsJudgedAndItsEndWrittenWithNoStatusOwed: a try written as checker_try writes it is taken by the running checker, -// judged through the build modules as a pull request's head merged onto its trunk, and ended pass in its key, with no -// verdict and no status owed (ADR 0501 §5). A whole try waits for the indexer's candidate of its group, which it reads on the -// key's watch, and writes the merge previews the indexer makes it from (issue 1921). -func TestATryIsJudgedAndItsEndWrittenWithNoStatusOwed(t *testing.T) { - b := startBed(t) - asked := b.engine(t, "n1") // a whole try is composed on every placed node, as a group's check is - b.start(t, nil) - store := triesStore{b.buckets[testBucket(check.TriesState)], b.ctx} - id, err := check.AskTry(store, map[string]string{repo: trunk}, check.TryAsk{Repository: repo, Head: head1}, time.Now()) - if err != nil { - t.Fatal(err) - } - var last check.Try - // The indexer's candidate of the try's group (here written by the test), at the heads of its members. - b.candidate(t, id, pull(repo, 0, head1)) - for deadline := time.Now().Add(20 * time.Second); time.Now().Before(deadline); time.Sleep(50 * time.Millisecond) { - raw, _ := store.Get(id) - if last, err = check.DecodeTry(raw); err == nil && last.Over() { - break - } - } - if last.State != check.TryPass || last.Trunk != trunk || last.Took == "" || last.Composition == nil { - t.Fatalf("try = %+v, want passed on the trunk with its composition made", last) - } - if got := asked(); len(got) != 1 || !strings.HasPrefix(got[0].Candidate, id+".") { - t.Errorf("the placed node's engine was asked %+v, want the try's candidate %s.", got, id) - } - if b.fake.count(goBuildModule+".build_go_fetch") == 0 { - t.Errorf("the try fetched nothing") - } - // A whole try's start and end are said on the stream checks, which the indexer hears to write and delete the - // candidate of its group: said once each, never waited out on a subject no stream holds. - checks, err := b.js.Stream(b.ctx, "CHECKS") - if err != nil { - t.Fatal(err) - } - for _, event := range []string{checkermsg.Started, checkermsg.Ended} { // the end is said once the try's end is written - said, err := b.js.OrderedConsumer(b.ctx, checks.CachedInfo().Config.Name, jetstream.OrderedConsumerConfig{ - FilterSubjects: []string{process.ModuleStreamSubject(testChecker, event)}}) - if err != nil { - t.Fatal(err) - } - if m, err := said.Next(jetstream.FetchMaxWait(5 * time.Second)); err != nil || !strings.Contains(string(m.Data()), id) { - t.Errorf("the stream checks holds no %s of the try %s: %v", event, id, err) - } - } - for _, name := range []string{testBucket(meshdeliverychecker.StateOwed), testBucket(meshdeliverychecker.StateVerdicts)} { - if keys, _ := b.buckets[name].Keys(b.ctx); len(keys) != 0 { - t.Errorf("a try wrote %s: %v", name, keys) - } - } - // Issue 734: a try whose ask the build seat gives up on (the controller keeps its copy in DEAD_LETTERS with the ask's - // message id) ends as error saying so, and its head asked again is a new try. - b.fake.hold.Store(head2) - lost, err := check.AskTry(store, map[string]string{repo: trunk}, check.TryAsk{Repository: repo, Head: head2}, time.Now()) - if err != nil { - t.Fatal(err) - } - steps, err := b.js.KeyValue(b.ctx, buildrun.StepsBucket(goBuildModule)) - if err != nil { - t.Fatal(err) - } - askID := "" - for deadline := time.Now().Add(20 * time.Second); askID == "" && time.Now().Before(deadline); time.Sleep(50 * time.Millisecond) { - keys, _ := steps.Keys(b.ctx) - for _, k := range keys { - if e, err := steps.Get(b.ctx, k); err == nil && strings.Contains(string(e.Value()), `"running"`) { - askID = strings.TrimPrefix(k, "n1.") - } - } - } - if askID == "" { - t.Fatal("the held try's ask was never taken") - } - dead := &nats.Msg{Subject: "mesh.events.dead.SEAT_NODE_BUILD_GO.SEAT_NODE_BUILD_GO_CHECK_worker", Header: nats.Header{}} - dead.Header.Set(buildrun.DeadHeaderMsgID, askID) - dead.Header.Set(buildrun.DeadHeaderDeliveries, "5") - dead.Header.Set(buildrun.DeadHeaderStream, "SEAT_NODE_BUILD_GO") - dead.Header.Set(buildrun.DeadHeaderGaveUp, time.Now().UTC().Format(time.RFC3339Nano)) - if _, err := b.js.PublishMsg(b.ctx, dead); err != nil { - t.Fatal(err) - } - for deadline := time.Now().Add(20 * time.Second); time.Now().Before(deadline); time.Sleep(50 * time.Millisecond) { - raw, _ := store.Get(lost) - if last, err = check.DecodeTry(raw); err == nil && last.Over() { - break - } - } - if last.State != check.TryError || !strings.Contains(last.Said, buildrun.LostWords+" after 5 deliveries") { - t.Fatalf("the try whose ask was given up = %+v, want error saying so", last) - } - if again, err := check.AskTry(store, map[string]string{repo: trunk}, check.TryAsk{Repository: repo, Head: head2}, time.Now()); err != nil || again == lost { - t.Errorf("its head asked again answered %q, %v, want a new try", again, err) - } -} - -// TestTheCheckerSaysOwedReadableOnTheBus: started, the checker says on its own states subject what it keeps, owed among -// the readable ones, which is what grants the forge module its read of owed (ADR 0495 §2-§3, ADR 0521; R4e finding R2-1). -func TestTheCheckerSaysOwedReadableOnTheBus(t *testing.T) { // R2-1 - b := startBed(t) - b.start(t, nil) - events, err := b.js.Stream(b.ctx, "EVENTS") - if err != nil { - t.Fatal(err) - } - var said announce.States - for deadline := time.Now().Add(10 * time.Second); time.Now().Before(deadline); time.Sleep(50 * time.Millisecond) { - m, err := events.GetLastMsgForSubject(b.ctx, announce.Subject("mesh-delivery-checker")) - if err != nil { - continue - } - if err := json.Unmarshal(m.Data, &said); err != nil { - t.Fatal(err) - } - break - } - if said.Module != "mesh-delivery-checker" || said.Node != "n1" || !said.Keeps("owed") || !said.Readable("owed") || - !said.Readable("previews") || !said.Readable("verdicts") || !said.Readable("kept") || !said.Readable("tries") || said.Readable("hearing") || - !said.Keeps("asks") || said.Readable("asks") || !said.Keeps("first-views") || said.Readable("first-views") || !said.Keeps("findings") || !said.Keeps("inputs") || said.Readable("inputs") || !said.Keeps("compositions") || said.Readable("compositions") || !said.Keeps("could-not-run") || said.Readable("could-not-run") || len(said.States) != 12 { - t.Fatalf("the checker said %+v, want its twelve states, asks, hearing, first-views, inputs, compositions and could-not-run its own (DLV-M2; W6.9), with kept, owed, previews, tries and verdicts readable, tries by the delivery view (1929/AC4; 1887 A5b; build_usage)", said) - } - // Design 47 G §717, A-298: the assignments are followed at the holder the seat-holders view of the catalog half's claimant - // names, no seat verb asked for it. - b.said(t, "holds "+testAssigner+"'s assignments, the holder of the seat mesh-module-assigner") -} - -// testChecker is the module the bed's credential names; the checker's own buckets and events are named from it (design 47 G A-296). -const testChecker = "mesh-delivery-checker" - -func testBucket(state string) string { return check.Bucket(testChecker, state) } - -const testAssigner = "acme-assigner" // a holder of the seat mesh-module-assigner no code names - -// buildSeatDefinitions are the seat definitions the bed's seat mesh-catalog lists: the build seats, as the mesh's own definitions of -// them, whose acting rules say which language each builds. -var buildSeatDefinitions = func() map[string]seatdef.Definition { - out := map[string]seatdef.Definition{} - for _, d := range seatlisttest.Definitions() { - if d.Seat == "node-build-go" || d.Seat == "node-build-node" { - out[d.Seat] = d - } - } - return out -}() - -// seatDefinitionsAnswer is the seat mesh-catalog's answer to the seat list's asks: every trunk seat with its digest when no -// seat is named, one seat's definition when it is. -func seatDefinitionsAnswer(body []byte) []byte { - var ask struct { - Seat string `json:"seat"` - } - _ = json.Unmarshal(body, &ask) - entry := func(seat string) seatlist.Entry { - raw, _ := json.Marshal(buildSeatDefinitions[seat]) - return seatlist.Entry{Seat: seat, Source: seatlist.SourceTrunk, Digest: fmt.Sprintf("%x", sha256.Sum256(raw)), Definition: raw} - } - var out any - if ask.Seat == "" { - l := seatlist.Listing{Revision: 1} - for _, seat := range slices.Sorted(maps.Keys(buildSeatDefinitions)) { - e := entry(seat) - e.Definition = nil - l.Seats = append(l.Seats, e) - } - out = l - } else if _, ok := buildSeatDefinitions[ask.Seat]; ok { - e := entry(ask.Seat) - out = seatlist.Answer{Seat: ask.Seat, Found: true, Entry: &e, Revision: 1} - } else { - out = seatlist.Answer{Seat: ask.Seat, Revision: 1} - } - raw, _ := json.Marshal(map[string]any{"result": out, "node": "ctl"}) - return raw -} - -// putBuildModule writes the indexer's module and manifest of a module that claims a build seat, so the checker finds the seat's -// holder (design 47 G A-82). Its repository is its own, so no repository the tests judge changes the build modules it names. -func (b *bed) putBuildModule(t *testing.T, module, seat string) { - t.Helper() - manifest := fmt.Sprintf(`{"module":%q,"version":"0.1","slug":"b","claims":[{"name":%q,"scope":"node"}]}`, module, seat) - digest := fmt.Sprintf("%x", sha256.Sum256([]byte(manifest))) - mkey, err := meshcatalogclient.ManifestsKey(digest) - if err != nil { - t.Fatal(err) - } - stored, err := meshcatalogclient.EncodeManifest(meshcatalog.ManifestsByDigestValue{Manifest: manifest, Module: module}) - if err != nil { - t.Fatal(err) - } - if _, err := b.buckets[check.ManifestsBucket].Put(b.ctx, mkey, stored); err != nil { - t.Fatal(err) - } - value, err := meshcatalogclient.EncodeModule(meshcatalog.ModulesByModuleValue{Repository: "novox/build-modules", Commit: strings.Repeat("b", 40), Path: "modules/" + module, Manifest: digest, - None2: "the fingerprint is computed with its chain"}) - if err != nil { - t.Fatal(err) - } - if _, err := b.buckets[check.ModulesBucket].Put(b.ctx, module, value); err != nil { - t.Fatal(err) - } -} diff --git a/modules/mesh-delivery-checker/cmd/mesh-delivery-checker/judge.go b/modules/mesh-delivery-checker/cmd/mesh-delivery-checker/judge.go deleted file mode 100644 index 3e3ec09f..00000000 --- a/modules/mesh-delivery-checker/cmd/mesh-delivery-checker/judge.go +++ /dev/null @@ -1,604 +0,0 @@ -package main - -import ( - "context" - "encoding/json" - "errors" - "fmt" - "path" - "slices" - "sort" - "strconv" - "strings" - "sync" - "time" - - "github.com/nats-io/nats.go/jetstream" - - "mesh-delivery-checker/internal/check" - - "git.novox.be/novox/mesh-contracts/go/clients/nodeengineclient" - nodeengine "git.novox.be/novox/mesh-contracts/go/seats/nodeengine" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-builder/buildrun" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-builder/builds" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog" - "git.novox.be/novox/mesh-sdk/go/catalogue" - "git.novox.be/novox/mesh-sdk/go/keys" - "git.novox.be/novox/mesh-sdk/go/process" - - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/graph" -) - -// judgeDeps are the parts the judge of a check is made of. -type judgeDeps struct { - // module is the checker's own, the credential's (check.Examiner.Module). - module string - // inputs keeps the checking program's inputs (check.InputsStateName, served on check.InputVerb). - inputs check.Inputs - // beginBound is how long a run ask may wait for a build node to begin it; check.DefaultBeginBound when 0. - beginBound time.Duration - asks check.Asks - renames check.Renames - seatDefs check.SeatDefinitions - // seats are the seat list the checker's reader holds, the base the checking program lays the heads over (seatlist.go). - seats check.SeatList - // buildSeats finds the build modules from the seat list and the holders of seats (design 47 G A-82). - buildSeats *buildrun.BuildSeats - tools *buildrun.ToolchainSet - trunks *check.Trunks - kept check.KV - previews check.KV - // candidates answers the indexer's candidate of a try's group (try_candidates.go); nil leaves a whole try with no - // manifest or composition judged, said. - candidates check.TryCandidates - repos *repoModules - // published is the indexer's packages state as it is followed (packages.go). - published *publishedPackages - forge check.Forge - announce check.Announcer - builds check.BuildStates - // ends waits on the builder's builds of a candidate before the check composes (ADR 0603 §10); nil composes without waiting. - ends check.BuildEnds - // buildWait is the setting build-wait-bound; check.DefaultBuildWait when 0. - buildWait time.Duration - // compositions makes a check's composition from the engines' answers (ADR 0593 §7); nil leaves it not run. - compositions check.CompositionReader - // nodes names every node with a record; nil hands no names. - nodes *nodeNames - // predefined is the indexer's kept list of predefined keys; nil reads none. - predefined check.PredefinedList - logf func(format string, args ...any) -} - -// keptPredefined reads the indexer's key predefined.list (the seat mesh-catalog's state predefined), bound once its state appears. -type keptPredefined struct{ kv jetstream.KeyValue } - -func (k keptPredefined) PredefinedList(ctx context.Context) (json.RawMessage, error) { - e, err := k.kv.Get(ctx, meshcatalog.PredefinedByListKey()) - if errors.Is(err, jetstream.ErrKeyNotFound) { - return nil, nil - } - if err != nil { - return nil, err - } - kept, err := meshcatalog.DecodePredefinedByListValue(e.Value()) - if err != nil { - return nil, err - } - return json.Marshal(kept.List) -} - -// keptSeatDefinitions reads a pull request's entries of the indexer's seat definitions from its first view: each whose -// `unparsed` says why its head's definition does not parse (the entry's shape is the indexer's read tool's answer). -type keptSeatDefinitions struct { - keys func(ctx context.Context) ([]string, error) - get func(ctx context.Context, key string) ([]byte, error) -} - -// seatDefinitionsOf reads the state's picture (a key gone between the keys and its get is none). -func seatDefinitionsOf(kv jetstream.KeyValue) keptSeatDefinitions { - return keptSeatDefinitions{keys: func(ctx context.Context) ([]string, error) { - keys, err := kv.Keys(ctx) - if errors.Is(err, jetstream.ErrNoKeysFound) { - return nil, nil - } - return keys, err - }, get: func(ctx context.Context, key string) ([]byte, error) { - e, err := kv.Get(ctx, key) - if errors.Is(err, jetstream.ErrKeyNotFound) { - return nil, nil - } - if err != nil { - return nil, err - } - return e.Value(), nil - }} -} - -func (k keptSeatDefinitions) Unparsed(ctx context.Context, repository string, pull int) ([]check.UnparsedSeat, error) { - suffix := ".pull." + keys.EscapeName(repository) + "." + strconv.Itoa(pull) - keys, err := k.keys(ctx) - if err != nil { - return nil, err - } - sort.Strings(keys) - var out []check.UnparsedSeat - for _, key := range keys { - if !strings.HasSuffix(key, suffix) { - continue - } - raw, err := k.get(ctx, key) - if err != nil { - return nil, err - } - if raw == nil { - continue - } - var v struct { - Seat string `json:"seat"` - Module string `json:"module"` - Directory string `json:"directory"` - Unparsed string `json:"unparsed"` - } - if err := json.Unmarshal(raw, &v); err != nil { - return nil, fmt.Errorf("%s is no seat definition entry: %w", key, err) - } - if v.Unparsed != "" { - out = append(out, check.UnparsedSeat{Seat: v.Seat, Module: v.Module, Directory: v.Directory, Why: v.Unparsed}) - } - } - return out, nil -} - -// nodeNames reads every node's name from the node-engine's have, one key `.node` per node with a record (novox/hq -// ADR 0567 §12), at each ask: a node enrolled since is named in the next check. -type nodeNames struct{ kv jetstream.KeyValue } - -// openNodeNames opens the node-engine's have for the nodes' names alone: it is not watched, so no check waits on a node. -func openNodeNames(ctx context.Context, js process.BucketOpener, logf func(string, ...any)) *nodeNames { - return &nodeNames{kv: process.OptionalBucket(ctx, js, check.HaveBucket, "no check is asked until it is: the names check needs the nodes' names", logf)} -} - -func (n nodeNames) Names(ctx context.Context) ([]string, error) { - if n.kv == nil { - return nil, fmt.Errorf("the bucket %s could not be opened at the checker's start", check.HaveBucket) - } - lister, err := n.kv.ListKeysFiltered(ctx, "*."+check.HaveNodeWord) - if err != nil { - return nil, err - } - var out []string - for key := range lister.Keys() { - if node, _, isNode, err := nodeengineclient.ParseHaveKey(key); err == nil && isNode { - out = append(out, node) - } - } - sort.Strings(out) - return out, nil -} - -// runningServes says what the running builds serve (novox/hq ADR 0614 §7), read when a check asks it: every module's have -// in the node-engine's have that runs healthy, the builder's build of its fingerprint, and the verbs its manifest serves -// (graph.Served). A build whose manifest cannot be read serves nothing here, said in the log. -type runningServes struct { - have *nodeNames - builds check.BuildStates - read check.ManifestReader - logf func(format string, args ...any) -} - -func (r runningServes) Served(ctx context.Context) (func(string) bool, error) { - if r.have == nil || r.have.kv == nil || r.builds == nil || r.read == nil { - return nil, fmt.Errorf("the node-engine's have, the builder's builds or the indexer's manifests cannot be read") - } - lister, err := r.have.kv.ListKeys(ctx) - if err != nil { - return nil, err - } - haves := map[string]map[string]nodeengine.HaveByNodeModuleValue{} - for key := range lister.Keys() { - node, module, isNode, err := nodeengineclient.ParseHaveKey(key) - if err != nil || isNode { - continue - } - e, err := r.have.kv.Get(ctx, key) - if err != nil { - continue - } - if h, err := nodeengineclient.DecodeHave(e.Value()); err == nil { - if haves[node] == nil { - haves[node] = map[string]nodeengine.HaveByNodeModuleValue{} - } - haves[node][module] = h - } - } - served, unread := graph.Served(haves, func(module, fp string) ([]string, bool) { - b, found, err := r.builds.Build(ctx, module, fp) - if err != nil || !found || b.Manifest == "" { - return nil, false - } - m, err := r.read.Manifest(ctx, b.Manifest) - if err != nil { - return nil, false - } - return graph.ServesOf(m), true - }, nil) - if len(unread) > 0 && r.logf != nil { - r.logf("the manifest of the running build of %v cannot be read, so it serves nothing the check counts (ADR 0614 §7)", unread) - } - return served, nil -} - -func newJudge(d judgeDeps) check.Judge { - var nodes interface { - Names(ctx context.Context) ([]string, error) - } - if d.nodes != nil { - nodes = d.nodes - } - ex := &check.Examiner{Module: d.module, Nodes: nodes, Compositions: d.compositions, Asks: d.asks, Toolchains: d.tools, - Kept: check.Kept{Store: d.kept}, Previews: d.previews, Candidates: d.candidates, Modules: d.repos, Packages: d.repos, Published: d.published, KnownPackages: d.published, Forge: d.forge, Runs: d.repos, Builds: d.builds, BuildEnds: d.ends, BuildWait: d.buildWait, Announce: d.announce, Trunks: d.trunks, Manifests: d.repos, Read: d.repos, Dirs: d.repos, Predefined: d.predefined, Renames: d.renames, SeatDefinitions: d.seatDefs, SeatList: d.seats, Seats: d.buildSeats, Inputs: d.inputs, BeginBound: d.beginBound, Logf: d.logf} - if d.nodes != nil && d.builds != nil && d.repos != nil { - ex.Serving = runningServes{have: d.nodes, builds: d.builds, read: d.repos, logf: d.logf} - } - return ex -} - -// manifestKV reads a manifest by its digest. -type manifestKV interface { - Get(ctx context.Context, key string) (value []byte, revision uint64, found bool, err error) -} - -// repoModules knows which build modules judge a repository, from the indexer's modules and their manifests: the Go build -// module always (a repository's go.mod files are its own), the Node one when a module of the repository has a TypeScript -// artifact (ADR 0484 clause 10). Safe for use from the watch and from a check at once. -type repoModules struct { - manifests manifestKV - logf func(format string, args ...any) - // verdicts keeps the indexer's verdict on each module's manifest, for the sandbox's composer (engines.go); nil keeps none. - verdicts *manifestVerdicts - // seats finds the build modules (design 47 G A-82); set before the first check. - seats *buildrun.BuildSeats - - mu sync.Mutex - claims map[string][]string // by manifest digest: the seats its module claims - langs map[string]map[string]bool // by manifest digest: the languages of its artifacts - tsPkgs map[string][]string // by manifest digest: the names of its TypeScript package artifacts - path map[string]string // by module: its directory in its repository - named map[string]map[string][]string // by module: each artifact's named paths, as the indexer keeps them - repoOf map[string]string // by module: its repository - fp map[string]string // by module: its entry's fingerprint, whose graph entry holds the manifest - commit map[string]string // by module: the commit its record was computed at (the commit the mesh runs) - typed map[string]string // by module: its manifest digest - parsed map[string]catalogue.Manifest // by manifest digest: the manifest as read, once (a digest's manifest never changes) -} - -// Manifest is the kept manifest of a digest, read from the indexer's manifests state once and then from memory. -func (r *repoModules) Manifest(ctx context.Context, digest string) (catalogue.Manifest, error) { - r.mu.Lock() - m, known := r.parsed[digest] - r.mu.Unlock() - if known { - return m, nil - } - key, err := meshcatalogclient.ManifestsKey(digest) - if err != nil { - return catalogue.Manifest{}, err - } - raw, _, found, err := r.manifests.Get(ctx, key) - if err != nil { - return catalogue.Manifest{}, err - } - if !found { - return catalogue.Manifest{}, fmt.Errorf("the indexer keeps no manifest %s", digest) - } - kept, err := meshcatalogclient.DecodeManifest(raw) - if err != nil { - return catalogue.Manifest{}, err - } - if m, err = parseManifest(kept.Manifest); err != nil { - return catalogue.Manifest{}, err - } - r.mu.Lock() - if r.parsed == nil { - r.parsed = map[string]catalogue.Manifest{} - } - r.parsed[digest] = m - r.mu.Unlock() - return m, nil -} - -// Put takes a change of the indexer's modules bucket in: a module's repository and the languages its manifest names. -func (r *repoModules) Put(ctx context.Context, key string, value []byte, deleted bool) { - r.mu.Lock() - if r.repoOf == nil { - r.repoOf, r.typed, r.langs, r.commit = map[string]string{}, map[string]string{}, map[string]map[string]bool{}, map[string]string{} - r.fp = map[string]string{} - r.tsPkgs, r.path, r.named = map[string][]string{}, map[string]string{}, map[string]map[string][]string{} - } - if deleted { - if r.verdicts != nil { - r.verdicts.put(key, nil) - } - delete(r.repoOf, key) - delete(r.typed, key) - delete(r.fp, key) - delete(r.commit, key) - delete(r.path, key) - delete(r.named, key) - r.mu.Unlock() - return - } - r.mu.Unlock() - m, err := meshcatalogclient.DecodeModule(value) - if err != nil { - return - } - if r.verdicts != nil { - r.verdicts.put(key, meshcatalogclient.ModuleVerdict(key, m)) - } - r.mu.Lock() - r.repoOf[key] = m.Repository - r.typed[key] = m.Manifest - r.fp[key] = m.Fp2 - r.commit[key] = m.Commit - r.path[key] = m.Path - r.named[key] = m.Paths - _, known := r.langs[m.Manifest] - r.mu.Unlock() - if m.Manifest == "" || known { - return - } - set := map[string]bool{} - var pkgs, claimed []string - if mk, err := meshcatalogclient.ManifestsKey(m.Manifest); err == nil { - if raw, _, found, err := r.manifests.Get(ctx, mk); err == nil && found { - if kept, err := meshcatalogclient.DecodeManifest(raw); err == nil { - if man, err := parseManifest(kept.Manifest); err == nil { - for _, c := range man.Claims { - claimed = append(claimed, c.Name) - } - } - if man, err := parseManifest(kept.Manifest); err == nil && man.Build != nil { - for _, a := range man.Build.Artifacts { - if a.Language != "" { - set[a.Language] = true - } - if a.Kind == "package" && a.Language == "typescript" { - pkgs = append(pkgs, a.Name) - } - } - } else if err != nil && r.logf != nil { - r.logf("the manifest %s cannot be read, so its module counts as no TypeScript: %v", m.Manifest, err) - } - } - } - } - r.mu.Lock() - r.langs[m.Manifest] = set - r.tsPkgs[m.Manifest] = pkgs - if r.claims == nil { - r.claims = map[string][]string{} - } - r.claims[m.Manifest] = claimed - r.mu.Unlock() -} - -// ModuleDir is a module's directory in its repository as the indexer's modules hold it (check.Examiner.Dirs); false for a -// module the indexer holds no directory of. -func (r *repoModules) ModuleDir(module string) (string, bool) { - r.mu.Lock() - defer r.mu.Unlock() - d, ok := r.path[module] - return d, ok && d != "" -} - -// TypeScriptPackages are the TypeScript package artifacts of a repository's modules, sorted by directory: each by its -// directory in the repository and the paths, relative to the repository, it is built from: the named paths the indexer -// keeps in each module's value (meshcatalog.ModulesByModuleValue.ArtifactPaths; only the indexer reads them from a -// manifest, the lead's decision L8), under the module's directory. A package's directory is the one path it names when -// that names a directory (the contracts folders, ts/seats/, each with its own package.json), else the module's -// directory (the SDK's lib names its package.json beside its sources), as the Node build module reads it -// (mesh-build-node artifact.packageDir). None for a module whose value holds no paths. -func (r *repoModules) TypeScriptPackages(repository string) []check.TypeScriptPackage { - r.mu.Lock() - defer r.mu.Unlock() - var out []check.TypeScriptPackage - for module, repo := range r.repoOf { - if repo != repository { - continue - } - dir := strings.Trim(r.path[module], "/") - if dir == meshcatalogclient.RootPath || dir == "." { - dir = "" - } - under := func(p string) string { - p = strings.Trim(strings.TrimPrefix(p, "./"), "/") - if dir != "" { - p = dir + "/" + p - } - return p - } - for _, name := range r.tsPkgs[r.typed[module]] { - named := r.named[module][name] - if len(named) == 0 { - continue - } - pkg := check.TypeScriptPackage{Dir: dir} - if one := strings.Trim(strings.TrimPrefix(named[0], "./"), "/"); len(named) == 1 && one != "" && !strings.Contains(path.Base(one), ".") { - pkg.Dir = under(one) - } - for _, p := range named { - pkg.Paths = append(pkg.Paths, under(p)) - } - sort.Strings(pkg.Paths) - out = append(out, pkg) - } - } - sort.Slice(out, func(i, j int) bool { return out[i].Dir < out[j].Dir }) - return out -} - -// HolderOf is the module whose manifest claims the seat, as the indexer's modules hold them: none while no module of the mesh -// claims it, and the first by name where several do (design 47 G A-82, as the catalog half's holder is read by the builder). -func (r *repoModules) HolderOf(seat string) (string, bool) { - r.mu.Lock() - defer r.mu.Unlock() - found := "" - for module, digest := range r.typed { - if slices.Contains(r.claims[digest], seat) && (found == "" || module < found) { - found = module - } - } - return found, found != "" -} - -// BuildModules are the build modules that judge a repository, sorted: the build module of Go always, and that of TypeScript -// when a module of the repository builds TypeScript. A repository of which the mesh knows no module (mesh-lab, hq) -// is judged by both, each finding its own directories in the tree (go.mod files; package.json files), so a repository -// with tests in either language and no manifest is judged whole (issue 1887 A12). A language no build seat on the seat list -// builds has none. -func (r *repoModules) BuildModules(repository string) []string { - var out []string - add := func(language string) { - if m, err := r.seats.For(language, ""); err == nil { - out = append(out, m.Module) - } - } - add("go") - r.mu.Lock() - typescript := false - known := false - for module, repo := range r.repoOf { - if repo != repository { - continue - } - known = true - if r.langs[r.typed[module]]["typescript"] { - typescript = true - break - } - } - r.mu.Unlock() - if typescript || !known { - add("typescript") - } - sort.Strings(out) - return out -} - -// buildReader reads the builder's build of a module at a fingerprint (mesh-delivery-builder_builds). -type buildReader struct{ kv kvStore } - -func (r buildReader) Build(ctx context.Context, module, fp2 string) (builds.BuilderBuild, bool, error) { - key, err := builds.BuilderBuildKey(module, fp2) - if err != nil { - return builds.BuilderBuild{}, false, err - } - value, _, found, err := r.kv.Get(ctx, key) - if err != nil || !found { - return builds.BuilderBuild{}, false, err - } - b, err := builds.DecodeBuilderBuild(value) - return b, err == nil, err -} - -// buildEnds hears the builder's build keys of a candidate on the bus (mesh-delivery-builder_builds): a watch of exactly -// those keys gives each one's value now and every write the builder makes after, so the check waits on the part that owns -// the fact and polls nothing (novox/hq ADR 0603 §10). -type buildEnds struct{ kv jetstream.KeyValue } - -func (e buildEnds) Ended(ctx context.Context, asked map[string]string) (map[string]builds.BuilderBuild, error) { - return e.until(ctx, asked, func(b builds.BuilderBuild) bool { - return b.State == builds.BuildDone || b.State == builds.BuildFailed - }) -} - -func (e buildEnds) Done(ctx context.Context, asked map[string]string) bool { - done, err := e.until(ctx, asked, func(b builds.BuilderBuild) bool { return b.State == builds.BuildDone }) - return err == nil && len(done) == len(asked) -} - -// until hears the builds' keys until each holds a build that ended holds, or ctx ends, and answers those that do, by module. -func (e buildEnds) until(ctx context.Context, asked map[string]string, ended func(builds.BuilderBuild) bool) (map[string]builds.BuilderBuild, error) { - byKey := map[string]string{} - keys := make([]string, 0, len(asked)) - for module, fp2 := range asked { - key, err := builds.BuilderBuildKey(module, fp2) - if err != nil { - return nil, err - } - byKey[key] = module - keys = append(keys, key) - } - out := map[string]builds.BuilderBuild{} - if len(keys) == 0 { - return out, nil - } - w, err := e.kv.WatchFiltered(ctx, keys) - if err != nil { - return nil, err - } - defer func() { _ = w.Stop() }() - for len(out) < len(keys) { - select { - case <-ctx.Done(): - return out, nil // the bound: the builds not ended are left out - case entry, open := <-w.Updates(): - if !open { - return out, nil - } - if entry == nil || entry.Operation() != jetstream.KeyValuePut { - continue // the end of the values now, or a key deleted: it has not ended - } - module, ours := byKey[entry.Key()] - if !ours { - continue - } - b, err := builds.DecodeBuilderBuild(entry.Value()) - if err == nil && ended(b) { - out[module] = b - } else { - delete(out, module) // asked again (builder_build_again), or not a build the check can read: not ended - } - } - } - return out, nil -} - -// ManifestDigests is the manifest digest of every module the indexer holds, by module: the catalogue the indexer's judge -// judges a change's manifests in (novox/hq ADR 0578 §2).8 §2). -func (r *repoModules) ManifestDigests() map[string]string { - r.mu.Lock() - defer r.mu.Unlock() - out := map[string]string{} - for module, digest := range r.typed { - if digest != "" { - out[module] = digest - } - } - return out -} - -// ManifestFingerprints is the fingerprint of every module the indexer holds, by module, whose catalog graph entry holds its manifest -// (design 47 G A-310). -func (r *repoModules) ManifestFingerprints() map[string]string { - r.mu.Lock() - defer r.mu.Unlock() - out := map[string]string{} - for module, fp := range r.fp { - if fp != "" { - out[module] = fp - } - } - return out -} - -// CommitOf is the commit the indexer's record of the module names: the commit its fingerprint first appeared at, so the source -// of the build the mesh runs (a later merge that leaves the module alone writes no record, the operator 2026-10-25). -func (r *repoModules) CommitOf(module string) string { - r.mu.Lock() - defer r.mu.Unlock() - return r.commit[module] -} diff --git a/modules/mesh-delivery-checker/cmd/mesh-delivery-checker/judge_test.go b/modules/mesh-delivery-checker/cmd/mesh-delivery-checker/judge_test.go deleted file mode 100644 index b77fec22..00000000 --- a/modules/mesh-delivery-checker/cmd/mesh-delivery-checker/judge_test.go +++ /dev/null @@ -1,258 +0,0 @@ -package main - -import ( - "context" - "encoding/json" - "fmt" - "maps" - "os" - "reflect" - "slices" - "strings" - "testing" - "time" - - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep" - "git.novox.be/novox/mesh-sdk/go/keys" - - "mesh-delivery-checker/internal/check" -) - -type memManifests map[string][]byte - -func (m memManifests) Get(_ context.Context, key string) ([]byte, uint64, bool, error) { - v, ok := m[key] - return v, 1, ok, nil -} - -func putModule(t *testing.T, r *repoModules, name, repository, manifest string) { - t.Helper() - data, err := meshcatalogclient.EncodeModule(meshcatalog.ModulesByModuleValue{Repository: repository, Commit: strings.Repeat("a", 40), Fp: "src1:" + strings.Repeat("a", 64), Manifest: meshcatalogclient.ManifestDigest([]byte(manifest))}) - if err != nil { - t.Fatal(err) - } - r.Put(context.Background(), name, data, false) -} - -func TestARepositoryWithATypeScriptModuleIsJudgedByTheNodeBuildModuleToo(t *testing.T) { // 1292/AC2 - own, err := os.ReadFile("../../module.json") // a manifest with a Go bundle: this module's own - if err != nil { - t.Fatal(err) - } - goManifest := string(own) - // A TypeScript bundle names neither a system nor a directory it is built from (the catalogue's parser says so). - var doc map[string]any - if err := json.Unmarshal(own, &doc); err != nil { - t.Fatal(err) - } - artifacts := doc["build"].(map[string]any)["artifacts"].([]any) - program := artifacts[0].(map[string]any) - program["language"] = "typescript" - delete(program, "system") - delete(program, "from") - delete(program, "binary") - tsRaw, err := json.Marshal(doc) - if err != nil { - t.Fatal(err) - } - tsManifest := string(tsRaw) - store := memManifests{} - for _, m := range []string{goManifest, tsManifest} { - data, err := meshcatalogclient.EncodeManifest(meshcatalog.ManifestsByDigestValue{Module: "demo", Manifest: m}) - if err != nil { - t.Fatal(err) - } - store[meshcatalogclient.ManifestDigest([]byte(m))] = data - } - r := &repoModules{manifests: store, seats: testBuildSeats()} - putModule(t, r, "mesh-delivery-checker", "novox/mesh-delivery", goManifest) - putModule(t, r, "mesh-ui", "novox/mesh-catalog", tsManifest) - if got := r.BuildModules("novox/mesh-delivery"); strings.Join(got, ",") != goBuildModule { - t.Errorf("mesh-delivery: %v, want the Go build module alone", got) - } - if got := r.BuildModules("novox/mesh-catalog"); strings.Join(got, ",") != goBuildModule+","+nodeBuildModule { - t.Errorf("mesh-catalog: %v, want both", got) - } - if got := r.CommitOf("mesh-delivery-checker"); got != strings.Repeat("a", 40) || r.CommitOf("gone") != "" { - t.Errorf("the commit the mesh runs = %q", got) - } - // 1887/A12: a repository with no module the mesh knows (mesh-lab: nested go.mod files and a root package.json) is - // judged by both build modules. - if got := r.BuildModules("novox/mesh-lab"); strings.Join(got, ",") != goBuildModule+","+nodeBuildModule { - t.Errorf("a repository with no module: %v, want both build modules", got) - } -} - -// sdkManifest is mesh-sdk's own manifest (its module.json at feat/r4e-sdk): one TypeScript package naming its paths. -const sdkManifest = `{"module":"mesh-sdk","version":"1","slug":"sdk","build":{"artifacts":[{"name":"lib","kind":"package","language":"typescript",` + - `"paths":["src","test","package.json","package-lock.json","tsconfig.json"]}]},"resources":[]}` - -func TestTheTypeScriptPackagesPathsComeFromTheIndexersModulesNotTheManifest(t *testing.T) { // ADR 0500 §5 with lead decision L8 - store := memManifests{} - data, err := meshcatalogclient.EncodeManifest(meshcatalog.ManifestsByDigestValue{Module: "mesh-sdk", Manifest: sdkManifest}) - if err != nil { - t.Fatal(err) - } - store[meshcatalogclient.ManifestDigest([]byte(sdkManifest))] = data - r := &repoModules{manifests: store} - put := func(path string, paths map[string][]string) { - v, err := meshcatalogclient.EncodeModule(meshcatalog.ModulesByModuleValue{Repository: "novox/mesh-sdk", Commit: strings.Repeat("a", 40), Fp: "src1:" + strings.Repeat("a", 64), - Manifest: meshcatalogclient.ManifestDigest([]byte(sdkManifest)), Path: path, Paths: paths}) - if err != nil { - t.Fatal(err) - } - r.Put(context.Background(), "mesh-sdk", v, false) - } - str := func(pkgs []check.TypeScriptPackage) string { - var out []string - for _, p := range pkgs { - out = append(out, p.Dir+":"+strings.Join(p.Paths, ",")) - } - return strings.Join(out, " ") - } - for _, row := range []struct { - name, path string - paths map[string][]string - want string - }{ - {"the indexer's word, not the manifest's five paths: the SDK's lib at the root", ".", map[string][]string{"lib": {"src", "package.json"}}, ":package.json,src"}, - {"under the module's directory", "ts", map[string][]string{"lib": {"package.json", "src"}}, "ts:ts/package.json,ts/src"}, - {"one path naming a directory is the package's own (A-285)", "modules/mesh-delivery-contracts", map[string][]string{"lib": {"ts/seats/git"}}, "modules/mesh-delivery-contracts/ts/seats/git:modules/mesh-delivery-contracts/ts/seats/git"}, - {"a value written before the indexer kept paths: nothing to serve by", ".", nil, ""}, - } { - put(row.path, row.paths) - if got := str(r.TypeScriptPackages("novox/mesh-sdk")); got != row.want { - t.Errorf("%s: packages = %q, want %q", row.name, got, row.want) - } - } - if got := r.TypeScriptPackages("novox/mesh-delivery"); len(got) != 0 { - t.Errorf("another repository: %v", got) - } -} - -// ADR 0593 §2 (D8): a Go check builds every mesh package at the version the indexer's packages state publishes, read -// there and computed nowhere here: a key's module at its commit, a deleted key gone, an unreadable value left out. -func TestThePublishedVersionsAreTheIndexersPackagesState(t *testing.T) { - var p publishedPackages - // Not read yet, the state names no package and judges none; read and empty, it is an empty list judged against. - if got := p.PackageNames(); got != nil { - t.Errorf("before the first reading the known packages = %v, want nil", got) - } - p.Answered() - if got := p.PackageNames(); got == nil || len(got) != 0 { - t.Errorf("read and empty, the known packages = %#v, want an empty map", got) - } - put := func(module, repository, dir, commit string) { - key := meshcatalog.PackagesByModuleKey(keys.EscapeName(module)) - now := time.Now().UTC() - raw, err := json.Marshal(meshcatalog.PackagesByModuleValue{V: keys.Version, Module: module, Repository: repository, Dir: dir, - Commit: commit, Requires: strings.Repeat("e", 64), - Packages: []meshcatalog.PackagesByModuleValuePackagesItem{{Package: module, Digest: strings.Repeat("d", 64)}}, At: &now}) - if err != nil { - t.Fatal(err) - } - p.Put(key, raw, false) - } - const sdk, build = "git.novox.be/novox/mesh-sdk/go", "git.novox.be/novox/mesh-catalog/modules/mesh-build-go" - put(sdk, "novox/mesh-sdk", "go", strings.Repeat("a", 40)) - put(build, "novox/mesh-catalog", "modules/mesh-build-go", strings.Repeat("b", 40)) - p.Put("broken", []byte("{"), false) - if got := p.LatestPackages(); !reflect.DeepEqual(got, buildstep.PackageVersions{sdk: strings.Repeat("a", 40), build: strings.Repeat("b", 40)}) { - t.Errorf("latest packages = %v", got) - } - key := meshcatalog.PackagesByModuleKey(keys.EscapeName(build)) - p.Put(key, nil, true) - if got := p.LatestPackages(); len(got) != 1 || got[sdk] == "" { - t.Errorf("after a delete: %v", got) - } - // Issue 1966: a module record names its module, with no series to say it, and none of the packages inside it. - if got := p.PackageNames(); !reflect.DeepEqual(got, map[string]string{sdk: ""}) { - t.Errorf("the known packages from a module record = %v", got) - } - // A series key names its package by its ecosystem name, the judge's known packages (DLV-I14, design 32), and is no - // module's published version. - now := time.Now().UTC() - series, err := json.Marshal(meshcatalog.PackagesByPackageSeriesValue{V: keys.Version, Name: sdk, Package: "mesh-sdk/go", Series: "0.1", At: &now}) - if err != nil { - t.Fatal(err) - } - p.Put(meshcatalog.PackagesByPackageSeriesKey(keys.EscapeName(sdk), "0.1"), series, false) - if got := p.PackageNames(); !reflect.DeepEqual(got, map[string]string{sdk: "mesh-sdk/go"}) || len(p.LatestPackages()) != 1 { - t.Errorf("the known packages = %v, the latest %v", got, p.LatestPackages()) - } - t.Run("a pull request's unparsed seat definitions are its entries of the indexer's seat-definitions", func(t *testing.T) { - state := map[string]string{ - "web-api.trunk": `{"seat":"web-api","source":"trunk","digest":"d"}`, - "web-api.pull." + keys.EscapeName("novox/web") + ".7": `{"seat":"web-api","source":"pull","module":"web-contracts","directory":"go","unparsed":"seat.json: bad"}`, - "mail-api.pull." + keys.EscapeName("novox/web") + ".7": `{"seat":"mail-api","source":"pull","digest":"e"}`, - "web-api.pull." + keys.EscapeName("novox/web") + ".17": `{"seat":"web-api","source":"pull","unparsed":"another pull request's"}`, - } - k := keptSeatDefinitions{keys: func(context.Context) ([]string, error) { return slices.Collect(maps.Keys(state)), nil }, - get: func(_ context.Context, key string) ([]byte, error) { return []byte(state[key]), nil }} - got, err := k.Unparsed(context.Background(), "novox/web", 7) - if want := []check.UnparsedSeat{{Seat: "web-api", Module: "web-contracts", Directory: "go", Why: "seat.json: bad"}}; err != nil || !reflect.DeepEqual(got, want) { - t.Errorf("unparsed of novox/web#7 = %+v, %v; want %+v", got, err, want) - } - }) -} - -// A manifest whose config value falls back to a predefined key (ADR 0348 §7) is read, not logged as unreadable for the -// catalogue's predefined.json this process never holds: the indexer and the assigner read it with -// catalogue.ParseManifestForInputs (issues 1751, 1906). xterm's module.json from mesh-catalog at 835bf22b. -func TestAManifestFallingBackToAPredefinedKeyIsRead(t *testing.T) { - raw, err := os.ReadFile("testdata/catalogue-835bf22b-xterm.module.json") - if err != nil { - t.Fatal(err) - } - manifest := string(raw) - data, err := meshcatalogclient.EncodeManifest(meshcatalog.ManifestsByDigestValue{Module: "xterm", Manifest: manifest}) - if err != nil { - t.Fatal(err) - } - store := memManifests{meshcatalogclient.ManifestDigest([]byte(manifest)): data} - var said []string - r := &repoModules{manifests: store, logf: func(f string, a ...any) { said = append(said, fmt.Sprintf(f, a...)) }} - putModule(t, r, "xterm", "novox/mesh-catalog", manifest) - r.BuildModules("novox/mesh-catalog") - for _, s := range said { - if strings.Contains(s, "cannot be read") { - t.Errorf("the manifest was not read: %s", s) - } - } - if _, err := parseManifest(manifest); err != nil { - t.Errorf("manifestReader: %v", err) - } - // The sandbox's composer may be an older node-engine, which knows no verdict waits: it is handed a wait as a refusal. - var held manifestVerdicts - held.put("nats", &meshcatalog.VerdictsByDigestValue{Module: "nats", State: meshcatalogclient.VerdictManifestWaits, Unknown: []string{"core-credentials"}, Judge: "j"}) - if v := held.all()["nats"]; v.State != meshcatalogclient.VerdictRefused || len(v.Problems) != 1 || len(v.Unknown) != 0 { - t.Errorf("a waiting verdict is handed to the sandbox as %+v", v) - } -} - -// The build modules are no names (design 47 G A-82): the holder of a seat is the module whose manifest, as the indexer's modules -// hold it, claims the seat. -func TestTheHolderOfASeatIsTheModuleWhoseManifestClaimsIt(t *testing.T) { - manifest := `{"module":"go-builds","version":"1","slug":"g","claims":[{"name":"node-build-go","scope":"node"}]}` - data, err := meshcatalogclient.EncodeManifest(meshcatalog.ManifestsByDigestValue{Module: "go-builds", Manifest: manifest}) - if err != nil { - t.Fatal(err) - } - r := &repoModules{manifests: memManifests{meshcatalogclient.ManifestDigest([]byte(manifest)): data}} - putModule(t, r, "go-builds", "novox/builds", manifest) - if got, ok := r.HolderOf("node-build-go"); !ok || got != "go-builds" { - t.Errorf("the holder of node-build-go = %q, %v, want go-builds", got, ok) - } - if got, ok := r.HolderOf("node-build-node"); ok { - t.Errorf("the holder of a seat no manifest claims = %q, want none", got) - } - var found []string - var changed buildsWatch - changed.Set(func() { found = append(found, "changed") }) - changed.Changed() - if len(found) != 1 { - t.Errorf("the build modules' change was not called through its watch: %v", found) - } -} diff --git a/modules/mesh-delivery-checker/cmd/mesh-delivery-checker/judgeseats.go b/modules/mesh-delivery-checker/cmd/mesh-delivery-checker/judgeseats.go deleted file mode 100644 index 2bc14572..00000000 --- a/modules/mesh-delivery-checker/cmd/mesh-delivery-checker/judgeseats.go +++ /dev/null @@ -1,60 +0,0 @@ -package main - -import ( - "encoding/json" - "fmt" - "maps" - "slices" - "sync/atomic" - - "git.novox.be/novox/mesh-sdk/go/seatdef" - "git.novox.be/novox/mesh-sdk/go/seatlist" -) - -// The checker reads the seat list through mesh-sdk's seatlist.Part, the one wiring (design 47 G §204): what the reader holds is the -// indexer's judge's Seats of a request, which the manifests of a change are judged against. - -// seatList is the reader as the check's SeatList: the held definitions raw, and an error while the seat has not answered. -type seatList struct{ reader *seatlist.Reader } - -func (s seatList) Definitions() ([]json.RawMessage, error) { - if s.reader == nil { - return nil, fmt.Errorf("the checker follows no seat list") - } - if st := s.reader.Status(); !st.Heard { - return nil, fmt.Errorf("%s", st.Health()) - } - defs := s.reader.Definitions() - var out []json.RawMessage - for _, seat := range slices.Sorted(maps.Keys(defs)) { - raw, err := json.Marshal(defs[seat]) - if err != nil { - return nil, fmt.Errorf("the definition of %s cannot be encoded: %w", seat, err) - } - out = append(out, raw) - } - return out, nil -} - -// buildsWatch is what is done when the build modules may have changed (design 47 G A-82): the seat list names the build seats -// and the indexer's modules the holders of the seats, so a change of either may name a build module not watched yet. It is set once -// the parts that watch the build modules are made, and called from then on. -type buildsWatch struct{ fn atomic.Pointer[func()] } - -// Set takes the function in. -func (b *buildsWatch) Set(f func()) { b.fn.Store(&f) } - -// Changed calls it, none before it is set. -func (b *buildsWatch) Changed() { - if f := b.fn.Load(); f != nil { - (*f)() - } -} - -// definitionsOf are the seat definitions the reader holds, none before it has answered. -func definitionsOf(reader *seatlist.Reader) map[string]seatdef.Definition { - if reader == nil { - return nil - } - return reader.Definitions() -} diff --git a/modules/mesh-delivery-checker/cmd/mesh-delivery-checker/kept_test.go b/modules/mesh-delivery-checker/cmd/mesh-delivery-checker/kept_test.go deleted file mode 100644 index c36810ad..00000000 --- a/modules/mesh-delivery-checker/cmd/mesh-delivery-checker/kept_test.go +++ /dev/null @@ -1,57 +0,0 @@ -package main - -import ( - "encoding/json" - "os" - "sort" - "testing" -) - -// The checker says on the bus which states it keeps and which others may read (novox/hq ADR 0495 clauses 2 and 3): a -// reader is granted from that announcement. owed is read by the forge module, which writes mesh/check from it (ADR 0521, -// R4e round 2 finding R2-1), and by the forge bridge; previews by the indexer; verdicts by the gate. The list names every -// state of the manifest, so no state is refused at the call for want of being announced (clause 5). -func TestTheCheckerAnnouncesEveryStateItKeepsAndOwedReadable(t *testing.T) { // R2-1, ADR 0495 §2-§3, ADR 0521 - raw, err := os.ReadFile("../../module.json") - if err != nil { - t.Fatal(err) - } - var m struct { - State []struct{ Name string } `json:"state"` - } - if err := json.Unmarshal(raw, &m); err != nil { - t.Fatal(err) - } - var manifest, announced, readable []string - for _, s := range m.State { - manifest = append(manifest, s.Name) - } - for _, s := range keptStates { - announced = append(announced, s.Name) - if s.Readable { - readable = append(readable, s.Name) - } - } - sort.Strings(manifest) - sort.Strings(announced) - if !equal(manifest, announced) { - t.Errorf("announced %v, the manifest keeps %v", announced, manifest) - } - // kept is read by the Go build module for a check ask (issue 1887 design limit 1); tries by the delivery view (build_usage). - // inputs are the checker's own: the Go build module asks the seat's verb input for one (ADR 0596 §2, issue 1921). - if want := []string{"kept", "owed", "previews", "tries", "verdicts"}; !equal(readable, want) { - t.Errorf("readable %v, want %v", readable, want) - } -} - -func equal(a, b []string) bool { - if len(a) != len(b) { - return false - } - for i := range a { - if a[i] != b[i] { - return false - } - } - return true -} diff --git a/modules/mesh-delivery-checker/cmd/mesh-delivery-checker/main.go b/modules/mesh-delivery-checker/cmd/mesh-delivery-checker/main.go deleted file mode 100644 index 97c0f9ab..00000000 --- a/modules/mesh-delivery-checker/cmd/mesh-delivery-checker/main.go +++ /dev/null @@ -1,538 +0,0 @@ -// Command mesh-delivery-checker is delivery's checker (novox/hq ADR 0453 clause 4, ADR 0447, ADR 0484, issues 1678 to 1686): for -// each candidate the indexer writes it judges every pull request's head merged onto its trunk, through the build modules' -// fetch, digest and test steps, keeps the passing packages' verdicts, writes the verdict, and owes the forge the status -// `mesh/check`, which the forge bridge sets. It runs dark: nothing reads its answers to merge or deliver (ADR 0453 clause 4). -// It serves no request subject and holds no timer: every reaction is a watch or a bus event (ADR 0437 §8). -package main - -import ( - "context" - "encoding/json" - "errors" - "fmt" - checker "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshdeliverychecker" - "io" - "log" - "os" - "os/signal" - "strings" - "sync/atomic" - "syscall" - "time" - - "github.com/nats-io/nats.go" - "github.com/nats-io/nats.go/jetstream" - - "git.novox.be/novox/mesh-contracts/go/seats/nodeengine" - - "mesh-delivery-checker/internal/check" - - "git.novox.be/novox/mesh-contracts/go/seats/meshmoduleassigner" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-builder/buildrun" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-builder/builds" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-checker/checkermsg" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep" - "git.novox.be/novox/mesh-sdk/go/announce" - "git.novox.be/novox/mesh-sdk/go/process" - "git.novox.be/novox/mesh-sdk/go/seatdef" - "git.novox.be/novox/mesh-sdk/go/seatlist" - "git.novox.be/novox/mesh-sdk/go/views" -) - -// eventSubject is the subject of an event of the checker's stream checks (the bus names the stream CHECKS): the indexer's -// watch of the previews bucket and the forge bridge's watch of the owed bucket are woken by them. -func eventSubject(module, event string) string { - return process.ModuleStreamSubject(module, event) -} - -const ( - // defaultLink is the base of the address a status points at; the verdict key follows. - defaultLink = "mesh-delivery-view/checks" -) - -func main() { - ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM) - defer stop() - if err := run(ctx, os.Getenv, os.Stderr); err != nil { - fmt.Fprintln(os.Stderr, "mesh-delivery-checker:", err) - os.Exit(1) - } -} - -// durationEnv reads a duration setting from the environment, def when it is not set. -func durationEnv(getenv func(string) string, name string, def time.Duration) (time.Duration, error) { - v := strings.TrimSpace(getenv(name)) - if v == "" { - return def, nil - } - d, err := time.ParseDuration(v) - if err != nil || d <= 0 { - return 0, fmt.Errorf("%s: %q is not a duration of more than 0", name, v) - } - return d, nil -} - -// The checker's own states of its first views (views.StatusState) and of its findings, where the condition keeper raises a -// first view unanswered past its bound (ADR 0615 §6); and the indexer's states it follows (check.CandidatesBucket, -// ModulesBucket, ManifestsBucket). -func firstViewsBucket(module string) string { return check.Bucket(module, views.StatusState) } - -const ( - candidatesState = "candidates" - // seatDefinitionsState is the indexer's state of the seat definitions (design 26), keyed `.trunk` and - // `.pull..`. - seatDefinitionsState = "seat-definitions" - // The owners' views families, as their manifests' `streams` name them. - indexerViews = "indexer-views" - modulesState = "modules" - manifestsState = "manifests" -) - -// run is the program: it returns when ctx ends or the bus cannot be used. -// keptStates is every state the checker keeps and which others may read (ADR 0495 §2-§3): owed by the forge module, -// which writes mesh/check from it (ADR 0521), and by the forge bridge; previews by the indexer; verdicts by the gate; tries by the delivery view. -var keptStates = []announce.State{ - // The kept verdicts are read by the Go build module, which takes them for a check ask's unchanged packages (issue 1887's - // design limit 1); the checker alone writes them (ADR 0444 clause 5). - // Whether DEAD_LETTERS is heard (issue 734): read by the checker's own status tool alone. - {Name: "hearing"}, - // The asks each running check put (check.AsksState): read by the checker's own checker_ask_again alone. - {Name: "asks"}, - // The checking program's inputs by their digest (check.InputsStateName): the checker's own, read by its tools alone, - // which serve one on the seat's verb input to the Go build module that runs the program (check.InputVerb; ADR 0596 §2, - // issue 1921). - {Name: check.InputsStateName}, - // The composition requests it sent the composer, per check and node (check.RequestsStateName): read by its tools alone. - {Name: check.RequestsStateName}, - {Name: "kept", Readable: true}, - {Name: "owed", Readable: true}, - {Name: "previews", Readable: true}, - // The tries are read by the delivery view, which tells a try's asks from a candidate's by the asks each names (build_usage). - {Name: "tries", Readable: true}, - {Name: "verdicts", Readable: true}, - // Where its first views of the indexer's and the assigner's states stand (read by checker_first_views alone), and its - // findings of one unanswered past its bound, which the condition keeper observes as it does every reader's (ADR 0615 §6). - {Name: views.StatusState}, - {Name: "findings"}, - // The checks that could not run (check.CouldNotRunState), each asked again when its part runs: read by checker_status. - {Name: check.CouldNotRunState}, -} - -func run(ctx context.Context, getenv func(string) string, logOut io.Writer) error { - logger := log.New(logOut, "mesh-delivery-checker: ", log.LstdFlags) - cred, err := process.ReadBrokerAccount(getenv) - if err != nil { - return err - } - conn, js, err := cred.Dial() - if err != nil { - return err - } - defer conn.Close() - // Its own states: a check without one of them would be unwritten, so each stops the start, naming its grant (issue 1945). - buckets := map[string]jetstream.KeyValue{} - own := func(state string) string { return check.Bucket(cred.Module, state) } // the credential's module, never a constant (A-296) - for _, state := range []string{checker.StateVerdicts, checker.StateKept, checker.StateOwed, checker.StatePreviews, check.TriesState} { - if buckets[state], err = process.EssentialBucket(ctx, js, "checker", own(state), "judge or keep a check"); err != nil { - return err - } - } - // Calls to the build modules go out as this module's own account, naming the machine (mesh-sdk process.CallOn); the - // buckets are read and written on the connection above. - caller, err := process.Connect(cred, nats.Name(cred.Node+"."+cred.Module+".calls"), nats.RetryOnFailedConnect(true)) - if err != nil { - return err - } - defer caller.Close() - // What the checker keeps, said on the bus (ADR 0495 §2-§3): a reader is granted from it. Not fatal when it cannot be said - // now: process.Conn says it again at every reconnect. - if err := caller.Keeps(keptStates...); err != nil { - logger.Printf("what the checker keeps could not be said on the bus, so readers of owed, previews and verdicts are not granted until it is: %v", err) - } - // The candidates it checks, the modules and manifests that say which build modules judge a repository, the published - // packages, the predefined keys and the assignments are their owners' states (the indexer's, the assigner's), read by the - // first view of their read tools and then their views families, never their buckets (ADR 0615 §1, ADR 0596, DLV-M2). - // An owner that is down never holds the start: the checks start once every first view is answered, and until then the - // unanswered first view is the checker's finding. - // The module has one durable consumer of EVENTS: one hub pulls it for the views reader and for the registry seats' - // published, started once both are registered. - hub := process.NewEventHub(logger.Printf) - reader := &views.ProcessReader{Module: cred.Module, Call: caller.Call, Logf: logger.Printf, Hub: hub} - var buildsChanged buildsWatch - seatPart := seatlist.NewPart("checker", nil) - seats := seatList{reader: seatPart.Follow(seatlist.ProcessBus(caller.Call, hub), buildsChanged.Changed, logger.Printf)} - // The finding writer is made once the checker is (its observe reads the checker's kept checks); until then a first view - // unanswered is said in the log alone. - var findings atomic.Pointer[checkerFindings] - reader.Findings = func() views.WireWriter { - if f := findings.Load(); f != nil { - return f.w - } - return nil - } - // Each by the owner's read tool and views family as the owner's manifest names them. - var followed error - followOwner := func(owner, state, tool, stream string) *views.Picture { - p, err := reader.Follow(owner, state, owner+"."+tool) - followed = errors.Join(followed, err) - return p - } - candidates := followOwner(check.IndexerModule, candidatesState, "indexer_read_candidates", indexerViews) - modules := followOwner(check.IndexerModule, modulesState, "indexer_read_modules", indexerViews) - manifests := followOwner(check.IndexerModule, manifestsState, "indexer_read_manifests", indexerViews) - packages := followOwner(check.IndexerModule, meshcatalog.StatePackages, "indexer_read_packages", indexerViews) - predefined := followOwner(check.IndexerModule, check.IndexerPredefinedState, "indexer_read_predefined", indexerViews) - // The assignments is followed once the seat list names the holder of the seat mesh-module-assigner (below). - var assignments atomic.Pointer[views.Picture] - // The seventh: the indexer's seat definitions, so a pull request whose head's definition does not parse fails. - seatDefs := followOwner(check.IndexerModule, seatDefinitionsState, "indexer_read_seat_definitions", indexerViews) - if followed != nil { - return followed - } - // The build modules are no names (design 47 G A-82): the holders of the build seats, the seat list's definitions and the - // holders the indexer's modules name by their manifests' claims, found at each use. - verdicts := &manifestVerdicts{} - repos := &repoModules{manifests: kvStore{manifests}, logf: logger.Printf, verdicts: verdicts} - buildSeats := buildrun.NewBuildSeats(func() map[string]seatdef.Definition { return definitionsOf(seats.reader) }, repos.HolderOf) - repos.seats = buildSeats - - stepBound, err := durationEnv(getenv, "MESH_CHECKER_STEP_BOUND", check.DefaultStepBound) - if err != nil { - return err - } - checkBound, err := durationEnv(getenv, "MESH_CHECKER_BOUND", check.DefaultBound) - if err != nil { - return err - } - settleWindow, err := durationEnv(getenv, "MESH_CHECKER_SETTLE", check.DefaultSettle) - if err != nil { - return err - } - // The begin bound of a run ask of the checking program (check.DefaultBeginBound, issue 1921). - beginBound, err := durationEnv(getenv, "MESH_CHECKER_BEGIN_BOUND", check.DefaultBeginBound) - if err != nil { - return err - } - link := strings.TrimSpace(getenv("MESH_CHECKER_LINK")) - if link == "" { - link = defaultLink - } - tools := &buildrun.ToolchainSet{Seats: buildSeats} - presence := &buildrun.PresenceSet{} - trunks := &check.Trunks{} - // A check is one ask per pull request and build module on the build seats' check stream, pulled by a build node with a - // free slot (novox/hq ADR 0525 §1, §3): the checker chooses no node and starts no step. - asks := buildrun.JetStreamAsks{JS: js} - // The asks the build seats gave up on (issue 734): heard from DEAD_LETTERS, each ends the step its asker waits for. - // Heard in the background, and again at a reconnect or an ask while it is not; whether it is heard is kept in the - // state hearing, which checker_status says (dead_letters). - dead := &buildrun.DeadLetters{} - // The state may not be on the bus yet when a delivery started the checker (the grants part creates it, issue 1790): it - // is bound when the bus says it was created, and the latest hearing is written then. - hearingKV := process.AwaitBucket(ctx, js, conn, own(buildrun.HearingState), "checker_status cannot say whether DEAD_LETTERS is heard", logger.Printf) - hearing := buildrun.NewDeadLetterHearing(ctx, buildrun.JetStreamDeadLetters{JS: js}, []string{buildstep.AskGo, buildstep.AskNode}, dead, - logger.Printf, buildrun.SayHearing(ctx, hearingKV, logger.Printf)) - defer hearing.Stop() - // Each ask's step is heard by its own watch and, at every step end of its build module and every reconnect, read - // (buildrun.HearEnds): a watch that goes deaf loses no end (the lost check of 2026-10-28). - heard := buildrun.HearEnds(ctx, asks, asks, buildSeats.Modules(), logger.Printf) - conn.SetReconnectHandler(func(*nats.Conn) { hearing.Again(); heard.Nudge("") }) - waiter := buildrun.LostAskWaiter{Inner: heard, Dead: dead, Hearing: hearing} - asksKV := process.AwaitBucket(ctx, js, conn, own(check.AsksState), "checker_ask_again refuses every check, as it cannot tell whether its ask waits in a stream", logger.Printf) - inputsKV := process.AwaitBucket(ctx, js, conn, own(check.InputsStateName), "no checking program can be asked, so every check fails naming it", logger.Printf) - couldNotRunKV := process.AwaitBucket(ctx, js, conn, own(check.CouldNotRunState), "a check that could not run is not asked again when its part runs", logger.Printf) - requestsKV := process.AwaitBucket(ctx, js, conn, own(check.RequestsStateName), "no composition request is kept, so every composition made with the node-engine's head fails naming it", logger.Printf) - ch := &check.Checker{ - Asks: awaitedKV{asksKV}, - Verdicts: kvStore{buckets[checker.StateVerdicts]}, - Owed: kvStore{buckets[checker.StateOwed]}, - // A check that could not run waits for its part's running, and is the finding check-could-not-run after its bound. - CouldNotRun: awaitedKV{couldNotRunKV}, - Trunks: trunks, - Bound: checkBound, - Link: link, - Logf: logger.Printf, - Settle: settleWindow, - } - cf, err := newCheckerFindings(ctx, cred, conn, js, caller.State("findings"), ch.RaisedCouldNotRun, logger.Printf) - if err != nil { - return fmt.Errorf("the checker's finding writer: %w", err) - } - defer cf.w.Close() - ch.Findings = cf - findings.Store(cf) - kept := make(chan struct{}, 1) - ch.CouldNotRunKept = func() { - select { - case kept <- struct{}{}: - default: - } - } - go waitCouldNotRun(ctx, ch, kept) - // The builder's builds say how the candidates' fingerprints stand (issue 1684); where its bucket is not there yet the line - // says nothing of the builds, until the checker starts again. - var buildStates check.BuildStates - var ends check.BuildEnds - if kv := process.OptionalBucket(ctx, js, builds.BuildsBucket(builds.BuilderModule), "the line says nothing of the builds, and a check composes without waiting on them, until the checker starts again", logger.Printf); kv != nil { - buildStates, ends = buildReader{kvStore{kv}}, buildEnds{kv} - } - if ends != nil { - ch.Rebuilds = ends // a check failed on a build is asked again once that build is done again (ADR 0603 §10) - } - // The check's composition is the checker's, from what each placed node's engine answers (ADR 0593 §7, §9). - set, err := readSettings(getenv("MESH_CHECKER_SETTINGS")) - if err != nil { - return err - } - answerBound := set.answer - holdCallsFor(answerBound) - compositions := check.EngineCompositions{ - Requests: check.RequestKeeper{Store: requestsKV}, - Asker: engineAsks{call: caller.CallOn}, - Placed: placedNodes{kv: assignedNodes(&assignments)}.Placed, - Bound: answerBound, - Sandbox: seatSandbox{module: cred.Module, asker: buildrun.Asker{Seats: buildSeats, Publisher: asks, Waiter: waiter, Bound: stepBound, Dropper: buildrun.SeatDrops{Caller: caller}, Outputs: caller.CallFile}}, - Verdicts: verdicts.all, - // The node-engine's trunk head: a group with no node-engine member composes with the composer built there (ADR 0656 §5). - Composer: func() string { return trunks.Heads()[check.NodeEngineRepository] }, - } - // The tries (ADR 0501 §5) are judged by the same judge, held by the same deliveries. - tryer := &check.Tryer{Tries: kvStore{buckets[check.TriesState]}, Bound: checkBound, NotTaken: stepBound, Logf: logger.Printf, - // A whole try's start and end are said on the stream checks, for the indexer to write and delete the candidate of its group. - Say: func(ctx context.Context, event string, body checkermsg.Event) error { - data, _ := json.Marshal(body) - _, err := js.Publish(ctx, eventSubject(cred.Module, event), data, jetstream.WithRetryAttempts(10), jetstream.WithRetryWait(time.Second)) - return err - }} - announce := func(ctx context.Context, event, key string) { - body, _ := json.Marshal(map[string]string{"key": key}) - if _, err := js.Publish(ctx, eventSubject(cred.Module, event), body); err != nil { - logger.Printf("%s of %s was written and the part that reads it could not be told: %v", event, key, err) - } - } - compositions.Composer = func() string { return repos.CommitOf(check.NodeEngineModule) } - compositions.Manifests = repos - // The indexer's packages state (ADR 0593 §2), so a Go check builds every mesh package at its published version: read - // once the first views are answered, before any check starts (afterFirstViews). - published := &publishedPackages{} - compositions.Published = published - ch.Runs = repos // the node-engine a check reads beside at its running commit (ADR 0548 §6) - ch.Says = verdictSays{module: cred.Module, js: js, node: cred.Node, now: time.Now} // a pull request's verdict event, on the stream asks (design 26 *Out of step*) - ch.Judge = newJudge(judgeDeps{ - module: cred.Module, - asks: buildrun.Asker{Seats: buildSeats, Publisher: asks, Waiter: waiter, Bound: stepBound, Dropper: buildrun.SeatDrops{Caller: caller}, Outputs: caller.CallFile}, tools: tools, trunks: trunks, - kept: kvStore{buckets[checker.StateKept]}, previews: kvStore{buckets[checker.StatePreviews]}, candidates: tryCandidates{candidates}, - repos: repos, published: published, builds: buildStates, ends: ends, buildWait: set.buildWait, forge: forgeReads{call: caller.Call}, logf: logger.Printf, - announce: announce, compositions: compositions, inputs: runInputs{awaitedKV{inputsKV}}, beginBound: beginBound, - nodes: openNodeNames(ctx, js, logger.Printf), - predefined: keptPredefined{predefined}, - renames: seatRenames{call: caller.Call}, - seatDefs: seatDefinitionsOf(seatDefs), - seats: seats, - buildSeats: buildSeats, - }) - ch.Announce = announce - tryer.Judge = ch.Judge - - // The toolchains first, so a check that starts from the first candidate finds the nodes. - watch := newToolchainWatch(ctx, js, buildSeats, tools, ch.NodesChanged, logger) - // Only the toolchain reports of nodes the catalogue places the build module on count (issue 1940, ADR 0549 §3): the - // assignments is settled first, so the toolchains settle through the gate already knowing it. - gate := buildrun.NewToolchainGate(buildSeats.Modules(), tools.Put, logger.Printf) - watch.put = gate.Toolchain - // Until the assignments's first view is answered the gate passes every report on, as before the assignments is settled. - assignmentsErrs := make(chan error, 1) - // The assignments is the seat mesh-module-assigner's view, followed at the holder the seat-holders view names and as it - // moves (design 47 G §717): the holder function is the catalog half's claimant's seat-holders view (A-298), so no assigner - // module is named and nothing asks for the holder on a timer. - branches, err := meshcatalogclient.FollowBranchesProcess(reader, caller.Call) - if err != nil { - return err - } - branches.Logf = logger.Printf - pic, err := reader.FollowSeat(meshmoduleassigner.Seat, meshmoduleassigner.StateAssignments, branches.SeatHolders(ctx)) - if err != nil { - return err - } - assignments.Store(pic) - go func() { - select { - case <-ctx.Done(): - return - case <-pic.Follower().Ready(): - } - pe, err := buildrun.FollowAssignmentsIn(ctx, reader, pic.Bucket(), gate, ch.NodesChanged, logger.Printf) - if err != nil { - assignmentsErrs <- err - return - } - assignmentsErrs <- <-pe - }() - if err := watch.start(); err != nil { - return err - } - // A build seat says each time a node reported its toolchain (its event toolchain-reported, design 47 G §492): the bucket of - // the seat's holder is watched then, if it is not (Reported), and again when the seat list or the holders change (below). - for _, lang := range []string{buildstep.AskGo, buildstep.AskNode} { - seat, err := buildstep.BuildSeat(lang) - if err != nil { - return err - } - if err := hub.Handle("mesh.seat."+seat+".event.toolchain-reported.>", func(m jetstream.Msg) { watch.Reported(m) }); err != nil { - return err - } - } - // The build modules are named by the seat list and the indexer's modules: a change of either watches the steps and toolchains of - // a build module not watched yet and tells the gate which modules' reports it passes on. - buildsChanged.Set(func() { - heard.Watch(buildSeats.Modules()) - gate.UseModules(buildSeats.Modules()) - if err := watch.start(); err != nil { - logger.Printf("the toolchains of a build module cannot be watched: %v", err) - } - }) - // The node-engine seat's running.., kept last per subject (design 47): a part a check could not hear runs, - // and the check is asked again (issue 1373). Its stream and the checker's durable consumer on it are made from the - // manifest's consumes; where they are not there yet the checker says so, and a check that could not run waits for its - // bound and is said as a finding. - if cons, err := cred.EventConsumer(ctx, js, nodeengine.StreamRunning); err != nil { - logger.Printf("the consumer %s_%s on %s does not exist yet, so no check that could not run is asked again until the checker starts again: %v", cred.Node, cred.Module, nodeengine.StreamRunning, err) - } else { - cc, err := process.HearEvents(cons, func(m jetstream.Msg) { heardRunning(ctx, ch, m.Data(), logger.Printf) }, logger.Printf) - if err != nil { - return err - } - defer cc.Stop() - } - errs := make(chan error, 8) - // The watchman's presence: a node coming back online asks again a check whose forge was not heard (UnheardWords), and - // the assigner's own presence says whether a composition is being made (compositionWatch, ADR 0537 §4). A check is no - // longer held for a node: its asks wait in the build seats' streams, which redeliver a lost node's ask (ADR 0525 §6, - // issue 1912), so the node-engine's have is not watched here. - if kv := process.OptionalBucket(ctx, js, check.PresenceBucket, "no node counts as online until the checker starts again", logger.Printf); kv != nil { - if pw, err := settle(ctx, kv, func(e jetstream.KeyValueEntry) { presence.Put(e.Key(), e.Value(), !opOf(e)) }); err != nil { - process.NotWatched(logger.Printf, check.PresenceBucket, err, "no node counts as online until the checker starts again") - } else { - go func() { - errs <- follow(ctx, pw, func(e jetstream.KeyValueEntry) { - if presence.Put(e.Key(), e.Value(), !opOf(e)) { - ch.NodesChanged(ctx) // a node came online or went: a check whose forge was not heard may now be heard - } - }) - }() - } - } - // The catalog half says the trunk head of each repository, which a pull request is merged onto (design 47 G §197). Where it - // does not answer yet no trunk is known, so nothing is checked. - firstTrunks, err := followTrunks(hub, caller.Call, trunks, ch.TrunkMoved, logger.Printf) - if err != nil { - return fmt.Errorf("the checker cannot hear the catalog half's revisions: %w", err) - } - firstTrunks(ctx) - afterFirstViews := func() error { - // The modules say which repository holds a TypeScript module, so the Node build module judges it too. - pw, err := settle(ctx, packages, func(e jetstream.KeyValueEntry) { published.Put(e.Key(), e.Value(), !opOf(e)) }) - if err != nil { - return err - } - published.Answered() // read whole, an empty state too: its names are judged from here on - go func() { - errs <- follow(ctx, pw, func(e jetstream.KeyValueEntry) { published.Put(e.Key(), e.Value(), !opOf(e)) }) - }() - mw, err := settle(ctx, modules, func(e jetstream.KeyValueEntry) { repos.Put(ctx, e.Key(), e.Value(), !opOf(e)) }) - if err != nil { - return err - } - buildsChanged.Changed() // the holders of the build seats are known from here - go func() { - errs <- follow(ctx, mw, func(e jetstream.KeyValueEntry) { - before := repos.CommitOf(check.NodeEngineModule) - repos.Put(ctx, e.Key(), e.Value(), !opOf(e)) - buildsChanged.Changed() // a holder of a build seat may have moved - if after := repos.CommitOf(check.NodeEngineModule); after != before { - ch.TrunkMoved(ctx) // the node-engine the mesh runs moved: a verdict that read it beside is carried (ADR 0548 §6) - } - }) - }() - each := func(e jetstream.KeyValueEntry) { - if opOf(e) { - ch.Candidate(ctx, e.Key(), e.Value()) - } else { - ch.Forget(e.Key()) - } - } - w, err := settle(ctx, candidates, each) - if err != nil { - return err - } - // A key left running for heads no candidate holds is closed; the candidates are all known now. - if err := ch.Sweep(ctx); err != nil { - return err - } - // The tries: a queued one starts, one left running is taken over, an ended one past its keeping is removed. - tw, err := settle(ctx, buckets[check.TriesState], func(jetstream.KeyValueEntry) {}) - if err != nil { - return err - } - tryer.Reconsider(ctx) - go func() { - errs <- follow(ctx, tw, func(e jetstream.KeyValueEntry) { - if opOf(e) { - tryer.Put(ctx, e.Key(), e.Value()) - } - }) - }() - // The checker's own verdicts, updates only, in one watch: one checker_ask_again wrote asks its check again - // (Checker.VerdictWritten); a deleted key of heads a candidate holds is judged again (Checker.VerdictDeleted, issue 1733). - vw, err := buckets[checker.StateVerdicts].WatchAll(ctx, jetstream.UpdatesOnly()) - if err != nil { - return fmt.Errorf("the checker's verdicts cannot be watched, so no check can be asked again by hand and a deleted verdict would never be written again: %w", err) - } - go func() { - errs <- follow(ctx, vw, func(e jetstream.KeyValueEntry) { - if opOf(e) { - ch.VerdictWritten(ctx, e.Key(), e.Value()) - } else { - ch.VerdictDeleted(ctx, e.Key()) - } - }) - }() - go func() { errs <- follow(ctx, w, each) }() - return nil - } - reader.Start(ctx, js, cred, process.AwaitBucket(ctx, js, conn, firstViewsBucket(cred.Module), "checker_first_views reads nothing and checker_first_view_again is not heard", logger.Printf)) - // Every part has registered. Where the consumer is not there yet the hub binds it as soon as it is, and the seat list is read - // again then if it is still unread. - if err := hub.StartUntilBound(ctx, js, cred, nil, seatPart.EventsLive); err != nil { - logger.Printf("%v, so no package registry's published is heard until the consumer is there; the checker tries again", err) - } - defer hub.Stop() - // The checks, the tries and the hand asks, once every first view is answered (the lead's ruling for DLV-M2): a check - // judged without the candidates, the modules, the manifests, the published packages, the predefined keys or the - // assignments would be another check. - go func() { - select { - case <-ctx.Done(): - return - case <-reader.Ready(): - } - if err := afterFirstViews(); err != nil { - errs <- err - } - }() - logger.Printf("started on %s", cred.Node) - select { - case <-ctx.Done(): - ch.Wait() - tryer.Wait() - return nil - case err := <-errs: - return err - case err := <-assignmentsErrs: - return err - case err := <-watch.errs: - return err - } -} diff --git a/modules/mesh-delivery-checker/cmd/mesh-delivery-checker/nodes_test.go b/modules/mesh-delivery-checker/cmd/mesh-delivery-checker/nodes_test.go deleted file mode 100644 index aa903e5b..00000000 --- a/modules/mesh-delivery-checker/cmd/mesh-delivery-checker/nodes_test.go +++ /dev/null @@ -1,22 +0,0 @@ -package main - -import ( - "os" - "strings" - "testing" -) - -// 1912: with checks as asks on the build seats' streams, the stream redelivers a lost node's ask (ADR 0525 §6), so the -// checker program watches no node-engine have to start again a check that failed for want of a node. It reads the have's -// keys only for the nodes' names at each ask (judge.go, novox/hq ADR 0567 §12). -func TestTheCheckerWatchesNoHave(t *testing.T) { - raw, err := os.ReadFile("main.go") - if err != nil { - t.Fatal(err) - } - for _, s := range []string{"check.HaveBucket", "buildrun.HaveSet"} { - if strings.Contains(string(raw), s) { - t.Errorf("the checker program still reads %s", s) - } - } -} diff --git a/modules/mesh-delivery-checker/cmd/mesh-delivery-checker/packages.go b/modules/mesh-delivery-checker/cmd/mesh-delivery-checker/packages.go deleted file mode 100644 index a1925e82..00000000 --- a/modules/mesh-delivery-checker/cmd/mesh-delivery-checker/packages.go +++ /dev/null @@ -1,108 +0,0 @@ -package main - -import ( - "strings" - "sync" - - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep" -) - -// publishedPackages is the indexer's state `packages` as the checker follows it (novox/hq ADR 0593 §2): by mesh Go -// module, the latest published commit of its repository the indexer read its packages at. The indexer alone computes a -// package's version; the checker reads it, so a Go check builds every mesh package at the version the mesh publishes -// (check.Examiner.Published) and computes none. -// -// Its series keys (meshcatalog.PackagesByPackageSeriesValue, decoded with meshcatalog.DecodePackagesByPackageSeriesValue) name each package by its name in its -// own ecosystem and the `/` it is built from (design 32): the known packages the judge takes -// (PackageNames). -type publishedPackages struct { - mu sync.Mutex - byKey map[string]meshcatalog.PackagesByModuleValue - series map[string]meshcatalog.PackagesByPackageSeriesValue - unread map[string]string - // answered is whether the state's first reading ended (Answered): until then the checker knows no package's name. - answered bool -} - -// Answered marks the state's first reading as ended, so PackageNames names what it holds, none included. -func (p *publishedPackages) Answered() { - p.mu.Lock() - defer p.mu.Unlock() - p.answered = true -} - -// Put takes one key of the state in: its value, or its deletion. A value that does not decode is kept out and remembered -// with why, never read as an older one. -func (p *publishedPackages) Put(key string, raw []byte, deleted bool) { - p.mu.Lock() - defer p.mu.Unlock() - if p.byKey == nil { - p.byKey, p.series, p.unread = map[string]meshcatalog.PackagesByModuleValue{}, map[string]meshcatalog.PackagesByPackageSeriesValue{}, map[string]string{} - } - delete(p.byKey, key) - delete(p.series, key) - delete(p.unread, key) - if deleted { - return - } - if isSeriesPackageKey(key) { - s, err := meshcatalog.DecodePackagesByPackageSeriesValue(raw) - if err != nil { - p.unread[key] = err.Error() - return - } - p.series[key] = s - return - } - v, err := meshcatalog.DecodePackagesByModuleValue(raw) - if err != nil { - p.unread[key] = err.Error() - return - } - p.byKey[key] = v -} - -// LatestPackages is the latest published version of every mesh Go module the indexer holds, by module path: the commit -// its repository was published at. A module the state does not hold is left out: a check builds it at the version -// go.mod names. -func (p *publishedPackages) LatestPackages() buildstep.PackageVersions { - p.mu.Lock() - defer p.mu.Unlock() - out := buildstep.PackageVersions{} - for _, v := range p.byKey { - if v.Module != "" && v.Commit != "" { - out[v.Module] = v.Commit - } - } - return out -} - -// PackageNames are the packages the state's series keys name, and the Go module path of each per-module record (issue -// 1966: the indexer's own knownPackages counts them the same way, with no `/` to say; never a package -// inside a module, design 32), by the name in its own ecosystem: the `/` -// each is built from (empty when the key does not say). Nil while the state is not read yet (Answered), which judges no -// name; once read never nil, an empty state included, so the judge judges every name against it. -func (p *publishedPackages) PackageNames() map[string]string { - p.mu.Lock() - defer p.mu.Unlock() - if !p.answered { - return nil - } - out := map[string]string{} - for _, s := range p.series { - if out[s.Name] == "" { - out[s.Name] = s.Package - } - } - for _, v := range p.byKey { - if _, ok := out[v.Module]; !ok && v.Module != "" { - out[v.Module] = "" - } - } - return out -} - -// isSeriesPackageKey says a key of the indexer's state packages is a package's series (`.`): a module's key -// is its path escaped, which holds no dot (keys.EscapeName). -func isSeriesPackageKey(key string) bool { return strings.Contains(key, ".") } diff --git a/modules/mesh-delivery-checker/cmd/mesh-delivery-checker/refused_test.go b/modules/mesh-delivery-checker/cmd/mesh-delivery-checker/refused_test.go deleted file mode 100644 index 9370f34f..00000000 --- a/modules/mesh-delivery-checker/cmd/mesh-delivery-checker/refused_test.go +++ /dev/null @@ -1,62 +0,0 @@ -package main - -import ( - "bytes" - "context" - "errors" - "log" - "strings" - "testing" - - "git.novox.be/novox/mesh-sdk/go/process" - - "github.com/nats-io/nats.go/jetstream" - - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-builder/buildrun" -) - -// 1945 (a part exits at start for a bucket it works without): a bus that refuses every toolchains bucket leaves the -// watch unstarted and the part running, said; a refused bucket it cannot work without is an error naming the bucket and -// its grant. The gate over the seat's assignments, and its refusal, are mesh-sdk's (buildrun.ToolchainGate, -// issue 774). -func TestARefusedBucketIsSaidAndThePartGoesOn(t *testing.T) { - set := &buildrun.ToolchainSet{Seats: testBuildSeats()} - var logs bytes.Buffer - logger := log.New(&logs, "", 0) - refused := refusingBus{err: errors.New("nats: permissions violation for publish to $JS.API.CONSUMER.CREATE.KV_mesh-build-node_toolchains")} - if err := newToolchainWatch(context.Background(), refusingBus{refuseOpen: true, err: refused.err}, testBuildSeats(), set, func(context.Context) {}, logger).start(); err != nil { - t.Errorf("a refused toolchains bucket stopped the start: %v", err) - } - if !strings.Contains(logs.String(), "cannot be read") { - t.Errorf("the refusals were not said: %q", logs.String()) - } - if _, err := process.EssentialBucket(context.Background(), refusingBus{refuseOpen: true, err: refused.err}, "checker", "mesh-delivery-indexer_modules", "work"); err == nil || - !strings.Contains(err.Error(), "grant of mesh-delivery-indexer_modules") { - t.Errorf("a refused bucket the part needs: %v, want an error naming its grant", err) - } -} - -// refusingBus is a bus that refuses: every open (refuseOpen), or every watch of a bucket it opens, with err. -type refusingBus struct { - refuseOpen bool - err error -} - -func (r refusingBus) KeyValue(context.Context, string) (jetstream.KeyValue, error) { - if r.refuseOpen { - return nil, r.err - } - return refusedWatch{err: r.err}, nil -} - -type refusedWatch struct { - jetstream.KeyValue - err error -} - -func (r refusedWatch) WatchAll(context.Context, ...jetstream.WatchOpt) (jetstream.KeyWatcher, error) { - return nil, r.err -} -func (r refusedWatch) Watch(context.Context, string, ...jetstream.WatchOpt) (jetstream.KeyWatcher, error) { - return nil, r.err -} diff --git a/modules/mesh-delivery-checker/cmd/mesh-delivery-checker/renames.go b/modules/mesh-delivery-checker/cmd/mesh-delivery-checker/renames.go deleted file mode 100644 index dca90323..00000000 --- a/modules/mesh-delivery-checker/cmd/mesh-delivery-checker/renames.go +++ /dev/null @@ -1,36 +0,0 @@ -package main - -import ( - "context" - "encoding/json" - "errors" - "fmt" - - "github.com/nats-io/nats.go" - - "git.novox.be/novox/mesh-contracts/go/seats/meshconfig" - - "mesh-delivery-checker/internal/check" -) - -// seatRenames asks the seat mesh-config's verb renames as the checker's own account (its `invokes` -// seat:mesh-config.renames; design 32). A call nobody answers is a holder serving no renames (the verb is optional), said -// as check.ErrRenamesNotServed with the bus's words; any other error is an ask that could not be made. -type seatRenames struct { - call func(key string, body any) (json.RawMessage, error) -} - -func (s seatRenames) Renames(_ context.Context, module string) (meshconfig.RenamesAnswer, error) { - raw, err := s.call(check.RenamesSeat, meshconfig.RenamesInput{Module: module}) - if errors.Is(err, nats.ErrNoResponders) { - return meshconfig.RenamesAnswer{}, fmt.Errorf("%w (nothing answers it: %v)", check.ErrRenamesNotServed, err) - } - if err != nil { - return meshconfig.RenamesAnswer{}, err - } - var a meshconfig.RenamesAnswer - if err := json.Unmarshal(raw, &a); err != nil { - return meshconfig.RenamesAnswer{}, fmt.Errorf("%s answered what is not its answer: %w", check.RenamesSeat, err) - } - return a, nil -} diff --git a/modules/mesh-delivery-checker/cmd/mesh-delivery-checker/seatlist_wiring_test.go b/modules/mesh-delivery-checker/cmd/mesh-delivery-checker/seatlist_wiring_test.go deleted file mode 100644 index f8e31bca..00000000 --- a/modules/mesh-delivery-checker/cmd/mesh-delivery-checker/seatlist_wiring_test.go +++ /dev/null @@ -1,29 +0,0 @@ -package main - -import ( - "os" - "path/filepath" - "strings" - "testing" -) - -// The checker wires no reader of the seat list of its own (design 47 G §204, CK9): it follows the list through mesh-sdk's -// seatlist.Part, and its code holds no seatlist.Start nor a file of its own for the list. -func TestTheCheckerWiresNoSeatListReaderOfItsOwn(t *testing.T) { - if _, err := os.Stat("seatlist.go"); err == nil { - t.Error("seatlist.go is the checker's own wiring of the seat list: mesh-sdk's seatlist.Part is the one wiring") - } - files, _ := filepath.Glob("*.go") - for _, f := range files { - if strings.HasSuffix(f, "_test.go") { - continue - } - src, err := os.ReadFile(f) - if err != nil { - t.Fatal(err) - } - if strings.Contains(string(src), "seatlist.Start(") { - t.Errorf("%s starts a seat list reader of its own: use seatlist.Part.Follow", f) - } - } -} diff --git a/modules/mesh-delivery-checker/cmd/mesh-delivery-checker/seats_test.go b/modules/mesh-delivery-checker/cmd/mesh-delivery-checker/seats_test.go deleted file mode 100644 index 856e6f6e..00000000 --- a/modules/mesh-delivery-checker/cmd/mesh-delivery-checker/seats_test.go +++ /dev/null @@ -1,23 +0,0 @@ -package main - -import ( - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-builder/buildrun" - "git.novox.be/novox/mesh-sdk/go/seatdef" -) - -// The holders of the build seats in the tests' seat list: names the checker's code does not know, found by the seats' acting -// rules (design 47 G A-82). -const ( - goBuildModule = "mesh-build-go" - nodeBuildModule = "mesh-build-node" -) - -// testBuildSeats is the finder over the build seats of the tests' seat list. -func testBuildSeats() *buildrun.BuildSeats { - rule := func(on string) seatdef.Definition { - return seatdef.Definition{Acts: []seatdef.ActingRule{{Step: seatdef.StepBuild, On: on}}} - } - defs := map[string]seatdef.Definition{"node-build-go": rule("go"), "node-build-node": rule("typescript")} - holders := map[string]string{"node-build-go": goBuildModule, "node-build-node": nodeBuildModule} - return buildrun.NewBuildSeats(func() map[string]seatdef.Definition { return defs }, func(seat string) (string, bool) { h, ok := holders[seat]; return h, ok }) -} diff --git a/modules/mesh-delivery-checker/cmd/mesh-delivery-checker/settings.go b/modules/mesh-delivery-checker/cmd/mesh-delivery-checker/settings.go deleted file mode 100644 index c198376e..00000000 --- a/modules/mesh-delivery-checker/cmd/mesh-delivery-checker/settings.go +++ /dev/null @@ -1,73 +0,0 @@ -package main - -import ( - "encoding/json" - "errors" - "fmt" - "io/fs" - "os" - "time" - - nec "git.novox.be/novox/mesh-contracts/go/clients/nodeengineclient" - "git.novox.be/novox/mesh-sdk/go/process" - - "mesh-delivery-checker/internal/check" -) - -// The checker's own settings (its config, written by the node-engine into ${dir:state}/settings.json, named to the -// process by MESH_CHECKER_SETTINGS): compose-answer-bound, the seconds a check waits for a node's engine to answer -// compose-candidate (novox/hq ADR 0593 §7, §9: 60 by default), and build-wait-bound, the seconds a check waits for the -// builder's builds of its candidate before it composes (ADR 0603 §10: 1800 by default). The checker owns both. - -// settings are the checker's settings as read. -type settings struct { - // answer is compose-answer-bound; buildWait is build-wait-bound. - answer, buildWait time.Duration -} - -// readSettings reads the settings file at path: each value's default where no file or no value is there; a value that is -// no whole number of seconds within its range is refused, naming it. -func readSettings(path string) (settings, error) { - out := settings{answer: nec.AnswerBound, buildWait: check.DefaultBuildWait} - if path == "" { - return out, nil - } - raw, err := os.ReadFile(path) - if errors.Is(err, fs.ErrNotExist) { - return out, nil - } - if err != nil { - return settings{}, err - } - var s struct { - Answer *float64 `json:"compose-answer-bound"` - BuildWait *float64 `json:"build-wait-bound"` - } - if err := json.Unmarshal(raw, &s); err != nil { - return settings{}, fmt.Errorf("%s is no settings file: %w", path, err) - } - for _, v := range []struct { - name string - value *float64 - min, max float64 - into *time.Duration - }{{"compose-answer-bound", s.Answer, 1, 600, &out.answer}, {"build-wait-bound", s.BuildWait, 60, 7200, &out.buildWait}} { - if v.value == nil { - continue - } - if *v.value < v.min || *v.value > v.max || *v.value != float64(int(*v.value)) { - return settings{}, fmt.Errorf("%s is %v: a whole number of seconds from %v to %v", v.name, *v.value, v.min, v.max) - } - *v.into = time.Duration(*v.value) * time.Second - } - return out, nil -} - -// holdCallsFor makes a bus call wait the compose-answer-bound (novox/hq ADR 0593 §7), not the SDK's CallTimeout of 30 s: -// the request of Conn.CallOn gives up at CallTimeout, so a node-engine answering at 30.4 s was lost before the bound -// applied (issue 1126). It only ever lengthens the SDK's bound, and it is set once, before the first call. -func holdCallsFor(bound time.Duration) { - if bound > process.CallTimeout { - process.CallTimeout = bound - } -} diff --git a/modules/mesh-delivery-checker/cmd/mesh-delivery-checker/settings_test.go b/modules/mesh-delivery-checker/cmd/mesh-delivery-checker/settings_test.go deleted file mode 100644 index 73e8b431..00000000 --- a/modules/mesh-delivery-checker/cmd/mesh-delivery-checker/settings_test.go +++ /dev/null @@ -1,53 +0,0 @@ -package main - -import ( - "os" - "path/filepath" - "testing" - "time" - - nec "git.novox.be/novox/mesh-contracts/go/clients/nodeengineclient" - "git.novox.be/novox/mesh-sdk/go/process" - - "mesh-delivery-checker/internal/check" -) - -// ADR 0593 §7: the answer bound is the checker's setting compose-answer-bound, 60 s when the file or the value is -// absent; a value that is no whole number of seconds from 1 to 600 stops the start, naming it. ADR 0603 §10: the wait for -// the candidate's builds is build-wait-bound, 30 minutes when absent, from 60 to 7200 seconds. -func TestTheAnswerBoundIsTheCheckersSetting(t *testing.T) { - dir := t.TempDir() - for _, row := range []struct { - body string - want time.Duration - err bool - buildWait time.Duration - }{{"", nec.AnswerBound, false, check.DefaultBuildWait}, {`{}`, nec.AnswerBound, false, check.DefaultBuildWait}, - {`{"compose-answer-bound": 90}`, 90 * time.Second, false, check.DefaultBuildWait}, {`{"compose-answer-bound": 0}`, 0, true, 0}, - {`{"compose-answer-bound": 1.5}`, 0, true, 0}, - {`{"compose-answer-bound": 60, "build-wait-bound": 600}`, 60 * time.Second, false, 10 * time.Minute}, - {`{"build-wait-bound": 30}`, 0, true, 0}} { - path := filepath.Join(dir, "settings.json") - os.Remove(path) - if row.body != "" { - if err := os.WriteFile(path, []byte(row.body), 0o600); err != nil { - t.Fatal(err) - } - } - set, err := readSettings(path) - got := set.answer - if (err != nil) != row.err || got != row.want || set.buildWait != row.buildWait { - t.Errorf("%q: %s, %s, %v", row.body, got, set.buildWait, err) - } - // Issue 1126: the SDK's call gives up at CallTimeout (30 s), so the checker's calls must wait the bound read - // (an answer at 31 s is heard under 60 s), and the bound never shortens the SDK's own. - if err == nil { - was := process.CallTimeout - holdCallsFor(got) - if process.CallTimeout < got || process.CallTimeout < was { - t.Errorf("%q: calls wait %v under bound %v", row.body, process.CallTimeout, got) - } - process.CallTimeout = was - } - } -} diff --git a/modules/mesh-delivery-checker/cmd/mesh-delivery-checker/testdata/catalogue-835bf22b-xterm.module.json b/modules/mesh-delivery-checker/cmd/mesh-delivery-checker/testdata/catalogue-835bf22b-xterm.module.json deleted file mode 100644 index b65be8eb..00000000 --- a/modules/mesh-delivery-checker/cmd/mesh-delivery-checker/testdata/catalogue-835bf22b-xterm.module.json +++ /dev/null @@ -1,236 +0,0 @@ -{ - "module": "xterm", - "version": "1", - "moved": true, - "capabilities": [ - "package-manager" - ], - "requires": [ - "x11-display" - ], - "claims": [ - { - "name": "node-terminal-emulator", - "scope": "node", - "serves": [ - "open" - ] - } - ], - "tools": [ - "xterm_font", - "xterm_colours" - ], - "config": { - "face": { - "type": "string", - "description": "The font family xterm draws with, as fc-list names it: JetBrainsMono Nerd Font, because research 026/04 chose it for its glyphs the prompt uses. A family the machine does not have falls back to the nearest installed face (xterm_font says which).", - "pattern": "[A-Za-z0-9 ._-]{1,64}", - "default": "JetBrainsMono Nerd Font" - }, - "size": { - "type": "number", - "description": "The size of xterm's text, in points: 12 reads well on a screen of about 100 DPI, and a denser screen needs a larger size.", - "minimum": 6, - "maximum": 72, - "predefined": "font-size", - "default": 12 - }, - "save-lines": { - "type": "number", - "description": "How many lines of scrollback xterm keeps per terminal: 10000 holds a long build log, and each line costs memory in every open terminal.", - "minimum": 0, - "maximum": 1000000, - "default": 10000 - }, - "term-name": { - "type": "string", - "description": "The TERM value xterm sets for the programs it runs: xterm-256color, because the palette has 256 colours and every program knows the name.", - "pattern": "[A-Za-z0-9._-]{1,64}", - "default": "xterm-256color" - }, - "render-font": { - "type": "boolean", - "description": "Whether xterm draws with fontconfig faces (true) or the old X core fonts (false): true, because the face is a fontconfig family and core fonts cannot show it.", - "default": true - }, - "bold-mode": { - "type": "boolean", - "description": "Whether xterm draws bold text by overstriking the normal face (true): false, because the face has a real bold style and overstriking blurs it.", - "default": false - }, - "always-bold-mode": { - "type": "boolean", - "description": "Whether xterm overstrikes bold even where the face has a bold style (true): false, for the same reason as bold-mode.", - "default": false - }, - "allow-bold-fonts": { - "type": "boolean", - "description": "Whether xterm may use the face's bold style for bold text (true): true, so bold text is drawn with the real bold weight.", - "default": true - }, - "background": { - "type": "string", - "description": "The terminal's background colour, as #rrggbb: black, as both workstations ran it.", - "pattern": "#[0-9a-fA-F]{6}", - "default": "#000000" - }, - "foreground": { - "type": "string", - "description": "The terminal's text colour, as #rrggbb: a light grey, easier on the eyes than white on black.", - "pattern": "#[0-9a-fA-F]{6}", - "default": "#a8a8a8" - }, - "color0": { - "type": "string", - "description": "Palette entry 0, the normal black, as #rrggbb: #000000, as both workstations ran it.", - "pattern": "#[0-9a-fA-F]{6}", - "default": "#000000" - }, - "color1": { - "type": "string", - "description": "Palette entry 1, the normal red, as #rrggbb: #9e1828, as both workstations ran it.", - "pattern": "#[0-9a-fA-F]{6}", - "default": "#9e1828" - }, - "color2": { - "type": "string", - "description": "Palette entry 2, the normal green, as #rrggbb: #008800, as both workstations ran it.", - "pattern": "#[0-9a-fA-F]{6}", - "default": "#008800" - }, - "color3": { - "type": "string", - "description": "Palette entry 3, the normal yellow, as #rrggbb: #d2bb4b, as both workstations ran it.", - "pattern": "#[0-9a-fA-F]{6}", - "default": "#d2bb4b" - }, - "color4": { - "type": "string", - "description": "Palette entry 4, the normal blue, as #rrggbb: #414171, as both workstations ran it.", - "pattern": "#[0-9a-fA-F]{6}", - "default": "#414171" - }, - "color5": { - "type": "string", - "description": "Palette entry 5, the normal magenta, as #rrggbb: #963c59, as both workstations ran it.", - "pattern": "#[0-9a-fA-F]{6}", - "default": "#963c59" - }, - "color6": { - "type": "string", - "description": "Palette entry 6, the normal cyan, as #rrggbb: #418179, as both workstations ran it.", - "pattern": "#[0-9a-fA-F]{6}", - "default": "#418179" - }, - "color7": { - "type": "string", - "description": "Palette entry 7, the normal white, as #rrggbb: #bebebe, as both workstations ran it.", - "pattern": "#[0-9a-fA-F]{6}", - "default": "#bebebe" - }, - "color8": { - "type": "string", - "description": "Palette entry 8, the bright black, as #rrggbb: #666666, as both workstations ran it.", - "pattern": "#[0-9a-fA-F]{6}", - "default": "#666666" - }, - "color9": { - "type": "string", - "description": "Palette entry 9, the bright red, as #rrggbb: #bc5766, as both workstations ran it.", - "pattern": "#[0-9a-fA-F]{6}", - "default": "#bc5766" - }, - "color10": { - "type": "string", - "description": "Palette entry 10, the bright green, as #rrggbb: #61a171, as both workstations ran it.", - "pattern": "#[0-9a-fA-F]{6}", - "default": "#61a171" - }, - "color11": { - "type": "string", - "description": "Palette entry 11, the bright yellow, as #rrggbb: #e7db52, as both workstations ran it.", - "pattern": "#[0-9a-fA-F]{6}", - "default": "#e7db52" - }, - "color12": { - "type": "string", - "description": "Palette entry 12, the bright blue, as #rrggbb: #5085af, as both workstations ran it.", - "pattern": "#[0-9a-fA-F]{6}", - "default": "#5085af" - }, - "color13": { - "type": "string", - "description": "Palette entry 13, the bright magenta, as #rrggbb: #a97a99, as both workstations ran it.", - "pattern": "#[0-9a-fA-F]{6}", - "default": "#a97a99" - }, - "color14": { - "type": "string", - "description": "Palette entry 14, the bright cyan, as #rrggbb: #6ba4a4, as both workstations ran it.", - "pattern": "#[0-9a-fA-F]{6}", - "default": "#6ba4a4" - }, - "color15": { - "type": "string", - "description": "Palette entry 15, the bright white, as #rrggbb: #ffffff, as both workstations ran it.", - "pattern": "#[0-9a-fA-F]{6}", - "default": "#ffffff" - }, - "copy-binding": { - "type": "string", - "description": "The key combination that copies the selection to the clipboard, in X translation syntax: Ctrl Shift ~Alt C, so a plain Ctrl+C still interrupts the program. It holds no colon, backslash or line break, which would end the resource.", - "pattern": "[^:\\\\\\n]+", - "default": "Ctrl Shift ~Alt C" - }, - "paste-binding": { - "type": "string", - "description": "The key combination that pastes the clipboard, in X translation syntax: Ctrl Shift ~Alt V, the pair of copy-binding. It holds no colon, backslash or line break, which would end the resource.", - "pattern": "[^:\\\\\\n]+", - "default": "Ctrl Shift ~Alt V" - } - }, - "items": [ - { - "collection": "environment", - "name": "terminal", - "attributes": { - "kind": "variable", - "name": "TERMINAL" - }, - "template": "files/env-terminal" - }, - { - "collection": "shell:xresources:normal", - "name": "xresources-normal", - "template": "files/xresources-normal" - } - ], - "resources": [ - { - "id": "package", - "type": "package", - "package": "xterm" - } - ], - "build": { - "artifacts": [ - { - "name": "tools", - "kind": "bundle", - "language": "go", - "system": "arch", - "from": "cmd/xterm-tools", - "binary": "xterm-tools", - "loads": [ - "xterm-tools" - ] - }, - { - "name": "files", - "kind": "archive", - "from": "files" - } - ] - } -} diff --git a/modules/mesh-delivery-checker/cmd/mesh-delivery-checker/toolchains.go b/modules/mesh-delivery-checker/cmd/mesh-delivery-checker/toolchains.go deleted file mode 100644 index 65f4643c..00000000 --- a/modules/mesh-delivery-checker/cmd/mesh-delivery-checker/toolchains.go +++ /dev/null @@ -1,108 +0,0 @@ -package main - -import ( - "context" - "errors" - "fmt" - "log" - "strings" - "sync" - - "git.novox.be/novox/mesh-sdk/go/process" - - "github.com/nats-io/nats.go/jetstream" - - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-builder/buildrun" -) - -// toolchainWatch keeps the build modules' toolchains in a buildrun.ToolchainSet and tells the builder when one changed. A -// build module's bucket is made when it is assigned, after the builder started, and the builder holds no timer (ADR 0437 -// §8): it watches the buckets that exist at start, and a build module says each time it wrote its toolchains key -// (toolchain.reported, handled by Reported); a bucket not watched yet is then watched. -type toolchainWatch struct { - ctx context.Context - js bucketOpener - seats *buildrun.BuildSeats // the build modules: the holders of the build seats (design 47 G A-82) - set *buildrun.ToolchainSet - // put takes a change of a toolchains bucket in: set.Put, or the gate of the assigned build nodes before it (issue 1940). - put func(module, key string, value []byte, deleted bool) bool - changed func(ctx context.Context) // a language's entries changed: the failed builds are tried again - logger *log.Logger - errs chan error - mu sync.Mutex - watched map[string]bool -} - -func newToolchainWatch(ctx context.Context, js bucketOpener, seats *buildrun.BuildSeats, set *buildrun.ToolchainSet, changed func(context.Context), logger *log.Logger) *toolchainWatch { - return &toolchainWatch{ctx: ctx, js: js, seats: seats, set: set, put: set.Put, changed: changed, logger: logger, errs: make(chan error, 16), watched: map[string]bool{}} -} - -// start watches the buckets that exist now; a missing one is said and waits for its build module's event. -func (w *toolchainWatch) start() error { - for _, module := range w.seats.Modules() { - if err := w.ensure(module); err != nil { - return err - } - } - return nil -} - -func (w *toolchainWatch) ensure(module string) error { - w.mu.Lock() - defer w.mu.Unlock() - if w.watched[module] { - return nil - } - name := buildrun.ToolchainsBucket(module) - kv, err := w.js.KeyValue(w.ctx, name) - switch { - case errors.Is(err, jetstream.ErrBucketNotFound): - w.logger.Printf("the bucket %s does not exist yet: it is watched when %s reports a toolchain", name, module) - return nil - case err != nil: - // Refused or not answered (its grant not on the bus yet, issue 1945): said, and opened again at the module's next report. - w.logger.Printf("the bucket %s cannot be read (%v): %s's toolchains are not heard until its next report", name, err, module) - return nil - } - watcher, err := settle(w.ctx, kv, func(e jetstream.KeyValueEntry) { w.put(module, e.Key(), e.Value(), !opOf(e)) }) - if err != nil { - process.NotWatched(w.logger.Printf, name, err, fmt.Sprintf("%s's toolchains are not heard until its next report", module)) - return nil - } - w.watched[module] = true - go func() { - w.errs <- follow(w.ctx, watcher, func(e jetstream.KeyValueEntry) { - if w.put(module, e.Key(), e.Value(), !opOf(e)) { - w.changed(w.ctx) - } - }) - }() - w.changed(w.ctx) // what the settle read is new to the builder - return nil -} - -// delivered is the part of a JetStream message the watch uses. -type delivered interface { - Subject() string - Ack() error - Term() error -} - -// Reported takes one toolchain-reported event of a build seat in: the seat is read off the subject, -// mesh.seat..event.toolchain-reported., and the bucket of its holder is watched if it is not. A subject of no build -// seat with a holder is terminated; a failure stays unacknowledged, and the server delivers it again. -func (w *toolchainWatch) Reported(m delivered) { - seat, _, _ := strings.Cut(strings.TrimPrefix(m.Subject(), "mesh.seat."), ".event.") - bm, known := w.seats.OfSeat(seat) - module := bm.Module - if !known || module == "" || bm.Toolchain == "" || !strings.HasPrefix(m.Subject(), "mesh.seat.") { - w.logger.Printf("%s: not the event of a build seat with a holder, dropped", m.Subject()) - _ = m.Term() - return - } - if err := w.ensure(module); err != nil { - w.logger.Printf("%s: left for redelivery: %v", m.Subject(), err) - return - } - _ = m.Ack() -} diff --git a/modules/mesh-delivery-checker/cmd/mesh-delivery-checker/trunk.go b/modules/mesh-delivery-checker/cmd/mesh-delivery-checker/trunk.go deleted file mode 100644 index 4cbc5466..00000000 --- a/modules/mesh-delivery-checker/cmd/mesh-delivery-checker/trunk.go +++ /dev/null @@ -1,57 +0,0 @@ -package main - -import ( - "context" - "encoding/json" - "fmt" - - "github.com/nats-io/nats.go/jetstream" - - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog" - - "mesh-delivery-checker/internal/check" -) - -// The checker takes the trunk heads a check merges onto from the catalog half (design 47 G §197), never from the gate's state -// `source`: a first view by the seat mesh-catalog's verb `revision`, which carries the trunk head of every repository, then -// the seat's event `catalog-revision` of a trunk revision, each read again by the verb. - -// readTrunks asks the catalog half's newest trunk revision and sets the heads it carries. It says whether they changed. A -// candidate's revision, or an answer that does not read, changes nothing. -func readTrunks(ask func(string, any) (json.RawMessage, error), trunks *check.Trunks) (bool, error) { - raw, err := ask(check.TrunkVerb, meshcatalog.RevisionInput{}) - if err != nil { - return false, fmt.Errorf("the catalog half's revision cannot be read: %w", err) - } - heads, err := check.TrunkHeads(raw) - if err != nil { - return false, err - } - return trunks.Set(heads), nil -} - -// followTrunks reads the first view and then follows `catalog-revision`: a trunk revision's event reads the heads again, and a -// change of them is the trunk moving (statuses go pending, a verdict for the old trunk is judged again). A read that fails is -// said, and made again at the next event. -func followTrunks(hub interface { - Handle(string, func(jetstream.Msg)) error -}, ask func(string, any) (json.RawMessage, error), trunks *check.Trunks, moved func(context.Context), logf func(string, ...any)) (first func(context.Context), err error) { - run := func(ctx context.Context) { - changed, err := readTrunks(ask, trunks) - if err != nil { - logf("no trunk is known until the catalog half answers, so nothing is checked: %v", err) - return - } - if changed { - moved(ctx) - } - } - err = hub.Handle(meshcatalog.SubjectCatalogRevisionAll, func(m jetstream.Msg) { - var e meshcatalog.CatalogRevisionEvent - if json.Unmarshal(m.Data(), &e) == nil && e.Kind == "trunk" { - run(context.Background()) - } - _ = m.Ack() - }) - return run, err -} diff --git a/modules/mesh-delivery-checker/cmd/mesh-delivery-checker/trunk_test.go b/modules/mesh-delivery-checker/cmd/mesh-delivery-checker/trunk_test.go deleted file mode 100644 index 611824a6..00000000 --- a/modules/mesh-delivery-checker/cmd/mesh-delivery-checker/trunk_test.go +++ /dev/null @@ -1,38 +0,0 @@ -package main - -import ( - "encoding/json" - "errors" - "testing" - - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog" - - "mesh-delivery-checker/internal/check" -) - -// design 47 G §197: the trunk heads come from the catalog half's trunk revision, by the seat verb revision, and never from the -// gate's source; a candidate's revision and an unanswered verb change nothing. -func TestTrunkHeadsComeFromTheCatalogHalf(t *testing.T) { - answer := func(kind string, heads ...meshcatalog.Head) func(string, any) (json.RawMessage, error) { - return func(key string, _ any) (json.RawMessage, error) { - if key != "seat:mesh-catalog.revision" { - t.Fatalf("asked %s", key) - } - return json.Marshal(meshcatalog.RevisionAnswer{Revision: &meshcatalog.CatalogRevision{Kind: kind, Trunk: heads}}) - } - } - trunks := &check.Trunks{} - h := meshcatalog.Head{Repository: "r", Commit: "c1"} - if changed, err := readTrunks(answer("trunk", h), trunks); err != nil || !changed || trunks.Heads()["r"] != "c1" { - t.Fatalf("first view: %v %v %v", changed, err, trunks.Heads()) - } - if changed, _ := readTrunks(answer("trunk", h), trunks); changed { - t.Fatal("the same heads moved the trunk") - } - if _, err := readTrunks(answer("candidate", meshcatalog.Head{Repository: "r", Commit: "c2"}), trunks); err == nil || trunks.Heads()["r"] != "c1" { - t.Fatalf("a candidate's revision: %v %v", err, trunks.Heads()) - } - if _, err := readTrunks(func(string, any) (json.RawMessage, error) { return nil, errors.New("down") }, trunks); err == nil || trunks.Heads()["r"] != "c1" { - t.Fatalf("an unanswered verb: %v %v", err, trunks.Heads()) - } -} diff --git a/modules/mesh-delivery-checker/cmd/mesh-delivery-checker/try_candidates.go b/modules/mesh-delivery-checker/cmd/mesh-delivery-checker/try_candidates.go deleted file mode 100644 index 02120bb6..00000000 --- a/modules/mesh-delivery-checker/cmd/mesh-delivery-checker/try_candidates.go +++ /dev/null @@ -1,70 +0,0 @@ -package main - -import ( - "context" - "fmt" - "time" - - "github.com/nats-io/nats.go/jetstream" - - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog" - - "mesh-delivery-checker/internal/check" -) - -// tryCandidates answers the indexer's candidate of a try's group (novox/hq ADR 0593 §7, issue 1921): the candidate the -// engines compose and the manifest validator judges, which the indexer makes of the try's previews. It waits for it on the -// key's own watch, with no timer between reads, and gives up at the bound. -type tryCandidates struct{ kv jetstream.KeyValue } - -func (t tryCandidates) TryCandidate(ctx context.Context, group, heads string, bound time.Duration) (meshcatalog.CandidatesByGroupValue, error) { - key, err := meshcatalogclient.CandidatesKey(group) - if err != nil { - return meshcatalog.CandidatesByGroupValue{}, err - } - if bound <= 0 { - bound = time.Minute - } - waiting, cancel := context.WithTimeout(ctx, bound) - defer cancel() - w, err := t.kv.Watch(waiting, key) // the value now, then each change - if err != nil { - return meshcatalog.CandidatesByGroupValue{}, fmt.Errorf("the indexer's candidate %s cannot be watched: %w", key, err) - } - defer func() { _ = w.Stop() }() - last := "the indexer holds none" - for { - select { - case <-waiting.Done(): - return meshcatalog.CandidatesByGroupValue{}, fmt.Errorf("the indexer wrote no candidate of %s at heads %s within %s (%s)", group, heads, bound, last) - case e := <-w.Updates(): - if e == nil || e.Operation() != jetstream.KeyValuePut { - continue - } - c, err := meshcatalog.DecodeCandidatesByGroupValue(e.Value()) - switch { - case err != nil: - last = "what it holds is not a candidate: " + err.Error() - case c.Heads != heads: - last = "it holds heads " + c.Heads - case waitsOnPreview(c): - last = "it has not yet the merge previews' fingerprints" - default: - return c, nil - } - } - } -} - -// waitsOnPreview says a module of the candidate has no fingerprint yet because its preview was not read. -func waitsOnPreview(c meshcatalog.CandidatesByGroupValue) bool { - for _, p := range c.Pulls { - for _, m := range p.Fps { - if check.WaitsOnPreview(m) { - return true - } - } - } - return false -} diff --git a/modules/mesh-delivery-checker/cmd/mesh-delivery-checker/verdictsay.go b/modules/mesh-delivery-checker/cmd/mesh-delivery-checker/verdictsay.go deleted file mode 100644 index 7a1319bd..00000000 --- a/modules/mesh-delivery-checker/cmd/mesh-delivery-checker/verdictsay.go +++ /dev/null @@ -1,43 +0,0 @@ -package main - -import ( - "context" - "crypto/sha256" - "encoding/json" - "fmt" - "strings" - "time" - - "github.com/nats-io/nats.go" - "github.com/nats-io/nats.go/jetstream" - - "mesh-delivery-checker/internal/check" -) - -// verdictSays is check.VerdictSayer on the bus: verdict published on the checker's own stream asks. -type verdictSays struct { - // module is the checker's own, the credential's: the stream of its events and their source. - module string - js jetstream.JetStream - node string - now func() time.Time -} - -// Say publishes one verdict on the checker's own stream asks with the checker's event headers; the message id makes a -// second publish of the same pull request's head, verdict and out-of-step files within the duplicate window one event. -func (t verdictSays) Say(ctx context.Context, v check.VerdictEvent) error { - body, err := json.Marshal(v) - if err != nil { - return err - } - msg := nats.NewMsg(eventSubject(t.module, check.EventVerdict)) - id := fmt.Sprintf("verdict.%s.%d.%s.%s.%x", v.Repository, v.Pull, v.Head, v.Verdict, sha256.Sum256([]byte(strings.Join(v.OutOfStep, "\n")))) - msg.Header.Set("x-event-id", id) - msg.Header.Set("x-source", t.module) - msg.Header.Set("x-node", t.node) - msg.Header.Set("x-time", t.now().UTC().Format(time.RFC3339Nano)) - msg.Header.Set("content-type", "application/json") - msg.Data = body - _, err = t.js.PublishMsg(ctx, msg, jetstream.WithMsgID(id)) - return err -} diff --git a/modules/mesh-delivery-checker/files/settings.json b/modules/mesh-delivery-checker/files/settings.json deleted file mode 100644 index c6d811e8..00000000 --- a/modules/mesh-delivery-checker/files/settings.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "compose-answer-bound": 60, - "build-wait-bound": 1800 -} diff --git a/modules/mesh-delivery-checker/go.mod b/modules/mesh-delivery-checker/go.mod deleted file mode 100644 index c86ebab1..00000000 --- a/modules/mesh-delivery-checker/go.mod +++ /dev/null @@ -1,67 +0,0 @@ -module mesh-delivery-checker - -go 1.26.0 - -require ( - git.novox.be/novox/mesh-contracts/go/clients/meshmoduleassignerclient v0.0.0-00010101000000-000000000000 - git.novox.be/novox/mesh-contracts/go/seats/meshmoduleassigner v0.0.0-00010101000000-000000000000 - git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshhandactsclient v0.0.0-00010101000000-000000000000 - git.novox.be/novox/mesh-contracts/health-and-repair/go/seats/meshwatchdogs v0.0.0-00010101000000-000000000000 - git.novox.be/novox/mesh-delivery/modules/mesh-delivery-builder/builds v0.0.0-00010101000000-000000000000 - git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient v0.0.0-00010101000000-000000000000 - git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshdeliverycheckerclient v0.0.0-00010101000000-000000000000 - git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshdeliveryclient v0.0.0-00010101000000-000000000000 - git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/git v0.0.0-00010101000000-000000000000 - git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog v0.0.0-00010101000000-000000000000 - git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshdelivery v0.0.0-00010101000000-000000000000 - git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshdeliverychecker v0.0.0-00010101000000-000000000000 - git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshwants v0.0.0-00010101000000-000000000000 - git.novox.be/novox/mesh-sdk/go v0.0.0-00010101000000-000000000000 - github.com/nats-io/nats-server/v2 v2.11.17 - github.com/nats-io/nats.go v1.54.0 -) - -require ( - git.novox.be/novox/mesh-contracts/go/clients/nodeengineclient v0.0.0-00010101000000-000000000000 - git.novox.be/novox/mesh-contracts/go/seats/meshconfig v0.0.0-00010101000000-000000000000 - git.novox.be/novox/mesh-contracts/go/seats/nodeengine v0.0.0-00010101000000-000000000000 - git.novox.be/novox/mesh-delivery/modules/mesh-delivery-builder/buildrun v0.0.0-00010101000000-000000000000 - github.com/antithesishq/antithesis-sdk-go v0.8.0-default-no-op // indirect - github.com/google/go-tpm v0.9.8 // indirect - github.com/klauspost/compress v1.20.1 // indirect - github.com/minio/highwayhash v1.0.4 // indirect - github.com/nats-io/jwt/v2 v2.8.2 // indirect - github.com/nats-io/nkeys v0.4.16 // indirect - github.com/nats-io/nuid v1.0.1 // indirect - golang.org/x/crypto v0.57.0 // indirect - golang.org/x/sys v0.48.0 // indirect - golang.org/x/time v0.16.0 // indirect -) - -require ( - git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshwantsclient v0.0.0-00010101000000-000000000000 // indirect - git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/gopackageregistry v0.0.0-00010101000000-000000000000 // indirect - git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/nodebuildgo v0.0.0-00010101000000-000000000000 // indirect - git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/npmpackageregistry v0.0.0-00010101000000-000000000000 // indirect -) - -replace git.novox.be/novox/mesh-delivery/modules/mesh-delivery-builder/buildrun => ../mesh-delivery-builder/buildrun - -require git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk v0.0.0-00010101000000-000000000000 - -require git.novox.be/novox/mesh-delivery/modules/mesh-delivery-checker/checkermsg v0.0.0-00010101000000-000000000000 - -replace git.novox.be/novox/mesh-delivery/modules/mesh-delivery-checker/checkermsg => ./checkermsg - -replace git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk => ../mesh-delivery-sdk - -require ( - git.novox.be/novox/mesh-contracts/health-and-repair/go/seats/meshconditions v0.0.0-00010101000000-000000000000 - git.novox.be/novox/mesh-contracts/health-and-repair/go/seats/meshhandacts v0.0.0-00010101000000-000000000000 // indirect - git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/containerimageregistryclient v0.0.0-00010101000000-000000000000 // indirect - git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/gopackageregistryclient v0.0.0-00010101000000-000000000000 // indirect - git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/npmpackageregistryclient v0.0.0-00010101000000-000000000000 // indirect - git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/ociartifactregistryclient v0.0.0-00010101000000-000000000000 // indirect - git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/containerimageregistry v0.0.0-00010101000000-000000000000 // indirect - git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/ociartifactregistry v0.0.0-00010101000000-000000000000 // indirect -) diff --git a/modules/mesh-delivery-checker/go.sum b/modules/mesh-delivery-checker/go.sum deleted file mode 100644 index 8ca93dfd..00000000 --- a/modules/mesh-delivery-checker/go.sum +++ /dev/null @@ -1,25 +0,0 @@ -github.com/antithesishq/antithesis-sdk-go v0.8.0-default-no-op h1:1BOWQJweNyvZMlpAHXGLiZQn9S+QXGcz3xh94lC0w6E= -github.com/antithesishq/antithesis-sdk-go v0.8.0-default-no-op/go.mod h1:FQyySiasQQM8735Ddel3MRojmy4dA1IqCeyJ5jmPMbI= -github.com/google/go-tpm v0.9.8 h1:slArAR9Ft+1ybZu0lBwpSmpwhRXaa85hWtMinMyRAWo= -github.com/google/go-tpm v0.9.8/go.mod h1:h9jEsEECg7gtLis0upRBQU+GhYVH6jMjrFxI8u6bVUY= -github.com/klauspost/compress v1.20.1 h1:T7kKElXUMXrUJ2E9QhQhxFtcK5rPyLdsGZvdbLMPdiQ= -github.com/klauspost/compress v1.20.1/go.mod h1:LUdAzn7YLVvxLpc7y3V1m40wESHTgc1422pwwBSKYuI= -github.com/minio/highwayhash v1.0.4 h1:asJizugGgchQod2ja9NJlGOWq4s7KsAWr5XUc9Clgl4= -github.com/minio/highwayhash v1.0.4/go.mod h1:GGYsuwP/fPD6Y9hMiXuapVvlIUEhFhMTh0rxU3ik1LQ= -github.com/nats-io/jwt/v2 v2.8.2 h1:XXRgB60MSTnqsRwejQurVDs/hcv2dkt+86GjI+I/bMc= -github.com/nats-io/jwt/v2 v2.8.2/go.mod h1:Ag/56sq9OblL4JgdYufDd16Egb17Kr/8WwwuO/forVc= -github.com/nats-io/nats-server/v2 v2.11.17 h1:GKEghcFK6A+aFx11Yf1LjgLC3txAwvyhnYzhBIQZA8I= -github.com/nats-io/nats-server/v2 v2.11.17/go.mod h1:B1sFVz4StNosQ903ak4N1G01Fl/9f8e06mXpFIE2K24= -github.com/nats-io/nats.go v1.54.0 h1:vsXoOxjHp/GmPUN+EcI7uOf/uB+iAP+kEsAFNQN0yzA= -github.com/nats-io/nats.go v1.54.0/go.mod h1:y+DZoD1oBOYfZTU681eTUiUjI0vbqYGixNVFHcjHJ0k= -github.com/nats-io/nkeys v0.4.16 h1:rd5oAuLOb8mnAycB0xleuEBNS1pVVnN0fv/FF34Eypg= -github.com/nats-io/nkeys v0.4.16/go.mod h1:llLgWoI0o4z/Q57q2R1kHfmocyhGV6VG/U18Glg1Afs= -github.com/nats-io/nuid v1.0.1 h1:5iA8DT8V7q8WK2EScv2padNa/rTESc1KdnPw4TC2paw= -github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c= -golang.org/x/crypto v0.57.0 h1:3ZVCjf8Ggz7zneR/EHRVx68Ctf+2pmIMP2UFhh9cC6M= -golang.org/x/crypto v0.57.0/go.mod h1:Fdz0i5U6CoizGwLda9DttjSk6qlZo25zYNtR+ycvuZA= -golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/sys v0.48.0 h1:bbX/i/6MgT9BVLM9RT1thmxL04yeTAhbEz4SyadbXoo= -golang.org/x/sys v0.48.0/go.mod h1:hNLxWAXmnKAxqDtdwIYC4bM9oQPEecfsnNMuSxOs3og= -golang.org/x/time v0.16.0 h1:vMb6ptszcQMkcwiRTAuNNU50gom6++Q/6gY2hDM6VDE= -golang.org/x/time v0.16.0/go.mod h1:rVKOqvZeKvrDKTQiAHJ7wmwP0RzleSphoEA9RcdLA0s= diff --git a/modules/mesh-delivery-checker/internal/check/adr548_test.go b/modules/mesh-delivery-checker/internal/check/adr548_test.go deleted file mode 100644 index 10f18b30..00000000 --- a/modules/mesh-delivery-checker/internal/check/adr548_test.go +++ /dev/null @@ -1,279 +0,0 @@ -package check - -import ( - "context" - "strings" - "testing" - "time" - - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshdeliverycheckerclient" - "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/meshdeliverychecker" -) - -// One check per delivery (novox/hq ADR 0548): the checker's part. A merge turn holds new checks off its repository (§3); -// a trunk or sibling move never ends a running check and carries its verdict once it ended (§1, §5, §6); only a head git -// refused gets a whole check after a move (§7); the line of a carried verdict says so (§8). - -// waitFor polls a condition the checker's goroutines make true, failing after ten seconds: a bound a loaded machine does -// not reach, waited out only by a failing test. -func waitFor(t testing.TB, what string, ok func() bool) { - t.Helper() - for deadline := time.Now().Add(10 * time.Second); !ok(); time.Sleep(time.Millisecond) { - if time.Now().After(deadline) { - t.Fatalf("%s did not happen", what) - } - } -} - -// pullWithFP is a pull request touching the module m at the fingerprint `src2:` and 64 times the hex digit d. -func pullWithFP(repo string, number int, head string, d string) meshcatalog.CandidatesByGroupValuePullsItem { - p := pullOf(repo, number, head) - p.Modules = []string{"m"} - p.Fps = map[string]meshcatalog.CandidatesByGroupValuePullsItemFpsValue{"m": {Fp2: "src2:" + strings.Repeat(d, 64)}} - return p -} - -func TestOneCheckPerDelivery(t *testing.T) { - ctx := context.Background() - for name, run := range map[string]func(t *testing.T){ - // Design 47 G §278 (test 52): a new check is claimed at once; the checker reads no state of the gate, so no merge turn holds it. - "a new check is claimed at once": func(t *testing.T) { - j := passJudge() - r := newRig(t, j) - cand := candidateOf(t, "feat/x", pullOf(repoA, 7, head1)) - r.ch.Candidate(ctx, "feat%2Fx", cand) - r.ch.Wait() - if j.count() != 1 || r.verdict(t, keyOf(t, "feat/x", cand)).State != meshdeliverycheckerclient.VerdictPass { - t.Errorf("judged %d times, want once at once", j.count()) - } - }, - // §1, §5: a trunk move during a running check calls the judge once, writes its verdict, keeps the status pending (a pass - // on an old trunk is never shown), then asks one carry, on the recheck stream, and no check. - "a trunk move during a check ends nothing and asks one carry after it": func(t *testing.T) { - var r *rig - var kinds []string - var from []map[string]string - judged := make(chan struct{}) - j := &judgeFunc{f: func(ctx context.Context, c *Case, call int) (Outcome, error) { - kinds, from = append(kinds, c.Kind), append(from, c.CarriedFrom) - if call == 1 { - r.setTrunks(t, map[string]string{repoA: trunkA2, repoSDK: trunkS}) // the trunk moves while it runs - r.ch.TrunkMoved(ctx) // as the watch of the source says it - close(judged) - } else if s := owedState(t, r, repoA, 7, head1); s != "pending" { - t.Errorf("the status during the carry is %q, want pending: the pass on the old trunk is never shown", s) - } - return Outcome{Verdict: passing()}, nil - }} - r = newRig(t, j) - cand := candidateOf(t, "feat/x", pullOf(repoA, 7, head1)) - r.ch.Candidate(ctx, "feat%2Fx", cand) - <-judged - r.ch.Wait() - v := r.verdict(t, keyOf(t, "feat/x", cand)) - if j.count() != 2 || kinds[0] != KindNew || kinds[1] != KindTrunk || from[0] != nil || from[1][repoA] != trunkA { - t.Fatalf("judged %d times as %v carried from %v; want a whole check, then one carry from %s", j.count(), kinds, from, trunkA[:12]) - } - if v.State != meshdeliverycheckerclient.VerdictPass || v.Trunk[repoA] != trunkA2 || v.CarriedFrom[repoA] != trunkA { - t.Errorf("the verdict is %s on %v carried from %v; want a pass on the new trunk carried from the old", v.State, v.Trunk, v.CarriedFrom) - } - if s := owedState(t, r, repoA, 7, head1); s != "success" { - t.Errorf("the status after the carry is %q, want success", s) - } - if r.verdicts.creates[keyOf(t, "feat/x", cand)] != 1 { - t.Error("the verdict key was made again: a carry rewrites it") - } - }, - // §5: the composition is kept when no fingerprint of a module it composed changed, and runs again otherwise. - "a carry keeps a passed composition while the fingerprints stay the same": func(t *testing.T) { - var kept []bool - j := &judgeFunc{f: func(_ context.Context, c *Case, _ int) (Outcome, error) { - kept = append(kept, c.Composition != nil) - v := passing() - v.Composition = &meshdeliverychecker.VerdictsByGroupHeadsValueComposition{State: meshdeliverycheckerclient.CompositionPass, Sdk: "v0.1.14-x", Fpset: c.FPSet} - return Outcome{Verdict: v}, nil - }} - r := newRig(t, j) - cand := candidateOf(t, "feat/x", pullWithFP(repoA, 7, head1, "a")) - r.ch.Candidate(ctx, "feat%2Fx", cand) - r.ch.Wait() - r.setTrunks(t, map[string]string{repoA: trunkA2, repoSDK: trunkS}) - r.ch.TrunkMoved(ctx) // the indexer's fingerprints of the candidate stay the same - r.ch.Wait() - r.ch.Candidate(ctx, "feat%2Fx", candidateOf(t, "feat/x", pullWithFP(repoA, 7, head1, "b"))) // a fingerprint changed with the move - r.setTrunks(t, map[string]string{repoA: trunkA, repoSDK: trunkS}) - r.ch.TrunkMoved(ctx) - r.ch.Wait() - if len(kept) != 3 || kept[0] || !kept[1] || kept[2] { - t.Errorf("the composition was kept in the checks %v; want composed, kept on the carry, composed again once a fingerprint changed", kept) - } - }, - // §6: a sibling's move puts the verdict out of date, its status pending saying it is carried, and the carry's verdict - // names the sibling's old commit; the status follows the carry's verdict. Which packages run is the digest's (only - // those that name MESH_CHECK_BESIDE change with a sibling), the build module's part. - "a sibling's move is carried and the status follows the carry": func(t *testing.T) { - var r *rig - var from map[string]string - j := &judgeFunc{f: func(_ context.Context, c *Case, call int) (Outcome, error) { - if call == 2 { - from = c.CarriedFrom - if s := owedState(t, r, repoA, 7, head1); s != "pending" { - t.Errorf("the status during the sibling's carry is %q, want pending", s) - } - } - return Outcome{Verdict: passing(), Beside: map[string]string{catalogueRepository: r.trunks.Heads()[catalogueRepository]}}, nil - }} - r = newRig(t, j) - r.setTrunks(t, map[string]string{repoA: trunkA, repoSDK: trunkS, catalogueRepository: trunkS}) - cand := candidateOf(t, "feat/x", pullOf(repoA, 7, head1)) - r.ch.Candidate(ctx, "feat%2Fx", cand) - r.ch.Wait() - if b := r.verdict(t, keyOf(t, "feat/x", cand)).Beside; b[catalogueRepository] != trunkS { - t.Fatalf("the verdict names the siblings %v, want the catalogue at %s", b, trunkS[:12]) - } - r.setTrunks(t, map[string]string{repoA: trunkA, repoSDK: trunkS, catalogueRepository: trunkS2}) - r.ch.TrunkMoved(ctx) - r.ch.Wait() - v := r.verdict(t, keyOf(t, "feat/x", cand)) - if j.count() != 2 || from[catalogueRepository] != trunkS || v.CarriedFrom[catalogueRepository] != trunkS || v.Beside[catalogueRepository] != trunkS2 { - t.Errorf("judged %d times, carried from %v, verdict beside %v carried from %v; want one carry over the catalogue's move", j.count(), from, v.Beside, v.CarriedFrom) - } - if s := owedState(t, r, repoA, 7, head1); s != "success" { - t.Errorf("the status after the carry is %q, want success", s) - } - }, - // §7: a carry whose merge conflicts fails naming the files and asks no check; a later move onto which the head merges - // cleanly asks a whole check, not a carry. - "a carry git refuses fails naming the files, and the next move asks a whole check": func(t *testing.T) { - var kinds []string - var from []map[string]string - j := &judgeFunc{f: func(_ context.Context, c *Case, call int) (Outcome, error) { - kinds, from = append(kinds, c.Kind), append(from, c.CarriedFrom) - if call == 2 { - return Outcome{Verdict: meshdeliverychecker.VerdictsByGroupHeadsValue{State: meshdeliverycheckerclient.VerdictFail, Failed: &FailedFirst{Machine: "ace", - Words: repoA + "#7 " + ConflictWords + "go.mod"}}}, nil - } - return Outcome{Verdict: passing()}, nil - }} - r := newRig(t, j) - cand := candidateOf(t, "feat/x", pullOf(repoA, 7, head1)) - r.ch.Candidate(ctx, "feat%2Fx", cand) - r.ch.Wait() - r.setTrunks(t, map[string]string{repoA: trunkA2, repoSDK: trunkS}) - r.ch.TrunkMoved(ctx) - r.ch.Wait() - r.ch.Reconsider(ctx) // anything else that looks again asks nothing of a conflict - r.ch.Wait() - if v := r.verdict(t, keyOf(t, "feat/x", cand)); j.count() != 2 || !IsConflictFailure(v) || !strings.Contains(v.Failed.Words, "go.mod") { - t.Fatalf("judged %d times, verdict %+v; want the carry failed naming go.mod and nothing asked after it", j.count(), v.Failed) - } - r.setTrunks(t, map[string]string{repoA: trunkA, repoSDK: trunkS}) - r.ch.TrunkMoved(ctx) - r.ch.Wait() - if j.count() != 3 || kinds[1] != KindTrunk || from[1] == nil || kinds[2] != KindNew || from[2] != nil { - t.Errorf("checks %v carried from %v; want a whole check, a carry, then a whole check after the conflict", kinds, from) - } - }, - // §8, §6: the line of a carried verdict names the head on the new trunk commit first, as the gate and the merge tool - // read a line, then where it was carried from and what the carry ran and kept; while it is carried it is pending and says so. - "the line of a carry says where it was carried from": func(t *testing.T) { - cs, p := lineCase(t, pullOf(repoA, 7, head1)) - v := passVerdict() - v.Trunk = map[string]string{repoA: trunkA} - v.Beside = map[string]string{catalogueRepository: trunkS2} - v.CarriedFrom = map[string]string{repoA: trunkA2, catalogueRepository: trunkS} - line := Line(v, cs, p, nil, nil, nil) - if !strings.HasPrefix(line, "pass 111111111111 on aaaaaaaaaaaa | carried from abababababab, mesh-catalog 555555555555 | unit 12 run") { - t.Errorf("the carried line = %q", line) - } - if head, trunk := checkWordsOf(line); head != head1[:12] || trunk != trunkA[:12] { - t.Errorf("the line names %s on %s first, want the head on the new trunk", head, trunk) - } - cs.CarriedFrom = map[string]string{repoA: trunkA2} - pending := Line(meshdeliverychecker.VerdictsByGroupHeadsValue{State: meshdeliverycheckerclient.VerdictRunning}, cs, p, nil, nil, nil) - if !strings.HasPrefix(pending, "being carried to 111111111111 on aaaaaaaaaaaa | from abababababab") { - t.Errorf("the pending line of a carry = %q", pending) - } - }, - // §3 (review round 1): two approved merges in one turn whose trunk moved each get their carry; neither holds the other's. - "two merges waiting in one turn each get their carry": func(t *testing.T) { - var r *rig - j := &judgeFunc{f: func(context.Context, *Case, int) (Outcome, error) { return Outcome{Verdict: passing()}, nil }} - r = newRig(t, j) - candA, candC := candidateOf(t, "feat/a", pullOf(repoA, 7, head1)), candidateOf(t, "feat/c", pullOf(repoA, 8, head2)) - r.ch.Candidate(ctx, "feat%2Fa", candA) - r.ch.Candidate(ctx, "feat%2Fc", candC) - r.ch.Wait() - a, _ := meshcatalog.DecodeCandidatesByGroupValue(candA) - c, _ := meshcatalog.DecodeCandidatesByGroupValue(candC) - _, _ = a, c - r.setTrunks(t, map[string]string{repoA: trunkA2, repoSDK: trunkS}) // a third merge moves the trunk under both - r.ch.TrunkMoved(ctx) - r.ch.Wait() - for _, cand := range [][]byte{candA, candC} { - group := map[bool]string{true: "feat/a", false: "feat/c"}[string(cand) == string(candA)] - if v := r.verdict(t, keyOf(t, group, cand)); v.Trunk[repoA] != trunkA2 || v.CarriedFrom[repoA] != trunkA { - t.Errorf("%s: verdict on %v carried from %v; want its carry claimed and done", group, v.Trunk, v.CarriedFrom) - } - } - }, - // §6 (review round 1): the node-engine read at the commit the mesh runs is named, and a new running commit is carried. - "a new running node-engine is carried": func(t *testing.T) { - runs := runsAt{nodeEngineModule: trunkS} - j := &judgeFunc{f: func(_ context.Context, c *Case, _ int) (Outcome, error) { - return Outcome{Verdict: passing(), Beside: map[string]string{nodeEngineRepo: runs[nodeEngineModule]}}, nil - }} - r := newRig(t, j) - r.ch.Runs = runs - cand := candidateOf(t, "feat/x", pullOf(repoA, 7, head1)) - r.ch.Candidate(ctx, "feat%2Fx", cand) - r.ch.Wait() - r.ch.TrunkMoved(ctx) // nothing moved: nothing is carried - r.ch.Wait() - runs[nodeEngineModule] = trunkS2 - r.ch.TrunkMoved(ctx) // what the indexer's watch does when mesh-host's running commit changes - r.ch.Wait() - v := r.verdict(t, keyOf(t, "feat/x", cand)) - if j.count() != 2 || v.CarriedFrom[nodeEngineRepo] != trunkS || v.Beside[nodeEngineRepo] != trunkS2 { - t.Errorf("judged %d times, verdict beside %v carried from %v; want one carry over the node-engine's new running commit", j.count(), v.Beside, v.CarriedFrom) - } - }, - // §5: a carry that fails names the move it failed on. - "a carry that fails names the move": func(t *testing.T) { - j := &judgeFunc{f: func(_ context.Context, c *Case, call int) (Outcome, error) { - if call == 1 { - return Outcome{Verdict: passing()}, nil - } - return Outcome{Verdict: meshdeliverychecker.VerdictsByGroupHeadsValue{State: meshdeliverycheckerclient.VerdictFail, Failed: &FailedFirst{Test: "unit: m/a.TestX", Words: "want 4"}}}, nil - }} - r := newRig(t, j) - cand := candidateOf(t, "feat/x", pullOf(repoA, 7, head1)) - r.ch.Candidate(ctx, "feat%2Fx", cand) - r.ch.Wait() - r.setTrunks(t, map[string]string{repoA: trunkA2, repoSDK: trunkS}) - r.ch.TrunkMoved(ctx) - r.ch.Wait() - v := r.verdict(t, keyOf(t, "feat/x", cand)) - if v.State != meshdeliverycheckerclient.VerdictFail || v.CarriedFrom != nil || !strings.HasPrefix(v.Failed.Words, "want 4") || - !strings.Contains(v.Failed.Words, repoA+" "+trunkA[:12]+" to "+trunkA2[:12]) { - t.Errorf("the failed carry is %s carried from %v with words %q; want the test's words, then the move", v.State, v.CarriedFrom, v.Failed.Words) - } - }, - } { - t.Run(name, run) - } -} - -// checkWordsOf is the head and trunk a line names first, as the gate reads it (mesh-delivery-gate onestatus.go checkLine). -func checkWordsOf(line string) (string, string) { - for _, part := range strings.Split(line, " | ") { - f := strings.Fields(part) - for i := 0; i+2 < len(f); i++ { - if f[i+1] == "on" && len(f[i]) == 12 && len(f[i+2]) == 12 { - return f[i], f[i+2] - } - } - } - return "", "" -} diff --git a/modules/mesh-delivery-checker/internal/check/askagain.go b/modules/mesh-delivery-checker/internal/check/askagain.go deleted file mode 100644 index 9be3f0e6..00000000 --- a/modules/mesh-delivery-checker/internal/check/askagain.go +++ /dev/null @@ -1,277 +0,0 @@ -package check - -import ( - "context" - "encoding/json" - "errors" - "fmt" - "strings" - - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-builder/buildrun" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshdeliverycheckerclient" - "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/meshdeliverychecker" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep" -) - -// **A check is asked again by hand** (the lost check of 2026-10-28; tools-are-how-a-module-is-spoken-to: every recovery -// has a tool). checker_ask_again ends a candidate's running verdict, whose wait judged nothing, with AskedAgainWords and -// the why; the checker hears it on its watch of its verdicts (Checker.VerdictWritten), ends the check of those heads -// running in it, and claims and asks it anew, a whole check (IsEnded). It is refused while a step of the candidate's pull -// requests can still run (checker_status's running_steps): that step's end judges it; and while an ask the check put is -// still in its build seat's stream, taken by no node (it has no step key yet): asking again then would run the check twice -// (issue 1791's kind). The checker keeps the asks each running check put in its state asks (AsksState, by verdict key). -// An ask is not put again under its own id instead: the stream de-duplicates an id within its window, so the copy waiting -// stays and the new one is dropped, and past the window both would run; nothing takes a put ask back (buildrun.Asker). - -// AsksState is the checker's state of the asks each running check put, by verdict key (CheckAsks). -const ( - AsksState = "asks" -) - -// CheckAsks are the asks a check put, in order, as the state asks keeps them while it runs; its end deletes the key. -type CheckAsks struct { - Asks []string `json:"asks"` -} - -// AsksKV is the state asks: a KV whose key a check's end deletes, so the state holds only the checks that run. -type AsksKV interface { - KV - Delete(ctx context.Context, key string) error -} - -// forgetAsks deletes the asks a check put at its end; one that cannot be deleted is said, and the next check of the same -// heads writes the key anew. -func (ch *Checker) forgetAsks(ctx context.Context, key string) { - if err := ch.Asks.Delete(ctx, key); err != nil { - ch.logf("%s: the asks it put could not be forgotten at its end: %v", key, err) - } -} - -// recordAsks keeps the asks a check put under its verdict key; nil Asks keeps nothing. A record that cannot be written -// is said: checker_ask_again then refuses the check, as it cannot tell whether its ask waits in a stream. -func (ch *Checker) recordAsks(ctx context.Context, key string, asks []string) { - if ch.Asks == nil { - return - } - data, err := json.Marshal(CheckAsks{Asks: asks}) - if err == nil { - _, err = putOnce(ctx, ch.Asks, key, data, func(cur []byte) bool { return string(cur) == string(data) }) - } - if err != nil { - ch.logf("%s: the asks it put cannot be kept (%v), so %s refuses it", key, err, AskAgainTool) - } -} - -// AskAgainTool asks a candidate's check again by hand. -const AskAgainTool = "checker_ask_again" - -// AskedAgainWords open the words of a verdict AskAgainTool wrote; the why follows. -const AskedAgainWords = EndedWords + "asked again by hand (" + AskAgainTool + "): " - -// errAskedAgain is the cause a running check is ended with when its verdict was asked again by hand. -var errAskedAgain = buildrun.Withdrawn{Why: "its verdict was asked again by hand (" + AskAgainTool + ")"} - -// IsAskedAgain says whether a verdict was written by AskAgainTool. -func IsAskedAgain(v meshdeliverychecker.VerdictsByGroupHeadsValue) bool { - return IsEnded(v) && strings.HasPrefix(failedOf(v).Words, AskedAgainWords) -} - -// VerdictEntry is the verdicts state as the ask-again tool writes it: a key's value and revision (nil and 0 for none), -// and a compare-and-set. -type VerdictEntry interface { - Entry(key string) (json.RawMessage, uint64, error) - Update(key string, value []byte, revision uint64) error -} - -// AskedAgain is the answer of AskAgainTool. -type AskedAgain struct { - Key string `json:"key"` - Was string `json:"was"` - Said string `json:"said"` - Note string `json:"note"` -} - -// AskAgain ends the running verdict of the group's candidate as asked again by hand, saying why. It refuses a group with -// no candidate, a verdict that is not running (a pass stands, and a failure unless every failing step ended on a transport fault, ADR 0664; both stand until a push or a trunk move), one a step of -// whose pull requests can still run, and one whose asks are not known or one of which no node took yet. -func (r Reader) AskAgain(w VerdictEntry, group, why string) (AskedAgain, error) { - why = strings.TrimSpace(why) - if group == "" || why == "" { - return AskedAgain{}, fmt.Errorf("give the group and why it is asked again") - } - if w == nil { - return AskedAgain{}, fmt.Errorf("the verdicts state cannot be written here") - } - c, ok := r.candidate(group) - if !ok { - return AskedAgain{}, fmt.Errorf("no candidate is held for the group %q", group) - } - key, err := meshdeliverycheckerclient.VerdictKey(c.Group, c.Heads) - if err != nil { - return AskedAgain{}, err - } - raw, rev, err := w.Entry(key) - if err != nil { - return AskedAgain{}, fmt.Errorf("%s cannot be read: %w", key, err) - } - if len(raw) == 0 { - return AskedAgain{}, fmt.Errorf("%s holds no verdict: the checker claims its check when it looks at the candidate (%s)", key, StatusReadTool) - } - v, err := meshdeliverycheckerclient.DecodeVerdict(raw) - if err != nil { - return AskedAgain{}, fmt.Errorf("%s holds what is not a verdict: %w", key, err) - } - failed := v.State == meshdeliverycheckerclient.VerdictFail - if v.State != meshdeliverycheckerclient.VerdictRunning && !failed { - return AskedAgain{}, fmt.Errorf("%s is %s, not running: a verdict stands until a push or a trunk move asks it again", key, v.State) - } - steps := r.readSteps() - if failed { - // ADR 0664 (operator answer 5, issue 1748): a failure stands, except one whose failing steps all ended on a transport - // fault (a step written passing): the network failed, not the change, so it is asked again like a lost check. - if err := steps.onlyTransportFaults(c); err != nil { - return AskedAgain{}, fmt.Errorf("%s is fail, and a failure stands until a push or a trunk move asks it again, unless every failing step of it ended on a transport fault: %w", key, err) - } - } - for _, rs := range steps.running { - if asksOf(c, rs.What) { - return AskedAgain{}, fmt.Errorf("a step of it runs: %s %s on %s since %s (%s); its end judges it", rs.Module, rs.ID, rs.Node, rs.Since, rs.What) - } - } - if failed { - return r.askedAgain(w, key, rev, v, why) - } - if r.AskState.Get == nil { - return AskedAgain{}, fmt.Errorf("the checker's asks are not readable here, so whether its ask waits in a build seat's stream cannot be told") - } - kept, err := r.AskState.Get(key) - var put CheckAsks - if err == nil && len(kept) > 0 { - err = json.Unmarshal(kept, &put) - } - if err == nil && len(put.Asks) == 0 && r.Backlog != nil { - // Issue 1373: the checker names no ask, so the build seats' check streams are read: with no check ask waiting or held - // on any of them (and no step of the candidate running, above) none of it can run, and it is asked anew. - if err := r.noCheckAskWaits(); err != nil { - return AskedAgain{}, err - } - return r.askedAgain(w, key, rev, v, why) - } - if err != nil || len(put.Asks) == 0 { - return AskedAgain{}, fmt.Errorf("the checker names no ask of %s (%v), so whether one waits in a build seat's stream cannot be told; asking again could run it twice", key, err) - } - taken := map[string]bool{} - for _, s := range steps.all { - taken[s.step.ID] = true - } - for _, id := range put.Asks { - if !taken[id] { - return AskedAgain{}, fmt.Errorf("its ask %s waits in its build seat's stream, taken by no node yet: asking again would run it twice; "+ - "the seats' backlog is in mesh-delivery-view.build_usage", id) - } - } - return r.askedAgain(w, key, rev, v, why) -} - -// onlyTransportFaults is nil when the candidate's pull requests have a failed or refused step and every one of them ended -// passing (buildstep.Step.Passing); else why not. -func (s stepsRead) onlyTransportFaults(c meshcatalog.CandidatesByGroupValue) error { - n := 0 - for _, ms := range s.all { - st := ms.step - if !asksOf(c, st.What) || (st.State != buildstep.StepFailed && st.State != buildstep.StepRefused) { - continue - } - if !st.Passing { - return fmt.Errorf("its step %s on %s ended %s and not on a transport fault: %s", st.ID, st.Node, st.State, st.Reason) - } - n++ - } - if n == 0 { - return errors.New("no failed step of it is read (the newest keys of each build module's steps are)") - } - return nil -} - -// askedAgain writes the verdict v ended as asked again by hand, why saying so. -func (r Reader) askedAgain(w VerdictEntry, key string, rev uint64, v meshdeliverychecker.VerdictsByGroupHeadsValue, why string) (AskedAgain, error) { - words := AskedAgainWords + why - ended := meshdeliverychecker.VerdictsByGroupHeadsValue{Group: v.Group, Heads: v.Heads, Trunk: v.Trunk, State: meshdeliverycheckerclient.VerdictFail, - Failed: &FailedFirst{Machine: "checker", Words: words}} - data, err := meshdeliverycheckerclient.EncodeVerdict(ended) - if err != nil { - return AskedAgain{}, err - } - if err := w.Update(key, data, rev); err != nil { - return AskedAgain{}, fmt.Errorf("%s changed while it was asked again, so it was not; read it again: %w", key, err) - } - return AskedAgain{Key: key, Was: v.State, Said: words, - Note: "the checker hears it on its watch of its verdicts, ends the wait that judged nothing and asks the check anew, whole; " + - VerdictsReadTool + " shows it running again"}, nil -} - -// VerdictWritten takes a change of the checker's verdicts in (its watch, updates only): a verdict AskAgainTool wrote ends -// the check of those heads running in this process, which then considers them again; with none running, the candidate -// that holds them is considered at once. Any other verdict is the checker's own, and left. -func (ch *Checker) VerdictWritten(ctx context.Context, key string, value []byte) { - v, err := meshdeliverycheckerclient.DecodeVerdict(value) - if err != nil || !IsAskedAgain(v) { - return - } - ch.init() - ch.mu.Lock() - if l, ok := ch.live[key]; ok { - l.end(errAskedAgain) - ch.mu.Unlock() - ch.logf("%s: %s; the check running for it is ended and asked again", key, failedOf(v).Words) - return - } - var group string - var cand meshcatalog.CandidatesByGroupValue - for k, c := range ch.known { - if vk, err := meshdeliverycheckerclient.VerdictKey(c.Group, c.Heads); err == nil && vk == key { - group, cand = k, c - break - } - } - ch.mu.Unlock() - if group == "" { - ch.logf("%s: %s, but no candidate holds these heads, so nothing is asked", key, failedOf(v).Words) - return - } - ch.logf("%s: %s; asked again", key, failedOf(v).Words) - ch.consider(ctx, group, cand) -} - -// BacklogRow is a row of the build seats' backlog as mesh-delivery-view's build_usage answers it (its backlog): the asks -// waiting and held on one language's stream of one kind of ask, or why it could not be read. -type BacklogRow struct { - Language string `json:"language"` - Kind string `json:"kind"` - Waiting uint64 `json:"waiting"` - Held uint64 `json:"held"` - Error string `json:"error,omitempty"` -} - -// noCheckAskWaits is nil when no check or recheck ask waits or is held on any build seat's stream and every row was read; else it -// names the stream that holds asks. It cannot tell whose ask one is, so any check ask refuses: asking again could run it twice. -func (r Reader) noCheckAskWaits() error { - rows, err := r.Backlog() - if err != nil { - return fmt.Errorf("the build seats' streams cannot be read (%v), so whether an ask of the check waits in one cannot be told; asking again could run it twice", err) - } - for _, row := range rows { - if row.Kind != "check" && row.Kind != "recheck" { // both kinds are the checker's asks (judge.go) - continue - } - if row.Error != "" { - return fmt.Errorf("the %s build seat's check stream cannot be read (%s), so whether an ask of the check waits in it cannot be told", row.Language, row.Error) - } - if row.Waiting > 0 || row.Held > 0 { - return fmt.Errorf("the %s build seat's check stream holds asks (%d waiting, %d held), one of them may be the check's: asking again could run it twice; "+ - "the seats' backlog is in mesh-delivery-view.build_usage", row.Language, row.Waiting, row.Held) - } - } - return nil -} diff --git a/modules/mesh-delivery-checker/internal/check/beside.go b/modules/mesh-delivery-checker/internal/check/beside.go deleted file mode 100644 index 097d588b..00000000 --- a/modules/mesh-delivery-checker/internal/check/beside.go +++ /dev/null @@ -1,218 +0,0 @@ -package check - -import ( - "context" - "errors" - "fmt" - "slices" - "strconv" - "strings" - - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/trunk" -) - -// BesideRef is a sibling repository a repository's tests read, placed beside the fetched tree as a plain directory (ADR -// 0484 clause 4). Ref names the pull request's head when the commit is only there. -type BesideRef struct { - Repository string `json:"repository"` - Commit string `json:"commit"` - Ref string `json:"ref,omitempty"` - // atTrunk says the sibling was read at its trunk's head, so a move of that trunk puts the verdict out of date and is - // carried (novox/hq ADR 0548 §6). Never sent: the node-engine at the commit the mesh runs, mesh-sdk at a pin and a - // group's member at its head do not move with a trunk. - atTrunk bool - // runs says the sibling was read at the commit the mesh runs (the node-engine, the indexer's record of mesh-host): a new - // running commit puts the verdict out of date and is carried (ADR 0548 §6). Never sent. - runs bool -} - -// NodeEngineModule is the module whose running commit the node-engine sibling is read at. -const NodeEngineModule = nodeEngineModule - -const ( - catalogueRepository = "novox/mesh-catalog" - nodeEngineRepo = NodeEngineRepository - nodeEngineModule = "mesh-host" - // networkingRepository holds route-proxy, whose manifest the node-engine's proofs of a composition read. - networkingRepository = "novox/mesh-networking" - // contractsRepository and deliveryRepository hold the seat definitions mesh-sdk's bootstrapped seats are compared with: its - // tests read both beside it (beside.Dir "mesh-contracts" and "mesh-delivery"), at the group's head for a member, else at the - // trunk (a group try lays them out the same way: besideFor serves the check and the try). - contractsRepository = "novox/mesh-contracts" - deliveryRepository = DeliveryRepository -) - -// besideRules are the repositories each core repository's tests read, as the tests state it (mesh-sdk go/internal/beside -// beside.go): the catalogue, the node-engine, the SDK, and the delivery's pinned forge dependencies (mesh-catalog -// checks/deps). Which commit of each is besideCommit's rule. No repository's tests read the controller, which ended by its -// unassignment (novox/hq ADR 0590, issue 1126), and its repository is emptied and archived (ADR 0593 §11), so it has no -// siblings placed either. mesh-sdk reads mesh-contracts and mesh-delivery (its bootstrapped seats against their contracts files). The catalogue's tests read the node-engine since its composer command moved there (ADR 0593 -// §7): mesh-build-go builds it for a compose ask, and with it every repository its composer requires at the zero version -// (issue 1921: with mesh-sdk alone beside, that build looked them up on the network and failed): those are not named -// here but derived from each sibling's go.mod (zeroVersionSiblings), so no rule can lack one. The node-engine's read -// mesh-networking since route-proxy's proofs of a composition moved into them (ADR 0593). -var besideRules = map[string][]string{ - nodeEngineRepo: {catalogueRepository, SDKRepository, networkingRepository}, - SDKRepository: {catalogueRepository, nodeEngineRepo, contractsRepository, deliveryRepository}, - catalogueRepository: {SDKRepository, nodeEngineRepo}, - "novox/mesh-delivery": {SDKRepository, catalogueRepository}, -} - -// besideFor are the siblings a pull request's tests read (ADR 0484 clause 4): the node-engine at the head of the group's pull -// request for it when the group holds one, else at the commit the mesh runs (the commit of the indexer's module mesh-host, -// its trunk head when none is known); any other sibling, the catalogue -// included, at the head of the group's pull request for it when the group holds one, else at its trunk, since a group's -// check judges each member against the group's heads (ADR 0482 §2, ADR 0573 §4; issue 1126: a judge a group changed was -// judged against the catalogue's trunk). And first, the change's own repository at the trunk it is merged onto, so a test -// comparing a shrink-only list with the trunk's copy reads it at $MESH_CHECK_BESIDE/ (issue 1887 A12, ADR 0529 §2): -// that is where a catalogue change's own trunk copy is placed. -func (j *Examiner) besideFor(ctx context.Context, c *Case, p Pull) ([]BesideRef, error) { - var heads map[string]string - if j.Trunks != nil { - heads = j.Trunks.Heads() - } - var out []BesideRef - if p.Trunk != "" { - out = append(out, BesideRef{Repository: p.Repository, Commit: p.Trunk}) - } - place := func(repo string) { - switch { - case repo == nodeEngineRepo && c.member(repo) != nil: - // A group's check judges each member against the group's heads (ADR 0573 §4, ADR 0482 §2), and the group's - // node-engine is what runs after its merge: it is placed at the member's head, as any member is. Neither atTrunk - // nor runs, so no move of the trunk or of the running commit puts the verdict out of date (besideAtTrunk). - member := c.member(repo) - out = append(out, BesideRef{Repository: repo, Commit: member.Head, Ref: refOf(member.Number)}) - case repo == nodeEngineRepo: - commit := "" - if j.Runs != nil { - commit = j.Runs.CommitOf(nodeEngineModule) - } - atTrunk := false - if commit == "" { - commit, atTrunk = heads[repo], true - } - if commit != "" { - // Named in the verdict either way (ADR 0548 §6, issue 568's own example): at the commit the mesh runs, a new - // running commit puts the verdict out of date; at the trunk, a trunk move does (Checker.besideNow). - out = append(out, BesideRef{Repository: repo, Commit: commit, atTrunk: atTrunk, runs: !atTrunk}) - } - default: - if member := c.member(repo); member != nil { - out = append(out, BesideRef{Repository: repo, Commit: member.Head, Ref: refOf(member.Number)}) - } else if head := heads[repo]; head != "" { - out = append(out, BesideRef{Repository: repo, Commit: head, atTrunk: true}) - } - } - } - for _, repo := range besideRules[p.Repository] { - place(repo) - } - // A sibling a test builds needs every repository its go.mod requires at the zero version beside it too: the build - // resolves them from what lies beside, with nothing fetched (issue 1921). Its go.mod names them all, indirect ones - // included, so one level is enough. - derived, err := j.zeroVersionSiblings(ctx, p.Repository, out) - if err != nil { - return nil, err - } - for _, repo := range derived { - place(repo) - } - return out, nil -} - -// zeroVersionSiblings are the repositories the root go.mod of each sibling in refs requires at the zero version that are -// not beside already, sorted; none where the checker reads no forge. A sibling with no root go.mod requires none; one the -// forge does not answer for is an error, never a sibling left out in silence. -func (j *Examiner) zeroVersionSiblings(ctx context.Context, own string, refs []BesideRef) ([]string, error) { - if j.Forge == nil { - return nil, nil - } - have := map[string]bool{own: true} - for _, r := range refs { - have[r.Repository] = true - } - var out []string - for _, r := range refs { - if r.Repository == own { - continue - } - text, err := j.Forge.File(ctx, r.Repository, "go.mod", r.Commit) - if errors.Is(err, ErrNotFound) { - continue - } - if err != nil { - return nil, fmt.Errorf("the go.mod of %s at %.12s, beside the change, cannot be read%s: %w", r.Repository, r.Commit, unheardWords(err), err) - } - for _, path := range zeroVersionRequires(text) { - repo, _, ok := trunk.PackageRepository(path) - if !ok || have[repo] { - continue - } - have[repo] = true - out = append(out, repo) - } - } - slices.Sort(out) - return out, nil -} - -// zeroVersionRequires are the module paths a go.mod's require lines (a block or single ones) name at the zero version. -func zeroVersionRequires(gomod string) []string { - var out []string - block := false - for _, line := range strings.Split(gomod, "\n") { - line, _, _ = strings.Cut(line, "//") - f := strings.Fields(line) - switch { - case len(f) == 0: - continue - case f[0] == "require" && len(f) > 1 && f[1] == "(": - block = true - continue - case block && f[0] == ")": - block = false - continue - case f[0] == "require": - f = f[1:] - case !block: - continue - } - if len(f) >= 2 && f[1] == zeroVersion { - out = append(out, f[0]) - } - } - return out -} - -// zeroVersion is the version a go.mod requires a mesh package at (ADR 0573 §4): the builder writes the version it builds. -const zeroVersion = "v0.0.0-00010101000000-000000000000" - -func (c *Case) member(repository string) *Pull { - for i := range c.Pulls { - if c.Pulls[i].Repository == repository { - return &c.Pulls[i] - } - } - return nil -} - -func refOf(number int) string { - if number <= 0 { - return "" - } - return "refs/pull/" + strconv.Itoa(number) + "/head" -} - -// besideAtTrunk are the siblings of refs read at their trunk's head that the case does not merge, by repository: what a -// verdict names as Beside (ADR 0548 §6). -func besideAtTrunk(c *Case, refs []BesideRef, into map[string]string) { - for _, r := range refs { - if _, merged := c.Trunk[r.Repository]; (r.atTrunk || r.runs) && !merged { - into[r.Repository] = r.Commit - } - } -} - -// NodeEngineRepository is the node-engine's repository, whose trunk head a check without its member composes at. -const NodeEngineRepository = "novox/mesh-host" diff --git a/modules/mesh-delivery-checker/internal/check/binaries.go b/modules/mesh-delivery-checker/internal/check/binaries.go deleted file mode 100644 index 21abbb51..00000000 --- a/modules/mesh-delivery-checker/internal/check/binaries.go +++ /dev/null @@ -1,27 +0,0 @@ -package check - -import ( - "fmt" - - "mesh-delivery-checker/rules" -) - -// A change that adds or modifies a compiled program fails (issue 1577): it is build output, `go build` in a module's folder -// writes one beside go.mod, and `git add -A` takes it. The build module's fetch step, which holds the merged clone, reads the -// first bytes of each changed file and reports the programs (the build modules' fetch tools); the checker judges the answer. - -// checkBinariesOf records what a pull request's first fetch answer read of compiled programs, whichever build module -// gave it, as a fact the rules judge (rules.JudgePrograms). A fetch that made the merge and names no program has none: the -// answer's `programs` is an omitted empty list (B2g), and `merge` tells a preview was made. -func (st *state) checkBinariesOf(t *target) { - key := fmt.Sprintf("%s#%d", t.pull.Repository, t.pull.Number) - if t.fetched.Merge == "" { - return // no merge was made: nothing was changed to judge - } - files := t.fetched.Programs - if files == nil { - files = []ProgramFile{} // reported, and none: the rules refuse nothing (a nil list is a module that reports none) - } - st.facts = append(st.facts, rules.Step{Repository: t.pull.Repository, Number: t.pull.Number, Module: t.module, Node: t.node, - Programs: &rules.Programs{Key: key, Files: &files}}) -} diff --git a/modules/mesh-delivery-checker/internal/check/binaries_test.go b/modules/mesh-delivery-checker/internal/check/binaries_test.go deleted file mode 100644 index dd5b1675..00000000 --- a/modules/mesh-delivery-checker/internal/check/binaries_test.go +++ /dev/null @@ -1,57 +0,0 @@ -package check - -import ( - "strings" - "testing" - - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshdeliverycheckerclient" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep" -) - -func TestAChangeWhoseFetchReportsProgramsFailsNamingEachFile(t *testing.T) { // 1577 - prog := func(p ...string) []buildstep.Program { - var out []buildstep.Program // no program is the omitted empty list of the typed answer - for _, f := range p { - path, commit, _ := strings.Cut(f, "@") // `path@commit`: added by a commit of the branch and removed later - out = append(out, buildstep.Program{Path: path, Kind: "ELF", Commit: commit}) - } - return out - } - for _, c := range []struct { - name string - programs []buildstep.Program - fail []string // paths named; none passes - }{ - {"none found", prog(), nil}, - {"one program", prog("modules/m/m"), []string{"modules/m/m"}}, - {"two programs", prog("a/x", "b/y"), []string{"a/x", "b/y"}}, - {"added and removed in the branch", prog("gone/prog@0123456789abcdef0123"), []string{"gone/prog: a compiled program added in 0123456789ab and removed later: it stays in history; squash the branch (issue 1577)"}}, - } { - b := newBench(t) - b.fetch.Merge, b.fetch.Programs = "mmmm", c.programs - cs := caseOf(t, pullOf(repoA, 7, head1)) - v := b.judge(t, cs).Verdict - if len(cs.Notes()) > 0 { - t.Errorf("%s: notes = %v: a merge with no program is not a fetch that reported none", c.name, cs.Notes()) - } - if len(c.fail) == 0 { - if v.State != meshdeliverycheckerclient.VerdictPass { - t.Errorf("%s: verdict = %+v", c.name, v) - } - continue - } - if v.State != meshdeliverycheckerclient.VerdictFail { - t.Errorf("%s: verdict = %+v, want a failure", c.name, v) - continue - } - for _, p := range c.fail { - want := p - if !strings.Contains(p, " added in ") { - want = p + ": a compiled program is build output: remove it and add it to .gitignore (issue 1577)" - } - if !strings.Contains(v.Failed.Words, want) { - t.Errorf("%s: words %q do not name %s", c.name, v.Failed.Words, p) - } - } - } -} diff --git a/modules/mesh-delivery-checker/internal/check/bounded.go b/modules/mesh-delivery-checker/internal/check/bounded.go deleted file mode 100644 index f444671d..00000000 --- a/modules/mesh-delivery-checker/internal/check/bounded.go +++ /dev/null @@ -1,79 +0,0 @@ -package check - -import ( - "fmt" - "sort" - "sync" - "sync/atomic" - - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep" -) - -// ReadWorkers is how many values a read tool asks the bus for at once. Each value is a round trip from the tool through the -// runtime to the bus, so reading a bucket of thousands of keys one after the other outlasts the 30 s a tool call is given -// (issue 1827, as the delivery view's issue 1945). It is a copy of the view's: a few lines are not worth a group delivery -// through mesh-sdk (rules-are-weighed). -const ReadWorkers = 16 - -// MaxReads bounds the values one call of a read tool reads; past it the answer says it was cut and how to narrow it. -const MaxReads = 1000 - -// parallel runs read(i) for i in [0, n), at most ReadWorkers at a time, and answers the first error; once one failed no -// further read starts. -func parallel(n int, read func(i int) error) error { - var ( - next atomic.Int64 - failed atomic.Bool - once sync.Once - first error - wg sync.WaitGroup - ) - for w := 0; w < min(ReadWorkers, n); w++ { - wg.Add(1) - go func() { - defer wg.Done() - for !failed.Load() { - i := int(next.Add(1) - 1) - if i >= n { - return - } - if err := read(i); err != nil { - once.Do(func() { first = err }) - failed.Store(true) - } - } - }() - } - wg.Wait() - return first -} - -// capKeys keeps the first MaxReads keys and answers a note when it cut the rest, "" otherwise. -func capKeys(keys []string, narrow string) ([]string, string) { - if len(keys) <= MaxReads { - return keys, "" - } - return keys[:MaxReads], fmt.Sprintf("read %d of %d matching keys and stopped; %s", MaxReads, len(keys), narrow) -} - -// newestFirst sorts step keys (.) by id, newest first: an id is the time in base 36, then six hex digits, so the -// longer id is the later and equal lengths compare as text. A key that is no step key goes last. -func newestFirst(keys []string) { - id := func(k string) (string, bool) { - _, _, id, err := buildstep.ParseStepKey(k) - return id, err == nil - } - sort.Slice(keys, func(i, j int) bool { - a, aok := id(keys[i]) - b, bok := id(keys[j]) - switch { - case aok != bok: - return aok - case len(a) != len(b): - return len(a) > len(b) - case a != b: - return a > b - } - return keys[i] > keys[j] - }) -} diff --git a/modules/mesh-delivery-checker/internal/check/build_change.go b/modules/mesh-delivery-checker/internal/check/build_change.go deleted file mode 100644 index 45985c49..00000000 --- a/modules/mesh-delivery-checker/internal/check/build_change.go +++ /dev/null @@ -1,144 +0,0 @@ -package check - -import ( - "context" - "fmt" - "maps" - "slices" - "strings" - - "git.novox.be/novox/mesh-sdk/go/catalogue" - - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/graph" -) - -// What the check builds of a candidate before it composes (novox/hq ADR 0603 §10). The builder builds every fingerprint the -// indexer's candidate carries, as a key of its own (builds..), with the build modules that run; the -// check adds no build path of its own and waits on those keys (awaitBuilds), so the node-engines compose the candidate's -// modules with their builds. It does not wait on two kinds of changed module, and names them in its composition's warnings: -// -// - one built by a build module the change alters (the recipe of mesh-build-go or mesh-build-node enters the fingerprint -// of every module it builds, ADR 0530 §1): its candidate build is the running build module's, and the check cannot run -// the candidate's build module to build it (it runs it only for its own digest and tests, ADR 0535 §1), so it is not -// composed with a build of the changed build module; it is built again once the agreed toolchain moves (ADR 0603 §3). -// The build module's own build is waited on, as any other: the running build module builds its new source. -// - one that stands on a module the change alters (build.on): its candidate fingerprint names the base's trunk -// fingerprint, and no build module builds on another module's artifact (ADR 0487 §1), so its build stands on the -// trunk's base; the base's own build is waited on. -// -// A module the trunk holds no record of yet is not built by the builder until it is merged, so it is not waited on either. -// -// A changed build module whose manifest invokes a seat verb or module tool no running build serves is one the check cannot -// run (ADR 0614 §7): the modules it builds are composed from their manifests, as above, and the words name the verb. - -// buildsOfTheCheck are the builds the check waits on before it composes (module to fingerprint) and the words for the -// changed modules it composes without waiting on their build, one line each, sorted. A manifest that cannot be read leaves -// every build waited on and nothing said of build modules or bases (nothing is said that was not read). -func (st *state) buildsOfTheCheck(ctx context.Context) (map[string]string, []string) { - wait := map[string]string{} - changed := map[string]catalogue.Manifest{} - readable := true - for _, p := range st.c.Pulls { - for module, cm := range p.Fps { - if cm.Fp2 == "" || cm.Manifest == "" { - continue // the builder builds no fingerprint of it (candidates.go: none of the new form, or no manifest) - } - wait[module] = cm.Fp2 - if !readable || st.j.Read == nil { - readable = false - continue - } - m, err := st.j.Read.Manifest(ctx, cm.Manifest) - if err != nil { - st.j.logf("%s: the manifest of %s cannot be read, so the modules built with a changed build module or base are not named and every build is waited on: %v", st.c.Key, module, err) - readable = false - continue - } - changed[module] = m - } - } - var words []string - if st.j.Runs != nil { - var unheld []string - for _, module := range slices.Sorted(maps.Keys(wait)) { - if st.j.Runs.CommitOf(module) == "" { - unheld = append(unheld, module) - delete(wait, module) - } - } - if len(unheld) > 0 { - words = append(words, fmt.Sprintf("%s: the trunk holds no record of it yet, so the builder builds it once it is merged and the check composes it without a build (ADR 0603 §10)", - strings.Join(unheld, ", "))) - } - } - if !readable { - return wait, words - } - for _, bm := range st.j.Seats.Modules() { - if st.j.languageOf(bm) == "" { - continue - } - if _, alters := changed[bm]; !alters { - continue - } - var built []string - for module, m := range changed { - if isBuildModule := st.j.languageOf(module) != ""; !isBuildModule && buildsWith(m, st.j.languageOf(bm)) { - built = append(built, module) - delete(wait, module) - } - } - slices.Sort(built) - if len(built) > 0 { - words = append(words, fmt.Sprintf("the change alters the build module %s: %s, which it builds, are built by the running %s, not the changed one, which the check cannot run, so the check does not wait on their builds; they are built again once the agreed toolchain moves (ADR 0603 §3, §10)", - bm, strings.Join(built, ", "), bm)) - } - if unserved := st.unservedVerbs(ctx, changed[bm]); len(unserved) > 0 { - what := "nothing it builds is in the change" - if len(built) > 0 { - what = strings.Join(built, ", ") + ", which it builds, are composed from their manifests" - } - words = append(words, fmt.Sprintf("the changed build module %s invokes %s, which no running build serves, so the check cannot run it: %s (ADR 0614 §7)", - bm, strings.Join(unserved, ", "), what)) - } - } - g := graph.OfManifests(changed) - for _, base := range slices.Sorted(maps.Keys(changed)) { - if on := g.Dependents(base); len(on) > 0 { - for _, module := range on { - delete(wait, module) - } - words = append(words, fmt.Sprintf("the change alters %s, a base of %s: their builds stand on the trunk's %s, since no build module builds on a candidate's base, so the check waits on the build of %s alone (ADR 0603 §10)", - base, strings.Join(on, ", "), base, base)) - } - } - return wait, words -} - -// buildsWith says whether a manifest has a bundle in the language: the artifacts whose fingerprint names that language's -// toolchain and its build module's recipe (an archive is packed with no toolchain, ADR 0478 clause 1). -func buildsWith(m catalogue.Manifest, language string) bool { - return m.Build != nil && slices.ContainsFunc(m.Build.Artifacts, func(a catalogue.Artifact) bool { - return a.Kind == catalogue.ArtifactBundle && a.Language == language - }) -} - -// unservedVerbs are the seat verbs and module tools m invokes (graph.InvokesOf) that no running build serves, sorted; none -// when nothing reads what runs, or what runs cannot be read (said in the log: nothing is said that was not read). -func (st *state) unservedVerbs(ctx context.Context, m catalogue.Manifest) []string { - if st.j.Serving == nil { - return nil - } - served, err := st.j.Serving.Served(ctx) - if err != nil { - st.j.logf("%s: what the running builds serve cannot be read, so no build module is named for a verb it invokes: %v", st.c.Key, err) - return nil - } - var out []string - for _, v := range graph.InvokesOf(m) { - if !served(v) { - out = append(out, v) - } - } - return out -} diff --git a/modules/mesh-delivery-checker/internal/check/builds.go b/modules/mesh-delivery-checker/internal/check/builds.go deleted file mode 100644 index 2493c1da..00000000 --- a/modules/mesh-delivery-checker/internal/check/builds.go +++ /dev/null @@ -1,169 +0,0 @@ -package check - -import ( - "context" - "fmt" - "maps" - "slices" - "sort" - "strings" - "time" - - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-builder/builds" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshdeliverycheckerclient" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshdeliverychecker" -) - -// The states of a build the status line says (ADR 0484 clause 7). -const ( - BuildBuilt = "built" - BuildFailed = "failed" - BuildWaiting = "waiting" -) - -// BuildStates reads the builder's build of a module at a fingerprint of the new form (builds..): the -// value and whether the key exists. -type BuildStates interface { - Build(ctx context.Context, module, fp2 string) (builds.BuilderBuild, bool, error) -} - -// NoteOf is the state of a build as the line says it: done is built, failed is failed, and one queued, building or not -// begun is waiting. -func NoteOf(b builds.BuilderBuild, found bool) string { - switch { - case !found: - return BuildWaiting - case b.State == builds.BuildDone: - return BuildBuilt - case b.State == builds.BuildFailed: - return BuildFailed - } - return BuildWaiting -} - -// buildNotes are the state of each build the case's modules carry a fingerprint of, by module, sorted. A module two pull -// requests give is said once. -func (j *Examiner) buildNotes(ctx context.Context, c *Case) []BuildNote { - if j.Builds == nil { - return nil - } - fps := map[string]string{} - for _, p := range c.Pulls { - for module, cm := range p.Fps { - if cm.Fp2 != "" { - fps[module] = cm.Fp2 - } - } - } - modules := make([]string, 0, len(fps)) - for m := range fps { - modules = append(modules, m) - } - sort.Strings(modules) - var notes []BuildNote - for _, m := range modules { - b, found, err := j.Builds.Build(ctx, m, fps[m]) - if err != nil { - j.logf("the build of %s at %s cannot be read: %v", m, fps[m], err) - found = false - } - notes = append(notes, BuildNote{Module: m, State: NoteOf(b, found)}) - } - return notes -} - -// DefaultBuildWait is how long a check waits for the candidate's builds to end before it composes (the setting -// build-wait-bound, novox/hq ADR 0603 §10): past it the check composes without the builds not ended and names them. -const DefaultBuildWait = 30 * time.Minute - -// BuildEnds waits on the builder's build keys (builds..), hearing each key's changes on the bus as the -// builder writes them: the builder owns the fact, and nothing is polled. -type BuildEnds interface { - // Ended waits until the build of every module at its fingerprint (module to fingerprint) is done or failed, or ctx ends, - // and answers the builds that ended, by module. An error is only builds that cannot be heard at all. - Ended(ctx context.Context, builds map[string]string) (map[string]builds.BuilderBuild, error) - // Done waits until the build of every module at its fingerprint is done (a failed one built again, builder_build_again), - // and says whether they all are; false when ctx ends first or they cannot be heard. - Done(ctx context.Context, builds map[string]string) bool -} - -// BuildFailedTest is what a failure of the check names a failed build of the candidate by: the test `build: `. -// A verdict failed on builds is asked again by the checker itself once each is built again (Checker.Rebuilt). -const BuildFailedTest = "build: " - -// failedBuilds are the candidate's builds a failed verdict names as failed (BuildFailedTest), by module, at the fingerprint -// the case carries for it; none for a verdict that names no failed build. -func failedBuilds(v meshdeliverychecker.VerdictsByGroupHeadsValue, cs *Case) map[string]string { - if v.State != meshdeliverycheckerclient.VerdictFail { - return nil - } - out := map[string]string{} - for _, f := range append([]FailedFirst{failedOf(v)}, failedList(v.Failures)...) { - module, named := strings.CutPrefix(f.Test, BuildFailedTest) - if !named { - continue - } - for _, p := range cs.Pulls { - if cm, ok := p.Fps[module]; ok && cm.Fp2 != "" { - out[module] = cm.Fp2 - } - } - } - if len(out) == 0 { - return nil - } - return out -} - -func (j *Examiner) buildWait() time.Duration { - if j.BuildWait > 0 { - return j.BuildWait - } - return DefaultBuildWait -} - -// awaitBuilds waits for the candidate's builds before the check composes (ADR 0603 §10): the check builds what the builder -// builds of the candidate and composes with it. A failed build fails the check, naming the module and the builder's words; -// a build not ended within the bound is named in late, and the check does not compose: an engine composes a module only at -// a done build, so its answer would be the builder's lateness read as the change's refusal (issue 1921). It answers the -// words of the composition's warnings (what the check composes without waiting on its build, and why) and the failures of -// the builds that failed, for the rules to take in (rules.JudgeComposition); failed says the check has failed already. -func (st *state) awaitBuilds(ctx context.Context, failed bool) (words []string, failedBuilds []FailedFirst, late string) { - wait, words := st.buildsOfTheCheck(ctx) - if len(wait) == 0 { - return words, nil, "" - } - modules := slices.Sorted(maps.Keys(wait)) - if failed { - // The check has failed already: its red status is never held back by a build (the lead, 2026-11-03). - return append(words, fmt.Sprintf("the check failed before its builds were waited on, so it composes at once, without waiting on the builds of %s (ADR 0603 §10)", strings.Join(modules, ", "))), nil, "" - } - if st.j.BuildEnds == nil { - return append(words, fmt.Sprintf("the builds of %s cannot be heard, so the check composes without waiting on them (ADR 0603 §10)", strings.Join(modules, ", "))), nil, "" - } - bound := st.j.buildWait() - waits := fmt.Sprintf("waits on the builder's builds of %s before it composes, at most %s (ADR 0603 §10)", strings.Join(modules, ", "), bound) - st.c.note(waits) - st.j.logf("%s %s", st.c.Key, waits) - at, cancel := context.WithTimeout(ctx, bound) - ended, err := st.j.BuildEnds.Ended(at, wait) - cancel() - if err != nil { - st.j.logf("%s: the builds of %s cannot be heard: %v", st.c.Key, strings.Join(modules, ", "), err) - return append(words, fmt.Sprintf("the builds of %s cannot be heard (%v), so the check composes without waiting on them (ADR 0603 §10)", strings.Join(modules, ", "), err)), nil, "" - } - var notEnded []string - for _, module := range modules { - b, done := ended[module] - switch { - case !done: - notEnded = append(notEnded, module) - case b.State == builds.BuildFailed: - failedBuilds = append(failedBuilds, FailedFirst{Test: BuildFailedTest + module, Words: fmt.Sprintf("the candidate's build at %s failed (rebuild with builder_build_again; the check asks itself again when the build is done): %s", wait[module], b.Error)}) - } - } - if len(notEnded) > 0 && ctx.Err() == nil { - late = fmt.Sprintf("the builder's builds of %s did not end within the build-wait-bound of %s, so the change is not composed: an engine composes a module only at a done build (ADR 0603 §10)", strings.Join(notEnded, ", "), bound) - } - return words, failedBuilds, late -} diff --git a/modules/mesh-delivery-checker/internal/check/buildseats.go b/modules/mesh-delivery-checker/internal/check/buildseats.go deleted file mode 100644 index 25b6e944..00000000 --- a/modules/mesh-delivery-checker/internal/check/buildseats.go +++ /dev/null @@ -1,56 +0,0 @@ -package check - -import ( - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep" - "mesh-delivery-checker/rules" -) - -// **The checker names no build module** (design 47 G A-82): a build module is the holder of a build seat found on the seat list -// (buildrun.BuildSeats), by the language of the toolchain its seat's acting rule `build` names. The checker's own logic keys on -// that language: the Go repositories and the manifests are judged by the build module of Go, a TypeScript module's by that of -// TypeScript. - -// Languages of the toolchains the checker's logic is keyed on (the `on` of the build seats' acting rules). -const ( - languageGo = rules.LanguageGo - languageTypeScript = rules.LanguageTypeScript -) - -// buildModuleOf is the module that holds the build seat building a language's artifacts; the seat's name while no module is -// known to hold it or the seat list is not read, so a failure always names where it is. -func (j *Examiner) buildModuleOf(language string) string { - if m, err := j.Seats.For(language, ""); err == nil { - return m.Module - } - for _, m := range j.Seats.All() { - if m.Toolchain == language { - return m.Seat - } - } - ask := buildstep.AskGo - if language == languageTypeScript { - ask = buildstep.AskNode - } - seat, _ := buildstep.BuildSeat(ask) - return seat -} - -// goModule is the build module the Go repositories are judged by. -func (j *Examiner) goModule() string { return j.buildModuleOf(languageGo) } - -// goModule is the build module the manifests, the module graph and the checking program are judged by. -func (st *state) goModule() string { return st.j.goModule() } - -// languageOf is the language of the toolchain a build module builds with, empty for a module no build seat names. -func (j *Examiner) languageOf(module string) string { - l, _ := j.Seats.LanguageOf(module) - return l -} - -// askLanguageOf is the language of the asks the module's build seat takes (buildstep.AskGo, buildstep.AskNode, ...). -func (j *Examiner) askLanguageOf(module string) string { - if m, ok := j.Seats.OfModule(module); ok { - return m.AskLanguage() - } - return "" -} diff --git a/modules/mesh-delivery-checker/internal/check/buildseats_test.go b/modules/mesh-delivery-checker/internal/check/buildseats_test.go deleted file mode 100644 index 7dc80331..00000000 --- a/modules/mesh-delivery-checker/internal/check/buildseats_test.go +++ /dev/null @@ -1,58 +0,0 @@ -package check - -import ( - "testing" - - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-builder/buildrun" - "git.novox.be/novox/mesh-sdk/go/seatdef" -) - -// The holders of the build seats in the tests' seat list: names the checker's code does not know, found by the seats' -// acting rules (design 47 G A-82). -const ( - goBuildModule = "mesh-build-go" - nodeBuildModule = "mesh-build-node" -) - -// testSeats is the finder over the build seats of the tests' seat list. -func testSeats() *buildrun.BuildSeats { - rule := func(on string) seatdef.Definition { - return seatdef.Definition{Acts: []seatdef.ActingRule{{Step: seatdef.StepBuild, On: on}}} - } - defs := map[string]seatdef.Definition{"node-build-go": rule("go"), "node-build-node": rule("typescript")} - holders := map[string]string{"node-build-go": goBuildModule, "node-build-node": nodeBuildModule} - return buildrun.NewBuildSeats(func() map[string]seatdef.Definition { return defs }, func(seat string) (string, bool) { h, ok := holders[seat]; return h, ok }) -} - -// stepStatesOf is a Reader's StepStates over fixed states. -func stepStatesOf(m map[string]StateRead) func() map[string]StateRead { - return func() map[string]StateRead { return m } -} - -// The checker names no build module (design 47 G A-82): it finds each by the language its seat's acting rule builds, whatever the -// holder is called, and says that holder's name in what it judges. -func TestTheBuildModulesAreFoundOnTheSeatListWhateverTheyAreCalled(t *testing.T) { - rule := func(on string) seatdef.Definition { - return seatdef.Definition{Acts: []seatdef.ActingRule{{Step: seatdef.StepBuild, On: on}}} - } - defs := map[string]seatdef.Definition{"node-build-go": rule("go"), "node-build-node": rule("typescript"), "node-build-image": rule("kind:image")} - holders := map[string]string{"node-build-go": "compilers", "node-build-node": "bundlers"} - j := &Examiner{Seats: buildrun.NewBuildSeats(func() map[string]seatdef.Definition { return defs }, func(seat string) (string, bool) { h, ok := holders[seat]; return h, ok })} - if got := j.goModule(); got != "compilers" { - t.Errorf("the module that judges Go = %q, want its seat's holder", got) - } - if got, lang, ask := j.buildModuleOf(languageTypeScript), j.languageOf("bundlers"), j.askLanguageOf("bundlers"); got != "bundlers" || lang != languageTypeScript || ask != "node" { - t.Errorf("TypeScript: module %q, language %q, ask language %q", got, lang, ask) - } - if got := j.languageOf("mesh-build-go"); got != "" { - t.Errorf("a module that holds no build seat builds with %q", got) - } - if !changesBuildGo(catalogueRepository, "compilers", []string{"modules/compilers/main.go"}) || changesBuildGo(catalogueRepository, "compilers", []string{"modules/mesh-build-go/main.go"}) { - t.Error("a change under the Go build module's own directory is the one that changes it") - } - // With no seat on the list the failure still names where it is: the seat. - none := &Examiner{Seats: buildrun.NewBuildSeats(func() map[string]seatdef.Definition { return defs }, nil)} - if got := none.goModule(); got != "node-build-go" { - t.Errorf("a build seat no module holds is named by the seat, got %q", got) - } -} diff --git a/modules/mesh-delivery-checker/internal/check/case.go b/modules/mesh-delivery-checker/internal/check/case.go deleted file mode 100644 index 1be72fdb..00000000 --- a/modules/mesh-delivery-checker/internal/check/case.go +++ /dev/null @@ -1,292 +0,0 @@ -package check - -import ( - "encoding/json" - "fmt" - "maps" - "slices" - "sort" - "strings" - "sync" - "time" - - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshdeliverycheckerclient" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshdeliveryclient" - "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/meshdeliverychecker" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep" -) - -// Pull is one pull request the checker judges: its head, the trunk head of its repository it is merged onto and the -// modules the indexer says it touches, with the fingerprints the indexer wrote for them. -type Pull struct { - Repository string - Number int - Head string - Trunk string - Modules []string - Fps map[string]meshcatalog.CandidatesByGroupValuePullsItemFpsValue -} - -// Case is one check: a candidate's pull requests that are judged (those of a repository whose trunk is not known are left -// out; hq is judged as any repository since R4g, its checks Go tests: ADR 0527), the trunk head of each repository and the key of the verdict. -type Case struct { - // AskedAt is the running that asked again a check of these heads that could not run (PartRunning), "" otherwise. - AskedAt string - // Key is the verdict key, `.`. - Key string - Group string - HeadsHash string - // Heads is the heads hash the gate matches an Approve's members by (GateHeads): a verdict carries it. - Heads string - Pulls []Pull - // Trunk is the trunk head of each repository of Pulls. - Trunk map[string]string - // Left says why pull requests of the candidate are not judged (a repository with no known trunk); empty when all are. - Left []string - // Queued is when the checker took the case up, for the time of its queue. - Queued time.Time - // Seats is the seat list the checking program made, the checker's reader's list with the heads' definitions laid over - // it, which the manifest validator's and the node-engine composer's requests carry (ADR 0636 §1, §4); none until it is - // made. - Seats []json.RawMessage - // Try narrows a try's check (its level, its tests); nil for a pull request's. - Try *TryOptions - // Judged are the check's own judge's verdicts on the manifests the change brings, by module, as the seat mesh-catalog's - // verdict value (judgeManifests): the composer's request carries them in place of the running indexer's (ADR 0578 §2). - Judged map[string]json.RawMessage - - notesMu sync.Mutex - // warnings are, by pull request, what part of its check did not run (Case.warn). - warnings map[string]string - // seriesOf are, by pull request, the changes of a package series it makes (series.go), named in its status line. - seriesOf map[string][]string - // seriesChanges are, by pull request, the same changes as structures (series.go), named in the verdict and its event. - seriesChanges map[string][]meshdeliverychecker.VerdictsByGroupHeadsValueSeriesItem - notes []string - // asks are the ids of the asks the check put on the build seats' streams, in order: a try names them (Try.Asks). - asks []string - // Watch, when set, hears each ask the check puts, as it is put (step nil), and each value its step key takes while - // the check waits for it: the node that took it, the phase it says, its end. A try writes them into its record, so a - // running try names its asks and where each stands (issue 1890). Called from the check's goroutines; it must not block - // for long. - Watch func(askID string, step *buildstep.Step) - // Progress says what the check is doing, so a check that ran past its bound names the step it was stuck at. - Progress *Progress - // Wait says what a whole try waits for now ("" when nothing); the try keeps it for try-read. Nil for a pull request's check. - Wait func(why string) - // Kind is what asked the check (KindNew, KindNodes, KindTrunk): a carry after a trunk or sibling move is asked on the - // build seats' recheck stream, every other check on check (ADR 0536 §4, ADR 0548 §5). - Kind string - // CarriedFrom are, for the carry of a verdict that passed, the trunk and sibling commits it was judged on (ADR 0548 §5); - // nil for a whole check. - CarriedFrom map[string]string - // FPSet is the candidate's fingerprint set (Candidate.Fpset): a composition names the set it judged. - FPSet string - // Composition is, for a carry, the composition that passed on the same fingerprint set: it is kept and not asked again, - // since no fingerprint of a module it composed changed (ADR 0548 §5). Nil composes. - Composition *meshdeliverychecker.VerdictsByGroupHeadsValueComposition -} - -// Asked records the id of an ask the check put. -func (c *Case) Asked(id string) { - c.notesMu.Lock() - c.asks = append(c.asks, id) - c.notesMu.Unlock() -} - -// Asks are the ids of the asks the check put, in order. -func (c *Case) Asks() []string { - c.notesMu.Lock() - defer c.notesMu.Unlock() - return append([]string(nil), c.asks...) -} - -// Progress is the step a check is at, written by the check and read when its bound passes. -type Progress struct { - mu sync.Mutex - stage, node string -} - -// Set records the step now running and the node it runs on, empty for none. -func (p *Progress) Set(stage, node string) { - p.mu.Lock() - p.stage, p.node = stage, node - p.mu.Unlock() -} - -// Now is the step recorded last and its node. -func (p *Progress) Now() (stage, node string) { - p.mu.Lock() - defer p.mu.Unlock() - return p.stage, p.node -} - -// CaseOf is the check of a candidate against the trunk heads (the gate's source.main): the pull requests that are judged. -// The checker judges pull requests into main only (ADR 0484 clause 11): the pull message carries no base, a merge into -// another branch is a closed message, so every candidate is into the trunk; a repository whose trunk head is not known has -// none to merge onto. It answers nil when no pull request is left to judge. -func CaseOf(c meshcatalog.CandidatesByGroupValue, trunk map[string]string) *Case { - key, err := meshdeliverycheckerclient.VerdictKey(c.Group, c.Heads) - if err != nil { - return nil - } - cs := &Case{Key: key, Group: c.Group, HeadsHash: c.Heads, Heads: GateHeads(c), Trunk: map[string]string{}, Progress: &Progress{}, FPSet: c.Fpset} - for _, p := range c.Pulls { - switch head, known := trunk[p.Repository]; { - case !known || head == "": - cs.Left = append(cs.Left, fmt.Sprintf("%s#%d: %s", p.Repository, p.Number, UntrunkedWordsOf([]string{p.Repository}))) - default: - cs.Pulls = append(cs.Pulls, Pull{Repository: p.Repository, Number: int(p.Number), Head: p.Head, Trunk: head, Modules: p.Modules, Fps: p.Fps}) - cs.Trunk[p.Repository] = head - } - } - if len(cs.Pulls) == 0 { - return nil - } - sort.SliceStable(cs.Pulls, func(i, j int) bool { - if cs.Pulls[i].Repository != cs.Pulls[j].Repository { - return cs.Pulls[i].Repository < cs.Pulls[j].Repository - } - return cs.Pulls[i].Number < cs.Pulls[j].Number - }) - return cs -} - -// UntrunkedWords open the words of a verdict, and of a status, of a pull request that cannot be judged because the gate's -// source.main names no trunk head of its repository (issue 1422): never a failure of the change, and judged whole once the -// trunk head is known. It is said loudly, never left silently "new". -const UntrunkedWords = "cannot be judged: the trunk head of " - -// UntrunkedWordsOf are those words for the repositories whose trunk head is not known, in order, each named once. -func UntrunkedWordsOf(repos []string) string { - rs := slices.Clone(repos) - slices.Sort(rs) - rs = slices.Compact(rs) - return UntrunkedWords + strings.Join(rs, ", ") + " is not known: the gate's source.main names none, so there is no commit to merge it onto" -} - -// IsUntrunked says whether a verdict says its heads cannot be judged for want of a trunk head (UntrunkedWords). -func IsUntrunked(v meshdeliverychecker.VerdictsByGroupHeadsValue) bool { - return v.State == meshdeliverycheckerclient.VerdictFail && failedOf(v).Machine == "checker" && strings.HasPrefix(failedOf(v).Words, UntrunkedWords) -} - -// **A candidate outside the mesh is not the checker's** (sweep 2026-10-30 item 7): the forge carries repositories the mesh -// does not deliver (an operator's own), whose pull requests the indexer writes as candidates like any. Their trunk the -// gate never names, so each was judged "cannot be judged" and owed the status error on mesh/check, which the forge -// module wrote 119 times per head into a repository the mesh's forge account may not write (403). A candidate every pull -// request of which is of a repository the gate's source.main names no trunk head of, and touches no module, is outside -// the mesh: judged nothing, owed nothing on the forge, said once in the log and in checker_status (outside_the_mesh). A -// new repository of the mesh is not outside: its first pull request adds a module, and is said untrunked (issue 1422). - -// OutsideWords say why a candidate is outside the mesh. -const OutsideWords = "outside the mesh: the gate's source.main names no trunk head of its repositories and it touches no module, so the checker judges nothing and owes no status on the forge" - -// Outside says every pull request of c is of a repository trunk names no head of and touches no module. Never with -// trunk unknown (nil): before the gate's source is read nothing is outside. -func Outside(c meshcatalog.CandidatesByGroupValue, trunk map[string]string) bool { - if trunk == nil || len(c.Pulls) == 0 { - return false - } - for _, p := range c.Pulls { - if trunk[p.Repository] != "" || len(p.Modules) > 0 || len(p.Fps) > 0 { - return false - } - } - return true -} - -// leftOf are the pull requests of a candidate whose repository has no trunk head known, with Trunk empty, in repository and -// number order; nil when every repository's is known. -func leftOf(c meshcatalog.CandidatesByGroupValue, trunk map[string]string) []Pull { - var out []Pull - for _, p := range c.Pulls { - if trunk[p.Repository] == "" { - out = append(out, Pull{Repository: p.Repository, Number: int(p.Number), Head: p.Head, Modules: p.Modules, Fps: p.Fps}) - } - } - sort.SliceStable(out, func(i, j int) bool { - if out[i].Repository != out[j].Repository { - return out[i].Repository < out[j].Repository - } - return out[i].Number < out[j].Number - }) - return out -} - -// GateHeads is the hash the gate matches the members an Approve covers by (mesh-catalog mesh-delivery-gate onestatus.go -// headsOf): meshdeliveryclient.Heads over every pull request of the candidate, hq's included, as -// `#=`. A lone pull request is a group of one. Empty for a candidate -// with no pull request. -func GateHeads(c meshcatalog.CandidatesByGroupValue) string { - heads := make([]meshdeliveryclient.Head, 0, len(c.Pulls)) - for _, p := range c.Pulls { - heads = append(heads, meshdeliveryclient.Head{Repository: strings.ToLower(p.Repository), Number: int(p.Number), Head: strings.ToLower(p.Head)}) - } - hash, err := meshdeliveryclient.HeadsHash(heads) - if err != nil { - return "" - } - return hash -} - -// sameTrunk says whether two verdicts' trunk heads are the same. -func sameTrunk(a, b map[string]string) bool { return maps.Equal(a, b) } - -// Trunks holds the trunk head of each repository, as the catalog half's trunk revision says (a follower of the seat mesh-catalog's -// verb revision and its event catalog-revision sets it; design 47 G §197). -type Trunks struct { - mu sync.Mutex - heads map[string]string -} - -// Set takes the trunk heads in and answers whether they changed. -func (t *Trunks) Set(heads map[string]string) bool { - t.mu.Lock() - defer t.mu.Unlock() - if maps.Equal(t.heads, heads) { - return false - } - t.heads = maps.Clone(heads) - return true -} - -// Heads are the trunk heads now (a copy). -func (t *Trunks) Heads() map[string]string { - t.mu.Lock() - defer t.mu.Unlock() - return maps.Clone(t.heads) -} - -// note puts a word of the check's way on the case, for a try's line (issue 1921). -func (c *Case) note(s string) { - c.notesMu.Lock() - defer c.notesMu.Unlock() - if !slices.Contains(c.notes, s) { - c.notes = append(c.notes, s) - } -} - -// warn says of a pull request (pullKey) that a part of its check did not run, in words for its status line (issue 1577). -func (c *Case) warn(key, words string) { - c.notesMu.Lock() - defer c.notesMu.Unlock() - if c.warnings == nil { - c.warnings = map[string]string{} - } - c.warnings[key] = words -} - -// Warning is what warn said of a pull request, or "". -func (c *Case) Warning(key string) string { - c.notesMu.Lock() - defer c.notesMu.Unlock() - return c.warnings[key] -} - -// Notes are the words noted on the case, in the order they were noted. -func (c *Case) Notes() []string { - c.notesMu.Lock() - defer c.notesMu.Unlock() - return slices.Clone(c.notes) -} diff --git a/modules/mesh-delivery-checker/internal/check/checker.go b/modules/mesh-delivery-checker/internal/check/checker.go deleted file mode 100644 index ee6bbf26..00000000 --- a/modules/mesh-delivery-checker/internal/check/checker.go +++ /dev/null @@ -1,1126 +0,0 @@ -package check - -import ( - "context" - "errors" - "fmt" - "maps" - "mesh-delivery-checker/rules" - "slices" - "sort" - "strings" - "sync" - "time" - - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-builder/buildrun" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshdeliverycheckerclient" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshdeliveryclient" - "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/meshdeliverychecker" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep" - "git.novox.be/novox/mesh-sdk/go/keys" -) - -// DefaultBound is how long a check may run before it is ended failed naming the step it was stuck at (ADR 0484, issue 1678): -// none since R4g. A check's asks wait in the build seats' streams as long as the backlog is (ADR 0525 §9), and each ask's -// step is bounded from its start on the node that took it (buildrun.Asker.Bound, DefaultStepBound); a bound set by -// MESH_CHECKER_BOUND still ends a check that ran past it. -const DefaultBound time.Duration = 0 - -// UnheardWords end the Words of a failure because a part of the mesh the check reads was not heard (the forge, issue 1624): -// like a failure of the nodes, it is not the change's, and is asked again when the part it could not hear runs. -const UnheardWords = "could not run: not heard; asked again when it runs" - -// The events the checker says on its stream checks (module.json): a preview or a status was written, so a part that reads -// the bucket, which is made when the checker is assigned and may not exist when that part starts, finds it (ADR 0437 §8: no -// timer). The body is {"key": ...}. -const ( - EventPreviewWritten = "preview.written" - EventOwedWritten = "owed.written" -) - -// Announcer says an event of the checker's stream, with the key written. -type Announcer func(ctx context.Context, event, key string) - -// Outcome is what judging a case gives: the verdict (state, failure, levels, times, composition; the checker adds the -// group, the heads and the trunk) and, for the line, what the check knows of the builds of the modules it touches. -type Outcome struct { - Verdict meshdeliverychecker.VerdictsByGroupHeadsValue - Builds []BuildNote - // Slowest names the slowest tests of a level that went over its bound ("unit pkg.Test 1.2s"). - Slowest []string - // Judged says, by pull request (pullKey), which program judged a change to a build module (ADR 0535 §5); a pull request - // that changes none is not named. - Judged map[string]string - // Beside are the siblings the check read at their trunk's head, by repository (ADR 0548 §6): the verdict names them, and - // a move of one is carried. - Beside map[string]string - // OutOfStep are, by pull request (pullKey), the generated files out of step with their seat definitions that its steps - // named (design 26): the verdict event carries them. - OutOfStep map[string][]string - // Unheard is the part of the mesh the check could not hear, when its verdict could not run (IsCouldNotRun): its running - // asks the check again (PartRunning). The zero Part is a part the judge could not name. - Unheard Part -} - -// BuildNote is the state of a candidate's module build, by module: built, failed or waiting (ADR 0484 clause 7). -type BuildNote struct { - Module string - State string -} - -// Judge runs the check of a case: the merge, the levels. It writes what it is doing to c.Progress. It answers an error -// only when it could not judge at all; a failure of the change is a Verdict. -type Judge interface { - Judge(ctx context.Context, c *Case) (Outcome, error) -} - -// Checker judges the candidates the indexer writes, dark (ADR 0453 clause 4, ADR 0484): for each candidate it claims a -// verdict key, runs the check through its Judge, writes the verdict and, for each pull request judged, the owed status -// `mesh/check` the forge bridge performs. It holds no timer; a check starts from a candidate or from a change of the -// nodes, the trunk or the controller's plan, and ends when its judge does or its bound passes. -type Checker struct { - Verdicts KV - Owed KV - Judge Judge - Trunks interface{ Heads() map[string]string } - // Runs says which commit the mesh runs of a module (the indexer's modules): the node-engine a verdict read beside at its - // running commit is out of date when that commit moves (ADR 0548 §6); nil reads every sibling at its trunk. - Runs interface{ CommitOf(module string) string } - // CouldNotRun is the checker's own state could-not-run (CouldNotRunState): the checks that could not run, each asked - // again when the part it could not hear runs (PartRunning); nil keeps none, and none is asked again. - CouldNotRun KV - // Findings writes the checker's finding of a check not asked again within CouldNotRunBound (CouldNotRunDue); nil - // writes none. - Findings FindingWriter - // CouldNotRunKept is called each time a check that could not run is kept, so the process waits for its bound anew. - CouldNotRunKept func() - // Bound is how long one check may run; none when 0 (DefaultBound). - Bound time.Duration - // Rebuilds hears the builder's build keys a failed verdict names (failedBuilds): once each is written done, the check of - // those heads is asked again by the checker itself (ADR 0603 §10), as a failure of the nodes is; nil asks none again. - Rebuilds BuildEnds - // Asks keeps the asks each running check put, by verdict key (AsksState), for checker_ask_again; nil keeps none. - Asks AsksKV - // Link is the base of the address a status points at; the verdict key follows. - Link string - // Announce says a status was written (EventOwedWritten); nil says nothing. - Announce Announcer - // Says publishes the verdict event of each pull request whose check ended (EventVerdict); nil says none. - Says VerdictSayer - Now func() time.Time - Logf func(format string, args ...any) - // Settle is how long a group's heads must stay the same after the candidate last changed them before its check starts - // (issue 1890): the members of a group are announced one after another, and a check of each partial set is thrown - // away at the next. None when 0; DefaultSettle in the module. - Settle time.Duration - - once sync.Once - wg sync.WaitGroup - mu sync.Mutex - known map[string]meshcatalog.CandidatesByGroupValue // by candidates key - inflight map[string]bool // by verdict key - again map[string]bool // by verdict key: asked again while it ran - tried map[string]bool // by verdict key: looked at since this process started - release map[string]string // by verdict key: the running that released a check that could not run - live map[string]liveCheck // by verdict key: the check running in this process, ended when its heads go - settling map[string]*window // by candidates key: the window its heads settle in - rebuilt map[string]bool // by verdict key: every failed build its verdict names is done again - awaiting map[string]bool // by verdict key: its failed builds are heard (awaitRebuilt) - // outsideSaid are the candidates outside the mesh said in the log, by group and heads. - outsideSaid map[string]bool -} - -// liveCheck is a check running in this process: the candidates key of its group and the end of its run. -type liveCheck struct { - group string - end context.CancelCauseFunc -} - -// window is a group's settle window: aborted with errUnsettled when its heads change again or the group goes, and with -// errSettled to end it at once. -type window struct{ abort context.CancelCauseFunc } - -var ( - errUnsettled = errors.New("the group's heads changed again") - errSettled = errors.New("the group's heads settled") -) - -// settleNow ends the settle window of every group at once, as if Settle had passed. -func (ch *Checker) settleNow() { - ch.mu.Lock() - defer ch.mu.Unlock() - for _, w := range ch.settling { - w.abort(errSettled) - } -} - -// DefaultSettle is the module's Settle (issue 1890). On 2026-10-26 the three members of a group were announced within 2.8 -// seconds of each other (20:31:52.3, :53.7, :55.1 UTC), a session opening or pushing them one API call after another; -// fifteen seconds holds five times that, and costs a check of 10 to 18 minutes under 2.5 % of its time. A member that comes -// later still is no waste beyond its asks already taken: the check of the heads it replaced is ended at once. -const DefaultSettle = 15 * time.Second - -// EndedWords open the words of a verdict the checker ended without judging it, its heads no candidate's any more (issue -// 1890): never a failure of the change, and judged whole if a candidate holds those heads again. -const EndedWords = "ended: " - -// IsEnded says whether a verdict was ended without being judged (EndedWords). -func IsEnded(v meshdeliverychecker.VerdictsByGroupHeadsValue) bool { - return v.State == meshdeliverycheckerclient.VerdictFail && failedOf(v).Machine == "checker" && strings.HasPrefix(failedOf(v).Words, EndedWords) -} - -// superseded is the cause a running check is ended with: the heads that replaced its own, or none when its group went. -type superseded struct{ by string } - -func (s superseded) Error() string { - if s.by == "" { - return EndedWords + "no candidate holds these heads any more: the group was closed or merged" - } - return EndedWords + "superseded by " + s.by -} - -// Unwrap makes a check ended so a withdrawal of its asks: the asker drops what it put on the build nodes (ADR 0664 §4, §5). -func (s superseded) Unwrap() error { return buildrun.Withdrawn{Why: s.Error()} } - -func (ch *Checker) init() { - ch.once.Do(func() { - ch.known, ch.inflight, ch.again, ch.tried = map[string]meshcatalog.CandidatesByGroupValue{}, map[string]bool{}, map[string]bool{}, map[string]bool{} - ch.release = map[string]string{} - ch.live, ch.settling = map[string]liveCheck{}, map[string]*window{} - ch.rebuilt, ch.awaiting = map[string]bool{}, map[string]bool{} - ch.outsideSaid = map[string]bool{} - }) -} - -// endOthers ends every check of the group running in this process whose verdict key is not keep: no candidate holds its -// heads any more (issue 1890). Called with ch.mu held. -func (ch *Checker) endOthers(group, keep, by string) { - for k, l := range ch.live { - if l.group == group && k != keep { - l.end(superseded{by: by}) - } - } -} - -func (ch *Checker) logf(format string, args ...any) { - if ch.Logf != nil { - ch.Logf(format, args...) - } -} - -func (ch *Checker) now() time.Time { - if ch.Now != nil { - return ch.Now() - } - return time.Now() -} - -func (ch *Checker) bound() time.Duration { - if ch.Bound > 0 { - return ch.Bound - } - return DefaultBound -} - -// Wait returns when every check started so far has ended. -func (ch *Checker) Wait() { ch.wg.Wait() } - -// Candidate takes one value of the indexer's candidates bucket in (the key is the group) and checks it if it is to be -// checked. A value that is not a candidate is said and left. -func (ch *Checker) Candidate(ctx context.Context, key string, value []byte) { - if meshcatalogclient.IsTryGroup(key) { - return // a try's candidate is judged by its try (Tryer), never as a pull request's check: judged twice, the engines were asked twice - } - ch.init() - c, err := meshcatalog.DecodeCandidatesByGroupValue(value) - if err != nil { - ch.logf("candidates.%s holds what is not a candidate, left: %v", key, err) - return - } - vkey, _ := meshdeliverycheckerclient.VerdictKey(c.Group, c.Heads) - ch.mu.Lock() - prev, had := ch.known[key] - ch.known[key] = c - // A check of heads this candidate no longer holds is ended at once (issue 1890): a member's new head, a member joining - // or leaving. - ch.endOthers(key, vkey, GateHeads(c)) - moved := !had || prev.Heads != c.Heads - if had && moved { - if old, err := meshdeliverycheckerclient.VerdictKey(prev.Group, prev.Heads); err == nil && old != vkey { - defer ch.clearCouldNotRun(ctx, old) // its heads were replaced, after the lock - } - } - if ch.Settle > 0 && (moved || ch.settling[key] != nil) { - // The group's heads changed: its check waits until they have been the same for Settle, so a group whose members - // are announced one after another is checked once, whole. A later change starts the window again. The wait is a - // context's bound, no timer (ADR 0437 §8). - if w := ch.settling[key]; w != nil { - w.abort(errUnsettled) - } - base, abort := context.WithCancelCause(ctx) - w := &window{abort: abort} - ch.settling[key] = w - ch.wg.Add(1) - go func() { - defer ch.wg.Done() - wait, done := context.WithTimeout(base, ch.Settle) - defer done() - <-wait.Done() - settled := errors.Is(wait.Err(), context.DeadlineExceeded) || errors.Is(context.Cause(wait), errSettled) - ch.mu.Lock() - if !settled || ch.settling[key] != w { - ch.mu.Unlock() - return // changed again, forgotten, or the checker stops - } - delete(ch.settling, key) - now, ok := ch.known[key] - ch.mu.Unlock() - abort(nil) - if ok { - ch.consider(ctx, key, now) - } - }() - ch.mu.Unlock() - return - } - ch.mu.Unlock() - ch.consider(ctx, key, c) -} - -// VerdictDeleted takes the delete of a verdict key in (the checker's watch of its verdicts, issue 1733): the gate asks the -// operator's Approve only on a verdict, so heads a candidate holds are never left without one. A check of them running in -// this process writes its verdict anew at its end; otherwise the candidate is considered at once and judged again (or said -// again to be unjudgeable). A key no candidate holds is said and left. -func (ch *Checker) VerdictDeleted(ctx context.Context, key string) { - ch.init() - ch.mu.Lock() - if ch.inflight[key] { - ch.mu.Unlock() - ch.logf("%s: deleted while its check runs; its end writes it anew", key) - return - } - var group string - var cand meshcatalog.CandidatesByGroupValue - for k, c := range ch.known { - if vk, err := meshdeliverycheckerclient.VerdictKey(c.Group, c.Heads); err == nil && vk == key { - group, cand = k, c - break - } - } - ch.mu.Unlock() - if group == "" { - ch.logf("%s: deleted, and no candidate holds these heads, so nothing is judged", key) - return - } - ch.logf("%s: deleted; its heads are judged again", key) - ch.consider(ctx, group, cand) -} - -// Forget takes a candidate out (its key was deleted): a check of its heads still running is ended, as no candidate holds -// them any more. -func (ch *Checker) Forget(key string) { - ch.init() - ch.mu.Lock() - gone, had := ch.known[key] - delete(ch.known, key) - if had { - if vkey, err := meshdeliverycheckerclient.VerdictKey(gone.Group, gone.Heads); err == nil { - defer ch.clearCouldNotRun(context.Background(), vkey) // its pull request closed, after the lock - } - } - if w := ch.settling[key]; w != nil { - w.abort(errUnsettled) - delete(ch.settling, key) - } - ch.endOthers(key, "", "") - ch.mu.Unlock() -} - -// NodesChanged is Reconsider after a change of the nodes: one came online or went, a build module became healthy or -// stopped being, or a toolchain moved. A check that could not run is not asked again by it, only by the running of the -// part it could not hear (PartRunning). -func (ch *Checker) NodesChanged(ctx context.Context) { - ch.init() - ch.Reconsider(ctx) -} - -// Reconsider looks at every candidate again: the trunk moved, the nodes changed or a delivery ended. A candidate whose -// verdict stands for the trunk it was judged against is left. -func (ch *Checker) Reconsider(ctx context.Context) { - ch.init() - ch.mu.Lock() - known := make(map[string]meshcatalog.CandidatesByGroupValue, len(ch.known)) - for k, c := range ch.known { - known[k] = c - } - ch.mu.Unlock() - for k, c := range known { - ch.consider(ctx, k, c) - } -} - -func (ch *Checker) heads() map[string]string { - if ch.Trunks == nil { - return nil - } - return ch.Trunks.Heads() -} - -func (ch *Checker) consider(ctx context.Context, key string, c meshcatalog.CandidatesByGroupValue) { - heads := ch.heads() - if Outside(c, heads) { - ch.outside(ctx, c) - return - } - if left := leftOf(c, heads); len(left) > 0 { - // A pull request the checker cannot claim (its repository's trunk head is not known) leaves its whole group - // unjudged, said in a failure verdict (issue 1422, issue 1733): the gate asks the Approve only on a verdict, and a - // pass of the other members would let the group merge with that one never checked. - ch.untrunked(ctx, c, left) - return - } - cs := CaseOf(c, heads) - if cs == nil { - return // no pull request at all: nothing to judge - } - cs.Queued = ch.now() - ch.mu.Lock() - if ch.settling[key] != nil { - ch.mu.Unlock() - return // its heads are settling: the window's end considers it (Settle) - } - if ch.inflight[cs.Key] { - ch.again[cs.Key] = true // looked at once more when the check ends, so a change of the trunk is never lost - ch.mu.Unlock() - return - } - ch.inflight[cs.Key] = true - run, end := context.WithCancelCause(ctx) - ch.live[cs.Key] = liveCheck{group: key, end: end} - ch.mu.Unlock() - ch.wg.Add(1) - go func() { - defer ch.wg.Done() - vkey := cs.Key - defer func() { - ch.mu.Lock() - delete(ch.inflight, vkey) - delete(ch.again, vkey) - delete(ch.live, vkey) - ch.mu.Unlock() - again := errors.Is(context.Cause(run), errAskedAgain) - end(nil) - if again && ctx.Err() == nil { - ch.consider(ctx, key, ch.candidate(key, c)) // asked again by hand (AskAgainTool): claimed anew - } - }() - for { - // Every check is asked at once: the build seats' streams hold the backlog, a new head's check and a check after a - // failure of the nodes on check, a re-judge after a trunk move on recheck, pulled after them (ADR 0525 §4, §9; - // ADR 0536 §4). The checker holds no place and no capacity of its own. - ch.prepare(ctx, key, cs) - ch.try(ctx, run, key, cs) - ch.hearFailedBuilds(ctx, key, cs) // a check it failed on a build is asked again once that build is done again - ch.mu.Lock() - more := ch.again[vkey] - delete(ch.again, vkey) - ch.mu.Unlock() - if !more || run.Err() != nil { - return - } - // Looked at again for the same heads only: a candidate that moved to other heads has its own check (issue 1890). - if next := CaseOf(ch.candidate(key, c), ch.heads()); next != nil { - if next.Key != vkey { - return - } - cs = next - } - cs.Queued = ch.now() - } - }() -} - -// untrunked says, loudly, that pull requests of a candidate cannot be judged because the gate's source.main names no trunk -// head of their repository (issue 1422): its verdict key holds a failure that says so, whatever it held before (a running -// verdict left by a check that can no longer run, or a verdict judged on a trunk that is no longer named: issue 1733), which -// checker_verdicts and checker_status show; and every pull request of the candidate gets the status error with -// UntrunkedWords, the members whose trunk is known too, as their group is not judged. It is logged once per head: when a -// status or the verdict is written, never at a look that finds them already said. Once the trunk head is known the verdict -// is stale (it names no trunk) and the heads are judged whole (prepare, claim). -func (ch *Checker) untrunked(ctx context.Context, c meshcatalog.CandidatesByGroupValue, left []Pull) { - key, err := meshdeliverycheckerclient.VerdictKey(c.Group, c.Heads) - if err != nil { - ch.logf("candidates of %s: no verdict key for heads %q, so it cannot be said that they cannot be judged: %v", c.Group, c.Heads, err) - return - } - repos := make([]string, 0, len(left)) - for _, p := range left { - repos = append(repos, p.Repository) - } - words := UntrunkedWordsOf(repos) - v := meshdeliverychecker.VerdictsByGroupHeadsValue{Group: c.Group, Heads: GateHeads(c), Trunk: map[string]string{}, State: meshdeliverycheckerclient.VerdictFail, - Failed: &FailedFirst{Machine: "checker", Words: words}} - data, err := meshdeliverycheckerclient.EncodeVerdict(v) - if err != nil { - ch.logf("%s: %s, and the verdict cannot say so: %v", key, words, err) - return - } - said, err := putOnce(ctx, ch.Verdicts, key, data, func(cur []byte) bool { - held, err := meshdeliverycheckerclient.DecodeVerdict(cur) - return err == nil && IsUntrunked(held) && failedOf(held).Words == words // the same words stand; anything else is replaced - }) - if err != nil { - ch.logf("%s: %s, and the verdict cannot say so: %v", key, words, err) - } - for _, cp := range c.Pulls { - okey, err := CheckerOwedKey(cp.Repository, int(cp.Number), cp.Head) - if err != nil { - ch.logf("%s: %v", key, err) - continue - } - o := meshdeliverychecker.OwedByRepositoryNumberHeadActValue{Act: meshdeliveryclient.OwedStatus, Context: meshdeliveryclient.StatusContextCheck, State: "error", - Target: strings.TrimSuffix(ch.Link, "/") + "/" + key, Text: rules.ClipLine(words, MaxLine)} - data, err := EncodeCheckerOwed(o) - if err != nil { - ch.logf("%s: the status of %s cannot be written: %v", key, okey, err) - continue - } - wrote, err := putOnce(ctx, ch.Owed, okey, data, func(cur []byte) bool { - held, err := DecodeCheckerOwed(cur) - o.V = keys.Version - return err == nil && held == o - }) - if err != nil { - ch.logf("%s: the status of %s cannot be written: %v", key, okey, err) - continue - } - if wrote { - said = true - if ch.Announce != nil { - ch.Announce(ctx, EventOwedWritten, okey) - } - } - } - if said { - names := make([]string, 0, len(left)) - for _, p := range left { - names = append(names, fmt.Sprintf("%s#%d@%s", p.Repository, p.Number, short12(p.Head))) - } - ch.logf("%s: %s %s; the verdict and every status of its group say so (error), and it is judged once the trunk head is known", key, strings.Join(names, ", "), words) - } -} - -// outside takes a candidate outside the mesh (case.go Outside): no verdict, and every status owed for its pull requests -// taken away, so the forge module stops writing one into a repository the mesh's forge account may not write. Said once -// per heads in the log. -func (ch *Checker) outside(ctx context.Context, c meshcatalog.CandidatesByGroupValue) { - var names []string - for _, p := range c.Pulls { - names = append(names, fmt.Sprintf("%s#%d@%s", p.Repository, p.Number, short12(p.Head))) - key, err := CheckerOwedKey(p.Repository, int(p.Number), p.Head) - if err != nil { - continue - } - _, _, found, err := ch.Owed.Get(ctx, key) - if err != nil || !found { - continue - } - d, ok := ch.Owed.(Deleter) - if !ok { - continue - } - if err := d.Delete(ctx, key); err != nil { - ch.logf("%s: the status owed of a pull request outside the mesh could not be taken away: %v", key, err) - } - } - said := c.Group + "@" + c.Heads - ch.mu.Lock() - first := !ch.outsideSaid[said] - ch.outsideSaid[said] = true - ch.mu.Unlock() - if first { - ch.logf("candidates of %s: %s %s", c.Group, strings.Join(names, ", "), OutsideWords) - } -} - -// The kinds of a check (ADR 0536 §4): a head never judged and a head asked again after a failure of the nodes are asked on -// the build seats' check stream; a carry, a verdict moved to a newer trunk or sibling commit by its package digests (ADR 0548 -// §5), on the recheck stream, pulled after. -const ( - KindNew = "new" - KindNodes = "nodes" - KindTrunk = "trunk" -) - -// prepare reads the case's verdict key and says what its check is (ADR 0548 §1, §5, §7): none (or one left running) is a -// head never judged, a whole check; a failure of the nodes is asked again after the nodes changed; a verdict judged on trunk -// or sibling commits that moved since is carried, its packages run only where the move changed their digest, and a pass's -// commits are named as the carry's CarriedFrom. A verdict that stands is ranked with the carries: its claim finds nothing -// to do. -func (ch *Checker) prepare(ctx context.Context, group string, cs *Case) { - cs.Kind, cs.CarriedFrom, cs.Composition = KindNew, nil, nil - value, _, found, err := ch.Verdicts.Get(ctx, cs.Key) - if err != nil || !found { - return - } - v, err := meshdeliverycheckerclient.DecodeVerdict(value) - switch { - case err != nil || v.State == meshdeliverycheckerclient.VerdictRunning: - return - case IsCouldNotRun(v): - cs.Kind = KindNodes - return - case failedBuilds(v, cs) != nil: - cs.Kind = KindNodes // asked again on check once its builds are done again (awaitRebuilt), never by a recheck - ch.awaitRebuilt(ctx, group, cs.Key, failedBuilds(v, cs)) - return - case IsConflictFailure(v): - return // a head git refused: its next check is whole (ADR 0548 §7) - case IsEnded(v), IsUntrunked(v): - return // ended unjudged when its heads went (issue 1890), or never judged for want of a trunk head (issue 1422): checked whole - } - cs.Kind = KindTrunk - if v.State == meshdeliverycheckerclient.VerdictPass && ch.stale(v, cs) { - cs.CarriedFrom = judgedOn(v) - if c := v.Composition; c != nil && c.State == meshdeliverycheckerclient.CompositionPass && c.Fpset != "" && c.Fpset == cs.FPSet { - kept := *c - cs.Composition = &kept - } - } -} - -// stale says whether a verdict was judged on commits that are no longer the case's: a trunk it merged moved, or a sibling it -// read at its trunk's head (ADR 0548 §6). -func (ch *Checker) stale(v meshdeliverychecker.VerdictsByGroupHeadsValue, cs *Case) bool { - return !sameTrunk(v.Trunk, cs.Trunk) || besideMoved(v.Beside, ch.besideNow()) -} - -// besideNow are the commits a sibling is read at now, by repository: its trunk head, and for the node-engine the commit the -// mesh runs when the indexer names one, as besideFor places them. -func (ch *Checker) besideNow() map[string]string { - return besideAt(ch.heads(), ch.Runs) -} - -// besideAt places the commits a sibling is read at: the trunk heads, with the node-engine at the commit the mesh runs when -// runs names one (ADR 0548 §6). The checker's decision and the status read the same commits through it. -func besideAt(now map[string]string, runs interface{ CommitOf(module string) string }) map[string]string { - if runs != nil { - if c := runs.CommitOf(nodeEngineModule); c != "" { - out := make(map[string]string, len(now)+1) - for r, h := range now { - out[r] = h - } - out[nodeEngineRepo] = c - return out - } - } - return now -} - -// besideMoved says whether a sibling read at these commits moved: the commit it is read at now is known and another. -func besideMoved(beside, now map[string]string) bool { - for r, c := range beside { - if h := now[r]; h != "" && h != c { - return true - } - } - return false -} - -// judgedOn are the trunk and sibling commits a verdict was judged on, by repository. -func judgedOn(v meshdeliverychecker.VerdictsByGroupHeadsValue) map[string]string { - out := make(map[string]string, len(v.Trunk)+len(v.Beside)) - for r, c := range v.Beside { - out[r] = c - } - for r, c := range v.Trunk { - out[r] = c - } - return out -} - -// carried is what a carry's verdict names as carried from (ADR 0548 §5): the commits it was judged on before, of the -// repositories the new verdict still judges or reads; nil when none of them moved. -func carried(from map[string]string, v meshdeliverychecker.VerdictsByGroupHeadsValue) map[string]string { - out, moved := map[string]string{}, false - for r, c := range from { - now, ok := v.Trunk[r] - if !ok { - now, ok = v.Beside[r] - } - if ok && now != "" && c != "" { - out[r] = c - moved = moved || now != c - } - } - if !moved { - return nil - } - return out -} - -// moveWords say a carry's moves, for the words of a failure: "carried from to of ", each moved -// repository, sorted. -func moveWords(from map[string]string, v meshdeliverychecker.VerdictsByGroupHeadsValue) string { - var moves []string - for r, c := range from { - now, ok := v.Trunk[r] - if !ok { - now = v.Beside[r] - } - if now != "" && now != c { - moves = append(moves, fmt.Sprintf("%s %s to %s", r, short12(c), short12(now))) - } - } - sort.Strings(moves) - return strings.Join(moves, ", ") -} - -func (ch *Checker) candidate(key string, fallback meshcatalog.CandidatesByGroupValue) meshcatalog.CandidatesByGroupValue { - ch.mu.Lock() - defer ch.mu.Unlock() - if c, ok := ch.known[key]; ok { - return c - } - return fallback -} - -// claimed is a verdict key the checker holds: the revision the next write is made at. -type claimed struct{ rev uint64 } - -// claim takes the check of the case, or answers nil when it is not this checker's to run now: -// - no key: it is created running; a create that finds the key made meanwhile gets nothing; -// - a key left running is taken over as it stands when this process looks at it for the first time (it was left by the -// checker that stopped; there is one instance, as there is one builder per node, ADR 0478 clause 6), and left otherwise; -// - a pass or a failure for the trunk heads the case has stands; one for other trunk heads (the trunk moved) is taken -// again by compare-and-set on the same key, and so is a failure of the nodes after the nodes changed. -func (ch *Checker) claim(ctx context.Context, cs *Case, first bool) (*claimed, error) { - running := meshdeliverychecker.VerdictsByGroupHeadsValue{Group: cs.Group, Heads: cs.Heads, Trunk: cs.Trunk, State: meshdeliverycheckerclient.VerdictRunning} - data, err := meshdeliverycheckerclient.EncodeVerdict(running) - if err != nil { - return nil, err - } - value, rev, found, err := ch.Verdicts.Get(ctx, cs.Key) - if err != nil { - return nil, fmt.Errorf("%s: %w", cs.Key, err) - } - if !found { - rev, err := ch.Verdicts.Create(ctx, cs.Key, data) - if errors.Is(err, ErrConflict) { - return nil, nil // another checker made it first - } - if err != nil { - return nil, fmt.Errorf("%s: %w", cs.Key, err) - } - return &claimed{rev}, nil - } - cur, err := meshdeliverycheckerclient.DecodeVerdict(value) - if err != nil { - return nil, fmt.Errorf("%s holds what is not a verdict: %w", cs.Key, err) - } - retake := false - switch { - case cur.State == meshdeliverycheckerclient.VerdictRunning: - if first { - return &claimed{rev}, nil - } - return nil, nil - case IsEnded(cur), ch.stale(cur, cs): - retake = true // heads held again after their check was ended unjudged (issue 1890), or a trunk that moved - case cur.State == meshdeliverycheckerclient.VerdictFail && ch.takeRebuilt(cs.Key): - retake = true // every failed build it names is done again (ADR 0603 §10) - case IsCouldNotRun(cur): - // Its claim was released when it could not run: only the running of the part it could not hear asks it again. - cs.AskedAt, retake = ch.takeRelease(cs.Key) - } - if !retake { - return nil, nil - } - rev, err = ch.Verdicts.Update(ctx, cs.Key, data, rev) - if errors.Is(err, ErrConflict) { - return nil, nil - } - if err != nil { - return nil, fmt.Errorf("%s: %w", cs.Key, err) - } - return &claimed{rev}, nil -} - -// ConflictWords are what the words of a head that git would not merge onto its trunk say before the files in conflict. -const ConflictWords = "does not merge into the trunk: files in conflict: " - -// IsConflictFailure says whether a verdict failed because its head did not merge onto its trunk (ADR 0548 §7): it has no -// pass to carry, so its next check, at a push or at a later trunk move, is a whole check of its head. -func IsConflictFailure(v meshdeliverychecker.VerdictsByGroupHeadsValue) bool { - return v.State == meshdeliverycheckerclient.VerdictFail && strings.Contains(failedOf(v).Words, ConflictWords) -} - -// try claims the check, judges it within its bound under run and writes the verdict and the owed statuses. A check that ends -// because ctx did is left running: the checker takes it again when it starts. A check whose run was ended because no -// candidate holds its heads any more (issue 1890) is ended: its verdict says so, and no status is written. -func (ch *Checker) try(ctx, run context.Context, key string, cs *Case) { - if run.Err() != nil { - return // ended before it was claimed: nothing to write - } - ch.mu.Lock() - first := !ch.tried[cs.Key] - ch.tried[cs.Key] = true - ch.mu.Unlock() - cl, err := ch.claim(ctx, cs, first) - if err != nil { - ch.logf("%s: %v", cs.Key, err) - return - } - if cl == nil { - return - } - ch.clearCouldNotRun(ctx, cs.Key) // checked again: a record that it could not run, and its finding, go - began := ch.now() - if cs.Watch == nil && ch.Asks != nil { - cs.Watch = func(_ string, step *buildstep.Step) { - if step == nil { // put: kept before its wait starts - ch.recordAsks(ctx, cs.Key, cs.Asks()) - } - } - defer ch.forgetAsks(ctx, cs.Key) - } - ch.writeOwed(ctx, cs, meshdeliverychecker.VerdictsByGroupHeadsValue{State: meshdeliverycheckerclient.VerdictRunning}, Outcome{}) - out := ch.judge(run, cs) - // An ask the build seat gave up on, or whose step the build module's next process ended because it was replaced under - // it, judged nothing (issue 734, IsLostAsk): the check is asked again under the same claim, its status pending, and after - // LostAskTries it fails as not heard, asked again when the part it could not hear runs. A step that ended while its watch was deaf is - // read at the next nudge (HeardEnds) and judged. - for try := 1; IsLostAsk(out.Verdict) && run.Err() == nil; try++ { - if try >= LostAskTries { - out.Verdict.Failed.Words = strings.TrimSpace(failedOf(out.Verdict).Words + "\nasked " + fmt.Sprint(LostAskTries) + - " times and given up each time: " + UnheardWords) - break - } - ch.logf("%s: %s; asked again (%d of %d)", cs.Key, failedOf(out.Verdict).Words, try+1, LostAskTries) - out = ch.judge(run, cs) - } - if ctx.Err() != nil || errors.Is(context.Cause(run), errAskedAgain) { - return // the checker stops, or the verdict was asked again by hand, which wrote it: its next check claims it anew - } - var why superseded - if errors.As(context.Cause(run), &why) { - ch.end(ctx, cs, cl, why) - return - } - v := out.Verdict - v.Group, v.Heads, v.Trunk, v.Beside = cs.Group, cs.Heads, cs.Trunk, nil - for r, c := range out.Beside { - if _, merged := cs.Trunk[r]; !merged && c != "" { - if v.Beside == nil { - v.Beside = map[string]string{} - } - v.Beside[r] = c - } - } - if cs.CarriedFrom != nil { - // A carry (ADR 0548 §5): a pass names the commits it was carried from; a failure names the move it failed on. - switch v.State { - case meshdeliverycheckerclient.VerdictPass: - v.CarriedFrom = carried(cs.CarriedFrom, v) - case meshdeliverycheckerclient.VerdictFail: - if moves := moveWords(cs.CarriedFrom, v); moves != "" { - v.Failed.Words = strings.TrimSpace(failedOf(v).Words + "\nfailed on the carry over the move of " + moves + ": the move changed what these tests read") - } - } - } - if tookOf(v).Queue == 0 && !cs.Queued.IsZero() && began.After(cs.Queued) { - if v.Took == nil { - v.Took = &meshdeliverychecker.VerdictsByGroupHeadsValueTook{} - } - v.Took.Queue = began.Sub(cs.Queued).Milliseconds() - } - data, err := meshdeliverycheckerclient.EncodeVerdict(v) - if err != nil { - ch.logf("%s: the verdict cannot be written: %v", cs.Key, err) - v = meshdeliverychecker.VerdictsByGroupHeadsValue{Group: cs.Group, Heads: cs.Heads, Trunk: cs.Trunk, State: meshdeliverycheckerclient.VerdictFail, - Failed: &FailedFirst{Machine: "checker", Words: "the verdict could not be written: " + err.Error()}} - if data, err = meshdeliverycheckerclient.EncodeVerdict(v); err != nil { - return - } - } - if _, err := ch.Verdicts.Update(ctx, cs.Key, data, cl.rev); err != nil { - if _, _, found, gerr := ch.Verdicts.Get(ctx, cs.Key); gerr == nil && !found { - _, err = ch.Verdicts.Create(ctx, cs.Key, data) // its key was deleted while it ran (issue 1733): written anew - } - if err != nil { - ch.logf("%s: the verdict could not be written: %v", cs.Key, err) - return - } - } - if IsCouldNotRun(v) { - ch.keepCouldNotRun(ctx, cs, v, out.Unheard, cs.AskedAt) - } - if ch.movedSince(cs) || besideMoved(v.Beside, ch.besideNow()) { - // Judged on a trunk that moved while it ran: the verdict is kept as judged, and the status stays pending until the - // check of the new trunk, which Reconsider starts, ends. - ch.owePending(ctx, cs, v) - ch.logf("%s: %s on a trunk that moved while it ran; the status stays pending until it is carried", cs.Key, v.State) - return - } - ch.writeOwed(ctx, cs, v, out) - ch.sayVerdict(ctx, cs, v, out) - ch.logf("%s: %s", cs.Key, v.State) -} - -// end writes the verdict of a check whose heads no candidate holds any more (issue 1890), by compare-and-set on its claim, -// and says it once in the log with the asks it had put: they stay in the build seats' streams, since an ask once put cannot -// be taken back (buildrun.Asker has no withdraw), and are no longer waited for. No status is written: the heads that -// replaced these have their own check, whose pending status stands. -func (ch *Checker) end(ctx context.Context, cs *Case, cl *claimed, why superseded) { - v := meshdeliverychecker.VerdictsByGroupHeadsValue{Group: cs.Group, Heads: cs.Heads, Trunk: cs.Trunk, State: meshdeliverycheckerclient.VerdictFail, - Failed: &FailedFirst{Machine: "checker", Words: why.Error()}} - data, err := meshdeliverycheckerclient.EncodeVerdict(v) - if err == nil { - _, err = ch.Verdicts.Update(ctx, cs.Key, data, cl.rev) - } - if err != nil { - ch.logf("%s: %s, but the verdict could not say so: %v", cs.Key, why.Error(), err) - return - } - stage, _ := cs.Progress.Now() - asks := cs.Asks() - ch.logf("%s: %s; it was at %q with %d asks put %v, which are no longer waited for", cs.Key, why.Error(), stage, len(asks), asks) -} - -// judge runs the case within the bound. A judge that fails to judge, and a check that ran past its bound, are verdicts of -// failure naming the machine and the step. -func (ch *Checker) judge(ctx context.Context, cs *Case) Outcome { - out, _ := judgeWithin(ctx, ch.Judge, cs, ch.bound()) - return out -} - -var errBound = errors.New("the check ran past its bound") - -func failure(machine, words string) meshdeliverychecker.VerdictsByGroupHeadsValue { - return meshdeliverychecker.VerdictsByGroupHeadsValue{State: meshdeliverycheckerclient.VerdictFail, Failed: &FailedFirst{Machine: machine, Words: words}} -} - -// writeOwed writes, for each pull request judged, the status the forge bridge performs: pending while the check runs, success -// or failure at its end (ADR 0484 clause 2). A key already holding the same value is not written again, so the bridge -// performs one act for each change; an older head's key is never touched. -func (ch *Checker) writeOwed(ctx context.Context, cs *Case, v meshdeliverychecker.VerdictsByGroupHeadsValue, out Outcome) { - for _, p := range cs.Pulls { - key, err := CheckerOwedKey(p.Repository, int(p.Number), p.Head) - if err != nil { - ch.logf("%s: %v", cs.Key, err) - continue - } - state := map[string]string{meshdeliverycheckerclient.VerdictRunning: "pending", meshdeliverycheckerclient.VerdictPass: "success", meshdeliverycheckerclient.VerdictFail: "failure"}[v.State] - o := meshdeliverychecker.OwedByRepositoryNumberHeadActValue{Act: meshdeliveryclient.OwedStatus, Context: meshdeliveryclient.StatusContextCheck, State: state, - Target: strings.TrimSuffix(ch.Link, "/") + "/" + cs.Key, Text: Line(v, cs, p, out.Builds, out.Slowest, out.Judged)} - data, err := EncodeCheckerOwed(o) - if err != nil { - ch.logf("%s: the status of %s cannot be written: %v", cs.Key, key, err) - continue - } - wrote, err := putOnce(ctx, ch.Owed, key, data, func(cur []byte) bool { - held, err := DecodeCheckerOwed(cur) - o.V = keys.Version - return err == nil && held == o - }) - if err != nil { - ch.logf("%s: the status of %s cannot be written: %v", cs.Key, key, err) - } else if wrote && ch.Announce != nil { - ch.Announce(ctx, EventOwedWritten, key) - } - } -} - -// putOnce writes data under key by create, or by compare-and-set when the key exists, and writes nothing when same says the -// key holds the value already. -func putOnce(ctx context.Context, kv KV, key string, data []byte, same func(cur []byte) bool) (bool, error) { - for try := 0; try < 4; try++ { - cur, rev, found, err := kv.Get(ctx, key) - if err != nil { - return false, err - } - if found && same(cur) { - return false, nil - } - if !found { - _, err = kv.Create(ctx, key, data) - } else { - _, err = kv.Update(ctx, key, data, rev) - } - if errors.Is(err, ErrConflict) { - continue - } - return err == nil, err - } - return false, fmt.Errorf("%s changed under every one of 4 tries", key) -} - -// Sweep closes, at start, every verdict left running for a candidate that no longer holds those heads: nothing will check -// them again, and the key would stay running for ever (the builder's Sweep, issue 1660). Call it once the candidates have been -// read. A key of heads a candidate holds now is not touched: the check takes it over. -func (ch *Checker) Sweep(ctx context.Context) error { - ch.init() - keys, err := ch.Verdicts.Keys(ctx) - if err != nil { - return err - } - ch.mu.Lock() - current := map[string]bool{} - for _, c := range ch.known { - if k, err := meshdeliverycheckerclient.VerdictKey(c.Group, c.Heads); err == nil { - current[k] = true - } - } - ch.mu.Unlock() - for _, key := range keys { - if current[key] { - continue - } - value, rev, found, err := ch.Verdicts.Get(ctx, key) - if err != nil || !found { - continue - } - cur, err := meshdeliverycheckerclient.DecodeVerdict(value) - if err != nil || cur.State != meshdeliverycheckerclient.VerdictRunning { - continue - } - cur.State = meshdeliverycheckerclient.VerdictFail - cur.Failed = &FailedFirst{Machine: "checker", Words: EndedWords + "closed at start: left running, and no candidate holds these heads any more, so nothing will check them"} - data, err := meshdeliverycheckerclient.EncodeVerdict(cur) - if err != nil { - return err - } - if _, err := ch.Verdicts.Update(ctx, key, data, rev); err != nil && !errors.Is(err, ErrConflict) { - return fmt.Errorf("%s: %w", key, err) - } - ch.logf("%s: closed, left running for heads no candidate holds", key) - } - return nil -} - -// TrunkMoved is Reconsider after a move of a trunk, which first owes mesh/check pending on every open pull request of a -// candidate whose verdict was judged on other trunk heads, every member's for a group (the lead's decision L4, the checker's -// part of issue 1302): the forge's success of the old trunk never stands while the check waits for a place or for a delivery -// that holds it, so the gate never reads it as the head's. -func (ch *Checker) TrunkMoved(ctx context.Context) { - ch.init() - ch.mu.Lock() - known := make(map[string]meshcatalog.CandidatesByGroupValue, len(ch.known)) - for k, c := range ch.known { - known[k] = c - } - ch.mu.Unlock() - heads := ch.heads() - for _, c := range known { - cs := CaseOf(c, heads) - if cs == nil { - continue - } - value, _, found, err := ch.Verdicts.Get(ctx, cs.Key) - if err != nil || !found { - continue // never judged: no status to put out of date - } - v, err := meshdeliverycheckerclient.DecodeVerdict(value) - if err == nil && !ch.stale(v, cs) { - continue - } - if err == nil && v.State == meshdeliverycheckerclient.VerdictPass { - cs.CarriedFrom = judgedOn(v) // the status says it is being carried to the new commit (ADR 0548 §6) - } - ch.writeOwed(ctx, cs, meshdeliverychecker.VerdictsByGroupHeadsValue{State: meshdeliverycheckerclient.VerdictRunning}, Outcome{}) - } - ch.Reconsider(ctx) -} - -// owePending owes mesh/check pending on the heads of a verdict judged on commits that moved while it ran: a pass says it is -// being carried to the trunk's head now (ADR 0548 §6), anything else that it is checked again. -func (ch *Checker) owePending(ctx context.Context, judged *Case, v meshdeliverychecker.VerdictsByGroupHeadsValue) { - next := judged - ckey, err := meshcatalogclient.CandidatesKey(v.Group) - ch.mu.Lock() - c, ok := ch.known[ckey] - ch.mu.Unlock() - if err == nil && ok { - if now := CaseOf(c, ch.heads()); now != nil && now.Key == judged.Key { - next = now - } - } - if v.State == meshdeliverycheckerclient.VerdictPass { - next.CarriedFrom = judgedOn(v) - } - ch.writeOwed(ctx, next, meshdeliverychecker.VerdictsByGroupHeadsValue{State: meshdeliverycheckerclient.VerdictRunning}, Outcome{}) -} - -// movedSince says whether a trunk the case was judged on is no longer the trunk's head. -func (ch *Checker) movedSince(cs *Case) bool { - now := ch.heads() - for repo, head := range cs.Trunk { - if now[repo] != head { - return true - } - } - return false -} - -// awaitRebuilt hears, once per verdict key, the builder's keys of the builds a failed verdict names: when each is written -// done again (builder_build_again), the check of those heads is asked again (claim retakes it), as a failure of the nodes -// is after the nodes changed, so no recheck by hand is needed (ADR 0603 §10). Heard on the builder's own writes, never -// polled; it ends with the checker. -func (ch *Checker) awaitRebuilt(ctx context.Context, group, vkey string, builds map[string]string) { - if ch.Rebuilds == nil { - return - } - ch.mu.Lock() - if ch.awaiting[vkey] { - ch.mu.Unlock() - return - } - ch.awaiting[vkey] = true - ch.mu.Unlock() - ch.wg.Add(1) - go func() { - defer ch.wg.Done() - done := ch.Rebuilds.Done(ctx, builds) - ch.mu.Lock() - delete(ch.awaiting, vkey) - if done { - ch.rebuilt[vkey] = true - } - c, known := ch.known[group] - ch.mu.Unlock() - if done && known && ctx.Err() == nil { - ch.logf("%s: the builds of %s it failed on are done again, so it is checked again (ADR 0603 §10)", vkey, strings.Join(slices.Sorted(maps.Keys(builds)), ", ")) - ch.consider(ctx, group, c) - } - }() -} - -// hearFailedBuilds starts awaitRebuilt for the case's verdict when it names failed builds (failedBuilds). -func (ch *Checker) hearFailedBuilds(ctx context.Context, group string, cs *Case) { - if ch.Rebuilds == nil || ctx.Err() != nil { - return - } - value, _, found, err := ch.Verdicts.Get(ctx, cs.Key) - if err != nil || !found { - return - } - if v, err := meshdeliverycheckerclient.DecodeVerdict(value); err == nil { - if builds := failedBuilds(v, cs); builds != nil { - ch.awaitRebuilt(ctx, group, cs.Key, builds) - } - } -} - -// takeRebuilt says whether every failed build the verdict of vkey names is done again, and forgets it: one retake each. -func (ch *Checker) takeRebuilt(vkey string) bool { - ch.mu.Lock() - defer ch.mu.Unlock() - was := ch.rebuilt[vkey] - delete(ch.rebuilt, vkey) - return was -} - -// containsWords says whether words hold the given words. -func containsWords(words, part string) bool { return strings.Contains(words, part) } diff --git a/modules/mesh-delivery-checker/internal/check/checker_test.go b/modules/mesh-delivery-checker/internal/check/checker_test.go deleted file mode 100644 index 0d48110d..00000000 --- a/modules/mesh-delivery-checker/internal/check/checker_test.go +++ /dev/null @@ -1,761 +0,0 @@ -package check - -import ( - "context" - "encoding/json" - "errors" - "fmt" - "strings" - "sync" - "testing" - "time" - - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-builder/buildrun" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshdeliverycheckerclient" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshdeliveryclient" - "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/meshdeliverychecker" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep" - "git.novox.be/novox/mesh-sdk/go/keys" -) - -const hqRepo = "novox/hq" - -const ( - repoA = "novox/mesh-delivery" - repoSDK = "novox/mesh-sdk" - head1 = "1111111111111111111111111111111111111111" - head2 = "2222222222222222222222222222222222222222" - trunkA = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" - trunkA2 = "abababababababababababababababababababab" - trunkS = "5555555555555555555555555555555555555555" - trunkS2 = "5656565656565656565656565656565656565656" -) - -// candidateOf is a candidate of a group with the given pull requests, as the indexer writes one. -func candidateOf(t testing.TB, group string, pulls ...meshcatalog.CandidatesByGroupValuePullsItem) []byte { - t.Helper() - heads := make([]meshdeliveryclient.Head, len(pulls)) - for i, p := range pulls { - heads[i] = meshdeliveryclient.Head{Repository: p.Repository, Number: int(p.Number), Head: p.Head} - } - hash, err := meshdeliveryclient.HeadsHash(heads) - if err != nil { - t.Fatal(err) - } - c := meshcatalog.CandidatesByGroupValue{V: keys.Version, Group: group, Heads: hash, Pulls: pulls, Fpset: meshcatalogclient.FingerprintSet(pulls)} - data, err := json.Marshal(c) - if err != nil { - t.Fatal(err) - } - return data -} - -func pullOf(repo string, number int, head string) meshcatalog.CandidatesByGroupValuePullsItem { - return meshcatalog.CandidatesByGroupValuePullsItem{Repository: repo, Number: int64(number), Head: head, Modules: []string{}} -} - -// newRepoPullOf is a pull request of a new repository of the mesh: its trunk not named yet, its first module added. -func newRepoPullOf(repo string, number int, head string) meshcatalog.CandidatesByGroupValuePullsItem { - p := pullOf(repo, number, head) - p.Modules = []string{"mod-u"} - return p -} - -// judgeFunc is a Judge written as a function; it counts its calls. -type judgeFunc struct { - mu sync.Mutex - calls int - f func(ctx context.Context, c *Case, call int) (Outcome, error) -} - -func (j *judgeFunc) Judge(ctx context.Context, c *Case) (Outcome, error) { - j.mu.Lock() - j.calls++ - n := j.calls - j.mu.Unlock() - return j.f(ctx, c, n) -} - -func (j *judgeFunc) count() int { j.mu.Lock(); defer j.mu.Unlock(); return j.calls } - -func passing() meshdeliverychecker.VerdictsByGroupHeadsValue { - return meshdeliverychecker.VerdictsByGroupHeadsValue{State: meshdeliverycheckerclient.VerdictPass, Levels: map[string]meshdeliverychecker.VerdictsByGroupHeadsValueLevelsValue{ - buildstep.LevelUnit: {Run: 2, Kept: 3}, buildstep.LevelIntegration: {Run: 1}}} -} - -func passJudge() *judgeFunc { - return &judgeFunc{f: func(context.Context, *Case, int) (Outcome, error) { return Outcome{Verdict: passing()}, nil }} -} - -type rig struct { - ch *Checker - verdicts *memKV - owed *memKV - trunks *Trunks -} - -func newRig(t testing.TB, j Judge) *rig { - t.Helper() - r := &rig{verdicts: newMemKV(), owed: newMemKV(), trunks: &Trunks{}} - r.setTrunks(t, map[string]string{repoA: trunkA, repoSDK: trunkS}) - r.ch = &Checker{Verdicts: r.verdicts, Owed: r.owed, Judge: j, Trunks: r.trunks, Link: "https://view.invalid/checks", Now: time.Now} - return r -} - -func (r *rig) setTrunks(t testing.TB, heads map[string]string) bool { - t.Helper() - return r.trunks.Set(heads) -} - -func (r *rig) verdict(t testing.TB, key string) meshdeliverychecker.VerdictsByGroupHeadsValue { - t.Helper() - raw, _, found, _ := r.verdicts.Get(context.Background(), key) - if !found { - t.Fatalf("no verdict %s; the bucket holds %v", key, r.verdicts.vals) - } - v, err := meshdeliverycheckerclient.DecodeVerdict(raw) - if err != nil { - t.Fatal(err) - } - return v -} - -func keyOf(t testing.TB, group string, value []byte) string { - t.Helper() - c, err := meshcatalog.DecodeCandidatesByGroupValue(value) - if err != nil { - t.Fatal(err) - } - k, err := meshdeliverycheckerclient.VerdictKey(group, c.Heads) - if err != nil { - t.Fatal(err) - } - return k -} - -func TestACandidateNotYetCheckedGetsItsVerdictKeyCreatedOnceAndIsJudged(t *testing.T) { // N6/AC1, 1678 - ctx, j := context.Background(), passJudge() - r := newRig(t, j) - cand := candidateOf(t, "feat/x", pullOf(repoA, 7, head1)) - r.ch.Candidate(ctx, "feat%2Fx", cand) - r.ch.Wait() - key := keyOf(t, "feat/x", cand) - if v := r.verdict(t, key); v.State != meshdeliverycheckerclient.VerdictPass || v.Group != "feat/x" || v.Trunk[repoA] != trunkA { - t.Fatalf("verdict = %+v", v) - } - if r.verdicts.creates[key] != 1 || j.count() != 1 { - t.Errorf("creates = %d, judged = %d, want one each", r.verdicts.creates[key], j.count()) - } - // The same candidate heard again, with nothing changed, is not judged again. - r.ch.Candidate(ctx, "feat%2Fx", cand) - r.ch.Wait() - if j.count() != 1 { - t.Errorf("judged %d times after the same candidate again, want once", j.count()) - } - // The candidate of a whole try's group is the try's: the try judges it, never the checker as a pull request's check. - r.ch.Candidate(ctx, "try-1793913602402800439", candidateOf(t, "try-1793913602402800439", pullOf(repoA, 7, head1))) - r.ch.Wait() - if j.count() != 1 { - t.Errorf("a try's candidate was judged as a check: %d judgments, want one", j.count()) - } -} - -// racyKV lets another instance create the key just before this one's create. -type racyKV struct { - *memKV - other []byte -} - -func (r racyKV) Create(ctx context.Context, key string, value []byte) (uint64, error) { - if r.other != nil { - _, _ = r.memKV.Create(ctx, key, r.other) - } - return r.memKV.Create(ctx, key, value) -} - -func TestASecondInstancesCreateIsRefusedAndItDoesNothing(t *testing.T) { // N6/AC1 - ctx, j := context.Background(), passJudge() - r := newRig(t, j) - cand := candidateOf(t, "feat/x", pullOf(repoA, 7, head1)) - key := keyOf(t, "feat/x", cand) - other, _ := meshdeliverycheckerclient.EncodeVerdict(meshdeliverychecker.VerdictsByGroupHeadsValue{Group: "feat/x", Heads: strings.SplitN(key, ".", 2)[1], State: meshdeliverycheckerclient.VerdictRunning}) - r.ch.Verdicts = racyKV{r.verdicts, other} - r.ch.Candidate(ctx, "feat%2Fx", cand) - r.ch.Wait() - if j.count() != 0 { - t.Errorf("the instance that lost the create judged %d times, want none", j.count()) - } - if v := r.verdict(t, key); v.State != meshdeliverycheckerclient.VerdictRunning { - t.Errorf("the other instance's key was changed: %+v", v) - } -} - -func TestARestartWithARunningKeyJudgesItAgain(t *testing.T) { // N6/AC2 - ctx, j := context.Background(), passJudge() - r := newRig(t, j) - cand := candidateOf(t, "feat/x", pullOf(repoA, 7, head1)) - key := keyOf(t, "feat/x", cand) - left, _ := meshdeliverycheckerclient.EncodeVerdict(meshdeliverychecker.VerdictsByGroupHeadsValue{Group: "feat/x", Heads: strings.SplitN(key, ".", 2)[1], Trunk: map[string]string{repoA: trunkA}, State: meshdeliverycheckerclient.VerdictRunning}) - if _, err := r.verdicts.Create(ctx, key, left); err != nil { - t.Fatal(err) - } - r.ch.Candidate(ctx, "feat%2Fx", cand) - r.ch.Wait() - if j.count() != 1 || r.verdict(t, key).State != meshdeliverycheckerclient.VerdictPass { - t.Fatalf("judged %d times, verdict %+v, want the left check judged once and passed", j.count(), r.verdict(t, key)) - } -} - -func TestACheckPastItsBoundFailsNamingTheStuckStep(t *testing.T) { // N6/AC3 - ctx := context.Background() - j := &judgeFunc{f: func(ctx context.Context, c *Case, _ int) (Outcome, error) { - c.Progress.Set("test the unit level of mesh-delivery", "shanks") - <-ctx.Done() - return Outcome{}, ctx.Err() - }} - r := newRig(t, j) - r.ch.Bound = 30 * time.Millisecond - cand := candidateOf(t, "feat/x", pullOf(repoA, 7, head1)) - r.ch.Candidate(ctx, "feat%2Fx", cand) - r.ch.Wait() - v := r.verdict(t, keyOf(t, "feat/x", cand)) - if v.State != meshdeliverycheckerclient.VerdictFail || v.Failed.Machine != "shanks" || !strings.Contains(v.Failed.Words, "stuck at: test the unit level of mesh-delivery") { - t.Fatalf("verdict = %+v, want a failure naming shanks and the stuck step", v) - } -} - -// findingsKept is a FindingWriter that keeps what is written, by ID. -type findingsKept map[string]Finding - -func (f findingsKept) Put(x Finding) error { f[x.ID] = x; return nil } -func (f findingsKept) Delete(x Finding) error { delete(f, x.ID); return nil } - -// A check that could not hear a part of the mesh says `could not run`, naming the part, and releases its claim; only the -// running of that part asks it again, once per heads and part at one fingerprint; not asked again within an hour it is the -// finding check-could-not-run, which clears when the heads are checked again, replaced, or their pull request closes -// (design 47 test 58, issue 1373; issue 1912: no check fails for want of a build node). -func TestACheckThatCouldNotRunIsAskedAgainWhenItsPartRuns(t *testing.T) { // N6/AC4, 47/58 - ctx := context.Background() - unheard := Part{Node: "g14", Module: "forge"} - newCase := func(t *testing.T, fails int) (*rig, *judgeFunc, findingsKept, *time.Time) { - j := &judgeFunc{f: func(_ context.Context, _ *Case, n int) (Outcome, error) { - if n <= fails { - return Outcome{Verdict: failure("the forge", "novox/mesh-delivery#7: go.mod cannot be read: no responders (the forge was "+UnheardWords+")"), Unheard: unheard}, nil - } - return Outcome{Verdict: passing()}, nil - }} - r := newRig(t, j) - found, now := findingsKept{}, time.Date(2026, 11, 9, 20, 0, 0, 0, time.UTC) - r.ch.CouldNotRun, r.ch.Findings, r.ch.Now = newMemKV(), found, func() time.Time { return now } - return r, j, found, &now - } - cand := candidateOf(t, "feat/x", pullOf(repoA, 7, head1)) - key := keyOf(t, "feat/x", cand) - for name, run := range map[string]func(t *testing.T){ - "it says could not run, naming the part, and only its running asks it again, once per fingerprint": func(t *testing.T) { - r, j, _, _ := newCase(t, 2) - r.ch.Candidate(ctx, "feat%2Fx", cand) - r.ch.Wait() - if v := r.verdict(t, key); !IsCouldNotRun(v) || !strings.Contains(v.Failed.Words, "could not run") { - t.Fatalf("verdict = %+v, want could not run", v) - } - if rec, _, ok := r.ch.couldNotRunOf(ctx, key); !ok || rec.Part != unheard || rec.AskedAt != "" { - t.Fatalf("could-not-run.%s = %+v (%v), want the part %v", key, rec, ok, unheard) - } - r.ch.Reconsider(ctx) // nothing ran: not asked again - r.ch.NodesChanged(ctx) - r.ch.PartRunning(ctx, "g14", "mail", "src2:1") // another part ran - r.ch.Wait() - if j.count() != 1 { - t.Fatalf("judged %d times before its part ran, want once", j.count()) - } - r.ch.PartRunning(ctx, "g14", "forge", "src2:1") - r.ch.Wait() - r.ch.PartRunning(ctx, "g14", "forge", "src2:1") // the same part at the same fingerprint asks nothing more - r.ch.Wait() - if j.count() != 2 { - t.Fatalf("judged %d times after its part ran twice at one fingerprint, want twice", j.count()) - } - if rec, _, _ := r.ch.couldNotRunOf(ctx, key); rec.AskedAt != runningAt("g14", "forge", "src2:1") { - t.Fatalf("asked-at = %q after it could not run again", rec.AskedAt) - } - r.ch.PartRunning(ctx, "g14", "forge", "src2:2") // a new build of the part asks once more - r.ch.Wait() - if j.count() != 3 || r.verdict(t, key).State != meshdeliverycheckerclient.VerdictPass { - t.Fatalf("judged %d times, verdict %+v, want a pass on the third", j.count(), r.verdict(t, key)) - } - if _, _, ok := r.ch.couldNotRunOf(ctx, key); ok { - t.Error("checked again, the record that it could not run is kept") - } - }, - "not asked again within the hour it is a finding, cleared when it is checked again": func(t *testing.T) { - r, _, found, now := newCase(t, 1) - r.ch.Candidate(ctx, "feat%2Fx", cand) - r.ch.Wait() - if due := r.ch.CouldNotRunDue(ctx, now.Add(59*time.Minute)); !due.Equal(now.Add(CouldNotRunBound)) || len(found) != 0 { - t.Fatalf("before its bound: due %v, findings %v", due, found) - } - if due := r.ch.CouldNotRunDue(ctx, now.Add(CouldNotRunBound)); !due.IsZero() || found[key].Kind != CouldNotRunKind || !strings.Contains(found[key].Summary, "forge on g14") { - t.Fatalf("at its bound: due %v, findings %+v, want %s naming the part", due, found, CouldNotRunKind) - } - if observed, err := r.ch.RaisedCouldNotRun(ctx); err != nil || len(observed) != 1 || observed[0].Kind != CouldNotRunKind || observed[0].ID != key { - t.Fatalf("observed at its bound = %+v, %v, want its one finding, for the finding writer's statement", observed, err) - } - r.ch.PartRunning(ctx, "g14", "forge", "src2:1") - r.ch.Wait() - if observed, _ := r.ch.RaisedCouldNotRun(ctx); len(found) != 0 || len(observed) != 0 { - t.Errorf("checked again, the finding stays: %v, observed %v", found, observed) - } - }, - "its heads replaced, or its pull request closed, the record and the finding go": func(t *testing.T) { - r, _, found, now := newCase(t, 1) - r.ch.Candidate(ctx, "feat%2Fx", cand) - r.ch.Wait() - r.ch.CouldNotRunDue(ctx, now.Add(CouldNotRunBound)) - r.ch.Candidate(ctx, "feat%2Fx", candidateOf(t, "feat/x", pullOf(repoA, 7, head2))) - r.ch.Wait() - if _, _, ok := r.ch.couldNotRunOf(ctx, key); ok || len(found) != 0 { - t.Fatalf("heads replaced: record kept %v, findings %v", ok, found) - } - r2, _, found2, now2 := newCase(t, 1) - r2.ch.Candidate(ctx, "feat%2Fx", cand) - r2.ch.Wait() - r2.ch.CouldNotRunDue(ctx, now2.Add(CouldNotRunBound)) - r2.ch.Forget("feat%2Fx") - if _, _, ok := r2.ch.couldNotRunOf(ctx, key); ok || len(found2) != 0 { - t.Fatalf("pull request closed: record kept %v, findings %v", ok, found2) - } - }, - } { - t.Run(name, run) - } -} - -// Issue 1422: a pull request of a repository the gate's source.main names no trunk head of (one never merged through the -// gate) is never dropped silently. It is not judged, its verdict says it cannot be judged and why, its status is error with -// those words, checker_status names it, and the log says it once per head. Once its trunk head is known it is judged whole; -// in a group, the members whose trunk is known are judged and the others' status says why they are not. -func TestARepositoryWithNoTrunkCannotBeJudgedLoudlyUntilItsTrunkIsKnown(t *testing.T) { // N6/AC6, ADR 0484 clause 11, 1422 - ctx, j := context.Background(), passJudge() - r := newRig(t, j) - var logged []string - r.ch.Logf = func(f string, a ...any) { logged = append(logged, fmt.Sprintf(f, a...)) } - const unknown = "novox/unknown" - cand := candidateOf(t, "feat/y", newRepoPullOf(unknown, 4, head1)) - key := keyOf(t, "feat/y", cand) - r.ch.Candidate(ctx, "feat/y", cand) - r.ch.Wait() - r.ch.Reconsider(ctx) // looked at again: nothing is written or said twice - r.ch.NodesChanged(ctx) - r.ch.Wait() - v := r.verdict(t, key) - if j.count() != 0 || !IsUntrunked(v) || !strings.Contains(v.Failed.Words, "the trunk head of "+unknown+" is not known") { - t.Fatalf("judged %d times, verdict %+v, want none judged and a verdict that says it cannot be judged", j.count(), v) - } - if s := owedState(t, r, unknown, 4, head1); s != "error" { - t.Errorf("%s#4 owes %q, want error", unknown, s) - } - if n := countWith(logged, "cannot be judged"); n != 1 { - t.Errorf("said %d times in the log, want once for the head: %q", n, logged) - } - reader := func() Reader { - ckey, _ := meshcatalogclient.CandidatesKey("feat/y") - return Reader{CandidateState: fakeState{ckey: cand}.read(), VerdictState: fakeState(r.verdicts.vals).read(), - Trunks: func() (map[string]string, error) { return r.trunks.Heads(), nil }} - } - st, err := reader().Status() - if err != nil { - t.Fatal(err) - } - if why := st.CannotBeJudged["feat/y"]; !strings.Contains(why, unknown) || len(st.Waiting[KindNew]) != 0 || len(st.Unjudged) != 0 { - t.Errorf("cannot_be_judged %v, waiting %v, unjudged %v: want feat/y named as cannot be judged, not as new", st.CannotBeJudged, st.Waiting, st.Unjudged) - } - if rows, _, err := reader().Verdicts("feat/y"); err != nil || len(rows) != 1 || !strings.Contains(rows[0].Reports[unknown+"#4"], "cannot be judged") { - t.Errorf("checker_verdicts %+v (%v), want the report of %s#4 to say it cannot be judged", rows, err, unknown) - } - - // Its trunk head becomes known: the heads are judged whole, the same key rewritten, the status success. - r.setTrunks(t, map[string]string{repoA: trunkA, repoSDK: trunkS, unknown: trunkA2}) - r.ch.TrunkMoved(ctx) - r.ch.Wait() - if v := r.verdict(t, key); j.count() != 1 || v.State != meshdeliverycheckerclient.VerdictPass || v.Trunk[unknown] != trunkA2 { - t.Errorf("judged %d times, verdict %+v, want one pass on %s", j.count(), v, trunkA2) - } - if s := owedState(t, r, unknown, 4, head1); s != "success" { - t.Errorf("%s#4 owes %q once its trunk is known, want success", unknown, s) - } - - // Issue 1733: the gate asks the Approve only on a verdict, so no candidate is left without one. A group with a member - // whose trunk is not known is not judged in part: its verdict fails naming that repository, and every status says so; a - // running verdict left for heads that cannot be judged is replaced; a verdict key deleted is judged again on its delete. - for _, row := range []struct { - name string - pulls []meshcatalog.CandidatesByGroupValuePullsItem - running bool // a running verdict is left under the key first - deleted bool // the key is deleted after its verdict - judged int - want string // the verdict's state, and for a failure the repository it names - }{ - {name: "a member the checker cannot claim", pulls: []meshcatalog.CandidatesByGroupValuePullsItem{pullOf(repoA, 9, head2), pullOf("novox/other", 2, head2)}, want: "novox/other"}, - {name: "a running verdict left for heads that cannot be judged", pulls: []meshcatalog.CandidatesByGroupValuePullsItem{newRepoPullOf(unknown, 5, head2)}, running: true, want: unknown}, - {name: "a verdict key deleted", pulls: []meshcatalog.CandidatesByGroupValuePullsItem{pullOf(repoA, 5, head2)}, deleted: true, judged: 2, want: meshdeliverycheckerclient.VerdictPass}, - } { - t.Run(row.name, func(t *testing.T) { - j := passJudge() - r := newRig(t, j) - cand := candidateOf(t, "feat/z", row.pulls...) - key := keyOf(t, "feat/z", cand) - if row.running { - group, heads, _ := meshdeliverycheckerclient.ParseVerdictKey(key) - raw, _ := meshdeliverycheckerclient.EncodeVerdict(meshdeliverychecker.VerdictsByGroupHeadsValue{Group: group, Heads: heads, State: meshdeliverycheckerclient.VerdictRunning}) - _, _ = r.verdicts.Create(ctx, key, raw) - } - r.ch.Candidate(ctx, "feat%2Fz", cand) - r.ch.Wait() - if row.deleted { - _ = r.verdicts.Delete(ctx, key) - r.ch.VerdictDeleted(ctx, key) // the watch of the verdicts hands the delete over - r.ch.Wait() - } - v := r.verdict(t, key) - if row.want == meshdeliverycheckerclient.VerdictPass { - if v.State != meshdeliverycheckerclient.VerdictPass || j.count() != row.judged { - t.Errorf("verdict %s after %d judgings, want a pass after %d", v.State, j.count(), row.judged) - } - return - } - if !IsUntrunked(v) || !strings.Contains(v.Failed.Words, row.want) || j.count() != 0 { - t.Errorf("verdict %+v after %d judgings, want a failure naming %s and none judged", v, j.count(), row.want) - } - for _, p := range row.pulls { - if s := owedState(t, r, p.Repository, int(p.Number), p.Head); s != "error" { - t.Errorf("%s#%d owes %q, want error", p.Repository, p.Number, s) - } - } - }) - } - - // ADR 0664 §5 (issue 1748): a candidate taken out (its pull request merged or closed) ends the check running for it with a - // cause its asks' wait names, never a plain cancel, so its asker drops the asks it put on the build nodes. - t.Run("a candidate taken out ends its check with a named cause", func(t *testing.T) { - ch := &Checker{} - ch.init() - run, end := context.WithCancelCause(context.Background()) - ch.live["g.heads"] = liveCheck{group: "g", end: end} - // The check's asker is waiting on an ask of its run when the candidate goes (review 1, finding 7). - drops := &checkDrops{} - fake := &buildrun.FakeAsks{} - done := make(chan struct{}) - go func() { - defer close(done) - (buildrun.Asker{Seats: testSeats(), Publisher: fake, Waiter: fake, Bound: time.Hour, Dropper: drops}).Wait(run, buildstep.StepAsk{ID: "mvl0frv18d2000", Language: buildstep.AskGo, Kind: buildstep.AskCheck}) - }() - ch.Forget("g") - <-done - var s superseded - if cause := context.Cause(run); !errors.As(cause, &s) || s.by != "" || errors.Is(cause, context.Canceled) { - t.Errorf("the check was ended with %v, want superseded with no heads, not a plain cancel", cause) - } - if len(drops.got) != 1 || !strings.Contains(drops.got[0], "mvl0frv18d2000") || !strings.Contains(drops.got[0], "no candidate holds these heads") { - t.Errorf("the asker dropped %q, want its ask withdrawn with the check's cause", drops.got) - } - }) -} - -// checkDrops keeps the asks an asker dropped: " ". -type checkDrops struct{ got []string } - -func (d *checkDrops) DropAsk(_ context.Context, a buildstep.StepAsk, why string) error { - d.got = append(d.got, a.ID+" "+why) - return nil -} - -func countWith(lines []string, words string) int { - n := 0 - for _, l := range lines { - if strings.Contains(l, words) { - n++ - } - } - return n -} - -// 1887/A10, ADR 0527 §2: hq is judged as any repository, its checks Go tests, and its pull request gets a verdict and a -// mesh/check; in a group, hq's member is judged with the others. -func TestAnHqPullRequestGetsAVerdictAndAStatus(t *testing.T) { - ctx, j := context.Background(), passJudge() - r := newRig(t, j) - r.setTrunks(t, map[string]string{repoA: trunkA, repoSDK: trunkS, hqRepo: trunkA2}) - r.ch.Candidate(ctx, "feat/hq", candidateOf(t, "feat/hq", pullOf(hqRepo, 3, head1))) - r.ch.Wait() - if j.count() != 1 || len(r.verdicts.vals) != 1 { - t.Fatalf("judged %d times, %d verdicts, want one", j.count(), len(r.verdicts.vals)) - } - if s := owedState(t, r, hqRepo, 3, head1); s != "success" { - t.Errorf("hq#3 owes %q, want success", s) - } - r.ch.Candidate(ctx, "feat/x", candidateOf(t, "feat/x", pullOf(hqRepo, 4, head2), pullOf(repoA, 7, head2))) - r.ch.Wait() - if s := owedState(t, r, hqRepo, 4, head2); s != "success" { - t.Errorf("hq#4 in a group owes %q, want success", s) - } -} - -func TestATrunkMoveRewritesTheSameVerdictKeyAndTheHeadsStatus(t *testing.T) { // 1300/AC7 - ctx, j := context.Background(), passJudge() - r := newRig(t, j) - cand := candidateOf(t, "feat/x", pullOf(repoA, 7, head1)) - key := keyOf(t, "feat/x", cand) - r.ch.Candidate(ctx, "feat%2Fx", cand) - r.ch.Wait() - _, rev1, _, _ := r.verdicts.Get(ctx, key) - owedKey, _ := CheckerOwedKey(repoA, 7, head1) - _, orev1, _, _ := r.owed.Get(ctx, owedKey) - if !r.setTrunks(t, map[string]string{repoA: trunkA2, repoSDK: trunkS}) { - t.Fatal("the trunks did not change") - } - r.ch.Reconsider(ctx) - r.ch.Wait() - _, rev2, _, _ := r.verdicts.Get(ctx, key) - if j.count() != 2 || rev2 <= rev1 || r.verdict(t, key).Trunk[repoA] != trunkA2 { - t.Fatalf("judged %d times, revisions %d then %d, trunk %v", j.count(), rev1, rev2, r.verdict(t, key).Trunk) - } - if r.verdicts.creates[key] != 1 { - t.Errorf("the key was created %d times, want the same key rewritten", r.verdicts.creates[key]) - } - if _, orev2, _, _ := r.owed.Get(ctx, owedKey); orev2 <= orev1 { - // the line is the same when nothing differs; the status is rewritten when the words change, here the trunk is in them - t.Logf("the status keeps revision %d (its words did not change)", orev2) - } - // A new head is another key, and the older head's status is not touched. - older, _, _, _ := r.owed.Get(ctx, owedKey) - cand2 := candidateOf(t, "feat/x", pullOf(repoA, 7, head2)) - r.ch.Candidate(ctx, "feat%2Fx", cand2) - r.ch.Wait() - if again, _, _, _ := r.owed.Get(ctx, owedKey); string(again) != string(older) { - t.Errorf("the older head's status was rewritten") - } - if n := len(r.owed.vals); n != 2 { - t.Errorf("%d statuses, want one for each head", n) - } -} - -func TestTheStatusIsPendingWhileTheCheckRunsAndEndsSuccessOrFailure(t *testing.T) { // 1300/AC5 (unit part) - ctx := context.Background() - var seen []string - var r *rig - j := &judgeFunc{f: func(ctx context.Context, c *Case, _ int) (Outcome, error) { - key, _ := CheckerOwedKey(repoA, 7, head1) - raw, _, _, _ := r.owed.Get(ctx, key) - o, _ := DecodeCheckerOwed(raw) - seen = append(seen, o.State) - c.series(repoA+"#7", []string{"web/pkg series 0.1 → 0.2"}, []meshdeliverychecker.VerdictsByGroupHeadsValueSeriesItem{{Module: "web", Artifact: "pkg", From: "0.1", To: "0.2"}}) - return Outcome{Verdict: meshdeliverychecker.VerdictsByGroupHeadsValue{State: meshdeliverycheckerclient.VerdictFail, Failed: &FailedFirst{Test: "m/a.TestX"}}, - OutOfStep: map[string][]string{repoA + "#7": {"go/seats/x/contract.go"}}}, nil - }} - r = newRig(t, j) - says := &verdictsSaid{} - r.ch.Says = says - r.ch.Candidate(ctx, "feat/x", candidateOf(t, "feat/x", pullOf(repoA, 7, head1))) - r.ch.Wait() - key, _ := CheckerOwedKey(repoA, 7, head1) - raw, _, _, _ := r.owed.Get(ctx, key) - o, err := DecodeCheckerOwed(raw) - if err != nil { - t.Fatal(err) - } - if len(seen) != 1 || seen[0] != "pending" || o.State != "failure" || o.Context != meshdeliveryclient.StatusContextCheck || !strings.HasPrefix(o.Target, "https://view.invalid/checks/") { - t.Errorf("while running %v, at the end %+v", seen, o) - } - // DLV-C2 (design 26 *Out of step*): the check's end says one verdict event for the pull request, naming its out-of-step - // files; the running status says none. - if len(says.said) != 1 || says.said[0].Repository != repoA || says.said[0].Pull != 7 || says.said[0].Head != head1 || - says.said[0].Verdict != meshdeliverycheckerclient.VerdictFail || strings.Join(says.said[0].OutOfStep, ",") != "go/seats/x/contract.go" || - // The join (A2j finding 2): and its series changes, as the seat's event names them. - len(says.said[0].Series) != 1 || says.said[0].Series[0] != (meshdeliverychecker.VerdictHolderEventSeriesItem{Module: "web", Artifact: "pkg", From: "0.1", To: "0.2"}) { - t.Errorf("verdict events %+v", says.said) - } -} - -// verdictsSaid is a VerdictSayer that keeps what it was told. -type verdictsSaid struct { - mu sync.Mutex - said []VerdictEvent -} - -func (s *verdictsSaid) Say(_ context.Context, v VerdictEvent) error { - s.mu.Lock() - defer s.mu.Unlock() - s.said = append(s.said, v) - return nil -} - -// No check of heads no candidate holds is left running (issue 1890): at start the sweep ends a key left running; while the -// checker runs, a check whose group moved to other heads is ended at once, unjudged, and writes no status; heads held again -// are checked whole; and a group's check starts only once its heads settled, so a partial set of members is never checked. -func TestHeadsNoCandidateHoldsAreNeverLeftRunning(t *testing.T) { - ctx, j := context.Background(), passJudge() - r := newRig(t, j) - cand := candidateOf(t, "feat/x", pullOf(repoA, 7, head1)) - live := keyOf(t, "feat/x", cand) - dead, _ := meshdeliverycheckerclient.VerdictKey("feat/gone", "0123456789ab") - for _, k := range []string{live, dead} { - group, heads, _ := meshdeliverycheckerclient.ParseVerdictKey(k) - raw, _ := meshdeliverycheckerclient.EncodeVerdict(meshdeliverychecker.VerdictsByGroupHeadsValue{Group: group, Heads: heads, State: meshdeliverycheckerclient.VerdictRunning}) - _, _ = r.verdicts.Create(ctx, k, raw) - } - r.ch.init() - var c meshcatalog.CandidatesByGroupValue - _ = json.Unmarshal(cand, &c) - r.ch.known["feat%2Fx"] = c - if err := r.ch.Sweep(ctx); err != nil { - t.Fatal(err) - } - if v := r.verdict(t, dead); !IsEnded(v) || !strings.Contains(v.Failed.Words, "closed at start") { - t.Errorf("the dead key = %+v", v) - } - if v := r.verdict(t, live); v.State != meshdeliverycheckerclient.VerdictRunning { - t.Errorf("the live key = %+v, want it left for the check to take over", v) - } - - // A member joins while the check of the lone member's heads runs: that check is ended, its judge's run cancelled. - started, ended := make(chan struct{}), make(chan error, 1) - j = &judgeFunc{f: func(run context.Context, _ *Case, call int) (Outcome, error) { - if call == 1 { - close(started) - <-run.Done() - ended <- context.Cause(run) - return Outcome{}, run.Err() - } - return Outcome{Verdict: passing()}, nil - }} - r = newRig(t, j) - var logged []string - var logMu sync.Mutex - r.ch.Logf = func(f string, a ...any) { logMu.Lock(); logged = append(logged, fmt.Sprintf(f, a...)); logMu.Unlock() } - alone, both := cand, candidateOf(t, "feat/x", pullOf(repoA, 7, head1), pullOf(repoSDK, 3, head2)) - r.ch.Candidate(ctx, "feat%2Fx", alone) - <-started - r.ch.Candidate(ctx, "feat%2Fx", both) - var bothC meshcatalog.CandidatesByGroupValue - _ = json.Unmarshal(both, &bothC) - select { - case err := <-ended: - if err == nil || !strings.Contains(err.Error(), "superseded by "+GateHeads(bothC)) { - t.Errorf("the old check's run ended with %v", err) - } - case <-time.After(5 * time.Second): - t.Fatal("the check of the heads the candidate left still runs") - } - r.ch.Wait() - if v := r.verdict(t, live); !IsEnded(v) || v.Failed.Words != EndedWords+"superseded by "+GateHeads(bothC) { - t.Errorf("the superseded verdict = %+v", v.Failed) - } - if v := r.verdict(t, keyOf(t, "feat/x", both)); v.State != meshdeliverycheckerclient.VerdictPass { - t.Errorf("the group's verdict = %s", v.State) - } - okey, _ := CheckerOwedKey(repoA, 7, head1) - if raw, _, _, _ := r.owed.Get(ctx, okey); !strings.Contains(string(raw), `"success"`) { - t.Errorf("the head's status = %s, want the group's success, never the ended check's", raw) - } - logMu.Lock() - said := 0 - for _, l := range logged { - if strings.Contains(l, "ended: superseded") { - said++ - } - } - logMu.Unlock() - if said != 1 { - t.Errorf("the end was said %d times: %v", said, logged) - } - // The member leaves again: the ended heads are held again and checked whole. - r.ch.Candidate(ctx, "feat%2Fx", alone) - r.ch.Wait() - if v := r.verdict(t, live); v.State != meshdeliverycheckerclient.VerdictPass || j.count() != 3 { - t.Errorf("the heads held again = %s after %d judgings, want a pass of a third", v.State, j.count()) - } - - // Members announced one after another: only the settled, whole set is checked. - j = passJudge() - r = newRig(t, j) - r.ch.Settle = time.Hour - sdk := candidateOf(t, "feat/y", pullOf(repoSDK, 4, head2)) - whole := candidateOf(t, "feat/y", pullOf(repoSDK, 4, head2), pullOf(repoA, 8, head1)) - r.ch.Candidate(ctx, "feat%2Fy", sdk) - r.ch.Candidate(ctx, "feat%2Fy", whole) - r.ch.Reconsider(ctx) // a trunk move or a turn while the heads settle starts nothing - if j.count() != 0 { - t.Fatalf("judged %d times before the heads settled", j.count()) - } - r.ch.settleNow() - r.ch.Wait() - if _, _, found, _ := r.verdicts.Get(ctx, keyOf(t, "feat/y", sdk)); found || j.count() != 1 { - t.Errorf("the partial set has a verdict (%v) or the judge ran %d times, want the whole set alone", found, j.count()) - } - if v := r.verdict(t, keyOf(t, "feat/y", whole)); v.State != meshdeliverycheckerclient.VerdictPass { - t.Errorf("the whole set = %s", v.State) - } -} - -func TestTheForgeBridgeIsToldOnceForEachChangeOfAStatus(t *testing.T) { // 1683 (the checker's half of AC5) - ctx, j := context.Background(), passJudge() - r := newRig(t, j) - var told []string - r.ch.Announce = func(_ context.Context, event, key string) { told = append(told, event+" "+key) } - cand := candidateOf(t, "feat/x", pullOf(repoA, 7, head1)) - r.ch.Candidate(ctx, "feat%2Fx", cand) - r.ch.Wait() - key, _ := CheckerOwedKey(repoA, 7, head1) - want := []string{EventOwedWritten + " " + key, EventOwedWritten + " " + key} // pending, then success - if len(told) != 2 || told[0] != want[0] || told[1] != want[1] { - t.Fatalf("told %v, want the status said when pending and when success", told) - } - r.ch.Candidate(ctx, "feat%2Fx", cand) // nothing changed: nothing written, nothing said - r.ch.Wait() - if len(told) != 2 { - t.Errorf("told %v after a check that changed nothing", told) - } -} - -// Sweep 2026-10-30 item 7: a pull request of a repository the mesh does not deliver (an operator's own, on the same -// forge) touches no module and its trunk the gate never names. It is outside the mesh: no verdict, no status owed (one -// owed before is taken away, so the forge module stops writing it into a repository the mesh may not write), said once. -func TestACandidateOutsideTheMeshIsJudgedNothingAndOwesNothing(t *testing.T) { - ctx, j := context.Background(), passJudge() - r := newRig(t, j) - var logged []string - r.ch.Logf = func(f string, a ...any) { logged = append(logged, fmt.Sprintf(f, a...)) } - const theirs = "someone/own-app" - okey, _ := CheckerOwedKey(theirs, 55, head1) - before, _ := EncodeCheckerOwed(meshdeliverychecker.OwedByRepositoryNumberHeadActValue{Act: meshdeliveryclient.OwedStatus, Context: meshdeliveryclient.StatusContextCheck, State: "error", Text: "cannot be judged"}) - if _, err := r.owed.Create(ctx, okey, before); err != nil { - t.Fatal(err) - } - cand := candidateOf(t, "feat/theirs", pullOf(theirs, 55, head1)) - key := keyOf(t, "feat/theirs", cand) - r.ch.Candidate(ctx, "feat/theirs", cand) - r.ch.Wait() - r.ch.Reconsider(ctx) - r.ch.Wait() - if _, _, found, _ := r.verdicts.Get(ctx, key); found || j.count() != 0 { - t.Errorf("a candidate outside the mesh was judged (%d) or given a verdict (%v)", j.count(), found) - } - if s := owedState(t, r, theirs, 55, head1); s != "" { - t.Errorf("%s#55 still owes %q on the forge", theirs, s) - } - if n := countWith(logged, "outside the mesh"); n != 1 { - t.Errorf("said %d times in the log, want once: %q", n, logged) - } - ckey, _ := meshcatalogclient.CandidatesKey("feat/theirs") - st, err := Reader{CandidateState: fakeState{ckey: cand}.read(), VerdictState: fakeState(r.verdicts.vals).read(), - Trunks: func() (map[string]string, error) { return r.trunks.Heads(), nil }}.Status() - if err != nil { - t.Fatal(err) - } - if st.Outside["feat/theirs"] == "" || len(st.CannotBeJudged) != 0 || len(st.Unjudged) != 0 { - t.Errorf("status: outside %v, cannot be judged %v, unjudged %v", st.Outside, st.CannotBeJudged, st.Unjudged) - } -} diff --git a/modules/mesh-delivery-checker/internal/check/composition_test.go b/modules/mesh-delivery-checker/internal/check/composition_test.go deleted file mode 100644 index 56f4f5ad..00000000 --- a/modules/mesh-delivery-checker/internal/check/composition_test.go +++ /dev/null @@ -1,344 +0,0 @@ -package check - -import ( - "context" - "encoding/json" - "errors" - "maps" - "mesh-delivery-checker/rules" - "slices" - "strings" - "testing" - - nec "git.novox.be/novox/mesh-contracts/go/clients/nodeengineclient" - ne "git.novox.be/novox/mesh-contracts/go/seats/nodeengine" - - buildsrec "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-builder/builds" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshdeliverycheckerclient" - "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/meshdeliverychecker" - "git.novox.be/novox/mesh-sdk/go/catalogue" -) - -// fakeCompositions answers a check's composition from memory, recording the keys asked. -type fakeCompositions struct { - v rules.Composed - err error - asked []string - // seats are the seat lists the cases asked carried (Case.Seats), one per ask. - seats [][]json.RawMessage - // waits answers only when its context ends. - waits bool -} - -func (f *fakeCompositions) Compose(ctx context.Context, c *Case) (rules.Composed, error) { - f.asked = append(f.asked, c.Key) - f.seats = append(f.seats, c.Seats) - if f.waits { - <-ctx.Done() - return rules.Composed{}, ctx.Err() - } - return f.v, f.err -} - -// composedOn is the engines' answers of a composition by composer on the nodes, each composing it, taking took ms. -func composedOn(composer string, took int64, nodes ...string) rules.Composed { - c := rules.Composed{Group: "feat/x", Heads: "0123456789ab", Composer: composer, Nodes: nodes, Took: took, Answers: map[string]ne.ComposeCandidateAnswer{}} - for _, n := range nodes { - c.Answers[n] = ne.ComposeCandidateAnswer{Node: n, Verdict: nec.Composed} - } - return c -} - -// refusedOn is the engines' answers of a composition the node refuses with the words. -func refusedOn(composer, node, words string) rules.Composed { - return rules.Composed{Group: "feat/x", Heads: "0123456789ab", Composer: composer, Nodes: []string{node}, - Answers: map[string]ne.ComposeCandidateAnswer{node: {Node: node, Verdict: nec.Refused, Refused: words}}} -} - -// 1297/AC3 (its unit half): a check whose tests pass takes the assigner's composition of it, by the check's own key, -// into its verdict: a pass says it passed with the mesh-sdk and machines it composed, and is no longer "not run". -func TestAPassingCheckTakesTheAssignersComposition(t *testing.T) { - t.Run("a change to a build module or base names the modules built on it", aChangeToABuildModuleOrBaseNamesTheModulesBuiltOnIt) - b := newBench(t) - f := &fakeCompositions{v: composedOn("v0.1.14-x", 40, "g14")} - b.ex.Compositions = f - cs := caseOf(t, pullOf(repoA, 7, head1)) - cs.FPSet = "fps-of-the-candidate" - v := b.judge(t, cs).Verdict - if v.State != meshdeliverycheckerclient.VerdictPass || v.Composition == nil || v.Composition.State != meshdeliverycheckerclient.CompositionPass || v.Composition.Sdk != "v0.1.14-x" || v.Took.Composition != 40 { - t.Fatalf("verdict = %+v, composition %+v", v, v.Composition) - } - if len(f.asked) != 1 || f.asked[0] != cs.Key { - t.Errorf("asked %v, want the check's key %s", f.asked, cs.Key) - } - if !compositionMentions(v, "passed") { - t.Errorf("the line says %q", compositionWords(v.Composition, v.Took.Composition)) - } - if v.Composition.Fpset == "" || v.Composition.Fpset != cs.FPSet { - t.Errorf("the composition names the fingerprint set %q, want the candidate's %q (ADR 0548 §5)", v.Composition.Fpset, cs.FPSet) - } - // Issue 1966 (the group try of 2026-11-06 10:07): the composition is handed the check's seat list, the judge's, once the - // checker's reader read it; a list not read hands none (the composer then judges no machine, ADR 0636 §1). - if len(f.seats) != 1 || f.seats[0] != nil { - t.Errorf("with no seat list reader the composition was handed %v, want none", f.seats) - } - for _, read := range []bool{true, false} { - b.ex.SeatList = fakeSeatList{read: read} - asked := len(f.seats) - rv := b.judge(t, caseOf(t, pullOf(repoA, 7, head1))).Verdict - if read { - if got := f.seats[len(f.seats)-1]; len(got) != 2 || string(got[0]) != `{"seat":"a"}` { - t.Errorf("with the list read the composition was handed %s, want the reader's two definitions", got) - } - } else if len(f.seats) != asked || rv.Failed == nil || !strings.Contains(rv.Failed.Words, "the seat list is not read") { - // A reader that has not read the list acts on nothing new (ADR 0636 §1): the check ends before any judge. - t.Errorf("with the list not read the composition was asked %d more, verdict %+v; want none and a fail naming the list", len(f.seats)-asked, rv.Failed) - } - } - // ADR 0635 §3: at a node-engine member's head a list not read fails the check, naming why, and asks no composer - // (a composer handed none would judge no machine and the composition would pass); read, it composes. - for _, read := range []bool{false, true} { - b.ex.SeatList = fakeSeatList{read: read} - asked := len(f.asked) - hv := b.judge(t, caseOf(t, pullOf(repoA, 7, head1), pullOf(nodeEngineRepo, 3, head2))).Verdict - switch { - case !read && (hv.State != meshdeliverycheckerclient.VerdictFail || hv.Failed == nil || !strings.Contains(hv.Failed.Words, "seat list") || len(f.asked) != asked): - t.Errorf("at a node-engine head with the list not read: verdict %+v, composition %+v, asked %d more; want a failed composition naming the seat list, no ask", hv, hv.Composition, len(f.asked)-asked) - case read && (hv.Composition == nil || hv.Composition.State != meshdeliverycheckerclient.CompositionPass || len(f.asked) != asked+1): - t.Errorf("at a node-engine head with the list read: composition %+v, want the composer's pass", hv.Composition) - } - } - b.ex.SeatList = nil - f.asked, f.seats = f.asked[:1], f.seats[:1] - // ADR 0548 §5: a carry whose fingerprints did not change keeps the composition it passed and asks the assigner nothing. - carry := caseOf(t, pullOf(repoA, 7, head1)) - carry.CarriedFrom, carry.Composition = map[string]string{repoA: trunkA2}, v.Composition - if kept := b.judge(t, carry).Verdict; kept.Composition == nil || kept.Composition.Sdk != "v0.1.14-x" || len(f.asked) != 1 { - t.Errorf("the carry's composition is %+v and the assigner was asked %d times; want the kept one and no second ask", kept.Composition, len(f.asked)) - } -} - -func compositionMentions(v meshdeliverychecker.VerdictsByGroupHeadsValue, word string) bool { - return strings.Contains(compositionWords(v.Composition, v.Took.Composition), word) -} - -// 1297/AC2 at the checker: a failed composition fails the check, naming the machine it failed at and its words. -func TestAFailedCompositionFailsTheCheck(t *testing.T) { - b := newBench(t) - b.ex.Compositions = &fakeCompositions{v: refusedOn("x", "g14", "g14 runs web, which the change removes from its source")} - v := b.judge(t, caseOf(t, pullOf(repoA, 7, head1))).Verdict - if v.State != meshdeliverycheckerclient.VerdictFail || v.Failed.Machine != "g14" || v.Composition == nil || v.Composition.State != meshdeliverycheckerclient.CompositionFail { - t.Fatalf("verdict = %+v", v) - } - v.Group, v.Heads = "feat/x", "0123456789ab" // the checker names them when it writes the verdict - if _, err := meshdeliverycheckerclient.EncodeVerdict(v); err != nil { - t.Errorf("the verdict cannot be written: %v", err) - } -} - -// 1297/B3d: a composition that cannot be read leaves it not run; a try is not composed. -func TestACompositionNotHadIsNotRun(t *testing.T) { - b := newBench(t) - f := &fakeCompositions{err: errors.New("the check's bound passed")} - b.ex.Compositions = f - v := b.judge(t, caseOf(t, pullOf(repoA, 7, head1))).Verdict - if v.State != meshdeliverycheckerclient.VerdictPass || v.Composition == nil || v.Composition.State != meshdeliverycheckerclient.CompositionNotRun { - t.Fatalf("verdict = %+v", v) - } - b2 := newBench(t) - f2 := &fakeCompositions{v: refusedOn("x", "g14", "w")} - b2.ex.Compositions = f2 - cs := caseOf(t, pullOf(repoA, 7, head1)) - cs.Try = &TryOptions{} - b2.judge(t, cs) - if len(f2.asked) != 0 { - t.Errorf("a try asked for a composition: %v", f2.asked) - } -} - -// fixedTrunks are trunk heads that never move. -type fixedTrunks struct{ heads map[string]string } - -func (f fixedTrunks) Heads() map[string]string { return f.heads } - -// fakeEnds answers the builder's builds of a candidate as fakeBuilds holds them, recording the builds waited on; the -// composition must not have been asked yet when it is (ADR 0603 §10: the check composes with the builds). -type fakeEnds struct { - builds fakeBuilds - asked map[string]string - composed *fakeCompositions - early bool -} - -func (f *fakeEnds) Ended(_ context.Context, asked map[string]string) (map[string]buildsrec.BuilderBuild, error) { - f.asked = asked - f.early = f.composed != nil && len(f.composed.asked) > 0 - out := map[string]buildsrec.BuilderBuild{} - for module, fp := range asked { - if b, ok := f.builds[module+" "+fp]; ok && (b.State == buildsrec.BuildDone || b.State == buildsrec.BuildFailed) { - out[module] = b - } - } - return out, nil -} - -func (f *fakeEnds) Done(context.Context, map[string]string) bool { return false } - -// fixedServing are the verbs the running builds serve. -type fixedServing []string - -func (f fixedServing) Served(context.Context) (func(string) bool, error) { - return func(v string) bool { return slices.Contains(f, v) }, nil -} - -// knownRuns are the modules the trunk holds a record of (the indexer's modules): any commit. -type knownRuns []string - -func (k knownRuns) CommitOf(module string) string { - if slices.Contains(k, module) { - return trunkA - } - return "" -} - -// ADR 0603 §10: before it composes, the check waits on the builder's builds of the candidate's changed modules and composes -// with them; a failed build fails the check naming it, and one not ended within the bound is named. It does not wait on a -// module built by a build module the change alters, nor on one standing on a base the change alters, nor on one the trunk -// holds no record of, and names each in the composition's warnings (and so the check's line); a change that alters none of -// these says nothing. -func aChangeToABuildModuleOrBaseNamesTheModulesBuiltOnIt(t *testing.T) { - dig := func(c string) string { return strings.Repeat(c, 64) } - fp := "src2:" + dig("f") - goBuild := &catalogue.Build{Artifacts: []catalogue.Artifact{{Name: "bin", Kind: catalogue.ArtifactBundle, Language: "go"}}} - tsBuild := &catalogue.Build{Artifacts: []catalogue.Artifact{{Name: "app", Kind: catalogue.ArtifactBundle, Language: "typescript"}}} - done := buildsrec.BuilderBuild{State: buildsrec.BuildDone} - for _, row := range []struct { - name string - manifest map[string]catalogue.Manifest - builds map[string]buildsrec.BuilderBuild // by module, at fp; nil leaves the check without the builds' ends - runs knownRuns // nil: the trunk holds every module - want []string - waited string // the modules waited on, sorted - failed string // the failure's test, when the check fails on a build - tests bool // the tests fail: the check fails before it would wait - served []string // what the running builds serve (ADR 0614 §7); nil reads nothing of what runs - preview bool // the check began on the candidate the indexer wrote before its merge preview (issue 1921) - late bool // a build did not end within the bound: the change is not composed (issue 1921) - }{ - {name: "the Go build module invokes a verb no running build serves", - manifest: map[string]catalogue.Manifest{"mesh-build-go": {Module: "mesh-build-go", Build: goBuild, - Invokes: []string{"seat:package-registry.publish", "seat:artifact-store.put"}}, "web": {Module: "web", Build: goBuild}}, - builds: map[string]buildsrec.BuilderBuild{"mesh-build-go": done}, served: []string{"seat:artifact-store.put"}, - want: []string{"the changed build module mesh-build-go invokes seat:package-registry.publish, which no running build serves, " + - "so the check cannot run it: web, which it builds, are composed from their manifests (ADR 0614 §7)"}, waited: "mesh-build-go"}, - {name: "the Go build module changes", - manifest: map[string]catalogue.Manifest{"mesh-build-go": {Module: "mesh-build-go", Build: goBuild}, "web": {Module: "web", Build: goBuild}, - "mail": {Module: "mail", Build: goBuild}, "docs": {Module: "docs"}}, - builds: map[string]buildsrec.BuilderBuild{"mesh-build-go": done, "docs": done}, - want: []string{"the build module mesh-build-go: mail, web, which it builds"}, waited: "docs, mesh-build-go"}, - {name: "the Node build module changes", - manifest: map[string]catalogue.Manifest{"mesh-build-node": {Module: "mesh-build-node", Build: goBuild}, "panel": {Module: "panel", Build: tsBuild}, - "web": {Module: "web", Build: goBuild}}, - builds: map[string]buildsrec.BuilderBuild{"mesh-build-node": done, "web": done}, - want: []string{"the build module mesh-build-node: panel, which it builds"}, waited: "mesh-build-node, web"}, - {name: "a base changes", - manifest: map[string]catalogue.Manifest{"image": {Module: "image"}, - "web": {Module: "web", Build: &catalogue.Build{On: []catalogue.BuildsOn{{Arg: "BASE", Module: "image", Artifact: "img"}}}}}, - builds: map[string]buildsrec.BuilderBuild{"image": done}, - want: []string{"alters image, a base of web", "waits on the build of image alone"}, waited: "image"}, - {name: "neither changes", manifest: map[string]catalogue.Manifest{"web": {Module: "web", Build: goBuild}}, - builds: map[string]buildsrec.BuilderBuild{"web": done}, waited: "web"}, - {name: "a build fails", manifest: map[string]catalogue.Manifest{"web": {Module: "web", Build: goBuild}, "mail": {Module: "mail", Build: goBuild}}, - builds: map[string]buildsrec.BuilderBuild{"web": {State: buildsrec.BuildFailed, Error: "go build: undefined: x"}, "mail": done}, - waited: "mail, web", failed: "build: web"}, - {name: "the tests fail", manifest: map[string]catalogue.Manifest{"web": {Module: "web", Build: goBuild}}, - builds: map[string]buildsrec.BuilderBuild{"web": {State: buildsrec.BuildBuilding}}, tests: true, - want: []string{"composes at once, without waiting on the builds of web"}}, - {name: "a build does not end within the bound", manifest: map[string]catalogue.Manifest{"web": {Module: "web", Build: goBuild}}, - builds: map[string]buildsrec.BuilderBuild{"web": {State: buildsrec.BuildBuilding}}, late: true, - want: []string{"the builder's builds of web did not end within the build-wait-bound", "the change is not composed"}, waited: "web"}, - {name: "the check began before the merge preview", manifest: map[string]catalogue.Manifest{"web": {Module: "web", Build: goBuild}}, - builds: map[string]buildsrec.BuilderBuild{"web": done}, preview: true, waited: "web"}, - {name: "a module the trunk does not hold", manifest: map[string]catalogue.Manifest{"web": {Module: "web", Build: goBuild}, "new": {Module: "new", Build: goBuild}}, - builds: map[string]buildsrec.BuilderBuild{"web": done}, runs: knownRuns{"web"}, - want: []string{"new: the trunk holds no record of it yet"}, waited: "web"}, - {name: "the builds cannot be heard", manifest: map[string]catalogue.Manifest{"web": {Module: "web", Build: goBuild}}, - want: []string{"the builds of web cannot be heard"}}, - } { - b := candidateBench(t, true) - if row.tests { - b.test = func(c stepCall) (any, error) { - r := captured[Tested](t, "go-test-failing") - r.Level, _ = c.args["level"].(string) - return r, nil - } - } - comps := &fakeCompositions{v: composedOn("x", 0, "g14")} - b.ex.Compositions = comps - var ends *fakeEnds - if row.builds != nil { - ends = &fakeEnds{builds: fakeBuilds{}, composed: comps} - for module, build := range row.builds { - ends.builds[module+" "+fp] = build - } - b.ex.BuildEnds = ends - } - if row.runs != nil { - b.ex.Runs = row.runs - } - if row.served != nil { - b.ex.Serving = fixedServing(row.served) - } - read, fps := fixedManifests{}, map[string]meshcatalog.CandidatesByGroupValuePullsItemFpsValue{} - for module, m := range row.manifest { - d := dig(string(rune('a' + len(read)))) - read[d], fps[module] = m, meshcatalog.CandidatesByGroupValuePullsItemFpsValue{Fp2: fp, Manifest: d} - } - b.ex.Read = read - p := pullOf(catalogueRepository, 9, head1) - p.Fps, p.Modules = fps, slices.Sorted(maps.Keys(fps)) - if row.preview { - previewed := p - b.ex.Candidates = &fakeTryCandidates{cand: meshcatalog.CandidatesByGroupValue{Fpset: "fps", Pulls: []meshcatalog.CandidatesByGroupValuePullsItem{previewed}}} - p.Fps = map[string]meshcatalog.CandidatesByGroupValuePullsItemFpsValue{} - for module, m := range fps { - p.Fps[module] = meshcatalog.CandidatesByGroupValuePullsItemFpsValue{Manifest: m.Manifest, None2: meshcatalogclient.NoneNoPreview} - } - } - v := b.judge(t, caseOf(t, p)).Verdict - asks := 1 - if row.late { - asks = 0 // never asked: an engine would read the builder's lateness as the change's refusal - } - if v.Composition == nil || len(comps.asked) != asks || row.late && v.Composition.State != meshdeliverycheckerclient.CompositionNotRun { - t.Fatalf("%s: composed %d times: %+v", row.name, len(comps.asked), v) - } - if ends != nil { - if got := strings.Join(slices.Sorted(maps.Keys(ends.asked)), ", "); got != row.waited || ends.early { - t.Errorf("%s: waited on %q (after the composition: %v), want %q before it composes", row.name, got, ends.early, row.waited) - } - } - switch { - case row.failed != "" && (v.State != meshdeliverycheckerclient.VerdictFail || v.Failed.Test != row.failed || !strings.Contains(v.Failed.Words, "undefined: x") || - !strings.Contains(v.Failed.Words, "the check asks itself again when the build is done")): - t.Errorf("%s: the verdict is %s failing %+v, want it failed naming %s, the builder's words and how it is asked again", row.name, v.State, v.Failed, row.failed) - case row.tests && v.State != meshdeliverycheckerclient.VerdictFail: - t.Errorf("%s: %+v, want the tests' failure", row.name, v) - case row.failed == "" && !row.tests && v.State != meshdeliverycheckerclient.VerdictPass: - t.Errorf("%s: %+v", row.name, v) - } - words := compositionWords(v.Composition, v.Took.Composition) - for _, w := range row.want { - if !strings.Contains(words, w) { - t.Errorf("%s: the line says %q, want it to name %q", row.name, words, w) - } - } - if row.want == nil && v.Composition.Words != "" { - t.Errorf("%s: warned %q though the check waited on every build of the change", row.name, v.Composition.Words) - } - } -} - -func ptr[T any](v T) *T { return &v } diff --git a/modules/mesh-delivery-checker/internal/check/couldnotrun.go b/modules/mesh-delivery-checker/internal/check/couldnotrun.go deleted file mode 100644 index 067c42c5..00000000 --- a/modules/mesh-delivery-checker/internal/check/couldnotrun.go +++ /dev/null @@ -1,275 +0,0 @@ -package check - -import ( - "context" - "encoding/json" - "errors" - "fmt" - "sort" - "time" - - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshdeliverycheckerclient" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshdeliverychecker" -) - -// A check that failed because a part of the mesh was not heard says `could not run`, naming the part, and releases its -// claim on the verdict key (design 47, *A check runs to its end*; issue 1373). It is asked again once per set of heads and -// per part returning, on the one event that can change its outcome: the node-engine seat's `running..` -// naming that part (PartRunning), never on a timer; a `running` of the same part at the same fingerprint after that asks -// nothing. One not asked again within CouldNotRunBound becomes the checker's finding CouldNotRunKind, which clears when the -// heads are checked again, replaced, or their pull request closes. -// -// What the checker knows of each such check is its own state could-not-run (CouldNotRunState), one key per verdict key, -// read by checker_status (could_not_run): kept on the bus, so a checker started again asks each one again on the next -// `running` and raises its finding at the same time. - -// CouldNotRunState is the checker's own state of its checks that could not run, by verdict key. -const CouldNotRunState = "could-not-run" - -// CouldNotRunKind is the checker's finding of a check that could not run and was not asked again within CouldNotRunBound. -const CouldNotRunKind = "check-could-not-run" - -// CouldNotRunBound is how long a check that could not run waits to be asked again before it is a finding: the check's own -// bound of an hour. -const CouldNotRunBound = time.Hour - -// Part is a part of the mesh a check could not hear: the node it runs on and its module, as the node-engine seat's -// `running..` names it. An empty field is not known: an empty Module is any part on Node, and an empty Node is -// Module wherever it runs; a Part with neither is a part the check could not name, asked again on the first `running`. -type Part struct { - Node string `json:"node,omitempty"` - Module string `json:"module,omitempty"` -} - -// String names the part as a verdict says it. -func (p Part) String() string { - switch { - case p.Node != "" && p.Module != "": - return p.Module + " on " + p.Node - case p.Module != "": - return p.Module - case p.Node != "": - return "the node " + p.Node - } - return "a part of the mesh" -} - -// matches says whether a `running` of module on node is the part's return. -func (p Part) matches(node, module string) bool { - return (p.Node == "" || p.Node == node) && (p.Module == "" || p.Module == module) -} - -// CouldNotRun is one check that could not run, as the state could-not-run keeps it. -type CouldNotRun struct { - V int `json:"v"` - Group string `json:"group"` - Heads string `json:"heads"` - Part Part `json:"part"` - Words string `json:"words"` - // Since is when its verdict was written; CouldNotRunBound after it, not asked again, it is a finding. - Since time.Time `json:"since"` - // AskedAt is the `running` that asked the check of these heads again, `.@`: a `running` of - // the same part at the same fingerprint asks nothing more. - AskedAt string `json:"asked-at,omitempty"` - // Raised says its finding is written. - Raised bool `json:"raised,omitempty"` -} - -// IsCouldNotRun says whether a verdict failed because a part of the mesh the check reads was not heard (UnheardWords): its -// claim is released, and it is asked again when that part runs (PartRunning). -func IsCouldNotRun(v meshdeliverychecker.VerdictsByGroupHeadsValue) bool { - return v.State == meshdeliverycheckerclient.VerdictFail && containsWords(failedOf(v).Words, UnheardWords) -} - -// running is how a `running` event is kept in AskedAt and in the release of a check. -func runningAt(node, module, fingerprint string) string { - return node + "." + module + "@" + fingerprint -} - -// PartRunning is the node-engine seat's `running..` at fingerprint: every check that could not run for want -// of that part, and was not asked again by the same part at the same fingerprint, is released and asked again once. -func (ch *Checker) PartRunning(ctx context.Context, node, module, fingerprint string) { - ch.init() - if ch.CouldNotRun == nil { - return - } - keys, err := ch.CouldNotRun.Keys(ctx) - if err != nil { - ch.logf("the checks that could not run cannot be listed, so the running of %s on %s asks none again: %v", module, node, err) - return - } - at := runningAt(node, module, fingerprint) - released := 0 - for _, key := range keys { - r, _, ok := ch.couldNotRunOf(ctx, key) - if !ok || !r.Part.matches(node, module) || r.AskedAt == at { - continue - } - ch.mu.Lock() - ch.release[key] = at - ch.mu.Unlock() - released++ - ch.logf("%s: %s runs (%s), which the check could not hear: asked again", key, module, at) - } - if released > 0 { - ch.Reconsider(ctx) - } -} - -// couldNotRunOf reads one key of the state could-not-run. -func (ch *Checker) couldNotRunOf(ctx context.Context, key string) (CouldNotRun, uint64, bool) { - raw, rev, found, err := ch.CouldNotRun.Get(ctx, key) - if err != nil || !found || len(raw) == 0 { - return CouldNotRun{}, 0, false - } - var r CouldNotRun - if json.Unmarshal(raw, &r) != nil { - return CouldNotRun{}, 0, false - } - return r, rev, true -} - -// takeRelease answers the `running` that released the check of key, once, and forgets it. -func (ch *Checker) takeRelease(key string) (string, bool) { - ch.mu.Lock() - defer ch.mu.Unlock() - at, ok := ch.release[key] - delete(ch.release, key) - return at, ok -} - -// keepCouldNotRun writes the check's record after a verdict that could not run, asked again by askedAt ("" for none). -func (ch *Checker) keepCouldNotRun(ctx context.Context, cs *Case, v meshdeliverychecker.VerdictsByGroupHeadsValue, part Part, askedAt string) { - if ch.CouldNotRun == nil { - return - } - r := CouldNotRun{V: 1, Group: cs.Group, Heads: cs.Heads, Part: part, Words: failedOf(v).Words, Since: ch.now().UTC(), AskedAt: askedAt} - data, err := json.Marshal(r) - if err != nil { - return - } - _, rev, found, err := ch.CouldNotRun.Get(ctx, cs.Key) - if err == nil && found { - _, err = ch.CouldNotRun.Update(ctx, cs.Key, data, rev) - } else if err == nil { - _, err = ch.CouldNotRun.Create(ctx, cs.Key, data) - } - if err != nil { - ch.logf("%s: could not run, and that cannot be kept, so no running of %s asks it again until it is checked again: %v", cs.Key, part, err) - return - } - if ch.CouldNotRunKept != nil { - ch.CouldNotRunKept() - } -} - -// clearCouldNotRun forgets the check of key that could not run, and clears its finding: its heads are checked again, -// replaced, or their pull request closed. -func (ch *Checker) clearCouldNotRun(ctx context.Context, key string) { - if ch.CouldNotRun == nil { - return - } - r, _, ok := ch.couldNotRunOf(ctx, key) - if !ok { - return - } - if d, can := ch.CouldNotRun.(Deleter); can { - if err := d.Delete(ctx, key); err != nil { - ch.logf("%s: the record that it could not run cannot be deleted: %v", key, err) - return - } - } - if r.Raised && ch.Findings != nil { - if err := ch.Findings.Delete(couldNotRunFinding(key, r, ch.now())); err != nil { - ch.logf("%s: its finding %s cannot be cleared: %v", key, CouldNotRunKind, err) - } - } -} - -// CouldNotRunDue raises the finding of every check that could not run and was not asked again within CouldNotRunBound by -// now, and answers when the next one is due (the zero time when none waits). The checker's process waits for that time; -// a test gives now. -func (ch *Checker) CouldNotRunDue(ctx context.Context, now time.Time) time.Time { - if ch.CouldNotRun == nil { - return time.Time{} - } - keys, err := ch.CouldNotRun.Keys(ctx) - if err != nil { - ch.logf("the checks that could not run cannot be listed, so none is raised as %s now: %v", CouldNotRunKind, err) - return time.Time{} - } - sort.Strings(keys) - var next time.Time - for _, key := range keys { - r, rev, ok := ch.couldNotRunOf(ctx, key) - if !ok || r.Raised { - continue - } - due := r.Since.Add(CouldNotRunBound) - if now.Before(due) { - if next.IsZero() || due.Before(next) { - next = due - } - continue - } - if ch.Findings == nil { - continue - } - if err := ch.Findings.Put(couldNotRunFinding(key, r, now)); err != nil { - ch.logf("%s: its finding %s cannot be written: %v", key, CouldNotRunKind, err) - continue - } - r.Raised = true - if data, err := json.Marshal(r); err == nil { - if _, err := ch.CouldNotRun.Update(ctx, key, data, rev); err != nil && !errors.Is(err, ErrConflict) { - ch.logf("%s: its finding is written, and that cannot be kept: %v", key, err) - } - } - } - return next -} - -// Finding is the checker's finding of a check that could not run, in plain fields: the checker's writer lays it out as the seat -// mesh-conditions' finding (design 47 G §689). -type Finding struct { - Kind, ID, Summary, Headline, Explanation string - At time.Time -} - -// FindingWriter writes and clears the checker's findings. -type FindingWriter interface { - Put(f Finding) error - Delete(f Finding) error -} - -// RaisedCouldNotRun is every finding the checker observes now (design 47 G §384, §461): the check that could not run -// and whose finding is written. The finding writer states them at its start and when the keeper asks. -func (ch *Checker) RaisedCouldNotRun(ctx context.Context) ([]Finding, error) { - if ch.CouldNotRun == nil { - return nil, nil - } - keys, err := ch.CouldNotRun.Keys(ctx) - if err != nil { - return nil, fmt.Errorf("the checks that could not run cannot be listed: %w", err) - } - sort.Strings(keys) - var out []Finding - for _, key := range keys { - if r, _, ok := ch.couldNotRunOf(ctx, key); ok && r.Raised { - out = append(out, couldNotRunFinding(key, r, r.Since)) - } - } - return out, nil -} - -// couldNotRunFinding is the finding of the check of key that could not run. -func couldNotRunFinding(key string, r CouldNotRun, at time.Time) Finding { - return Finding{Kind: CouldNotRunKind, ID: key, - Summary: fmt.Sprintf("the check of %s (heads %s) could not run since %s: %s was not heard, and has not run since", - r.Group, r.Heads, r.Since.UTC().Format(time.RFC3339), r.Part), - Headline: fmt.Sprintf("The check of %s could not run", r.Group), - Explanation: "A check that cannot hear a part of the mesh it reads says so and is asked again when that part runs. " + - "It has not run for an hour: look at " + r.Part.String() + ". The finding clears when the heads are checked again, " + - "replaced, or their pull request closes.", - At: at.UTC()} -} diff --git a/modules/mesh-delivery-checker/internal/check/declared.go b/modules/mesh-delivery-checker/internal/check/declared.go deleted file mode 100644 index 95bf4c55..00000000 --- a/modules/mesh-delivery-checker/internal/check/declared.go +++ /dev/null @@ -1,115 +0,0 @@ -package check - -import ( - "context" - "errors" - "fmt" - "strings" - - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient" - "git.novox.be/novox/mesh-sdk/go/catalogue" -) - -// declaredPackage is one package a group member declares: the module, its directory in the repository (RootPath for its -// root, empty when not known), and the artifact's name, paths and language. -type declaredPackage struct { - pull Pull - module, dir string - name string - paths []string - language string -} - -// manifestAtHead is a touched module's manifest read from the forge at its member's head (the lead's ruling 4 on A2c's -// finding 4): with no preview of the merge, a package new in the group is declared only there, never at the trunk. The -// module's directory is the indexer's when it knows the module, else modules/ or the repository's root, the one -// whose manifest names the module. Found is false when no such file names it. -func (st *state) manifestAtHead(ctx context.Context, p Pull, module string) (m catalogue.Manifest, dir string, found bool, err error) { - var dirs []string - if st.j.Dirs != nil { - if d, ok := st.j.Dirs.ModuleDir(module); ok { - dirs = []string{d} - } - } - if dirs == nil { - dirs = []string{"modules/" + module, meshcatalogclient.RootPath} - } - for _, d := range dirs { - file := "module.json" - if t := strings.Trim(d, "/"); t != "" && t != meshcatalogclient.RootPath { - file = t + "/module.json" - } - text, err := st.j.Forge.File(ctx, p.Repository, file, p.Head) - if errors.Is(err, ErrNotFound) { - continue - } - if err != nil { - return catalogue.Manifest{}, "", false, fmt.Errorf("the manifest of %s at the head of %s cannot be read%s: %w", module, pullKey(p), unheardWords(err), err) - } - m, err := catalogue.Decode([]byte(text)) - if err != nil { - return catalogue.Manifest{}, "", false, fmt.Errorf("the manifest %s of %s at the head of %s is no manifest: %w", file, module, pullKey(p), err) - } - if m.Module == module { - return m, d, true, nil - } - } - return catalogue.Manifest{}, "", false, nil -} - -// declaredPackages are the packages the case's members declare, read from each touched module's manifest at the merge -// preview (the candidate's); with no preview, at the member's head on the forge, so a package new in the group is asked -// for on the first check too (trunk's manifest when no forge is read): a member that declares none is not asked for. -func (st *state) declaredPackages(ctx context.Context) ([]declaredPackage, error) { - if st.j.Read == nil && st.j.Forge == nil { - return nil, nil - } - var trunk map[string]string - if st.j.Manifests != nil { - trunk = st.j.Manifests.ManifestDigests() - } - var out []declaredPackage - for _, p := range st.c.Pulls { - for _, module := range p.Modules { - var m catalogue.Manifest - var dir string - digest := p.Fps[module].Manifest - switch { - case digest != "" && st.j.Read != nil: - var err error - if m, err = st.j.Read.Manifest(ctx, digest); err != nil { - return nil, fmt.Errorf("the manifest of %s (%s) cannot be read, so the packages it declares are not known: %w", module, pullKey(p), err) - } - case st.j.Forge != nil: - var found bool - var err error - if m, dir, found, err = st.manifestAtHead(ctx, p, module); err != nil { - return nil, fmt.Errorf("%v, so the packages it declares are not known", err) - } - if !found { - continue - } - case trunk[module] != "" && st.j.Read != nil: - var err error - if m, err = st.j.Read.Manifest(ctx, trunk[module]); err != nil { - return nil, fmt.Errorf("the manifest of %s (%s) cannot be read, so the packages it declares are not known: %w", module, pullKey(p), err) - } - default: - continue - } - if dir == "" && st.j.Dirs != nil { - dir, _ = st.j.Dirs.ModuleDir(module) - } - if m.Build == nil { - continue - } - for _, a := range m.Build.Artifacts { - if a.Kind != catalogue.ArtifactPackage { - continue - } - out = append(out, declaredPackage{pull: p, module: module, dir: dir, name: a.Name, paths: a.Paths, language: a.Language}) - } - } - } - return out, nil -} diff --git a/modules/mesh-delivery-checker/internal/check/digestform_test.go b/modules/mesh-delivery-checker/internal/check/digestform_test.go deleted file mode 100644 index 1648c337..00000000 --- a/modules/mesh-delivery-checker/internal/check/digestform_test.go +++ /dev/null @@ -1,84 +0,0 @@ -package check - -import ( - "encoding/json" - "strings" - "testing" - - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshdeliverycheckerclient" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep" -) - -// 1930/AC3: given a check ask whose stored end keeps the digest's packages as a list of {package, digest} (issue 1930), -// or one stored before it with the packages a map keyed by package path, when the same heads are checked a second time, -// then the kept verdicts the first check wrote are read from it: every package it passed is kept, none run again. -func TestKeptVerdictsAreReadFromTheDigestsListForm(t *testing.T) { - for _, tc := range []struct { - name string - old bool - }{{"the list form", false}, {"a map stored before issue 1930", true}} { - t.Run(tc.name, func(t *testing.T) { - b := newBench(t) - var stored []string - b.asks.Answer = func(a buildstep.StepAsk) buildstep.Step { - s := b.answer(a) - if tc.old && s.State == buildstep.StepPassed { - s.Result = oldDigestForm(t, s.Result) - } - stored = append(stored, string(s.Result)) - return s - } - first := b.judge(t, caseOf(t, pullOf(repoA, 7, head1))).Verdict - u := first.Levels[buildstep.LevelUnit] - if first.State != meshdeliverycheckerclient.VerdictPass || u.Run == 0 || u.Kept != 0 { - t.Fatalf("the first check = %+v", first) - } - if len(stored) == 0 { - t.Fatal("no ask's end was stored") - } - list := strings.Contains(stored[0], `"packages":[{"package":"fixture/slow"`) - if list == tc.old || strings.Contains(stored[0], `"fixture/slow":"`) != tc.old { - t.Fatalf("the stored end is not in the form under test: %s", stored[0]) - } - b.steps.calls = nil - second := b.judge(t, caseOf(t, pullOf(repoA, 7, head1))).Verdict - if s := second.Levels[buildstep.LevelUnit]; second.State != meshdeliverycheckerclient.VerdictPass || s.Kept != u.Run || s.Run != 0 { - t.Fatalf("the second check's unit level = %+v, want %d kept and none run", s, u.Run) - } - if n := len(b.steps.tool("test")); n != 0 { - t.Errorf("%d test steps ran on the second check", n) - } - }) - } -} - -// oldDigestForm rewrites a check answer's level digests to the form stored before issue 1930: packages as a map keyed by -// package path. -func oldDigestForm(t *testing.T, result json.RawMessage) json.RawMessage { - t.Helper() - var a struct { - Fetch json.RawMessage `json:"fetch"` - Levels []map[string]any `json:"levels"` - } - if err := json.Unmarshal(result, &a); err != nil { - t.Fatal(err) - } - for _, l := range a.Levels { - d, ok := l["digest"].(map[string]any) - if !ok { - continue - } - m := map[string]any{} - list, _ := d["packages"].([]any) - for _, p := range list { - pd := p.(map[string]any) - m[pd["package"].(string)] = pd["digest"] - } - d["packages"] = m - } - raw, err := json.Marshal(a) - if err != nil { - t.Fatal(err) - } - return raw -} diff --git a/modules/mesh-delivery-checker/internal/check/doc.go b/modules/mesh-delivery-checker/internal/check/doc.go deleted file mode 100644 index 781347eb..00000000 --- a/modules/mesh-delivery-checker/internal/check/doc.go +++ /dev/null @@ -1,6 +0,0 @@ -// Package check is the checker's logic (novox/hq ADR 0484, ADR 0453 clause 4, ADR 0447, ADR 0444), apart from the bus: the -// claim of a verdict key, the judging of a pull request's head merged onto its trunk through the build modules' fetch, -// digest and test steps, the kept verdicts, the line of the status and the act the forge bridge performs. The bus is -// reached through the small interfaces here, so each part is tested with fakes. The checker runs dark: nothing reads its -// answers to merge or deliver (ADR 0453 clause 4). -package check diff --git a/modules/mesh-delivery-checker/internal/check/engines.go b/modules/mesh-delivery-checker/internal/check/engines.go deleted file mode 100644 index bf2fc352..00000000 --- a/modules/mesh-delivery-checker/internal/check/engines.go +++ /dev/null @@ -1,261 +0,0 @@ -package check - -import ( - "context" - "encoding/json" - "fmt" - "mesh-delivery-checker/rules" - "sort" - "strings" - "sync" - "time" - - "git.novox.be/novox/mesh-contracts/go/clients/nodeengineclient" - nec "git.novox.be/novox/mesh-contracts/go/clients/nodeengineclient" - ne "git.novox.be/novox/mesh-contracts/go/seats/nodeengine" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/composer" -) - -// **A check's composition is the checker's, made from what each node's engine answers** (novox/hq ADR 0593 §7, §9). -// Only a node knows whether a change composes there: the checker asks every placed node's engine -// `node-engine.compose-candidate` in parallel, with the check's candidate, and waits at most its answer bound -// (compose-answer-bound, 60 s by default). A node that refuses fails the check, naming the node and each module with the -// engine's words; a node that does not answer within the bound, answers unready or cannot be asked is named, "not composed -// on that node: no answer", and the check passes with that warning: its own composition judges again when it applies, -// and the canary rule holds. The checker decides by the answer's verdict, never by its words. -// -// **A group that changes the node-engine's composition code** (a member of the node-engine's repository) is not judged by -// the running engines, which cannot judge their own next code: each node's engine answers the composition input it -// composed from (ne.ComposeCandidateInput.Input), and the composer program built from that member's head composes it in a -// build module's sandbox (Sandbox), with every manifest of the catalogue as the case leaves it and the indexer's verdicts. - -// EngineAsker asks one node's engine to compose a check's candidate (the verb node-engine.compose-candidate on that node). -type EngineAsker interface { - ComposeCandidate(ctx context.Context, node string, ask ne.ComposeCandidateInput) (ne.ComposeCandidateAnswer, error) -} - -// Sandbox runs a compose job on the Go build seat and answers the composer's verdict. -type Sandbox interface { - Compose(ctx context.Context, job buildstep.ComposeJob) (composer.Verdict, error) -} - -// EngineCompositions is the checker's composition of a check (Examiner.Compositions). -type EngineCompositions struct { - Asker EngineAsker - // Placed names every node in assignments now (the seat mesh-module-assigner's state), or why it cannot be read: then no node - // can be asked, and the composition is not made (an error), never passed with nobody asked. - Placed func() ([]string, error) - // Bound is the answer bound (the setting compose-answer-bound); zero is nec.AnswerBound. - Bound time.Duration - // Composer is the node-engine's trunk head: a check whose group has no node-engine member is composed by the composer - // built there, so every check composes with an acting part built from the change's heads or their trunk, never with - // the running engines' own code (ADR 0656 §5; the lead's ruling Q3 on milestone 47/G). Nil, or an empty head, leaves - // such a check composed by the running engines, said. - Composer func() string - // Sandbox runs the composer of a node-engine member's head; nil leaves such a group judged by the running engines, - // said in a warning. - Sandbox Sandbox - // Manifests are the indexer's trunk manifest digests by module, and Verdicts its refusals of them: the catalogue the - // sandbox composes with, before the case's own manifests are laid over. - Manifests TrunkManifests - // Published names the latest published version of every mesh package (Examiner.Published): the composer is built - // against them and the group's heads, as a check is (issue 1921); nil names the group's heads alone. - Published interface { - LatestPackages() buildstep.PackageVersions - } - Verdicts func() map[string]meshcatalog.VerdictsByDigestValue - // Requests keeps each request sent to the composer, per check and node (issue 1921); nil keeps none. A request that - // cannot be kept fails the node's composition, naming why: never dropped. - Requests interface { - Keep(ctx context.Context, key, node string, body []byte) error - } -} - -// composerHead is the node-engine member's head of a case, or empty. -// atWord names where a composer was built: the member's head or the node-engine's trunk. -func atWord(member bool) string { - if member { - return "head" - } - return "trunk" -} - -func composerHead(c *Case) string { - if m := c.member(nodeEngineRepo); m != nil { - return m.Head - } - return "" -} - -// Compose asks every placed node and answers their answers, for the rules to judge (rules.JudgeEngines). An error is only a -// case it cannot ask at all. -func (e EngineCompositions) Compose(ctx context.Context, c *Case) (rules.Composed, error) { - began := time.Now() - key, err := nodeengineclient.CompositionKey(c.Group, c.Heads) - if err != nil { - return rules.Composed{}, err - } - var nodes []string - if e.Placed != nil { - if nodes, err = e.Placed(); err != nil { - return rules.Composed{}, fmt.Errorf("the assignments cannot be read, so no node can be asked: %w", err) - } - } - bound := e.Bound - if bound <= 0 { - bound = nec.AnswerBound - } - // One composition path (ADR 0656 §5): the composer built at the node-engine member's head, else at its trunk. - head, member := composerHead(c), true - if head == "" && e.Composer != nil { - head, member = e.Composer(), false - } - sandboxed := head != "" && e.Sandbox != nil - answers := map[string]ne.ComposeCandidateAnswer{} - silent := map[string]string{} - var mu sync.Mutex - var wg sync.WaitGroup - for _, node := range nodes { - wg.Add(1) - go func() { - defer wg.Done() - at, cancel := context.WithTimeout(ctx, bound) - defer cancel() - a, err := e.Asker.ComposeCandidate(at, node, ne.ComposeCandidateInput{Candidate: key, Input: sandboxed}) - if err == nil && sandboxed && a.Verdict != nec.Unready { - // The composer's build and run are the check's to bound, not the engine's answer bound. A composer that - // cannot run is no silent node (ADR 0593 §9 lets only that pass): the node's composition fails, naming - // the head. - if composed, serr := e.inSandbox(ctx, c, head, node, a); serr != nil { - a = ne.ComposeCandidateAnswer{V: a.V, Node: node, Candidate: a.Candidate, Verdict: nec.Refused, - Refused: "the composer at the node-engine's " + atWord(member) + " " + head + " could not compose it: " + serr.Error()} - } else { - a = composed - } - } - mu.Lock() - defer mu.Unlock() - switch { - case err != nil: - silent[node] = err.Error() - case a.Verdict == nec.Unready: - silent[node] = "unready" - default: - answers[node] = a - } - }() - } - wg.Wait() - // What composed, named by the node-engine's commit: the member's head in the sandbox, else the one the mesh runs. - composerName := "node-engine" - if sandboxed { - composerName = head - } - v := rules.Composed{Group: c.Group, Heads: c.HeadsHash, Composer: composerName, Nodes: nodes, Answers: answers, Silent: silent} - switch { - case member && head != "" && e.Sandbox == nil: - v.Warnings = append(v.Warnings, "the group changes the node-engine's composition code and was composed by the running engines") - case !sandboxed && e.Sandbox != nil && len(nodes) > 0: - v.Warnings = append(v.Warnings, "composed by the running engines: no composer at the node-engine's trunk is known to build") - } - v.Took = time.Since(began).Milliseconds() - return v, nil -} - -// inSandbox composes a node's answer again with the composer built from the node-engine member's head, over the input the -// node's engine composed from: the node's answer becomes the sandbox's, refused with the composer's words where the -// composer refuses the node. -func (e EngineCompositions) inSandbox(ctx context.Context, c *Case, head, node string, a ne.ComposeCandidateAnswer) (ne.ComposeCandidateAnswer, error) { - if len(a.Input) == 0 { - return a, fmt.Errorf("the engine of %s answered no composition input, so the node-engine's head cannot compose it", node) - } - manifests := map[string]composer.Manifest{} - if e.Manifests != nil { - fps := e.Manifests.ManifestFingerprints() - for name, digest := range e.Manifests.ManifestDigests() { - manifests[name] = composer.Manifest{Digest: digest, Fingerprint: fps[name]} - } - } - for _, p := range c.Pulls { - for name, m := range p.Fps { - if m.Manifest != "" { - manifests[name] = composer.Manifest{Digest: m.Manifest, Fingerprint: m.Fp2} - } - } - } - verdicts := map[string]json.RawMessage{} - if e.Verdicts != nil { - for name, v := range e.Verdicts() { - raw, err := json.Marshal(v) - if err != nil { - return a, fmt.Errorf("the verdict of the manifest of %s cannot be encoded: %w", name, err) - } - verdicts[name] = raw - } - } - // A manifest the change brings is the check's own judge's (ADR 0578 §2, §3): its verdict there when the judge gave one, - // else none, which the composer reads as accepted; never the running indexer's (F5 of milestone 47/G). - for _, p := range c.Pulls { - for name := range p.Fps { - delete(verdicts, name) - if raw, ok := c.Judged[name]; ok { - verdicts[name] = raw - } - } - } - // The answer carries its input as the object the seat's contract names, decoded with its numbers as written - // (json.Number), so encoding it again gives the composer the same values the engine sent. - input, err := json.Marshal(a.Input) - if err != nil { - return a, fmt.Errorf("the engine of %s answered a composition input that cannot be encoded again: %w", node, err) - } - req := composer.Request{V: composer.Version, Input: input, Depth: composer.DepthCompose, Machines: []string{node}, - Cases: []composer.Case{{Name: "change", Manifests: manifests, Verdicts: verdicts}}, Seats: c.Seats} - raw, err := json.Marshal(req) - if err != nil { - return a, err - } - if e.Requests != nil { - key, err := nodeengineclient.CompositionKey(c.Group, c.Heads) - if err == nil { - err = e.Requests.Keep(ctx, key, node, raw) - } - if err != nil { - return a, err - } - } - job := buildstep.ComposeJob{Fetch: buildstep.Fetch{Repository: nodeEngineRepo, Commit: head, Dir: meshcatalogclient.RootPath, Packages: packagesFor(e.Published, c, nodeEngineRepo)}, Dir: meshcatalogclient.RootPath, - Package: composer.Package, Request: raw, Reader: "the node-engine head of " + c.Group} - // The ask travels on the bus, whose message limit a whole request passes (1.2 MB for a large node): it goes packed. - if err := job.PackRequest(raw); err != nil { - return a, err - } - verdict, err := e.Sandbox.Compose(ctx, job) - if err != nil { - return a, fmt.Errorf("the composer at the node-engine's head %s did not answer for %s: %w", head, node, err) - } - out := ne.ComposeCandidateAnswer{V: a.V, Node: node, Candidate: a.Candidate, Verdict: nec.Composed} - notJudged := "" - for _, cv := range verdict.Cases { - if m, ok := cv.Machines[node]; ok && m.NotJudged != "" { - notJudged = m.NotJudged // the composer did not judge the node: neither composed nor refused (ADR 0593 §9) - } else if ok && !m.Composes { - out.Verdict = nec.Refused - out.Refused = strings.Join(append(append([]string{m.Reason}, m.Problems...), m.Refusals...), "; ") - } - for name, read := range cv.Manifests { - if !read.Accepted { - out.Verdict = nec.Refused - out.Modules = append(out.Modules, ne.Module{Module: name, State: nec.ModuleRefused, Words: read.Refused}) - } - } - } - sort.Slice(out.Modules, func(i, j int) bool { return out.Modules[i].Module < out.Modules[j].Module }) - if notJudged != "" && out.Verdict == nec.Composed { - out.Verdict, out.Refused = nec.NotJudged, notJudged - } - return out, nil -} diff --git a/modules/mesh-delivery-checker/internal/check/engines_test.go b/modules/mesh-delivery-checker/internal/check/engines_test.go deleted file mode 100644 index 66483abb..00000000 --- a/modules/mesh-delivery-checker/internal/check/engines_test.go +++ /dev/null @@ -1,392 +0,0 @@ -package check - -import ( - "context" - "encoding/json" - "errors" - "fmt" - "mesh-delivery-checker/rules" - "strings" - "sync" - "testing" - "time" - - "git.novox.be/novox/mesh-contracts/go/clients/nodeengineclient" - nec "git.novox.be/novox/mesh-contracts/go/clients/nodeengineclient" - ne "git.novox.be/novox/mesh-contracts/go/seats/nodeengine" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshdeliverycheckerclient" - "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/meshdeliverychecker" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshwants" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/composer" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/trunk" -) - -// fakeEngines answers compose-candidate by node from memory; a node it holds no answer for never answers. -type fakeEngines struct { - mu sync.Mutex - answers map[string]ne.ComposeCandidateAnswer - errs map[string]error - asked map[string]ne.ComposeCandidateInput -} - -func (f *fakeEngines) ComposeCandidate(ctx context.Context, node string, ask ne.ComposeCandidateInput) (ne.ComposeCandidateAnswer, error) { - f.mu.Lock() - if f.asked == nil { - f.asked = map[string]ne.ComposeCandidateInput{} - } - f.asked[node] = ask - a, ok := f.answers[node] - err := f.errs[node] - f.mu.Unlock() - if err != nil { - return ne.ComposeCandidateAnswer{}, err - } - if !ok { - <-ctx.Done() - return ne.ComposeCandidateAnswer{}, ctx.Err() - } - return a, nil -} - -// fakeSandbox answers a compose job with a verdict, recording the job. -type fakeSandbox struct { - mu sync.Mutex - jobs []buildstep.ComposeJob - v func(node string) composer.Verdict - err error -} - -func (f *fakeSandbox) Compose(_ context.Context, job buildstep.ComposeJob) (composer.Verdict, error) { - var req composer.Request - body, err := job.RequestBytes() - if err != nil { - return composer.Verdict{}, err - } - if err := json.Unmarshal(body, &req); err != nil { - return composer.Verdict{}, err - } - f.mu.Lock() - f.jobs = append(f.jobs, job) - f.mu.Unlock() - if f.err != nil { - return composer.Verdict{}, f.err - } - return f.v(req.Machines[0]), nil -} - -// keptRequests is the state of composition requests in memory; a put fails with err when it is set. -type keptRequests struct { - mu sync.Mutex - vals map[string][]byte - err error -} - -func (k *keptRequests) Put(_ context.Context, key string, value []byte) (uint64, error) { - k.mu.Lock() - defer k.mu.Unlock() - if k.err != nil { - return 0, k.err - } - if k.vals == nil { - k.vals = map[string][]byte{} - } - k.vals[key] = value - return 1, nil -} - -func (k *keptRequests) read() StateRead { - return StateRead{Keys: func() ([]string, error) { - var out []string - for n := range k.vals { - out = append(out, n) - } - return out, nil - }, Get: func(key string) (json.RawMessage, error) { return k.vals[key], nil }} -} - -type digests map[string]string - -func (d digests) ManifestDigests() map[string]string { return d } - -// ManifestFingerprints: the trunk entry of each module is src2: in a test. -func (d digests) ManifestFingerprints() map[string]string { - out := map[string]string{} - for m := range d { - out[m] = "src2:" + m - } - return out -} - -// ADR 0593 §7, §9 (D12, G1, G2): the checker asks every placed node's engine in parallel and makes the composition from -// their answers: a refusal fails it naming the node and each module; a node that does not answer within the bound, -// answers unready or cannot be asked is named "not composed on that node: no answer" and the check passes with that -// warning, decided by the verdict and never by its words; a group with a node-engine member is composed by the composer -// built at that member's head, over the input each node's engine composed from. -func TestTheCompositionIsMadeFromTheEnginesAnswers(t *testing.T) { - composed := func(node string) ne.ComposeCandidateAnswer { - return ne.ComposeCandidateAnswer{Node: node, Verdict: nec.Composed, - Modules: []ne.Module{{Module: "web", State: nec.ModuleComposed, Digest: "sha256:" + strings.Repeat("a", 64)}}, - Own: ne.Module{Module: nec.Own, State: nec.ModuleComposed, Digest: "sha256:" + strings.Repeat("b", 64)}} - } - cs := caseOf(t, pullOf(repoA, 7, head1)) - key, _ := nodeengineclient.CompositionKey(cs.Group, cs.HeadsHash) - var last rules.Composed // the engines' answers of the last compose, for the check's verdict to take in - compose := func(e *fakeEngines, nodes ...string) meshwants.CompositionsByGroupHeadsValue { - t.Helper() - ec := EngineCompositions{Asker: e, Placed: func() ([]string, error) { return nodes, nil }, Bound: 50 * time.Millisecond, - Composer: func() string { return strings.Repeat("7", 40) }} - raw, err := ec.Compose(context.Background(), cs) - if err != nil { - t.Fatal(err) - } - last = raw - return rules.JudgeEngines(raw) - } - - t.Run("one node refusing fails the composition, naming the node and the module", func(t *testing.T) { - refusing := composed("laptop") - refusing.Verdict = nec.Refused - refusing.Modules = []ne.Module{{Module: "web", State: nec.ModuleRefused, Words: "a required value is unset"}, - {Module: "mail", State: nec.ModuleHeld, Words: "held as today"}} - e := &fakeEngines{answers: map[string]ne.ComposeCandidateAnswer{"anchor": composed("anchor"), "laptop": refusing}} - v := compose(e, "anchor", "laptop") - if v.State != meshdeliverycheckerclient.CompositionFail || v.Machine != "laptop" || !strings.Contains(v.Words, "not composed on laptop: web: a required value is unset") || - strings.Contains(v.Words, "mail") || len(v.Machines) != 2 { - t.Errorf("verdict = %+v", v) - } - if e.asked["anchor"].Candidate != key || e.asked["laptop"].Input { - t.Errorf("asked %+v, want the check's candidate %s and no input", e.asked, key) - } - var ver meshdeliverychecker.VerdictsByGroupHeadsValue - rules.JudgeComposition(&ver, rules.Composition{Composed: &last}) - if ver.State != meshdeliverycheckerclient.VerdictFail || ver.Failed.Machine != "laptop" { - t.Errorf("the check's verdict = %+v", ver) - } - }) - - t.Run("a silent, unready or unreachable node is no answer, and the check passes naming it", func(t *testing.T) { - unready := ne.ComposeCandidateAnswer{Node: "g14", Verdict: nec.Unready, Refused: "a module refused it"} - e := &fakeEngines{answers: map[string]ne.ComposeCandidateAnswer{"anchor": composed("anchor"), "g14": unready}, - errs: map[string]error{"ace": errors.New("no responders")}} - began := time.Now() - v := compose(e, "anchor", "laptop", "g14", "ace") - if took := time.Since(began); took > 2*time.Second { - t.Errorf("the nodes were not asked in parallel within the bound: %s", took) - } - // No sandbox: the running engines composed, named so, though the node-engine's trunk head is known. - if v.State != meshdeliverycheckerclient.CompositionPass || v.Sdk != "node-engine" || len(v.Machines) != 1 { - t.Fatalf("verdict = %+v", v) - } - for _, node := range []string{"ace", "g14", "laptop"} { - if !strings.Contains(strings.Join(v.Warnings, "; "), node+": "+nec.NoAnswer) { - t.Errorf("%s is not named: %v", node, v.Warnings) - } - } - var ver meshdeliverychecker.VerdictsByGroupHeadsValue - ver.State = meshdeliverycheckerclient.VerdictPass - rules.JudgeComposition(&ver, rules.Composition{Composed: &last}) - if ver.State != meshdeliverycheckerclient.VerdictPass || !strings.Contains(composition(ver.Composition, 0, false), "laptop: "+nec.NoAnswer) { - t.Errorf("the line = %q", composition(ver.Composition, 0, false)) - } - }) - - t.Run("a node-engine member is composed by the composer at its head over each node's input", func(t *testing.T) { - c, err := meshcatalog.DecodeCandidatesByGroupValue(candidateOf(t, "feat/x", pullOf(nodeEngineRepo, 3, head2), pullOf(repoA, 7, head1))) - if err != nil { - t.Fatal(err) - } - host := CaseOf(c, map[string]string{repoA: trunkA, nodeEngineRepo: trunkA}) - host.Seats = []json.RawMessage{json.RawMessage(`{"seat":"node-x","scope":"node"}`)} // the heads' list (ADR 0636 §4) - withInput := composed("anchor") - withInput.Input = map[string]any{"nodes": []any{map[string]any{"name": "anchor"}}} - // Issue 1966 (the group try of 2026-11-06 10:07): the composer at the head composes against the check's seat list. - host.Seats = []json.RawMessage{json.RawMessage(`{"format":1,"seat":"node-uplink"}`)} - e := &fakeEngines{answers: map[string]ne.ComposeCandidateAnswer{"anchor": withInput}} - sb := &fakeSandbox{v: func(node string) composer.Verdict { - return composer.Verdict{V: composer.Version, Cases: []composer.CaseVerdict{{Name: "change", - Machines: map[string]composer.Machine{node: {Composes: false, Reason: "the new composer refuses it"}}}}} - }} - ec := EngineCompositions{Asker: e, Placed: func() ([]string, error) { return []string{"anchor"}, nil }, Bound: time.Second, - Sandbox: sb, Manifests: digests{"web": "sha256:" + strings.Repeat("c", 64)}, Published: published{}} - raw, err := ec.Compose(context.Background(), host) - v := rules.JudgeEngines(raw) - if err != nil { - t.Fatal(err) - } - if !e.asked["anchor"].Input || len(sb.jobs) != 1 { - t.Fatalf("asked %+v, jobs %+v: want the input asked and one job", e.asked, sb.jobs) - } - job := sb.jobs[0] - if job.Fetch.Dir == "" || job.Fetch.Dir != job.Dir { // a build is for one module: its fetch names the directory (A-447b) - t.Errorf("the compose job's fetch names the directory %q, want its module's %q", job.Fetch.Dir, job.Dir) - } - var req composer.Request - if len(job.Request) == 0 || job.Request[0] != '"' { - t.Errorf("the request went whole, not packed (issue 1966): %.60s", job.Request) - } - body, _ := job.RequestBytes() - _ = json.Unmarshal(body, &req) - if job.Fetch.Repository != nodeEngineRepo || job.Fetch.Commit != head2 || job.Package != composer.Package || - string(req.Input) != `{"nodes":[{"name":"anchor"}]}` || req.Cases[0].Manifests["web"].Digest == "" || - len(req.Seats) != 1 || string(req.Seats[0]) != string(host.Seats[0]) { - t.Errorf("job = %+v, request %+v", job, req) - } - // Issue 1921 (notes 66-67): the request sent to the composer is kept per check and node, exactly as sent (read back - // whole through the tool's reader); a request that cannot be kept fails the node's composition, naming why. - store := &keptRequests{} - ec.Requests = RequestKeeper{Store: store} - if _, err := ec.Compose(context.Background(), host); err != nil { - t.Fatal(err) - } - keyOfHost, _ := nodeengineclient.CompositionKey(host.Group, host.Heads) - lastBody, _ := sb.jobs[len(sb.jobs)-1].RequestBytes() - got, err := ReadRequests(store.read(), keyOfHost, "anchor") - if b, _ := json.Marshal(got); err != nil || !strings.Contains(string(b), `"request":`+string(lastBody)) { - t.Errorf("kept %s, %v: want the request of the last job under %s/anchor", b, err, keyOfHost) - } - store.err = errors.New("the state is full") - raw, _ = ec.Compose(context.Background(), host) - if v := rules.JudgeEngines(raw); v.State != meshdeliverycheckerclient.CompositionFail || !strings.Contains(v.Words, "could not be kept") || !strings.Contains(v.Words, "the state is full") || !strings.Contains(v.Words, RequestsDropTool) { - t.Errorf("a request that cannot be kept gave %+v, which must name %s", v, RequestsDropTool) - } - // The drop tool: records the hand act first (a drop whose act is not recorded is not made), then drops that check's - // requests and the pieces no other kept request names; another check's stay. - store.err = nil - other := RequestKeeper{Store: store} - if err := other.Keep(context.Background(), "g.other", "anchor", []byte("another check's request")); err != nil { - t.Fatal(err) - } - drop := StateDrop{StateRead: store.read(), Delete: func(k string) error { store.mu.Lock(); delete(store.vals, k); store.mu.Unlock(); return nil }} - before := len(store.vals) - if _, err := DropRequests(drop, keyOfHost, "the state is full", func(string) error { return errors.New("no holder") }); err == nil || len(store.vals) != before { - t.Errorf("a drop whose hand act was not recorded was made: %v, %d of %d kept", err, len(store.vals), before) - } - var acts []string - answer, err := DropRequests(drop, keyOfHost, "the state is full", func(what string) error { acts = append(acts, what); return nil }) - if b, _ := json.Marshal(answer); err != nil || len(acts) != 1 || !strings.Contains(string(b), `"dropped_requests":["anchor"]`) { - t.Errorf("the drop answered %s, %v, acts %v", b, err, acts) - } - if _, still := store.vals[RequestKey(keyOfHost, "anchor")]; still { - t.Errorf("the dropped check's request is kept still") - } - if got, err := ReadRequests(store.read(), "g.other", "anchor"); err != nil || !strings.Contains(fmt.Sprint(got), "another check's request") { - t.Errorf("another check's request after the drop: %v, %v", got, err) - } - if _, err := DropRequests(drop, keyOfHost, "again", func(string) error { return nil }); err == nil { - t.Errorf("a check with no kept request was dropped") - } - ec.Requests = nil - // Issue 1921: the composer is built at the group's heads, also a member that publishes no package yet. - if pkgs := job.Fetch.Packages; len(pkgs) != 1 || pkgs[trunk.ForgeModulePrefix+"mesh-delivery"] != head1 { - t.Errorf("the composer is fetched with the packages %v, want the group's mesh-delivery member at its head %s alone", pkgs, head1) - } - if v.State != meshdeliverycheckerclient.CompositionFail || v.Sdk != head2 || !strings.Contains(v.Words, "the new composer refuses it") { - t.Errorf("verdict = %+v", v) - } - // ADR 0593 §9 (ADR 0601 §4's kind): a node the composer did not judge is named as no answer with its words, by the - // contract's field, and the check passes; words in Reason alone are no such mark. - sb.err = nil - for _, row := range []struct { - m composer.Machine - pass bool - }{ - {composer.Machine{NotJudged: "its node-engine sends no running state for web"}, true}, - {composer.Machine{Reason: "not judged: its node-engine sends no running state for web"}, false}, - } { - sb.v = func(node string) composer.Verdict { - return composer.Verdict{V: composer.Version, Cases: []composer.CaseVerdict{{Name: "change", Machines: map[string]composer.Machine{node: row.m}}}} - } - raw, err = ec.Compose(context.Background(), host) - v = rules.JudgeEngines(raw) - named := len(v.Warnings) == 1 && strings.Contains(v.Warnings[0], "anchor: "+nec.NoAnswer+" (its node-engine sends no running state for web)") - if err != nil || (v.State == meshdeliverycheckerclient.CompositionPass) != row.pass || named != row.pass { - t.Errorf("%+v: verdict %+v, %v", row.m, v, err) - } - } - // Review finding 3 (ADR 0593 §9 lets only a node that does not answer pass): a composer at the head that cannot - // run fails the composition, naming the head, never passing as a silent node. - sb.err = errors.New("the build of mesh-compose failed") - raw, err = ec.Compose(context.Background(), host) - v = rules.JudgeEngines(raw) - if err != nil || v.State != meshdeliverycheckerclient.CompositionFail || !strings.Contains(v.Words, head2) || - !strings.Contains(v.Words, "the build of mesh-compose failed") || len(v.Warnings) != 0 { - t.Errorf("a composer that cannot run: %+v, %v", v, err) - } - }) - - // ADR 0578 §2, §3, ADR 0656 §5 (milestone 47/G D12, D13): with no node-engine member, every node is composed by the - // composer built at the node-engine's trunk over the input its engine answers, and a manifest the change brings carries - // the check's own judge's verdict, not the running indexer's: one the running indexer refused and the judge accepted - // composes, and the verdict names the trunk's composer. - t.Run("a change's manifest the check's judge accepted is composed by the composer at the node-engine's trunk", func(t *testing.T) { - p := pullOf(repoA, 7, head1) - p.Modules = []string{"mesh-build-go"} - p.Fps = map[string]meshcatalog.CandidatesByGroupValuePullsItemFpsValue{"mesh-build-go": {Fp2: "src2:" + strings.Repeat("f", 64), Manifest: strings.Repeat("d", 64)}} - brings := caseOf(t, p) - brings.Judged = map[string]json.RawMessage{"mesh-build-go": json.RawMessage(`{"module":"mesh-build-go","state":"accepted"}`)} - trunkHead := strings.Repeat("7", 40) - withInput := composed("anchor") - withInput.Input = map[string]any{"nodes": []any{map[string]any{"name": "anchor"}}} - e := &fakeEngines{answers: map[string]ne.ComposeCandidateAnswer{"anchor": withInput}} - sb := &fakeSandbox{v: func(node string) composer.Verdict { - return composer.Verdict{V: composer.Version, Cases: []composer.CaseVerdict{{Name: "change", - Machines: map[string]composer.Machine{node: {Composes: true}}}}} - }} - indexer := map[string]meshcatalog.VerdictsByDigestValue{"mesh-build-go": {Module: "mesh-build-go", State: "refused", Problems: []string{"serves no verb input"}}, "mail": {Module: "mail", State: "accepted"}} - ec := EngineCompositions{Asker: e, Placed: func() ([]string, error) { return []string{"anchor"}, nil }, Bound: time.Second, - Sandbox: sb, Composer: func() string { return trunkHead }, Published: published{}, - Verdicts: func() map[string]meshcatalog.VerdictsByDigestValue { return indexer }} - raw, err := ec.Compose(context.Background(), brings) - if err != nil { - t.Fatal(err) - } - if v := rules.JudgeEngines(raw); v.State != meshdeliverycheckerclient.CompositionPass || v.Sdk != trunkHead { - t.Fatalf("verdict = %+v, want a pass composed at the node-engine's trunk %s", v, trunkHead) - } - if len(sb.jobs) != 1 || sb.jobs[0].Fetch.Commit != trunkHead || sb.jobs[0].Fetch.Repository != nodeEngineRepo { - t.Fatalf("jobs %+v: want one job at the node-engine's trunk", sb.jobs) - } - var req composer.Request - b0, _ := sb.jobs[0].RequestBytes() - _ = json.Unmarshal(b0, &req) - if got := string(req.Cases[0].Verdicts["mesh-build-go"]); got != string(brings.Judged["mesh-build-go"]) || len(req.Cases[0].Verdicts) != 2 { - t.Errorf("the request's verdicts %s: want the check's judge's for mesh-build-go and the indexer's for mail", req.Cases[0].Verdicts) - } - // A manifest the judge gave no verdict on carries none, which the composer reads as accepted (ADR 0578 §3). - brings.Judged = nil - if _, err := ec.Compose(context.Background(), brings); err != nil { - t.Fatal(err) - } - var none composer.Request - bn, _ := sb.jobs[len(sb.jobs)-1].RequestBytes() - _ = json.Unmarshal(bn, &none) - if _, kept := none.Cases[0].Verdicts["mesh-build-go"]; kept { - t.Errorf("the running indexer's verdict on the change's manifest was kept: %s", none.Cases[0].Verdicts) - } - // A refusal the trunk's composer makes stays the node-engine's own. - sb.v = func(node string) composer.Verdict { - return composer.Verdict{V: composer.Version, Cases: []composer.CaseVerdict{{Name: "change", - Machines: map[string]composer.Machine{node: {Composes: false, Reason: "a required value is unset"}}}}} - } - raw, _ = ec.Compose(context.Background(), brings) - if v := rules.JudgeEngines(raw); v.State != meshdeliverycheckerclient.CompositionFail || !strings.Contains(v.Words, "a required value is unset") { - t.Errorf("a refusal the trunk's composer makes: %+v", v) - } - }) - - // Review finding 4: assignments that cannot be read is no mesh with no node: the composition is not made, said. - t.Run("an unreadable assignments makes no composition", func(t *testing.T) { - ec := EngineCompositions{Asker: &fakeEngines{}, Placed: func() ([]string, error) { return nil, errors.New("no such bucket") }} - if _, err := ec.Compose(context.Background(), cs); err == nil || !strings.Contains(err.Error(), "no such bucket") { - t.Errorf("an unreadable assignments: %v", err) - } - b := newBench(t) - b.ex.Compositions = ec - v := b.judge(t, cs).Verdict - if v.Composition == nil || v.Composition.State != meshdeliverycheckerclient.CompositionNotRun || !strings.Contains(v.Composition.Words, "no such bucket") { - t.Errorf("the verdict's composition = %+v", v.Composition) - } - }) -} diff --git a/modules/mesh-delivery-checker/internal/check/every_failure_test.go b/modules/mesh-delivery-checker/internal/check/every_failure_test.go deleted file mode 100644 index 6016ff00..00000000 --- a/modules/mesh-delivery-checker/internal/check/every_failure_test.go +++ /dev/null @@ -1,119 +0,0 @@ -package check - -import ( - "encoding/json" - "fmt" - "mesh-delivery-checker/rules" - "strings" - "testing" - - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshdeliverycheckerclient" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshdeliverychecker" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep" -) - -// failingResult is a level's test result in which the named tests failed, each in its own package. -func failingResult(t *testing.T, tests int, failed ...Failure) json.RawMessage { - t.Helper() - raw, err := json.Marshal(Tested{Level: buildstep.LevelIntegration, Tests: tests, Elapsed: 2, Failed: failed, Passed: len(failed) == 0}) - if err != nil { - t.Fatal(err) - } - return raw -} - -func judgeLevel(t *testing.T, tests ...json.RawMessage) (*meshdeliverychecker.VerdictsByGroupHeadsValue, *state) { - t.Helper() - st := &state{j: &Examiner{}, c: &Case{}, levels: rules.NewTally()} - st.level(t.Context(), &target{pull: Pull{Repository: "novox/x"}}, buildstep.LevelAnswer{Level: buildstep.LevelIntegration, Tests: tests}) - // 1921 (B0, D1a): the running checker only gathers the level as a fact; the rules judge it, and count what it kept. - judged := rules.Judge(rules.Facts{V: rules.FactsVersion, Steps: st.facts}) - if judged.Levels[buildstep.LevelIntegration] != (meshdeliverychecker.VerdictsByGroupHeadsValueLevelsValue{Run: int64(st.levels[buildstep.LevelIntegration].Run)}) { - t.Errorf("the rules count %+v, the running checker %+v", judged.Levels, *st.levels[buildstep.LevelIntegration]) - } - if judged.State == meshdeliverycheckerclient.VerdictPass { - return nil, st - } - return &judged, st -} - -// Issue 1921: two failing tests in two packages are two entries of the verdict's Failures and two lines of a try's -// failed list, each with its own first line (its cause, issue 1901), whether the build module answered them in one test -// result (one go test run over both packages) or in two (the changed packages first, then the rest); every result is -// counted, the ones after a failure too; and Failed keeps the first one's words whole. -func TestTwoFailingTestsInTwoPackagesAreTwoEntries(t *testing.T) { - a := Failure{Package: "x/a", Test: "TestA", Cause: "a_test.go:9: want 1, got 2", Output: " a_test.go:3: logged\n a_test.go:9: want 1, got 2\n--- FAIL: TestA (0.00s)"} - b := Failure{Package: "x/b", Test: "TestB", Cause: "b_test.go:4: boom", Output: " b_test.go:4: boom\n--- FAIL: TestB (0.00s)"} - for name, tests := range map[string][]json.RawMessage{ - "one result": {failingResult(t, 10, a, b)}, - "two results": {failingResult(t, 4, a), failingResult(t, 3), failingResult(t, 3, b)}, - } { - v, st := judgeLevel(t, tests...) - if v == nil { - t.Fatalf("%s: the level passed", name) - } - want := []string{"integration: x/a.TestA: a_test.go:9: want 1, got 2", "integration: x/b.TestB: b_test.go:4: boom"} - if got := failedLines(*v); strings.Join(got, "\n") != strings.Join(want, "\n") { - t.Errorf("%s: failed lines\n%s\nwant\n%s", name, strings.Join(got, "\n"), strings.Join(want, "\n")) - } - if len(v.Failures) != 2 || v.Failed.Test != "integration: x/a.TestA" || !strings.Contains(v.Failed.Words, "a_test.go:3: logged") { - t.Errorf("%s: verdict %+v", name, v) - } - if run := st.levels[buildstep.LevelIntegration].Run; run != 10 { - t.Errorf("%s: %d tests counted, want all 10", name, run) - } - if _, err := meshdeliverycheckerclient.EncodeVerdict(meshdeliverychecker.VerdictsByGroupHeadsValue{Group: "g", Heads: "0123456789ab", State: v.State, Failed: v.Failed, Failures: v.Failures}); err != nil { - t.Errorf("%s: the verdict is not written: %v", name, err) - } - } - // Design 26 *Out of step* (DLV-C2): the out-of-step files the compare step names, in each result, are the outcome's for - // the pull request, each once and sorted; a level naming none leaves the outcome with none. - step := func(files ...string) json.RawMessage { - raw, _ := json.Marshal(Tested{Level: buildstep.LevelUnit, Tests: 1, Passed: false, Why: "out of step", OutOfStep: files}) - return raw - } - _, st := judgeLevel(t, step("go/seats/b/contract.go", "go/seats/a/contract.go"), step("go/seats/a/contract.go")) - if got := st.outcome(meshdeliverychecker.VerdictsByGroupHeadsValue{State: meshdeliverycheckerclient.VerdictFail}).OutOfStep["novox/x#0"]; strings.Join(got, ",") != "go/seats/a/contract.go,go/seats/b/contract.go" { - t.Errorf("out of step %v", got) - } - if _, st := judgeLevel(t, failingResult(t, 2, a)); st.outcome(meshdeliverychecker.VerdictsByGroupHeadsValue{State: meshdeliverycheckerclient.VerdictFail}).OutOfStep != nil { - t.Errorf("a level naming no out-of-step file has %v", st.outOfStep) - } -} - -// Issue 1921: past meshdeliverycheckerclient.MaxFailures the list names the first fifty and how many more, the status line says how many -// failed and names the first, cut so "and N more" stays whole, and each entry's line is cut to rules.MaxFailureLine. -func TestFailuresAreCappedWithHowManyMore(t *testing.T) { - var fs []Failure - for i := range 60 { - fs = append(fs, Failure{Package: fmt.Sprintf("x/p%d", i), Test: "TestT", Cause: strings.Repeat("y", 500)}) - } - v, _ := judgeLevel(t, failingResult(t, 60, fs...)) - if len(v.Failures) != meshdeliverycheckerclient.MaxFailures+1 || v.Failures[meshdeliverycheckerclient.MaxFailures].Test != "and 10 more" { - t.Fatalf("%d entries, last %+v", len(v.Failures), v.Failures[len(v.Failures)-1]) - } - if len(v.Failures[0].Words) > rules.MaxFailureLine { - t.Errorf("an entry's line is %d bytes", len(v.Failures[0].Words)) - } - if n := rules.FailedCount(*v); n != 60 { - t.Errorf("failedCount = %d, want 60", n) - } - cs := &Case{Pulls: []Pull{{Repository: "novox/x", Head: "0123456789abcdef", Trunk: "fedcba9876543210"}}} - if line := Line(*v, cs, cs.Pulls[0], nil, nil, nil); !strings.HasPrefix(line, "failed (60): integration: x/p0.TestT: yyy") || - !strings.Contains(line, "…; and 59 more | 0123456789ab on fedcba987654") { - t.Errorf("line %q", line) - } - // A composition failing after them is counted in the last entry (the operator, 2026-11-02). - refused := refusedOn("x", "g14", "route-proxy is defined twice") - rules.JudgeComposition(v, rules.Composition{Composed: &refused}) - if n := rules.FailedCount(*v); n != 61 || v.Failed.Test != "integration: x/p0.TestT" { - t.Errorf("after the composition failedCount = %d, failed %+v", n, v.Failed) - } - - // A verdict that names no list (a conflict, a refused step, a verdict written before issue 1921) is one failed line, as - // before. - one := meshdeliverychecker.VerdictsByGroupHeadsValue{State: meshdeliverycheckerclient.VerdictFail, Failed: &FailedFirst{Machine: "g14", Words: "files in conflict: go.mod\nmore"}} - if got := failedLines(one); len(got) != 1 || got[0] != "g14: files in conflict: go.mod" { - t.Fatalf("%q", got) - } -} diff --git a/modules/mesh-delivery-checker/internal/check/examiner_test.go b/modules/mesh-delivery-checker/internal/check/examiner_test.go deleted file mode 100644 index e09bbee2..00000000 --- a/modules/mesh-delivery-checker/internal/check/examiner_test.go +++ /dev/null @@ -1,1671 +0,0 @@ -package check - -import ( - "cmp" - "context" - "crypto/sha256" - "encoding/hex" - "encoding/json" - "errors" - "fmt" - "io/fs" - "mesh-delivery-checker/rules" - "os" - "path/filepath" - "reflect" - "slices" - "sort" - "strings" - "sync" - "testing" - "testing/fstest" - "time" - "unicode/utf8" - - "git.novox.be/novox/mesh-contracts/go/seats/meshconfig" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-builder/buildrun" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-builder/builds" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshdeliverycheckerclient" - "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/meshdeliverychecker" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/composer" - gobuild "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/steprun" - "git.novox.be/novox/mesh-sdk/go/catalogue" -) - -// captured reads a result the build module's own code marshalled (testdata/captured/README). -func captured[T any](t testing.TB, name string) T { - t.Helper() - raw, err := os.ReadFile(filepath.Join("testdata", "captured", name+".json")) - if err != nil { - t.Fatal(err) - } - var v T - if err := json.Unmarshal(raw, &v); err != nil { - t.Fatal(err) - } - return v -} - -type stepCall struct { - module, node, tool string - args map[string]any -} - -// fakeSteps stands for the build modules: a handler for each tool answers what the module's code answers. -type fakeSteps struct { - mu sync.Mutex - calls []stepCall - handlers map[string]func(c stepCall) (any, error) -} - -func (f *fakeSteps) Run(_ context.Context, module, node, tool string, args map[string]any) (json.RawMessage, error) { - c := stepCall{module, node, tool, args} - f.mu.Lock() - f.calls = append(f.calls, c) - h := f.handlers[tool] - f.mu.Unlock() - if h == nil { - return nil, fmt.Errorf("the fake build module has no tool %s", tool) - } - v, err := h(c) - if err != nil { - return nil, err - } - return json.Marshal(v) -} - -func (f *fakeSteps) tool(name string) []stepCall { - f.mu.Lock() - defer f.mu.Unlock() - var out []stepCall - for _, c := range f.calls { - if strings.HasSuffix(c.tool, "_"+name) { - out = append(out, c) - } - } - return out -} - -type entries []buildstep.NodeToolchain - -func (e entries) Entries(language string) []buildstep.NodeToolchain { - var out []buildstep.NodeToolchain - for _, x := range e { - if x.Language == language { - out = append(out, x) - } - } - return out -} - -type langs map[string][]string - -func (l langs) BuildModules(repository string) []string { - if m, ok := l[repository]; ok { - return m - } - return []string{goBuildModule} -} - -func goEntries(nodes ...string) entries { - var e entries - for _, n := range nodes { - e = append(e, buildstep.NodeToolchain{Node: n, Toolchain: buildstep.Toolchain{Language: "go", Version: "go1.27.1", Recipe: "7"}}) - e = append(e, buildstep.NodeToolchain{Node: n, Toolchain: buildstep.Toolchain{Language: "typescript", Version: "node24", Recipe: "3"}}) - } - return e -} - -const digC = "cc33cc33cc33cc33cc33cc33cc33cc33cc33cc33cc33cc33cc33cc33cc33cc33" -const digD = "dd44dd44dd44dd44dd44dd44dd44dd44dd44dd44dd44dd44dd44dd44dd44dd44" - -type bench struct { - ex *Examiner - asks *buildrun.FakeAsks - steps *fakeSteps - kept *memKV - prev *memKV - fetch Fetched - digest map[string]Digested // by level - test func(c stepCall) (any, error) - // declines is how many asks naming needs a node lacking them declines before shanks, which has every need, takes - // one (issue 890); an ask naming none runs on shanks, which then has none. - declines int - // inputs are the checking program's kept inputs; heads the heads laid for it (none when nil); run, when set, answers - // a run ask in its place (a program that does not build or answer). - inputs *memKV - heads fs.FS - run func(a buildstep.StepAsk) (buildstep.Step, bool) - mu sync.Mutex - runs []buildstep.StepAsk // the run asks put -} - -// benchAsks puts the bench's asks: a run ask is answered at once by the checking program's work (answerRun), written by -// write and kept apart (bench.runs); every other ask goes to inner (the fake bus by default), answered as it answers. -type benchAsks struct { - b *bench - inner buildrun.AskPublisher - write func(buildstep.Step) -} - -func (b *bench) asker(inner buildrun.AskPublisher, write func(buildstep.Step)) benchAsks { - return benchAsks{b: b, inner: inner, write: write} -} - -func (p benchAsks) PublishAsk(ctx context.Context, subject, id string, data []byte) error { - inner, write := p.inner, p.write - if inner == nil { - inner, write = p.b.asks, p.b.asks.Write - } - a, err := buildstep.DecodeStepAsk(data) - if err != nil || a.Run == nil { - return inner.PublishAsk(ctx, subject, id, data) - } - p.b.mu.Lock() - p.b.runs = append(p.b.runs, a) - p.b.mu.Unlock() - if step := p.b.answerRun(a); step.ID != "" { - write(step) - } - return nil -} - -// trunkD is mesh-delivery's trunk the bench's checking program is built at. -var trunkD = strings.Repeat("d", 40) - -// answerRun answers a run ask as the build module would: the checking program's work (rules.Program) over the input the -// ask names, read from the kept inputs and checked against its digest. -func (b *bench) answerRun(a buildstep.StepAsk) buildstep.Step { - began := time.Date(2026, 10, 21, 19, 0, 0, 0, time.UTC) - step := buildstep.Step{ID: a.ID, Tool: a.Kind + " ask", Node: "shanks", State: buildstep.StepPassed, Started: began, Ended: began.Add(time.Second)} - if b.run != nil { - if s, ok := b.run(a); ok { - return s - } - } - answer := buildstep.RunAnswer{Built: true, Key: "program-0123456789abcdef"} - out, err := rules.Program(a.Run.Args, func() ([]byte, error) { - body, _, _, _ := b.inputs.Get(context.Background(), a.Run.Input.Digest) - return body, a.Run.Input.Verify(body) - }, b.heads) - if err != nil { - answer.Exit, answer.Said = 2, err.Error() - } - answer.Output = out - step.Result, _ = json.Marshal(answer) - return step -} - -// refsOf reads the siblings of a fetch's arguments, as they arrive in an ask (JSON) or as the checker gave them. -func refsOf(v any) []BesideRef { - raw, _ := json.Marshal(v) - var refs []BesideRef - _ = json.Unmarshal(raw, &refs) - return refs -} - -// toolPrefix is the start of each build module's tool names, as the fake build modules answer them. -var toolPrefix = map[string]string{goBuildModule: "build_go_", nodeBuildModule: "build_node_"} - -// answer runs a check ask as the build module that pulls it does (gobuild.RunAsk), with the fake tools on shanks and the -// bench's kept verdicts, and answers the step it writes. -func (b *bench) answer(a buildstep.StepAsk) buildstep.Step { - bm, _ := testSeats().OfAskLanguage(a.Language) - module := bm.Module - const node = "shanks" - tool := func(name string) gobuild.StepFunc { - return func(ctx context.Context, args map[string]any) (any, error) { - raw, err := b.steps.Run(ctx, module, node, toolPrefix[module]+name, args) - if err != nil { - return nil, err - } - return raw, nil - } - } - steps := gobuild.AskSteps{Fetch: tool("fetch"), Test: tool("test"), - Kept: func(ctx context.Context, level, digest string) (int, bool, error) { - k, found, err := (Kept{Store: b.kept}).Lookup(ctx, level, digest) - return int(k.Tests), found, err - }} - if module == goBuildModule { - steps.Digest = tool("digest") - } - began := time.Date(2026, 10, 21, 19, 0, 0, 0, time.UTC) - if len(a.Needs) > 0 { - if b.declines > 0 { - b.declines-- - result, _ := json.Marshal(buildstep.StepDeclined{Declined: true, Needs: a.Needs, Lacks: a.Needs}) - return buildstep.Step{ID: a.ID, Tool: a.Kind + " ask", Node: "ace", State: buildstep.StepRefused, Started: began, Ended: began, - Reason: "declined", Result: result} - } - steps.Has = func(string) bool { return true } - } - out, err := gobuild.RunAsk(context.Background(), steps, a) - step := buildstep.Step{ID: a.ID, Tool: a.Kind + " ask", Node: node, State: buildstep.StepPassed, Started: began, Ended: began.Add(2 * time.Second)} - if out != nil { - step.Result, _ = json.Marshal(out) // a failed step keeps what it answered beside its error, as the step runner does - } - if err != nil { - step.State, step.Reason = buildstep.StepFailed, err.Error() - } - return step -} - -// newBench is an examiner over fake build modules that merge cleanly, digest the captured fixture's packages and pass -// the captured slow fixture's result at both levels, on shanks. -func newBench(t testing.TB) *bench { - b := &bench{steps: &fakeSteps{}, kept: newMemKV(), prev: newMemKV(), inputs: newMemKV(), heads: fstest.MapFS{}} - b.fetch = captured[Fetched](t, "go-fetch-clean") - b.fetch.Modules, b.fetch.Changed, b.fetch.Trees = []string{"."}, []string{"README.md"}, nil - one := captured[Digested](t, "go-digest") - b.digest = map[string]Digested{ - buildstep.LevelUnit: {Level: "unit", Packages: map[string]string{"fixture/slow": digA}}, - buildstep.LevelIntegration: {Level: "integration", Packages: map[string]string{"fixture/slow": digB}}, - } - _ = one - slow := captured[Tested](t, "go-test-slow") - b.test = func(c stepCall) (any, error) { - r := slow - r.Level, _ = c.args["level"].(string) - return r, nil - } - b.steps.handlers = map[string]func(stepCall) (any, error){ - "build_go_fetch": func(stepCall) (any, error) { return b.fetch, nil }, - "build_node_fetch": func(stepCall) (any, error) { return b.fetch, nil }, - "build_go_digest": func(c stepCall) (any, error) { return echoBeside(b, b.digest[c.args["level"].(string)]), nil }, - "build_go_test": func(c stepCall) (any, error) { return b.test(c) }, - "build_node_test": func(c stepCall) (any, error) { return b.test(c) }, - } - now := time.Date(2026, 10, 21, 19, 0, 0, 0, time.UTC) - b.asks = &buildrun.FakeAsks{Answer: b.answer} - b.ex = &Examiner{Module: "acme-checker", Asks: buildrun.Asker{Seats: testSeats(), Publisher: b.asker(nil, nil), Waiter: b.asks, Bound: 5 * time.Second}, Toolchains: goEntries("shanks"), Kept: Kept{Store: b.kept}, Previews: b.prev, - Modules: langs{}, Seats: testSeats(), Trunks: &Trunks{heads: map[string]string{DeliveryRepository: trunkD}}, Inputs: memInputs{b.inputs}, Now: func() time.Time { now = now.Add(50 * time.Millisecond); return now }} - return b -} - -func caseOf(t testing.TB, pulls ...meshcatalog.CandidatesByGroupValuePullsItem) *Case { - t.Helper() - raw := candidateOf(t, "feat/x", pulls...) - c, err := meshcatalog.DecodeCandidatesByGroupValue(raw) - if err != nil { - t.Fatal(err) - } - cs := CaseOf(c, map[string]string{repoA: trunkA, repoSDK: trunkS, "novox/mesh-controller": trunkA, "novox/mesh-catalog": trunkA, - "novox/mesh-host": trunkA, "novox/mesh-networking": trunkA}) - if cs == nil { - t.Fatal("no case") - } - return cs -} - -func (b *bench) judge(t testing.TB, cs *Case) Outcome { - t.Helper() - out, err := b.ex.Judge(context.Background(), cs) - if err != nil { - t.Fatal(err) - } - return out -} - -func testedWith(t testing.TB, name string, edit func(*Tested)) Tested { - r := captured[Tested](t, name) - if edit != nil { - edit(&r) - } - return r -} - -func packagesOf(c stepCall) []string { - var out []string - if l, ok := c.args["packages"].([]string); ok { - out = l - } - return out -} - -// overlapAsks counts the asks put and not yet ended, and the most at once: a wait holds until a second ask is put, or a -// second passed, so asks put one after another never overlap. -type overlapAsks struct { - Asks - mu sync.Mutex - open, top int - more chan struct{} -} - -func (o *overlapAsks) Put(ctx context.Context, a buildstep.StepAsk) error { - o.mu.Lock() - o.open++ - if o.open > o.top { - o.top = o.open - } - if o.open >= 2 { - select { - case <-o.more: - default: - close(o.more) - } - } - o.mu.Unlock() - return o.Asks.Put(ctx, a) -} - -func (o *overlapAsks) Wait(ctx context.Context, a buildstep.StepAsk) (buildstep.Step, error) { - select { - case <-o.more: - case <-time.After(time.Second): - } - defer func() { o.mu.Lock(); o.open--; o.mu.Unlock() }() - return o.Asks.Wait(ctx, a) -} - -// Design 47 G A-304 (ADR 0525 §4): a phase puts every ask of its own at once and then waits for them all, and the -// verdict is judged in the order of the members as before. -func TestAPhasesAsksAreAllOutstandingAtOnce(t *testing.T) { - b := newBench(t) - o := &overlapAsks{Asks: b.ex.Asks, more: make(chan struct{})} - b.ex.Asks = o - v := b.judge(t, caseOf(t, pullOf(repoA, 7, head1), pullOf(repoSDK, 12, head2))).Verdict - if o.top < 2 { - t.Errorf("at most %d asks were outstanding at once, want both members' asks of the phase", o.top) - } - if v.State != meshdeliverycheckerclient.VerdictPass { - t.Errorf("verdict = %+v", v) - } - if fetch := b.steps.tool("fetch"); len(fetch) != 2 { - t.Errorf("fetch calls = %+v, want one per member", fetch) - } -} - -func TestACleanMergeIsFetchedAtItsTrunkAndBothLevelsPass(t *testing.T) { // 1679/AC1 - b := newBench(t) - cs := caseOf(t, pullOf(repoA, 7, head1)) - out := b.judge(t, cs) - v := out.Verdict - if v.State != meshdeliverycheckerclient.VerdictPass || v.Levels[buildstep.LevelUnit].Run != 2 || v.Levels[buildstep.LevelIntegration].Run != 2 { - t.Fatalf("verdict = %+v", v) - } - if v.Composition == nil || v.Composition.State != meshdeliverycheckerclient.CompositionNotRun { - t.Errorf("composition = %+v, want not run", v.Composition) - } - if len(v.Machines) != 1 || v.Machines[0] != "shanks" { - t.Errorf("machines = %v", v.Machines) - } - fetch := b.steps.tool("fetch") - if len(fetch) != 1 || fetch[0].args["repository"] != repoA || fetch[0].args["commit"] != head1 || fetch[0].args["base"] != trunkA || fetch[0].args["ref"] != "refs/pull/7/head" { - t.Fatalf("fetch calls = %+v", fetch) - } - if v.Took.Clone <= 0 || v.Took.Unit <= 0 { - t.Errorf("took = %+v, want the clone and the unit level timed", v.Took) - } - // What passed is kept under each level's digest. - for _, k := range []string{"unit." + digA, "integration." + digB} { - if _, _, found, _ := b.kept.Get(context.Background(), k); !found { - t.Errorf("%s was not kept", k) - } - } - - // ADR 0567 §12: every check ask carries every node's name for the names check; a check whose names cannot be read, or - // that reads none, is not asked and fails saying so. - for _, c := range []struct { - names []string - err error - fails string - }{{[]string{"anchor", "laptop"}, nil, ""}, {nil, nil, "no node record"}, {nil, errors.New("no bucket"), "no bucket"}} { - b := newBench(t) - b.ex.Nodes = namesOf{c.names, c.err} - out := b.judge(t, caseOf(t, pullOf(repoA, 7, head1))) - asks := b.asks.Asks() - if c.fails != "" { - if out.Verdict.State != meshdeliverycheckerclient.VerdictFail || len(asks) != 0 || !strings.Contains(out.Verdict.Failed.Words, c.fails) { - t.Errorf("names %v, %v: verdict %+v, %d asks", c.names, c.err, out.Verdict, len(asks)) - } - } else if len(asks) == 0 || strings.Join(asks[0].Check.NodeNames, ",") != "anchor,laptop" { - t.Errorf("the check ask carries the names %v", asks) - } - } - - // Issue 1921 (B0, D4 to D6): the check's verdict is the checking program's, built at the group's mesh-delivery head, - // else at mesh-delivery's trunk, over the facts kept as its input; a program that is never begun, does not build or - // does not answer fails the check naming it, and a rule the change's program alters judges the check. - verdictOf := func(state, words string) json.RawMessage { - out, _ := json.Marshal(rules.Answer{V: rules.AnswerVersion, Verdict: meshdeliverychecker.VerdictsByGroupHeadsValue{State: state, Failed: &FailedFirst{Words: words}}}) - return out - } - for _, row := range []struct { - name string - repo string // the member's repository: mesh-delivery unless named - run func(a buildstep.StepAsk, s buildstep.Step) (buildstep.Step, bool) - at string // the commit the program is built at; empty when it fails - fails string - runs int // the run asks put when it fails: each put twice when never begun, and none after the seat list's - }{ - {name: "at the group's mesh-delivery head", at: head1}, - {name: "at mesh-delivery's trunk", repo: "novox/mesh-catalog", at: trunkD}, - {name: "never begun", run: func(buildstep.StepAsk, buildstep.Step) (buildstep.Step, bool) { return buildstep.Step{}, true }, - fails: "no build node began the job run of the asks", runs: 2}, - {name: "does not build", run: func(_ buildstep.StepAsk, s buildstep.Step) (buildstep.Step, bool) { - s.State, s.Reason = buildstep.StepFailed, "the program does not build: undefined: rules.Nothing" - return s, true - }, fails: "by the checking program: its run ask", runs: 1}, - // Design 47 G A-290: a run whose program exited other than 0 ends its key failed, its answer kept; the checker reads it. - {name: "a program that exits other than 0", run: func(_ buildstep.StepAsk, s buildstep.Step) (buildstep.Step, bool) { - s.State, s.Reason = buildstep.StepFailed, "the program exited 2: bad flag" - s.Result, _ = json.Marshal(buildstep.RunAnswer{Key: "program-0123456789abcdef", Built: true, Exit: 2, Said: "bad flag"}) - return s, true - }, fails: "it exited 2 on shanks: bad flag", runs: 1}, - {name: "a rule the change alters", at: head1, run: func(a buildstep.StepAsk, s buildstep.Step) (buildstep.Step, bool) { - if a.Run.Args[0] != "-verdict" { - return s, false - } - s.Result, _ = json.Marshal(buildstep.RunAnswer{Key: "program-0123456789abcdef", Output: verdictOf(meshdeliverycheckerclient.VerdictFail, "the change's own rule refuses it")}) - return s, true - }, fails: "the change's own rule refuses it"}, - } { - b := newBench(t) - b.ex.BeginBound = 20 * time.Millisecond - if row.run != nil { - b.run = func(a buildstep.StepAsk) (buildstep.Step, bool) { - return row.run(a, buildstep.Step{ID: a.ID, Tool: "check ask", Node: "shanks", State: buildstep.StepPassed}) - } - } - repo := cmp.Or(row.repo, repoA) - v := b.judge(t, caseOf(t, pullOf(repo, 7, head1))).Verdict - if row.fails != "" { - if v.State != meshdeliverycheckerclient.VerdictFail || !strings.Contains(v.Failed.Words, row.fails) { - t.Errorf("%s: verdict %+v, want a fail saying %q", row.name, v, row.fails) - } - if row.at == "" && (len(b.runs) != row.runs || v.JudgedBy != nil || slices.ContainsFunc(b.runs, func(a buildstep.StepAsk) bool { return a.Run.Args[0] == "-verdict" })) { - t.Errorf("%s: %d run asks, judged by %+v: want %d and none judging", row.name, len(b.runs), v.JudgedBy, row.runs) - } - } else if v.State != meshdeliverycheckerclient.VerdictPass { - t.Errorf("%s: verdict %+v", row.name, v) - } - if row.at == "" { - continue - } - if by := v.JudgedBy; by == nil || by.Program.Commit != row.at || by.Program.Package != CheckingProgramPackage || by.Key == "" || - len(by.Heads) != 1 || by.Heads[0].Repository != repo || by.Heads[0].Commit != head1 { - t.Errorf("%s: judged by %+v, want the program at %s over the member's head", row.name, v.JudgedBy, row.at) - } - if len(b.runs) != 2 || b.runs[0].Run.Args[0] != "-seats" || b.runs[1].Run.Args[0] != "-verdict" { - t.Fatalf("%s: run asks %+v, want the seat list and then the verdict", row.name, b.runs) - } - in := b.runs[1].Run.Input // the facts kept as their exact bytes under their digest - body, _, found, _ := b.inputs.Get(context.Background(), in.Digest) - if !found || in.Verify(body) != nil || in.Verb != InputVerb || - !strings.Contains(string(body), `"group":"feat/x"`) { - t.Errorf("%s: the verdict's input %+v is not kept whole: %s", row.name, in, body) - } - // Review round 1 of milestone 47/B0: a level is carried as the rules read it, without its digest, its packages or - // its kept packages' names, so a group's facts stay within the input's bound. - for _, unread := range []string{`"digest":{`, `"packages":[`, `"unmet"`, `"package":"m/`} { - if strings.Contains(string(body), unread) { - t.Errorf("%s: the facts carry %s, which no rule reads: %s", row.name, unread, body) - } - } - } -} - -// namesOf is the nodes' names as a test gives them. -type namesOf struct { - names []string - err error -} - -func (n namesOf) Names(context.Context) ([]string, error) { return n.names, n.err } - -func TestOnlyThePackageWithoutAKeptVerdictRuns(t *testing.T) { // 1288/AC1 - b := newBench(t) - b.digest[buildstep.LevelUnit] = Digested{Level: "unit", Packages: map[string]string{"fixture/slow": digA, "fixture/other": digC}} - if _, err := (Kept{Store: b.kept}).Keep(context.Background(), "unit", digC, keptValue("fixture/other", 40)); err != nil { - t.Fatal(err) - } - out := b.judge(t, caseOf(t, pullOf(repoA, 7, head1))) - tests := b.steps.tool("test") - if len(tests) != 2 || strings.Join(packagesOf(tests[0]), ",") != "fixture/slow" || tests[0].args["level"] != "unit" { - t.Fatalf("test calls = %+v, want the unit level of fixture/slow alone, then the integration level", tests) - } - if u := out.Verdict.Levels[buildstep.LevelUnit]; u.Run != 2 || u.Kept != 40 { - t.Errorf("unit = %+v, want 2 run and 40 kept", u) - } - - // Issue 890/AC5: a package needing node-build-node is left unmet where the node lacks it; the check keeps the passes - // and asks the integration level again for a node with it, puts it again when a node declines it, and that node tests - // the package alone, its kept passes not counted twice. - // fixture/outside has no kept verdict after its pass (it reads outside itself: its digest moves every call), so a - // placed ask that ran more than its unmet packages would run and count it again. - b = newBench(t) - b.declines = 1 - outside := 0 - b.steps.handlers["build_go_digest"] = func(c stepCall) (any, error) { - d := echoBeside(b, b.digest[c.args["level"].(string)]) - if d.Level == "integration" { - outside++ - d.Packages = map[string]string{"fixture/slow": digB, "fixture/node": digC, "fixture/outside": fmt.Sprintf("%064x", outside)} - } - return d, nil - } - b.digest[buildstep.LevelIntegration] = Digested{Level: "integration", - Needs: []buildstep.PackageNeeds{{Package: "fixture/node", Needs: []string{buildstep.NeedNodeBuildNode}}}} - out = b.judge(t, caseOf(t, pullOf(repoA, 7, head1))) - asks := b.asks.Asks() - if out.Verdict.State != meshdeliverycheckerclient.VerdictPass || len(asks) != 3 || len(asks[0].Needs) != 0 { - t.Fatalf("verdict %+v, asks %+v: want a pass of three asks, the first naming no need", out.Verdict, asks) - } - for _, a := range asks { // ADR 0584: every check ask names the agreed toolchain, so a node off it declines - if a.Check.Toolchain == nil || a.Check.Toolchain.Version != "go1.27" || a.Check.Toolchain.Recipe != "7" { - t.Errorf("a check ask names toolchain %+v, want go1.27 recipe 7", a.Check.Toolchain) - } - } - for _, a := range asks[1:] { - if strings.Join(a.Needs, ",") != buildstep.NeedNodeBuildNode || strings.Join(a.Check.Levels, ",") != buildstep.LevelIntegration || strings.Join(a.Check.Packages, ",") != "fixture/node" { - t.Errorf("a placed ask %+v, want the integration level needing node-build-node", a) - } - } - tests = b.steps.tool("test") - if last := tests[len(tests)-1]; len(tests) != 3 || strings.Join(packagesOf(last), ",") != "fixture/node" || last.args["level"] != "integration" { - t.Errorf("test calls = %+v, want the unit level, the integration level of fixture/slow and fixture/outside, then fixture/node alone", tests) - } - slow := captured[Tested](t, "go-test-slow") - if i := out.Verdict.Levels[buildstep.LevelIntegration]; int(i.Run) != 2*slow.Tests || i.Kept != 0 { - t.Errorf("integration = %+v, want %d run and nothing counted kept", i, 2*slow.Tests) - } - // And where no node has the need, the check fails once the declines outlast the bound, naming the need. - b.kept, b.declines = newMemKV(), 1000 - b.ex.Kept, b.ex.DeclineBound = Kept{Store: b.kept}, 200*time.Millisecond - if v := b.judge(t, caseOf(t, pullOf(repoA, 7, head1))).Verdict; v.State != meshdeliverycheckerclient.VerdictFail || !strings.Contains(failedOf(v).Words, "needs a node with node-build-node") { - t.Errorf("with no node having the need: %+v", v) - } -} - -func TestAReAskRunsOnlyWhatFailedAndWhatChanged(t *testing.T) { // 1288/AC2, AC3 - b := newBench(t) - failing := captured[Tested](t, "go-test-failing") - b.digest[buildstep.LevelUnit] = Digested{Level: "unit", Packages: map[string]string{"fixture/failing/bad": digA, "fixture/failing/good": digB}} - b.test = func(c stepCall) (any, error) { - if c.args["level"] == "unit" { - return failing, nil - } - return captured[Tested](t, "go-test-slow"), nil - } - cs := caseOf(t, pullOf(repoA, 7, head1)) - first := b.judge(t, cs).Verdict - if first.State != meshdeliverycheckerclient.VerdictFail || first.Failed.Test != "unit: fixture/failing/bad.TestThreeIsFour" { - t.Fatalf("first = %+v", first) - } - if _, _, found, _ := b.kept.Get(context.Background(), "unit."+digB); !found { - t.Fatal("the package that passed in the failing run was not kept") - } - if _, _, found, _ := b.kept.Get(context.Background(), "unit."+digA); found { - t.Fatal("the package that failed was kept") - } - // Asked again with nothing changed: only the failed package runs; the good one is taken. - b.steps.calls = nil - b.judge(t, caseOf(t, pullOf(repoA, 7, head1))) - tests := b.steps.tool("test") - if len(tests) == 0 || strings.Join(packagesOf(tests[0]), ",") != "fixture/failing/bad" { - t.Fatalf("the re-ask ran %+v, want only fixture/failing/bad", tests) - } - // The trunk moved and one digest changed: that package runs, the unchanged one is taken. - b.digest[buildstep.LevelUnit] = Digested{Level: "unit", Packages: map[string]string{"fixture/failing/bad": digA, "fixture/failing/good": digD}} - b.steps.calls = nil - b.judge(t, caseOf(t, pullOf(repoA, 7, head1))) - tests = b.steps.tool("test") - if got := strings.Join(packagesOf(tests[0]), ","); got != "fixture/failing/bad,fixture/failing/good" && got != "fixture/failing/good,fixture/failing/bad" { - t.Errorf("after a digest changed the run was %q, want the failed package and the changed one", got) - } -} - -func TestANodePackageIsNeverKeptAndRunsEveryCheck(t *testing.T) { // 1288/AC4, 1292/AC1 - b := newBench(t) - b.ex.Modules = langs{repoA: {nodeBuildModule}} - b.fetch = captured[Fetched](t, "node-fetch-clean") - b.test = func(c stepCall) (any, error) { - return Tested{Level: c.args["level"].(string), Module: "modules/m", Passed: true, Elapsed: 0.4, Bound: 5}, nil - } - cs := caseOf(t, pullOf(repoA, 7, head1)) - for i := 0; i < 2; i++ { - v := b.judge(t, cs).Verdict - if v.State != meshdeliverycheckerclient.VerdictPass || v.Levels[buildstep.LevelUnit].Kept != 0 || v.Levels[buildstep.LevelUnit].Run != 1 { - t.Fatalf("round %d: verdict = %+v", i, v) - } - } - if n := len(b.steps.tool("test")); n != 4 { - t.Errorf("%d node test calls in two checks, want 4 (both levels each time)", n) - } - if n := len(b.steps.tool("digest")); n != 0 { - t.Errorf("the node build module was asked for a digest %d times", n) - } - if keys, _ := b.kept.Keys(context.Background()); len(keys) != 0 { - t.Errorf("kept %v for a node package", keys) - } -} - -// The operator, 2026-11-02 ("A failed check shows only its first fault"): a check runs every member, every level and the -// composition to its end and its verdict names every failure in the order judged, Failed keeping the first whole; the -// change's own tests still run first (issue 1289), and the rest of the level after them. A member that only failed its -// tests still gets its preview, so the composition is read and its failure named after the tests'. A member whose head -// does not merge has no preview of a merge, so the assigner's composition would only wait: the check does not wait for it -// and says why it was not run (review of 650a1d0). A member whose step failed after its fetch merged is previewed from the -// fetch the failed step answered, and the composition is read (design 47 G A-286). -func TestEveryFailureOfEveryMemberLevelAndTheCompositionIsNamed(t *testing.T) { - for _, kind := range []string{"tests", "conflicts", "errors"} { - conflicts, errs := kind == "conflicts", kind == "errors" - b := newBench(t) - comps := &fakeCompositions{v: refusedOn("x", "g14", "route-proxy is defined twice"), waits: conflicts} - b.ex.Compositions = comps - b.fetch.Changed = []string{"modules/m/internal/b/b_test.go"} - b.digest[buildstep.LevelUnit] = Digested{Level: "unit", Packages: map[string]string{"m/internal/a": digA, "m/internal/b": digB}} - conflict := captured[Fetched](t, "go-fetch-conflict") - b.steps.handlers["build_go_fetch"] = func(c stepCall) (any, error) { - if conflicts && c.args["repository"] == repoSDK { - return conflict, nil - } - return b.fetch, nil - } - failing := captured[Tested](t, "go-test-failing") - b.test = func(c stepCall) (any, error) { - if errs && c.args["level"] == "unit" { - return nil, errors.New("the seat definitions in . do not generate") - } - if got := packagesOf(c); c.args["level"] == "integration" || (len(got) == 1 && got[0] == "m/internal/b") { - r := failing - r.Level = c.args["level"].(string) - return r, nil - } - return captured[Tested](t, "go-test-slow"), nil - } - cs := caseOf(t, pullOf(repoA, 7, head1), pullOf(repoSDK, 12, head2)) - done := make(chan meshdeliverychecker.VerdictsByGroupHeadsValue, 1) - go func() { done <- b.judge(t, cs).Verdict }() - var v meshdeliverychecker.VerdictsByGroupHeadsValue - select { - case v = <-done: - case <-time.After(5 * time.Second): - t.Fatalf("conflicts %v: the check waits on a composition that only waits", conflicts) - } - if errs { - keys, _ := b.prev.Keys(context.Background()) - if len(keys) != 2 || len(comps.asked) == 0 || v.Composition == nil || v.Composition.State == meshdeliverycheckerclient.CompositionNotRun { - t.Errorf("a step failed after its fetch merged: previews %v, asked %v, composition %+v, want both previews and the composition read", - keys, comps.asked, v.Composition) - } - continue - } - var got []string - for _, f := range v.Failures { - got = append(got, firstFailed(meshdeliverychecker.VerdictsByGroupHeadsValue{Failed: &FailedFirst{Test: f.Test, Machine: f.Machine, Words: f.Words}})) - } - tests := []string{"unit: fixture/failing/bad.TestThreeIsFour", "integration: fixture/failing/bad.TestThreeIsFour"} - want := append(append(slices.Clone(tests), tests...), "g14: not composed on g14: route-proxy is defined twice") // both members fail their tests - if conflicts { - want = append([]string{"shanks: novox/mesh-sdk#12 does not merge into the trunk: files in conflict: a.go"}, tests...) - } - if v.State != meshdeliverycheckerclient.VerdictFail || len(got) != len(want) { - t.Fatalf("conflicts %v: verdict %+v: failures\n%s\nwant\n%s", conflicts, v, strings.Join(got, "\n"), strings.Join(want, "\n")) - } - for i := range want { - if !strings.HasPrefix(got[i], want[i]) { - t.Errorf("conflicts %v: failure %d is %q, want %q", conflicts, i, got[i], want[i]) - } - } - keys, _ := b.prev.Keys(context.Background()) - switch { - case !conflicts && (len(keys) != 2 || v.Composition == nil || v.Composition.State != meshdeliverycheckerclient.CompositionFail): - t.Errorf("tests alone failed: previews %v, composition %+v, want both previews and the composition read", keys, v.Composition) - case conflicts && (len(comps.asked) != 0 || v.Composition == nil || v.Composition.State != meshdeliverycheckerclient.CompositionNotRun || - !strings.Contains(v.Composition.Words, "novox/mesh-sdk#12 (its head does not merge)")): - t.Errorf("a member did not merge: asked %v, composition %+v, want not run naming novox/mesh-sdk#12", comps.asked, v.Composition) - } - var unit []string - for _, c := range b.steps.tool("test") { - if c.args["level"] == "unit" && c.args["workspace"] != nil { - unit = append(unit, strings.Join(packagesOf(c), ",")) - } - } - if conflicts && (strings.Join(unit, " | ") != "m/internal/b | m/internal/a" || len(b.steps.tool("digest")) != 2) { - t.Errorf("the unit level ran %v and %d digests, want the changed test's package, then the rest, at both levels", unit, len(b.steps.tool("digest"))) - } - v.Group, v.Heads = "feat/x", "0123456789ab" - if _, err := meshdeliverycheckerclient.EncodeVerdict(v); err != nil { - t.Errorf("conflicts %v: the verdict cannot be written: %v", conflicts, err) - } - if line := Line(v, cs, cs.Pulls[0], nil, nil, nil); !strings.HasPrefix(line, fmt.Sprintf("failed (%d): %s", len(want), want[0][:20])) || - !strings.Contains(line, fmt.Sprintf("; and %d more | ", len(want)-1)) || utf8.RuneCountInString(line) > MaxLine { - t.Errorf("conflicts %v: line %q", conflicts, line) - } - } -} - -func TestTheChangesOwnPassingTestRunsFirstAndTheRestFollow(t *testing.T) { // 1289/AC3 - b := newBench(t) - b.fetch.Changed = []string{"modules/m/internal/b/b_test.go", "modules/m/internal/a/a.go"} - b.digest[buildstep.LevelUnit] = Digested{Level: "unit", Packages: map[string]string{"m/internal/a": digA, "m/internal/b": digB}} - out := b.judge(t, caseOf(t, pullOf(repoA, 7, head1))) - if out.Verdict.State != meshdeliverycheckerclient.VerdictPass { - t.Fatalf("verdict = %+v", out.Verdict) - } - var unit []string - for _, c := range b.steps.tool("test") { - if c.args["level"] == "unit" { - unit = append(unit, strings.Join(packagesOf(c), ",")) - } - } - if strings.Join(unit, " | ") != "m/internal/b | m/internal/a" { - t.Errorf("the unit level ran %v, want the changed test's package first, then the rest", unit) - } -} - -func TestAHeadThatDoesNotMergeEndsFailedNamingTheFilesAndRunsNoTest(t *testing.T) { // 1289/AC4 - b := newBench(t) - b.fetch = captured[Fetched](t, "go-fetch-conflict") - out := b.judge(t, caseOf(t, pullOf(repoA, 7, head1))) - f := out.Verdict.Failed - if out.Verdict.State != meshdeliverycheckerclient.VerdictFail || f.Machine != "shanks" || !strings.Contains(f.Words, "files in conflict: a.go, sub/b.go") { - t.Fatalf("verdict = %+v", out.Verdict) - } - if n := len(b.steps.tool("digest")) + len(b.steps.tool("test")); n != 0 { - t.Errorf("%d digest and test steps ran after a conflict", n) - } - // 1921/D1c: the node that ran the step is a fact, so the verdict judged from the facts names its machine. - if m := out.Verdict.Machines; len(m) != 1 || m[0] != "shanks" { - t.Errorf("machines = %v, want the node that ran the step", m) - } -} - -func TestALevelWhoseDigestIsNotNamedRunsWholeAndKeepsNothing(t *testing.T) { // 1287/AC4 - b := newBench(t) - b.steps.handlers["build_go_digest"] = func(stepCall) (any, error) { return nil, fmt.Errorf("go list failed") } - out := b.judge(t, caseOf(t, pullOf(repoA, 7, head1))) - if out.Verdict.State != meshdeliverycheckerclient.VerdictPass { - t.Fatalf("verdict = %+v", out.Verdict) - } - tests := b.steps.tool("test") - if len(tests) != 2 || tests[0].args["packages"] != nil { - t.Errorf("test calls = %+v, want each level once, whole", tests) - } - if keys, _ := b.kept.Keys(context.Background()); len(keys) != 0 { - t.Errorf("kept %v with no digest", keys) - } -} - -func TestALevelOverItsBoundIsNamedWithItsSlowestTestsAndKeepsItsVerdict(t *testing.T) { // 1300/AC3 - b := newBench(t) - b.test = func(c stepCall) (any, error) { - return testedWith(t, "go-test-slow", func(r *Tested) { - r.Level = c.args["level"].(string) - r.OverBound = true - r.OverWhich = "run" - r.Elapsed = 7 - }), nil - } - out := b.judge(t, caseOf(t, pullOf(repoA, 7, head1))) - v := out.Verdict - if v.State != meshdeliverycheckerclient.VerdictPass || strings.Join(v.OverBound, ",") != "unit,integration" { - t.Fatalf("verdict = %+v", v) - } - if len(out.Slowest) == 0 || !strings.Contains(out.Slowest[0], "TestTakesAWhile") { - t.Errorf("slowest = %v", out.Slowest) - } -} - -func TestSkippedTestsAreCountedPerLevel(t *testing.T) { // 1300/AC6, 1251 - b := newBench(t) - b.test = func(c stepCall) (any, error) { - return testedWith(t, "go-test-slow", func(r *Tested) { r.Level = c.args["level"].(string); r.Skipped = 3 }), nil - } - v := b.judge(t, caseOf(t, pullOf(repoA, 7, head1))).Verdict - if v.Levels[buildstep.LevelUnit].Skipped != 3 || v.Levels[buildstep.LevelIntegration].Skipped != 3 { - t.Errorf("levels = %+v", v.Levels) - } -} - -func TestAGroupIsOneVerdictAndEachMembersTestsReadTheOthersAtTheirHeads(t *testing.T) { // 1624/AC1 - b := newBench(t) - cs := caseOf(t, pullOf(repoA, 7, head1), pullOf(repoSDK, 12, head2)) - v := b.judge(t, cs).Verdict - if v.State != meshdeliverycheckerclient.VerdictPass { - t.Fatalf("verdict = %+v", v) - } - fetch := b.steps.tool("fetch") - if len(fetch) != 2 { - t.Fatalf("%d fetches, want one for each member", len(fetch)) - } - var forA []BesideRef - for _, f := range fetch { - if f.args["repository"] == repoA { - forA, _ = refsOf(f.args["beside"]), true - } - } - found := false - for _, r := range forA { - if r.Repository == repoSDK && r.Commit == head2 { - found = true - } - } - if !found { - t.Errorf("mesh-delivery's tests were not given the SDK member at its head: %+v", forA) - } -} - -func TestAnExaminerIsAJudgeOfTheChecker(t *testing.T) { - var _ Judge = (*Examiner)(nil) -} - -const ( - manA = "0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a" -) - -func TestACleanMergeWritesItsPreviewWithTheTreesManifestsAndLocks(t *testing.T) { // 1445/AC1 - b := newBench(t) - b.fetch.Trees = map[string]buildstep.ModuleTree{ - "modules/avahi": {Tree: "7777777777777777777777777777777777777777", Manifest: manA, Locks: map[string]string{"go.sum": "ff00"}}, - "modules/bare": {Tree: "8888888888888888888888888888888888888888"}, // no manifest digest: left out - } - b.judge(t, caseOf(t, pullOf(repoA, 7, head1))) - key, _ := meshdeliverycheckerclient.PreviewKey(repoA, head1, trunkA) - raw, _, found, _ := b.prev.Get(context.Background(), key) - if !found { - t.Fatalf("no preview %s; the bucket holds %v", key, b.prev.vals) - } - pv, err := meshdeliverycheckerclient.DecodePreview(raw) - if err != nil { - t.Fatal(err) - } - m := pv.Modules["modules/avahi"] - if pv.Merge != b.fetch.Merge || pv.Trunk != trunkA || pv.Head != head1 || len(pv.Modules) != 1 || m.Tree != "7777777777777777777777777777777777777777" || m.Manifest != manA || m.Locks["go.sum"] != "ff00" { - t.Errorf("preview = %+v", pv) - } -} - -func TestAHeadThatDoesNotMergeWritesAPreviewOfItsConflictsAlone(t *testing.T) { // 1445/AC5 - b := newBench(t) - b.fetch = captured[Fetched](t, "go-fetch-conflict") - b.judge(t, caseOf(t, pullOf(repoA, 7, head1))) - key, _ := meshdeliverycheckerclient.PreviewKey(repoA, head1, trunkA) - raw, _, found, _ := b.prev.Get(context.Background(), key) - if !found { - t.Fatalf("no preview for a head that does not merge; the bucket holds %v", b.prev.vals) - } - pv, err := meshdeliverycheckerclient.DecodePreview(raw) - if err != nil || strings.Join(pv.Conflicts, ",") != "a.go,sub/b.go" || pv.Merge != "" || len(pv.Modules) != 0 { - t.Errorf("preview = %+v, %v, want the files in conflict and no merge", pv, err) - } -} - -func TestAPreviewIsWrittenOnceAndAnExistingKeyStands(t *testing.T) { - b := newBench(t) - b.judge(t, caseOf(t, pullOf(repoA, 7, head1))) - b.fetch.Merge = "5656565656565656565656565656565656565656" - b.judge(t, caseOf(t, pullOf(repoA, 7, head1))) - key, _ := meshdeliverycheckerclient.PreviewKey(repoA, head1, trunkA) - if b.prev.creates[key] != 1 { - t.Errorf("the preview was created %d times, want once", b.prev.creates[key]) - } - raw, _, _, _ := b.prev.Get(context.Background(), key) - if pv, _ := meshdeliverycheckerclient.DecodePreview(raw); pv.Merge == b.fetch.Merge { - t.Error("the second merge commit replaced the first") - } -} - -func TestTheIndexerIsToldOfAPreviewOnceWhenItIsCreated(t *testing.T) { // 1445/AC4 (the checker's half) - b := newBench(t) - var told []string - b.ex.Announce = func(_ context.Context, event, key string) { told = append(told, event+" "+key) } - b.judge(t, caseOf(t, pullOf(repoA, 7, head1))) - b.judge(t, caseOf(t, pullOf(repoA, 7, head1))) - key, _ := meshdeliverycheckerclient.PreviewKey(repoA, head1, trunkA) - if len(told) != 1 || told[0] != EventPreviewWritten+" "+key { - t.Errorf("told %v, want once of %s", told, key) - } -} - -type fakeBuilds map[string]builds.BuilderBuild - -func (f fakeBuilds) Build(_ context.Context, module, fp2 string) (builds.BuilderBuild, bool, error) { - b, ok := f[module+" "+fp2] - return b, ok, nil -} - -func TestTheOutcomeSaysIfEachCandidatesModuleIsBuiltFailedOrWaiting(t *testing.T) { // N7/AC1 (the checker reads the builder's keys) - b := newBench(t) - fpA := "src2:" + strings.Repeat("a", 64) - fpB := "src2:" + strings.Repeat("b", 64) - fpC := "src2:" + strings.Repeat("c", 64) - b.ex.Builds = fakeBuilds{ - "avahi " + fpA: {State: builds.BuildDone}, - "mesh-tools " + fpB: {State: builds.BuildFailed, Error: "boom"}, - // netcheck has no key yet - } - p := pullOf(repoA, 7, head1) - p.Modules = []string{"avahi", "mesh-tools", "netcheck", "nofp"} - p.Fps = map[string]meshcatalog.CandidatesByGroupValuePullsItemFpsValue{"avahi": {Fp2: fpA}, "mesh-tools": {Fp2: fpB}, "netcheck": {Fp2: fpC}, "nofp": {None2: "toolchain not yet reported"}} - out := b.judge(t, caseOf(t, p)) - var got []string - for _, n := range out.Builds { - got = append(got, n.Module+" "+n.State) - } - if strings.Join(got, ", ") != "avahi built, mesh-tools failed, netcheck waiting" { - t.Errorf("builds = %v, want one note for each module that has a fingerprint, sorted", got) - } -} - -// trunksOf are trunk heads of every repository, as the catalog half's trunk revision names them. -func trunksOf(t *testing.T, heads map[string]string) *Trunks { - t.Helper() - tr := &Trunks{} - tr.Set(heads) - return tr -} - -func TestNothingIsKeptForAWorkspaceGivenSiblingsWhenTheDigestDoesNotSayItCoversThem(t *testing.T) { // review D1, ADR 0444, issue 1287 - b := newBench(t) - // A build module whose digest does not echo the siblings (before DigestVersion 3). - b.steps.handlers["build_go_digest"] = func(c stepCall) (any, error) { return b.digest[c.args["level"].(string)], nil } - b.ex.Trunks = trunksOf(t, map[string]string{repoSDK: trunkS, "novox/mesh-catalog": trunkA}) - b.judge(t, caseOf(t, pullOf(repoA, 7, head1))) - if got := len(b.steps.tool("fetch")); got != 1 || b.steps.tool("fetch")[0].args["beside"] == nil { - t.Fatalf("the fetch was not given siblings: %+v", b.steps.tool("fetch")) - } - if keys, _ := b.kept.Keys(context.Background()); len(keys) != 0 { - t.Errorf("kept %v for a package whose digest does not say it covers the siblings", keys) - } - // And a kept verdict of the same digest from elsewhere is not taken for it: everything runs. - if _, err := (Kept{Store: b.kept}).Keep(context.Background(), "unit", digA, keptValue("fixture/slow", 2)); err != nil { - t.Fatal(err) - } - b.steps.calls = nil - b.judge(t, caseOf(t, pullOf(repoA, 7, head1))) - if n := len(b.steps.tool("test")); n != 2 { - t.Errorf("%d test steps, want both levels run whole", n) - } -} - -// besideDigest stands for the Go build module's digest over a workspace with siblings (DigestVersion 3, lead decision L5): -// each package's digest folds the siblings' commits in, and the answer echoes the lines it folded. -// echoBeside is d with the siblings the fetches placed, as the Go build module's digest echoes them (its DigestResult's -// Beside): every check now places the change's own repository at its trunk (issue 1887 A12). -func echoBeside(b *bench, d Digested) Digested { - var lines []string - if fetches := b.steps.tool("fetch"); len(fetches) > 0 { // the workspace digested is the last fetch's (issue 890: a placed ask fetches again) - for _, r := range refsOf(fetches[len(fetches)-1].args["beside"]) { - lines = append(lines, r.Repository+" "+r.Commit) - } - } - sort.Strings(lines) - d.Beside = lines - return d -} - -func besideDigest(b *bench) func(c stepCall) (any, error) { - return func(c stepCall) (any, error) { - level := c.args["level"].(string) - var lines []string - for _, f := range b.steps.tool("fetch") { - refs, _ := refsOf(f.args["beside"]), true - for _, r := range refs { - lines = append(lines, r.Repository+" "+r.Commit) - } - } - sort.Strings(lines) - sum := sha256.Sum256([]byte(level + "\n" + strings.Join(lines, "\n"))) - return Digested{Level: level, Packages: map[string]string{"fixture/slow": hex.EncodeToString(sum[:])}, Beside: lines}, nil - } -} - -func TestACoreRepositorysPassingPackageIsKeptUnderADigestCoveringItsSiblings(t *testing.T) { // 1287 AC1-AC3, AC7 with L5 - b := newBench(t) - b.steps.handlers["build_go_digest"] = besideDigest(b) - b.ex.Trunks = trunksOf(t, map[string]string{repoSDK: trunkS, "novox/mesh-catalog": trunkA}) - b.judge(t, caseOf(t, pullOf(repoA, 7, head1))) - keys, _ := b.kept.Keys(context.Background()) - if len(keys) != 2 { - t.Fatalf("kept %v, want the passing package at both levels", keys) - } - // The same siblings again: everything is taken, nothing runs. - b.steps.calls = nil - v := b.judge(t, caseOf(t, pullOf(repoA, 7, head1))).Verdict - if n := len(b.steps.tool("test")); n != 0 || v.Levels[buildstep.LevelUnit].Run != 0 || v.Levels[buildstep.LevelUnit].Kept == 0 { - t.Fatalf("%d test steps, unit %+v, want none run and the kept verdict taken", n, v.Levels[buildstep.LevelUnit]) - } - // A sibling's commit moves: a new digest, so the package runs again and is kept under it. - b.ex.Trunks = trunksOf(t, map[string]string{repoSDK: trunkS2, "novox/mesh-catalog": trunkA}) - b.steps.calls = nil - b.judge(t, caseOf(t, pullOf(repoA, 7, head1))) - if n := len(b.steps.tool("test")); n != 2 { - t.Errorf("%d test steps after a sibling moved, want both levels run", n) - } - if keys, _ := b.kept.Keys(context.Background()); len(keys) != 4 { - t.Errorf("kept %v, want a second key per level under the new digest", keys) - } -} - -func TestADigestThatEchoesOtherSiblingsKeepsNothing(t *testing.T) { // 1287 with L5: an echo that differs is not trusted - b := newBench(t) - inner := besideDigest(b) - b.steps.handlers["build_go_digest"] = func(c stepCall) (any, error) { - v, err := inner(c) - d := v.(Digested) - d.Beside = d.Beside[:len(d.Beside)-1] - return d, err - } - b.ex.Trunks = trunksOf(t, map[string]string{repoSDK: trunkS, "novox/mesh-catalog": trunkA}) - b.judge(t, caseOf(t, pullOf(repoA, 7, head1))) - if keys, _ := b.kept.Keys(context.Background()); len(keys) != 0 { - t.Errorf("kept %v under a digest that does not cover every sibling", keys) - } -} - -type pkgPaths map[string][]TypeScriptPackage - -func (p pkgPaths) TypeScriptPackages(repository string) []TypeScriptPackage { return p[repository] } - -// contractsGit is a contracts package of mesh-delivery: one directory with its own package.json. -const contractsGit = "modules/mesh-delivery-contracts/ts/seats/git" - -// groupPackageBench is a group of a TypeScript member (mesh-delivery, with a contracts package) and the mesh-sdk member, -// whose merges change changed of each repository. -func groupPackageBench(t *testing.T, changed map[string][]string) *bench { - b := newBench(t) - b.ex.Modules = langs{repoA: {goBuildModule, nodeBuildModule}, repoSDK: {goBuildModule, nodeBuildModule}} - b.ex.Packages = pkgPaths{ - repoSDK: {{Dir: "", Paths: []string{"package-lock.json", "package.json", "src", "tsconfig.json"}}}, - repoA: {{Dir: contractsGit, Paths: []string{contractsGit}}}, - } - fetch := func(c stepCall) (any, error) { - f := b.fetch - f.Changed = changed[c.args["repository"].(string)] - return f, nil - } - b.steps.handlers["build_go_fetch"], b.steps.handlers["build_node_fetch"] = fetch, fetch - return b -} - -func nodeFetchOf(b *bench, repo string) stepCall { - for _, c := range b.steps.tool("fetch") { - if c.module == nodeBuildModule && c.args["repository"] == repo { - return c - } - } - return stepCall{} -} - -// design 47 G A-284, A-285 (ADR 0500 §5): every TypeScript fetch of a group's check is given every package any member's -// merge changes, each at its member's head with its directory there; the registry's only for a package none changes. -func TestATypeScriptMemberTakesEveryPackageTheGroupChanges(t *testing.T) { - sdk := map[string]any{"repository": repoSDK, "commit": head2, "ref": "refs/pull/12/head"} - git := map[string]any{"repository": repoA, "commit": head1, "ref": "refs/pull/7/head", "path": contractsGit} - for _, row := range []struct { - name string - changed map[string][]string - want []any - }{ - {"the SDK's sources", map[string][]string{repoSDK: {"go/delivery/x.go", "src/state.ts"}}, []any{sdk}}, - {"another member's contracts package", map[string][]string{repoA: {contractsGit + "/index.ts"}}, []any{git}}, - {"both", map[string][]string{repoSDK: {"package.json"}, repoA: {contractsGit + "/package.json", "go.mod"}}, []any{sdk, git}}, - {"Go alone", map[string][]string{repoSDK: {"go/delivery/x.go"}, repoA: {"modules/mesh-delivery-contracts/go/seats/git/contract.go"}}, nil}, - {"the manifest alone", map[string][]string{repoSDK: {"module.json"}}, nil}, - {"beside the named paths", map[string][]string{repoSDK: {"srcx/a.ts"}, repoA: {contractsGit + "x/a.ts"}}, nil}, - } { - b := groupPackageBench(t, row.changed) - b.judge(t, caseOf(t, pullOf(repoA, 7, head1), pullOf(repoSDK, 12, head2))) - for _, repo := range []string{repoA, repoSDK} { - got, _ := nodeFetchOf(b, repo).args["group-packages"].([]any) - if !reflect.DeepEqual(got, row.want) { - t.Errorf("%s: the Node fetch of %s was given %v, want %v", row.name, repo, got, row.want) - } - if pkg, ok := nodeFetchOf(b, repo).args["package"]; ok { - t.Errorf("%s: the Node fetch of %s was given the retired package %v", row.name, repo, pkg) - } - } - } - // A lone pull request: no group package. - b := groupPackageBench(t, map[string][]string{repoA: {contractsGit + "/index.ts"}}) - b.judge(t, caseOf(t, pullOf(repoA, 7, head1))) - if got, ok := nodeFetchOf(b, repoA).args["group-packages"]; ok { - t.Errorf("a lone pull request's Node fetch was given %v", got) - } -} - -// design 47 G A-284: the mesh-sdk member is judged first, and its TypeScript fetch still learns the package another -// member's merge changes: every member's other fetches come before any TypeScript one. -func TestEveryMembersMergeIsKnownBeforeATypeScriptFetch(t *testing.T) { - b := groupPackageBench(t, map[string][]string{repoA: {contractsGit + "/index.ts"}}) - b.judge(t, caseOf(t, pullOf(repoA, 7, head1), pullOf(repoSDK, 12, head2))) - var order []string - for _, c := range b.steps.tool("fetch") { - order = append(order, c.module+" "+c.args["repository"].(string)) - } - want := []string{goBuildModule + " " + repoSDK, goBuildModule + " " + repoA, nodeBuildModule + " " + repoSDK, nodeBuildModule + " " + repoA} - if !reflect.DeepEqual(order, want) { - t.Errorf("fetches in the order %v, want %v", order, want) - } -} - -func TestNoStepOfACheckCarriesPublish(t *testing.T) { // ADR 0500 §4, 1309 (the checker's half): only the builder's trunk build publishes - b := groupPackageBench(t, map[string][]string{repoSDK: {"src/state.ts"}}) - b.judge(t, caseOf(t, pullOf(repoA, 7, head1), pullOf(repoSDK, 12, head2))) - if len(b.steps.calls) == 0 { - t.Fatal("no step ran") - } - for _, c := range b.steps.calls { - if _, ok := c.args["publish"]; ok { - t.Errorf("%s was given publish: %v", c.tool, c.args) - } - if strings.HasSuffix(c.tool, "_build") || strings.HasSuffix(c.tool, "_pack") { - t.Errorf("the checker asked %s: a check builds no artifact of its own", c.tool) - } - } -} - -// 1890/AC1, 1887/A5a: an ask whose step never ends (the build node stopped with it running, and nothing redelivered it in -// time) ends the check loudly at the asker's bound; the checker holds no place to free. -func TestAnAskWhoseStepNeverEndsEndsTheCheckLoudly(t *testing.T) { - b := newBench(t) - // A node took the ask and its step stays running: the bound runs from its start (review round 2 item 1). - b.asks.Answer = func(a buildstep.StepAsk) buildstep.Step { - return buildstep.Step{ID: a.ID, Tool: "check ask", Node: "shanks", State: buildstep.StepRunning, Started: time.Now()} - } - b.ex.Asks = buildrun.Asker{Seats: testSeats(), Publisher: b.asker(nil, nil), Waiter: b.asks, Bound: 20 * time.Millisecond} - out := b.judge(t, caseOf(t, pullOf(repoA, 7, head1))) - if f := out.Verdict.Failed; out.Verdict.State != meshdeliverycheckerclient.VerdictFail || !strings.Contains(f.Words, "on shanks did not end within") { - t.Fatalf("verdict = %+v", out.Verdict) - } - if n := len(b.asks.Asks()); n != 1 || b.asks.Asks()[0].Kind != buildstep.AskCheck || b.asks.Asks()[0].Check == nil { - t.Fatalf("asks = %+v, want one check ask", b.asks.Asks()) - } -} - -// 1887/A5a, ADR 0536 §4: a check is one ask per pull request and build module on the check stream, a re-judge after a -// trunk move one on the recheck stream, each carrying both levels with the kept verdicts taken by the build module. -func TestACheckIsOneAskAndAReJudgeGoesOnTheRecheckStream(t *testing.T) { - b := newBench(t) - b.judge(t, caseOf(t, pullOf(repoA, 7, head1))) - asks := b.asks.Asks() - if len(asks) != 1 || asks[0].Kind != buildstep.AskCheck || asks[0].Language != buildstep.AskGo || asks[0].Asker != "acme-checker" { - t.Fatalf("asks = %+v, want one Go check ask", asks) - } - if j := asks[0].Check; j == nil || !j.Kept || strings.Join(j.Levels, ",") != "unit,integration" || j.Fetch.Repository != repoA { - t.Fatalf("the job = %+v", asks[0].Check) - } - // B2g: the job carries the toolchain the checker agreed (ADR 0584), with its language, so a node on another declines it. - if tc := asks[0].Check.Toolchain; tc == nil || *tc != (buildstep.ToolchainUsed{Language: "go", Version: "go1.27", Recipe: "7"}) { - t.Errorf("the job's toolchain = %+v, want the agreed go toolchain", tc) - } - cs := caseOf(t, pullOf(repoA, 7, head1)) - cs.Kind = KindTrunk - b.judge(t, cs) - if asks := b.asks.Asks(); len(asks) != 2 || asks[1].Kind != buildstep.AskRecheck { - t.Fatalf("asks = %+v, want the re-judge on recheck", asks) - } -} - -// Review round 2 item 1: a check ask that waits in its stream longer than the step bound (no node has a free slot during a -// large rebuild) is not failed: the check goes on when a node takes it, and no second ask is put. -func TestACheckAskWaitingInItsStreamIsNotBounded(t *testing.T) { - b := newBench(t) - answer := b.asks.Answer - b.asks.Answer = nil - b.ex.Asks = buildrun.Asker{Seats: testSeats(), Publisher: b.asker(nil, nil), Waiter: b.asks, Bound: 20 * time.Millisecond} - done := make(chan Outcome, 1) - go func() { done <- b.judge(t, caseOf(t, pullOf(repoA, 7, head1))) }() - for deadline := time.Now().Add(10 * time.Second); len(b.asks.Asks()) == 0; time.Sleep(time.Millisecond) { - if time.Now().After(deadline) { - t.Fatal("no ask was put") - } - } - time.Sleep(100 * time.Millisecond) // five bounds in the stream - select { - case out := <-done: - t.Fatalf("the check ended while its ask waited: %+v", out.Verdict) - default: - } - b.asks.End(answer(b.asks.Asks()[0])) // a node took it and ran it - if out := <-done; out.Verdict.State != meshdeliverycheckerclient.VerdictPass || len(b.asks.Asks()) != 1 { - t.Fatalf("verdict %+v after %d asks, want a pass from the one ask", out.Verdict, len(b.asks.Asks())) - } -} - -// 1917: the digest is taken inside the check ask, as the build module's own digest step answers it (no step key is asked -// of it), so a second check of the same heads keeps every package the first one passed: "N kept", nothing run again. -func TestASecondCheckOfTheSameHeadsKeepsWhatTheFirstPassed(t *testing.T) { - b := newBench(t) - first := b.judge(t, caseOf(t, pullOf(repoA, 7, head1))).Verdict - u := first.Levels[buildstep.LevelUnit] - if first.State != meshdeliverycheckerclient.VerdictPass || u.Run == 0 || u.Kept != 0 { - t.Fatalf("the first check = %+v", first) - } - b.steps.calls = nil - second := b.judge(t, caseOf(t, pullOf(repoA, 7, head1))).Verdict - if s := second.Levels[buildstep.LevelUnit]; second.State != meshdeliverycheckerclient.VerdictPass || s.Kept != u.Run || s.Run != 0 { - t.Fatalf("the second check's unit level = %+v, want %d kept and none run", s, u.Run) - } - if n := len(b.steps.tool("test")); n != 0 { - t.Errorf("%d test steps ran on the second check", n) - } -} - -// keptList is the indexer's kept predefined list as a test gives it. -type keptList string - -func (k keptList) PredefinedList(context.Context) (json.RawMessage, error) { - return json.RawMessage(k), nil -} - -// fixedManifests are the indexer's kept manifests by digest as a test gives them. -type fixedManifests map[string]catalogue.Manifest - -func (f fixedManifests) Manifest(_ context.Context, digest string) (catalogue.Manifest, error) { - m, ok := f[digest] - if !ok { - return catalogue.Manifest{}, errors.New("no manifest " + digest) - } - return m, nil -} - -// fixedDigests are the indexer's manifest digests as a test gives them. -type fixedDigests map[string]string - -func (f fixedDigests) ManifestDigests() map[string]string { return f } - -func (f fixedDigests) ManifestFingerprints() map[string]string { - out := map[string]string{} - for m := range f { - out[m] = "src2:" + m - } - return out -} - -// ADR 0578 §2: a change's manifests are judged by the indexer's judge, built at mesh-delivery's trunk and run as the -// composer is (a compose ask of its command); a refusal fails the check naming the manifest and each problem; a group -// whose mesh-delivery member changes the judge is judged by that member's head. -func TestTheIndexersJudgeJudgesTheChangesManifests(t *testing.T) { - web, trunk := strings.Repeat("e", 64), strings.Repeat("d", 40) - for _, row := range []struct { - name string - refused string - fails string - // untouched is the judge's refusal of mail, which the change leaves as it is, and trunkMail its refusal on the trunk: - // a problem the trunk had is a warning, one the change causes fails (ADR 0579 §2) - untouched, trunkMail string - // cycle reads the manifests, so the change's module graph is worked out (ADR 0603 §2): with "provisions" the change's - // web awaits mail's site while mail awaits web's database, and trunkCycle has the trunk's web await it too; with "bases" - // each is built on the other; with "verbs" each invokes the other's tool, and with "a verb and a provision" web invokes - // mail's tool while mail awaits web's database: both left out, so neither is refused (ADR 0614 §3, §6). - cycle string - trunkCycle bool - // series is the series of web's package the change raises it to, and the words its status line names (DLV-C4). - series, seriesWords string - // renames is what the change does to web's renamed-from ("bring", "drop") and what the seat mesh-config's verb - // renames answers ("served", "open" on g14, "not served", "unasked" with no seat to ask, "error"); DLV-C5. - renames, seat string - // unparsed is the indexer's words of why the pull request's head's seat definition of web-api does not parse. - unparsed string - // known are the judge's known packages the request hands it (DLV-I14, design 32): the packages state's names and, - // of web's package new in the group, the name its go.mod says at the member's head. - known []string - // emptyState is a packages state answered and empty, no member declaring a package: the judge is handed an empty - // list, never nil, so every name a manifest's packages names is refused (review round 1, DLV-I14). - emptyState bool - // indexer makes web the holder of the seat mesh-catalog, and the trunk's manifest validator answers for it: "held" with no verdict, - // "aside" with a field it does not know; ownJudge has the group change the judge, so the manifest is also judged by the - // trunk's, in a second ask (ADR 0633 clause 6, 1585/T22, T23) - indexer string - ownJudge bool - // seats is the seat list the checker holds: "read" gives the judge its two definitions as the request's Seats, "unread" - // is a reader the seat has not answered, and the manifests are then judged by nothing (ADR 0636 §1). - seats string - // try judges the same change as a whole group try, whose manifests come from the indexer's candidate of the try's - // group (issue 1921): the same judge, the same verdicts. - try bool - // heads has the change touch a contracts module too, whose head defines the Delivery seat mesh-catalog with a verb of - // a part it includes: "domain" is the domain's contracts module, so the judges get that definition over the list's - // (ADR 0636 §4, ADR 0633 §6); "outside" is mesh-contracts, whose definition of another domain's seat is not taken - // (ADR 0636 §5); "misnamed" is the domain's module whose seats/mesh-catalog/seat.json names another seat. - heads string - // headSeats lays heads that add a seat: the checking program's seat list is carried by every judge ask's request (ADR - // 0636 §4, issue 1921 D4). - headSeats bool - }{ - {name: "the seat list read is the request's Seats", seats: "read"}, - {name: "the members' heads' definitions over the list's, for the trunk's manifest validator too", seats: "read", indexer: "ok", heads: "domain"}, - {name: "a head's definition of a seat outside its module's domain is not taken", seats: "read", indexer: "ok", heads: "outside"}, - {name: "a head's definition naming another seat than its directory's fails the judging", seats: "read", heads: "misnamed", - fails: `names the seat "other", not "mesh-catalog"`}, - {name: "the seat list not read judges nothing", seats: "unread", - fails: "the change's manifests cannot be judged: the seat list is not read (the seat list is held from the bootstrap"}, - {name: "a seat definition that does not parse", unparsed: "seats/web-api/seat.json: unexpected end of JSON input", - fails: "novox/mesh-delivery#7: the seat definition of web-api (module web-contracts, go) does not parse: seats/web-api/seat.json: unexpected end of JSON input"}, - {name: "a rename brought, the verb not served", renames: "bring", seat: "not served", - fails: "web (novox/mesh-delivery#7) renames new-key from old-key: refused, the holder of the seat mesh-config does not serve its verb renames"}, - {name: "a rename brought, the verb served", renames: "bring", seat: "served"}, - {name: "a renamed-from dropped while its window is open", renames: "drop", seat: "open", - fails: "web (novox/mesh-delivery#7) drops renamed-from old-key of new-key while its rename window is open on g14"}, - {name: "a renamed-from dropped once its window closed", renames: "drop", seat: "served"}, - {name: "a rename the check cannot ask of", renames: "bring", seat: "error", fails: "the check cannot ask seat:mesh-config.renames: the bus said no"}, - {name: "a rename with no seat to ask", renames: "drop", seat: "unasked", fails: "this checker cannot ask seat:mesh-config.renames"}, - {name: "accepted"}, - {name: "a package series raised", series: "0.2", seriesWords: "web/pkg series 0.1 → 0.2"}, - {name: "a package series kept", series: "0.1"}, - {name: "a package new in the group", series: "0.1", known: []string{"git.novox.be/novox/mesh-sdk/go", "git.novox.be/novox/web/go"}}, - {name: "an answered packages state holding no name", emptyState: true, known: []string{}}, - {name: "the heads' seat list is carried by the head's judge and the trunk's", headSeats: true, indexer: "ok", ownJudge: true}, - {name: "accepted in a group try", try: true}, - {name: "refused in a group try", try: true, refused: "web has no id", fails: "the indexer's judge at mesh-delivery's trunk " + strings.Repeat("d", 40) + ` refuses the manifest of web: web has no id`}, - {name: "a cycle the group try makes", try: true, cycle: "provisions", fails: "the change's module graph has the cycle mail -> web -> mail"}, - {name: "the indexer accepted by the trunk's manifest validator", indexer: "ok"}, - {name: "the indexer held by the trunk's manifest validator", indexer: "held", fails: "the indexer web, the holder of the seat mesh-catalog, would never run: the trunk's manifest validator at mesh-delivery's trunk " + strings.Repeat("d", 40) + " does not accept its manifest: the manifest validator holds it, with no verdict yet"}, - {name: "the indexer with a field the trunk's manifest validator does not know", indexer: "aside", fails: "the manifest validator does not know its fields new_field, so it waits"}, - {name: "the indexer refused by the trunk's manifest validator", indexer: "refused", refused: "web has no id", fails: "does not accept its manifest: web has no id"}, - {name: "the indexer under a changed judge is judged by the trunk's as well", indexer: "aside", ownJudge: true, fails: "the manifest validator does not know its fields new_field, so it waits"}, - {name: "a touched manifest the judge holds", indexer: "heldplain", fails: "holds the manifest of web: it gave no verdict"}, - {name: "an untouched manifest's problem the trunk had", untouched: "mail says no credential form", trunkMail: "mail says no credential form"}, - {name: "a problem the change causes in an untouched manifest", untouched: "mail reads a state web no longer keeps", - fails: "refuses the manifest of mail: mail reads a state web no longer keeps"}, - {name: "a cycle the change makes", cycle: "provisions", fails: "the change's module graph has the cycle mail -> web -> mail"}, - {name: "a cycle the trunk has", cycle: "provisions", trunkCycle: true}, - {name: "a cycle of bases", cycle: "bases", fails: "the change's module graph has the cycle mail -> web -> mail"}, - {name: "a cycle of verbs", cycle: "verbs"}, - {name: "a cycle of a verb and a provision", cycle: "a verb and a provision"}, - {name: "refused", refused: "web requires \"amqp\"\nweb has no id", fails: "the indexer's judge at mesh-delivery's trunk " + strings.Repeat("d", 40) + ` refuses the manifest of web: web requires "amqp"; web has no id`}, - } { - b := newBench(t) - if row.headSeats { - b.heads = fstest.MapFS{ - repoA + "/modules/x-contracts/module.json": {Data: []byte(`{"module": "x-contracts", "build": {"artifacts": [{"name": "go", "kind": "package", "language": "go", "generated-from": "."}]}}`)}, - repoA + "/modules/x-contracts/seats/node-x/seat.json": {Data: []byte(`{"format":1,"seat":"node-x","scope":"node","grain":"whole","domain":"Delivery","decision":"ADR 1"}`)}, - } - } - b.ex.Manifests = fixedDigests{"mail": strings.Repeat("a", 64), "web": strings.Repeat("b", 64)} - b.ex.Trunks = fixedTrunks{heads: map[string]string{DeliveryRepository: trunk}} - b.ex.Predefined = keptList(`{"font-size": {"type": "number", "description": "the size"}}`) - if row.cycle != "" { - offer := func(name string) []catalogue.Offer { - return []catalogue.Offer{{Name: name, Scope: catalogue.ScopeMesh, AnsweredBy: catalogue.AnsweredByHelper}} - } - on := func(module string) *catalogue.Build { - return &catalogue.Build{On: []catalogue.BuildsOn{{Arg: "BASE", Module: module, Artifact: "img"}}} - } - trunkWeb := catalogue.Manifest{Module: "web", Provides: offer("database")} - if row.trunkCycle { - trunkWeb.Requires = []string{"site"} - } - mail := catalogue.Manifest{Module: "mail", Provides: offer("site"), Requires: []string{"database"}} - changed := catalogue.Manifest{Module: "web", Provides: offer("database"), Requires: []string{"site"}} - switch row.cycle { - case "bases": - mail = catalogue.Manifest{Module: "mail", Build: on("web")} - changed = catalogue.Manifest{Module: "web", Build: on("mail")} - case "verbs": - mail = catalogue.Manifest{Module: "mail", Tools: []string{"mail_send"}, Invokes: []string{"web.web_page"}} - changed = catalogue.Manifest{Module: "web", Tools: []string{"web_page"}, Invokes: []string{"mail.mail_send"}} - case "a verb and a provision": - mail = catalogue.Manifest{Module: "mail", Tools: []string{"mail_send"}, Requires: []string{"database"}} - changed = catalogue.Manifest{Module: "web", Provides: offer("database"), Invokes: []string{"mail.mail_send"}} - } - b.ex.Read = fixedManifests{strings.Repeat("a", 64): mail, strings.Repeat("b", 64): trunkWeb, web: changed} - } - if row.series != "" { - pkg := func(series string) *catalogue.Build { - return &catalogue.Build{Artifacts: []catalogue.Artifact{{Name: "pkg", Kind: catalogue.ArtifactPackage, Language: "go", Series: series}}} - } - b.ex.Read = fixedManifests{strings.Repeat("a", 64): {Module: "mail"}, strings.Repeat("b", 64): {Module: "web", Build: pkg("")}, - web: {Module: "web", Build: pkg(row.series)}} - } - if row.known != nil { - b.ex.KnownPackages = knownNames{"git.novox.be/novox/mesh-sdk/go": "mesh-sdk/go"} - b.ex.Read = fixedManifests{strings.Repeat("a", 64): {Module: "mail"}, strings.Repeat("b", 64): {Module: "web"}, web: {Module: "web", - Build: &catalogue.Build{Artifacts: []catalogue.Artifact{{Name: "pkg", Kind: catalogue.ArtifactPackage, Language: "go", Paths: []string{"go"}}}}}} - b.ex.Forge = headFiles{repoA + " modules/web/go/go.mod " + head1: "module git.novox.be/novox/web/go\n\ngo 1.26\n"} - } - if row.emptyState { - b.ex.KnownPackages = knownNames{} - b.ex.Read = fixedManifests{strings.Repeat("a", 64): {Module: "mail"}, strings.Repeat("b", 64): {Module: "web"}, web: {Module: "web"}} - } - if row.renames != "" { - renamed := map[string]catalogue.SettingDeclaration{"new-key": {Type: catalogue.ConfigString, RenamedFrom: "old-key"}} - plain := map[string]catalogue.SettingDeclaration{"new-key": {Type: catalogue.ConfigString}} - trunkWeb, headWeb := catalogue.Manifest{Module: "web", Settings: plain}, catalogue.Manifest{Module: "web", Settings: renamed} - if row.renames == "drop" { - trunkWeb, headWeb = headWeb, trunkWeb - } - b.ex.Read = fixedManifests{strings.Repeat("a", 64): {Module: "mail"}, strings.Repeat("b", 64): trunkWeb, web: headWeb} - // The verb faked from its definition: the answer of the seat's fixture (mesh-contracts seats/mesh-config). - fake := fakeRenames{} - switch row.seat { - case "not served": - fake.err = fmt.Errorf("%w (nothing answers it)", ErrRenamesNotServed) - case "error": - fake.err = errors.New("the bus said no") - case "open": - fake.answer = meshconfig.RenamesAnswer{Renames: []meshconfig.RenamesAnswerRenamesItem{{Module: "web", From: "old-key", To: "new-key", At: "2026-11-04T12:00:00Z", Open: []string{"g14"}}}} - } - if row.seat != "unasked" { - b.ex.Renames = fake - } - } - if row.unparsed != "" { - b.ex.SeatDefinitions = fakeSeatDefinitions{"novox/mesh-delivery#7": {{Seat: "web-api", Module: "web-contracts", Directory: "go", Why: row.unparsed}}} - } - if row.indexer != "" && row.indexer != "heldplain" { - b.ex.Read = fixedManifests{strings.Repeat("a", 64): {Module: "mail"}, strings.Repeat("b", 64): {Module: "web"}, - web: {Module: "web", Claims: []catalogue.Claim{{Name: CatalogSeat}}}} - } - if row.seats != "" { - b.ex.SeatList = fakeSeatList{read: row.seats == "read"} - } - var judged []buildstep.ComposeJob - answer := b.asks.Answer - b.asks.Answer = func(a buildstep.StepAsk) buildstep.Step { - if a.Compose == nil { - return answer(a) - } - judged = append(judged, *a.Compose) - read := composer.ManifestRead{Accepted: row.refused == "", Refused: row.refused} - switch row.indexer { - case "held", "heldplain": - read = composer.ManifestRead{} - case "aside": - read.SetAside = "new_field" - } - verdict, _ := json.Marshal(composer.Verdict{V: composer.Version, SDK: "exe:1", Cases: []composer.CaseVerdict{{Name: JudgeCase, - Manifests: map[string]composer.ManifestRead{"web": read, "mail": {Accepted: row.untouched == "", Refused: row.untouched}}}, - {Name: JudgeTrunk, Manifests: map[string]composer.ManifestRead{"web": {Accepted: true}, "mail": {Accepted: row.trunkMail == "", Refused: row.trunkMail}}}}}) - result, _ := json.Marshal(buildstep.ComposeAnswer{Key: "k", Verdict: verdict}) - return buildstep.Step{ID: a.ID, State: buildstep.StepPassed, Result: result} - } - p := pullOf(repoA, 7, head1) - if row.ownJudge { - p = pullOf(DeliveryRepository, 7, head1) - b.fetch.Changed = []string{JudgeDir + "/judge/judge.go"} - } - p.Modules = []string{"web"} - if row.heads != "" { - contracts, seat := "mesh-delivery-contracts", "mesh-catalog" - switch row.heads { - case "outside": - contracts = "mesh-contracts" - case "misnamed": - seat = "other" - } - dir := "modules/" + contracts - p.Modules = append(p.Modules, contracts) - // The checking program reads the heads the build node lays for its run (D6): the running checker reads none. - b.heads = fstest.MapFS{ - repoA + "/" + dir + "/module.json": {Data: []byte(`{"module": "` + contracts + `", "build": {"artifacts": [{"name": "go", "kind": "package", "language": "go", "generated-from": "."}]}}`)}, - repoA + "/" + dir + "/seats/mesh-catalog/seat.json": {Data: []byte(`{"format":1,"seat":"` + seat + `","scope":"mesh","grain":"whole","domain":"Delivery","decision":"ADR 1","includes":["lists"],` + - `"verbs":[{"name":"modules","input":{"type":"object"},"answer":{"type":"object"}}]}`)}, - repoA + "/" + dir + "/seats/mesh-catalog/fixtures/a.json": {Data: []byte(`{}`)}, - repoA + "/" + dir + "/parts/lists.json": {Data: []byte(`{"format":1,"part":"lists","verbs":[{"name":"seat-definitions","input":{"type":"object"},"answer":{"type":"object"}}]}`)}, - } - } - p.Fps = map[string]meshcatalog.CandidatesByGroupValuePullsItemFpsValue{"web": {Fp2: "src2:" + strings.Repeat("f", 64), Manifest: web}} - // Issue 1921: the judge is built at the group's heads too, also a member that publishes no package yet. - cs := caseOf(t, p, pullOf("novox/mesh-networking", 9, head2)) - if row.try { - cs = TryCase("try-1", Try{Members: []TryMember{{Repository: repoA, Head: head1, Trunk: trunkA}}}, nil) - b.ex.Candidates = &fakeTryCandidates{cand: meshcatalog.CandidatesByGroupValue{Fpset: "fps", Pulls: []meshcatalog.CandidatesByGroupValuePullsItem{p}}} - } - v := b.judge(t, cs).Verdict - if line := Line(v, cs, cs.Pulls[0], nil, nil, nil); row.seriesWords != "" && !strings.Contains(line, row.seriesWords) || row.seriesWords == "" && strings.Contains(line, "series") { - t.Errorf("%s: the line %q, want it to name %q", row.name, line, row.seriesWords) - } - // The join (A2j finding 2): the verdict names each series change as {module, artifact, from, to}. - if want := []meshdeliverychecker.VerdictsByGroupHeadsValueSeriesItem(nil); row.series == "0.2" { - if want = []meshdeliverychecker.VerdictsByGroupHeadsValueSeriesItem{{Module: "web", Artifact: "pkg", From: "0.1", To: "0.2"}}; !reflect.DeepEqual(v.Series, want) { - t.Errorf("%s: the verdict's series %+v, want %+v", row.name, v.Series, want) - } - } else if len(v.Series) != 0 { - t.Errorf("%s: the verdict's series %+v, want none", row.name, v.Series) - } - if row.indexer == "ok" && !slices.ContainsFunc(cs.notes, func(n string) bool { - return strings.Contains(n, "the new indexer's manifest of web is accepted by the trunk's manifest validator") - }) { - t.Errorf("%s: the case says %v, want the new indexer's manifest said accepted by the trunk's manifest validator", row.name, cs.notes) - } - if row.seats == "unread" || row.heads == "misnamed" { - if v.State != meshdeliverycheckerclient.VerdictFail || !strings.Contains(v.Failed.Words, row.fails) || len(judged) != 0 { - t.Errorf("%s: %+v, judged %d, want a fail saying %q before any judge", row.name, v.Failed, len(judged), row.fails) - } - continue - } - // Issue 1921: the judge of the change is built at the group's heads (also a member that publishes no package yet), but - // the trunk's manifest validator that rules on a new indexer is built at the latest published versions alone, never - // at a group's head (ADR 0633 clause 6): a group with a member of its own then judges the indexer a second time. - trunkRuns := 0 - if row.indexer != "" && row.indexer != "heldplain" && (row.ownJudge || !row.try) { - trunkRuns = 1 - } - if want := 1 + trunkRuns; len(judged) != want { - t.Fatalf("%s: %d judge asks %+v, want %d", row.name, len(judged), judged, want) - } - for i, j := range judged { - pkgs := j.Fetch.Packages - atGroup := pkgs["git.novox.be/novox/mesh-networking"] == head2 - switch trunkRun := trunkRuns == 1 && i == len(judged)-1; { - case row.try: - case trunkRun && atGroup: - t.Errorf("%s: the trunk's manifest validator is built with the group's head: %v", row.name, pkgs) - case !trunkRun && !atGroup: - t.Errorf("%s: the judge at %v is fetched with the packages %v, want the group's mesh-networking member at its head %s", row.name, j.Fetch.Commit, pkgs, head2) - } - } - if row.ownJudge && (len(judged) != 2 || judged[0].Fetch.Commit != head1 || judged[1].Fetch.Commit != trunk) { - t.Fatalf("%s: judged %+v, want the head's judge and then the trunk's", row.name, judged) - } - if row.ownJudge { - judged = judged[1:] - } else if trunkRuns == 1 { - judged = judged[1:] // the group's run; the trunk's is the one read below - } - if len(judged) != 1 || judged[0].Fetch.Repository != DeliveryRepository || judged[0].Fetch.Commit != trunk || - judged[0].Package != JudgePackage || judged[0].Dir != JudgeDir { - t.Fatalf("%s: judged %+v (verdict %+v)", row.name, judged, v) - } - for _, j := range judged { - var seated composer.Request - if err := json.Unmarshal(j.Request, &seated); err != nil || (len(seated.Seats) == 1) != row.headSeats || - (row.headSeats && !strings.Contains(string(seated.Seats[0]), `"node-x"`)) { - t.Errorf("%s: the judge at %v is handed the seats %s, want the heads' list: %v", row.name, j.Fetch.Commit, seated.Seats, err) - } - } - var req composer.Request - if err := json.Unmarshal(judged[0].Request, &req); err != nil || req.Cases[0].Manifests["web"].Digest != web || - req.Cases[1].Name != JudgeTrunk || req.Cases[1].Manifests["web"].Digest != strings.Repeat("b", 64) || - req.Predefined["font-size"].Type != "number" || - req.Cases[0].Manifests["mail"].Digest != strings.Repeat("a", 64) { - t.Fatalf("%s: the request %+v: %v", row.name, req, err) - } - if row.heads != "" { - // Review round 2 of G (programs.go's digest side): the checking program's -seats input carries the digest of - // every definition the reader holds, never the list, and its answer is laid over the list (below). - var digests map[string]string - b.inputs.mu.Lock() - for _, body := range b.inputs.vals { - var f rules.Facts - if json.Unmarshal(body, &f) == nil && f.SeatDigests != nil { - digests = f.SeatDigests - } - } - b.inputs.mu.Unlock() - if want := map[string]string{"a": rules.SeatDigest(json.RawMessage(`{"seat":"a"}`)), "b": rules.SeatDigest(json.RawMessage(`{"seat": "b"}`))}; !reflect.DeepEqual(digests, want) { - t.Errorf("%s: the -seats input carries the digests %v, want the reader's list's %v", row.name, digests, want) - } - var got []string - for _, raw := range req.Seats { - var d struct { - Seat string `json:"seat"` - Verbs []struct { - Name string `json:"name"` - } `json:"verbs"` - } - _ = json.Unmarshal(raw, &d) - for _, v := range d.Verbs { - d.Seat += "." + v.Name - } - got = append(got, d.Seat) - } - want := []string{"a", "b", "mesh-catalog.seat-definitions.modules"} - if row.heads == "outside" { - want = want[:2] - } - if !slices.Equal(got, want) { - t.Errorf("%s: the trunk's manifest validator's seats %v, want %v: the list's with the head's definition, its part resolved", row.name, got, want) - } - } else if row.seats == "read" && (len(req.Seats) != 2 || string(req.Seats[0]) != `{"seat":"a"}` || string(req.Seats[1]) != `{"seat":"b"}`) { - t.Errorf("%s: the request's seats %s, want the two definitions the reader holds", row.name, req.Seats) - } - if row.seats == "" && !row.headSeats && len(req.Seats) != 0 { - t.Errorf("%s: the request's seats %s, want none from a checker that follows no list", row.name, req.Seats) - } - if !reflect.DeepEqual(req.Packages, row.known) || len(req.Input) != 0 && string(req.Input) != "null" { - t.Errorf("%s: the judge's known packages %v and input %s, want the known packages %v and no input", row.name, - req.Packages, req.Input, row.known) - } - switch { - case row.fails == "" && v.State != meshdeliverycheckerclient.VerdictPass: - t.Errorf("%s: %+v", row.name, v) - case row.fails != "" && (v.State != meshdeliverycheckerclient.VerdictFail || !strings.Contains(v.Failed.Words, row.fails)): - t.Errorf("%s: %+v, want a fail saying %q", row.name, v.Failed, row.fails) - } - } - if !changesJudge(DeliveryRepository, []Fetched{{Changed: []string{JudgeDir + "/judge/judge.go"}}}) || - changesJudge(DeliveryRepository, []Fetched{{Changed: []string{JudgeDir + "/internal/index/x.go"}}}) || - changesJudge("novox/mesh-catalog", []Fetched{{Changed: []string{JudgeDir + "/judge/judge.go"}}}) { - t.Error("which merge changes the judge") - } -} - -// fakeSeatList is the seat list reader as a test gives it: two definitions once read, else the reader's words. -type fakeSeatList struct{ read bool } - -func (f fakeSeatList) Definitions() ([]json.RawMessage, error) { - if !f.read { - return nil, errors.New("the seat list is held from the bootstrap (2 seats) and nothing new is acted on") - } - return []json.RawMessage{json.RawMessage(`{"seat":"a"}`), json.RawMessage(`{"seat":"b"}`)}, nil -} - -// knownNames are the packages state's names as a test gives them, each with the / it is built from. -type knownNames map[string]string - -func (k knownNames) PackageNames() map[string]string { return k } - -// fakeRenames is the seat mesh-config's verb renames as its definition answers it. -type fakeRenames struct { - answer meshconfig.RenamesAnswer - err error -} - -func (f fakeRenames) Renames(context.Context, string) (meshconfig.RenamesAnswer, error) { - return f.answer, f.err -} - -// fakeSeatDefinitions are the indexer's unparsed seat definitions by pull request (pullKey). -type fakeSeatDefinitions map[string][]UnparsedSeat - -func (f fakeSeatDefinitions) Unparsed(_ context.Context, repository string, pull int) ([]UnparsedSeat, error) { - return f[fmt.Sprintf("%s#%d", repository, pull)], nil -} diff --git a/modules/mesh-delivery-checker/internal/check/failure_words_test.go b/modules/mesh-delivery-checker/internal/check/failure_words_test.go deleted file mode 100644 index 37e2b87c..00000000 --- a/modules/mesh-delivery-checker/internal/check/failure_words_test.go +++ /dev/null @@ -1,108 +0,0 @@ -package check - -import ( - "encoding/json" - "mesh-delivery-checker/rules" - "strings" - "testing" - - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshdeliverycheckerclient" -) - -// The failure the build module reported for group r4g on 2026-10-23: the test logged a line, then failed with a multi-line -// t.Fatalf. Its output is what the build module now sends (its last lines, with the error line as Cause). -func fatalAfterLog() Failure { - return Failure{ - Package: "github.com/novox/mesh-controller/internal/broker", Test: "TestTheCataloguesDerivedSubjectsMeet", - Cause: "3 subscription(s) derive to a subject no emitter owns:", - Output: " agreement_catalogue_test.go:130: judged against /var/lib/mesh-build-go-work/id/beside/mesh-catalog as cloned\n" + - " agreement_catalogue_test.go:186: 3 subscription(s) derive to a subject no emitter owns:\n" + - " a.b.c\n d.e.f\n g.h.i\n--- FAIL: TestTheCataloguesDerivedSubjectsMeet (0.00s)", - } -} - -// A failed test's words are its whole failure message, kept within their bound by their last lines (issue 1901). -func TestAFailuresWordsAreItsWholeMessageWithinTheirBound(t *testing.T) { - for _, row := range []struct { - name string - test func(t *testing.T) - }{ - {"a failed tests verdict keeps its whole failure message", func(t *testing.T) { // 1901/AC1 - v := rules.LevelFailure("", "", "", "unit", Tested{Failed: []Failure{fatalAfterLog()}}) - for _, want := range []string{"3 subscription(s) derive to a subject no emitter owns:", "a.b.c", "d.e.f", "g.h.i"} { - if !strings.Contains(v.Failed.Words, want) { - t.Errorf("words lack %q: %q", want, v.Failed.Words) - } - } - if len(v.Failed.Words) > rules.MaxWords+200 { - t.Errorf("words are %d bytes, bound %d", len(v.Failed.Words), rules.MaxWords) - } - }}, - {"the status line names the failure not the first logged line", func(t *testing.T) { // 1901/AC2 - v := rules.LevelFailure("", "", "", "unit", Tested{Failed: []Failure{fatalAfterLog()}}) - got := firstFailed(*v) - if !strings.Contains(got, "3 subscription(s) derive to a subject no emitter owns:") || strings.Contains(got, "judged against") || strings.Contains(got, "\n") { - t.Errorf("firstFailed = %q", got) - } - // With no cause told apart (an older build module), the words still start at the first line, as before. - f := fatalAfterLog() - f.Cause = "" - v = rules.LevelFailure("", "", "", "unit", Tested{Failed: []Failure{f}}) - if !strings.HasPrefix(afterHid(v.Failed.Words), "agreement_catalogue_test.go:130") { - t.Errorf("words = %q", v.Failed.Words) - } - }}, - {"words longer than the bound keep their last lines", func(t *testing.T) { // 1901/AC1 - f := Failure{Output: strings.Repeat("log line of some length\n", 500) + "the cause is here"} - v := rules.LevelFailure("", "", "", "unit", Tested{Failed: []Failure{f}}) - if !strings.HasSuffix(v.Failed.Words, "the cause is here") || len(v.Failed.Words) > rules.MaxWords+200 { - t.Errorf("%d bytes, ends %q", len(v.Failed.Words), v.Failed.Words[len(v.Failed.Words)-30:]) - } - _ = meshdeliverycheckerclient.VerdictFail - }}, - // An older build module sends no "cause": its answer is still accepted and the verdict's words are its output, as before - // (1901/AC3). A failure that hides its cause (none, or a passing line) is said loudly first in the words and in the status - // line, naming the build module and the version it says it is, and the level still fails; a failure that keeps the - // contract is worded as before (1901/AC8). - {"an older build modules failure is accepted with its whole output", func(t *testing.T) { // 1901/AC3, AC8 - old := `{"package":"p","test":"TestX","output":"x_test.go:1: logged\nx_test.go:2: the old kept lines"}` - var f Failure - if err := json.Unmarshal([]byte(old), &f); err != nil || f.Cause != "" { - t.Fatalf("1901/AC3: err = %v, cause = %q", err, f.Cause) - } - v := rules.LevelFailure("", "", "", "unit", Tested{Failed: []Failure{f}}) - if afterHid(v.Failed.Words) != "x_test.go:1: logged\nx_test.go:2: the old kept lines" { - t.Errorf("1901/AC3: words = %q", v.Failed.Words) - } - if got := firstFailed(*v); !strings.Contains(got, "the build module hid the failure") || strings.Contains(got, "\n") { - t.Errorf("1901/AC3, AC8: status = %q", got) - } - - by := "mesh-build-node with mesh-sdk v0.1.14-0.20261026184535-e40dd0f56a78" - for _, c := range []struct { - name, module, by, cause, output, loud string - }{ - {"no cause", "mesh-build-node", by, "", "test/b.test.ts: something", "the build module hid the failure (mesh-build-node at mesh-sdk v0.1.14-0.20261026184535-e40dd0f56a78): it sent no cause"}, - {"a passing line as its cause", "mesh-build-node", by, "\u2714 the same merge has the same id (8.006913ms)", "", "the build module hid the failure (mesh-build-node at mesh-sdk v0.1.14-0.20261026184535-e40dd0f56a78): its cause is a passing line"}, - {"from before the contract", "mesh-build-node", "", "", "\u2714 the same merge has the same id (8.006913ms)", "the build module hid the failure (mesh-build-node at a version before the failure contract): it sent no cause"}, - {"a real cause", "mesh-build-node", by, "one plus one is not three", "not ok 3 - fails", ""}, - } { - t.Run(c.name, func(t *testing.T) { - v := rules.LevelFailure("", c.module, "", "unit", Tested{By: c.by, Failed: []Failure{{Package: "modules/gitea", Test: "fails", Cause: c.cause, Output: c.output}}}) - if v.State != meshdeliverycheckerclient.VerdictFail { - t.Errorf("1901/AC8: the verdict is %q, want it failed", v.State) - } - line := firstFailed(*v) - switch { - case c.loud == "" && strings.Contains(v.Failed.Words, "hid the failure"): - t.Errorf("1901/AC8: a failure that keeps the contract is said hidden: %q", v.Failed.Words) - case c.loud != "" && (!strings.HasPrefix(v.Failed.Words, c.loud) || !strings.Contains(line, c.loud) || !strings.Contains(v.Failures[0].Words, "hid the failure")): - t.Errorf("1901/AC8: words %q, status %q, want both to start with %q", v.Failed.Words, line, c.loud) - } - }) - } - }}, - } { - t.Run(row.name, row.test) - } -} diff --git a/modules/mesh-delivery-checker/internal/check/fakes_test.go b/modules/mesh-delivery-checker/internal/check/fakes_test.go deleted file mode 100644 index bade10ab..00000000 --- a/modules/mesh-delivery-checker/internal/check/fakes_test.go +++ /dev/null @@ -1,81 +0,0 @@ -package check - -import ( - "context" - "sort" - "sync" -) - -// memKV is a bucket in memory with the revisions a real one gives. -type memKV struct { - mu sync.Mutex - vals map[string][]byte - revs map[string]uint64 - next uint64 - // creates counts the creates that succeeded, by key. - creates map[string]int -} - -func newMemKV() *memKV { - return &memKV{vals: map[string][]byte{}, revs: map[string]uint64{}, creates: map[string]int{}} -} - -func (m *memKV) Get(_ context.Context, key string) ([]byte, uint64, bool, error) { - m.mu.Lock() - defer m.mu.Unlock() - v, ok := m.vals[key] - return v, m.revs[key], ok, nil -} - -func (m *memKV) Create(_ context.Context, key string, value []byte) (uint64, error) { - m.mu.Lock() - defer m.mu.Unlock() - if _, ok := m.vals[key]; ok { - return 0, ErrConflict - } - m.next++ - m.vals[key], m.revs[key] = append([]byte(nil), value...), m.next - m.creates[key]++ - return m.next, nil -} - -func (m *memKV) Update(_ context.Context, key string, value []byte, revision uint64) (uint64, error) { - m.mu.Lock() - defer m.mu.Unlock() - if _, ok := m.vals[key]; !ok || m.revs[key] != revision { - return 0, ErrConflict - } - m.next++ - m.vals[key], m.revs[key] = append([]byte(nil), value...), m.next - return m.next, nil -} - -func (m *memKV) Keys(context.Context) ([]string, error) { - m.mu.Lock() - defer m.mu.Unlock() - keys := make([]string, 0, len(m.vals)) - for k := range m.vals { - keys = append(keys, k) - } - sort.Strings(keys) - return keys, nil -} - -func (m *memKV) Delete(_ context.Context, key string) error { - m.mu.Lock() - defer m.mu.Unlock() - delete(m.vals, key) - delete(m.revs, key) - return nil -} - -// memInputs keeps run inputs in a memKV, under their digest. -type memInputs struct{ kv *memKV } - -func (m memInputs) Keep(ctx context.Context, digest string, body []byte) error { - if _, _, found, _ := m.kv.Get(ctx, digest); found { - return nil - } - _, err := m.kv.Create(ctx, digest, body) - return err -} diff --git a/modules/mesh-delivery-checker/internal/check/gate_test.go b/modules/mesh-delivery-checker/internal/check/gate_test.go deleted file mode 100644 index 63680278..00000000 --- a/modules/mesh-delivery-checker/internal/check/gate_test.go +++ /dev/null @@ -1,89 +0,0 @@ -package check - -import ( - "context" - "strings" - "testing" - - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshdeliveryclient" -) - -// What the gate reads of the checker (R4e, lead's interface with dev-r4e-gate): the verdict's heads are the gate's hash over -// `#=`, a lone pull request is a group of one, and a move of a trunk marks -// mesh/check pending on every open pull request into it, every member's for a group, before any check starts. - -func owedState(t testing.TB, r *rig, repo string, number int, head string) string { - t.Helper() - key, err := CheckerOwedKey(repo, number, head) - if err != nil { - t.Fatal(err) - } - raw, _, found, _ := r.owed.Get(context.Background(), key) - if !found { - return "" - } - o, err := DecodeCheckerOwed(raw) - if err != nil { - t.Fatal(err) - } - return o.State -} - -func TestTheVerdictsHeadsAreTheGatesHashOverLowercaseHeads(t *testing.T) { // gate (b), (c) - ctx := context.Background() - r := newRig(t, passJudge()) - upper := strings.ToUpper(head1[:20]) + head1[20:] - r.setTrunks(t, map[string]string{"Novox/Mesh-Delivery": trunkA, repoA: trunkA, repoSDK: trunkS}) - cand := candidateOf(t, "feat/x", pullOf("Novox/Mesh-Delivery", 7, upper)) - r.ch.Candidate(ctx, "feat%2Fx", cand) - r.ch.Wait() - want, _ := meshdeliveryclient.HeadsHash([]meshdeliveryclient.Head{{Repository: repoA, Number: 7, Head: head1}}) - if v := r.verdict(t, keyOf(t, "feat/x", cand)); v.Heads != want { - t.Errorf("heads = %q, want the gate's hash of the lone pull request, a group of one, %q", v.Heads, want) - } -} - -func TestAGroupsVerdictHeadsCoverEveryMember(t *testing.T) { // gate (b): hq's member too, as the gate's ask covers it - ctx := context.Background() - r := newRig(t, passJudge()) - cand := candidateOf(t, "feat/x", pullOf(repoA, 7, head1), pullOf(repoSDK, 12, head2), pullOf(hqRepo, 3, head2)) - r.ch.Candidate(ctx, "feat%2Fx", cand) - r.ch.Wait() - want, _ := meshdeliveryclient.HeadsHash([]meshdeliveryclient.Head{{Repository: repoA, Number: 7, Head: head1}, {Repository: repoSDK, Number: 12, Head: head2}, - {Repository: hqRepo, Number: 3, Head: head2}}) - if v := r.verdict(t, keyOf(t, "feat/x", cand)); v.Heads != want { - t.Errorf("heads = %q, want %q", v.Heads, want) - } -} - -func TestATrunkMoveMarksEveryOpenPullRequestIntoItPendingAtOnce(t *testing.T) { // gate (a), lead decision L4 (1302's checker part) - ctx := context.Background() - r := newRig(t, passJudge()) - r.ch.Candidate(ctx, "feat%2Fg", candidateOf(t, "feat/g", pullOf(repoA, 7, head1), pullOf(repoSDK, 12, head2))) - r.ch.Candidate(ctx, "feat%2Fs", candidateOf(t, "feat/s", pullOf(repoSDK, 13, head1))) - r.ch.Wait() - for _, p := range []struct { - repo string - n int - head string - }{{repoA, 7, head1}, {repoSDK, 12, head2}, {repoSDK, 13, head1}} { - if s := owedState(t, r, p.repo, p.n, p.head); s != "success" { - t.Fatalf("%s#%d is %q before the move", p.repo, p.n, s) - } - } - // mesh-delivery's trunk moves; the re-judges it asks are held in their judge (in the stream, since R4g) meanwhile. - release := make(chan struct{}) - r.ch.Judge = &judgeFunc{f: func(context.Context, *Case, int) (Outcome, error) { <-release; return Outcome{Verdict: passing()}, nil }} - defer func() { close(release); r.ch.Wait() }() - r.setTrunks(t, map[string]string{repoA: trunkA2, repoSDK: trunkS}) - r.ch.TrunkMoved(ctx) - if s := owedState(t, r, repoA, 7, head1); s != "pending" { - t.Errorf("mesh-delivery#7, into the moved trunk, is %q, want pending", s) - } - if s := owedState(t, r, repoSDK, 12, head2); s != "pending" { - t.Errorf("mesh-sdk#12, a member of the same group, is %q, want pending", s) - } - if s := owedState(t, r, repoSDK, 13, head1); s != "success" { - t.Errorf("mesh-sdk#13, alone into a trunk that did not move, is %q, want its success to stand", s) - } -} diff --git a/modules/mesh-delivery-checker/internal/check/graph_edges.go b/modules/mesh-delivery-checker/internal/check/graph_edges.go deleted file mode 100644 index e7c7afef..00000000 --- a/modules/mesh-delivery-checker/internal/check/graph_edges.go +++ /dev/null @@ -1,116 +0,0 @@ -package check - -import ( - "cmp" - "context" - "fmt" - "maps" - "slices" - "strings" - - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/composer" - "git.novox.be/novox/mesh-sdk/go/catalogue" - - "mesh-delivery-checker/rules" - - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/graph" -) - -// The module graph of a change (novox/hq ADR 0603 §2, ADR 0614 §6): the running checker gathers its ordering edges, the -// checking program judges whether it has a cycle (rules.JudgeGraph, ADR 0656 §5). The graph is worked out from the -// catalogue as the change leaves it (every trunk manifest, each one a pull request touches replaced by its candidate's) -// and as the trunk has it, with the contract's ManifestGraph, the way the indexer works out its graph's edges; the facts -// carry only each edge's two modules and its kind. - -// ManifestReader reads a kept manifest by its digest (the indexer's manifests state). -type ManifestReader interface { - Manifest(ctx context.Context, digest string) (catalogue.Manifest, error) -} - -// gatherGraph records the change's and the trunk's module graph edges as a fact; none when the case touches no manifest -// or nothing reads manifests. A change's manifest that cannot be read fails the check, said, never passes it; a trunk's -// that cannot be read leaves the trunk's graph unread, so no cycle is the trunk's. -func (st *state) gatherGraph(ctx context.Context) { - if st.j.Manifests == nil || st.j.Read == nil || st.narrowTry() { - return - } - req, touched := judgeRequest(st.j.Manifests.ManifestDigests(), st.j.Manifests.ManifestFingerprints(), st.c.Pulls) - if len(touched) == 0 { - return - } - read := func(digests map[string]composer.Manifest) (map[string]catalogue.Manifest, error) { - out := map[string]catalogue.Manifest{} - for _, module := range slices.Sorted(maps.Keys(digests)) { - m, err := st.j.Read.Manifest(ctx, digests[module].Digest) - if err != nil { - return nil, fmt.Errorf("the manifest %s of %s: %w", digests[module].Digest, module, err) - } - out[module] = m - } - return out, nil - } - change, err := read(req.Cases[0].Manifests) - if err != nil { - st.fail(st.goModule(), "the change's module graph cannot be worked out, so no cycle can be ruled out: "+err.Error()) - return - } - g := rules.Graph{} - changed := orderingEdges(graph.OfManifests(change)) - trunk := map[[2]string]string{} - if before, err := read(req.Cases[1].Manifests); err == nil { - g.Trunk = true - trunk = orderingEdges(graph.OfManifests(before)) - } - for _, pair := range slices.SortedFunc(maps.Keys(changed), cmpPair) { - e := rules.Edge{From: pair[0], To: pair[1], Kind: changed[pair]} - if _, both := trunk[pair]; !both && g.Trunk { - e.Only = rules.EdgeChange - } - g.Edges = append(g.Edges, e) - } - for _, pair := range slices.SortedFunc(maps.Keys(trunk), cmpPair) { - if _, both := changed[pair]; !both { - g.Edges = append(g.Edges, rules.Edge{From: pair[0], To: pair[1], Kind: trunk[pair], Only: rules.EdgeTrunk}) - } - } - st.facts = append(st.facts, rules.Step{Module: st.goModule(), Graph: &g}) -} - -func cmpPair(a, b [2]string) int { - return cmp.Or(strings.Compare(a[0], b[0]), strings.Compare(a[1], b[1])) -} - -// orderingEdges are the graph's ordering edges (graph.Graph.Before) between its modules, each pair once with the kind it -// is first met by: a base, a provision or bus state awaited of another provider, or a verb the graph keeps served by -// another module (a base on itself is a cycle). A verb edge the graph leaves out (ADR 0614 §3), a toolchain and a package edge are none (§6). -func orderingEdges(g graph.Graph) map[[2]string]string { - out := map[[2]string]string{} - add := func(from, to, kind string) { - if _, ours := g[to]; !ours || (from == to && kind != rules.EdgeBase) { - return - } - if _, met := out[[2]string{from, to}]; !met { - out[[2]string{from, to}] = kind - } - } - for _, name := range slices.Sorted(maps.Keys(g)) { - n := g[name] - for _, b := range n.Bases { - add(name, b, rules.EdgeBase) - } - for _, a := range n.Awaits { - for _, p := range g.Providers(a) { - add(name, p, rules.EdgeAwaits) - } - } - for _, v := range n.Invokes { - if slices.Contains(n.LeftOut, v) { - continue - } - for _, s := range g.Servers(v) { - add(name, s, rules.EdgeInvokes) - } - } - } - return out -} diff --git a/modules/mesh-delivery-checker/internal/check/heard.go b/modules/mesh-delivery-checker/internal/check/heard.go deleted file mode 100644 index b10bd09f..00000000 --- a/modules/mesh-delivery-checker/internal/check/heard.go +++ /dev/null @@ -1,21 +0,0 @@ -package check - -import ( - "errors" - - "github.com/nats-io/nats.go" -) - -// Unheard is the error of a call that reached nobody: the bus had no responder for it, or none answered within the call's -// bound. The program wraps the errors of its forge calls in it where the bus gives a timeout; a no-responders error is -// known as it is. A build step is no call since R4g: an ask whose node stops is delivered again by its stream (ADR 0525 §6). -type Unheard struct{ Err error } - -func (u *Unheard) Error() string { return u.Err.Error() } -func (u *Unheard) Unwrap() error { return u.Err } - -// isUnheard says whether err is a call that reached nobody. A step that began and failed, or ended failed, is not. -func isUnheard(err error) bool { - var u *Unheard - return errors.As(err, &u) || errors.Is(err, nats.ErrNoResponders) -} diff --git a/modules/mesh-delivery-checker/internal/check/judge.go b/modules/mesh-delivery-checker/internal/check/judge.go deleted file mode 100644 index ac25c7e3..00000000 --- a/modules/mesh-delivery-checker/internal/check/judge.go +++ /dev/null @@ -1,992 +0,0 @@ -package check - -import ( - "context" - "encoding/json" - "fmt" - "mesh-delivery-checker/rules" - "slices" - "sort" - "strings" - "time" - - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-builder/buildrun" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshdeliverycheckerclient" - "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/meshdeliverychecker" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep" -) - -// RunnerWorkspace is the runner the Go build module's digest and test steps are asked with when the merge changes the build -// module itself: the installed module compiles the candidate's program from the merged tree and runs the step as it, shut -// off (ADR 0535 §1). -const RunnerWorkspace = "workspace" - -// buildGoDir is the Go build module's directory in the catalogue: a merge changing a path under it is judged by its -// candidate (ADR 0535 §1). The other build modules' own directories are judged by the installed module until its part of issue 1898. -func buildGoDir(goModule string) string { return "modules/" + goModule + "/" } - -// changesBuildGo says whether a merge of the repository with these changed paths changes the Go build module. -func changesBuildGo(repository, goModule string, changed []string) bool { - if repository != catalogueRepository || goModule == "" { - return false - } - for _, p := range changed { - if strings.HasPrefix(p, buildGoDir(goModule)) { - return true - } - } - return false -} - -// The words of the line on the program that judged a change to the Go build module (ADR 0535 §2, §5). -func judgedByOldInstalled(module string) string { - return "judged by the installed " + module + ": it does not run a candidate yet" -} -func judgedByInstalled(module string) string { return "judged by the installed " + module } -func judgedByCandidate(module string) string { return "judged by the candidate's " + module + " at " } - -// Asks puts a check's ask on its build seat's stream and waits for its step (buildrun.Asker; ADR 0525 §1, §6): the -// checker chooses no node, starts no step and holds none; whichever build node pulls the ask runs the check. -type Asks interface { - Put(ctx context.Context, a buildstep.StepAsk) error - Wait(ctx context.Context, a buildstep.StepAsk) (buildstep.Step, error) -} - -// ToolchainEntries are the nodes' toolchain entries of a language (buildrun.ToolchainSet). -type ToolchainEntries interface { - Entries(language string) []buildstep.NodeToolchain -} - -// BuildModules says which build modules judge a repository: the Go one always, the Node one when the repository holds a -// TypeScript module. -type BuildModules interface { - BuildModules(repository string) []string -} - -// Examiner judges a case through the build seats (ADR 0484 clauses 3, 4, 10, 13; ADR 0525 §1, §3): for each pull request -// and build module it puts one check ask whose job fetches the head merged onto its trunk head, then runs the unit level -// and the integration level, taking the kept verdicts of unchanged packages and running the change's own tests first; -// every level and member runs to its end also after a failure, so the verdict names every failure (the operator, -// 2026-11-02). It judges the step's answer as it judged the tools' answers. -type Examiner struct { - // Module is the checker's own module, the credential's: the asker of its asks and the owner of its buckets (design 47 G A-296). - Module string - Asks Asks - // DeclineBound is how long a placed ask may go on being declined, from its first decline, before the check fails - // saying no node with its need took it (issue 890, ADR 0552); DefaultDeclineBound when zero. - DeclineBound time.Duration - // Toolchains are the nodes' toolchains: a kept verdict names the toolchain the nodes agree on. - Toolchains ToolchainEntries - Kept Kept - // Previews is the previews bucket; nil writes none. - Previews KV - Modules BuildModules - // Seats finds the build modules from the seat list and the holders of seats (design 47 G A-82). - Seats *buildrun.BuildSeats - // Runs says which commit the mesh runs of a module (the indexer's modules); nil knows none. - Runs interface{ CommitOf(module string) string } - // Forge reads the forge's files for the siblings a repository's tests read; nil reads none. - Forge Forge - // Published names the latest published version of every mesh package a module of the mesh uses, by package, from the - // indexer's modules (novox/hq ADR 0573 §2): a check builds against those, or against a member's head for a package - // its group publishes (§4), whatever go.mod names. Nil names none, and go.mod's versions are built. - Published interface { - LatestPackages() buildstep.PackageVersions - } - // KnownPackages names the packages the indexer's packages state knows (its series keys, meshcatalog.PackagesByPackageSeriesValue), by the - // name in its own ecosystem, each with the `/` it is built from: the names a manifest's `packages` is - // judged against (manifests_judge.go, design 32). Nil, or PackageNames answering nil while the state is not read yet, - // hands the judge no names, and it judges none; an empty map is a state read and empty, against which every name fails. - KnownPackages interface { - PackageNames() map[string]string - } - // Builds says how the build of a fingerprint the candidate carries stands (the builder's builds bucket); nil says nothing - // of the builds. - Builds BuildStates - // BuildEnds waits on the builder's builds of the candidate before the check composes (ADR 0603 §10); nil composes - // without waiting, said in the composition's warnings. - BuildEnds BuildEnds - // BuildWait is how long the check waits for those builds (the setting build-wait-bound); DefaultBuildWait when 0. - BuildWait time.Duration - // Announce says a preview was written under the key (EventPreviewWritten); nil says nothing. - Announce Announcer - // Dirs names a module's directory in its repository, from the indexer's modules, so a manifest is read at a member's - // head (tagwanted.go); nil, or a module it does not know, tries modules/ and the repository's root. - Dirs interface { - ModuleDir(module string) (string, bool) - } - // Packages names, of a repository, its TypeScript package artifacts, each by its directory and the paths - // (repository-relative) it is built from, from the indexer's modules (meshcatalog.ModulesByModuleValue.ArtifactPaths, - // lead decision L8); nil serves no group package. - Packages interface { - TypeScriptPackages(repository string) []TypeScriptPackage - } - // Trunks are the trunk heads of every repository, for the siblings a repository's tests read. - Trunks interface{ Heads() map[string]string } - // Manifests are the indexer's manifest digests by module: the catalogue a change's manifests are judged in by the - // indexer's judge (manifests_judge.go, novox/hq ADR 0578 §2); nil judges no manifest. - Manifests TrunkManifests - // SeatDefinitions reads the indexer's seat definitions of a pull request (seatdefs.go, design 26); nil reads none. - SeatDefinitions SeatDefinitions - // SeatList gives the seat list the checker's reader holds from the seat mesh-catalog (verb seat-definitions): the base the - // checking program lays the heads' definitions over (programs.go, novox/hq ADR 0636 §1, §4); nil gives it none. - SeatList SeatList - // Renames asks the seat mesh-config's verb renames for a change that brings or drops a `renamed-from` (renames.go, - // design 32); nil fails such a change, saying it cannot ask. - Renames Renames - // Read reads a kept manifest by its digest: the change's module graph is worked out from them (graph_edges.go, novox/hq - // ADR 0603 §2); nil works out no graph. - Read ManifestReader - // Serving says, from what runs, whether a running healthy build serves a seat verb or module tool (novox/hq ADR 0614 - // §7): the node-engines' haves, the builder's build of each, its manifest (graph.Served). Nil reads nothing, and no - // changed build module is named for a verb it invokes. - Serving interface { - Served(ctx context.Context) (func(invoke string) bool, error) - } - // Predefined reads the catalogue's predefined keys the indexer keeps (manifests_judge.go); nil reads none. - Predefined PredefinedList - // Compositions makes a check's composition (ADR 0593 §7): the engines' answers (EngineCompositions); nil leaves the - // composition not run. - Compositions CompositionReader - // Nodes names every node with a record, read from each `.node` of the node-engine's have (novox/hq ADR 0567 - // §12): every check ask carries them (CheckJob.NodeNames) for the names check, so no repository lists them. A check - // whose names cannot be read, or that reads none, is not asked and fails saying so; nil hands no names. - Nodes interface { - Names(ctx context.Context) ([]string, error) - } - // Candidates answers the indexer's candidate of a try's group once it wrote it from the try's previews, the manifests - // and fingerprints a group try's manifest validator and composition judge (issue 1921), and of a pull request's check - // that began before the indexer read its merge preview; nil leaves such a case with no manifest or composition judged, - // said. - Candidates TryCandidates - // Inputs keeps the checking program's inputs (the state InputsStateName, served on InputVerb); BeginBound is how long a run ask may wait for a - // build node to begin it (DefaultBeginBound when zero). - Inputs Inputs - BeginBound time.Duration - Now func() time.Time - Logf func(format string, args ...any) -} - -// TryCandidates answers the candidate the indexer holds for a try's group at its heads hash, waiting for it within the -// bound; an error says it did not come (and why). -type TryCandidates interface { - TryCandidate(ctx context.Context, group, heads string, bound time.Duration) (meshcatalog.CandidatesByGroupValue, error) -} - -// CompositionReader composes a check: the engines' answers, which the rules judge (rules.JudgeEngines); an error is only -// a case that cannot be composed at all. -type CompositionReader interface { - Compose(ctx context.Context, c *Case) (rules.Composed, error) -} - -func (j *Examiner) now() time.Time { - if j.Now != nil { - return j.Now() - } - return time.Now() -} - -func (j *Examiner) logf(format string, args ...any) { - if j.Logf != nil { - j.Logf(format, args...) - } -} - -// fetchBeside are the siblings as the fetch is asked to place them. -func fetchBeside(refs []BesideRef) []buildstep.FetchBeside { - out := make([]buildstep.FetchBeside, 0, len(refs)) - for _, r := range refs { - out = append(out, buildstep.FetchBeside{Repository: r.Repository, Commit: r.Commit}) - } - return out -} - -// besideLines are the siblings as the digest step echoes them: ` `, sorted. -func besideLines(refs []BesideRef) []string { - out := make([]string, 0, len(refs)) - for _, r := range refs { - out = append(out, r.Repository+" "+r.Commit) - } - sort.Strings(out) - return out -} - -// TypeScriptPackage is one TypeScript package artifact of a repository's module: Dir, its directory in the repository -// ("" for the repository's root), and Paths, the repository-relative paths it is built from. -type TypeScriptPackage struct { - Dir string - Paths []string -} - -// target is a pull request on one build module: the node that pulled its ask, the workspace its fetch made and what it -// said. -type target struct { - pull Pull - module string - // language is the language of the toolchain the build module builds with (the `on` of its seat's acting rule). - language string - node string - toolchain string - // agreed is the toolchain the ask names, so a node off it declines the check (ADR 0584); nil when none is agreed. - agreed *buildstep.ToolchainUsed - fetched Fetched - // fetchArgs are the arguments of the fetch its check ask runs. - fetchArgs buildstep.Fetch - // priority are the Go packages (import paths) or the Node module directories whose test files the merge changes. - changed []string - // beside are the lines ` ` of the siblings the workspace was given, sorted: its tests may read them, - // so a verdict is kept or taken only under a digest that says it folded exactly these in (lead decision L5). - beside []string - // runner is RunnerWorkspace when the target's ask runs the candidate's own build module (ADR 0535 §1), empty otherwise. - runner string - // judged is what the line says of the program that judged a change to the build module; empty for any other change. - judged string -} - -// judgedBy takes what a step under runner workspace answered of the program that ran it (judged_by): the candidate, or the -// installed module (a module that does not take the runner says nothing, and is asked without it from now on: ADR 0535 §2). -// It says whether the candidate ran. -func (t *target) judgedBy(answer string) bool { - switch { - case strings.HasPrefix(answer, "candidate "): - t.judged = judgedByCandidate(t.module) + short12(strings.TrimPrefix(answer, "candidate ")) - return true - case answer == "": - t.judged, t.runner = judgedByOldInstalled(t.module), "" - default: - t.judged, t.runner = judgedByInstalled(t.module), "" - } - return false -} - -// stepArgs are a step's arguments with the target's runner. -func (t *target) stepArgs(args map[string]any) map[string]any { - if t.runner != "" { - args["runner"] = t.runner - } - return args -} - -// state is one judging. -type state struct { - j *Examiner - c *Case - targets []*target - levels rules.Tally - // facts are the facts of the check met so far, in order: what the checking program judges (milestone 47/B0). - facts []rules.Step - // composition is how the check composed, recorded after every step (compose). - composition *rules.Composition - clone time.Duration - slow []string - // beside are the siblings read at their trunk's head, by repository (ADR 0548 §6). - beside map[string]string - // judgeHead is the group's mesh-delivery member head when its merge changes the judge (ADR 0578 §2); empty judges - // with mesh-delivery's trunk. - judgeHead string - // predefinedHead is the catalogue member's head when its merge changes predefined.json: the list is read there. - predefinedHead string - // unpreviewed are the members (pullKey) with no preview of a merge, each with which of the two it is: a head that does not - // merge, or a fetch that did not answer (design 47 G A-286). The indexer holds no manifest of them, so the assigner's - // composition would only wait: it is not awaited. A member whose fetch merged is previewed whatever its later steps ended with. - unpreviewed []string - // conflicted are the members (pullKey) whose head does not merge into its trunk. - conflicted map[string]bool - // outOfStep are, by pull request (pullKey), the generated files a level's compare step found out of step (design 26). - outOfStep map[string][]string - // noCandidate says why the case has no previewed candidate of its heads from the indexer within the bound: for a whole - // try its manifests were not judged and it was not composed; for a pull request's check that began on the indexer's - // first write, its manifests were judged from that write and it was not composed. Empty when it has one, and for a pull - // request's check whose case already holds its fingerprints. - noCandidate string -} - -// narrowTry says the case is a try narrowed to a level or to some tests: it judges no manifest, graph or composition. -func (st *state) narrowTry() bool { return st.c.Try != nil && !st.c.Try.Whole() } - -// WaitsOnPreview says a candidate's module has no fingerprint yet because the indexer wrote it from a pull message alone, -// before it read the head's merge preview (meshcatalogclient.NoneNoPreview): its fingerprint comes with the preview, on the -// same heads, so a candidate that holds one is not yet the candidate of its heads previewed. -func WaitsOnPreview(m meshcatalog.CandidatesByGroupValuePullsItemFpsValue) bool { - return m.None2 == meshcatalogclient.NoneNoPreview -} - -// previewPending says a module of the case's pulls waits on its merge preview (WaitsOnPreview). -func (st *state) previewPending() bool { - for _, p := range st.c.Pulls { - for _, m := range p.Fps { - if WaitsOnPreview(m) { - return true - } - } - } - return false -} - -// takeTryCandidate gives a whole try's pulls the fingerprints and manifests the indexer's candidate of its group holds, -// once the indexer wrote it from the try's previews. A pull request's check has them from its candidate (CaseOf), but the -// indexer writes a pull request's candidate first from its pull message alone and its fingerprints only with the merge -// preview, on the same heads: a check that began on that first write takes the previewed candidate too, before it judges -// the manifests, waits on the builds and composes (ADR 0603 §10; issue 1921: a check otherwise waited on no build and -// the engines, reading the previewed candidate, refused its modules as not yet built). A case with no such candidate is -// said so, in a note and in its composition, and is no pass (Tryer.run). -func (st *state) takeTryCandidate(ctx context.Context) { - if st.c.Try != nil && !st.c.Try.Whole() || st.c.Try == nil && !st.previewPending() { - return - } - no := func(why string) { - what := "the group's manifests and composition were not judged: " - if st.c.Try == nil { - what = "the composition was not judged (the manifests were judged from the indexer's first write): " - } - st.noCandidate = what + why - st.c.note(st.noCandidate) - } - if st.j.Candidates == nil { - no("the checker reads no candidate of the indexer's") - return - } - if len(st.unpreviewed) > 0 { - no("no preview of a merge of " + strings.Join(st.unpreviewed, ", ")) - return - } - if st.c.Wait != nil { - st.c.Wait("the indexer's candidate of the group at its heads (up to " + st.j.buildWait().String() + ")") - defer st.c.Wait("") - } - cand, err := st.j.Candidates.TryCandidate(ctx, st.c.Group, st.c.HeadsHash, st.j.buildWait()) - if err != nil { - no(err.Error()) - return - } - for i, p := range st.c.Pulls { - for _, cp := range cand.Pulls { - if cp.Repository == p.Repository && cp.Head == p.Head { - st.c.Pulls[i].Modules, st.c.Pulls[i].Fps = cp.Modules, cp.Fps - } - } - } - st.c.FPSet = cand.Fpset -} - -// Judge runs the case (it is the Judge of a Checker). A failure of the change, of a merge or of a step is a verdict; an error is only a case that cannot -// be judged at all. -func (j *Examiner) Judge(ctx context.Context, c *Case) (Outcome, error) { - st := &state{j: j, c: c, levels: rules.NewTally(), - beside: map[string]string{}} - // Every member and level runs to its end, and every manifest the change touches is judged by the indexer's judge (ADR - // 0578 §2), also after a failure: the verdict names every failure, not only the first (the operator, 2026-11-02). - // Each failure is a fact recorded where it is met; the verdict is the judging rules' of the facts. - st.judgeAll(ctx) - st.takeTryCandidate(ctx) - st.seriesChanges(ctx) // DLV-C4: a fact of the check, named in the verdict whatever it is - // The heads' seat list, from the checking program, before the validator and the composer are asked (ADR 0636 §4). - // A list it cannot make ends the check there, failed naming the checking program, worded from the facts so far. - var answer rules.Answer - var by *meshdeliverychecker.VerdictsByGroupHeadsValueJudgedBy - if st.seatList(ctx) { - st.judgeManifests(ctx) - st.gatherGraph(ctx) - st.judgeRenames(ctx) - st.refuseUnparsed(ctx) - st.compose(ctx) - // The verdict is the checking program's of the facts (ADR 0644 §1, ADR 0656 §5). - answer, by = st.judged(ctx) - } else { - answer = rules.Answer{V: rules.AnswerVersion, Verdict: rules.Judge(st.factsOf())} - } - for _, n := range answer.Notes { - st.c.note(n) - } - answer.Verdict.JudgedBy = by - out := st.outcome(answer.Verdict) - out.Builds = st.j.buildNotes(ctx, st.c) - return out, nil -} - -// compose records how the check composed as the facts' composition, after every step (ADR 0593 §7, §9): kept by a carry, -// not run (said why), or the engines' answers with the candidate's builds awaited first (ADR 0603 §10). A narrowed try -// and an examiner that composes nothing record none. -func (st *state) compose(ctx context.Context) { - if st.c.Composition != nil && st.c.Try == nil { - // A carry whose candidate's fingerprints did not change keeps the composition it passed (ADR 0548 §5). - kept := *st.c.Composition - st.composition = &rules.Composition{Kept: &kept} - st.c.note("the composition is kept: no fingerprint of a module it composed changed") - return - } - if st.narrowTry() { - return - } - if st.noCandidate != "" { - st.composition = &rules.Composition{NotRun: st.noCandidate} - return - } - if st.j.Compositions == nil { - return - } - if len(st.unpreviewed) > 0 { - // An engine would only say it cannot read a manifest the indexer will not have: the check does not ask it. - st.composition = &rules.Composition{NotRun: "no preview of a merge of " + strings.Join(st.unpreviewed, ", ") + - ", so the change cannot be composed"} - return - } - // ADR 0603 §10: the check composes with the candidate's builds; whether it failed already is the running rules' word - // on the facts so far, an asking choice only (the verdict is the rules' of every fact). - failed := rules.Judge(st.factsOf()).State == meshdeliverycheckerclient.VerdictFail - words, builds, late := st.awaitBuilds(ctx, failed) - c := &rules.Composition{Waits: words, BuildsFailed: builds, FPSet: st.c.FPSet} - st.composition = c - if late != "" { - c.NotRun = late // the builder's lateness, said by name, never the change's refusal (issue 1921) - return - } - comp, err := st.j.Compositions.Compose(ctx, st.c) - if err != nil { - // Said in the verdict, never left as a composition not yet run (review finding 4). - st.j.logf("%s: the composition could not be made, so it is said as not run: %v", st.c.Key, err) - c.NotRun = "not made: " + err.Error() - return - } - c.Composed = &comp -} - -// outcome is the verdict judged from the facts with the slowest tests, the siblings read and what judged a build module. -func (st *state) outcome(v meshdeliverychecker.VerdictsByGroupHeadsValue) Outcome { - slow := rules.Slowest(st.levels) - out := Outcome{Verdict: v, Slowest: slow, OutOfStep: st.outOfStep} - if len(st.beside) > 0 { - out.Beside = st.beside - } - for _, t := range st.targets { - if t.judged != "" { - if out.Judged == nil { - out.Judged = map[string]string{} - } - out.Judged[pullKey(Pull{Repository: t.pull.Repository, Number: t.pull.Number})] = t.judged - } - } - return out -} - -// stepOutOfStep keeps the out-of-step files a step of the pull request named, each once, sorted. -func (st *state) stepOutOfStep(p Pull, files []string) { - if len(files) == 0 { - return - } - if st.outOfStep == nil { - st.outOfStep = map[string][]string{} - } - k := pullKey(Pull{Repository: p.Repository, Number: p.Number}) - all := append(st.outOfStep[k], files...) - slices.Sort(all) - st.outOfStep[k] = slices.Compact(all) -} - -// fail records a failure the asking met as a fact of the check, where it is met, and answers it as a verdict of failure -// at a machine: the verdict is the judging rules' of the facts (rules.Judge), so a failure only returned is no failure -// (milestone 47/B0). -func (st *state) fail(machine, words string) { - st.facts = append(st.facts, rules.Step{Failed: &FailedFirst{Machine: machine, Words: words}}) -} - -// fail is a verdict of failure at a machine, for a step that answers one before any member is asked (tagged); it is -// recorded as facts (failedAll), never returned as the check's verdict. -func fail(machine, words string) *meshdeliverychecker.VerdictsByGroupHeadsValue { - v := failure(machine, words) - return &v -} - -// failedAll records every failure a verdict of the asking names (its list, else its first) as facts of the check. -func (st *state) failedAll(v meshdeliverychecker.VerdictsByGroupHeadsValue) { - all := failedList(v.Failures) - if len(all) == 0 { - all = []FailedFirst{failedOf(v)} - } - for _, f := range all { - st.facts = append(st.facts, rules.Step{Failed: &f}) - } -} - -// factsOf are the check's facts as met: what the checking program judges. -func (st *state) factsOf() rules.Facts { - f := st.factsHead() - f.Steps, f.CloneMS, f.Composition, f.Notes = st.facts, st.clone.Milliseconds(), st.composition, st.c.Notes() - f.Series = st.c.allSeries() - return f -} - -// levels are the levels a case's asks run: both, or the one a try names. -func (st *state) levelsOf() []string { - if st.c.Try != nil && st.c.Try.Level != "" { - return []string{st.c.Try.Level} // a try of one level runs that level alone - } - return []string{buildstep.LevelUnit, buildstep.LevelIntegration} -} - -// judgeAll puts one check ask per pull request and build module the repository needs, the mesh-sdk member first, and -// judges each answer. A head that does not merge, a pin that is not allowed or a level that fails is a failure of that -// member; every other member is still judged, and the verdict names every failure (the operator, 2026-11-02), unjoined -// to its first lines (settled does that). Only a check whose context ended stops. -// -// Every member's asks of the other languages come first and its TypeScript asks after them all: the merges those -// fetches answer say which TypeScript packages the group changes, and each TypeScript fetch is given them all -// (groupPackages; design 47 G A-284, A-285). -func (st *state) judgeAll(ctx context.Context) { - pulls := slices.Clone(st.c.Pulls) - slices.SortStableFunc(pulls, func(a, b Pull) int { - if (a.Repository == SDKRepository) != (b.Repository == SDKRepository) { - if a.Repository == SDKRepository { - return -1 - } - return 1 - } - return 0 - }) - met := len(st.facts) - stopped := func() bool { - if ctx.Err() == nil { - return false - } - if !st.failedSince(met) { // an ask that ended with the context said it already - st.fail(st.j.Module, ctx.Err().Error()) - } - return true - } - merged := make([][]Fetched, len(pulls)) - modules := make([][]string, len(pulls)) - for i, p := range pulls { - modules[i] = st.j.Modules.BuildModules(p.Repository) - } - // Each phase puts every ask of its own at once and then waits for them all (design 47 G A-304, ADR 0525 §4): its - // asks are judged in the order they were put, whatever order they end in. - phase := func(typeScript bool, group []buildstep.FetchPackage) bool { - var asked []*asking - for i, p := range pulls { - for _, bm := range modules[i] { - if (st.j.languageOf(bm) == languageTypeScript) != typeScript { - continue - } - if stopped() { - return false - } - if t := st.memberTarget(ctx, p, bm, group); t != nil { - if q := st.prepareAsk(ctx, t, &merged[i], st.levelsOf(), nil, nil); q != nil && st.putAsk(ctx, q) { - asked = append(asked, q) - } - } - } - } - for _, q := range asked { - go q.wait(ctx, st) - } - for n, q := range asked { - if n > 0 && stopped() { - return false - } - <-q.done - st.judgeAsk(ctx, q) - } - return true - } - if !phase(false, nil) { - return - } - var group []buildstep.FetchPackage - if len(st.c.Pulls) > 1 { - group = st.groupPackages(pulls, merged) - } - if !phase(true, group) { - return - } - for i, p := range pulls { - // Every build module's fetch merged (each is in merged once): the preview is written, also when the member's tests - // or a later step failed, so the indexer holds its manifests and the assigner can compose the change (review of - // 650a1d0; design 47 G A-286). - switch { - case st.narrowTry(): // a try of a level or some tests owes the indexer no preview: it judges no manifest - case len(merged[i]) == len(modules[i]): - st.j.writePreview(ctx, p, merged[i]) - case st.conflicted[pullKey(p)]: - st.unpreviewed = append(st.unpreviewed, pullKey(p)+" (its head does not merge)") - default: - st.unpreviewed = append(st.unpreviewed, pullKey(p)+" (its fetch did not answer)") - } - st.judgedByMember(p, merged[i]) - } -} - -// memberTarget is the target of the check ask of one build module of a member, nil when it cannot be asked (said as a -// failure); a TypeScript fetch is given the group's packages. -func (st *state) memberTarget(ctx context.Context, p Pull, bm string, group []buildstep.FetchPackage) *target { - t := &target{pull: p, module: bm, language: st.j.languageOf(bm)} - if tc, none := buildstep.AgreedToolchain(st.j.Toolchains.Entries(t.language)); none == "" { - t.toolchain = tc.Version - t.agreed = &buildstep.ToolchainUsed{Language: t.language, Version: tc.Version, Recipe: tc.Recipe} - } - args := buildstep.Fetch{Repository: p.Repository, Commit: p.Head, Ref: refOf(p.Number), Base: p.Trunk} - if t.language == languageTypeScript { - args.GroupPackages = group - } - if t.language == languageGo { - beside, err := st.j.besideFor(ctx, st.c, p) - if err != nil { - st.fail(forgeMachine(err, bm), err.Error()+unheardWords(err)) - return nil - } - if len(beside) > 0 { - args.Beside = fetchBeside(beside) - t.beside = besideLines(beside) - besideAtTrunk(st.c, beside, st.beside) - } - if p.Repository == catalogueRepository { - t.runner = RunnerWorkspace // used by the build module when the merge changes it (ADR 0535 §1) - } - } - t.fetchArgs = args - st.targets = append(st.targets, t) - return t -} - -// groupPackages are the TypeScript packages the group's merges change (design 47 G A-284, A-285): every package of a -// member whose named paths a merge of that member changes, each at the member's head with its directory there, in the -// order of the members and then of the directories. A change of the manifest alone, or of files outside those paths, -// changes no package (ADR 0500 §5). -func (st *state) groupPackages(pulls []Pull, merged [][]Fetched) []buildstep.FetchPackage { - if st.j.Packages == nil { - return nil - } - var out []buildstep.FetchPackage - for i, p := range pulls { - for _, pkg := range st.j.Packages.TypeScriptPackages(p.Repository) { - if changesPaths(pkg.Paths, merged[i]) { - out = append(out, buildstep.FetchPackage{Repository: p.Repository, Commit: p.Head, Ref: refOf(p.Number), Path: pkg.Dir}) - } - } - } - return out -} - -// failedSince says a failure was recorded among the facts from the nth on. -func (st *state) failedSince(n int) bool { - for _, f := range st.facts[n:] { - if f.Failed != nil { - return true - } - } - return false -} - -// DefaultDeclineBound is an Examiner's DeclineBound when it names none: longer than a check runs, so a node with the -// need that is busy is waited for, and short enough that a mesh where no node has it says so. -const DefaultDeclineBound = 30 * time.Minute - -// askNeeding puts the target's check ask, waits for it and judges its answer, with the levels to run, what the node must have and the packages it tests: none for the first ask -// of a target; for the placed one the unmet packages' needs and those packages alone, so no package the first ask judged -// is run or counted again (ADR 0552 §4). -func (st *state) askNeeding(ctx context.Context, t *target, merged *[]Fetched, levels, needs, packages []string) { - q := st.prepareAsk(ctx, t, merged, levels, needs, packages) - if q == nil || !st.putAsk(ctx, q) { - return - } - q.wait(ctx, st) - st.judgeAsk(ctx, q) -} - -// asking is one check ask put and waited for: its target, the merges its fetch adds to, the ask as put last (a declined -// one is put again under a new id) and, once done is closed, the step it ended with or why it has none. -type asking struct { - t *target - merged *[]Fetched - a buildstep.StepAsk - kind string - needs []string - placed bool - step buildstep.Step - failed bool // the ask ended with no step to judge: failOn and failWords say why - failOn string - failWords string - done chan struct{} -} - -// prepareAsk makes the target's ask with the levels to run, what the node must have and the packages it tests; nil when -// it cannot be asked (said as a failure). -func (st *state) prepareAsk(ctx context.Context, t *target, merged *[]Fetched, levels, needs, packages []string) *asking { - p := t.pull - job := &buildstep.CheckJob{Fetch: t.fetchArgs, Levels: levels, Kept: true, Packages: packages, Toolchain: t.agreed} - if st.j.Nodes != nil { - names, err := st.j.Nodes.Names(ctx) - if err == nil && len(names) == 0 { - err = fmt.Errorf("no node record is on the bus") - } - if err != nil { - st.fail(t.module, fmt.Sprintf("the check of %s#%d is not asked: the nodes' names the names check needs cannot be read: %v", p.Repository, p.Number, err)) - return nil - } - job.NodeNames = names - } - if t.runner != "" { - job.Runner, job.RunnerWhen = t.runner, buildGoDir(st.goModule()) - } - if st.c.Try != nil && st.c.Try.Run != "" { - job.Run, job.Kept = st.c.Try.Run, false // a try of some tests runs them alone: a partial run proves no package - } - kind := buildstep.AskCheck - if st.c.Kind == KindTrunk { - kind = buildstep.AskRecheck // a re-judge after a trunk move goes after every new head's check (ADR 0536 §4) - } - a := buildstep.StepAsk{ID: buildstep.NewID(), Kind: kind, Language: st.j.askLanguageOf(t.module), Asker: st.j.Module, - At: st.j.now().UTC(), Check: job, Needs: needs} - if a.Language == buildstep.AskGo { - a.Packages = st.packagesOf(p.Repository) - } - return &asking{t: t, merged: merged, a: a, kind: kind, needs: needs, placed: len(needs) > 0, done: make(chan struct{})} -} - -// putAsk puts the ask on its build seat's stream; false when it could not be put (said as a failure). -func (st *state) putAsk(ctx context.Context, q *asking) bool { - if err := st.put(ctx, q); err != nil { - st.fail(q.t.module, fmt.Sprintf("the check of %s#%d could not be asked: %v", q.t.pull.Repository, q.t.pull.Number, err)) - return false - } - return true -} - -// put puts the ask as it stands now. It touches only what is safe from a waiting goroutine: the progress, the case's -// ask ids and its watch. -func (st *state) put(ctx context.Context, q *asking) error { - p := q.t.pull - what := fmt.Sprintf("the %s ask %s of %s#%d", q.kind, q.a.ID, p.Repository, p.Number) - if q.placed { - what += " for a node with " + strings.Join(q.needs, ", ") - } - st.c.Progress.Set(what, "") - st.c.Asked(q.a.ID) - if err := st.j.Asks.Put(ctx, q.a); err != nil { - return err - } - if watch := st.c.Watch; watch != nil { - watch(q.a.ID, nil) // put: a try names it at once, not only when it ends (issue 1890) - } - return nil -} - -// wait waits for the step of the node that pulled the ask, putting a declined ask again for a node that has its need, -// and closes done. It runs on its own goroutine beside the phase's other asks, so it changes nothing of the check but -// the asking itself (the facts and failures are the judging's, in order). -func (q *asking) wait(ctx context.Context, st *state) { - defer close(q.done) - p := q.t.pull - var firstDecline time.Time - for { - waiting := ctx - if watch := st.c.Watch; watch != nil { - id := q.a.ID - waiting = buildrun.WithStepSeen(ctx, func(s buildstep.Step) { watch(id, &s) }) - } - step, err := st.j.Asks.Wait(waiting, q.a) - if err != nil { - q.failed, q.failOn = true, q.t.module - if ctx.Err() != nil { - q.failWords = ctx.Err().Error() - } else { - q.failWords = fmt.Sprintf("the check of %s#%d: %v", p.Repository, p.Number, err) - } - return - } - q.step = step - d, declined := buildstep.DeclinedOf(step) - if !declined { - return - } - // A node that lacks the need dropped the ask (issue 890): it is put again, for a node that has it to take; the - // node that declined looks at the stream again only after its next pull's wait. - now := st.j.now() - if firstDecline.IsZero() { - firstDecline = now - } - bound := st.j.DeclineBound - if bound <= 0 { - bound = DefaultDeclineBound - } - if now.Sub(firstDecline) > bound { - lacks := strings.Join(q.needs, ", ") - if lacks == "" { - lacks = strings.Join(d.Lacks, ", ") // a node off the agreed toolchain declined it (ADR 0584) - } - q.failed, q.failOn = true, step.Node - q.failWords = fmt.Sprintf("the check of %s#%d needs a node with %s, and none took it in %s: every node that pulled it lacks it (last %s)", - p.Repository, p.Number, lacks, bound, step.Node) - return - } - st.j.logf("%s#%d: the ask %s was declined on %s, which lacks %s; asked again", p.Repository, p.Number, q.a.ID, step.Node, strings.Join(d.Lacks, ", ")) - q.a.ID, q.a.At = buildstep.NewID(), now.UTC() - if err := st.put(ctx, q); err != nil { - q.failed, q.failOn = true, q.t.module - q.failWords = fmt.Sprintf("the check of %s#%d could not be asked: %v", p.Repository, p.Number, err) - return - } - } -} - -// judgeAsk judges the step an ask ended with: the fetch, then each level's digest, kept verdicts and tests. When the -// answer leaves packages unmet, their tests needing what that node lacks (issue 890), the passes are kept and the levels -// from the first such one are asked again of a node that has it (placed). -func (st *state) judgeAsk(ctx context.Context, q *asking) { - if q.failed { - st.fail(q.failOn, q.failWords) - return - } - t, merged, needs, placed, step := q.t, q.merged, q.needs, q.placed, q.step - p := t.pull - // The fetch and the digests are what of the ask's time its levels' running did not take (Took.Clone). - took := time.Duration(0) - if !step.Started.IsZero() && step.Ended.After(step.Started) { - took = step.Ended.Sub(step.Started) - } - t.node = step.Node - st.facts = append(st.facts, rules.Step{Repository: p.Repository, Number: p.Number, Module: t.module, Node: step.Node}) - st.c.Progress.Set(fmt.Sprintf("judge the check of %s#%d", p.Repository, p.Number), step.Node) - if step.State != buildstep.StepPassed { - // A step that failed after its fetch merged answers the fetch beside its error (design 47 G A-286): the merge is - // previewed from it, so its manifests are judged and the change composed whatever the step ended with. - var failed buildstep.CheckAnswer - if !placed && json.Unmarshal(step.Result, &failed) == nil && failed.Fetch.Workspace != "" && len(failed.Fetch.Conflicts) == 0 { - t.fetched, t.changed = failed.Fetch, failed.Fetch.Changed - *merged = append(*merged, t.fetched) - st.checkBinariesOf(t) - } - st.fail(step.Node, fmt.Sprintf("the check of %s#%d %s: %s", p.Repository, p.Number, step.State, step.Reason)) - return - } - var answer buildstep.CheckAnswer - if err := json.Unmarshal(step.Result, &answer); err != nil { - st.fail(step.Node, fmt.Sprintf("the check of %s#%d answered what is not a check: %s", p.Repository, p.Number, step.Result)) - return - } - if t.fetched = answer.Fetch; t.fetched.Workspace == "" { - st.fail(step.Node, fmt.Sprintf("the fetch of %s#%d answered no workspace: %s", p.Repository, p.Number, step.Result)) - return - } - if len(t.fetched.Conflicts) > 0 { - if st.conflicted == nil { - st.conflicted = map[string]bool{} - } - st.conflicted[pullKey(p)] = true - if !st.narrowTry() { - st.j.writePreview(ctx, p, append(*merged, t.fetched)) - } - st.fail(step.Node, fmt.Sprintf("%s#%d %s%s", p.Repository, p.Number, ConflictWords, strings.Join(t.fetched.Conflicts, ", "))) - return - } - t.changed = t.fetched.Changed - if !changesBuildGo(p.Repository, st.goModule(), t.changed) { - t.runner = "" // the build module used no runner: the merge does not change it - } - if !placed { // the placed ask fetched the same merge: its preview was read from the first - *merged = append(*merged, t.fetched) - st.checkBinariesOf(t) // the levels still run: the verdict names every failure - } - ran := 0.0 - for _, la := range answer.Levels { - if placed { - if len(la.Unmet) > 0 { - st.clone += max(0, took-time.Duration(ran*float64(time.Second))) - st.fail(step.Node, fmt.Sprintf("the %s level of %s#%d left %s untested on %s, which was asked for a node with %s", - la.Level, p.Repository, p.Number, unmetNames(la.Unmet), step.Node, strings.Join(needs, ", "))) - return - } - la.Kept = nil // it names its packages and takes no other's kept verdict; this is only a guard against an older module - } - ran += st.level(ctx, t, la) // the next level was run too (buildstep): its failures are named as well - } - st.clone += max(0, took-time.Duration(ran*float64(time.Second))) - if unmet := buildstep.UnmetNeeds(answer.Levels); len(unmet) > 0 && !placed { - // Every level ran, its passes kept, and some packages were left to a node with what their tests need: the levels - // from the first that left one are asked of such a node, which takes the kept passes and tests those (issue 890). - var again, packages []string - seen := map[string]bool{} - for _, la := range answer.Levels { - if len(again) > 0 || len(la.Unmet) > 0 { - again = append(again, la.Level) - } - for _, u := range la.Unmet { - if !seen[u.Package] { - seen[u.Package] = true - packages = append(packages, u.Package) - } - } - } - st.j.logf("%s#%d: %s on %s left untested; asked of a node with %s", p.Repository, p.Number, unmetOf(answer.Levels), step.Node, strings.Join(unmet, ", ")) - st.askNeeding(ctx, t, merged, again, unmet, packages) - } -} - -// unmetNames names the unmet packages and their needs. -func unmetNames(unmet []buildstep.PackageNeeds) string { - var out []string - for _, u := range unmet { - out = append(out, u.Package+" (needs "+strings.Join(u.Needs, ", ")+")") - } - return strings.Join(out, ", ") -} - -// unmetOf names the unmet packages of every level. -func unmetOf(levels []buildstep.LevelAnswer) string { - var out []string - for _, la := range levels { - if len(la.Unmet) > 0 { - out = append(out, "at "+la.Level+" "+unmetNames(la.Unmet)) - } - } - return strings.Join(out, "; ") -} - -// level judges one level of a check ask's answer as the tools' answers were judged: the digest keys the kept verdicts -// of the packages that passed, the kept ones taken are counted, and every test result is read and counted, also after -// one that did not pass, so the verdict names every failed test of the level (issue 1921). It answers the level's -// running time (its tests' and setup's). -func (st *state) level(ctx context.Context, t *target, la buildstep.LevelAnswer) float64 { - if t.runner != "" && t.language == languageGo && la.Digest != nil { - t.judgedBy(la.Digest.JudgedBy) // the installed module judged it: the runner is not used again - } - if t.runner != "" && la.Judged != "" { - t.judgedBy(la.Judged) // the candidate judged the level: nothing is kept (ADR 0535 §4) - } - _, elapsed, results := st.levels.Level(t.pull.Repository, t.pull.Number, t.module, t.language, t.node, la) - st.facts = append(st.facts, rules.Step{Repository: t.pull.Repository, Number: t.pull.Number, Module: t.module, Language: t.language, Node: t.node, Level: rules.LevelFact(la)}) - var digests map[string]string - if t.language == languageGo && la.Digest != nil { - // The packages come as a list, never keyed by a package path (issue 1930); an answer stored before reads too. - digests = la.Digest.Map() - } - for _, res := range results { - if t.runner != "" { - t.judgedBy(res.JudgedBy) - } - st.stepOutOfStep(t.pull, res.OutOfStep) - if len(digests) > 0 { - if _, err := st.j.Kept.KeepPasses(ctx, t.pull.Repository, la.Level, t.toolchain, res, digests, st.j.now()); err != nil { - st.j.logf("%s#%d: a passing package could not be kept: %v", t.pull.Repository, t.pull.Number, err) - } - } - } - return elapsed -} - -// changesPaths says whether a merge changes a file inside one of the named paths (repository-relative). -func changesPaths(paths []string, merged []Fetched) bool { - for _, f := range merged { - for _, changed := range f.Changed { - for _, named := range paths { - named = strings.TrimSuffix(strings.TrimPrefix(named, "./"), "/") - if changed == named || strings.HasPrefix(changed, named+"/") { - return true - } - } - } - } - return false -} diff --git a/modules/mesh-delivery-checker/internal/check/judged_test.go b/modules/mesh-delivery-checker/internal/check/judged_test.go deleted file mode 100644 index 080e20c2..00000000 --- a/modules/mesh-delivery-checker/internal/check/judged_test.go +++ /dev/null @@ -1,208 +0,0 @@ -package check - -import ( - "context" - "strings" - "testing" - - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshdeliverycheckerclient" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep" -) - -// The judged_by answer of mesh-build-go's digest and test steps (ADR 0535 §5; the milestone file's interface for issue -// 1898): "installed" for a step its installed program ran, "candidate " for one the candidate's program ran -// under runner workspace; an installed module older than the runner names nothing (it ignores the unknown argument: the -// SDK's tool server checks no argument against the input schema). - -const buildGoFile = "modules/mesh-build-go/cmd/mesh-build-go/digest.go" - -// candidateBench is a bench whose fetch changes the Go build module's directory, and whose build module runs the candidate -// when asked to (a module with the runner) or ignores the runner (one without). -func candidateBench(t *testing.T, takesRunner bool) *bench { - b := newBench(t) - b.fetch.Changed = []string{"README.md", buildGoFile} - judged := func(c stepCall) string { - if !takesRunner { - return "" - } - if c.args["runner"] == RunnerWorkspace { - return "candidate " + b.fetch.Merge - } - return "installed" - } - b.steps.handlers["build_go_digest"] = func(c stepCall) (any, error) { - d := echoBeside(b, b.digest[c.args["level"].(string)]) - d.JudgedBy = judged(c) - return d, nil - } - b.test = func(c stepCall) (any, error) { - r := captured[Tested](t, "go-test-slow") - r.Level, _ = c.args["level"].(string) - r.JudgedBy = judged(c) - return r, nil - } - return b -} - -func TestAMergeChangingTheGoBuildModuleIsAskedWithTheCandidateRunner(t *testing.T) { // 1898/AC1 - b := candidateBench(t, true) - b.judge(t, caseOf(t, pullOf(catalogueRepository, 9, head1))) - asked := append(b.steps.tool("digest"), b.steps.tool("test")...) - if len(asked) < 3 { - t.Fatalf("asked %+v, want the digest and both levels", asked) - } - for _, c := range asked { - if c.args["runner"] != RunnerWorkspace { - t.Errorf("%s %v was asked with runner %v, want %s", c.tool, c.args["level"], c.args["runner"], RunnerWorkspace) - } - } -} - -func TestAMergeNotChangingTheGoBuildModuleIsAskedWithoutARunner(t *testing.T) { // 1898/AC1 - for _, tc := range []struct { - name, repo, path string - }{ - {"another module of the catalogue", catalogueRepository, "modules/mesh-build-node/cmd/mesh-build-node/main.go"}, - {"a look-alike path in another repository", repoA, buildGoFile}, - } { - t.Run(tc.name, func(t *testing.T) { - b := candidateBench(t, true) - b.fetch.Changed = []string{tc.path} - out := b.judge(t, caseOf(t, pullOf(tc.repo, 9, head1))) - for _, c := range append(b.steps.tool("digest"), b.steps.tool("test")...) { - if _, ok := c.args["runner"]; ok { - t.Errorf("%s was asked with runner %v", c.tool, c.args["runner"]) - } - } - if len(out.Judged) != 0 { - t.Errorf("judged = %v, want nothing said of the program", out.Judged) - } - }) - } -} - -func TestAnInstalledModuleWithoutTheRunnerJudgesAsTodayAndTheLineSaysSo(t *testing.T) { // 1898/AC2 - b := candidateBench(t, false) - cs := caseOf(t, pullOf(catalogueRepository, 9, head1)) - out := b.judge(t, cs) - if out.Verdict.State != meshdeliverycheckerclient.VerdictPass { - t.Fatalf("verdict = %+v", out.Verdict) - } - // As today: the digests key kept verdicts, and the levels are asked without the runner the module ignored. - for _, c := range b.steps.tool("test") { - if _, ok := c.args["runner"]; ok { - t.Errorf("the %v level was asked again with the runner the module does not take", c.args["level"]) - } - } - if keys, _ := b.kept.Keys(context.Background()); len(keys) != 2 { - t.Errorf("kept %v, want the passing package at both levels, as today", keys) - } - p := cs.Pulls[0] - want := "judged by the installed mesh-build-go: it does not run a candidate yet" - if got := out.Judged[pullKey(p)]; got != want { - t.Fatalf("judged = %q, want %q", got, want) - } - if l := Line(out.Verdict, cs, p, out.Builds, out.Slowest, out.Judged); !strings.Contains(l, want) { - t.Errorf("line %q does not say %q", l, want) - } -} - -func TestACandidateJudgedCheckTakesNoKeptVerdictAndWritesNone(t *testing.T) { // 1898/AC3 - b := candidateBench(t, true) - if _, err := (Kept{Store: b.kept}).Keep(context.Background(), "unit", digA, keptValue("fixture/slow", 2)); err != nil { - t.Fatal(err) - } - out := b.judge(t, caseOf(t, pullOf(catalogueRepository, 9, head1))) - if out.Verdict.State != meshdeliverycheckerclient.VerdictPass { - t.Fatalf("verdict = %+v", out.Verdict) - } - tests := b.steps.tool("test") - if len(tests) != 2 { - t.Fatalf("test calls = %+v, want both levels", tests) - } - for _, c := range tests { - if _, ok := c.args["packages"]; ok { - t.Errorf("the %v level was asked for %v, want it whole", c.args["level"], c.args["packages"]) - } - } - if u := out.Verdict.Levels[buildstep.LevelUnit]; u.Kept != 0 { - t.Errorf("unit = %+v, want nothing taken", u) - } - if keys, _ := b.kept.Keys(context.Background()); len(keys) != 1 || keys[0] != "unit."+digA { - t.Errorf("kept keys = %v, want only the one kept before", keys) - } -} - -func TestTheLineNamesTheCandidateThatJudged(t *testing.T) { // 1898/AC6 - b := candidateBench(t, true) - cs := caseOf(t, pullOf(catalogueRepository, 9, head1)) - out := b.judge(t, cs) - p := cs.Pulls[0] - want := "judged by the candidate's mesh-build-go at " + b.fetch.Merge[:12] - for name, l := range map[string]string{ - "line": Line(out.Verdict, cs, p, out.Builds, out.Slowest, out.Judged), - "report": Report(out.Verdict, cs, p, out.Builds, out.Slowest, out.Judged), - } { - if !strings.Contains(l, want) { - t.Errorf("the %s %q does not say %q", name, l, want) - } - } - // A long failing line keeps the program it was judged by; only the lesser parts go. - v := out.Verdict - v.State = meshdeliverycheckerclient.VerdictFail - v.Failed = &FailedFirst{Test: "unit: git.novox.be/novox/mesh-catalog/modules/mesh-build-go/cmd/mesh-build-go.TestADigestFoldsTheSiblings", Words: strings.Repeat("x", 60)} - if l := Line(v, cs, p, out.Builds, out.Slowest, out.Judged); !strings.Contains(l, "judged by the candidate's") { - t.Errorf("the long line %q dropped the program", l) - } -} - -func TestInAGroupOnlyTheBuildModulesPullRequestNamesItsProgram(t *testing.T) { // 1898/AC6 - b := candidateBench(t, true) - cs := caseOf(t, pullOf(catalogueRepository, 9, head1), pullOf(repoA, 7, head1)) - out := b.judge(t, cs) - for _, p := range cs.Pulls { - l := Report(out.Verdict, cs, p, out.Builds, out.Slowest, out.Judged) - says := strings.Contains(l, "judged by") - if says != (p.Repository == catalogueRepository) { - t.Errorf("%s#%d: %q", p.Repository, p.Number, l) - } - } -} - -func TestACandidateThatDoesNotCompileFailsTheCheckWithTheCompilersWords(t *testing.T) { // ADR 0535 §3, checker side - b := candidateBench(t, true) - refusal := "the candidate's mesh-build-go does not compile: modules/mesh-build-go/cmd/mesh-build-go/digest.go:12:2: undefined: x" - b.steps.handlers["build_go_digest"] = func(stepCall) (any, error) { return nil, errorString(refusal) } - b.test = func(stepCall) (any, error) { return nil, errorString(refusal) } - out := b.judge(t, caseOf(t, pullOf(catalogueRepository, 9, head1))) - if out.Verdict.State != meshdeliverycheckerclient.VerdictFail || !strings.Contains(out.Verdict.Failed.Words, "undefined: x") { - t.Fatalf("verdict = %+v, want a failure naming the compile error", out.Verdict) - } - if n := len(b.steps.tool("test")); n != 1 { - t.Errorf("%d test steps, want the first one's failure to end the check", n) - } -} - -type errorString string - -func (e errorString) Error() string { return string(e) } - -func TestTheStatusTheForgeShowsNamesTheProgramThatJudged(t *testing.T) { // 1898/AC6, the forge's line - ctx := context.Background() - words := judgedByCandidate(goBuildModule) + "fedcba987654" - j := &judgeFunc{f: func(context.Context, *Case, int) (Outcome, error) { - return Outcome{Verdict: passing(), Judged: map[string]string{repoA + "#7": words}}, nil - }} - r := newRig(t, j) - r.ch.Candidate(ctx, "feat/x", candidateOf(t, "feat/x", pullOf(repoA, 7, head1))) - r.ch.Wait() - key, _ := CheckerOwedKey(repoA, 7, head1) - raw, _, _, _ := r.owed.Get(ctx, key) - o, err := DecodeCheckerOwed(raw) - if err != nil { - t.Fatal(err) - } - if o.State != "success" || !strings.Contains(o.Text, words) { - t.Errorf("status %+v, want success saying %q", o, words) - } -} diff --git a/modules/mesh-delivery-checker/internal/check/kept.go b/modules/mesh-delivery-checker/internal/check/kept.go deleted file mode 100644 index e00b5b2f..00000000 --- a/modules/mesh-delivery-checker/internal/check/kept.go +++ /dev/null @@ -1,101 +0,0 @@ -package check - -import ( - "context" - "errors" - "fmt" - "sort" - "time" - - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshdeliverycheckerclient" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshdeliverychecker" -) - -// Kept is the checker's bucket of kept verdicts (ADR 0444, ADR 0484 clause 13): a passing verdict per package and level, -// under the digest the language's build module named for it. A key is written once, by a create that fails when it -// exists, from the result the checker read from the test step and never from anything the code under test wrote; nothing -// changes it afterwards. -type Kept struct{ Store KV } - -// Lookup is the kept verdict of a level under a digest, or none. -func (k Kept) Lookup(ctx context.Context, level, digest string) (meshdeliverychecker.KeptByLevelDigestValue, bool, error) { - key, err := meshdeliverycheckerclient.KeptKey(level, digest) - if err != nil { - return meshdeliverychecker.KeptByLevelDigestValue{}, false, err - } - value, _, found, err := k.Store.Get(ctx, key) - if err != nil || !found { - return meshdeliverychecker.KeptByLevelDigestValue{}, false, err - } - v, err := meshdeliverycheckerclient.DecodeKept(value) - if err != nil { - return meshdeliverychecker.KeptByLevelDigestValue{}, false, fmt.Errorf("%s holds what is not a kept verdict: %w", key, err) - } - return v, true, nil -} - -// Keep writes v under level and digest by a create. It answers false, and writes nothing, when the key exists: the first -// value stands. -func (k Kept) Keep(ctx context.Context, level, digest string, v meshdeliverychecker.KeptByLevelDigestValue) (bool, error) { - key, err := meshdeliverycheckerclient.KeptKey(level, digest) - if err != nil { - return false, err - } - v.Level = level - data, err := meshdeliverycheckerclient.EncodeKept(v) - if err != nil { - return false, err - } - if _, err := k.Store.Create(ctx, key, data); err != nil { - if errors.Is(err, ErrConflict) { - return false, nil - } - return false, fmt.Errorf("%s: %w", key, err) - } - return true, nil -} - -// KeepPasses keeps, for the packages of a test result that passed with tests, a verdict under the digest the build module -// named for the package at the level. A package that failed, has no tests or has no digest is never kept (ADR 0444 clause -// 1): it runs every check. A package with skipped tests is not kept either: a pass that skipped (a test needing a -// toolchain the node lacks) would be reused for its digest and never run anywhere (issue 890). A build module that -// counts skips only per result, not per package, keeps nothing of a result in which a test skipped. It answers the -// packages it kept now. -func (k Kept) KeepPasses(ctx context.Context, repository, level, toolchain string, res Tested, digests map[string]string, at time.Time) ([]string, error) { - var kept []string - perPackage := false - for _, p := range res.Packages { - perPackage = perPackage || p.Skipped > 0 - } - if res.Skipped > 0 && !perPackage { - return kept, nil // an older build module: the skip cannot be placed in a package - } - for _, p := range res.Packages { - digest, ok := digests[p.Package] - if !ok || !p.Passed || p.NoTests || p.Tests == 0 || p.Skipped > 0 { - continue - } - if failedIn(res, p.Package) { - continue - } - made, err := k.Keep(ctx, level, digest, meshdeliverychecker.KeptByLevelDigestValue{State: meshdeliverycheckerclient.VerdictPass, Repository: repository, Package: p.Package, - Level: level, Tests: int64(p.Tests), Took: int64(p.Elapsed * 1000), Toolchain: toolchain, At: at.UTC().Format(time.RFC3339)}) - if err != nil { - return kept, err - } - if made { - kept = append(kept, p.Package) - } - } - sort.Strings(kept) - return kept, nil -} - -func failedIn(res Tested, pkg string) bool { - for _, f := range res.Failed { - if f.Package == pkg { - return true - } - } - return false -} diff --git a/modules/mesh-delivery-checker/internal/check/kept_test.go b/modules/mesh-delivery-checker/internal/check/kept_test.go deleted file mode 100644 index f6a7abd5..00000000 --- a/modules/mesh-delivery-checker/internal/check/kept_test.go +++ /dev/null @@ -1,130 +0,0 @@ -package check - -import ( - "context" - "strings" - "testing" - "time" - - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshdeliverycheckerclient" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshdeliverychecker" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep" -) - -var at0 = time.Date(2026, 10, 21, 19, 0, 0, 0, time.UTC) - -const ( - digA = "aa11aa11aa11aa11aa11aa11aa11aa11aa11aa11aa11aa11aa11aa11aa11aa11" - digB = "bb22bb22bb22bb22bb22bb22bb22bb22bb22bb22bb22bb22bb22bb22bb22bb22" -) - -func keptValue(pkg string, tests int) meshdeliverychecker.KeptByLevelDigestValue { - return meshdeliverychecker.KeptByLevelDigestValue{State: meshdeliverycheckerclient.VerdictPass, Repository: "novox/mesh-delivery", Package: pkg, Tests: int64(tests), Took: 120, Toolchain: "go1.26.0", At: at0.UTC().Format(time.RFC3339)} -} - -func TestAPassIsKeptByACreateUnderItsLevelAndDigest(t *testing.T) { // 1287/AC1 - ctx, st := context.Background(), newMemKV() - k := Kept{Store: st} - made, err := k.Keep(ctx, buildstep.LevelUnit, digA, keptValue("m/a", 3)) - if err != nil || !made { - t.Fatalf("Keep = %v, %v, want made", made, err) - } - key, _ := meshdeliverycheckerclient.KeptKey(buildstep.LevelUnit, digA) - if st.creates[key] != 1 { - t.Fatalf("the key %s was created %d times, want once", key, st.creates[key]) - } - got, found, err := k.Lookup(ctx, buildstep.LevelUnit, digA) - if err != nil || !found || got.Package != "m/a" || got.Tests != 3 || got.Level != buildstep.LevelUnit || got.Toolchain != "go1.26.0" { - t.Fatalf("Lookup = %+v, %v, %v", got, found, err) - } -} - -func TestASecondKeepUnderTheSameDigestIsRefusedAndTheFirstStands(t *testing.T) { // 1287/AC2 - ctx, st := context.Background(), newMemKV() - k := Kept{Store: st} - if made, err := k.Keep(ctx, buildstep.LevelUnit, digA, keptValue("m/a", 3)); err != nil || !made { - t.Fatal(made, err) - } - made, err := k.Keep(ctx, buildstep.LevelUnit, digA, keptValue("m/other", 9)) - if err != nil || made { - t.Fatalf("the second Keep = %v, %v, want refused without an error", made, err) - } - got, _, _ := k.Lookup(ctx, buildstep.LevelUnit, digA) - if got.Package != "m/a" || got.Tests != 3 { - t.Errorf("the first value did not stand: %+v", got) - } -} - -func TestOnlyPassingPackagesWithADigestAreKept(t *testing.T) { // 1287/AC3, AC4 - ctx, st := context.Background(), newMemKV() - k := Kept{Store: st} - res := Tested{Level: "unit", Passed: false, Packages: []GoPackage{ - {Package: "m/a", Passed: true, Tests: 4, Elapsed: 0.2}, - {Package: "m/b", Passed: false, Tests: 2}, - {Package: "m/c", Passed: true, Tests: 1}, // no digest named - {Package: "m/d", Passed: true, NoTests: true}, // no tests - }, Failed: []Failure{{Package: "m/b", Test: "TestB"}}} - kept, err := k.KeepPasses(ctx, "novox/mesh-delivery", "unit", "go1.26.0", res, map[string]string{"m/a": digA, "m/b": digB, "m/d": digB}, at0) - if err != nil { - t.Fatal(err) - } - if strings.Join(kept, ",") != "m/a" { - t.Fatalf("kept %v, want only m/a", kept) - } - if keys, _ := st.Keys(ctx); len(keys) != 1 { - t.Errorf("the bucket holds %v, want one key", keys) - } -} - -func TestAResultWithSkippedTestsKeepsNothing(t *testing.T) { // issue 890: a pass that skipped proved nothing - ctx, st := context.Background(), newMemKV() - k := Kept{Store: st} - res := Tested{Level: "integration", Passed: true, Skipped: 2, Packages: []GoPackage{{Package: "m/a", Passed: true, Tests: 4}}} - kept, err := k.KeepPasses(ctx, "novox/mesh-catalog", "integration", "go1.26.0", res, map[string]string{"m/a": digA}, at0) - if err != nil || len(kept) != 0 { - t.Fatalf("kept %v, %v, want nothing", kept, err) - } - if keys, _ := st.Keys(ctx); len(keys) != 0 { - t.Errorf("the bucket holds %v, want none", keys) - } -} - -func TestOnlyTheSkippingPackageOfAResultIsWithheld(t *testing.T) { // issue 890 - ctx, st := context.Background(), newMemKV() - k := Kept{Store: st} - res := Tested{Level: "integration", Passed: true, Skipped: 2, Packages: []GoPackage{ - {Package: "m/a", Passed: true, Tests: 4, Skipped: 2}, - {Package: "m/b", Passed: true, Tests: 3}, - }} - kept, err := k.KeepPasses(ctx, "novox/mesh-catalog", "integration", "go1.26.0", res, map[string]string{"m/a": digA, "m/b": digB}, at0) - if err != nil || strings.Join(kept, ",") != "m/b" { - t.Fatalf("kept %v, %v, want only m/b", kept, err) - } -} - -func TestAKeptValueOfAnotherDigestIsNotRead(t *testing.T) { // 1287/AC7 - ctx, st := context.Background(), newMemKV() - k := Kept{Store: st} - if _, err := k.Keep(ctx, buildstep.LevelUnit, digA, keptValue("m/a", 3)); err != nil { - t.Fatal(err) - } - // A toolchain change changes the digest, so the new digest finds nothing and the old key is not deleted. - if _, found, _ := k.Lookup(ctx, buildstep.LevelUnit, digB); found { - t.Error("a digest that was not kept was found") - } - if _, found, _ := k.Lookup(ctx, buildstep.LevelIntegration, digA); found { - t.Error("a kept unit verdict was found at the integration level") - } - if keys, _ := st.Keys(ctx); len(keys) != 1 { - t.Errorf("the old key was removed: %v", keys) - } -} - -func TestAKeptVerdictThatIsNotAPassIsRefused(t *testing.T) { - k := Kept{Store: newMemKV()} - v := keptValue("m/a", 1) - v.State = meshdeliverycheckerclient.VerdictFail - if _, err := k.Keep(context.Background(), buildstep.LevelUnit, digA, v); err == nil { - t.Error("a failure was kept") - } -} diff --git a/modules/mesh-delivery-checker/internal/check/line.go b/modules/mesh-delivery-checker/internal/check/line.go deleted file mode 100644 index 0dca6e35..00000000 --- a/modules/mesh-delivery-checker/internal/check/line.go +++ /dev/null @@ -1,394 +0,0 @@ -package check - -import ( - "fmt" - "mesh-delivery-checker/rules" - "slices" - "strings" - "unicode/utf8" - - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshdeliverycheckerclient" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshdeliverychecker" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep" -) - -// MaxLine is the most characters a status's line has: the forge shows a status's description in a short space, and the full -// report is linked (ADR 0447 clause 3, ADR 0484 clause 7). A line that would be longer drops its lesser parts in a fixed -// order, and is cut last. -const MaxLine = 140 - -// seconds is a time in milliseconds in the unit a person reads: 350ms, 4.1s, 72s. -func seconds(ms int64) string { - switch { - case ms < 1000: - return fmt.Sprintf("%dms", ms) - case ms < 10000: - return fmt.Sprintf("%.1fs", float64(ms)/1000) - } - return fmt.Sprintf("%ds", (ms+500)/1000) -} - -func short12(s string) string { - if len(s) > 12 { - return s[:12] - } - return s -} - -// firstFailed is what failed first, in words: a conflict, a refused step or a test, named before anything else. -func firstFailed(v meshdeliverychecker.VerdictsByGroupHeadsValue) string { - f := failedOf(v) - switch { - case f.Test != "": - if w := firstWordsLine(f.Words); w != "" { - return f.Test + ": " + w - } - return f.Test - case f.Machine != "" && firstWordsLine(f.Words) != "": - return f.Machine + ": " + firstWordsLine(f.Words) - case f.Machine != "": - return f.Machine - } - return firstWordsLine(f.Words) -} - -// failedLines is everything a verdict names as failed, one line each: every failed test with its first line (issue -// 1921), or what failed first when the verdict names no list (a conflict, a refused step, an older verdict). -func failedLines(v meshdeliverychecker.VerdictsByGroupHeadsValue) []string { - if len(v.Failures) == 0 { - if f := firstFailed(v); f != "" { - return []string{f} - } - return nil - } - lines := make([]string, 0, len(v.Failures)) - for _, f := range v.Failures { - lines = append(lines, firstFailed(meshdeliverychecker.VerdictsByGroupHeadsValue{Failed: &FailedFirst{Machine: f.Machine, Test: f.Test, Words: f.Words}})) - } - return lines -} - -// failedHead is the head of a failed verdict's line: what failed first, and when more did, how many failed and "and N -// more" after it (the operator, 2026-11-02), so a line cut to MaxLine still says that more failed. The words of the first -// are cut to fit room characters when room is not negative; the count and "and N more" are never cut. -func failedHead(v meshdeliverychecker.VerdictsByGroupHeadsValue, room int) string { - first := firstFailed(v) - n := rules.FailedCount(v) - if n <= 1 { - return clipRunes("failed: "+first, room) - } - prefix, more := fmt.Sprintf("failed (%d): ", n), fmt.Sprintf("; and %d more", n-1) - if room >= 0 { - first = clipRunes(first, room-utf8.RuneCountInString(prefix+more)) - } - return prefix + first + more -} - -// clipRunes cuts s to at most n characters, the last an ellipsis; a negative n leaves it whole. -func clipRunes(s string, n int) string { - r := []rune(s) - if n < 0 || len(r) <= n { - return s - } - if n < 1 { - return "" - } - return string(r[:n-1]) + "…" -} - -// firstWordsLine is the first line of a failure's words: the words are several lines (issue 1901) and the status line one. -func firstWordsLine(w string) string { return rules.FirstLine(w) } - -// pieces are the parts of a line, from the most to the least needed. -type pieces struct { - head, commits, counts, shortCounts, times, shortTimes, over, builds, composition, shortComposition, group string - // judged names the program that judged a change to a build module (ADR 0535 §5); never dropped. - judged string - // carried says, of a carried verdict, the commits it was carried from (ADR 0548 §8); never dropped. - carried string - // warning says that a part of the check did not run, for instance that an older build module could not refuse a compiled program; never dropped. - warning string - // series names each change of a package series the pull request makes (design 32, DLV-C4); never dropped. - series string -} - -// pullKey names a pull request of a case: `#`. -func pullKey(p Pull) string { return fmt.Sprintf("%s#%d", p.Repository, p.Number) } - -func (p pieces) join(drop int) string { - parts := []string{p.head, p.commits, p.carried, p.warning, p.counts, p.judged, p.series} - switch { - case drop < 3 && p.times != "": - parts = append(parts, p.times) - case drop == 3 && p.shortTimes != "": - parts = []string{p.head, p.commits, p.carried, p.warning, p.shortCounts, p.judged, p.series, p.shortTimes} - } - if p.over != "" { - parts = append(parts, p.over) - } - if drop < 1 && p.builds != "" { - parts = append(parts, p.builds) - } - if drop < 2 && p.group != "" { - parts = append(parts, p.group) - } - switch { - case drop >= 3 && p.shortComposition != "": - parts = append(parts, p.shortComposition) - case p.composition != "": - parts = append(parts, p.composition) - } - return joinSet(parts...) -} - -func levelWords(name string, r meshdeliverychecker.VerdictsByGroupHeadsValueLevelsValue) string { - s := fmt.Sprintf("%s %d run, %d kept", name, r.Run, r.Kept) - if r.Skipped > 0 { - s += fmt.Sprintf(", %d skipped", r.Skipped) - } - return s -} - -// compositionWords says the composition: not yet run, or once the engines answered (ADR 0593 §7) passed, with the nodes -// that gave no answer, or failed, with the time it took and the machines it composed (issue 1300). -func compositionWords(c *meshdeliverychecker.VerdictsByGroupHeadsValueComposition, took int64) string { - return composition(c, took, false) -} - -// composition is compositionWords; short counts the machines and leaves the SDK commit to the report. -func composition(c *meshdeliverychecker.VerdictsByGroupHeadsValueComposition, took int64, short bool) string { - if c != nil && c.State == meshdeliverycheckerclient.CompositionNotRun && c.Words != "" { - return "composition not judged: " + c.Words - } - if c == nil || c.State == meshdeliverycheckerclient.CompositionNotRun { - return "composition not yet run" - } - in := "" - if took > 0 { - in = " in " + seconds(took) - } - on := "" - if len(c.Machines) > 0 { - machines := slices.Sorted(slices.Values(c.Machines)) - on = " on " + strings.Join(machines, ", ") - switch { - case len(machines) > 1 && short: - on = fmt.Sprintf(" on %d machines", len(machines)) - case len(machines) > 1: - on = fmt.Sprintf(" on %d machines: %s", len(machines), strings.Join(machines, ", ")) - } - } - warned := "" - if c.State == meshdeliverycheckerclient.CompositionPass && c.Words != "" { - warned = " (" + c.Words + ")" // a node that did not answer (ADR 0593 §9) - } - switch { - case c.State == meshdeliverycheckerclient.CompositionPass && short: - return "composition passed" + in + on + warned // what it composed with is in the report - case c.State == meshdeliverycheckerclient.CompositionPass: - return "composition passed" + in + " with " + short12(c.Sdk) + on + warned - } - return "composition failed" + in + on + ": " + c.Words -} - -func buildWords(builds []BuildNote) string { - if len(builds) == 0 { - return "" - } - parts := make([]string, len(builds)) - for i, b := range builds { - parts[i] = b.Module + " " + b.State - } - return "builds: " + strings.Join(parts, ", ") -} - -// carriedWords say the commits a verdict was carried from, for the line of pull request p (ADR 0548 §8): its own trunk's -// commit as twelve characters, a sibling's with its name before it; only those that moved, sorted. Empty when none did. -func carriedWords(from map[string]string, v meshdeliverychecker.VerdictsByGroupHeadsValue, cs *Case, p Pull) string { - var own string - var others []string - for r, old := range from { - now, ok := v.Trunk[r] - if cs != nil && !ok { - now, ok = cs.Trunk[r] - } - if !ok { - now = v.Beside[r] - } - if now == "" || now == old { - continue - } - if strings.EqualFold(r, p.Repository) { - own = short12(old) - continue - } - name := r - if i := strings.LastIndex(r, "/"); i >= 0 { - name = r[i+1:] - } - others = append(others, name+" "+short12(old)) - } - slices.Sort(others) - if own != "" { - others = append([]string{own}, others...) - } - return strings.Join(others, ", ") -} - -// parts makes the pieces of the line of a pull request of a case. -func parts(v meshdeliverychecker.VerdictsByGroupHeadsValue, cs *Case, p Pull, builds []BuildNote, slowest []string, judged map[string]string) pieces { - var pc pieces - pc.judged = judged[pullKey(p)] - pc.series = seriesWords(cs, p) - if cs != nil { - pc.warning = cs.Warning(pullKey(p)) - } - commits := short12(p.Head) + " on " + short12(p.Trunk) - switch v.State { - case meshdeliverycheckerclient.VerdictRunning: - pc.head = "checking " + commits - if cs != nil && cs.CarriedFrom != nil { - // Out of date and being carried to the new commit (ADR 0548 §6): pending, and saying so. - pc.head = "being carried to " + commits - if w := carriedWords(cs.CarriedFrom, v, cs, p); w != "" { - pc.carried = "from " + w - } - } - case meshdeliverycheckerclient.VerdictPass: - pc.head = "pass " + commits - if w := carriedWords(v.CarriedFrom, v, cs, p); w != "" { - pc.carried = "carried from " + w // the counts that follow say what the carry ran and kept - } - default: - pc.head = failedHead(v, -1) - pc.commits = commits - } - var counts []string - for _, level := range []string{buildstep.LevelUnit, buildstep.LevelIntegration} { - if r, ok := v.Levels[level]; ok { - counts = append(counts, levelWords(level, r)) - } - } - pc.counts = strings.Join(counts, " | ") - var short []string - for _, level := range []string{buildstep.LevelUnit, buildstep.LevelIntegration} { - if r, ok := v.Levels[level]; ok { - name := map[string]string{buildstep.LevelUnit: "unit", buildstep.LevelIntegration: "int"}[level] - w := fmt.Sprintf("%s %d run %d kept", name, r.Run, r.Kept) - if r.Skipped > 0 { - w += fmt.Sprintf(" %d skipped", r.Skipped) - } - short = append(short, w) - } - } - pc.shortCounts = strings.Join(short, " | ") - if v.State != meshdeliverycheckerclient.VerdictRunning { - t := tookOf(v) - var times []string - for _, x := range []struct { - name string - ms int64 - }{{"queue", t.Queue}, {"clone", t.Clone}, {"lint", t.Lint}, {"unit", t.Unit}, {"int setup", t.IntegrationSetup}, {"int run", t.IntegrationRun}} { - if x.ms > 0 { - times = append(times, x.name+" "+seconds(x.ms)) - } - } - if len(times) > 0 { - pc.times = strings.Join(times, ", ") - } - // The compact form for a line that is too long: the parts that dominate, the integration level's setup and run as one. - short = short[:0:0] - if t.Clone > 0 { - short = append(short, "clone "+seconds(t.Clone)) - } - if t.Lint > 0 { - short = append(short, "lint "+seconds(t.Lint)) - } - if t.Unit > 0 { - short = append(short, "unit "+seconds(t.Unit)) - } - switch { - case t.IntegrationSetup > 0 && t.IntegrationRun > 0: - short = append(short, "int "+seconds(t.IntegrationSetup)+"+"+seconds(t.IntegrationRun)) - case t.IntegrationRun > 0: - short = append(short, "int "+seconds(t.IntegrationRun)) - } - pc.shortTimes = strings.Join(short, " ") - } - if len(v.OverBound) > 0 { - pc.over = "over bound: " + strings.Join(v.OverBound, ", ") - if len(slowest) > 0 { - pc.over += " (slowest " + strings.Join(slowest, ", ") + ")" - } - } - pc.builds = buildWords(builds) - if v.State != meshdeliverycheckerclient.VerdictRunning { - pc.composition = compositionWords(v.Composition, tookOf(v).Composition) - pc.shortComposition = composition(v.Composition, tookOf(v).Composition, true) - } - if cs != nil && len(cs.Pulls) > 1 { - pc.group = fmt.Sprintf("group %s of %d pull requests", cs.Group, len(cs.Pulls)) - if v.State != meshdeliverycheckerclient.VerdictPass { - pc.group = fmt.Sprintf("%s#%d in group %s", p.Repository, p.Number, cs.Group) - } - } - return pc -} - -// Report is the full line of a pull request's status, with no limit: what the read tools and the full report say. -func Report(v meshdeliverychecker.VerdictsByGroupHeadsValue, cs *Case, p Pull, builds []BuildNote, slowest []string, judged map[string]string) string { - return parts(v, cs, p, builds, slowest, judged).join(0) -} - -// Line is the words of a status for one pull request of a case (ADR 0447 clause 3, ADR 0484 clause 7): the verdict first (a -// failure names the conflict, the refused step or the test before anything), the head and the trunk commit as twelve -// characters each, the tests run, kept and skipped per level, the time of each part, a level over its bound with its slowest -// tests, the builds of the touched modules, and that the composition was not yet run; for a change to a build module, the -// program that judged it (judged, by pullKey; ADR 0535 §5). It is at most MaxLine characters: the -// builds, then the group drop first, then the times are given in their compact form, then dropped, and the line is cut at last. -// The program that judged is never dropped: a line naming it gives the counts in their compact form, then drops them and -// what follows, and is cut in its first part rather than lose it. -func Line(v meshdeliverychecker.VerdictsByGroupHeadsValue, cs *Case, p Pull, builds []BuildNote, slowest []string, judged map[string]string) string { - pc := parts(v, cs, p, builds, slowest, judged) - if v.State == meshdeliverycheckerclient.VerdictFail { - // The head gives way first to the commits and what is never dropped: its count and "and N more" stay whole. - kept := joinSet(pc.commits, pc.carried, pc.warning, pc.judged, pc.series) - pc.head = failedHead(v, MaxLine-utf8.RuneCountInString(" | "+kept)) - } - for drop := 0; drop <= 4; drop++ { - if s := pc.join(drop); utf8.RuneCountInString(s) <= MaxLine { - return s - } - } - if pc.judged != "" || pc.series != "" { - for _, counts := range []string{pc.shortCounts, ""} { - if s := joinSet(pc.head, pc.commits, counts, pc.judged, pc.series); utf8.RuneCountInString(s) <= MaxLine { - return s - } - } - rest := " | " + joinSet(pc.commits, pc.judged, pc.series) - room := MaxLine - utf8.RuneCountInString(rest) - 1 - if head := []rune(pc.head); room > 0 && len(head) > room { - return string(head[:room]) + "…" + rest - } - } - if v.State == meshdeliverycheckerclient.VerdictFail { - // A failure's head, sized above, and the commits fit: the counts and the composition are in the report. - if s := joinSet(pc.head, pc.commits, pc.carried, pc.warning, pc.judged, pc.series); utf8.RuneCountInString(s) <= MaxLine { - return s - } - } - runes := []rune(pc.join(4)) - return string(runes[:MaxLine-1]) + "…" -} - -// joinSet joins the parts that are not empty. -func joinSet(parts ...string) string { - out := make([]string, 0, len(parts)) - for _, s := range parts { - if s != "" { - out = append(out, s) - } - } - return strings.Join(out, " | ") -} diff --git a/modules/mesh-delivery-checker/internal/check/line_test.go b/modules/mesh-delivery-checker/internal/check/line_test.go deleted file mode 100644 index 2b80bb72..00000000 --- a/modules/mesh-delivery-checker/internal/check/line_test.go +++ /dev/null @@ -1,193 +0,0 @@ -package check - -import ( - "fmt" - "strings" - "testing" - "unicode/utf8" - - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshdeliverycheckerclient" - "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/meshdeliverychecker" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep" -) - -func lineCase(t testing.TB, pulls ...meshcatalog.CandidatesByGroupValuePullsItem) (*Case, Pull) { - cs := caseOf(t, pulls...) - return cs, cs.Pulls[0] -} - -func passVerdict() meshdeliverychecker.VerdictsByGroupHeadsValue { - return meshdeliverychecker.VerdictsByGroupHeadsValue{State: meshdeliverycheckerclient.VerdictPass, - Levels: map[string]meshdeliverychecker.VerdictsByGroupHeadsValueLevelsValue{buildstep.LevelUnit: {Run: 12, Kept: 301}, buildstep.LevelIntegration: {Run: 3, Kept: 40}}, - Took: &meshdeliverychecker.VerdictsByGroupHeadsValueTook{Queue: 800, Clone: 4100, Unit: 400, IntegrationSetup: 3200, IntegrationRun: 12000}, - Composition: &meshdeliverychecker.VerdictsByGroupHeadsValueComposition{State: meshdeliverycheckerclient.CompositionNotRun}} -} - -func TestAPassOpensWithTheVerdictAndSaysTheCommitsTheCountsTheTimesAndThatTheCompositionWasNotRun(t *testing.T) { // 1300/AC1 - cs, p := lineCase(t, pullOf(repoA, 7, head1)) - full := Report(passVerdict(), cs, p, nil, nil, nil) - for _, want := range []string{"pass 111111111111 on aaaaaaaaaaaa", "unit 12 run, 301 kept", "integration 3 run, 40 kept", "queue 800ms", "clone 4.1s", "unit 400ms", "int setup 3.2s", "int run 12s", "composition not yet run"} { - if !strings.Contains(full, want) { - t.Errorf("the report %q lacks %q", full, want) - } - } - if !strings.HasPrefix(full, "pass ") || strings.Contains(full, "composition passed") { - t.Errorf("report = %q", full) - } - line := Line(passVerdict(), cs, p, nil, nil, nil) - if n := utf8.RuneCountInString(line); n > MaxLine { - t.Errorf("the line is %d characters, want at most %d: %q", n, MaxLine, line) - } - if !strings.HasPrefix(line, "pass 111111111111 on aaaaaaaaaaaa") || !strings.Contains(line, "composition not yet run") || !strings.Contains(line, "unit 12 run 301 kept") || - !strings.Contains(line, "clone 4.1s") || !strings.Contains(line, "int 3.2s+12s") { - t.Errorf("line = %q", line) - } -} - -func TestAFailureNamesTheTestTheConflictOrTheRefusedStepFirst(t *testing.T) { // 1300/AC2 - cs, p := lineCase(t, pullOf(repoA, 7, head1)) - long := FailedFirst{Test: "integration: " + strings.Repeat("pkg/", 50) + "TestSomething", Words: strings.Repeat("because ", 40)} - for name, c := range map[string]struct { - v meshdeliverychecker.VerdictsByGroupHeadsValue - want string - }{ - "test": {meshdeliverychecker.VerdictsByGroupHeadsValue{State: meshdeliverycheckerclient.VerdictFail, Failed: &FailedFirst{Test: "unit: m/a.TestX", Words: "want 4"}}, "failed: unit: m/a.TestX: want 4"}, - "conflict": {meshdeliverychecker.VerdictsByGroupHeadsValue{State: meshdeliverycheckerclient.VerdictFail, Failed: &FailedFirst{Machine: "shanks", Words: "novox/mesh-delivery#7 does not merge into the trunk: files in conflict: go.mod"}}, "failed: shanks: novox/mesh-delivery#7 does not merge into the trunk: files in conflict: go.mod"}, - "refused": {meshdeliverychecker.VerdictsByGroupHeadsValue{State: meshdeliverycheckerclient.VerdictFail, Failed: &FailedFirst{Machine: "mesh-build-go", Words: "no go build node qualifies: builders disagree"}}, "failed: mesh-build-go: no go build node qualifies"}, - // ADR 0591: a first failure longer than the forge's limit is shortened; "failed (N)" and "and N-1 more" are never cut. - "many, the first too long": {meshdeliverychecker.VerdictsByGroupHeadsValue{State: meshdeliverycheckerclient.VerdictFail, Failed: &long, Failures: failureItems([]FailedFirst{long, {Machine: "g14", Words: "route-proxy is defined twice"}, - {Test: "unit: m/b.TestY", Words: "boom"}})}, "failed (3): integration: pkg/pkg/"}, - } { - line := Line(c.v, cs, p, nil, nil, nil) - if more := len(c.v.Failures) - 1; more > 0 && (!strings.Contains(line, fmt.Sprintf("…; and %d more | 111111111111", more)) || utf8.RuneCountInString(line) > MaxLine) { - t.Errorf("%s: line = %q (%d), want the first's words shortened, the count and \"and %d more\" whole, within %d", name, line, utf8.RuneCountInString(line), more, MaxLine) - } - if !strings.HasPrefix(line, c.want) || !strings.Contains(line, "111111111111 on aaaaaaaaaaaa") { - t.Errorf("%s: line = %q, want it to open with %q and name the commits", name, line, c.want) - } - } -} - -// The status line and its full report say each part of a verdict, within the forge's limit (issue 1300, ADR 0484). -func TestTheLineAndTheReportSayEachPartOfTheVerdict(t *testing.T) { - for _, row := range []struct { - name string - test func(t *testing.T) - }{ - {"a level over its bound is named with its slowest tests and the verdict is not changed", func(t *testing.T) { // 1300/AC3 - cs, p := lineCase(t, pullOf(repoA, 7, head1)) - v := passVerdict() - v.OverBound = []string{"unit"} - line := Line(v, cs, p, nil, []string{"unit pkg.TestSlow 7.0s"}, nil) - if !strings.HasPrefix(line, "pass ") || !strings.Contains(Report(v, cs, p, nil, []string{"unit pkg.TestSlow 7.0s"}, nil), "over bound: unit (slowest unit pkg.TestSlow 7.0s)") { - t.Errorf("line = %q", line) - } - }}, - {"skipped tests are said and never a flat pass", func(t *testing.T) { // 1300/AC6 - cs, p := lineCase(t, pullOf(repoA, 7, head1)) - v := passVerdict() - v.Levels[buildstep.LevelUnit] = meshdeliverychecker.VerdictsByGroupHeadsValueLevelsValue{Run: 12, Kept: 301, Skipped: 2} - if line := Line(v, cs, p, nil, nil, nil); !strings.Contains(line, "unit 12 run, 301 kept, 2 skipped") { - t.Errorf("line = %q", line) - } - }}, - {"a groups members each carry the same verdict", func(t *testing.T) { // 1300/AC4 - cs := caseOf(t, pullOf(repoA, 7, head1), pullOf(repoSDK, 12, head2)) - a := Line(passVerdict(), cs, cs.Pulls[0], nil, nil, nil) - b := Line(passVerdict(), cs, cs.Pulls[1], nil, nil, nil) - if !strings.HasPrefix(a, "pass ") || !strings.HasPrefix(b, "pass ") || !strings.Contains(Report(passVerdict(), cs, cs.Pulls[0], nil, nil, nil), "group feat/x of 2 pull requests") { - t.Errorf("lines %q and %q", a, b) - } - if !strings.Contains(a, "111111111111") || !strings.Contains(b, "222222222222") { - t.Errorf("each member's line names its own head: %q and %q", a, b) - } - }}, - {"the builds of the touched modules are said and dropped first when the line is too long", func(t *testing.T) { // ADR 0484 clause 7 - cs, p := lineCase(t, pullOf(repoA, 7, head1)) - builds := []BuildNote{{"avahi", "built"}, {"mesh-tools", "waiting"}} - if r := Report(passVerdict(), cs, p, builds, nil, nil); !strings.Contains(r, "builds: avahi built, mesh-tools waiting") { - t.Errorf("report = %q", r) - } - line := Line(passVerdict(), cs, p, builds, nil, nil) - if utf8.RuneCountInString(line) > MaxLine { - t.Errorf("line %q is too long", line) - } - short := passVerdict() - short.Took = &meshdeliverychecker.VerdictsByGroupHeadsValueTook{} - if l := Line(short, cs, p, builds[:1], nil, nil); !strings.Contains(l, "builds: avahi built") { - t.Errorf("a short line keeps its builds: %q", l) - } - }}, - {"a line is never longer than the limit", func(t *testing.T) { // 1300/AC1 - cs, p := lineCase(t, pullOf(repoA, 7, head1)) - v := meshdeliverychecker.VerdictsByGroupHeadsValue{State: meshdeliverycheckerclient.VerdictFail, Failed: &FailedFirst{Test: "integration: " + strings.Repeat("pkg/", 50) + ".TestSomething", Words: strings.Repeat("because ", 40)}} - if line := Line(v, cs, p, nil, nil, nil); utf8.RuneCountInString(line) > MaxLine || !strings.HasPrefix(line, "failed: integration: ") { - t.Errorf("line = %q (%d)", line, utf8.RuneCountInString(line)) - } - }}, - {"a running check is pending", func(t *testing.T) { - cs, p := lineCase(t, pullOf(repoA, 7, head1)) - if line := Line(meshdeliverychecker.VerdictsByGroupHeadsValue{State: meshdeliverycheckerclient.VerdictRunning}, cs, p, nil, nil, nil); line != "checking 111111111111 on aaaaaaaaaaaa" { - t.Errorf("line = %q", line) - } - }}, - {"the passed composition is said only when it was run", func(t *testing.T) { // ADR 0484 clause 6 - cs, p := lineCase(t, pullOf(repoA, 7, head1)) - v := passVerdict() - v.Composition = &meshdeliverychecker.VerdictsByGroupHeadsValueComposition{State: meshdeliverycheckerclient.CompositionPass, Sdk: "afbe371003a570f088be4a394d83aa7a9458f7ab"} - if r := Report(v, cs, p, nil, nil, nil); !strings.Contains(r, "composition passed with afbe371003a5") { - t.Errorf("report = %q", r) - } - v.Composition = nil - if r := Report(v, cs, p, nil, nil, nil); !strings.Contains(r, "composition not yet run") || strings.Contains(r, "composition passed") { - t.Errorf("a verdict with no composition: %q", r) - } - }}, - {"the compositions time and machines are said once the assigner reports them", func(t *testing.T) { // 1300 (C10), the assigner's verdict (issue 1297) - cs, p := lineCase(t, pullOf(repoA, 7, head1)) - v := passVerdict() - v.Took.Composition = 2400 - v.Composition = &meshdeliverychecker.VerdictsByGroupHeadsValueComposition{State: meshdeliverycheckerclient.CompositionPass, Sdk: "afbe371003a570f088be4a394d83aa7a9458f7ab", Machines: []string{"g14", "ace", "novox", "shanks"}} - r := Report(v, cs, p, nil, nil, nil) - for _, want := range []string{"composition passed in 2.4s with afbe371003a5 on 4 machines: ace, g14, novox, shanks"} { - if !strings.Contains(r, want) { - t.Errorf("report %q lacks %q", r, want) - } - } - if l := Line(v, cs, p, nil, nil, nil); !strings.Contains(l, "composition passed in 2.4s") || !strings.Contains(l, "on 4 machines") || utf8.RuneCountInString(l) > MaxLine { - t.Errorf("line = %q", l) - } - v.State, v.Failed = meshdeliverycheckerclient.VerdictFail, &FailedFirst{Machine: "novox", Words: "composition refused"} - v.Composition = &meshdeliverychecker.VerdictsByGroupHeadsValueComposition{State: meshdeliverycheckerclient.CompositionFail, Words: "novox: two seats claim dns", Machines: []string{"novox"}} - if r := Report(v, cs, p, nil, nil, nil); !strings.Contains(r, "composition failed in 2.4s on novox: novox: two seats claim dns") { - t.Errorf("failed composition report = %q", r) - } - }}, - } { - t.Run(row.name, row.test) - } -} - -// 1887/D7-go, review round 2 item 5: the line says the unit level's gofmt and go vet time beside its tests'. -func TestTheLineSaysTheLintTime(t *testing.T) { - b := newBench(t) - test := b.test - b.test = func(c stepCall) (any, error) { - r, err := test(c) - if res, ok := r.(Tested); ok && res.Level == buildstep.LevelUnit { - res.Lint = 1.5 - return res, err - } - return r, err - } - out := b.judge(t, caseOf(t, pullOf(repoA, 7, head1))) - if out.Verdict.Took.Lint != 1500 { - t.Fatalf("took = %+v, want the lint's 1.5 s", out.Verdict.Took) - } - cs := caseOf(t, pullOf(repoA, 7, head1)) - pc := parts(out.Verdict, cs, cs.Pulls[0], out.Builds, out.Slowest, out.Judged) - if !strings.Contains(pc.times, "lint 1.5s") || !strings.Contains(pc.shortTimes, "lint 1.5s") { - t.Errorf("times = %q, short %q, want the lint's time in both forms of the line", pc.times, pc.shortTimes) - } -} diff --git a/modules/mesh-delivery-checker/internal/check/lostask.go b/modules/mesh-delivery-checker/internal/check/lostask.go deleted file mode 100644 index 8672fd62..00000000 --- a/modules/mesh-delivery-checker/internal/check/lostask.go +++ /dev/null @@ -1,36 +0,0 @@ -package check - -import ( - "strings" - - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-builder/buildrun" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshdeliverycheckerclient" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshdeliverychecker" - sdkrun "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildrun" -) - -// **An ask the build seat gave up on ends its step** (novox/hq issue 734): mesh-sdk buildrun.LostAskWaiter hands the -// waiting asker a failed step on the node buildrun.LostNode when DEAD_LETTERS keeps the ask's copy (buildrun.HearDeadLetters, -// granted by buscompose DeadLetterReads), and, under buildrun.NotTakenBound, when no build node took the ask within the -// bound. What follows is the checker's: a try ends as error (Tryer.run), with the not-taken bound at the step bound -// (Tryer.NotTaken); a check is asked again under its claim, at most LostAskTries times, then fails as not heard and is -// asked again when the part it could not hear runs (Checker.try). A check's ask has no not-taken bound: it waits in the stream as long as -// the backlog is (ADR 0525 §9), and a check ended for a backlog would owe its pull request a failure. - -// LostAskTries is how often a check asks again whose ask was given up, before it fails as not heard (UnheardWords) and is -// asked again when the part it could not hear runs. -const LostAskTries = 3 - -// IsLostAsk says whether a verdict failed because its ask judged nothing: the build seat gave it up (buildrun.LostWords), or -// the build module that ran its step was replaced under it, and its next process ended the step it left running -// (sdkrun.RestartReason; a delivery of the build module, as on 2026-10-28). Neither is the change's failure: the check -// is asked again, as for a given-up ask. -func IsLostAsk(v meshdeliverychecker.VerdictsByGroupHeadsValue) bool { - return v.State == meshdeliverycheckerclient.VerdictFail && (strings.Contains(failedOf(v).Words, buildrun.LostWords) || - strings.Contains(failedOf(v).Words, sdkrun.RestartReason)) -} - -// IsNotTaken says whether a verdict failed because no build node took its ask within the bound (buildrun.NotTakenWords). -func IsNotTaken(v meshdeliverychecker.VerdictsByGroupHeadsValue) bool { - return v.State == meshdeliverycheckerclient.VerdictFail && strings.Contains(failedOf(v).Words, buildrun.NotTakenWords) -} diff --git a/modules/mesh-delivery-checker/internal/check/lostask_test.go b/modules/mesh-delivery-checker/internal/check/lostask_test.go deleted file mode 100644 index d1073b8d..00000000 --- a/modules/mesh-delivery-checker/internal/check/lostask_test.go +++ /dev/null @@ -1,418 +0,0 @@ -package check - -import ( - "context" - "encoding/json" - "fmt" - "maps" - "slices" - "strings" - "sync" - "testing" - "time" - - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-builder/buildrun" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshdeliverycheckerclient" - sdkrun "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildrun" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep" -) - -// losingAsks is the build seat over a bus that gives up the first `lose` asks put (DEAD_LETTERS keeps them, as on -// 2026-10-26 during a bus reload: try-1793017340003993788) and answers the rest; with never set it neither answers nor -// gives up (an ask no node takes). -type losingAsks struct { - *buildrun.FakeAsks - answer func(buildstep.StepAsk) buildstep.Step - dead *buildrun.DeadLetters - never bool - - mu sync.Mutex - lose int -} - -func (l *losingAsks) PublishAsk(ctx context.Context, subject, id string, data []byte) error { - if err := l.FakeAsks.PublishAsk(ctx, subject, id, data); err != nil { - return err - } - l.mu.Lock() - lost := l.lose > 0 - if lost { - l.lose-- - } - l.mu.Unlock() - switch { - case l.never: - case lost: - h := map[string][]string{buildrun.DeadHeaderMsgID: {id}, buildrun.DeadHeaderDeliveries: {"5"}, buildrun.DeadHeaderStream: {"SEAT_NODE_BUILD_GO"}, - buildrun.DeadHeaderGaveUp: {"2026-10-26T12:26:40Z"}} - g, ok := buildrun.GivenUpOf(h) - if !ok { - return nil - } - go l.dead.Heard(g) - default: - a, err := buildstep.DecodeStepAsk(data) - if err != nil { - return err - } - l.Write(l.answer(a)) - } - return nil -} - -func losing(b *bench, lose int) *losingAsks { - l := &losingAsks{FakeAsks: &buildrun.FakeAsks{}, answer: b.answer, dead: &buildrun.DeadLetters{}, lose: lose} - b.ex.Asks = buildrun.Asker{Seats: testSeats(), Publisher: b.asker(l, l.FakeAsks.Write), Waiter: buildrun.LostAskWaiter{Inner: l.FakeAsks, Dead: l.dead}, Bound: 5 * time.Second} - return l -} - -// endable is the tries state as the end tool sees it. -type endable struct{ kv *memKV } - -func (e endable) Entry(key string) (json.RawMessage, uint64, error) { - v, rev, _, err := e.kv.Get(context.Background(), key) - return v, rev, err -} -func (e endable) Update(key string, value []byte, revision uint64) error { - _, err := e.kv.Update(context.Background(), key, value, revision) - return err -} - -// Issue 734: a try whose ask the build seat gave up on ends as error saying so, and the next ask of its head is a new try; -// one no node takes ends at the step bound; one ended by hand frees its place and stops being waited for. -func TestAnAskGivenUpOrNeverTakenEndsItsTryAsErrorAndItsHeadIsAskedAnew(t *testing.T) { - ctx := context.Background() - for _, row := range []struct { - name string - lose int - never bool - // notTaken is the try's bound on an ask no node takes: short only where it is what ends the try, an hour where the - // dead letter must (a loaded machine let 200 ms pass before the dead letter was heard). - notTaken time.Duration - want string - }{ - {"given up by the build seat", 1, false, time.Hour, buildrun.LostWords + " after 5 deliveries at 2026-10-26T12:26:40Z"}, - {"taken by no build node within the bound", 0, true, 200 * time.Millisecond, buildrun.NotTakenWords + " within 200ms"}, - } { - t.Run(row.name, func(t *testing.T) { - kv := newMemKV() - at := time.Date(2026, 10, 26, 12, 22, 20, 0, time.UTC) - id, err := AskTry(memTries{kv}, tryTrunks, TryAsk{Repository: repoA, Head: head1}, at) - if err != nil { - t.Fatal(err) - } - b := newBench(t) - l := losing(b, row.lose) - l.never = row.never - tr := &Tryer{Tries: kv, Judge: b.ex, NotTaken: row.notTaken} - raw, _, _, _ := kv.Get(ctx, id) - tr.Put(ctx, id, raw) - tr.Wait() - got := readTry(t, kv, id) - if got.State != TryError || len(got.Failed) != 1 || !strings.Contains(got.Failed[0], row.want) || !strings.Contains(got.Said, row.want) { - t.Fatalf("try = %+v, want error saying %q", got, row.want) - } - again, err := AskTry(memTries{kv}, tryTrunks, TryAsk{Repository: repoA, Head: head1}, at.Add(time.Minute)) - if err != nil || again == id { - t.Errorf("the head asked again answered %q, %v, want a new try", again, err) - } - }) - } - t.Run("ended by hand", func(t *testing.T) { - kv := newMemKV() - id, _ := AskTry(memTries{kv}, tryTrunks, TryAsk{Repository: repoA, Head: head1}, time.Now()) - b := newBench(t) - losing(b, 0).never = true - tr := &Tryer{Tries: kv, Judge: b.ex} // no bound: only the hand ends it - raw, _, _, _ := kv.Get(ctx, id) - tr.Put(ctx, id, raw) - deadline := time.Now().Add(10 * time.Second) - for readTry(t, kv, id).State != TryRunning && time.Now().Before(deadline) { - time.Sleep(5 * time.Millisecond) - } - if _, err := EndTry(endable{kv}, id, "", time.Now()); err == nil { - t.Error("an end without a why was taken") - } - ended, err := EndTry(endable{kv}, id, "its ask was lost in the bus reload", time.Now()) - if err != nil || ended.State != TryError || !strings.HasPrefix(ended.Said, "ended by hand ("+TryEndTool+"): its ask was lost") { - t.Fatalf("ended = %+v, %v", ended, err) - } - raw, _, _, _ = kv.Get(ctx, id) - tr.Put(ctx, id, raw) // the watch of the tries hands the end over - tr.Wait() // returns: the try's judging stopped - if got := readTry(t, kv, id); got.State != TryError || got.Said != ended.Said { - t.Errorf("try = %+v, want the hand's end kept", got) - } - if _, err := EndTry(endable{kv}, id, "again", time.Now()); err == nil || !strings.Contains(err.Error(), "ended already") { - t.Errorf("a second end answered %v", err) - } - }) -} - -// troubled is the build seat as a check meets it when its step's end does not reach its wait: the first `restarts` asks' -// steps are ended by the build module's next process (sdkrun.RestartReason), and the first `deaf` asks' watches hear -// nothing though their steps end (the lost check of 2026-10-28). Its steps state is read through AskSteps and Steps. -type troubled struct { - *buildrun.FakeAsks - answer func(buildstep.StepAsk) buildstep.Step - - mu sync.Mutex - restarts, deaf int - deafIDs map[string]bool - steps map[string]buildstep.Step -} - -func (tr *troubled) PublishAsk(ctx context.Context, subject, id string, data []byte) error { - if err := tr.FakeAsks.PublishAsk(ctx, subject, id, data); err != nil { - return err - } - a, err := buildstep.DecodeStepAsk(data) - if err != nil { - return err - } - step := tr.answer(a) - read, _ := buildstep.AskAs[buildstep.Ask](a) - step.What = sdkrun.AskWhat(read) - tr.mu.Lock() - if tr.restarts > 0 { - tr.restarts-- - step.State, step.Reason, step.Result = buildstep.StepFailed, sdkrun.RestartReason, nil - } - deaf := tr.deaf > 0 - if deaf { - tr.deaf-- - tr.deafIDs[id] = true - } - tr.steps[id] = step - tr.mu.Unlock() - if !deaf { - tr.Write(step) - } - return nil -} - -func (tr *troubled) WatchAsk(ctx context.Context, module, asker, askID string) (<-chan buildstep.Step, error) { - tr.mu.Lock() - deaf := tr.deafIDs[askID] - tr.mu.Unlock() - if deaf { - return make(chan buildstep.Step), nil // open, and silent for good - } - return tr.FakeAsks.WatchAsk(ctx, module, asker, askID) -} - -func (tr *troubled) AskSteps(_ context.Context, _, _, askID string) ([]buildstep.Step, error) { - tr.mu.Lock() - defer tr.mu.Unlock() - if s, ok := tr.steps[askID]; ok { - return []buildstep.Step{s}, nil - } - return nil, nil -} - -// Steps is the steps state as the read tools read it, with running in place of every step the hand has not let end. -func (tr *troubled) Steps(running bool) StateRead { - tr.mu.Lock() - defer tr.mu.Unlock() - vals := map[string]json.RawMessage{} - for id, s := range tr.steps { - if running { - s.State, s.Ended, s.Started = buildstep.StepRunning, time.Time{}, time.Now() - } - raw, _ := buildstep.EncodeStep(s) - vals[s.Node+"."+id] = raw - } - return StateRead{Keys: func() ([]string, error) { - var out []string - for k := range vals { - out = append(out, k) - } - return out, nil - }, Get: func(k string) (json.RawMessage, error) { return vals[k], nil }} -} - -// kvRead is a bucket in memory as the read tools read it, live. -func kvRead(kv *memKV) StateRead { - return StateRead{Keys: func() ([]string, error) { return kv.Keys(context.Background()) }, - Get: func(k string) (json.RawMessage, error) { - v, _, _, err := kv.Get(context.Background(), k) - return v, err - }} -} - -// asVerdicts is the rig's verdicts as the ask-again tool reads and writes them. -type asVerdicts struct{ kv *memKV } - -func (a asVerdicts) Entry(key string) (json.RawMessage, uint64, error) { - v, rev, _, err := a.kv.Get(context.Background(), key) - return v, rev, err -} -func (a asVerdicts) Update(key string, value []byte, revision uint64) error { - _, err := a.kv.Update(context.Background(), key, value, revision) - return err -} - -// Issue 734 and the lost check of 2026-10-28: a check whose ask judged nothing is asked again, and one whose step ended -// unheard is judged. Given up by the build seat once, or its step ended by the build module's next process after a -// delivery replaced it, the check is asked again under its claim and passes; given up every time it fails loudly as not -// heard, could not run, asked again when its part runs. A step whose watch went deaf is read at the next step end of its build module -// (a nudge) and judged with no new ask; one no event reaches is named lost by checker_status, refused by checker_ask_again -// while its step still runs, and asked again by it once its step ended. -func TestACheckWhoseAskJudgedNothingIsAskedAgainOrRead(t *testing.T) { - ctx := context.Background() - for _, row := range []struct { - name string - lose, restarts, deaf int - how string // "nudge": a step of the build module ends; "hand": checker_ask_again - state string - asks int - }{ - {name: "given up once", lose: 1, state: meshdeliverycheckerclient.VerdictPass, asks: 2}, - {name: "given up every time", lose: LostAskTries, state: meshdeliverycheckerclient.VerdictFail, asks: LostAskTries}, - {name: "its build module replaced under it", restarts: 1, state: meshdeliverycheckerclient.VerdictPass, asks: 2}, - {name: "replaced under every ask", restarts: LostAskTries, state: meshdeliverycheckerclient.VerdictFail, asks: LostAskTries}, - {name: "its watch deaf, a step of its build module ends", deaf: 1, how: "nudge", state: meshdeliverycheckerclient.VerdictPass, asks: 1}, - {name: "its watch deaf, asked again by hand", deaf: 1, how: "hand", state: meshdeliverycheckerclient.VerdictPass, asks: 2}, - {name: "its watch deaf, asked again by hand after its build module replaced it", deaf: 1, restarts: 1, how: "hand", state: meshdeliverycheckerclient.VerdictPass, asks: 2}, - } { - t.Run(row.name, func(t *testing.T) { - b := newBench(t) - var asked func() int - var heard *buildrun.HeardEnds - var tr *troubled - if row.lose > 0 { - l := losing(b, row.lose) - asked = func() int { return len(l.Asks()) } - } else { - tr = &troubled{FakeAsks: &buildrun.FakeAsks{}, answer: b.answer, restarts: row.restarts, deaf: row.deaf, - deafIDs: map[string]bool{}, steps: map[string]buildstep.Step{}} - heard = &buildrun.HeardEnds{Inner: tr, Read: tr} - b.ex.Asks = buildrun.Asker{Seats: testSeats(), Publisher: b.asker(tr, tr.Write), Waiter: heard, Bound: 5 * time.Second} - asked = func() int { return len(tr.Asks()) } - } - r := newRig(t, b.ex) - asksKept := newMemKV() - r.ch.Asks = asksKept - cand := candidateOf(t, "feat/x", pullOf(repoA, 7, head1)) - key := keyOf(t, "feat/x", cand) - r.ch.Candidate(ctx, "feat%2Fx", cand) - if row.deaf > 0 { - for deadline := time.Now().Add(10 * time.Second); heard.Waiting() == 0 && time.Now().Before(deadline); { - time.Sleep(2 * time.Millisecond) - } - if v := r.verdict(t, key); v.State != meshdeliverycheckerclient.VerdictRunning { - t.Fatalf("a check whose step ended unheard = %s, want running until it is read", v.State) - } - } - switch row.how { - case "nudge": - heard.Nudge(nodeBuildModule) // another build module's step: not this one's to read - heard.Nudge(goBuildModule) - case "hand": - cands := newMemKV() - ckey, _ := meshcatalogclient.CandidatesKey("feat/x") - _, _ = cands.Create(ctx, ckey, cand) - none := StateRead{Keys: func() ([]string, error) { return nil, nil }, Get: func(string) (json.RawMessage, error) { return nil, nil }} - steps := map[string]StateRead{goBuildModule: none} - rd := Reader{CandidateState: kvRead(cands), VerdictState: kvRead(r.verdicts), AskState: kvRead(asksKept), - StepStates: func() map[string]StateRead { return steps }} // no node took its ask yet - if _, err := rd.AskAgain(asVerdicts{r.verdicts}, "feat/x", "its watch went deaf"); err == nil || !strings.Contains(err.Error(), "waits in its build seat's stream") { - t.Errorf("asked again while its ask waits in the stream (issue 1791's kind): %v", err) - } - steps[goBuildModule] = tr.Steps(true) - if _, err := rd.AskAgain(asVerdicts{r.verdicts}, "feat/x", "its watch went deaf"); err == nil || !strings.Contains(err.Error(), "a step of it runs") { - t.Errorf("asked again while its step runs: %v", err) - } - steps[goBuildModule] = tr.Steps(false) - if st, _ := rd.Status(); !strings.Contains(st.Lost["feat/x"], AskAgainTool) { - t.Errorf("status lost = %v, want feat/x named with %s", st.Lost, AskAgainTool) - } - // Issue 1373: a check that names no ask is asked again only when no check ask waits or is held in any build seat's stream. - { - raw, _, _, _ := r.verdicts.Get(ctx, key) - vcopy := newMemKV() - _, _ = vcopy.Create(ctx, key, raw) - noAsk := rd - noAsk.AskState = kvRead(newMemKV()) - for _, c := range []struct { - name string - rows []BacklogRow - bad string - }{{"a check ask waits", []BacklogRow{{Language: "go", Kind: "check", Waiting: 1}}, "holds asks"}, - {"a check ask is held", []BacklogRow{{Language: "go", Kind: "check", Held: 1}}, "holds asks"}, - {"a recheck ask waits", []BacklogRow{{Language: "go", Kind: "recheck", Waiting: 1}}, "holds asks"}, - {"a recheck ask is held", []BacklogRow{{Language: "go", Kind: "recheck", Held: 1}}, "holds asks"}, - {"a stream cannot be read", []BacklogRow{{Language: "go", Kind: "check", Error: "no worker"}}, "cannot be read"}, - {"only a delivery ask waits", []BacklogRow{{Language: "go", Kind: "delivery", Waiting: 3}}, ""}} { - noAsk.Backlog = func() ([]BacklogRow, error) { return c.rows, nil } - w := VerdictEntry(asVerdicts{r.verdicts}) - if c.bad == "" { - w = asVerdicts{vcopy} - } - got, err := noAsk.AskAgain(w, "feat/x", "no ask") - if (c.bad == "") != (err == nil) || (c.bad != "" && !strings.Contains(err.Error(), c.bad)) || (c.bad == "" && !strings.HasPrefix(got.Said, AskedAgainWords)) { - t.Errorf("a check naming no ask, %s: %+v, %v", c.name, got, err) - } - } - } - got, err := rd.AskAgain(asVerdicts{r.verdicts}, "feat/x", "its watch went deaf") - if err != nil || got.Key != key || !strings.HasPrefix(got.Said, AskedAgainWords) { - t.Fatalf("asked again = %+v, %v", got, err) - } - raw, _, _, _ := r.verdicts.Get(ctx, key) - r.ch.VerdictWritten(ctx, key, raw) // the checker's watch of its verdicts hands it over - } - r.ch.Wait() - v := r.verdict(t, key) - if v.State != row.state || asked() != row.asks { - t.Errorf("verdict %s (%s) after %d asks, want %s after %d", v.State, v.Failed.Words, asked(), row.state, row.asks) - } - if _, _, kept, _ := asksKept.Get(ctx, key); kept { - t.Errorf("the asks of the ended check are still kept under %s", key) - } - if row.state == meshdeliverycheckerclient.VerdictFail && (!IsLostAsk(v) || !IsCouldNotRun(v)) { - t.Errorf("a check that judged nothing every time = %q, want lost and could not run", v.Failed.Words) - } - if row.how == "hand" { - rd := Reader{VerdictState: kvRead(r.verdicts), CandidateState: kvRead(newMemKV())} - if _, err := rd.AskAgain(asVerdicts{r.verdicts}, "feat/x", "again"); err == nil { - t.Error("a judged check was asked again") - } - // ADR 0664 (issue 1748, operator answer 5): a failed verdict whose failing steps all ended on a transport fault - // is asked again; one with a failing step that did not, or with none read, stands. - for _, c := range []struct { - name string - passing []bool - ok bool - }{{"every failing step on a transport fault", []bool{true, true}, true}, {"one step failed on the source", []bool{true, false}, false}, {"no failed step read", nil, false}} { - failedKV := newMemKV() - judgedRaw, _, _, _ := r.verdicts.Get(ctx, key) - failed, _ := meshdeliverycheckerclient.DecodeVerdict(judgedRaw) - failed.State, failed.Failed = meshdeliverycheckerclient.VerdictFail, &FailedFirst{Machine: "ace", Words: "a transport fault on 3 runs"} - raw, _ := meshdeliverycheckerclient.EncodeVerdict(failed) - failedKV.Create(ctx, key, raw) - vals := map[string]json.RawMessage{} - for i, p := range c.passing { - id := fmt.Sprint("mvl0frv18d19", 80+i) - vals["ace."+id], _ = buildstep.EncodeStep(buildstep.Step{ID: id, Node: "ace", Tool: "check ask", State: buildstep.StepFailed, Passing: p, Ended: time.Now(), What: "check " + repoA + "@" + short12(head1)}) - } - rd := Reader{CandidateState: kvRead(cands2(t, cand)), VerdictState: kvRead(failedKV), AskState: kvRead(newMemKV()), StepStates: stepStatesOf(map[string]StateRead{goBuildModule: { - Keys: func() ([]string, error) { return slices.Collect(maps.Keys(vals)), nil }, Get: func(k string) (json.RawMessage, error) { return vals[k], nil }}})} - if got, err := rd.AskAgain(asVerdicts{failedKV}, "feat/x", "the network"); (err == nil) != c.ok || (c.ok && !strings.HasPrefix(got.Said, AskedAgainWords)) { - t.Errorf("%s: asked again = %+v, %v, want asked again %v", c.name, got, err, c.ok) - } - } - } - }) - } -} - -// cands2 is a candidates state holding cand under feat/x. -func cands2(t *testing.T, cand []byte) *memKV { - t.Helper() - kv := newMemKV() - ckey, _ := meshcatalogclient.CandidatesKey("feat/x") - _, _ = kv.Create(context.Background(), ckey, cand) - return kv -} diff --git a/modules/mesh-delivery-checker/internal/check/manifests_judge.go b/modules/mesh-delivery-checker/internal/check/manifests_judge.go deleted file mode 100644 index f665de95..00000000 --- a/modules/mesh-delivery-checker/internal/check/manifests_judge.go +++ /dev/null @@ -1,401 +0,0 @@ -package check - -import ( - "context" - "encoding/json" - "errors" - "fmt" - "maps" - "mesh-delivery-checker/rules" - "slices" - "strings" - - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/composer" - "git.novox.be/novox/mesh-sdk/go/catalogue" - - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/packagename" -) - -// A change's manifests are judged by the indexer's judge (novox/hq ADR 0578 §2): the checker asks the Go build seat to -// build the judge's command (mesh-delivery's modules/mesh-delivery-indexer, cmd/mesh-judge) at mesh-delivery's trunk, or -// at the group's mesh-delivery member head when that member changes the judge, and to run it in its sandbox over the -// catalogue as the change leaves it, exactly as the composer is run (buildstep.ComposeJob, ADR 0482 §4). A manifest the -// change touches that the judge refuses fails the check, naming the manifest and each problem. The checker links no -// judge of its own. - -// The judge the checker runs. -const ( - DeliveryRepository = "novox/mesh-delivery" - JudgeDir = "modules/mesh-delivery-indexer" - JudgePackage = "mesh-delivery-indexer/cmd/mesh-judge" - // JudgeCase is the case of a judge request holding the catalogue as the change leaves it, and JudgeTrunk the one - // holding it as the trunk holds it: a problem the change case has and the trunk case lacks is the change's (ADR 0579 §2). - JudgeCase = "change" - JudgeTrunk = "trunk" - // judgeBetween is how the judge names the problems between manifests that no one module's removal ends. - judgeBetween = rules.BetweenManifests -) - -// judgePaths are the paths of mesh-delivery whose change changes the judge: a group whose mesh-delivery member changes -// one is judged by that member's head. -var judgePaths = []string{JudgeDir + "/judge/", JudgeDir + "/cmd/mesh-judge/", JudgeDir + "/go.mod", JudgeDir + "/go.sum"} - -// changesJudge says whether a merge of mesh-delivery with these changed paths changes the judge. -func changesJudge(repository string, merged []Fetched) bool { - if repository != DeliveryRepository { - return false - } - for _, f := range merged { - for _, p := range f.Changed { - for _, j := range judgePaths { - if p == j || strings.HasPrefix(p, j) { - return true - } - } - } - } - return false -} - -// TrunkManifests says the manifest digest of every module the indexer holds (its modules state), by module. -type TrunkManifests interface { - ManifestDigests() map[string]string - // ManifestFingerprints is the fingerprint of the entry of every such module in the trunk revision, by module, whose - // catalog graph entry holds that manifest (design 47 G A-310). - ManifestFingerprints() map[string]string -} - -// SeatList gives the seat definitions the manifests are judged against, whole, as raw definitions (a request's Seats): the -// list the seat list reader holds. It is an error when the list has not been read from the seat yet, since a manifest judged -// against the bootstrapped seats alone would be refused for a seat it names that the mesh defines (novox/hq ADR 0636 §1). -type SeatList interface { - Definitions() ([]json.RawMessage, error) -} - -// PredefinedList is the catalogue's list of predefined keys the indexer keeps (its state predefined, key list), the one a -// config value falling back to a key is judged against (ADR 0348 §7); nil when it keeps none. -type PredefinedList interface { - PredefinedList(ctx context.Context) (json.RawMessage, error) -} - -// judgeRequest is the judge's request over the catalogue as the case leaves it: every trunk manifest by its digest, each -// one a pull request touches replaced by the digest its candidate names; touched are the modules whose manifest the -// change adds or changes (a digest the trunk does not hold for it), sorted (novox/hq ADR 0579 §2). -func judgeRequest(trunk, trunkFps map[string]string, pulls []Pull) (req composer.Request, touched []string) { - manifests, before := map[string]composer.Manifest{}, map[string]composer.Manifest{} - for module, digest := range trunk { - if digest != "" { - manifests[module] = composer.Manifest{Digest: digest, Fingerprint: trunkFps[module]} - before[module] = composer.Manifest{Digest: digest, Fingerprint: trunkFps[module]} - } - } - seen := map[string]bool{} - for _, p := range pulls { - for module, cm := range p.Fps { - if cm.Manifest == "" { - continue - } - manifests[module] = composer.Manifest{Digest: cm.Manifest, Fingerprint: cm.Fp2} - if trunk[module] != cm.Manifest { - seen[module] = true - } - } - } - return composer.Request{V: composer.Version, Cases: []composer.Case{{Name: JudgeCase, Manifests: manifests}, - {Name: JudgeTrunk, Manifests: before}}}, slices.Sorted(maps.Keys(seen)) -} - -// judgeManifests runs the indexer's judge over the case's manifests and records its answers as a fact the rules judge -// (rules.JudgeManifests), with the trunk validator's answer on a new indexer (ADR 0633 clause 6). A case that touches no -// manifest, or an examiner that reads no trunk manifests, judges nothing; a judge that cannot be asked or does not answer -// is a failure, said, never a pass. -func (st *state) judgeManifests(ctx context.Context) { - if st.j.Manifests == nil || st.narrowTry() { - return - } - req, touched := judgeRequest(st.j.Manifests.ManifestDigests(), st.j.Manifests.ManifestFingerprints(), st.c.Pulls) - if len(touched) == 0 { - return - } - commit, at := st.judgeHead, "the group's mesh-delivery head "+st.judgeHead - if commit == "" { - if st.j.Trunks != nil { - commit = st.j.Trunks.Heads()[DeliveryRepository] - } - at = "mesh-delivery's trunk " + commit - } - if commit == "" { - st.fail(st.goModule(), "the change's manifests cannot be judged: the trunk head of "+DeliveryRepository+" is not known") - return - } - // The list of predefined keys the manifests are judged against (ADR 0578 §2): the catalogue member's predefined.json - // when the change alters it, else the one the indexer keeps. - if list, from := st.predefinedList(ctx); list != nil { - req.Predefined = list - st.c.note("the manifests are judged against the predefined keys of " + from) - } - req.Packages = st.knownPackages(ctx) - // The heads' seat list, for the change case and the trunk case both (ADR 0636 §4). - req.Seats = st.c.Seats - cv, trunkCase, ok := st.runJudge(ctx, req, touched, commit, at, st.packagesOf(DeliveryRepository)) - if !ok { - return - } - st.judgedVerdicts(cv, at) - m := rules.Manifests{Touched: touched, At: at, Change: cv, Trunk: trunkCase} - if !st.indexerOf(ctx, req, touched, cv, at, &m) { - return - } - st.facts = append(st.facts, rules.Step{Module: st.goModule(), Manifests: &m}) -} - -// runJudge asks the Go build seat to build the judge at the commit and run it over the request, and reads its change and -// trunk cases; false, the failure recorded, when it cannot be asked or does not answer. -func (st *state) runJudge(ctx context.Context, req composer.Request, touched []string, commit, at string, versions buildstep.PackageVersions) (change, trunk composer.CaseVerdict, ok bool) { - raw, err := json.Marshal(req) - if err != nil { - st.fail(st.goModule(), err.Error()) - return change, trunk, false - } - job := buildstep.ComposeJob{Fetch: buildstep.Fetch{Repository: DeliveryRepository, Commit: commit, Dir: JudgeDir, Packages: versions}, Dir: JudgeDir, - Package: JudgePackage, Request: raw, Reader: "the indexer's judge at " + at} - a := buildstep.StepAsk{ID: buildstep.NewID(), Kind: buildstep.AskCheck, Language: buildstep.AskGo, Asker: st.j.Module, - At: st.j.now().UTC(), Compose: &job} - st.c.Progress.Set(fmt.Sprintf("the judge ask %s of the manifests of %s", a.ID, strings.Join(touched, ", ")), "") - st.c.Asked(a.ID) - if err := st.j.Asks.Put(ctx, a); err != nil { - st.fail(st.goModule(), "the judge of the change's manifests could not be asked: "+err.Error()) - return change, trunk, false - } - step, err := st.j.Asks.Wait(ctx, a) - if err != nil { - st.fail(st.goModule(), "the judge of the change's manifests: "+err.Error()) - return change, trunk, false - } - change, trunk, why := judgeAnswer(step) - if why != "" { - st.fail(st.goModule(), fmt.Sprintf("the indexer's judge at %s did not judge the change's manifests: %s", at, why)) - return change, trunk, false - } - return change, trunk, true -} - -// CatalogSeat is the seat the indexer holds (rules.CatalogSeat). -const CatalogSeat = rules.CatalogSeat - -// indexerOf finds the touched module whose manifest claims the seat mesh-catalog, the indexer, and puts in m the trunk's -// manifest validator's change case on it, the one the running parts hold (ADR 0633 clause 6): when the change judges -// with its own head's validator, or at other package versions than the latest published, the trunk's is asked as well. -// False, the failure recorded, when a manifest cannot be read or the trunk's validator cannot be asked. -func (st *state) indexerOf(ctx context.Context, req composer.Request, touched []string, cv composer.CaseVerdict, judgedAt string, m *rules.Manifests) bool { - if st.j.Read == nil { - return true - } - var indexer string - for _, module := range touched { - man, err := st.j.Read.Manifest(ctx, req.Cases[0].Manifests[module].Digest) - if err != nil { - st.fail(st.goModule(), fmt.Sprintf("the manifest of %s cannot be read, so the indexer cannot be ruled out: %v", module, err)) - return false - } - for _, c := range man.Claims { - if c.Name == CatalogSeat { - indexer = module - } - } - } - if indexer == "" { - return true - } - // The validator the running parts hold is the trunk's, built at the latest published versions alone, never at the group's - // heads (ADR 0633 clause 6): a group's mesh-sdk or mesh-contracts head must not change the validator that judges the new - // indexer. The head's run is reused when it was that validator already. - if trunkVersions := st.trunkJudgeVersions(); st.judgeHead != "" || !maps.Equal(st.packagesOf(DeliveryRepository), trunkVersions) { - trunk := "" - if st.j.Trunks != nil { - trunk = st.j.Trunks.Heads()[DeliveryRepository] - } - if trunk == "" { - st.fail(st.goModule(), "the new indexer cannot be judged by the trunk's manifest validator: the trunk head of "+DeliveryRepository+" is not known") - return false - } - judgedAt = "mesh-delivery's trunk " + trunk - var ok bool - if cv, _, ok = st.runJudge(ctx, req, touched, trunk, judgedAt, trunkVersions); !ok { - return false - } - } - m.Indexer, m.IndexerAt, m.OfIndexer = indexer, judgedAt, &cv - return true -} - -// judgeAnswer reads the judge's change and trunk cases from its step, or why it cannot. -func judgeAnswer(step buildstep.Step) (change, trunk composer.CaseVerdict, why string) { - if step.State != buildstep.StepPassed { - return change, trunk, fmt.Sprintf("its step %s: %s", step.State, step.Reason) - } - var a buildstep.ComposeAnswer - if err := json.Unmarshal(step.Result, &a); err != nil { - return change, trunk, "its step's answer cannot be read: " + err.Error() - } - var v composer.Verdict - if err := json.Unmarshal(a.Verdict, &v); err != nil || v.V != composer.Version { - return change, trunk, fmt.Sprintf("its verdict cannot be read (version %d): %v", v.V, err) - } - found := 0 - for _, c := range v.Cases { - switch c.Name { - case JudgeCase: - change, found = c, found+1 - case JudgeTrunk: - trunk, found = c, found+1 - } - } - if found != 2 { - return change, trunk, "its verdict does not hold both the cases " + JudgeCase + " and " + JudgeTrunk - } - return change, trunk, "" -} - -// predefinedList is the list of predefined keys a case's manifests are judged against, and where it comes from: the -// catalogue member's predefined.json at its head when its merge changes it, else the one the indexer keeps; nil when -// neither can be read, said, and the judge then takes each fallback as its value declares it. -func (st *state) predefinedList(ctx context.Context) (catalogue.PredefinedList, string) { - read := func(raw []byte, from string) (catalogue.PredefinedList, string) { - list, err := catalogue.ParsePredefined(raw) - if err != nil { - st.c.note("the predefined keys of " + from + " cannot be read, so fallbacks are judged as their values declare them: " + err.Error()) - return nil, "" - } - return list, from - } - if st.predefinedHead != "" && st.j.Forge != nil { - text, err := st.j.Forge.File(ctx, catalogueRepository, catalogue.PredefinedFile, st.predefinedHead) - if err == nil { - return read([]byte(text), "the catalogue member's head "+st.predefinedHead) - } - st.c.note("the catalogue member's predefined.json cannot be read: " + err.Error()) - } - if st.j.Predefined == nil { - return nil, "" - } - raw, err := st.j.Predefined.PredefinedList(ctx) - if err != nil || raw == nil { - if err != nil { - st.c.note("the indexer's predefined keys cannot be read: " + err.Error()) - } - return nil, "" - } - return read(raw, "the indexer's kept list") -} - -// judgedByMember notes the group's mesh-delivery member head as the judge's when its merge changes the judge, and the -// catalogue member's head as where the predefined keys are read when its merge changes predefined.json. -func (st *state) judgedByMember(p Pull, merged []Fetched) { - if changesJudge(p.Repository, merged) { - st.judgeHead = p.Head - } - if p.Repository == catalogueRepository { - for _, f := range merged { - if slices.Contains(f.Changed, catalogue.PredefinedFile) { - st.predefinedHead = p.Head - } - } - } -} - -// knownPackages are the packages a manifest's `packages` may name, sorted (DLV-I14, design 32): every name the indexer's -// packages state holds, and, of each package a member of the case declares that the state does not know by its -// `/`, the name read at that member's head through the forge (packagename.Of, the indexer's own reader -// at a merge). A name that cannot be read is said and left out, so a manifest naming it is refused naming it. Nil, which -// judges no name, when the checker follows no packages state or has not read it yet (PackageNames nil); an answered -// state that holds no name is an empty list, never nil, so every name is judged against it. -func (st *state) knownPackages(ctx context.Context) []string { - if st.j.KnownPackages == nil { - return nil - } - names := st.j.KnownPackages.PackageNames() - if names == nil { - return nil - } - built := map[string]bool{} - for _, b := range names { - built[b] = true - } - known := make([]string, 0, len(names)) - known = append(known, slices.Collect(maps.Keys(names))...) - declared, err := st.declaredPackages(ctx) - if err != nil { - st.c.note("the packages the group's members declare are not known, so only the packages state's names are known to the judge: " + err.Error()) - } - for _, d := range declared { - if built[d.module+"/"+d.name] { - continue - } - if st.j.Forge == nil { - st.c.note(fmt.Sprintf("the name of the package %s/%s new in the group is not read: this checker reads no forge", d.module, d.name)) - continue - } - read := func(ctx context.Context, repository, commit, file string) ([]byte, error) { - text, err := st.j.Forge.File(ctx, repository, file, commit) - if errors.Is(err, ErrNotFound) { - return nil, nil - } - return []byte(text), err - } - dirs := []string{d.dir} - if d.dir == "" { - dirs = []string{"modules/" + d.module, meshcatalogclient.RootPath} - } - var why []string - for _, dir := range dirs { - a := catalogue.Artifact{Name: d.name, Kind: catalogue.ArtifactPackage, Language: d.language, Paths: d.paths} - name, err := packagename.Of(ctx, read, d.pull.Repository, d.pull.Head, dir, a) - if err == nil { - known, why = append(known, name), nil - break - } - why = append(why, err.Error()) - } - if len(why) > 0 { - st.c.note(fmt.Sprintf("the name of the package %s/%s new in the group is not read at the head of %s: %s", d.module, d.name, pullKey(d.pull), strings.Join(why, "; "))) - } - } - slices.Sort(known) - return slices.Compact(known) -} - -// trunkJudgeVersions are the versions the trunk's manifest validator is built at: the latest published version of each -// package, with no group member's head (ADR 0633 clause 6). -func (st *state) trunkJudgeVersions() buildstep.PackageVersions { - return packagesFor(st.j.Published, &Case{}, DeliveryRepository) -} - -// judgedVerdicts puts the check's own judge's verdict on each manifest the change brings on the case, as the seat -// mesh-catalog's verdict value, for the composer's request (ADR 0578 §2, §3; F5 of milestone 47/G): accepted, or refused -// with its words; a manifest the judge gave no verdict on carries none, which the composer reads as accepted. -func (st *state) judgedVerdicts(cv composer.CaseVerdict, at string) { - for _, p := range st.c.Pulls { - for name, fp := range p.Fps { - read, ok := cv.Manifests[name] - if fp.Manifest == "" || !ok || (!read.Accepted && read.Refused == "") { - continue - } - v := meshcatalog.VerdictsByDigestValue{Module: name, State: meshcatalogclient.VerdictAccepted, Judge: at} - if !read.Accepted { - v.State, v.Problems = meshcatalogclient.VerdictRefused, []string{read.Refused} - } - raw, err := json.Marshal(v) - if err != nil { - continue - } - if st.c.Judged == nil { - st.c.Judged = map[string]json.RawMessage{} - } - st.c.Judged[name] = raw - } - } -} diff --git a/modules/mesh-delivery-checker/internal/check/manifests_judge_test.go b/modules/mesh-delivery-checker/internal/check/manifests_judge_test.go deleted file mode 100644 index edf3ae6a..00000000 --- a/modules/mesh-delivery-checker/internal/check/manifests_judge_test.go +++ /dev/null @@ -1,23 +0,0 @@ -package check - -import ( - "reflect" - "testing" - - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/composer" -) - -// Design 47 G A-310: a manifest the judge's request names by its digest names the fingerprint whose catalog graph entry holds -// it: a pull's own fingerprint for a module the pull changes, the trunk revision's entry for the rest. -func TestTheJudgeRequestNamesEachManifestsFingerprint(t *testing.T) { - pull := Pull{Fps: map[string]meshcatalog.CandidatesByGroupValuePullsItemFpsValue{"changed": {Manifest: "d2", Fp2: "src2:pull"}}} - req, _ := judgeRequest(map[string]string{"changed": "d1", "same": "d3"}, map[string]string{"changed": "src2:trunk", "same": "src2:same"}, []Pull{pull}) - got, trunk := req.Cases[0].Manifests, req.Cases[1].Manifests - if !reflect.DeepEqual(got["changed"], composer.Manifest{Digest: "d2", Fingerprint: "src2:pull"}) || !reflect.DeepEqual(got["same"], composer.Manifest{Digest: "d3", Fingerprint: "src2:same"}) { - t.Errorf("the change's manifests = %+v", got) - } - if !reflect.DeepEqual(trunk["changed"], composer.Manifest{Digest: "d1", Fingerprint: "src2:trunk"}) { - t.Errorf("the trunk's manifest = %+v, want the trunk entry's fingerprint", trunk["changed"]) - } -} diff --git a/modules/mesh-delivery-checker/internal/check/names.go b/modules/mesh-delivery-checker/internal/check/names.go deleted file mode 100644 index 18c199f8..00000000 --- a/modules/mesh-delivery-checker/internal/check/names.go +++ /dev/null @@ -1,83 +0,0 @@ -package check - -import ( - "git.novox.be/novox/mesh-contracts/go/seats/nodeengine" - "git.novox.be/novox/mesh-contracts/health-and-repair/go/seats/meshwatchdogs" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog" - checker "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshdeliverychecker" -) - -// The holders and buckets the checker names. No contract names a holder (novox/hq ADR 0625 §4, ADR 0634 §1), so these are its -// own constants, each a state of a seat (the seat's state name beside the holder's module name) and each declared in its -// manifest (module.json: its own states, its `reads`); a unit row checks them against the manifest (TestTheNamesAreTheManifests). -const ( - // GateModule holds the seat mesh-delivery's states source and turns, which the checker reads (reads: mesh-delivery-gate.source, - // mesh-delivery-gate.turns). - GateModule = "mesh-delivery-gate" - - // IndexerModule holds the seat mesh-catalog's states, which the checker follows by their views (consumes: - // mesh-delivery-indexer.views.*). - IndexerModule = "mesh-delivery-indexer" - CandidatesBucket = IndexerModule + "_" + meshcatalog.StateCandidates - ModulesBucket = IndexerModule + "_" + meshcatalog.StateModules - ManifestsBucket = IndexerModule + "_" + meshcatalog.StateManifests - IndexerPredefinedState = meshcatalog.StatePredefined - - // WatchmanModule holds the seat mesh-watchdogs' presence (reads: mesh-delivery-watchman.presence). - WatchmanModule = "mesh-delivery-watchman" - PresenceBucket = WatchmanModule + "_" + meshwatchdogs.StatePresence - - // HaveBucket is the node-engine's state have (reads: node-engine.have); a node's own key ends in HaveNodeWord. - HaveBucket = "node-engine_" + nodeengine.StateHave - HaveNodeWord = "node" - - // compositionWaits is the state of the assigner's composition answer that waits for what it composes from. - compositionWaits = "waits" -) - -// FailedFirst names what failed: a test (its package and name) or a machine, with the words of the failure. It is the shape of -// the verdict's `failed` and of each entry of its `failures` (the seat's two types of it have the same fields), so the check -// judges with one and converts at the verdict's edge (failureItems, failedList). -type FailedFirst = checker.VerdictsByGroupHeadsValueFailed - -// failedOf is the first failure a verdict names: the zero value of a verdict that names none. -func failedOf(v checker.VerdictsByGroupHeadsValue) FailedFirst { - if v.Failed == nil { - return FailedFirst{} - } - return *v.Failed -} - -// tookOf is the time of each part of a check a verdict names: the zero value of a verdict that names none. -func tookOf(v checker.VerdictsByGroupHeadsValue) checker.VerdictsByGroupHeadsValueTook { - if v.Took == nil { - return checker.VerdictsByGroupHeadsValueTook{} - } - return *v.Took -} - -func failureItems(list []FailedFirst) []checker.VerdictsByGroupHeadsValueFailuresItem { - if list == nil { - return nil - } - out := make([]checker.VerdictsByGroupHeadsValueFailuresItem, len(list)) - for i, f := range list { - out[i] = checker.VerdictsByGroupHeadsValueFailuresItem(f) - } - return out -} - -func failedList(items []checker.VerdictsByGroupHeadsValueFailuresItem) []FailedFirst { - if items == nil { - return nil - } - out := make([]FailedFirst, len(items)) - for i, f := range items { - out[i] = FailedFirst(f) - } - return out -} - -// Bucket is the bucket of one of the checker's own states, `_`, module its credential's, never a constant -// (design 47 G A-296, §428). -func Bucket(module, state string) string { return module + "_" + state } diff --git a/modules/mesh-delivery-checker/internal/check/owed.go b/modules/mesh-delivery-checker/internal/check/owed.go deleted file mode 100644 index 4de3ad97..00000000 --- a/modules/mesh-delivery-checker/internal/check/owed.go +++ /dev/null @@ -1,49 +0,0 @@ -package check - -import ( - "fmt" - - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshdeliveryclient" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshdelivery" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshdeliverychecker" -) - -// The checker's owed state holds the one act it owes, the status mesh/check on a pull request at a head: the gate's owed act -// with the context mesh/check. Its value has the shape of the gate's (the seat mesh-delivery's owed), so its rules and its -// codec are the mesh-delivery client's; only the checker reads it, so the checker's own narrowing to its one act lives here. - -// CheckerOwedAct is the act the checker owes. -const CheckerOwedAct = meshdeliveryclient.OwedStatus + "=" + meshdeliveryclient.StatusContextCheck - -// CheckerOwedKey is the key, in the checker's owed state, of the status the checker owes on a pull request at a head. -func CheckerOwedKey(repository string, number int, head string) (string, error) { - return meshdeliveryclient.OwedKey(repository, number, head, CheckerOwedAct) -} - -func checkCheckerOwed(o meshdeliverychecker.OwedByRepositoryNumberHeadActValue) error { - if o.Act != meshdeliveryclient.OwedStatus || o.Context != meshdeliveryclient.StatusContextCheck { - return fmt.Errorf("the checker owes only a status with the context %s, not the act %q with the context %q", meshdeliveryclient.StatusContextCheck, o.Act, o.Context) - } - return nil -} - -// EncodeCheckerOwed is o as the gate's owed value, refused for any act but the checker's status. -func EncodeCheckerOwed(o meshdeliverychecker.OwedByRepositoryNumberHeadActValue) ([]byte, error) { - if err := checkCheckerOwed(o); err != nil { - return nil, err - } - return meshdeliveryclient.EncodeOwed(meshdelivery.OwedByRepositoryNumberHeadActValue(o)) -} - -// DecodeCheckerOwed reads an owed act of the checker's state. -func DecodeCheckerOwed(data []byte) (meshdeliverychecker.OwedByRepositoryNumberHeadActValue, error) { - g, err := meshdeliveryclient.DecodeOwed(data) - if err != nil { - return meshdeliverychecker.OwedByRepositoryNumberHeadActValue{}, err - } - o := meshdeliverychecker.OwedByRepositoryNumberHeadActValue(g) - if err := checkCheckerOwed(o); err != nil { - return meshdeliverychecker.OwedByRepositoryNumberHeadActValue{}, err - } - return o, nil -} diff --git a/modules/mesh-delivery-checker/internal/check/package_cause_test.go b/modules/mesh-delivery-checker/internal/check/package_cause_test.go deleted file mode 100644 index 7922e012..00000000 --- a/modules/mesh-delivery-checker/internal/check/package_cause_test.go +++ /dev/null @@ -1,109 +0,0 @@ -package check - -import ( - "mesh-delivery-checker/rules" - "strings" - "testing" -) - -// What the build module before this fix sent for two packages that failed after their tests passed (issue 1901, its third -// meeting: a try of mesh-controller kept "PASS" as its failure's words). Each is that build module's Output for the real -// `go test -json` of a throwaway package (mesh-catalog modules/mesh-build-go testdata/captured/go-test-json-pkg-*.jsonl): -// TestMain panicking in a goroutine after m.Run, TestMain exiting 2 after m.Run, and TestMain racing after m.Run. -const ( - oldPassThenPanic = "PASS\npanic: the bus closed after the tests: nats: connection closed\ngoroutine 20 [running]:\n" + - "example.com/passthenfail.TestMain.func1()\n\t/tmp/fix-1901b/passthenfail/p_test.go:13 +0x25\n" + - "created by example.com/passthenfail.TestMain in goroutine 1\n\t/tmp/fix-1901b/passthenfail/p_test.go:13 +0x25\n" + - "FAIL\texample.com/passthenfail\t0.005s" - oldPassThenExit = "PASS\nFAIL\texample.com/mainexit\t0.004s" - // TestMain racing after m.Run passed, under go test -race (go-test-json-pkg-racemain.jsonl). - oldPassThenRace = "PASS\n==================\nWARNING: DATA RACE\nWrite at 0x000000836428 by goroutine 9:\n example.com/racemain.TestMain.func1()\n /tmp/fix-1901b/racemain/p_test.go:15 +0x24\nPrevious write at 0x000000836428 by main goroutine:\n example.com/racemain.TestMain()\n /tmp/fix-1901b/racemain/p_test.go:16 +0x44\n main.main()\n _testmain.go:48 +0x171\nGoroutine 9 (running) created at:\n example.com/racemain.TestMain()\n /tmp/fix-1901b/racemain/p_test.go:15 +0x37\n main.main()\n _testmain.go:48 +0x171\n==================\nFound 1 data race(s)\nFAIL\texample.com/racemain\t1.031s" -) - -// A package's failure is worded by its cause, cut to its bound, and never as pass (issue 1901, AC5). -func TestAPackageFailuresCauseIsWordedNeverPass(t *testing.T) { - for _, row := range []struct { - name string - test func(t *testing.T) - }{ - // A failure with no cause told apart never has "PASS" or "ok" as its words: the checker takes the panic line from the - // output, or says that the tests passed and the program failed after them (1901/AC5). - {"a package failure is never worded pass", func(t *testing.T) { // 1901/AC5 - cases := []struct { - name, output, want string - }{ - {"panic after the tests", oldPassThenPanic, "panic: the bus closed after the tests: nats: connection closed"}, - {"exit after the tests", oldPassThenExit, "the tests passed, then the test program exited with a failure"}, - {"race after the tests", oldPassThenRace, "WARNING: DATA RACE: Write at 0x000000836428 by goroutine 9 in example.com/racemain.TestMain.func1()"}, - {"a panic deep in a long output", "PASS\npanic: the seat row vanished\n" + strings.Repeat("goroutine 7 [chan receive]:\n\tsome/frame.go:1 +0x1\n", 300) + "FAIL\tp\t2.0s", "panic: the seat row vanished"}, - } - for _, c := range cases { - t.Run(c.name, func(t *testing.T) { - v := rules.LevelFailure("", "", "", "integration", Tested{Failed: []Failure{{Package: "github.com/novox/mesh-controller/cmd/mesh-controller", Output: c.output}}}) - for _, l := range strings.Split(v.Failed.Words, "\n") { - if l = strings.TrimSpace(l); l == "PASS" || strings.HasPrefix(l, "ok ") || strings.HasPrefix(l, "ok\t") { - t.Errorf("1901/AC5: the words keep %q: %q", l, v.Failed.Words) - } - } - if !strings.HasPrefix(afterHid(v.Failed.Words), c.want) { - t.Errorf("1901/AC5: words after the loud line start %q, want %q", rules.FirstLine(afterHid(v.Failed.Words)), c.want) - } - if got := firstFailed(*v); !strings.Contains(got, "the build module hid the failure") || strings.HasSuffix(got, ": PASS") { - t.Errorf("1901/AC5, AC8: status = %q", got) - } - }) - } - }}, - // A cause the build module told apart is cut to a line's bound, so the words keep their bound (the 1901 review's note). - {"a long cause is cut to a lines bound", func(t *testing.T) { // 1901/AC5 - f := Failure{Package: "p", Test: "TestX", Cause: strings.Repeat("c", 5000), Output: "x_test.go:1: something"} - v := rules.LevelFailure("", "", "", "unit", Tested{Failed: []Failure{f}}) - if len(v.Failed.Words) > rules.MaxWords+200 { - t.Errorf("1901/AC5: words are %d bytes, bound %d", len(v.Failed.Words), rules.MaxWords) - } - }}, - // The build module on main sends a package that stopped (a timeout, an exit, a kill) as only go test's last line, with no - // cause: the words then say so, never nothing (review round 1). Each output is what that build module sends for the - // capture of the same name (go-test-json-pkg-timeout, -exiting, -killed): the package's own output, its "FAIL" line. - {"a package stopped with only its fail line is still worded", func(t *testing.T) { // 1901/AC5 - for _, out := range []string{"FAIL\texample.com/timeout\t2.017s", "FAIL\texample.com/exiting\t0.006s", "FAIL\texample.com/killed\t0.006s"} { - v := rules.LevelFailure("", "", "", "integration", Tested{Failed: []Failure{{Package: "example.com/x", Output: out}}}) - if !strings.HasPrefix(afterHid(v.Failed.Words), "the package failed with no test to name and no panic, signal or build error in its output") { - t.Errorf("1901/AC5: %q is worded %q", out, v.Failed.Words) - } - } - }}, - // A line of the test's own that starts as go's summary does, or that holds a runtime's words indented, is not taken for - // either (review round 1): go prints its summary in exact forms and the runtime's lines at column 0. - {"only gos exact forms are summary or cause", func(t *testing.T) { // 1901/AC5 - out := " x_test.go:3: ok so far\nok then: the seat is free\n panic: child retried and recovered\npanic: the real one\nFAIL\tp\t1.0s" - v := rules.LevelFailure("", "", "", "unit", Tested{Failed: []Failure{{Package: "p", Output: out}}}) - if !strings.HasPrefix(afterHid(v.Failed.Words), "panic: the real one") || !strings.Contains(v.Failed.Words, "ok then: the seat is free") { - t.Errorf("1901/AC5: words = %q", v.Failed.Words) - } - }}, - // The words keep rules.MaxWords exactly, counting the cause, the marker and the newlines (review round 1). - {"the words keep their bound exactly", func(t *testing.T) { // 1901/AC5 - for _, cause := range []string{"", "a cause", strings.Repeat("c", 3000)} { - for _, n := range []int{100, 170, 171, 172, 500} { - f := Failure{Package: "p", Test: "TestX", Cause: cause, Output: strings.Repeat("a log line of twenty\n", n) + "the end"} - if w := rules.FailureWords(f); len(w) > rules.MaxWords { - t.Errorf("1901/AC5: cause %d bytes, %d lines: words are %d bytes, bound %d", len(cause), n, len(w), rules.MaxWords) - } - } - } - }}, - } { - t.Run(row.name, row.test) - } -} - -// afterHid is a verdict's words after the checker's loud line, which a failure with no cause from an older build module -// now starts with (1901/AC8). -func afterHid(w string) string { - if strings.HasPrefix(w, "the build module hid the failure") { - _, rest, _ := strings.Cut(w, "\n") - return rest - } - return w -} diff --git a/modules/mesh-delivery-checker/internal/check/pins.go b/modules/mesh-delivery-checker/internal/check/pins.go deleted file mode 100644 index 277bedc5..00000000 --- a/modules/mesh-delivery-checker/internal/check/pins.go +++ /dev/null @@ -1,76 +0,0 @@ -package check - -import ( - "context" - "errors" - "maps" - - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/grouppackages" -) - -// **A check builds against the group's own package heads, not against what a member names** (novox/hq ADR 0573 §2, §4; -// issue 1585). Every Go check ask carries the version of each mesh package to build against (buildstep.StepAsk.Packages): -// the head of the group's member that publishes it, else its latest published version as the indexer holds it. The build -// module writes them into the workspace, whatever version or commit a member's go.mod names, so no member is refused -// for naming no version of the group's package, an older head of it, a merge commit or a commit on no pull request: that -// refusal (issue 1624's pin check) was a fault of the check (§4), and is gone. - -// SDKRepository is the repository of mesh-sdk, and SDKModulePath its Go module. -const ( - SDKRepository = "novox/mesh-sdk" - SDKModulePath = "git.novox.be/novox/mesh-sdk/go" -) - -// ErrNotFound is what Forge.File wraps when the ref holds no such file (the forge answered 404): a file the ref does not hold, -// told from a forge that could not be read (issue 1845). -var ErrNotFound = errors.New("the ref holds no such file") - -// Forge reads a file of a repository at a ref. -type Forge interface { - // File is the text of a file at a ref (a branch, a tag or a commit). - File(ctx context.Context, repository, path, ref string) (string, error) -} - -// packagesOf is the version of each mesh package a Go build of repository (a check ask, the judge, the composer) builds -// against (ADR 0573 §2, §4, as ADR 0607 §5 changes §4): packagesFor over the latest published version of each package the -// mesh's modules use (Published) and the heads of the case's pull requests. Nil for none. -func (st *state) packagesOf(repository string) buildstep.PackageVersions { - return packagesFor(st.j.Published, st.c, repository) -} - -// packagesFor is packagesOf for a case and the published versions: every producer of a build at a group's heads takes its -// versions from here, so none leaves a member out (issue 1921). grouppackages.Heads names each package at its member's -// head, also a member that publishes no package yet. A package of repository itself comes with the tree the build -// fetched, and is left out. -func packagesFor(published interface { - LatestPackages() buildstep.PackageVersions -}, c *Case, repository string) buildstep.PackageVersions { - latest := buildstep.PackageVersions{} - if published != nil { - maps.Copy(latest, published.LatestPackages()) - } - heads := map[string]string{} - for _, m := range c.Pulls { - heads[m.Repository] = m.Head - } - versions := grouppackages.Heads(latest, heads, repository) - return versions -} - -// unheardWords ends the words of a failed read of the forge that reached nobody: the forge was not heard (UnheardWords). -func unheardWords(err error) string { - if isUnheard(err) { - return " (the forge was " + UnheardWords + ")" - } - return "" -} - -// forgeMachine is the machine a failed read of the forge is put at: the forge when nobody answered it (no build node is to -// blame, issue 1820), the build node whose workspace was read otherwise. -func forgeMachine(err error, node string) string { - if isUnheard(err) { - return "forge" - } - return node -} diff --git a/modules/mesh-delivery-checker/internal/check/pins_test.go b/modules/mesh-delivery-checker/internal/check/pins_test.go deleted file mode 100644 index e7cc68d2..00000000 --- a/modules/mesh-delivery-checker/internal/check/pins_test.go +++ /dev/null @@ -1,301 +0,0 @@ -package check - -import ( - "context" - "maps" - "slices" - "strings" - "testing" - - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshdeliverycheckerclient" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep" - "git.novox.be/novox/mesh-delivery/modules/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 " "; 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/. -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/modules/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) - } -} diff --git a/modules/mesh-delivery-checker/internal/check/preview.go b/modules/mesh-delivery-checker/internal/check/preview.go deleted file mode 100644 index 8cb11808..00000000 --- a/modules/mesh-delivery-checker/internal/check/preview.go +++ /dev/null @@ -1,87 +0,0 @@ -package check - -import ( - "context" - "errors" - "fmt" - "regexp" - "slices" - - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshdeliverycheckerclient" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshdeliverychecker" -) - -var digest64 = regexp.MustCompile(`^[0-9a-f]{64}$`) - -// PreviewOf is what the fetch steps said of a pull request's head merged onto its trunk head, as the value of a previews -// key (ADR 0484 clause 3): the merge commit and, for each module directory the fetches named with a manifest, its tree, the -// digest of its manifest, the hashes of its lock files and its named paths' objects (ADR 0499 clause 2). The fetches of the repository's build modules merge the same -// trees; the first one's merge commit is kept. A module directory with no tree or no manifest digest is left out, so the -// indexer gives its module no fingerprint and says why. A head that does not merge has a preview of the files in conflict -// alone, so the indexer says the candidate's modules have no fingerprint because it does not merge (issue 1445). It -// answers false when no fetch was made. -func PreviewOf(p Pull, fetched []Fetched) (meshdeliverychecker.PreviewsByRepositoryHeadTrunkValue, bool) { - var merge string - var conflicts []string - mods := map[string]meshdeliverychecker.PreviewsByRepositoryHeadTrunkValueModulesValue{} - for _, f := range fetched { - if len(f.Conflicts) > 0 { - conflicts = append(conflicts, f.Conflicts...) - } - } - if len(conflicts) > 0 { - slices.Sort(conflicts) - return meshdeliverychecker.PreviewsByRepositoryHeadTrunkValue{Repository: p.Repository, Head: p.Head, Trunk: p.Trunk, Conflicts: slices.Compact(conflicts)}, true - } - for _, f := range fetched { - if f.Merge == "" { - continue - } - if merge == "" { - merge = f.Merge - } - for dir, t := range f.Trees { - if t.Tree == "" || !digest64.MatchString(t.Manifest) { - continue - } - mods[dir] = meshdeliverychecker.PreviewsByRepositoryHeadTrunkValueModulesValue{Tree: t.Tree, Manifest: t.Manifest, Locks: t.Locks, Paths: t.Paths, Packages: t.Packages} - } - } - if merge == "" { - return meshdeliverychecker.PreviewsByRepositoryHeadTrunkValue{}, false - } - pv := meshdeliverychecker.PreviewsByRepositoryHeadTrunkValue{Repository: p.Repository, Head: p.Head, Trunk: p.Trunk, Merge: merge} - if len(mods) > 0 { - pv.Modules = mods - } - return pv, true -} - -// writePreview writes the preview of a pull request by a create: one writer per key, and the same head on the same trunk -// head merges to the same trees, so a key that exists stands. A head that did not merge has no preview. A failure is said -// and does not fail the check: the preview is for the indexer's fingerprints, not for the verdict. -func (j *Examiner) writePreview(ctx context.Context, p Pull, fetched []Fetched) { - if j.Previews == nil { - return - } - pv, ok := PreviewOf(p, fetched) - if !ok { - return - } - key, err := meshdeliverycheckerclient.PreviewKey(p.Repository, p.Head, p.Trunk) - if err == nil { - var data []byte - if data, err = meshdeliverycheckerclient.EncodePreview(pv); err == nil { - _, err = j.Previews.Create(ctx, key, data) - if errors.Is(err, ErrConflict) { - return - } - if err == nil && j.Announce != nil { - j.Announce(ctx, EventPreviewWritten, key) - } - } - } - if err != nil { - j.logf("%s#%d: the preview cannot be written: %v", p.Repository, p.Number, fmt.Errorf("%w", err)) - } -} diff --git a/modules/mesh-delivery-checker/internal/check/preview_named_test.go b/modules/mesh-delivery-checker/internal/check/preview_named_test.go deleted file mode 100644 index ebd968a2..00000000 --- a/modules/mesh-delivery-checker/internal/check/preview_named_test.go +++ /dev/null @@ -1,24 +0,0 @@ -package check - -import ( - "encoding/json" - "reflect" - "testing" -) - -// I8, ADR 0499 clause 2: the preview carries each named path's object a fetch's module trees answer (mesh-sdk -// buildstep.ModuleTree's paths), so the indexer computes the candidate's narrowed tree from them by the one function. -func TestAPreviewCarriesTheNamedPathsObjectsOfAFetchsModuleTrees(t *testing.T) { - var f Fetched - // As buildstep.ModuleTrees answers a module naming its paths: the named tree and the objects. - raw := `{"workspace":"w","merge":"6666666666666666666666666666666666666666","trees":{".":{"tree":"named:aa","manifest":"` + - "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" + `","paths":{"src":"1111111111111111111111111111111111111111"},"packages":["git.novox.be/novox/mesh-sdk/go"]}}}` - if err := json.Unmarshal([]byte(raw), &f); err != nil { - t.Fatal(err) - } - pv, ok := PreviewOf(Pull{Repository: "novox/mesh-sdk", Head: "h", Trunk: "t"}, []Fetched{f}) - if !ok || !reflect.DeepEqual(pv.Modules["."].Paths, map[string]string{"src": "1111111111111111111111111111111111111111"}) || pv.Modules["."].Tree != "named:aa" || - !reflect.DeepEqual(pv.Modules["."].Packages, []string{"git.novox.be/novox/mesh-sdk/go"}) { // and the packages it uses (issue 1585) - t.Errorf("preview = %+v, want the module's named tree and its objects", pv) - } -} diff --git a/modules/mesh-delivery-checker/internal/check/programs.go b/modules/mesh-delivery-checker/internal/check/programs.go deleted file mode 100644 index 56bfc134..00000000 --- a/modules/mesh-delivery-checker/internal/check/programs.go +++ /dev/null @@ -1,294 +0,0 @@ -package check - -import ( - "context" - "encoding/json" - "fmt" - "maps" - "slices" - "strings" - "sync" - "time" - - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshdeliverycheckerclient" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshdeliverychecker" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep" - - "mesh-delivery-checker/rules" - - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-builder/buildrun" -) - -// The checking program (novox/hq ADR 0644 §1, ADR 0656 §5; design 47's bootstrap delivery; issue 1921): every check has -// the program built from the group's mesh-delivery member head, else from mesh-delivery's trunk, and run in the build -// seat's sandbox through the seat node-build-go's ask `run`, with every member's head laid for it. It answers the heads' -// seat list first (`-seats`), which the manifest validator's and the composer's requests carry, and then the check's -// verdict of the facts the asking gathered (`-verdict`). The running checker asks, keeps and records; it judges nothing. - -const ( - // InputsStateName is the checker's own state of run inputs and InputsBucket its bucket: every input by the sha256 of - // its exact bytes, read by the checker alone. InputVerb is the seat verb a run ask's input names - // (buildstep.RunInput.Verb), which the checker's tools serve from that state (Reader.Input): the Go build module asks it - // as its manifest's invokes grants it and checks the digest (buildstep.RunInput.Read), never reading the state (ADR 0596 - // §2; the operator's answer on milestone 47/B0). - InputsStateName = "inputs" - InputVerb = meshdeliverycheckerclient.InputVerb - // CheckingProgramDir and CheckingProgramPackage are where in mesh-delivery the checking program is built. - CheckingProgramDir = "modules/mesh-delivery-checker" - CheckingProgramPackage = "mesh-delivery-checker/cmd/mesh-checking-program" - // DefaultBeginBound is how long a run ask may wait for a build node to begin its step before it is put once more, and - // after that once more before the check fails naming the job: a build module that does not know the job `run` drops - // it unanswered (the lead's ruling on milestone 47/B0, 2026-11-06). - DefaultBeginBound = 5 * time.Minute -) - -// Inputs keeps a run's input under its digest, exactly its bytes. -type Inputs interface { - Keep(ctx context.Context, digest string, body []byte) error -} - -func (j *Examiner) beginBound() time.Duration { - if j.BeginBound > 0 { - return j.BeginBound - } - return DefaultBeginBound -} - -// checkingProgram is where this check's checking program is built: the group's mesh-delivery member head, else -// mesh-delivery's trunk; false when neither is known. -func (st *state) checkingProgram() (buildstep.RunProgram, string, bool) { - p := buildstep.RunProgram{Repository: DeliveryRepository, Dir: CheckingProgramDir, Package: CheckingProgramPackage} - for _, pull := range st.c.Pulls { - if pull.Repository == DeliveryRepository { - p.Commit = pull.Head - return p, "the group's mesh-delivery head " + pull.Head, true - } - } - if st.j.Trunks != nil { - p.Commit = st.j.Trunks.Heads()[DeliveryRepository] - } - return p, "mesh-delivery's trunk " + p.Commit, p.Commit != "" -} - -// runHeads are the members' heads, as the program reads them. -func (st *state) runHeads() []buildstep.RunHead { - out := make([]buildstep.RunHead, 0, len(st.c.Pulls)) - for _, p := range st.c.Pulls { - out = append(out, buildstep.RunHead{Repository: p.Repository, Commit: p.Head}) - } - return out -} - -// runProgram has the checking program built and run with args over body, and answers its output and what judged; an -// error says why it did not answer: its input over its bound, no build node beginning the job, a step that did not -// pass, or a program that exited otherwise than 0. -func (st *state) runProgram(ctx context.Context, args []string, body []byte) (json.RawMessage, *meshdeliverychecker.VerdictsByGroupHeadsValueJudgedBy, error) { - prog, at, ok := st.checkingProgram() - if !ok { - return nil, nil, fmt.Errorf("it cannot be built: the trunk head of %s is not known", DeliveryRepository) - } - if st.j.Inputs == nil { - return nil, nil, fmt.Errorf("its input cannot be kept: the checker keeps no state %s", InputsStateName) - } - in, err := buildstep.RunInputOf(InputVerb, body) - if err != nil { - return nil, nil, err - } - if err := st.j.Inputs.Keep(ctx, in.Digest, body); err != nil { - return nil, nil, fmt.Errorf("its input could not be kept in %s: %w", InputsStateName, err) - } - job := buildstep.RunJob{Program: prog, Heads: st.runHeads(), Input: in, Args: args, Reader: "the checking program at " + at} - var ids []string - for range 2 { - a := buildstep.StepAsk{ID: buildstep.NewID(), Kind: buildstep.AskCheck, Language: buildstep.AskGo, Asker: st.j.Module, - At: st.j.now().UTC(), Packages: st.packagesOf(DeliveryRepository), Run: &job} - ids = append(ids, a.ID) - st.c.Progress.Set(fmt.Sprintf("the run ask %s of the checking program %s", a.ID, strings.Join(args, " ")), "") - st.c.Asked(a.ID) - if err := st.j.Asks.Put(ctx, a); err != nil { - return nil, nil, fmt.Errorf("its run ask could not be put: %w", err) - } - waiting := ctx - if watch := st.c.Watch; watch != nil { - id := a.ID - watch(id, nil) // a try names it at once (issue 1890) - waiting = buildrun.WithStepSeen(ctx, func(s buildstep.Step) { watch(id, &s) }) - } - step, begun, err := st.waitBegun(waiting, a) - if !begun { - continue - } - if err != nil { - return nil, nil, fmt.Errorf("its run ask %s: %w", a.ID, err) - } - var answer buildstep.RunAnswer - if step.State != buildstep.StepPassed { - // A run whose program exited other than 0 ends its key failed with its answer kept (design 47 G A-290). - if json.Unmarshal(step.Result, &answer) == nil && answer.Exit != 0 { - return nil, nil, fmt.Errorf("it exited %d on %s: %s", answer.Exit, step.Node, answer.Said) - } - return nil, nil, fmt.Errorf("its run ask %s ended %s on %s: %s", a.ID, step.State, step.Node, step.Reason) - } - if err := json.Unmarshal(step.Result, &answer); err != nil { - return nil, nil, fmt.Errorf("its run ask %s answered no run answer: %w", a.ID, err) - } - if answer.Exit != 0 { - return nil, nil, fmt.Errorf("it exited %d on %s: %s", answer.Exit, step.Node, answer.Said) - } - return answer.Output, judgedByOf(prog, answer, job.Heads), nil - } - return nil, nil, fmt.Errorf("no build node began the job run of the asks %s within %s each: a build module that does not know the job run drops it", - strings.Join(ids, " and "), st.j.beginBound()) -} - -// waitBegun waits for a's step, and stops waiting, begun false, when no build node began it within the begin bound: a -// bound on the wait's context, no timer of its own. -func (st *state) waitBegun(ctx context.Context, a buildstep.StepAsk) (buildstep.Step, bool, error) { - wait, cancel := context.WithCancel(ctx) - defer cancel() - begin, stop := context.WithTimeout(ctx, st.j.beginBound()) - defer stop() - seen := make(chan struct{}) - var once sync.Once - type ended struct { - step buildstep.Step - err error - } - done := make(chan ended, 1) - go func() { - step, err := st.j.Asks.Wait(buildrun.WithStepSeen(wait, func(buildstep.Step) { once.Do(func() { close(seen) }) }), a) - done <- ended{step, err} - }() - select { - case e := <-done: - return e.step, true, e.err - case <-seen: - case <-begin.Done(): - if ctx.Err() != nil { - return buildstep.Step{}, true, ctx.Err() - } - return buildstep.Step{}, false, nil - } - e := <-done - return e.step, true, e.err -} - -// seatList asks the checking program for the heads' seat list, which the validator's and the composer's requests carry -// (ADR 0636 §4); the list and what it left out are the check's notes. A list it cannot make fails the check, naming why, -// and answers false: the check ends there, with no verdict asked of a program that could not answer its list (review -// round 1 of milestone 47/B0: a build node with no job run would hold the check two begin bounds more). -func (st *state) seatList(ctx context.Context) bool { - if st.narrowTry() { - return true - } - // The list the checker's reader holds from the seat mesh-catalog: a reader that has not read it acts on nothing new - // (ADR 0636 §1), so the check ends here, said. - var base []json.RawMessage - if st.j.SeatList != nil { - defs, err := st.j.SeatList.Definitions() - if err != nil { - st.fail(st.goModule(), "the change's manifests cannot be judged: the seat list is not read ("+err.Error()+")") - return false - } - base = defs - } - // The program answers only the heads' definitions the list does not hold as they are: the list's digests ride in its - // input, never the list, whose definitions are larger than a run's input or answer may be (review finding 3 of G). - head := st.factsHead() - if len(base) > 0 { - head.SeatDigests = map[string]string{} - for _, raw := range base { - var d struct { - Seat string `json:"seat"` - } - if json.Unmarshal(raw, &d) == nil && d.Seat != "" { - head.SeatDigests[d.Seat] = rules.SeatDigest(raw) - } - } - } - body, err := json.Marshal(head) - if err == nil { - var out json.RawMessage - if out, _, err = st.runProgram(ctx, []string{"-seats"}, body); err == nil { - var a rules.SeatsAnswer - if err = json.Unmarshal(out, &a); err == nil && a.V != rules.SeatsVersion { - err = fmt.Errorf("it answered a seat list of version %d, not %d", a.V, rules.SeatsVersion) - } - if err == nil { - st.c.Seats = overSeats(base, a.Seats) - if len(a.Seats) > 0 { - st.c.note(fmt.Sprintf("the heads carry %d seat definitions new or changed (and %d the seat list holds as they are), laid over the %d the seat list holds", len(a.Seats), a.Same, len(base))) - } - for _, l := range a.Left { - st.c.note("the heads' seat list leaves out " + l.Path + ": " + l.Why) - } - return true - } - } - } - st.fail(st.goModule(), "the heads' seat list could not be made by the checking program: "+err.Error()) - return false -} - -// overSeats is the list's definitions with each of the heads' put in place of the one of its seat, or added, sorted by -// seat: the checker reads of a definition only its seat's name. -func overSeats(list, heads []json.RawMessage) []json.RawMessage { - by := map[string]json.RawMessage{} - for _, l := range [][]json.RawMessage{list, heads} { - for _, raw := range l { - var d struct { - Seat string `json:"seat"` - } - if json.Unmarshal(raw, &d) == nil && d.Seat != "" { - by[d.Seat] = raw - } - } - } - var out []json.RawMessage // none when neither holds one: the requests then carry no list - for _, seat := range slices.Sorted(maps.Keys(by)) { - out = append(out, by[seat]) - } - return out -} - -// factsHead are the facts that name the check, without what the asking gathered. -func (st *state) factsHead() rules.Facts { - f := rules.Facts{V: rules.FactsVersion, Group: st.c.Group, Heads: st.c.Heads, Trunk: st.c.Trunk} - for _, p := range st.c.Pulls { - f.Members = append(f.Members, rules.Member{Repository: p.Repository, Number: p.Number, Head: p.Head, Trunk: p.Trunk}) - } - return f -} - -// judged is the checking program's answer to the check's facts (`-verdict`), with what judged; a program that cannot be -// asked, built or run, or does not answer a verdict, fails the check naming the checking program, never the running -// checker's rules in its place: the facts gain the failure and the verdict is worded from them as a failure. -func (st *state) judged(ctx context.Context) (rules.Answer, *meshdeliverychecker.VerdictsByGroupHeadsValueJudgedBy) { - body, err := json.Marshal(st.factsOf()) - var by *meshdeliverychecker.VerdictsByGroupHeadsValueJudgedBy - if err == nil { - var out json.RawMessage - if out, by, err = st.runProgram(ctx, []string{"-verdict"}, body); err == nil { - var a rules.Answer - if err = json.Unmarshal(out, &a); err == nil && a.V != rules.AnswerVersion { - err = fmt.Errorf("it answered a verdict of version %d, not %d", a.V, rules.AnswerVersion) - } - if err == nil { - return a, by - } - } - } - st.fail(st.goModule(), "the check could not be judged by the checking program: "+err.Error()) - return rules.Answer{V: rules.AnswerVersion, Verdict: rules.Judge(st.factsOf())}, by -} - -// judgedByOf is the verdict's judged-by of a run of the checking program: where it was built, the key its build is kept -// under, whether this run built it, and the heads it read. -func judgedByOf(prog buildstep.RunProgram, answer buildstep.RunAnswer, heads []buildstep.RunHead) *meshdeliverychecker.VerdictsByGroupHeadsValueJudgedBy { - by := &meshdeliverychecker.VerdictsByGroupHeadsValueJudgedBy{Program: meshdeliverychecker.VerdictsByGroupHeadsValueJudgedByProgram{ - Repository: prog.Repository, Commit: prog.Commit, Dir: prog.Dir, Package: prog.Package}, Key: answer.Key, Built: answer.Built} - for _, h := range heads { - by.Heads = append(by.Heads, meshdeliverychecker.VerdictsByGroupHeadsValueJudgedByHeadsItem{Repository: h.Repository, Commit: h.Commit}) - } - return by -} diff --git a/modules/mesh-delivery-checker/internal/check/rank_test.go b/modules/mesh-delivery-checker/internal/check/rank_test.go deleted file mode 100644 index 4f3961cc..00000000 --- a/modules/mesh-delivery-checker/internal/check/rank_test.go +++ /dev/null @@ -1,117 +0,0 @@ -package check - -import ( - "context" - "fmt" - "sync" - "testing" - - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshdeliverycheckerclient" - "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/meshdeliverychecker" -) - -// The checker's ranked start of checks (ADR 0536 §4, issue 1897): a freed place goes to a head never judged (or asked again -// after a failure of the nodes) before a head asked again only because its trunk moved; among equals the oldest asked first. -// A running check is never stopped. - -// rankRig is a checker of one check at a time whose judge records the order checks start in and holds the first check -// after hold is set until release is closed. -type rankRig struct { - *rig - mu sync.Mutex - started []*Case - hold bool - held chan struct{} // closed when the held check started - release chan struct{} - errs []error // ctx errors the held check saw when released -} - -func group(n int) string { return fmt.Sprintf("feat/g%d", n) } - -func groups(cs []*Case) []string { - out := make([]string, len(cs)) - for i, c := range cs { - out[i] = c.Group - } - return out -} - -func TestCheckerStatusNamesTheWaitingChecksByKind(t *testing.T) { // 1897/AC4 - ctx := context.Background() - j := &judgeFunc{f: func(_ context.Context, c *Case, _ int) (Outcome, error) { - if c.Group == group(2) { - return Outcome{Verdict: failure("the forge", "go.mod cannot be read: no responders (the forge was "+UnheardWords+")")}, nil - } - return Outcome{Verdict: passing()}, nil - }} - r := newRig(t, j) - cands := fakeState{} - put := func(n int, head string) { - cand := candidateOf(t, group(n), pullOf(repoA, n, head)) - ckey, _ := meshcatalogclient.CandidatesKey(group(n)) - cands[ckey] = cand - r.ch.Candidate(ctx, group(n), cand) - } - put(1, head1) // judged on the old trunk: a re-judge waits - put(2, head1) // failed for the nodes: waits for them - r.ch.Wait() - r.setTrunks(t, map[string]string{repoA: trunkA2, repoSDK: trunkS}) - put(4, head1) // judged on the new trunk: stands - r.ch.Wait() - cand3 := candidateOf(t, group(3), pullOf(repoA, 3, head1)) // never judged - ckey3, _ := meshcatalogclient.CandidatesKey(group(3)) - cands[ckey3] = cand3 - verdicts := fakeState{} - for k, v := range r.verdicts.vals { - verdicts[k] = v - } - rd := Reader{CandidateState: cands.read(), VerdictState: verdicts.read(), - Trunks: func() (map[string]string, error) { return map[string]string{repoA: trunkA2, repoSDK: trunkS}, nil }} - st, err := rd.Status() - if err != nil { - t.Fatal(err) - } - want := map[string][]string{KindNew: {group(3)}, KindNodes: {group(2)}, KindTrunk: {group(1)}} - if fmt.Sprint(st.Waiting) != fmt.Sprint(want) { - t.Errorf("waiting = %v, want %v", st.Waiting, want) - } -} - -// 568 note 21: a verdict that read the node-engine at its running commit is not waiting for a trunk move while that commit -// is still the one the mesh runs, though the node-engine's trunk has moved on (ADR 0548 §6). -func TestCheckerStatusReadsTheNodeEngineAtItsRunningCommit(t *testing.T) { // 568/21 - cand := candidateOf(t, group(1), pullOf(repoA, 1, head1)) - ckey, _ := meshcatalogclient.CandidatesKey(group(1)) - vkey := keyOf(t, group(1), cand) - dc, _ := meshcatalog.DecodeCandidatesByGroupValue(cand) - judged, err := meshdeliverycheckerclient.EncodeVerdict(meshdeliverychecker.VerdictsByGroupHeadsValue{Group: group(1), Heads: dc.Heads, Trunk: map[string]string{repoA: trunkA}, Beside: map[string]string{nodeEngineRepo: "run111"}, State: meshdeliverycheckerclient.VerdictPass, Levels: passing().Levels}) - if err != nil { - t.Fatal(err) - } - heads := func() (map[string]string, error) { - return map[string]string{repoA: trunkA, nodeEngineRepo: "trunk222"}, nil - } - for _, row := range []struct { - name string - runs runsAt - want int - }{ - {"the running commit the verdict read", runsAt{nodeEngineModule: "run111"}, 0}, - {"the running commit moved", runsAt{nodeEngineModule: "run999"}, 1}, - {"no running commit known: the trunk's", nil, 1}, - } { - rd := Reader{CandidateState: fakeState{ckey: cand}.read(), VerdictState: fakeState{vkey: judged}.read(), Trunks: heads} - if row.runs != nil { - rd.Runs = row.runs - } - st, err := rd.Status() - if err != nil { - t.Fatal(err) - } - if got := len(st.Waiting[KindTrunk]); got != row.want { - t.Errorf("%s: waiting for a trunk move = %v, want %d", row.name, st.Waiting[KindTrunk], row.want) - } - } -} diff --git a/modules/mesh-delivery-checker/internal/check/read.go b/modules/mesh-delivery-checker/internal/check/read.go deleted file mode 100644 index ee8f7f1f..00000000 --- a/modules/mesh-delivery-checker/internal/check/read.go +++ /dev/null @@ -1,791 +0,0 @@ -package check - -import ( - "crypto/sha256" - "encoding/hex" - "encoding/json" - "fmt" - "slices" - "sort" - "strings" - "time" - - "git.novox.be/novox/mesh-contracts/go/clients/nodeengineclient" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-builder/buildrun" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-builder/builds" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshdeliverycheckerclient" - "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/meshdeliverychecker" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep" -) - -// The read tools (novox/hq ADR 0484 clauses 8 and 13, issue 1686): what the checker stored, as stored, with the line of the -// status it owes in full, so a check is read live without a shell. They write nothing. - -// The read tools, named as the module is: checker_ and the noun. -const ( - VerdictsReadTool = "checker_verdicts" - PullReadTool = "checker_pull" - KeptReadTool = "checker_kept" - InputsReadTool = "checker_inputs" - // PreviewsReadTool reads the previews state (issue 1680); StatusReadTool reads what the checker runs (issue 1685: nothing holds it since R4g). - PreviewsReadTool = "checker_previews" - StatusReadTool = "checker_status" -) - -// StateRead reads one state: its keys and a key's stored value (nil for a key with none). -type StateRead struct { - Keys func() ([]string, error) - Get func(key string) (json.RawMessage, error) -} - -// Reader answers the read tools from the checker's verdicts and kept states and the indexer's candidates. -type Reader struct { - VerdictState, KeptState, CandidateState StateRead - - PreviewState StateRead // the checker's merge previews - InputState StateRead // the checking program's inputs (InputsStateName) - StepStates func() map[string]StateRead // the build modules' steps states, by module: the holders of the build seats (design 47 G A-82), found at each read - HaveState StateRead // the node-engine's have: whether a build module is on a node and running - StepBound time.Duration // how long the checker waits for one step; DefaultStepBound when 0 - // CouldNotRunState is the checker's own state could-not-run (CouldNotRunState); without it none is named. - CouldNotRunState StateRead - // Trunks are the trunk heads of every repository (the gate's source); nil names no re-judge after a trunk move. - Trunks func() (map[string]string, error) - // Runs says which commit the mesh runs of a module (the indexer's modules), as the checker's decision reads it: the - // node-engine a verdict names is compared at its running commit, not at the trunk's (ADR 0548 §6); nil knows none. - Runs interface{ CommitOf(module string) string } - // HearingState is the checker's state hearing: whether it hears DEAD_LETTERS (issue 734). - HearingState StateRead - // BuildState is the builder's builds (mesh-delivery-builder.builds): the builds of a running check's candidate that have - // not ended, which the check waits on before it composes (ADR 0603 §10); without it none is named. - BuildState StateRead - // AskState is the checker's state asks: the asks each running check put (AsksState), which checker_ask_again reads. - AskState StateRead - // Backlog is the build seats' backlog (mesh-delivery-view.build_usage); checker_ask_again reads it for a check that names no ask. - Backlog func() ([]BacklogRow, error) - Now func() time.Time -} - -// VerdictRead is a verdict as stored with every failure it names, one line each, and the full report of the status of each -// pull request it judged (Report), when the candidate still holds those heads; without it the report is that of the verdict alone. -type VerdictRead struct { - Key string `json:"key"` - Verdict json.RawMessage `json:"verdict"` - // Failed is everything the verdict names as failed, one line each, in the order judged (failedLines): every member's - // failed tests, refused steps and conflicts, the manifests' refusals and the composition (the operator, 2026-11-02). - Failed []string `json:"failed,omitempty"` - // Judged says which checking program judged the verdict, in one line (judgedLine): where it was built, the key its build - // is kept under, whether this check built it, and the heads it read (issue 1921); empty for a verdict written before. - Judged string `json:"judged,omitempty"` - Reports map[string]string `json:"reports,omitempty"` - Note string `json:"note,omitempty"` -} - -func (r Reader) candidate(group string) (meshcatalog.CandidatesByGroupValue, bool) { - key, err := meshcatalogclient.CandidatesKey(group) - if err != nil || r.CandidateState.Get == nil { - return meshcatalog.CandidatesByGroupValue{}, false - } - raw, err := r.CandidateState.Get(key) - if err != nil || len(raw) == 0 { - return meshcatalog.CandidatesByGroupValue{}, false - } - c, err := meshcatalog.DecodeCandidatesByGroupValue(raw) - return c, err == nil -} - -func (r Reader) read(key string, raw json.RawMessage) (VerdictRead, error) { - out := VerdictRead{Key: key, Verdict: raw} - v, err := meshdeliverycheckerclient.DecodeVerdict(raw) - if err != nil { - return out, fmt.Errorf("%s holds what is not a verdict: %w", key, err) - } - out.Failed = failedLines(v) - out.Judged = judgedLine(v.JudgedBy) - c, ok := r.candidate(v.Group) - if !ok || (c.Heads != v.Heads && GateHeads(c) != v.Heads) { - out.Note = "the candidate no longer holds these heads" - return out, nil - } - cs := CaseOf(c, v.Trunk) - out.Reports = map[string]string{} - if cs == nil { - if IsUntrunked(v) { - for _, p := range leftOf(c, v.Trunk) { - out.Reports[pullKey(p)] = failedOf(v).Words - } - } - return out, nil - } - for _, p := range cs.Pulls { - out.Reports[pullKey(p)] = Report(v, cs, p, nil, nil, nil) - } - for _, l := range cs.Left { - out.Reports[strings.SplitN(l, ": ", 2)[0]] = strings.SplitN(l, ": ", 2)[1] - } - return out, nil -} - -// Verdicts are the verdicts the checker holds, by key; with a group only that group's. The keys are narrowed by the group -// before any value is read, at most MaxReads are read (sixteen at a time), and cut says when it stopped there. -func (r Reader) Verdicts(group string) (out []VerdictRead, cut string, err error) { - if r.VerdictState.Keys == nil || r.VerdictState.Get == nil { - return nil, "", fmt.Errorf("the verdicts state cannot be read here") - } - keys, err := r.VerdictState.Keys() - if err != nil { - return nil, "", err - } - sort.Strings(keys) - var matching []string - for _, k := range keys { - if group != "" { - if g, _, err := meshdeliverycheckerclient.ParseVerdictKey(k); err != nil || g != group { - continue - } - } - matching = append(matching, k) - } - matching, cut = capKeys(matching, "give a group to narrow the answer") - rows := make([]VerdictRead, len(matching)) - found := make([]bool, len(matching)) - if err := parallel(len(matching), func(i int) error { - raw, err := r.VerdictState.Get(matching[i]) - if err != nil || len(raw) == 0 { - return err - } - rows[i], err = r.read(matching[i], raw) - found[i] = err == nil - return err - }); err != nil { - return nil, "", err - } - for i, row := range rows { - if found[i] { - out = append(out, row) - } - } - return out, cut, nil -} - -// Pull answers for one pull request: the verdict of the candidate that holds it, with its report; for one the indexer holds -// in no candidate, that none does. -func (r Reader) Pull(repository string, number int) (VerdictRead, error) { - if r.CandidateState.Keys == nil || r.CandidateState.Get == nil { - return VerdictRead{}, fmt.Errorf("the candidates state cannot be read here") - } - keys, err := r.CandidateState.Keys() - if err != nil { - return VerdictRead{}, err - } - keys = slices.DeleteFunc(keys, meshcatalogclient.IsTryGroup) - sort.Strings(keys) - keys, cut := capKeys(keys, "") - // The candidates are read in batches, each in parallel and taken in key order, so the read stops at the batch that holds it. - for from := 0; from < len(keys); from += ReadWorkers * 4 { - batch := keys[from:min(from+ReadWorkers*4, len(keys))] - cands := make([]meshcatalog.CandidatesByGroupValue, len(batch)) - ok := make([]bool, len(batch)) - _ = parallel(len(batch), func(i int) error { - raw, err := r.CandidateState.Get(batch[i]) - if err != nil || len(raw) == 0 { - return nil - } - c, err := meshcatalog.DecodeCandidatesByGroupValue(raw) - cands[i], ok[i] = c, err == nil - return nil - }) - for i, c := range cands { - if !ok[i] { - continue - } - for _, p := range c.Pulls { - if p.Repository != repository || int(p.Number) != number { - continue - } - vkey, err := meshdeliverycheckerclient.VerdictKey(c.Group, c.Heads) - if err != nil { - return VerdictRead{}, err - } - vraw, err := r.VerdictState.Get(vkey) - if err != nil { - return VerdictRead{}, err - } - if len(vraw) == 0 { - return VerdictRead{Key: vkey, Note: "no verdict yet for the heads of its candidate"}, nil - } - return r.read(vkey, vraw) - } - } - } - if cut != "" { - return VerdictRead{}, fmt.Errorf("no candidate among the first %d holds %s#%d", MaxReads, repository, number) - } - return VerdictRead{}, fmt.Errorf("no candidate holds %s#%d", repository, number) -} - -// Kept is the kept verdicts: one key's value as stored, or with an empty key the keys of a level (or every level) and their values. -func (r Reader) Kept(level, digest string) (map[string]json.RawMessage, string, error) { - if r.KeptState.Keys == nil || r.KeptState.Get == nil { - return nil, "", fmt.Errorf("the kept state cannot be read here") - } - if digest != "" { - key, err := meshdeliverycheckerclient.KeptKey(level, digest) - if err != nil { - return nil, "", err - } - raw, err := r.KeptState.Get(key) - if err != nil { - return nil, "", err - } - if len(raw) == 0 { - return nil, "", fmt.Errorf("no kept verdict %s", key) - } - return map[string]json.RawMessage{key: raw}, "", nil - } - keys, err := r.KeptState.Keys() - if err != nil { - return nil, "", err - } - sort.Strings(keys) - var matching []string - for _, k := range keys { - if l, _, err := meshdeliverycheckerclient.ParseKeptKey(k); err == nil && (level == "" || l == level) { - matching = append(matching, k) - } - } - matching, cut := capKeys(matching, "give a level and a digest to read one") - values := make([]json.RawMessage, len(matching)) - if err := parallel(len(matching), func(i int) (err error) { - values[i], err = r.KeptState.Get(matching[i]) - return err - }); err != nil { - return nil, "", err - } - out := map[string]json.RawMessage{} - for i, k := range matching { - if len(values[i]) > 0 { - out[k] = values[i] - } - } - return out, cut, nil -} - -// Input is the answer of the seat's verb input (InputVerb): the input kept under digest, its exact bytes, which the Go build -// module hands the checking program a run ask names (buildstep.RunInput.Read). A digest that is no sha256, one the checker -// keeps nothing under, and bytes that read back as another digest are errors, never an answer. -func (r Reader) Input(digest string) (meshdeliverychecker.InputAnswer, error) { - if r.InputState.Get == nil { - return meshdeliverychecker.InputAnswer{}, fmt.Errorf("the state %s cannot be read here", InputsStateName) - } - if len(digest) != 64 || strings.Trim(digest, "0123456789abcdef") != "" { - return meshdeliverychecker.InputAnswer{}, fmt.Errorf("%q is no sha256 digest of 64 lowercase hex digits", digest) - } - raw, err := r.InputState.Get(digest) - if err != nil { - return meshdeliverychecker.InputAnswer{}, fmt.Errorf("the input %s cannot be read: %w", digest, err) - } - if len(raw) == 0 { - return meshdeliverychecker.InputAnswer{}, fmt.Errorf("the checker keeps no input %s (an input is kept a day)", digest) - } - if sum := sha256.Sum256(raw); hex.EncodeToString(sum[:]) != digest { - return meshdeliverychecker.InputAnswer{}, fmt.Errorf("the input kept under %s reads back as %d bytes of another digest", digest, len(raw)) - } - return meshdeliverycheckerclient.InputAnswerOf(raw), nil -} - -// Inputs are the checking program's kept inputs: with a digest that input as kept, else every digest with its size. -func (r Reader) Inputs(digest string) (map[string]json.RawMessage, string, error) { - if r.InputState.Keys == nil || r.InputState.Get == nil { - return nil, "", fmt.Errorf("the state %s cannot be read here", InputsStateName) - } - if digest != "" { - raw, err := r.InputState.Get(digest) - if err != nil { - return nil, "", err - } - if len(raw) == 0 { - return nil, "", fmt.Errorf("no input %s is kept", digest) - } - return map[string]json.RawMessage{digest: raw}, "", nil - } - keys, err := r.InputState.Keys() - if err != nil { - return nil, "", err - } - sort.Strings(keys) - keys, cut := capKeys(keys, "give a digest to read one") - sizes := make([]int, len(keys)) - if err := parallel(len(keys), func(i int) error { - raw, err := r.InputState.Get(keys[i]) - sizes[i] = len(raw) - return err - }); err != nil { - return nil, "", err - } - out := map[string]json.RawMessage{} - for i, k := range keys { - out[k] = json.RawMessage(fmt.Sprintf(`{"size":%d}`, sizes[i])) - } - return out, cut, nil -} - -// PreviewRead is one preview as stored, with the parts of its key. -type PreviewRead struct { - Key string `json:"key"` - Repository string `json:"repository"` - Head string `json:"head"` - Trunk string `json:"trunk"` - Preview json.RawMessage `json:"preview"` -} - -// Previews are the previews the checker holds, each as stored. With a repository only that repository's; with a head (a -// prefix of at least 7 characters is enough) only previews of that head. A key that is no preview key is listed as unreadable. -func (r Reader) Previews(repository, head string) ([]PreviewRead, []string, string, error) { - if r.PreviewState.Keys == nil || r.PreviewState.Get == nil { - return nil, nil, "", fmt.Errorf("the previews state cannot be read here") - } - keys, err := r.PreviewState.Keys() - if err != nil { - return nil, nil, "", err - } - sort.Strings(keys) - type part struct{ repo, head, trunk string } - parts := map[string]part{} - var matching, bad []string - for _, k := range keys { - repo, h, trunk, err := meshdeliverycheckerclient.ParsePreviewKey(k) - if err != nil { - bad = append(bad, k) - continue - } - if (repository != "" && repo != repository) || (head != "" && !strings.HasPrefix(h, head)) { - continue - } - parts[k] = part{repo, h, trunk} - matching = append(matching, k) - } - matching, cut := capKeys(matching, "give a repository and a head to narrow the answer") - values := make([]json.RawMessage, len(matching)) - if err := parallel(len(matching), func(i int) (err error) { - values[i], err = r.PreviewState.Get(matching[i]) - return err - }); err != nil { - return nil, nil, "", err - } - out := []PreviewRead{} - for i, k := range matching { - if len(values[i]) > 0 { - p := parts[k] - out = append(out, PreviewRead{Key: k, Repository: p.repo, Head: p.head, Trunk: p.trunk, Preview: values[i]}) - } - } - return out, bad, cut, nil -} - -// RunningStep is a step in flight on a build module. -type RunningStep struct { - Module string `json:"module"` - Node string `json:"node"` - ID string `json:"id"` - Tool string `json:"tool"` - Since string `json:"since,omitempty"` - // What says what the step is (buildstep.AskWhat): an ask's kind, repository@head and levels. - What string `json:"what,omitempty"` -} - -// LeftStep is a key a build module left running that no step behind it runs any more, and why. -type LeftStep struct { - RunningStep - Why string `json:"why"` -} - -// Status is what runs now, read from the buckets: the steps in flight on the build modules and the candidates without a -// verdict for their heads. Nothing holds a check since R4g: a check is an ask on the build seats' streams, whose backlog -// the delivery view shows (ADR 0525 §9). -type Status struct { - Running []RunningStep `json:"running_steps"` - LeftRunning []LeftStep `json:"left_running"` - RunningByNode map[string]int `json:"running_by_node"` - Unjudged []string `json:"unjudged_candidates"` - // Waiting are the candidates whose check waits, by kind (ADR 0536 §4): new (no verdict for its heads) and nodes (failed - // for the nodes, asked again when they change) start before trunk (judged on trunk heads that moved since). - Waiting map[string][]string `json:"waiting_by_kind"` - // CannotBeJudged are the candidates no pull request of which can be judged, by group, with why: the gate's source.main - // names no trunk head of their repositories (issue 1422). They are judged once it does; until then their status is error. - CannotBeJudged map[string]string `json:"cannot_be_judged"` - // CouldNotRun are the checks that could not run, by verdict key: the part not heard, since when, the running that asked - // it again, and whether it is the finding check-could-not-run (design 47 test 58). Each is asked again when its part runs. - CouldNotRun map[string]CouldNotRun `json:"could_not_run"` - // Outside are the candidates outside the mesh, by group, with why (case.go Outside): judged nothing, owed nothing. - Outside map[string]string `json:"outside_the_mesh"` - // Lost are the candidates whose verdict is running while no step of theirs can still run and their newest step ended, by - // group, with that step: nothing will judge them (the lost check of 2026-10-28); checker_ask_again asks one again. - Lost map[string]string `json:"lost"` - // BuildsNotEnded are, of each candidate whose check runs, the builder's builds of its changed modules that are neither - // done nor failed, by group: ` `, sorted (no key yet is `not begun`). A check waits on them before it - // composes (ADR 0603 §10), but for the modules its line names as composed without them; builder_build_again builds a failed one again, and the check asks itself again when it is done. - BuildsNotEnded map[string]string `json:"builds_not_ended,omitempty"` - // DeadLetters says whether the checker hears the asks the build seats give up on (issue 734): deaf, a try or check - // whose ask is given up waits until its bound. - DeadLetters DeadLettersHeard `json:"dead_letters"` - Notes []string `json:"notes,omitempty"` -} - -// DeadLettersHeard is the checker's hearing of DEAD_LETTERS as the status says it: healthy or not, and why. -type DeadLettersHeard struct { - Heard bool `json:"heard"` - Why string `json:"why"` -} - -// deadLetters reads the checker's kept hearing (buildrun.HearingHealth). -func (r Reader) deadLetters() DeadLettersHeard { - if r.HearingState.Get == nil { - return DeadLettersHeard{Why: "the checker's state hearing is not readable here"} - } - raw, err := r.HearingState.Get(buildrun.HearingKey) - if err != nil { - return DeadLettersHeard{Why: "the checker's state hearing cannot be read: " + err.Error()} - } - a := buildrun.HearingHealth(raw) - return DeadLettersHeard{Heard: a.Healthy, Why: a.Why} -} - -// couldNotRun reads the checks that could not run, by verdict key; nil when they cannot be read, said in a note. -func (r Reader) couldNotRun(st *Status) map[string]CouldNotRun { - if r.CouldNotRunState.Keys == nil || r.CouldNotRunState.Get == nil { - st.Notes = append(st.Notes, "the checker's state could-not-run is not readable here, so no check that could not run is named") - return nil - } - keys, err := r.CouldNotRunState.Keys() - if err != nil { - st.Notes = append(st.Notes, "the checker's state could-not-run cannot be listed: "+err.Error()) - return nil - } - out := map[string]CouldNotRun{} - for _, k := range keys { - var c CouldNotRun - if raw, err := r.CouldNotRunState.Get(k); err == nil && json.Unmarshal(raw, &c) == nil { - out[k] = c - } - } - return out -} - -// Status reads the build modules' steps and the candidates against their verdicts. -func (r Reader) Status() (Status, error) { - st := Status{RunningByNode: map[string]int{}, Lost: map[string]string{}} - read := r.readSteps() - st.Running, st.LeftRunning, st.Notes = read.running, read.left, read.notes - for _, rs := range st.Running { - st.RunningByNode[rs.Node]++ - } - if r.HaveState.Get == nil { - st.Notes = append(st.Notes, "the node-engine's have is not readable here, so a step is not checked against its build module being on its node") - } - if len(st.LeftRunning) > 0 { - st.Notes = append(st.Notes, "left_running are keys a build module left running (it stopped, restarted or was unassigned before it wrote the step's end): the checker's wait for each ended at the step bound, so none holds a place; the build module never ends them") - } - st.Unjudged = []string{} - st.Waiting = map[string][]string{KindNew: {}, KindNodes: {}, KindTrunk: {}} - st.CannotBeJudged, st.Outside = map[string]string{}, map[string]string{} - var heads map[string]string - if r.Trunks == nil { - st.Notes = append(st.Notes, "the trunk heads are not readable here, so no check is named as waiting for a trunk move") - } else if h, err := r.Trunks(); err != nil { - st.Notes = append(st.Notes, "the trunk heads cannot be read, so no check is named as waiting for a trunk move: "+err.Error()) - } else { - heads = h - } - if r.CandidateState.Keys != nil && r.CandidateState.Get != nil && r.VerdictState.Get != nil { - keys, err := r.CandidateState.Keys() - if err != nil { - return st, err - } - keys = slices.DeleteFunc(keys, meshcatalogclient.IsTryGroup) // a try's candidate is judged by its try, never as a check - sort.Strings(keys) - total := len(keys) - keys, cut := capKeys(keys, "") - if cut != "" { - st.Notes = append(st.Notes, fmt.Sprintf("read the first %d candidates of %d", MaxReads, total)) - } - type judged struct { - c meshcatalog.CandidatesByGroupValue - raw json.RawMessage - ok bool - } - rows := make([]judged, len(keys)) - _ = parallel(len(keys), func(i int) error { - raw, err := r.CandidateState.Get(keys[i]) - if err != nil || len(raw) == 0 { - return nil - } - c, err := meshcatalog.DecodeCandidatesByGroupValue(raw) - if err != nil { - return nil - } - vkey, err := meshdeliverycheckerclient.VerdictKey(c.Group, c.Heads) - if err != nil { - return nil - } - rows[i].c = c - if vraw, err := r.VerdictState.Get(vkey); err == nil { - rows[i].raw, rows[i].ok = vraw, true - } - return nil - }) - for _, row := range rows { - if !row.ok { - continue - } - c, raw := row.c, row.raw - if Outside(c, heads) { - st.Outside[c.Group] = OutsideWords - continue - } - if heads != nil && len(leftOf(c, heads)) > 0 { - // Nothing of it can be judged now, whatever its verdict says (issue 1422): never counted as waiting. - var repos []string - for _, p := range leftOf(c, heads) { - repos = append(repos, p.Repository) - } - st.CannotBeJudged[c.Group] = UntrunkedWordsOf(repos) - continue - } - if len(raw) == 0 { - st.Unjudged = append(st.Unjudged, c.Group) - st.Waiting[KindNew] = append(st.Waiting[KindNew], c.Group) - continue - } - v, err := meshdeliverycheckerclient.DecodeVerdict(raw) - switch { - case err != nil: - case v.State == meshdeliverycheckerclient.VerdictRunning: - if why := read.lostWhy(c); why != "" { - st.Lost[c.Group] = why - } - if words := r.buildsNotEnded(c); words != "" { - if st.BuildsNotEnded == nil { - st.BuildsNotEnded = map[string]string{} - } - st.BuildsNotEnded[c.Group] = words - } - case IsCouldNotRun(v): - st.Waiting[KindNodes] = append(st.Waiting[KindNodes], c.Group) - case IsUntrunked(v): - // Its trunk head is known now: it waits for its whole check. - st.Waiting[KindNew] = append(st.Waiting[KindNew], c.Group) - case heads != nil: - if cs := CaseOf(c, heads); cs != nil && (!sameTrunk(v.Trunk, cs.Trunk) || besideMoved(v.Beside, besideAt(heads, r.Runs))) { - st.Waiting[KindTrunk] = append(st.Waiting[KindTrunk], c.Group) - } - } - } - } - st.DeadLetters = r.deadLetters() - st.CouldNotRun = r.couldNotRun(&st) - st.Notes = append(st.Notes, "nothing holds the checker and it holds no place: running_steps are the build modules' keys that can still be running (started within the step bound, their build module running on the node); a candidate without a verdict has its check ask in a build seat's stream, waiting for a node with a free slot, whose backlog the delivery view shows (ADR 0525 §4, §9)") - return st, nil -} - -// stepsRead is what the build modules' steps states hold: the steps that can still run, those left running, and every -// ask step read, by module, for the candidate it belongs to (stepsOf). -type stepsRead struct { - running []RunningStep - left []LeftStep - all []moduleStep - notes []string -} - -type moduleStep struct { - module string - step buildstep.Step -} - -// readSteps reads the newest MaxReads keys of each build module's steps state. -func (r Reader) readSteps() stepsRead { - out := stepsRead{running: []RunningStep{}, left: []LeftStep{}} - var states map[string]StateRead - if r.StepStates != nil { - states = r.StepStates() - } - mods := make([]string, 0, len(states)) - for m := range states { - mods = append(mods, m) - } - sort.Strings(mods) - now, bound := time.Now(), r.StepBound - if r.Now != nil { - now = r.Now() - } - if bound <= 0 { - bound = DefaultStepBound - } - for _, m := range mods { - sr := states[m] - if sr.Keys == nil || sr.Get == nil { - continue - } - keys, err := sr.Keys() - if err != nil { - out.notes = append(out.notes, "the steps of "+m+" cannot be listed: "+err.Error()) - continue - } - // A step that runs started lately: the newest ids are read first, at most MaxReads of them. - newestFirst(keys) - keys, cut := capKeys(keys, "") - if cut != "" { - out.notes = append(out.notes, "the steps of "+m+": read the newest "+fmt.Sprint(MaxReads)+" of its keys; a step older than those is not shown") - } - steps := make([]buildstep.Step, len(keys)) - decoded := make([]bool, len(keys)) - _ = parallel(len(keys), func(i int) error { - raw, err := sr.Get(keys[i]) - if err != nil || len(raw) == 0 { - return nil - } - step, err := buildstep.DecodeStep(raw) - steps[i], decoded[i] = step, err == nil - return nil - }) - for i := range keys { - if !decoded[i] { - continue - } - step := steps[i] - out.all = append(out.all, moduleStep{module: m, step: step}) - if step.State != buildstep.StepRunning { - continue - } - rs := RunningStep{Module: m, Node: step.Node, ID: step.ID, Tool: step.Tool, What: step.What} - if !step.Started.IsZero() { - rs.Since = step.Started.UTC().Format("2006-01-02T15:04:05Z") - } - if why := r.leftWhy(m, step, now, bound); why != "" { - out.left = append(out.left, LeftStep{RunningStep: rs, Why: why}) - continue - } - out.running = append(out.running, rs) - } - } - return out -} - -// asksOf says whether a step is an ask of one of the candidate's pull requests: its What names `@` -// (buildstep.AskWhat). -func asksOf(c meshcatalog.CandidatesByGroupValue, what string) bool { - for _, p := range c.Pulls { - if p.Repository != "" && strings.Contains(what, p.Repository+"@"+short12(p.Head)) { - return true - } - } - return false -} - -// lostWhy says why a candidate whose verdict is running has a check that nothing will judge, or "": no step of its pull -// requests can still run, and its newest one ended. -func (s stepsRead) lostWhy(c meshcatalog.CandidatesByGroupValue) string { - for _, rs := range s.running { - if asksOf(c, rs.What) { - return "" - } - } - var last *buildstep.Step - for i := range s.all { - st := s.all[i].step - if buildstep.Ended(st) && asksOf(c, st.What) && (last == nil || st.Ended.After(last.Ended)) { - last = &s.all[i].step - } - } - if last == nil { - return "" // its ask waits in its build seat's stream: no node took it yet - } - return fmt.Sprintf("its verdict is running, but no step of it runs: its last step %s on %s ended %s at %s and no verdict followed; %s asks it again", - last.ID, last.Node, last.State, last.Ended.UTC().Format(time.RFC3339), AskAgainTool) -} - -// DefaultStepBound is how long one check ask's step may run once a build node took it (its key written running; the fetch, -// the digests and the levels), never counting its wait in the stream; past it the check fails naming the node. -const DefaultStepBound = 30 * time.Minute - -// leftWhy says why a key in the running state runs no step any more, or "" when it can still be running: its build module -// is not on its node or is not running there (the node-engine's have), or it started longer ago than the step bound, when -// the checker stopped waiting for it. -func (r Reader) leftWhy(module string, step buildstep.Step, now time.Time, bound time.Duration) string { - if r.HaveState.Get != nil { - key, err := nodeengineclient.HaveKey(step.Node, module) - if err == nil { - raw, err := r.HaveState.Get(key) - switch { - case err != nil: - case len(raw) == 0: - return fmt.Sprintf("%s is not on %s", module, step.Node) - default: - if h, err := nodeengineclient.DecodeHave(raw); err == nil && h.Phase != nodeengineclient.PhaseRunning { - return fmt.Sprintf("%s on %s is %s", module, step.Node, h.Phase) - } - } - } - } - if step.Started.IsZero() { - return fmt.Sprintf("it says no start, so no wait of the checker's (bound %s) can be behind it", bound) - } - if end := step.Started.Add(bound); now.After(end) { - return fmt.Sprintf("started %s, past the step bound of %s: the checker stopped waiting for it at %s", step.Started.UTC().Format(time.RFC3339), bound, end.UTC().Format(time.RFC3339)) - } - return "" -} - -// buildsNotEnded are the builder's builds of the candidate's changed modules that are neither done nor failed, as -// Status.BuildsNotEnded says them; empty when none, or when the builder's builds are not readable here. -func (r Reader) buildsNotEnded(c meshcatalog.CandidatesByGroupValue) string { - if r.BuildState.Get == nil { - return "" - } - var out []string - for _, p := range c.Pulls { - for module, cm := range p.Fps { - if cm.Fp2 == "" || cm.Manifest == "" { - continue - } - key, err := builds.BuilderBuildKey(module, cm.Fp2) - if err != nil { - continue - } - raw, err := r.BuildState.Get(key) - if err != nil { - continue - } - state := "not begun" - if len(raw) > 0 { - b, err := builds.DecodeBuilderBuild(raw) - if err != nil || b.State == builds.BuildDone || b.State == builds.BuildFailed { - continue - } - state = b.State - } - out = append(out, module+" "+state) - } - } - sort.Strings(out) - return strings.Join(slices.Compact(out), ", ") -} - -// judgedLine is a verdict's JudgedBy in one line, as the verdict tools answer it. -func judgedLine(by *meshdeliverychecker.VerdictsByGroupHeadsValueJudgedBy) string { - if by == nil { - return "" - } - built := "kept" - if by.Built { - built = "built for this check" - } - heads := make([]string, len(by.Heads)) - for i, h := range by.Heads { - heads[i] = h.Repository + " " + h.Commit - } - return fmt.Sprintf("by the checking program %s of %s at %s (%s), %s as %s, over %s", by.Program.Package, by.Program.Repository, - by.Program.Commit, by.Program.Dir, built, by.Key, strings.Join(heads, ", ")) -} diff --git a/modules/mesh-delivery-checker/internal/check/read_test.go b/modules/mesh-delivery-checker/internal/check/read_test.go deleted file mode 100644 index 1ba52ccd..00000000 --- a/modules/mesh-delivery-checker/internal/check/read_test.go +++ /dev/null @@ -1,446 +0,0 @@ -package check - -import ( - "context" - "encoding/json" - "fmt" - "strings" - "sync/atomic" - "testing" - "time" - - "git.novox.be/novox/mesh-contracts/go/clients/nodeengineclient" - "git.novox.be/novox/mesh-contracts/go/seats/nodeengine" - buildsrec "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-builder/builds" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshdeliverycheckerclient" - "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/meshdeliverychecker" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep" -) - -type fakeState map[string][]byte - -func (f fakeState) read() StateRead { - return StateRead{ - Keys: func() ([]string, error) { - var k []string - for key := range f { - k = append(k, key) - } - return k, nil - }, - Get: func(key string) (json.RawMessage, error) { - if v, ok := f[key]; ok { - return json.RawMessage(v), nil - } - return nil, nil - }, - } -} - -// readerOf is a reader over a verdict the checker wrote through its own code and the candidate it judged. -func readerOf(t *testing.T) (Reader, string) { - t.Helper() - r := newRig(t, passJudge()) - r.setTrunks(t, map[string]string{repoA: trunkA, repoSDK: trunkS, hqRepo: trunkA2}) - cand := candidateOf(t, "feat/x", pullOf(repoA, 7, head1), pullOf(hqRepo, 3, head2)) - r.ch.Candidate(context.Background(), "feat%2Fx", cand) - r.ch.Wait() - ckey, _ := meshcatalogclient.CandidatesKey("feat/x") - verdicts, kept := fakeState{}, fakeState{} - for k, v := range r.verdicts.vals { - verdicts[k] = v - } - if _, err := (Kept{Store: r.verdicts}).Keep(context.Background(), "unit", digA, keptValue("m/a", 3)); err != nil { - t.Fatal(err) - } - kept["unit."+digA] = r.verdicts.vals["unit."+digA] - return Reader{VerdictState: verdicts.read(), KeptState: kept.read(), CandidateState: fakeState{ckey: cand}.read()}, keyOf(t, "feat/x", cand) -} - -func TestTheVerdictToolsAnswerTheStoredVerdictWithTheFullReportOfEachPullRequest(t *testing.T) { // N9/AC1, 1686 - rd, key := readerOf(t) - vs, _, err := rd.Verdicts("") - if err != nil || len(vs) != 1 || vs[0].Key != key { - t.Fatalf("verdicts = %+v, %v", vs, err) - } - if _, err := meshdeliverycheckerclient.DecodeVerdict(vs[0].Verdict); err != nil { - t.Errorf("the verdict is not as stored: %v", err) - } - if got := vs[0].Reports["novox/mesh-delivery#7"]; !strings.HasPrefix(got, "pass 111111111111 on aaaaaaaaaaaa") || !strings.Contains(got, "composition not yet run") { - t.Errorf("reports = %v", vs[0].Reports) - } - if vs[0].Judged != "" { - t.Errorf("judged = %q of a verdict with no JudgedBy", vs[0].Judged) - } - if only, _, _ := rd.Verdicts("feat/other"); len(only) != 0 { - t.Errorf("another group's verdicts = %+v", only) - } - // A failed verdict is answered with every failure it names, one line each (the operator, 2026-11-02). - raw, _ := meshdeliverycheckerclient.EncodeVerdict(meshdeliverychecker.VerdictsByGroupHeadsValue{Group: "feat/x", Heads: "0123456789ab", State: meshdeliverycheckerclient.VerdictFail, - Failed: &FailedFirst{Test: "unit: m/a.TestA", Words: "a_test.go:3: boom\nmore"}, - Failures: failureItems([]FailedFirst{{Test: "unit: m/a.TestA", Words: "a_test.go:3: boom"}, {Machine: "g14", Words: "route-proxy is defined twice"}}), - // Issue 1921: it names the checking program that judged it, its build and the heads it read. - JudgedBy: judgedByOf(buildstep.RunProgram{Repository: repoA, Commit: head1, Dir: CheckingProgramDir, Package: CheckingProgramPackage}, - buildstep.RunAnswer{Key: "program-0123456789abcdef", Built: true}, []buildstep.RunHead{{Repository: repoA, Commit: head1}})}) - want := "by the checking program " + CheckingProgramPackage + " of " + repoA + " at " + head1 + " (" + CheckingProgramDir + - "), built for this check as program-0123456789abcdef, over " + repoA + " " + head1 - if got, _ := rd.read(key, raw); strings.Join(got.Failed, " | ") != "unit: m/a.TestA: a_test.go:3: boom | g14: route-proxy is defined twice" || got.Judged != want { - t.Errorf("failed = %q, judged %q, want %q", got.Failed, got.Judged, want) - } -} - -// 1887/A10: an hq pull request is answered as any other, its report its verdict's (ADR 0527 §2), never a note that a script -// judges it. -func TestAnHqPullRequestIsAnsweredAsAnyOther(t *testing.T) { - rd, _ := readerOf(t) - hq, err := rd.Pull(hqRepo, 3) - if err != nil || hq.Note != "" || hq.Verdict == nil { - t.Errorf("hq pull = %+v, %v", hq, err) - } - p, err := rd.Pull(repoA, 7) - if err != nil || p.Note != "" || !strings.HasPrefix(p.Reports["novox/mesh-delivery#7"], "pass ") { - t.Errorf("pull = %+v, %v", p, err) - } - if _, err := rd.Pull(repoA, 99); err == nil { - t.Error("a pull request no candidate holds was answered") - } -} - -func TestTheKeptToolAnswersTheKeysAsStoredByLevelAndByDigest(t *testing.T) { // N9/AC1 - rd, _ := readerOf(t) - all, _, err := rd.Kept("", "") - if err != nil || len(all) != 1 { - t.Fatalf("kept = %v, %v", all, err) - } - one, _, err := rd.Kept("unit", digA) - if err != nil || len(one) != 1 { - t.Fatalf("one kept = %v, %v", one, err) - } - for _, raw := range one { - if k, err := meshdeliverycheckerclient.DecodeKept(raw); err != nil || k.Package != "m/a" { - t.Errorf("kept value = %+v, %v", k, err) - } - } - if none, _, _ := rd.Kept("integration", ""); len(none) != 0 { - t.Errorf("integration = %v", none) - } - if _, _, err := rd.Kept("unit", digB); err == nil { - t.Error("a digest nothing kept was answered") - } - // Issue 1921: checker_inputs answers the checking program's inputs, every digest with its size, or one as kept. - inputs := newMemKV() - body := []byte(`{"v":1,"group":"feat/x"}`) - in, _ := buildstep.RunInputOf(InputVerb, body) - _ = memInputs{inputs}.Keep(context.Background(), in.Digest, body) - rd.InputState = kvRead(inputs) - if all, _, err := rd.Inputs(""); err != nil || string(all[in.Digest]) != fmt.Sprintf(`{"size":%d}`, len(body)) { - t.Errorf("inputs = %s, %v", all, err) - } - if one, _, err := rd.Inputs(in.Digest); err != nil || string(one[in.Digest]) != string(body) { - t.Errorf("one input = %s, %v", one, err) - } - if _, _, err := rd.Inputs(strings.Repeat("0", 64)); err == nil { - t.Error("an input nothing kept was answered") - } - // The operator's answer on B0: the seat's verb input answers the exact bytes, which the build module's read takes; - // a digest that is none, one nothing is kept under, and bytes kept under another digest are errors. - if got, err := meshdeliverycheckerclient.ReadInput(func(key string, b any) (json.RawMessage, error) { - if key != "seat:mesh-delivery-checker.input" { - return nil, fmt.Errorf("asked %s", key) - } - a, err := rd.Input(b.(meshdeliverychecker.InputInput).Digest) - if err != nil { - return nil, err - } - return json.Marshal(a) - }, in.Digest); err != nil || string(got) != string(body) { - t.Errorf("the input through the verb = %s, %v", got, err) - } - _, _ = inputs.Create(context.Background(), strings.Repeat("1", 64), []byte(`{"v":2}`)) - for _, digest := range []string{"d1", strings.Repeat("0", 64), strings.Repeat("1", 64)} { - if a, err := rd.Input(digest); err == nil { - t.Errorf("the verb answered %s: %+v", digest, a) - } - } -} - -// 1680 live acceptance: checker_previews shows the preview key of an open pull request, as stored, narrowed by repository and head. -func TestThePreviewsToolShowsTheStoredPreviewOfAPullRequest(t *testing.T) { - pv := meshdeliverychecker.PreviewsByRepositoryHeadTrunkValue{Repository: repoA, Head: head1, Trunk: head2, Merge: "m1", Modules: map[string]meshdeliverychecker.PreviewsByRepositoryHeadTrunkValueModulesValue{}} - data, err := meshdeliverycheckerclient.EncodePreview(pv) - if err != nil { - t.Fatal(err) - } - key, _ := meshdeliverycheckerclient.PreviewKey(repoA, head1, head2) - rd := Reader{PreviewState: fakeState{key: data, "junk": []byte("{}")}.read()} - got, bad, _, err := rd.Previews(repoA, head1[:8]) - if err != nil || len(got) != 1 || got[0].Key != key || got[0].Head != head1 || got[0].Trunk != head2 || string(got[0].Preview) != string(data) { - t.Fatalf("previews = %+v, %v", got, err) - } - if len(bad) != 1 || bad[0] != "junk" { - t.Errorf("unreadable = %v", bad) - } - if got, _, _, _ := rd.Previews("novox/other", ""); len(got) != 0 { - t.Errorf("another repository's = %+v", got) - } - if _, _, _, err := (Reader{}).Previews("", ""); err == nil { - t.Error("answered with no state to read") - } -} - -// checker_status reads the steps in flight by node and the candidates without a verdict; since R4g nothing holds the checker -// and it has no capacity of its own (ADR 0525 §4, §7; 1685 closed by the hold's deletion). -func TestTheStatusToolReadsRunningSteps(t *testing.T) { - running, _ := buildstep.EncodeStep(buildstep.Step{ID: "abc1", Tool: "build_go_test", Node: "shanks", State: buildstep.StepRunning, Started: time.Date(2026, 10, 22, 15, 0, 0, 0, time.UTC)}) - passed, _ := buildstep.EncodeStep(buildstep.Step{ID: "abc2", Tool: "build_go_test", Node: "ace", State: buildstep.StepPassed}) - cand := candidateOf(t, "feat/x", pullOf(repoA, 7, head1)) - ckey, _ := meshcatalogclient.CandidatesKey("feat/x") - // ADR 0603 §10: feat/y's check runs and waits on the builds of its changed modules: web building, mail not begun; api - // is done and named nowhere. - fp, man := "src2:"+strings.Repeat("f", 64), strings.Repeat("e", 64) - py := pullOf(repoA, 8, head2) - py.Modules, py.Fps = []string{"api", "mail", "web"}, map[string]meshcatalog.CandidatesByGroupValuePullsItemFpsValue{"web": {Fp2: fp, Manifest: man}, "mail": {Fp2: fp, Manifest: man}, "api": {Fp2: fp, Manifest: man}} - candY := candidateOf(t, "feat/y", py) - ykey, _ := meshcatalogclient.CandidatesKey("feat/y") - runningV, _ := meshdeliverycheckerclient.EncodeVerdict(meshdeliverychecker.VerdictsByGroupHeadsValue{Group: "feat/y", Heads: "0123456789ab", State: meshdeliverycheckerclient.VerdictRunning}) - builds := fakeState{} - for module, state := range map[string]string{"web": buildsrec.BuildBuilding, "api": buildsrec.BuildDone} { - k, _ := buildsrec.BuilderBuildKey(module, fp) - builds[k], _ = json.Marshal(buildsrec.BuilderBuild{V: 1, State: state}) - } - rd := Reader{ - StepStates: stepStatesOf(map[string]StateRead{"mesh-build-go": fakeState{"shanks.abc1": running, "ace.abc2": passed}.read()}), - CandidateState: fakeState{ckey: cand, ykey: candY}.read(), - VerdictState: fakeState{keyOf(t, "feat/y", candY): runningV}.read(), - BuildState: builds.read(), - HaveState: fakeState{"shanks.mesh-build-go": haveOf(t, nodeengineclient.PhaseRunning)}.read(), - HearingState: fakeState{"dead-letters": []byte(`{"heard":false,"streams":["SEAT_NODE_BUILD_GO"],` + - `"why":"DEAD_LETTERS is not heard, so an ask a build seat gives up on is waited for until its bound: SEAT_NODE_BUILD_GO: permissions violation",` + - `"at":"2026-10-26T13:00:00Z"}`)}.read(), - Now: func() time.Time { return time.Date(2026, 10, 22, 15, 10, 0, 0, time.UTC) }, - } - st, err := rd.Status() - if err != nil { - t.Fatal(err) - } - if len(st.Running) != 1 || st.Running[0].Node != "shanks" || st.RunningByNode["shanks"] != 1 || st.RunningByNode["ace"] != 0 { - t.Errorf("running = %+v %v", st.Running, st.RunningByNode) - } - if len(st.Unjudged) != 1 || st.Unjudged[0] != "feat/x" { - t.Errorf("unjudged = %v", st.Unjudged) - } - if got := st.BuildsNotEnded; len(got) != 1 || got["feat/y"] != "mail not begun, web building" { - t.Errorf("builds not ended = %v, want feat/y's mail not begun and web building", got) - } - // Issue 734, review round 1: a checker that does not hear DEAD_LETTERS says so in its status, with why. - if st.DeadLetters.Heard || !strings.Contains(st.DeadLetters.Why, "permissions violation") { - t.Errorf("dead letters = %+v, want not heard, saying why", st.DeadLetters) - } - // What cannot be read is said, not guessed. - st, err = Reader{}.Status() - if err != nil || len(st.Notes) == 0 || st.DeadLetters.Heard { - t.Errorf("empty status = %+v, %v", st, err) - } -} - -func haveOf(t *testing.T, phase string) []byte { - t.Helper() - raw, err := nodeengineclient.EncodeHave(nodeengine.HaveByNodeModuleValue{Phase: phase, Health: nodeengineclient.HealthOK}) - if err != nil { - t.Fatal(err) - } - return raw -} - -func stepOf(t *testing.T, id, node string, started time.Time) []byte { - t.Helper() - raw, err := buildstep.EncodeStep(buildstep.Step{ID: id, Tool: "build_go_fetch", Node: node, State: buildstep.StepRunning, Started: started}) - if err != nil { - t.Fatal(err) - } - return raw -} - -// 1890: a key a build module left running (it stopped, restarted or was unassigned before it wrote the step's end) holds -// no place in the checker, whose wait for it ended at the step bound; the status says it is left running and why, and -// counts only the steps that can still run. -func TestTheStatusCountsOnlyStepsThatCanStillRunAndSaysWhyTheOthersAreLeft(t *testing.T) { // 1890/AC2, AC3 - now := time.Date(2026, 10, 23, 7, 0, 0, 0, time.UTC) - rd := Reader{ - StepStates: stepStatesOf(map[string]StateRead{ - "mesh-build-go": fakeState{ - "g14.fresh1": stepOf(t, "fresh1", "g14", now.Add(-5*time.Minute)), - "g14.old1": stepOf(t, "old1", "g14", now.Add(-33*time.Hour)), - "ace.gone1": stepOf(t, "gone1", "ace", now.Add(-2*time.Minute)), - "shanks.down1": stepOf(t, "down1", "shanks", now.Add(-time.Minute)), - }.read(), - }), - HaveState: fakeState{ - "g14.mesh-build-go": haveOf(t, nodeengineclient.PhaseRunning), - "shanks.mesh-build-go": haveOf(t, nodeengineclient.PhaseFailed), - }.read(), - StepBound: 30 * time.Minute, - Now: func() time.Time { return now }, - } - st, err := rd.Status() - if err != nil { - t.Fatal(err) - } - if len(st.Running) != 1 || st.Running[0].ID != "fresh1" || len(st.RunningByNode) != 1 || st.RunningByNode["g14"] != 1 { - t.Fatalf("running = %+v by node %v", st.Running, st.RunningByNode) - } - why := map[string]string{} - for _, l := range st.LeftRunning { - why[l.ID] = l.Why - } - if len(why) != 3 { - t.Fatalf("left running = %+v", st.LeftRunning) - } - for id, want := range map[string]string{"old1": "past the step bound of 30m0s", "gone1": "mesh-build-go is not on ace", "down1": "mesh-build-go on shanks is failed"} { - if !strings.Contains(why[id], want) { - t.Errorf("why %s = %q, want it to say %q", id, why[id], want) - } - } -} - -// 1887/A10: a group of hq's pull requests alone is judged by the checker since R4g, so without a verdict it is unjudged. -func TestTheStatusCountsAnHQOnlyGroupAsUnjudged(t *testing.T) { - cand := candidateOf(t, "pb-x", pullOf(hqRepo, 3, head2)) - ckey, _ := meshcatalogclient.CandidatesKey("pb-x") - st, err := Reader{CandidateState: fakeState{ckey: cand}.read(), VerdictState: fakeState{}.read()}.Status() - if err != nil { - t.Fatal(err) - } - if len(st.Unjudged) != 1 || st.Unjudged[0] != "pb-x" { - t.Errorf("unjudged = %v, want pb-x", st.Unjudged) - } - // A check that could not run is named with the part not heard (design 47 test 58). - rec := json.RawMessage(`{"v":1,"group":"feat/x","heads":"0123456789ab","part":{"node":"g14","module":"forge"},"since":"2026-11-09T20:00:00Z"}`) - st, err = Reader{CandidateState: fakeState{}.read(), VerdictState: fakeState{}.read(), CouldNotRunState: fakeState{"feat/x.0123456789ab": rec}.read()}.Status() - if err != nil { - t.Fatal(err) - } - if c := st.CouldNotRun["feat/x.0123456789ab"]; c.Part != (Part{Node: "g14", Module: "forge"}) { - t.Errorf("could_not_run = %+v, want the check of feat/x naming forge on g14", st.CouldNotRun) - } -} - -// slowBucket wraps a state with a Get that takes delay and counts the values read, the lists and the most Gets in flight. -type slowBucket struct { - vals fakeState - reads, lists atomic.Int64 - inFlight, maxFlight atomic.Int64 -} - -func (b *slowBucket) get(key string) (json.RawMessage, error) { - b.reads.Add(1) - now := b.inFlight.Add(1) - for m := b.maxFlight.Load(); now > m && !b.maxFlight.CompareAndSwap(m, now); m = b.maxFlight.Load() { - } - time.Sleep(time.Millisecond) - b.inFlight.Add(-1) - return b.vals.read().Get(key) -} - -func (b *slowBucket) read() StateRead { - return StateRead{Keys: func() ([]string, error) { b.lists.Add(1); return b.vals.read().Keys() }, Get: b.get} -} - -func (b *slowBucket) Keys() ([]string, error) { return b.read().Keys() } -func (b *slowBucket) Get(key string) (json.RawMessage, error) { return b.get(key) } -func (b *slowBucket) Create(string, []byte) error { return nil } - -// 1827: a read tool lists the keys of a bucket of thousands and reads only the values its answer needs, sixteen at a time, at -// most MaxReads, saying when it cut (on the live shape of 2026-10-26: kept 7990 keys, steps 10034, tries 1000s). -func TestReadToolsReadOnlyWhatTheyNeedInParallelAndSayWhenCut(t *testing.T) { // 1827 - kept := fakeState{} - for i := 0; i < 1800; i++ { - level := map[bool]string{true: "unit", false: "integration"}[i%9 != 0] - k, _ := meshdeliverycheckerclient.KeptKey(level, fmt.Sprintf("%064x", i)) - kept[k] = []byte(`{"v":1}`) - } - previews := fakeState{} - for i := 0; i < 1500; i++ { - repo := map[bool]string{true: repoA, false: repoSDK}[i < 300] - k, _ := meshdeliverycheckerclient.PreviewKey(repo, fmt.Sprintf("%08x%032x", i, 0), trunkA) - previews[k] = []byte(`{"v":1}`) - } - for _, row := range []struct { - name string - call func(*slowBucket) (rows int, cut string, err error) - rows int - reads, lists int64 - cut bool - }{ - {"kept of one key", func(b *slowBucket) (int, string, error) { - m, c, err := Reader{KeptState: b.read()}.Kept("unit", fmt.Sprintf("%064x", 1)) - return len(m), c, err - }, 1, 1, 0, false}, - {"kept of a level", func(b *slowBucket) (int, string, error) { - m, c, err := Reader{KeptState: b.read()}.Kept("integration", "") - return len(m), c, err - }, 200, 200, 1, false}, - {"kept of everything", func(b *slowBucket) (int, string, error) { - m, c, err := Reader{KeptState: b.read()}.Kept("", "") - return len(m), c, err - }, MaxReads, MaxReads, 1, true}, - {"previews of a repository", func(b *slowBucket) (int, string, error) { - p, _, c, err := Reader{PreviewState: b.read()}.Previews(repoSDK, "") - return len(p), c, err - }, 1200, 1000, 1, true}, - {"previews of a repository and a head", func(b *slowBucket) (int, string, error) { - p, _, c, err := Reader{PreviewState: b.read()}.Previews(repoA, fmt.Sprintf("%08x", 7)) - return len(p), c, err - }, 1, 1, 1, false}, - } { - b := &slowBucket{} - b.vals = kept - if strings.HasPrefix(row.name, "previews") { - b.vals = previews - } - start := time.Now() - rows, cut, err := row.call(b) - if err != nil { - t.Fatalf("%s: %v", row.name, err) - } - if rows != min(row.rows, MaxReads) || b.reads.Load() != row.reads || b.lists.Load() != row.lists || (cut != "") != row.cut { - t.Errorf("%s: %d rows, %d reads, %d lists, cut %q; want %d, %d, %d, cut %v", row.name, rows, b.reads.Load(), b.lists.Load(), cut, min(row.rows, MaxReads), row.reads, row.lists, row.cut) - } - if row.reads > 20 && b.maxFlight.Load() < 2 { - t.Errorf("%s: values were read one at a time", row.name) - } - t.Logf("%s: %d values in %v (one after the other: %v)", row.name, b.reads.Load(), time.Since(start), time.Duration(b.reads.Load())*time.Millisecond) - } - - // The status reads the newest steps of a bucket of 1500 first, at most MaxReads, and finds the one that runs. - now := time.Date(2026, 10, 26, 7, 0, 0, 0, time.UTC) - steps := fakeState{} - for i := 0; i < 1500; i++ { - id := fmt.Sprintf("mvo5%04dabcdef", i) - step := buildstep.Step{ID: id, Tool: "t", Node: "g14", State: buildstep.StepPassed} - if i == 1499 { - step.State, step.Started = buildstep.StepRunning, now.Add(-time.Minute) - } - raw, _ := buildstep.EncodeStep(step) - steps["g14."+id] = raw - } - sb := &slowBucket{vals: steps} - st, err := Reader{StepStates: stepStatesOf(map[string]StateRead{"mesh-build-go": sb.read()}), HaveState: fakeState{"g14.mesh-build-go": haveOf(t, nodeengineclient.PhaseRunning)}.read(), - Now: func() time.Time { return now }}.Status() - if err != nil || sb.reads.Load() != MaxReads || len(st.Running) != 1 || sb.maxFlight.Load() < 2 { - t.Errorf("status: %d reads (want %d), running %+v, in flight %d, %v", sb.reads.Load(), MaxReads, st.Running, sb.maxFlight.Load(), err) - } - - // A new try reads the newest TryScan of 1500 ended tries, not all, and still finds the same head asked twice. - tries := fakeState{} - for i := 0; i < 1500; i++ { - raw, _ := encodeTry(Try{ID: fmt.Sprintf("try-%d", 1700000000000000000+i), Repository: repoA, Head: head1, Trunk: trunkA, State: TryPass}) - tries[fmt.Sprintf("try-%d", 1700000000000000000+i)] = raw - } - tb := &slowBucket{vals: tries} - if _, err := AskTry(tb, tryTrunks, TryAsk{Repository: repoA, Head: head2, Trunk: trunkA}, now); err != nil || tb.reads.Load() != TryScan { - t.Errorf("AskTry read %d of 1500 tries (want %d), %v", tb.reads.Load(), TryScan, err) - } -} diff --git a/modules/mesh-delivery-checker/internal/check/renames.go b/modules/mesh-delivery-checker/internal/check/renames.go deleted file mode 100644 index fee28b0f..00000000 --- a/modules/mesh-delivery-checker/internal/check/renames.go +++ /dev/null @@ -1,100 +0,0 @@ -package check - -import ( - "context" - "errors" - "mesh-delivery-checker/rules" - - "git.novox.be/novox/mesh-contracts/go/seats/meshconfig" - "git.novox.be/novox/mesh-sdk/go/catalogue" -) - -// A config value renamed (design 32 *A config value renamed*, DLV-C5): the checker asks the seat mesh-config's verb -// renames, never the module, for every change that brings `renamed-from` or drops one. A holder that does not serve the -// verb refuses `renamed-from`, naming that; while a rename's window is open, dropping its `renamed-from` is refused, -// naming the nodes holding it open; a check that cannot ask fails, saying so. - -// RenamesSeat is the verb the checker asks, as its manifest's `invokes` names it. -var RenamesSeat = rules.RenamesSeat - -// ErrRenamesNotServed is the answer of Renames when the seat's holder serves no verb renames. -var ErrRenamesNotServed = errors.New("the holder of the seat " + meshconfig.Seat + " does not serve its verb " + meshconfig.VerbRenames) - -// Renames asks the seat mesh-config's verb renames for a module's open renames. -type Renames interface { - Renames(ctx context.Context, module string) (meshconfig.RenamesAnswer, error) -} - -// renameChange is what a pull request's head does to a module's `renamed-from` against the trunk: the declarations it -// brings (key from old name) and the ones it drops (key, old name). -type renameChange struct { - brought, dropped map[string]string -} - -// renamesOf compares a module's config declarations at the trunk and at the head. -func renamesOf(was, now catalogue.Manifest) renameChange { - rc := renameChange{brought: map[string]string{}, dropped: map[string]string{}} - for key, d := range now.Settings { - if d.RenamedFrom != "" && was.Settings[key].RenamedFrom != d.RenamedFrom { - rc.brought[key] = d.RenamedFrom - } - } - for key, d := range was.Settings { - if d.RenamedFrom != "" && now.Settings[key].RenamedFrom != d.RenamedFrom { - rc.dropped[key] = d.RenamedFrom - } - } - return rc -} - -// judgeRenames records, of each module a member changes that brings or drops a `renamed-from`, what it brings and drops -// and how the seat mesh-config's verb renames answered for it, as a fact the rules judge (rules.JudgeRenames): a rename -// whose value cannot be moved, and the drop of one whose window is open, fail the check (design 32). -func (st *state) judgeRenames(ctx context.Context) { - if st.c.Try != nil { - return - } - for _, p := range st.c.Pulls { - for _, module := range p.Modules { - r := rules.Renames{Module: module, Key: pullKey(p)} - was, now, ok, err := st.manifestPair(ctx, p, module) - if err != nil { - r.Unread = err.Error() - st.facts = append(st.facts, rules.Step{Repository: p.Repository, Number: p.Number, Renames: &r}) - continue - } - if !ok { - was = catalogue.Manifest{} // a module new on the pull request brings every rename it declares - if now, ok = st.headManifest(ctx, p, module); !ok { - continue - } - } - rc := renamesOf(was, now) - if len(rc.brought) == 0 && len(rc.dropped) == 0 { - continue - } - r.Brought, r.Dropped = rc.brought, rc.dropped - if st.j.Renames != nil { - answer, err := st.j.Renames.Renames(ctx, module) - switch { - case err != nil: - r.Unasked, r.NotServed = err.Error(), errors.Is(err, ErrRenamesNotServed) - default: - r.Answer = &answer - } - } - st.facts = append(st.facts, rules.Step{Repository: p.Repository, Number: p.Number, Renames: &r}) - } - } -} - -func (st *state) headManifest(ctx context.Context, p Pull, module string) (catalogue.Manifest, bool) { - if digest := p.Fps[module].Manifest; digest != "" && st.j.Read != nil { - if st.j.Manifests != nil && st.j.Manifests.ManifestDigests()[module] == digest { - return catalogue.Manifest{}, false // unchanged - } - m, err := st.j.Read.Manifest(ctx, digest) - return m, err == nil - } - return catalogue.Manifest{}, false -} diff --git a/modules/mesh-delivery-checker/internal/check/requests.go b/modules/mesh-delivery-checker/internal/check/requests.go deleted file mode 100644 index a18ba5dc..00000000 --- a/modules/mesh-delivery-checker/internal/check/requests.go +++ /dev/null @@ -1,299 +0,0 @@ -package check - -import ( - "bytes" - "compress/gzip" - "context" - "crypto/sha256" - "encoding/base64" - "encoding/hex" - "encoding/json" - "fmt" - "io" - "sort" - "strings" - "time" -) - -// The composition requests a check sends (issue 1921, notes 66-67): the request the checker sends the composer for one -// node, the checking program's whole input of a composition, is kept in the checker's own state RequestsStateName, so a -// session reproduces a check's composition exactly. The checker is a foundation part (novox/hq ADR 0619 §1-3), so its -// kept data is a section of its manifest's old form, here `state`, and not an object store asked in `requires`. -// -// **What bounds it.** A request is the node-engine's whole composition input of one node, 0.7 to 0.8 MB as JSON and -// growing with the mesh. A state's value holds at most 256 KiB (kvlimit.ModuleStateValueBytes, headers included), and -// the compressed request already passed it (issue 1966: 300127 bytes), so it is kept gzip-compressed in pieces: the key -// of the check and node holds a small document naming the request's digest, size and number of pieces, and each piece is -// a value of its own under RequestChunkKey, of at most RequestChunkBytes. The kept data is the checker's, a foundation -// part's, so it stays in the old section `state` (ADR 0619 §2) and is read through the tool runner's state read, which -// serves no object store of the old sections. The manifest's ttl-seconds is the lifetime (3 days) of the pointer and of -// every piece and its max-mib the most the state holds (256): the bus drops a value past the one and refuses a put past the -// other, so nothing waits on a timer here; a state that is full says so in the check's words, which name RequestsDropTool. A check kept again overwrites the key; -// a request whose pieces cannot all be put is refused naming the size (never dropped, never half kept: the pointer is -// put after its pieces). -const ( - // RequestsStateName is the checker's state of kept requests and RequestsBucket its bucket. - RequestsStateName = "compositions" - // RequestsReadTool is the tool that reads a kept request. - RequestsReadTool = "checker_composition_requests" - // RequestsDropTool is the tool that drops a check's kept requests by hand (a state that is full is freed with it). - RequestsDropTool = "checker_composition_requests_drop" - // RequestChunkBytes is the most compressed bytes one piece holds: base64 of it, in its document, stays well under - // the state's 256 KiB value. - RequestChunkBytes = 128 << 10 -) - -// KeptRequest is the pointer to a request as the state holds it: whose it is, and what its pieces make. -type KeptRequest struct { - V int `json:"v"` - Check string `json:"check"` - Node string `json:"node"` - KeptAt time.Time `json:"kept_at"` - // Size and Digest are the request's, uncompressed: its bytes and their sha256. - Size int `json:"size"` - Digest string `json:"digest"` - // Pieces is how many pieces (RequestChunkKey of the digest, 0 to Pieces-1) make the request's gzip bytes. - Pieces int `json:"pieces"` -} - -// KeptPiece is one piece of a request's gzip bytes, base64-encoded. -type KeptPiece struct { - V int `json:"v"` - Digest string `json:"digest"` - Index int `json:"index"` - Gzip string `json:"gzip"` -} - -// isPieceKey is whether a key is a piece's: under pieces/ and a sha256 digest, which no check's key (group.heads/node) is. -func isPieceKey(k string) bool { - rest, ok := strings.CutPrefix(k, "pieces/") - if !ok { - return false - } - digest, _, _ := strings.Cut(rest, "/") - return len(digest) == 64 -} - -// RequestChunkKey is the key of a request's piece: under the request's digest, so a request kept again for the same -// bytes writes the same pieces. -func RequestChunkKey(digest string, index int) string { - return fmt.Sprintf("pieces/%s/%d", digest, index) -} - -// RequestKey is the key a check's request to a node is kept under: the check's key (group.heads) and the node. -func RequestKey(key, node string) string { return key + "/" + node } - -// RequestPutter writes a value of the state, replacing one of that key. -type RequestPutter interface { - Put(ctx context.Context, key string, value []byte) (uint64, error) -} - -// RequestKeeper keeps the requests of a check. -type RequestKeeper struct { - Store RequestPutter - Now func() time.Time -} - -// Keep stores body under the check's key and the node. An error says why it could not, for the verdict's words. -func (k RequestKeeper) Keep(ctx context.Context, key, node string, body []byte) error { - var packed bytes.Buffer - zw := gzip.NewWriter(&packed) - if _, err := zw.Write(body); err != nil { - return fmt.Errorf("the composition request of check %s to %s could not be compressed: %w", key, node, err) - } - if err := zw.Close(); err != nil { - return fmt.Errorf("the composition request of check %s to %s could not be compressed: %w", key, node, err) - } - now := time.Now - if k.Now != nil { - now = k.Now - } - sum := sha256.Sum256(body) - digest := hex.EncodeToString(sum[:]) - pieces := (packed.Len() + RequestChunkBytes - 1) / RequestChunkBytes - fail := func(err error) error { - return fmt.Errorf("the composition request of check %s to %s (%d bytes, %d compressed in %d pieces) could not be kept in the state %s: %w (when the state is full, free it by dropping the kept requests of a check no longer read, with the tool %s)", - key, node, len(body), packed.Len(), pieces, RequestsStateName, err, RequestsDropTool) - } - for i := 0; i < pieces; i++ { - end := min((i+1)*RequestChunkBytes, packed.Len()) - doc, err := json.Marshal(KeptPiece{V: 2, Digest: digest, Index: i, Gzip: base64.StdEncoding.EncodeToString(packed.Bytes()[i*RequestChunkBytes : end])}) - if err != nil { - return err - } - if _, err := k.Store.Put(ctx, RequestChunkKey(digest, i), doc); err != nil { - return fail(err) - } - } - doc, err := json.Marshal(KeptRequest{V: 2, Check: key, Node: node, KeptAt: now().UTC(), Size: len(body), Digest: digest, Pieces: pieces}) - if err != nil { - return err - } - if _, err := k.Store.Put(ctx, RequestKey(key, node), doc); err != nil { - return fail(err) - } - return nil -} - -// ReadRequests answers the kept requests: with a check and a node, that request whole; with a check, the nodes it kept -// one for; with neither, every kept request. A node without a check is refused. get is the state's value of a key. -func ReadRequests(s StateRead, key, node string) (any, error) { - if s.Keys == nil || s.Get == nil { - return nil, fmt.Errorf("the state %s cannot be read here", RequestsStateName) - } - if node != "" && key == "" { - return nil, fmt.Errorf("a node is asked for with the check's key (group.heads) of the request") - } - if node != "" { - raw, err := s.Get(RequestKey(key, node)) - if err != nil { - return nil, err - } - if len(raw) == 0 { - return nil, fmt.Errorf("no composition request of check %s to %s is kept (none was sent, or it is past its lifetime)", key, node) - } - kept, body, err := unpackRequest(s, raw) - if err != nil { - return nil, fmt.Errorf("the kept request %s: %w", RequestKey(key, node), err) - } - return map[string]any{"check": kept.Check, "node": kept.Node, "size": kept.Size, "digest": kept.Digest, "kept_at": kept.KeptAt, "request": json.RawMessage(body)}, nil - } - keys, err := s.Keys() - if err != nil { - return nil, err - } - sort.Strings(keys) - listed := []map[string]any{} - for _, k := range keys { - if key != "" && !strings.HasPrefix(k, key+"/") { - continue - } - if isPieceKey(k) { - continue // a piece of a request, not a request: never read here - } - raw, err := s.Get(k) - if err != nil { - return nil, err - } - var kept KeptRequest - if err := json.Unmarshal(raw, &kept); err != nil { - listed = append(listed, map[string]any{"key": k, "unreadable": err.Error()}) - continue - } - listed = append(listed, map[string]any{"check": kept.Check, "node": kept.Node, "size": kept.Size, "digest": kept.Digest, "kept_at": kept.KeptAt}) - } - return map[string]any{"kept": listed}, nil -} - -// unpackRequest reads a kept pointer's pieces and the request's bytes, which must match the digest they were kept with. -func unpackRequest(s StateRead, raw []byte) (KeptRequest, []byte, error) { - var kept KeptRequest - if err := json.Unmarshal(raw, &kept); err != nil { - return kept, nil, fmt.Errorf("is no kept request: %w", err) - } - if kept.V != 2 { - return kept, nil, fmt.Errorf("is a kept request of version %d, which this reader does not read (it reads version 2; an older one is past its lifetime within 3 days)", kept.V) - } - var packed []byte - for i := 0; i < kept.Pieces; i++ { - raw, err := s.Get(RequestChunkKey(kept.Digest, i)) - if err != nil { - return kept, nil, err - } - var piece KeptPiece - if err := json.Unmarshal(raw, &piece); err != nil || len(raw) == 0 { - return kept, nil, fmt.Errorf("lacks its piece %d of %d (past its lifetime, or never kept)", i, kept.Pieces) - } - part, err := base64.StdEncoding.DecodeString(piece.Gzip) - if err != nil { - return kept, nil, fmt.Errorf("holds no base64 in its piece %d: %w", i, err) - } - packed = append(packed, part...) - } - zr, err := gzip.NewReader(bytes.NewReader(packed)) - if err != nil { - return kept, nil, fmt.Errorf("holds no gzip: %w", err) - } - body, err := io.ReadAll(zr) - if err != nil { - return kept, nil, fmt.Errorf("holds no complete gzip: %w", err) - } - if sum := sha256.Sum256(body); hex.EncodeToString(sum[:]) != kept.Digest { - return kept, nil, fmt.Errorf("does not match the digest it was kept with") - } - return kept, body, nil -} - -// StateDrop is the state of kept requests as the drop tool needs it: its keys, a value, and a key removed. -type StateDrop struct { - StateRead - Delete func(key string) error -} - -// DropRequests drops the requests kept for a check, after record (the hand act, recorded first: a drop that is not -// recorded is not made), and answers what it dropped: the nodes, and the pieces. A piece another kept request still names -// (the same request kept for another check has the same digest) stays. A check naming no kept request is refused. -func DropRequests(s StateDrop, key, why string, record func(what string) error) (any, error) { - if strings.TrimSpace(key) == "" || strings.TrimSpace(why) == "" { - return nil, fmt.Errorf("drop takes check (its key, group.heads) and why") - } - if s.Keys == nil || s.Get == nil || s.Delete == nil { - return nil, fmt.Errorf("the state %s cannot be changed here", RequestsStateName) - } - keys, err := s.Keys() - if err != nil { - return nil, err - } - sort.Strings(keys) - var drop []string - kept := map[string]bool{} // digests the requests that stay name - dropping := map[string]bool{} - for _, k := range keys { - if isPieceKey(k) { - continue - } - raw, err := s.Get(k) - if err != nil { - return nil, err - } - var r KeptRequest - if len(raw) == 0 || json.Unmarshal(raw, &r) != nil { - continue - } - if strings.HasPrefix(k, key+"/") { - drop = append(drop, k) - dropping[r.Digest] = true - continue - } - kept[r.Digest] = true - } - if len(drop) == 0 { - return nil, fmt.Errorf("no composition request of check %s is kept (none was sent, or it is past its lifetime): nothing was dropped", key) - } - if err := record(fmt.Sprintf("dropped the %d kept composition requests of check %s (%s)", len(drop), key, RequestsStateName)); err != nil { - return nil, fmt.Errorf("the hand act was not recorded, so nothing was dropped: %w", err) - } - var pieces int - for _, k := range drop { - if err := s.Delete(k); err != nil { - return nil, fmt.Errorf("dropping %s: %w", k, err) - } - } - for _, k := range keys { - if !isPieceKey(k) { - continue - } - digest := strings.Split(strings.TrimPrefix(k, "pieces/"), "/")[0] - if dropping[digest] && !kept[digest] { - if err := s.Delete(k); err != nil { - return nil, fmt.Errorf("dropping %s: %w", k, err) - } - pieces++ - } - } - nodes := make([]string, len(drop)) - for i, k := range drop { - nodes[i] = strings.TrimPrefix(k, key+"/") - } - return map[string]any{"check": key, "dropped_requests": nodes, "dropped_pieces": pieces, "why": why}, nil -} diff --git a/modules/mesh-delivery-checker/internal/check/results.go b/modules/mesh-delivery-checker/internal/check/results.go deleted file mode 100644 index d3accb7c..00000000 --- a/modules/mesh-delivery-checker/internal/check/results.go +++ /dev/null @@ -1,43 +0,0 @@ -package check - -import ( - "mesh-delivery-checker/rules" - - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep" -) - -// The shapes of what the build modules' steps answer, as their code writes them (mesh-catalog modules/mesh-build-go -// cmd/mesh-build-go levels.go TestResult, digest.go DigestResult, fetch.go FetchResult; modules/mesh-build-node -// cmd/mesh-build-node check.go TestResult, fetch.go FetchResult) with the fields the fetch step adds for a merge (ADR 0484 -// clause 3). Only the fields the checker reads are named; the rest is ignored. - -// Fetched is the answer of a build module's fetch step, whole: the Delivery SDK's FetchAnswer, which a check answer keeps -// (B2g; the build seats' part FetchAnswer): the workspace, the merge preview with its conflicts, changed paths, programs and -// trees. A conflict is an answer. -type Fetched = buildstep.FetchAnswer - -// ProgramFile is a changed file that is a compiled program (rules.ProgramFile). -type ProgramFile = rules.ProgramFile - -// The test step's answer is read by the judging rules (milestone 47/B0); these name their shapes here. -type ( - Failure = rules.Failure - TestTime = rules.TestTime - Tested = rules.Tested - GoPackage = rules.GoPackage -) - -// Digested is the answer of the Go build module's digest step: one digest per package that has tests at the level, by import -// path. -type Digested struct { - // Beside are the lines ` ` of the siblings the digest folded in (DigestVersion 3, lead decision L5), - // sorted; absent when the workspace has none or the build module folds none in. - Beside []string `json:"beside,omitempty"` - Level string `json:"level"` - Packages map[string]string `json:"packages"` - WithoutTests []string `json:"without_tests,omitempty"` - // JudgedBy is the program that ran the digest, as Tested.JudgedBy says. - JudgedBy string `json:"judged_by,omitempty"` - // Needs are the packages whose tests need something of the node at this level (issue 890). - Needs []buildstep.PackageNeeds `json:"needs,omitempty"` -} diff --git a/modules/mesh-delivery-checker/internal/check/seatdefs.go b/modules/mesh-delivery-checker/internal/check/seatdefs.go deleted file mode 100644 index 94e92cc9..00000000 --- a/modules/mesh-delivery-checker/internal/check/seatdefs.go +++ /dev/null @@ -1,41 +0,0 @@ -package check - -import ( - "context" - "mesh-delivery-checker/rules" -) - -// A pull request whose head's seat definition does not parse fails its check, naming the seat and where it lives (design -// 26; the lead's ruling on A2i's finding 1): the indexer keeps such a definition as the pull request's entry of its state -// seat-definitions with `unparsed` set, and cannot refuse the manifest itself, whose digest the trunk may share. - -// UnparsedSeat is one seat definition of a pull request's head that does not parse (rules.UnparsedSeat). -type UnparsedSeat = rules.UnparsedSeat - -// SeatDefinitions reads the indexer's seat definitions of one pull request (its state seat-definitions, through its -// first view, DLV-M2). -type SeatDefinitions interface { - Unparsed(ctx context.Context, repository string, pull int) ([]UnparsedSeat, error) -} - -// refuseUnparsed records, of each pull request, the indexer's seat definitions of its head that do not parse, or why -// they cannot be read, as a fact the rules judge (rules.JudgeUnparsed). -func (st *state) refuseUnparsed(ctx context.Context) { - if st.j.SeatDefinitions == nil || st.c.Try != nil { - return - } - for _, p := range st.c.Pulls { - u := rules.Unparsed{Key: pullKey(p)} - bad, err := st.j.SeatDefinitions.Unparsed(ctx, p.Repository, p.Number) - if err != nil { - u.Unread = err.Error() - } - u.Seats = bad - if u.Unread != "" || len(u.Seats) > 0 { - st.facts = append(st.facts, rules.Step{Repository: p.Repository, Number: p.Number, Unparsed: &u}) - } - } -} - -// SeatDefinitionsMachine names what refused a seat definition in a verdict's failure. -const SeatDefinitionsMachine = rules.SeatDefinitionsMachine diff --git a/modules/mesh-delivery-checker/internal/check/series.go b/modules/mesh-delivery-checker/internal/check/series.go deleted file mode 100644 index 1a6d91db..00000000 --- a/modules/mesh-delivery-checker/internal/check/series.go +++ /dev/null @@ -1,150 +0,0 @@ -package check - -import ( - "context" - "fmt" - "slices" - "strings" - - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshdeliverychecker" - "git.novox.be/novox/mesh-sdk/go/catalogue" -) - -// A change of a package series is named in the verdict, so the review of the change sees it (design 32 *A package, its -// series*; DLV-C4): for each module a pull request touches, every artifact both its trunk manifest and its head's -// manifest declare whose series differs, as `/ series → `. An artifact that names none -// is in catalogue.DefaultSeries. A manifest that cannot be read is said in the same words, never left out. - -// seriesChanges names, on the case per pull request, each change of an artifact's series the pull request makes. -func (st *state) seriesChanges(ctx context.Context) { - for _, p := range st.c.Pulls { - var words []string - var changes []meshdeliverychecker.VerdictsByGroupHeadsValueSeriesItem - for _, module := range p.Modules { - was, now, ok, err := st.manifestPair(ctx, p, module) - if err != nil { - words = append(words, fmt.Sprintf("%s: its series not compared (%v)", module, err)) - continue - } - if ok { - moved := seriesMoved(module, was, now) - changes = append(changes, moved...) - for _, c := range moved { - words = append(words, seriesLine(c)) - } - } - } - if len(words) > 0 { - st.c.series(pullKey(p), words, changes) - } - } -} - -// manifestPair is a touched module's trunk manifest and its manifest at the pull request's head: the head's by the digest -// its candidate names, else read from the forge at the head. ok is false when the module is new on the pull request, -// unchanged, or not read here. -func (st *state) manifestPair(ctx context.Context, p Pull, module string) (was, now catalogue.Manifest, ok bool, err error) { - if st.j.Read == nil || st.j.Manifests == nil { - return was, now, false, nil - } - trunk := st.j.Manifests.ManifestDigests()[module] - digest := p.Fps[module].Manifest - if trunk == "" || digest == trunk { - return was, now, false, nil - } - if was, err = st.j.Read.Manifest(ctx, trunk); err != nil { - return was, now, false, fmt.Errorf("the trunk's manifest not read: %w", err) - } - switch { - case digest != "": - if now, err = st.j.Read.Manifest(ctx, digest); err != nil { - return was, now, false, fmt.Errorf("the head's manifest not read: %w", err) - } - case st.j.Forge != nil: - var found bool - if now, _, found, err = st.manifestAtHead(ctx, p, module); err != nil || !found { - return was, now, false, err - } - default: - return was, now, false, nil - } - return was, now, true, nil -} - -// seriesLine is a series change as the status line names it: `/ series → `. -func seriesLine(c meshdeliverychecker.VerdictsByGroupHeadsValueSeriesItem) string { - return fmt.Sprintf("%s/%s series %s → %s", c.Module, c.Artifact, c.From, c.To) -} - -// seriesMoved are the artifacts of module whose series the head's manifest changes from the trunk's, by artifact. An -// artifact new on the head is no series change (the lead's ruling): it has no series on the trunk. -func seriesMoved(module string, was, now catalogue.Manifest) []meshdeliverychecker.VerdictsByGroupHeadsValueSeriesItem { - if was.Build == nil || now.Build == nil { - return nil - } - before := map[string]string{} - for _, a := range was.Build.Artifacts { - before[a.Name] = a.SeriesOf() - } - var out []meshdeliverychecker.VerdictsByGroupHeadsValueSeriesItem - for _, a := range now.Build.Artifacts { - if old, ok := before[a.Name]; ok && old != a.SeriesOf() { - out = append(out, meshdeliverychecker.VerdictsByGroupHeadsValueSeriesItem{Module: module, Artifact: a.Name, From: old, To: a.SeriesOf()}) - } - } - slices.SortFunc(out, func(a, b meshdeliverychecker.VerdictsByGroupHeadsValueSeriesItem) int { - return strings.Compare(a.Artifact, b.Artifact) - }) - return out -} - -// series keeps, of a pull request (pullKey), the words of the series changes it makes and the changes themselves. -func (c *Case) series(key string, words []string, changes []meshdeliverychecker.VerdictsByGroupHeadsValueSeriesItem) { - c.notesMu.Lock() - defer c.notesMu.Unlock() - if c.seriesOf == nil { - c.seriesOf, c.seriesChanges = map[string][]string{}, map[string][]meshdeliverychecker.VerdictsByGroupHeadsValueSeriesItem{} - } - c.seriesOf[key], c.seriesChanges[key] = words, changes -} - -// SeriesChanges are the series changes a pull request (pullKey) makes, as the verdict and its event name them. -func (c *Case) SeriesChanges(key string) []meshdeliverychecker.VerdictsByGroupHeadsValueSeriesItem { - c.notesMu.Lock() - defer c.notesMu.Unlock() - return slices.Clone(c.seriesChanges[key]) -} - -// allSeries are the series changes of every pull request of the case, each module's artifact once, by module and -// artifact: what the verdict names (meshdeliverychecker.VerdictsByGroupHeadsValue.Series). -func (c *Case) allSeries() []meshdeliverychecker.VerdictsByGroupHeadsValueSeriesItem { - var out []meshdeliverychecker.VerdictsByGroupHeadsValueSeriesItem - seen := map[string]bool{} - for _, p := range c.Pulls { - for _, s := range c.SeriesChanges(pullKey(p)) { - if k := s.Module + "/" + s.Artifact; !seen[k] { - seen[k] = true - out = append(out, s) - } - } - } - slices.SortFunc(out, func(a, b meshdeliverychecker.VerdictsByGroupHeadsValueSeriesItem) int { - return strings.Compare(a.Module+"/"+a.Artifact, b.Module+"/"+b.Artifact) - }) - return out -} - -// Series are the series changes a pull request (pullKey) makes, as the check named them; none when it makes none. -func (c *Case) Series(key string) []string { - c.notesMu.Lock() - defer c.notesMu.Unlock() - return slices.Clone(c.seriesOf[key]) -} - -// seriesWords is a pull request's series changes for its status line. -func seriesWords(c *Case, p Pull) string { - if c == nil { - return "" - } - return strings.Join(c.Series(pullKey(p)), ", ") -} diff --git a/modules/mesh-delivery-checker/internal/check/store.go b/modules/mesh-delivery-checker/internal/check/store.go deleted file mode 100644 index 6e7dbe22..00000000 --- a/modules/mesh-delivery-checker/internal/check/store.go +++ /dev/null @@ -1,24 +0,0 @@ -package check - -import ( - "context" - "errors" -) - -// ErrConflict is what a KV answers when a Create finds the key or an Update finds another revision than the one given. -var ErrConflict = errors.New("the key exists or changed") - -// KV is one of the checker's buckets: read, create and compare-and-set, each write answering the key's new revision. Only -// the checker's credential writes them (ADR 0444 clause 5, ADR 0484 clause 2). -type KV interface { - Get(ctx context.Context, key string) (value []byte, revision uint64, found bool, err error) - Create(ctx context.Context, key string, value []byte) (uint64, error) - Update(ctx context.Context, key string, value []byte, revision uint64) (uint64, error) - // Keys are every key of the bucket. - Keys(ctx context.Context) ([]string, error) -} - -// Deleter is a KV that can take a key away; a KV that cannot leaves it. -type Deleter interface { - Delete(ctx context.Context, key string) error -} diff --git a/modules/mesh-delivery-checker/internal/check/testdata/captured/README b/modules/mesh-delivery-checker/internal/check/testdata/captured/README deleted file mode 100644 index f2b348a3..00000000 --- a/modules/mesh-delivery-checker/internal/check/testdata/captured/README +++ /dev/null @@ -1,17 +0,0 @@ -go-test-failing.json, go-test-slow.json, go-test-empty.json and go-digest.json are what mesh-catalog's mesh-build-go answers -(TestResult and DigestResult, cmd/mesh-build-go levels.go and digest.go), marshalled by the module's own code: a throwaway -test beside the module's test_test.go and digest_test.go (workspaceFor + runUnit on the fixtures testdata/captured/failing, -slow and empty, and digestFixture + digests on testdata/repos/digest) at mesh-catalog origin/main cdbdb474, captured on -2026-10-21 for issue 1679 and not kept there. The fixtures' package names are the build module's own (fixture/failing/bad...). - -go-fetch-clean.json and go-fetch-conflict.json are what mesh-build-go's fetch step ends with (FetchResult, cmd/mesh-build-go -fetch.go and preview.go) for a fetch with a base, the Result bytes of the step in mesh-catalog's own tests -TestFetchWithABaseMergesAndAnswersThePreview and TestFetchWithAConflictEndsPassedAndNamesTheFiles (preview_test.go), copied -into a throwaway test that wrote them out, at mesh-catalog feat/r4c5-checker d5804927 (the git commands are the test's fake, -so the shas are its constants; the shape and the field names are the module's own marshalling). node-fetch-clean.json is the -FetchResult json.Marshal of mesh-build-node's fetch (fetch.go, preview.go) in its test TestFetchWithABaseMergesAndAnswersThePreview -(cmd/mesh-build-node/preview_test.go) at the same commit. Captured on 2026-10-21 for issue 1679. Both clean fetches carry `"programs":[]`, which a merging fetch of the build modules answers since issue 1577 (mesh-sdk buildstep.MergeInto's Programs), added by hand to the captured bytes: a fixture without it is an older build module's, and its line warns that no compiled program is refused. - -forge-get-file-go-mod.json is the answer of the forge's gitea_get_file (mesh-catalog modules/gitea, tools/index.ts) for modules/mesh-delivery-builder/go.mod of -novox/mesh-delivery at main, called through the mesh on 2026-10-21 for issue 1624; the checker's whole-module test answers its content through the seat -git's verb file (milestone 47/G W6.14). diff --git a/modules/mesh-delivery-checker/internal/check/testdata/captured/forge-get-file-go-mod.json b/modules/mesh-delivery-checker/internal/check/testdata/captured/forge-get-file-go-mod.json deleted file mode 100644 index a591e7e9..00000000 --- a/modules/mesh-delivery-checker/internal/check/testdata/captured/forge-get-file-go-mod.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "file": { - "content": "module mesh-delivery-builder\n\ngo 1.26.0\n\nrequire (\n\tgit.novox.be/novox/mesh-sdk/go v0.1.14-0.20261021100209-cb54756c3865\n\tgithub.com/nats-io/nats-server/v2 v2.11.17\n\tgithub.com/nats-io/nats.go v1.54.0\n)\n\nrequire (\n\tgithub.com/antithesishq/antithesis-sdk-go v0.7.0-default-no-op // indirect\n\tgithub.com/google/go-tpm v0.9.8 // indirect\n\tgithub.com/klauspost/compress v1.20.0 // indirect\n\tgithub.com/minio/highwayhash v1.0.4 // indirect\n\tgithub.com/nats-io/jwt/v2 v2.8.1 // indirect\n\tgithub.com/nats-io/nkeys v0.4.16 // indirect\n\tgithub.com/nats-io/nuid v1.0.1 // indirect\n\tgolang.org/x/crypto v0.57.0 // indirect\n\tgolang.org/x/sys v0.48.0 // indirect\n\tgolang.org/x/time v0.15.0 // indirect\n)\n", - "path": "modules/mesh-delivery-builder/go.mod", - "ref": "main", - "sha": "4431597e2e4d2a26b59006f9f8c54659a964ec68", - "size": 691 - } -} diff --git a/modules/mesh-delivery-checker/internal/check/testdata/captured/go-digest.json b/modules/mesh-delivery-checker/internal/check/testdata/captured/go-digest.json deleted file mode 100644 index 50f848bc..00000000 --- a/modules/mesh-delivery-checker/internal/check/testdata/captured/go-digest.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "level": "unit", - "packages": { - "fixture/digest/a": "c288afe6252c38d9e7286ecb5f28b3c961780871fcc253670dcc3151c11c1df2", - "fixture/digest/c": "11abf5f32f0f12caafd76c565e4c2c2f3bf2e3ce6c2c7fcb6c2264a06db40087" - }, - "without_tests": [ - "fixture/digest/b", - "fixture/digest/d" - ] -} diff --git a/modules/mesh-delivery-checker/internal/check/testdata/captured/go-fetch-clean.json b/modules/mesh-delivery-checker/internal/check/testdata/captured/go-fetch-clean.json deleted file mode 100644 index a87c2221..00000000 --- a/modules/mesh-delivery-checker/internal/check/testdata/captured/go-fetch-clean.json +++ /dev/null @@ -1 +0,0 @@ -{"workspace":"mvii1iwu5414e4","commit":"0123456789abcdef0123456789abcdef01234567","modules":["."],"base":"abcdef0123456789abcdef0123456789abcdef01","merge":"fedcba9876543210fedcba9876543210fedcba98","changed":["a.go","modules/m/main.go"],"programs":[],"trees":{"modules/m":{"tree":"1111111111111111111111111111111111111111","manifest":"ca3d163bab055381827226140568f3bef7eaac187cebd76878e0b63e9e442356","locks":{"go.sum":"c5fc83c01e92404452b986527d239140ccf9a48b88e0c268fbf38c2e1429e9c9"}}}} diff --git a/modules/mesh-delivery-checker/internal/check/testdata/captured/go-fetch-conflict.json b/modules/mesh-delivery-checker/internal/check/testdata/captured/go-fetch-conflict.json deleted file mode 100644 index e1d8a999..00000000 --- a/modules/mesh-delivery-checker/internal/check/testdata/captured/go-fetch-conflict.json +++ /dev/null @@ -1 +0,0 @@ -{"workspace":"mvii1iwz5050eb","commit":"0123456789abcdef0123456789abcdef01234567","modules":["."],"base":"abcdef0123456789abcdef0123456789abcdef01","conflicts":["a.go","sub/b.go"]} diff --git a/modules/mesh-delivery-checker/internal/check/testdata/captured/go-test-empty.json b/modules/mesh-delivery-checker/internal/check/testdata/captured/go-test-empty.json deleted file mode 100644 index daee148b..00000000 --- a/modules/mesh-delivery-checker/internal/check/testdata/captured/go-test-empty.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "level": "unit", - "passed": true, - "why": "the repository has no tests at the unit level", - "no_tests": true, - "tests": 0, - "skipped": 0, - "packages": [ - { - "dir": ".", - "package": "fixture/empty", - "passed": true, - "elapsed": 0, - "tests": 0, - "no_tests": true - } - ], - "elapsed": 0, - "bound": 5, - "over_bound": false -} diff --git a/modules/mesh-delivery-checker/internal/check/testdata/captured/go-test-failing.json b/modules/mesh-delivery-checker/internal/check/testdata/captured/go-test-failing.json deleted file mode 100644 index 2f6d90b0..00000000 --- a/modules/mesh-delivery-checker/internal/check/testdata/captured/go-test-failing.json +++ /dev/null @@ -1,45 +0,0 @@ -{ - "level": "unit", - "passed": false, - "why": "1 failed: fixture/failing/bad TestThreeIsFour", - "tests": 2, - "skipped": 0, - "packages": [ - { - "dir": ".", - "package": "fixture/failing/bad", - "passed": false, - "elapsed": 0.003, - "tests": 1 - }, - { - "dir": ".", - "package": "fixture/failing/good", - "passed": true, - "elapsed": 0.002, - "tests": 1 - } - ], - "elapsed": 0.003, - "bound": 5, - "slowest": [ - { - "package": "fixture/failing/bad", - "test": "TestThreeIsFour", - "elapsed": 0 - }, - { - "package": "fixture/failing/good", - "test": "TestTwo", - "elapsed": 0 - } - ], - "failed": [ - { - "package": "fixture/failing/bad", - "test": "TestThreeIsFour", - "output": " bad_test.go:7: Three() = 3, want 4\n--- FAIL: TestThreeIsFour (0.00s)" - } - ], - "over_bound": false -} diff --git a/modules/mesh-delivery-checker/internal/check/testdata/captured/go-test-slow.json b/modules/mesh-delivery-checker/internal/check/testdata/captured/go-test-slow.json deleted file mode 100644 index aa6e5754..00000000 --- a/modules/mesh-delivery-checker/internal/check/testdata/captured/go-test-slow.json +++ /dev/null @@ -1,30 +0,0 @@ -{ - "level": "unit", - "passed": true, - "tests": 2, - "skipped": 0, - "packages": [ - { - "dir": ".", - "package": "fixture/slow", - "passed": true, - "elapsed": 0.065, - "tests": 2 - } - ], - "elapsed": 0.065, - "bound": 5, - "slowest": [ - { - "package": "fixture/slow", - "test": "TestTakesAWhile", - "elapsed": 0.06 - }, - { - "package": "fixture/slow", - "test": "TestQuick", - "elapsed": 0 - } - ], - "over_bound": false -} diff --git a/modules/mesh-delivery-checker/internal/check/testdata/captured/node-fetch-clean.json b/modules/mesh-delivery-checker/internal/check/testdata/captured/node-fetch-clean.json deleted file mode 100644 index 55ecfeca..00000000 --- a/modules/mesh-delivery-checker/internal/check/testdata/captured/node-fetch-clean.json +++ /dev/null @@ -1 +0,0 @@ -{"workspace":"mvii1sxt979f67","commit":"0123456789abcdef0123456789abcdef01234567","modules":["modules/m"],"installed":[],"refused":[],"base":"abcdef0123456789abcdef0123456789abcdef01","merge":"0123456789abcdef0123456789abcdef01234567","changed":["modules/m/package.json"],"programs":[],"trees":{"modules/m":{"tree":"0123456789abcdef0123456789abcdef01234567","manifest":"0581b699d9d05517e69b21f5cedbeb2eee8aba2b205280b561be731594d7feef"}}} diff --git a/modules/mesh-delivery-checker/internal/check/trunkview.go b/modules/mesh-delivery-checker/internal/check/trunkview.go deleted file mode 100644 index d4f4f13d..00000000 --- a/modules/mesh-delivery-checker/internal/check/trunkview.go +++ /dev/null @@ -1,31 +0,0 @@ -package check - -import ( - "encoding/json" - "fmt" - - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog" -) - -// TrunkVerb is the key of the seat verb the trunk heads are asked by (design 47 G §197). -const TrunkVerb = "seat:" + meshcatalog.Seat + "." + meshcatalog.VerbRevision - -// TrunkHeads reads the trunk head of every repository out of the seat mesh-catalog's answer of `revision`. A candidate's -// revision is no trunk's and is refused. -func TrunkHeads(raw json.RawMessage) (map[string]string, error) { - var a meshcatalog.RevisionAnswer - if err := json.Unmarshal(raw, &a); err != nil { - return nil, fmt.Errorf("the catalog half's revision does not read: %w", err) - } - if a.Revision == nil { - return nil, fmt.Errorf("the catalog half's revision answers no revision (none-yet: %v)", a.NoneYet) - } - if a.Revision.Kind != "trunk" { - return nil, fmt.Errorf("the catalog half's revision %d is a %q revision, not a trunk's", a.Revision.Revision, a.Revision.Kind) - } - heads := map[string]string{} - for _, h := range a.Revision.Trunk { - heads[h.Repository] = h.Commit - } - return heads, nil -} diff --git a/modules/mesh-delivery-checker/internal/check/try.go b/modules/mesh-delivery-checker/internal/check/try.go deleted file mode 100644 index 9b35b4b2..00000000 --- a/modules/mesh-delivery-checker/internal/check/try.go +++ /dev/null @@ -1,852 +0,0 @@ -package check - -import ( - "context" - "encoding/json" - "errors" - "fmt" - "regexp" - "slices" - "sort" - "strconv" - "strings" - "sync" - "time" - - "git.novox.be/novox/mesh-contracts/go/clients/nodeengineclient" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-builder/buildrun" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-checker/checkermsg" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshdeliverycheckerclient" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshdeliveryclient" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshdeliverychecker" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep" - "git.novox.be/novox/mesh-sdk/go/keys" -) - -// A try is a pushed head judged by the checker as a pull request's head is, before its pull request is opened (ADR 0501 -// §5; issue 686's `mesh-controller.try`, which calls these tools from R4e): the head merged onto its trunk, the unit and the -// integration level through the build modules. It owes the forge nothing (no status, no preview) and writes no verdict; its -// state is the value of its key in the checker's state tries. - -// The try's tools and state. -const ( - TryTool = "checker_try" - TryReadTool = "checker_try_read" - TryEndTool = "checker_try_end" - // TriesTool lists the tries that wait or run (OpenTries). - TriesTool = "checker_tries" - // TriesState is the checker's state of tries: the bucket mesh-delivery-checker_tries, keys try-. - TriesState = "tries" - // MaxTries and MaxTriesWaiting are checked when a try is asked, mesh-wide: a new try is refused while MaxTries tries run - // on a build node or MaxTriesWaiting wait for one (queued, or their asks not yet taken by a node). It is no bound on - // what runs later: tries let in while waiting may later all run at once, and each node's build capacity bounds what - // runs on it. A try waiting behind the seat's other asks holds no node, so it no longer blocks the next try (issue - // 1890: at 19:53 on 2026-10-26 four tries sat queued behind 44 checks for up to 47 minutes and no fifth could be asked). - MaxTries = 4 - MaxTriesWaiting = 8 - // TryScan is how many of the newest tries a new ask reads to find the ones that wait or run (issue 1827). - TryScan = 64 - // TryKeep is how long an ended try's key is kept before the checker removes it. - TryKeep = 7 * 24 * time.Hour -) - -// The states of a try: asked and waiting, running, and its end. -const ( - TryQueued = "queued" - TryRunning = "running" - TryPass = "pass" - TryFail = "fail" - TryError = "error" -) - -var ( - tryHeadOK = regexp.MustCompile(`^([0-9a-f]{40}|[0-9a-f]{64})$`) - tryTestsOK = regexp.MustCompile(`^[A-Za-z0-9_^$|().*+?/\[\]-]+$`) - tryRepoOK = regexp.MustCompile(`^[A-Za-z0-9][A-Za-z0-9._-]*/[A-Za-z0-9][A-Za-z0-9._-]*$`) - tryTrunkOK = regexp.MustCompile(`^[A-Za-z0-9][A-Za-z0-9._/-]*$`) -) - -// Try is the value of a tries key. -type Try struct { - V int `json:"v"` - ID string `json:"id"` - // Repository, Head, Trunk and Branch are the first member's (the try's headline, and all a try of one repository - // names); Members are every member of the try, by repository: each an exact commit merged onto a trunk commit (a - // group try, issue 1921). A try written before members read as one member. - Repository string `json:"repository"` - // Head is the commit tried; Trunk the trunk commit it is merged onto, and Branch the trunk's branch when it was asked by name. - Head string `json:"head"` - Trunk string `json:"trunk"` - Branch string `json:"branch,omitempty"` - Members []TryMember `json:"members,omitempty"` - // Tests is a go test -run pattern: only those tests run, and nothing is kept. Level is unit or integration: only that - // level runs. Empty is every test of both levels. - Tests string `json:"tests,omitempty"` - Level string `json:"level,omitempty"` - State string `json:"state"` - // Told is true from the moment a whole try's start is said on the checker's stream until its end is said there: kept in the - // try's own state, so an end that is written and not said (the checker stopped between) is said when the checker starts. - Told bool `json:"told,omitempty"` - // Waiting is what the running try waits for now (its group's candidate from the indexer, ADR 0639 §5), empty when it waits for nothing; - // try-read gives it, so a try that sits still says why. - Waiting string `json:"waiting,omitempty"` - // Said is the try's report in words: what failed first, the tests run, kept and skipped per level, the time of each part. - Said string `json:"said,omitempty"` - // Took is the time from its start to its end, as Go writes a duration. - Took string `json:"took,omitempty"` - // Failed is every test that failed, each with its first line, at most meshdeliverycheckerclient.MaxFailures and then how many more - // (issue 1921); or what else failed first (a conflict, a refused step). - Failed []string `json:"failed,omitempty"` - Levels map[string]meshdeliverychecker.VerdictsByGroupHeadsValueLevelsValue `json:"levels,omitempty"` - Machines []string `json:"machines,omitempty"` - // Composition is what the composition on every placed node came to (a whole try, not one narrowed to a level or to - // some tests), and Notes the words the check noted on its way (the manifests judged, the module graph, the kept - // verdicts taken): the same as a group's pull-request check reports. - Composition *meshdeliverychecker.VerdictsByGroupHeadsValueComposition `json:"composition,omitempty"` - Notes []string `json:"notes,omitempty"` - // Asks are the ids of the asks the try put on the build seats' streams, each ending on the step key . of its - // build module: the delivery view counts those steps as a try's, not a candidate's check (build_usage). - Asks []string `json:"asks,omitempty"` - // Steps say where each ask stands while the try runs and after: asked until a node takes it, then the node, its - // state, the phase its step says and when (issue 1890: a 31-minute try could not be told queued from running). - Steps []TryStep `json:"steps,omitempty"` - Asked time.Time `json:"asked"` - Started time.Time `json:"started,omitzero"` - Ended time.Time `json:"ended,omitzero"` -} - -// TryMember is one repository of a try: the exact commit asked, never the branch's head now, and the trunk commit it is -// merged onto. Branch is the trunk's branch when the trunk was asked by name. -type TryMember struct { - Repository string `json:"repository"` - Head string `json:"head"` - Trunk string `json:"trunk"` - Branch string `json:"branch,omitempty"` -} - -// MembersOf are the try's members: its Members, or the one its headline names. -func (t Try) MembersOf() []TryMember { - if len(t.Members) > 0 { - return t.Members - } - return []TryMember{{Repository: t.Repository, Head: t.Head, Trunk: t.Trunk, Branch: t.Branch}} -} - -// TryAsked is a TryStep's state before a build node took its ask: it waits in the seat's stream. -const TryAsked = "asked" - -// TryStep is one ask of a try as its step key last said it. -type TryStep struct { - Ask string `json:"ask"` - Node string `json:"node,omitempty"` - State string `json:"state"` - Phase string `json:"phase,omitempty"` - Started time.Time `json:"started,omitzero"` - PhaseAt time.Time `json:"phase-at,omitzero"` - Ended time.Time `json:"ended,omitzero"` -} - -// tryWriter writes a running try's record again as its asks are put and their steps move: one writer per try, holding -// the revision it wrote last, so the try's end is written at that revision. A write refused (the try ended by hand) -// stops the writes; the end's own write then says it. -type tryWriter struct { - mu sync.Mutex - tr *Tryer - ctx context.Context - key string - t Try - rev uint64 - stopped bool -} - -// heard takes an ask put (step nil) or a value of its step key in, and writes the record when it changed. -func (w *tryWriter) heard(askID string, step *buildstep.Step) { - w.mu.Lock() - defer w.mu.Unlock() - if w.stopped { - return - } - changed := false - if !slices.Contains(w.t.Asks, askID) { - w.t.Asks, changed = append(w.t.Asks, askID), true - } - i := slices.IndexFunc(w.t.Steps, func(s TryStep) bool { return s.Ask == askID }) - if i < 0 { - w.t.Steps, changed = append(w.t.Steps, TryStep{Ask: askID, State: TryAsked}), true - i = len(w.t.Steps) - 1 - } - if step != nil { - now := TryStep{Ask: askID, Node: step.Node, State: step.State, Phase: step.Phase, Started: step.Started, - PhaseAt: step.PhaseAt, Ended: step.Ended} - changed = changed || now != w.t.Steps[i] - w.t.Steps[i] = now - } - if changed { - w.write() - } -} - -// waiting writes what the try waits for now ("" when it waits for nothing). -func (w *tryWriter) waiting(why string) { - w.mu.Lock() - defer w.mu.Unlock() - if w.stopped || w.t.Waiting == why { - return - } - w.t.Waiting = why - w.write() -} - -// write writes the record at the revision written last; a refusal stops the writes. -func (w *tryWriter) write() { - data, err := encodeTry(w.t) - if err != nil { - return - } - rev, err := w.tr.Tries.Update(w.ctx, w.key, data, w.rev) - if err != nil { - w.stopped = true - w.tr.logf("%s: its asks' progress is no longer written: %v", w.key, err) - return - } - w.rev = rev -} - -// end stops the writes and answers the record and its revision, for the try's end. -func (w *tryWriter) end() (Try, uint64) { - w.mu.Lock() - defer w.mu.Unlock() - w.stopped = true - return w.t, w.rev -} - -// HoldsANode says whether the try holds a build node now: it runs, and a step of its asks runs on a node, or it names -// no step (a checker that writes its asks only at the end, or one about to put its first). -func (t Try) HoldsANode() bool { - if t.State != TryRunning { - return false - } - if len(t.Steps) == 0 { - return true - } - return slices.ContainsFunc(t.Steps, func(s TryStep) bool { return s.State == buildstep.StepRunning || s.State == buildstep.StepAgain }) -} - -// Over says whether the try came to its end. -func (t Try) Over() bool { return t.State == TryPass || t.State == TryFail || t.State == TryError } - -// DecodeTry reads a tries value. -func DecodeTry(raw []byte) (Try, error) { - var t Try - if err := json.Unmarshal(raw, &t); err != nil { - return Try{}, fmt.Errorf("not a try: %w", err) - } - if !meshcatalogclient.IsTryGroup(t.ID) || t.Repository == "" || t.Head == "" || t.Trunk == "" { - return Try{}, errors.New("not a try: it names no id, repository, head or trunk") - } - t.Members = t.MembersOf() - return t, nil -} - -func encodeTry(t Try) ([]byte, error) { - t.V = keys.Version - return json.Marshal(t) -} - -// TryAsk is what checker_try is given. -type TryAsk struct { - Repository, Head, Trunk, Tests, Level string - // Members are the repositories of a group try, each an exact commit and, optionally, its trunk (a commit, or the - // trunk's branch for its head now); the single Repository, Head and Trunk above are one member. Both at once are refused. - Members []TryAskMember -} - -// TryAskMember is one repository of a group try as it is asked. -type TryAskMember struct { - Repository, Head, Trunk string -} - -// TryStore is the tries state as the tools see it. -type TryStore interface { - Keys() ([]string, error) - Get(key string) (json.RawMessage, error) - Create(key string, value []byte) error -} - -// NotChecked is the error of a try of a repository the checker judges no level of: one whose trunk the gate's source does -// not name. -func NotChecked(repository string) error { - return fmt.Errorf("no level of %s is checked by the checker", repository) -} - -// tryMember checks one member as it is asked and resolves its trunk: the gate's trunk head of its repository, a commit -// asked, or the trunk's branch (its head now). A repository with no trunk head is no repository the checker checks. -func tryMember(trunks map[string]string, a TryAskMember) (TryMember, error) { - repo := strings.ToLower(strings.TrimSuffix(strings.TrimSpace(a.Repository), ".git")) - head := strings.ToLower(strings.TrimSpace(a.Head)) - switch { - case !tryRepoOK.MatchString(repo) || strings.Contains(repo, ".."): - return TryMember{}, fmt.Errorf("%q is not a repository, /", a.Repository) - case !tryHeadOK.MatchString(head): - return TryMember{}, fmt.Errorf("the head %q of %s is not a full commit, 40 or 64 hex digits", a.Head, repo) - } - trunkHead := "" - for r, h := range trunks { - if strings.EqualFold(r, repo) { - trunkHead = h - } - } - if trunkHead == "" { - return TryMember{}, NotChecked(repo) - } - m := TryMember{Repository: repo, Head: head} - switch trunk := strings.TrimSpace(a.Trunk); { - case trunk == "": - m.Trunk = trunkHead - case tryHeadOK.MatchString(strings.ToLower(trunk)): - m.Trunk = strings.ToLower(trunk) - case tryTrunkOK.MatchString(trunk) && !strings.Contains(trunk, ".."): - // The checker judges pull requests into the trunk alone (ADR 0484 clause 11): a branch named is the trunk's head now. - m.Trunk, m.Branch = trunkHead, trunk - default: - return TryMember{}, fmt.Errorf("the trunk %q of %s is neither a full commit nor a branch", a.Trunk, repo) - } - return m, nil -} - -// sameMembers says whether two tries ask the same commits onto the same trunk commits. -func sameMembers(a, b []TryMember) bool { - return slices.EqualFunc(a, b, func(x, y TryMember) bool { - return x.Repository == y.Repository && x.Head == y.Head && x.Trunk == y.Trunk - }) -} - -// AskTry writes a new try, queued, and answers its id: a try of the same commits that waits or runs is the answer to a second -// ask, and a new try is refused while MaxTries tries run on a build node or MaxTriesWaiting wait for one. A try is a group of -// one or more members (issue 1921), each an exact commit, never the branch's head now: a push after the ask changes nothing -// of what is tried. trunks are the gate's trunk heads of every repository (source.main): a repository with none is no -// repository the checker checks. A trunk asked by name is its trunk head now. -func AskTry(store TryStore, trunks map[string]string, a TryAsk, now time.Time) (string, error) { - asked := a.Members - if a.Repository != "" || a.Head != "" || a.Trunk != "" { - if len(asked) > 0 { - return "", errors.New("name the members, or one repository with its head, not both") - } - asked = []TryAskMember{{Repository: a.Repository, Head: a.Head, Trunk: a.Trunk}} - } - if len(asked) == 0 { - return "", errors.New("name what to try: members (repository and head each), or a repository and its head") - } - switch { - case a.Level != "" && a.Level != buildstep.LevelUnit && a.Level != buildstep.LevelIntegration: - return "", fmt.Errorf("the level %q is neither unit nor integration", a.Level) - case a.Tests != "" && !tryTestsOK.MatchString(a.Tests): - return "", fmt.Errorf("the tests %q are not a go test -run pattern", a.Tests) - } - var members []TryMember - for _, m := range asked { - tm, err := tryMember(trunks, m) - if err != nil { - return "", err - } - if slices.ContainsFunc(members, func(o TryMember) bool { return o.Repository == tm.Repository }) { - return "", fmt.Errorf("%s is named twice: a try holds one commit of a repository", tm.Repository) - } - members = append(members, tm) - } - slices.SortFunc(members, func(x, y TryMember) int { return strings.Compare(x.Repository, y.Repository) }) - first := members[0] - t := Try{Repository: first.Repository, Head: first.Head, Trunk: first.Trunk, Branch: first.Branch, Members: members, - Tests: a.Tests, Level: a.Level, State: TryQueued, Asked: now.UTC()} - keys, err := store.Keys() - if err != nil { - return "", fmt.Errorf("the tries cannot be listed: %w", err) - } - // An ended try's key stays TryKeep, so the bucket holds thousands; one that waits or runs was asked lately. Only the - // newest TryScan keys are read, in parallel (a try id is the time in nanoseconds, so the newest sorts last). - sort.Slice(keys, func(i, j int) bool { - if len(keys[i]) != len(keys[j]) { - return len(keys[i]) > len(keys[j]) - } - return keys[i] > keys[j] - }) - if len(keys) > TryScan { - keys = keys[:TryScan] - } - tries := make([]Try, len(keys)) - live := make([]bool, len(keys)) - if err := parallel(len(keys), func(i int) error { - raw, err := store.Get(keys[i]) - if err != nil || len(raw) == 0 { - return nil - } - cur, err := DecodeTry(raw) - tries[i], live[i] = cur, err == nil && !cur.Over() - return nil - }); err != nil { - return "", err - } - var holding, waiting []string - for i, cur := range tries { - if !live[i] { - continue - } - if sameMembers(cur.MembersOf(), t.Members) && cur.Tests == t.Tests && cur.Level == t.Level { - return cur.ID, nil - } - said := fmt.Sprintf("%s (%s, %s)", cur.ID, sayMembers(cur.MembersOf()), cur.State) - if cur.HoldsANode() { - holding = append(holding, said) - } else { - waiting = append(waiting, said) - } - } - // Checked at this ask only: a try queued behind the seat's checks holds no node; tries let in while waiting may later - // all run at once, and each node's build capacity bounds what runs on it. - if len(holding) >= MaxTries || len(waiting) >= MaxTriesWaiting { - return "", fmt.Errorf("a new try is refused while %d tries run on a build node or %d wait for one; now %d run and %d wait: running %s; waiting %s; ask again when one ends", - MaxTries, MaxTriesWaiting, len(holding), len(waiting), orNone(holding), orNone(waiting)) - } - t.ID = "try-" + strconv.FormatInt(now.UnixNano(), 10) - data, err := encodeTry(t) - if err != nil { - return "", err - } - if err := store.Create(t.ID, data); err != nil { - return "", fmt.Errorf("the try %s cannot be written: %w", t.ID, err) - } - return t.ID, nil -} - -// ReadTry is a try's value, as stored. -func ReadTry(store TryStore, id string) (json.RawMessage, error) { - if !meshcatalogclient.IsTryGroup(id) { - return nil, fmt.Errorf("%q is not a try's id, try-", id) - } - raw, err := store.Get(id) - if err != nil { - return nil, err - } - if len(raw) == 0 { - return nil, fmt.Errorf("no try %s: it was never asked, or it ended more than %s ago and was removed", id, TryKeep) - } - return raw, nil -} - -// TryEnder is the tries state as the end tool sees it: one key with its revision, and a write at that revision. -type TryEnder interface { - Entry(key string) (json.RawMessage, uint64, error) - Update(key string, value []byte, revision uint64) error -} - -// EndTry ends a try that waits or runs as error, saying why and that it was ended by hand (issue 734): its place is -// free at once, and the next checker_try of its head asks anew. A try that ended already is refused, naming its end. -func EndTry(store TryEnder, id, why string, now time.Time) (Try, error) { - if !meshcatalogclient.IsTryGroup(id) { - return Try{}, fmt.Errorf("%q is not a try's id, try-", id) - } - why = strings.TrimSpace(why) - if why == "" { - return Try{}, errors.New("say why the try is ended: the why is kept in what it says") - } - raw, rev, err := store.Entry(id) - if err != nil { - return Try{}, err - } - if len(raw) == 0 { - return Try{}, fmt.Errorf("no try %s: it was never asked, or it ended more than %s ago and was removed", id, TryKeep) - } - t, err := DecodeTry(raw) - if err != nil { - return Try{}, err - } - if t.Over() { - return Try{}, fmt.Errorf("%s ended already, %s at %s", id, t.State, t.Ended.Format(time.RFC3339)) - } - t.State, t.Ended = TryError, now.UTC() - if !t.Started.IsZero() { - t.Took = t.Ended.Sub(t.Started).Round(time.Second).String() - } - t.Said = strings.TrimSpace("ended by hand (" + TryEndTool + "): " + why + " | " + t.Said) - t.Said = strings.TrimSuffix(t.Said, " |") - data, err := encodeTry(t) - if err != nil { - return Try{}, err - } - if err := store.Update(id, data, rev); err != nil { - return Try{}, fmt.Errorf("%s changed while it was ended, read it and end it again: %w", id, err) - } - return t, nil -} - -// TryOptions narrow what a try runs; a pull request's check has none. -type TryOptions struct { - Level string - Run string -} - -// Whole says the try runs everything a group's pull-request check runs (both levels of every member, the manifests judged by -// the manifest validator, the module graph, the composition on every placed node): it is narrowed to neither a level nor -// some tests. Such a try judges by the same code as the check, so the two cannot drift (issue 1921). -func (o *TryOptions) Whole() bool { return o != nil && o.Level == "" && o.Run == "" } - -// TryCase is the case a try is judged as: one pull of the group per member at its exact commit, with no pull request number -// (no ref: the commit is fetched as it is), the group named by the try's key, and the heads hash its candidate is keyed by. -func TryCase(key string, t Try, watch func(string, *buildstep.Step)) *Case { - cs := &Case{Key: key, Group: key, Watch: watch, Trunk: map[string]string{}, Queued: t.Asked, Progress: &Progress{}, - Try: &TryOptions{Level: t.Level, Run: t.Tests}} - var heads []meshdeliveryclient.Head - for _, m := range t.MembersOf() { - cs.Pulls = append(cs.Pulls, Pull{Repository: m.Repository, Head: m.Head, Trunk: m.Trunk}) - cs.Trunk[m.Repository] = m.Trunk - heads = append(heads, meshdeliveryclient.Head{Repository: m.Repository, Head: m.Head}) - } - cs.HeadsHash, _ = meshdeliveryclient.HeadsHash(heads) - cs.Heads = cs.HeadsHash - return cs -} - -// compositionMade says whether a composition was made; notMadeWords what it says when it was not. -func compositionMade(c *meshdeliverychecker.VerdictsByGroupHeadsValueComposition) bool { - return c != nil && c.State != meshdeliverycheckerclient.CompositionNotRun -} - -func notMadeWords(c *meshdeliverychecker.VerdictsByGroupHeadsValueComposition) string { - if c == nil || c.Words == "" { - return "no reason was given" - } - return c.Words -} - -// Tryer runs the tries: it takes a queued try, judges it through the same Judge as a pull request's check (a check ask, ADR -// 0525 §1), and writes its end. It holds no timer: a try starts when its key is written. -type Tryer struct { - Tries KV - Judge Judge - Bound time.Duration - // NotTaken ends a try whose ask no build node took within it as error (issue 734); none when 0. - NotTaken time.Duration - Now func() time.Time - Logf func(format string, args ...any) - - // Say publishes an event of the checker's stream (checkermsg.Started, checkermsg.Ended) with its body; nil says nothing. The - // indexer, which hears them, writes and deletes the candidate of a whole try's group. - // It answers the publish's error, nil only when the stream acknowledged it: an end not acknowledged is said again. - Say func(ctx context.Context, event string, body checkermsg.Event) error - - mu sync.Mutex - ending map[string]bool // tries whose end is being said now - wg sync.WaitGroup - inflight map[string]context.CancelFunc - seen map[string]bool // looked at since this process started: a try left running is taken over the first time -} - -func (tr *Tryer) now() time.Time { - if tr.Now != nil { - return tr.Now() - } - return time.Now() -} - -func (tr *Tryer) logf(format string, args ...any) { - if tr.Logf != nil { - tr.Logf(format, args...) - } -} - -// Wait returns when every try started so far has ended. -func (tr *Tryer) Wait() { tr.wg.Wait() } - -// Put takes a value of the tries state in: a queued try is started, and a try left running is taken over the first time -// this process sees it (the checker that ran it stopped; there is one checker). -func (tr *Tryer) Put(ctx context.Context, key string, value []byte) { - t, err := DecodeTry(value) - if err != nil { - tr.logf("tries.%s holds what is not a try, left: %v", key, err) - return - } - tr.mu.Lock() - if tr.inflight == nil { - tr.inflight, tr.seen = map[string]context.CancelFunc{}, map[string]bool{} - } - if t.Over() { - // Ended while it ran (checker_try_end): its judging stops, and its asks are no longer waited for. - if stop := tr.inflight[key]; stop != nil { - stop() - } - tr.mu.Unlock() - tr.sendEnd(ctx, key) // ended by hand while it ran, or its end was written and not said: the indexer drops its candidate - return - } - if tr.inflight[key] != nil || (t.State == TryRunning && tr.seen[key]) { - tr.mu.Unlock() - return - } - run, stop := context.WithCancel(ctx) - tr.seen[key] = true - tr.inflight[key] = stop - tr.mu.Unlock() - tr.wg.Add(1) - go func() { - defer tr.wg.Done() - defer func() { tr.mu.Lock(); delete(tr.inflight, key); tr.mu.Unlock(); stop() }() - tr.run(run, key) - }() -} - -// Reconsider looks at every try again (a delivery that held them ended), and removes the ended tries older than TryKeep. -func (tr *Tryer) Reconsider(ctx context.Context) { - keys, err := tr.Tries.Keys(ctx) - if err != nil { - tr.logf("the tries cannot be listed: %v", err) - return - } - for _, k := range keys { - raw, _, found, err := tr.Tries.Get(ctx, k) - if err != nil || !found { - continue - } - if t, err := DecodeTry(raw); err == nil && t.Over() && tr.now().Sub(t.Ended) > TryKeep { - if d, ok := tr.Tries.(interface { - Delete(ctx context.Context, key string) error - }); ok { - if err := d.Delete(ctx, k); err != nil { - tr.logf("%s ended %s ago and could not be removed: %v", k, tr.now().Sub(t.Ended).Round(time.Hour), err) - } - } - continue - } - tr.Put(ctx, k, raw) - } -} - -// run claims the try by compare-and-set, judges it within its bound and writes its end. -func (tr *Tryer) run(ctx context.Context, key string) { - raw, rev, found, err := tr.Tries.Get(ctx, key) - if err != nil || !found { - return - } - t, err := DecodeTry(raw) - if err != nil || t.Over() { - return - } - t.State, t.Started = TryRunning, tr.now().UTC() - t.Told = (&TryOptions{Level: t.Level, Run: t.Tests}).Whole() // its start is said below; its end is owed from now on - data, err := encodeTry(t) - if err != nil { - return - } - if rev, err = tr.Tries.Update(ctx, key, data, rev); err != nil { - if !errors.Is(err, ErrConflict) { - tr.logf("%s: %v", key, err) - } - return - } - progress := &tryWriter{tr: tr, ctx: ctx, key: key, t: t, rev: rev} - if t.Told { - started := checkermsg.Event{ID: key} - for _, m := range t.MembersOf() { - started.Members = append(started.Members, checkermsg.Member{Repository: m.Repository, Head: m.Head, Trunk: m.Trunk}) - } - tr.say(ctx, checkermsg.Started, started) - } - cs := TryCase(key, t, progress.heard) - cs.Wait = progress.waiting - judging := ctx - if tr.NotTaken > 0 { - judging = buildrun.NotTakenBound(ctx, tr.NotTaken) - } - out, judged := judgeWithin(judging, tr.Judge, cs, tr.Bound) - if ctx.Err() != nil { - return // left running: the checker takes it over when it starts; or ended by hand, which wrote its end - } - t, rev = progress.end() - t.Waiting = "" - v := out.Verdict - t.Ended = tr.now().UTC() - t.Took = t.Ended.Sub(t.Started).Round(time.Second).String() - t.Levels, t.Machines, t.Asks = v.Levels, v.Machines, cs.Asks() - t.Composition = v.Composition - t.Said = Report(v, cs, cs.Pulls[0], out.Builds, out.Slowest, out.Judged) - if len(cs.Pulls) > 1 { - t.Said = sayMembers(t.MembersOf()) + ": " + t.Said - } - t.Notes = cs.Notes() - for _, n := range t.Notes { - t.Said += " | " + n - } - switch { - case !judged || IsCouldNotRun(v) || IsLostAsk(v) || IsNotTaken(v): - // Not the change's: its ask was given up or never taken (issue 734), or a part of the mesh was not heard. - t.State = TryError - if IsLostAsk(v) || IsNotTaken(v) { - t.Failed = []string{failedOf(v).Words} - } - case v.State == meshdeliverycheckerclient.VerdictPass && cs.Try.Whole() && compositionMade(v.Composition) && strings.Contains(v.Composition.Words, nodeengineclient.NoAnswer): - // A node that gave no answer passes a group's check with a warning; a try that is to say the group composes says it - // did not, naming the node (ADR 0637 §3). - t.State = TryError - t.Failed = []string{"the composition was not made on every placed node: " + v.Composition.Words} - case v.State == meshdeliverycheckerclient.VerdictPass && cs.Try.Whole() && !compositionMade(v.Composition): - // A whole try that judged the tests and not the manifests and the composition has not tried what its group's check - // judges: it is no pass, and it says why (failure must be loud). It is an error, not the change's failure. - t.State = TryError - t.Failed = []string{"the composition was not made: " + notMadeWords(v.Composition)} - case v.State == meshdeliverycheckerclient.VerdictPass: - t.State = TryPass - default: - t.State = TryFail - t.Failed = failedLines(v) - } - if t.Tests != "" { - t.Said += " | only the tests " + t.Tests + " (Go); nothing kept" - } - if data, err = encodeTry(t); err == nil { - _, err = tr.Tries.Update(ctx, key, data, rev) - } - if err != nil { - tr.logf("%s: its end could not be written: %v", key, err) - return - } - tr.logf("%s: %s", key, t.State) - // The end just written comes back on the key's watch, and Put then stops this run's context (it stops judging a try - // ended by hand) while this run says the end, which Put's own say leaves to it: the end is said on a context that - // stop does not cancel, or it is never said and the indexer keeps the candidate of the try's group. - tr.sendEnd(context.WithoutCancel(ctx), key) -} - -// sendEnd says the end of an ended try whose start was said (Told) with the state it ended in, then clears Told in the try's -// own state; a checker that stopped between the two says it again at its start. Every end is said so: pass, fail, error and -// by hand. -func (tr *Tryer) sendEnd(ctx context.Context, key string) { - tr.mu.Lock() - if tr.ending[key] { - tr.mu.Unlock() - return - } - if tr.ending == nil { - tr.ending = map[string]bool{} - } - tr.ending[key] = true - tr.mu.Unlock() - defer func() { tr.mu.Lock(); delete(tr.ending, key); tr.mu.Unlock() }() - raw, rev, found, err := tr.Tries.Get(ctx, key) - if err != nil || !found { - return - } - t, err := DecodeTry(raw) - if err != nil || !t.Over() || !t.Told { - return - } - if tr.say(ctx, checkermsg.Ended, checkermsg.Event{ID: key, State: t.State}) != nil { - return // not acknowledged: Told stays, and the next Put or Reconsider says the end again - } - t.Told = false - data, err := encodeTry(t) - if err == nil { - _, err = tr.Tries.Update(ctx, key, data, rev) - } - if err != nil && !errors.Is(err, ErrConflict) { - tr.logf("%s: its end was said and Told could not be cleared: %v", key, err) - } -} - -// say publishes a try event; a failure is said in the log (the indexer finds the open tries again at its start). -func (tr *Tryer) say(ctx context.Context, event string, body checkermsg.Event) error { - if tr.Say == nil { - return nil - } - err := tr.Say(ctx, event, body) - if err != nil { - tr.logf("%s of %s could not be said: %v", event, body.ID, err) - } - return err -} - -// OpenTries are every try that waits or runs now: what checker_tries answers, so a part that missed an event (the indexer at -// its start) finds them without reading the checker's state. All the keys are read (an old open try is as open as a new one), in -// parallel. -func OpenTries(store TryStore) ([]checkermsg.Open, error) { - keys, err := store.Keys() - if err != nil { - return nil, fmt.Errorf("the tries cannot be listed: %w", err) - } - sort.Slice(keys, func(i, j int) bool { - if len(keys[i]) != len(keys[j]) { - return len(keys[i]) > len(keys[j]) - } - return keys[i] > keys[j] - }) - found := make([]*checkermsg.Open, len(keys)) - if err := parallel(len(keys), func(i int) error { - raw, err := store.Get(keys[i]) - if err != nil || len(raw) == 0 { - return nil - } - t, err := DecodeTry(raw) - if err != nil || t.Over() { - return nil - } - o := checkermsg.Open{ID: t.ID, State: t.State, Whole: (&TryOptions{Level: t.Level, Run: t.Tests}).Whole()} - for _, m := range t.MembersOf() { - o.Members = append(o.Members, checkermsg.Member{Repository: m.Repository, Head: m.Head, Trunk: m.Trunk}) - } - found[i] = &o - return nil - }); err != nil { - return nil, err - } - out := []checkermsg.Open{} // none open is an empty list, never null: a reader tells it from no answer (issue 1921) - for _, o := range found { - if o != nil { - out = append(out, *o) - } - } - return out, nil -} - -// judgeWithin runs a case within the bound (none when 0: the asks' steps are bounded from their start, ADR 0525 §6). A -// judge that fails to judge, and a check that ran past its bound, are verdicts of failure naming the machine and the step, -// and judged says false for them. -func judgeWithin(ctx context.Context, j Judge, cs *Case, bound time.Duration) (Outcome, bool) { - run, cancel := context.WithCancel(ctx) - if bound > 0 { - run, cancel = context.WithTimeoutCause(ctx, bound, errBound) - } - defer cancel() - out, err := j.Judge(run, cs) - stage, node := cs.Progress.Now() - if node == "" { - node = "checker" - } - switch { - case ctx.Err() != nil: - return Outcome{}, false - case context.Cause(run) == errBound: - if stage == "" { - stage = "starting" - } - return Outcome{Verdict: failure(node, fmt.Sprintf("the check ran past its bound of %s, stuck at: %s", bound, stage))}, false - case err != nil: - return Outcome{Verdict: failure(node, err.Error())}, false - } - return out, true -} - -// sayMembers names a try's members, each repository at its short commit. -func sayMembers(ms []TryMember) string { - var out []string - for _, m := range ms { - out = append(out, fmt.Sprintf("%s@%.12s", m.Repository, m.Head)) - } - return strings.Join(out, " + ") -} - -// orNone joins the tries said, or says none. -func orNone(said []string) string { - if len(said) == 0 { - return "none" - } - return strings.Join(said, ", ") -} diff --git a/modules/mesh-delivery-checker/internal/check/try_test.go b/modules/mesh-delivery-checker/internal/check/try_test.go deleted file mode 100644 index d6dc4827..00000000 --- a/modules/mesh-delivery-checker/internal/check/try_test.go +++ /dev/null @@ -1,505 +0,0 @@ -package check - -import ( - "context" - "encoding/json" - "errors" - "fmt" - "mesh-delivery-checker/rules" - "slices" - "strings" - "testing" - "time" - - "git.novox.be/novox/mesh-contracts/go/clients/nodeengineclient" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-checker/checkermsg" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshdeliverycheckerclient" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep" -) - -// memTries is the tries state as the tools see it, over a memKV. -type memTries struct{ kv *memKV } - -func (m memTries) Keys() ([]string, error) { return m.kv.Keys(context.Background()) } -func (m memTries) Get(key string) (json.RawMessage, error) { - v, _, _, err := m.kv.Get(context.Background(), key) - return v, err -} -func (m memTries) Create(key string, value []byte) error { - _, err := m.kv.Create(context.Background(), key, value) - return err -} - -// writtenTries is a memKV that keeps every running try it was given to write, in order. -type writtenTries struct { - *memKV - running []Try -} - -func (w *writtenTries) Update(ctx context.Context, key string, value []byte, rev uint64) (uint64, error) { - if t, err := DecodeTry(value); err == nil && !t.Over() { - w.running = append(w.running, t) - } - return w.memKV.Update(ctx, key, value, rev) -} - -var tryTrunks = map[string]string{repoA: trunkA, repoSDK: trunkS, hqRepo: trunkA} - -func readTry(t testing.TB, kv *memKV, id string) Try { - t.Helper() - raw, _, found, _ := kv.Get(context.Background(), id) - if !found { - t.Fatalf("no try %s", id) - } - tr, err := DecodeTry(raw) - if err != nil { - t.Fatal(err) - } - return tr -} - -func TestATryIsAskedQueuedOncePerHeadAndAtMostFourAtOnce(t *testing.T) { // ADR 0501 §5 - kv := newMemKV() - store := memTries{kv} - at := time.Date(2026, 10, 22, 18, 0, 0, 0, time.UTC) - id, err := AskTry(store, tryTrunks, TryAsk{Repository: repoA, Head: head1, Trunk: "main"}, at) - if err != nil || !strings.HasPrefix(id, "try-") { - t.Fatalf("id %q, %v", id, err) - } - tr := readTry(t, kv, id) - if tr.State != TryQueued || tr.Trunk != trunkA || tr.Branch != "main" || tr.Head != head1 || tr.Repository != repoA { - t.Errorf("try = %+v, want queued on the trunk's head", tr) - } - again, err := AskTry(store, tryTrunks, TryAsk{Repository: repoA, Head: head1, Trunk: "main"}, at.Add(time.Second)) - if err != nil || again != id { - t.Errorf("a second ask of the same head answered %q, %v, want %q", again, err, id) - } - // Issue 1890: tries on a build node (a step of theirs running, or none named yet) and tries waiting for one (queued, or - // their asks not taken) are bounded apart, MaxTries and MaxTriesWaiting; the refusal names both counts. - // A group try is the same try whatever the order of its members; the commits asked are the commits tried. - group := TryAsk{Members: []TryAskMember{{Repository: repoSDK, Head: head2}, {Repository: repoA, Head: head1}}} - gid, err := AskTry(store, tryTrunks, group, at.Add(time.Second)) - if err != nil || gid == id { - t.Fatalf("the group try = %q, %v, want a try of its own", gid, err) - } - group.Members[0], group.Members[1] = group.Members[1], group.Members[0] - if again, err := AskTry(store, tryTrunks, group, at.Add(time.Minute)); err != nil || again != gid { - t.Errorf("the group asked in another order answered %q, %v, want %q", again, err, gid) - } - if g := readTry(t, kv, gid); len(g.Members) != 2 || g.Members[0].Repository != repoA || g.Members[0].Head != head1 || g.Members[1].Trunk != trunkS { - t.Errorf("group try = %+v, want its members by repository at the commits asked", g.Members) - } - if open, err := OpenTries(store); err != nil || len(open) != 2 || !open[0].Whole || len(open[1].Members) != 2 && len(open[0].Members) != 2 { - t.Errorf("open tries = %+v, %v, want the two queued", open, err) - } - if !meshcatalogclient.IsTryGroup(gid) || meshcatalogclient.IsTryGroup("feat/x") || meshcatalogclient.IsTryGroup("fix/1921-try-1") { - t.Errorf("which candidates keys are a try's group: %s is, a branch is not", gid) - } - onNode := func(i int) Try { - return Try{ID: fmt.Sprintf("try-%d", i), Repository: repoA, Head: fmt.Sprintf("%040x", i), Trunk: trunkA, State: TryRunning, - Steps: []TryStep{{Ask: "a", State: buildstep.StepRunning}}} - } - waitingFor := func(i int) Try { - return Try{ID: fmt.Sprintf("try-%d", i), Repository: repoA, Head: fmt.Sprintf("%040x", i), Trunk: trunkA, State: TryRunning, - Steps: []TryStep{{Ask: "a", State: TryAsked}}} - } - for _, c := range []struct { - what string - holding, wait int - refused string - }{ - {"four queued behind the checks, none on a node: a fifth is taken", 0, 4, ""}, - {"four on a node", MaxTries, 0, "now 4 run and 0 wait"}, - {"three on a node, eight waiting", 3, MaxTriesWaiting, "a new try is refused while 4 tries run on a build node or 8 wait for one; now 3 run and 8 wait"}, - } { - kv := newMemKV() - for i := range c.holding + c.wait { - tr := waitingFor(i + 1) - if i < c.holding { - tr = onNode(i + 1) - } - data, _ := encodeTry(tr) - _, _ = kv.Create(context.Background(), tr.ID, data) - } - _, err := AskTry(memTries{kv}, tryTrunks, TryAsk{Repository: repoSDK, Head: head1}, at.Add(time.Minute)) - if (c.refused == "") != (err == nil) || (err != nil && !strings.Contains(err.Error(), c.refused)) { - t.Errorf("%s: answered %v, want refused %q", c.what, err, c.refused) - } - } - // Issue 1748: a try whose step ended on a transport fault, the bus giving its ask again, still runs. - if !(Try{State: TryRunning, Steps: []TryStep{{Ask: "a", State: buildstep.StepAgain}}}).HoldsANode() { - t.Error("a try with a step given again no longer runs") - } -} - -func TestATryOfARepositoryWithNoCheckedLevelIsRefused(t *testing.T) { // the agreed error of the try - store := memTries{newMemKV()} - for _, repo := range []string{"novox/no-trunk", "novox/mesh-lab"} { // hq is checked since R4g (ADR 0527): see tryTrunks - _, err := AskTry(store, tryTrunks, TryAsk{Repository: repo, Head: head1, Trunk: "main"}, time.Now()) - if err == nil || err.Error() != "no level of "+repo+" is checked by the checker" { - t.Errorf("%s: %v", repo, err) - } - } - for _, bad := range []TryAsk{{Repository: repoA, Head: "abc"}, {Repository: repoA, Head: head1, Level: "e2e"}, - {Repository: repoA, Head: head1, Tests: "a b"}, {Repository: "x", Head: head1}, {Repository: repoA, Head: head1, Trunk: "-x"}, - // A group try (issue 1921): members or one repository, never both or none; one commit per repository; every member checked. - {}, - {Repository: repoA, Head: head1, Members: []TryAskMember{{Repository: repoSDK, Head: head2}}}, - {Members: []TryAskMember{{Repository: repoA, Head: head1}, {Repository: repoA, Head: head2}}}, - {Members: []TryAskMember{{Repository: repoA, Head: head1}, {Repository: repoSDK, Head: "main"}}}, - {Members: []TryAskMember{{Repository: repoA, Head: head1}, {Repository: "novox/no-trunk", Head: head2}}}} { - if _, err := AskTry(store, tryTrunks, bad, time.Now()); err == nil { - t.Errorf("%+v was taken", bad) - } - } -} - -// fakeTryCandidates answers the indexer's candidate of a try's group from memory, recording the keys asked. -type fakeTryCandidates struct { - cand meshcatalog.CandidatesByGroupValue - err error - asked []string - // during is called while the try waits for the candidate. - during func() -} - -func (f *fakeTryCandidates) TryCandidate(_ context.Context, group, heads string, _ time.Duration) (meshcatalog.CandidatesByGroupValue, error) { - if f.during != nil { - f.during() - } - f.asked = append(f.asked, group+"."+heads) - return f.cand, f.err -} - -// wholeBench makes the bench judge a whole try as the checker does: the composition on every placed node and the -// indexer's candidate of the try's group. -func wholeBench(b *bench, cand meshcatalog.CandidatesByGroupValue) (*fakeCompositions, *fakeTryCandidates) { - comps := &fakeCompositions{v: composedOn("v0.1.14-x", 40, "g14", "shanks")} - cands := &fakeTryCandidates{cand: cand} - b.ex.Compositions, b.ex.Candidates = comps, cands - return comps, cands -} - -// A group try (issue 1921): several repositories each at the exact commit asked, judged by the code of a group's pull-request -// check; the two cannot drift, and a later check of the same heads keeps what the try passed. -func TestATryIsJudgedAsAGroupsCheckAndOwesTheForgeNothing(t *testing.T) { // ADR 0501 §5, issue 1921 - ctx := context.Background() - kv := newMemKV() - id, err := AskTry(memTries{kv}, tryTrunks, TryAsk{Members: []TryAskMember{{Repository: repoSDK, Head: head2, Trunk: trunkS}, {Repository: repoA, Head: head1, Trunk: trunkA}}}, time.Now()) - if err != nil { - t.Fatal(err) - } - b := newBench(t) - comps, cands := wholeBench(b, meshcatalog.CandidatesByGroupValue{Fpset: "fps-of-the-try"}) - written := &writtenTries{memKV: kv} - var waiting string - cands.during = func() { waiting = readTry(t, kv, id).Waiting } // ADR 0639 §5: the stored try says what it waits for - var said []string - var tr *Tryer - echoed := false - tr = &Tryer{Tries: written, Judge: b.ex, Say: func(ctx context.Context, event string, e checkermsg.Event) error { - if event == checkermsg.Ended && !echoed { - // The end the run wrote comes back on the key's watch while the run says it: Put stops the run's context and - // leaves the saying to the run, whose say must not be stopped with it (issue 1921). - echoed = true - raw, _, _, _ := kv.Get(context.Background(), id) - tr.Put(context.Background(), id, raw) - } - if err := ctx.Err(); err != nil { - return err // a publish on a stopped context is never acknowledged - } - said = append(said, fmt.Sprintf("%s %s %d %s", event, e.ID, len(e.Members), e.State)) - return nil - }} - raw, _, _, _ := kv.Get(ctx, id) - tr.Put(ctx, id, raw) - tr.Wait() - // The indexer hears the start with the members at their commits, and the end (it writes and deletes the group's candidate). - if len(said) != 2 || said[0] != "try.started "+id+" 2 " || said[1] != "try.ended "+id+" 0 "+TryPass { - t.Errorf("events = %v, want the start with 2 members and the end", said) - } - // What the indexer reads: checkermsg.Decode accepts the events as said and refuses a body that is no try's. - for _, row := range []struct { - name, event, body string - ok bool - }{ - {"a start with its members", checkermsg.Started, `{"id":"` + id + `","members":[{"repository":"` + repoA + `","head":"` + head1 + `","trunk":"` + trunkA + `"}]}`, true}, - {"an end with its state", checkermsg.Ended, `{"id":"` + id + `","state":"pass"}`, true}, - {"an id that is no try's", checkermsg.Ended, `{"id":"pull-7","state":"pass"}`, false}, - {"a start with no member", checkermsg.Started, `{"id":"` + id + `"}`, false}, - {"a body that is no JSON", checkermsg.Ended, `try-7`, false}, - } { - if e, err := checkermsg.Decode(row.event, []byte(row.body)); (err == nil) != row.ok || (row.ok && e.ID != id) { - t.Errorf("Decode of %s = %+v, %v, want ok=%v", row.name, e, err, row.ok) - } - } - got := readTry(t, kv, id) - if !strings.Contains(waiting, "candidate") || got.Waiting != "" { - t.Errorf("waiting while the candidate was awaited = %q, after the end %q: want the reason, then none", waiting, got.Waiting) - } - if got.Told { // the end was said: nothing is owed - t.Errorf("the ended try still owes its end: %+v", got) - } - if open, err := OpenTries(memTries{kv}); err != nil || len(open) != 0 { - t.Errorf("open tries after the end = %v, %v", open, err) - } else if raw, _ := json.Marshal(open); string(raw) != "[]" { // issue 1921: none open is [] on the wire, never null - t.Errorf("none open is answered %s, want []", raw) - } - if got.State != TryPass || got.Took == "" || len(got.Members) != 2 || got.Members[0].Repository != repoA || got.Members[1].Head != head2 || - got.Said == "" || got.Levels[buildstep.LevelUnit].Run+got.Levels[buildstep.LevelUnit].Kept != 4 { // the bench gives both members the same digests - t.Fatalf("try = %+v", got) - } - if got.Composition == nil || got.Composition.State != meshdeliverycheckerclient.CompositionPass || len(got.Machines) == 0 { - t.Errorf("the try's composition = %+v, want the composition on every placed node, as a check's", got.Composition) - } - // The same key the indexer's candidate of the group has: the try's id and the heads of its members. - if len(comps.asked) != 1 || comps.asked[0] != id || len(cands.asked) != 1 || !strings.HasPrefix(cands.asked[0], id+".") { - t.Errorf("composed %v, candidate asked %v, want the try's key %s", comps.asked, cands.asked, id) - } - // Issue 1890: while it runs, the try names its asks as soon as they are put, and then where each step stands. - if len(written.running) < 3 || len(written.running[1].Asks) != 1 || written.running[1].Steps[0].State != TryAsked { - t.Errorf("the running try's writes = %+v, want its ask named while it ran", written.running) - } - // Two check asks and the checking program's two run asks (the seat list and the verdict). - if len(got.Steps) != 4 || got.Steps[0].Node != "shanks" || got.Steps[0].State != buildstep.StepPassed || len(got.Asks) != 4 { - t.Errorf("the ended try's steps = %+v, asks %v", got.Steps, got.Asks) - } - for _, a := range got.Asks { // the delivery view counts their steps as a try's (build_usage) - if _, err := buildstep.AskStepKey("", "shanks", a); err != nil { - t.Errorf("the try names %q, which is no ask id: %v", a, err) - } - } - // Each member is fetched at the exact commit asked, merged onto its own trunk, with no pull request's ref. - fetch := b.steps.tool("fetch") - if len(fetch) != 2 { - t.Fatalf("fetch = %+v, want one per member", fetch) - } - for _, f := range fetch { - want := map[string][2]string{repoA: {head1, trunkA}, repoSDK: {head2, trunkS}}[f.args["repository"].(string)] - if f.args["commit"] != want[0] || f.args["base"] != want[1] || f.args["ref"] != nil { - t.Errorf("fetch = %+v, want the exact commit %s merged onto %s", f.args, want[0], want[1]) - } - } - // A whole try writes the merge previews the indexer makes its candidate from; it writes no status and asks no Approve. - if keys, _ := b.prev.Keys(ctx); len(keys) != 2 { - t.Errorf("a whole try wrote the previews %v, want one per member", keys) - } - // An ended try is not run again. - raw, _, _, _ = kv.Get(ctx, id) - tr.Put(ctx, id, raw) - tr.Wait() - if n := len(b.steps.tool("fetch")); n != 2 { - t.Errorf("an ended try was fetched again: %d fetches", n) - } - // The kept verdicts: what the try passed is kept under the digests of the merged trees, so the pull-request check of - // the same head on the same trunk runs none of it again (and a push of other code runs only what changed). - before := len(b.steps.tool("test")) - out := b.judge(t, caseOf(t, pullOf(repoA, 7, head1))) - if out.Verdict.State != meshdeliverycheckerclient.VerdictPass || out.Verdict.Levels[buildstep.LevelUnit].Kept == 0 || out.Verdict.Levels[buildstep.LevelUnit].Run != 0 || - out.Verdict.Levels[buildstep.LevelIntegration].Run != 0 { - t.Errorf("the check of the tried head = %+v, want everything the try passed kept and nothing run", out.Verdict.Levels) - } - if after := len(b.steps.tool("test")); after != before { - t.Errorf("the check of the tried head ran %d test steps, want none: the try's passes are kept", after-before) - } -} - -func TestATryOfOneLevelAndSomeTestsRunsThemAloneAndKeepsNothing(t *testing.T) { - ctx := context.Background() - kv := newMemKV() - id, err := AskTry(memTries{kv}, tryTrunks, TryAsk{Repository: repoA, Head: head1, Level: buildstep.LevelIntegration, Tests: "TestBus|TestStore"}, time.Now()) - if err != nil { - t.Fatal(err) - } - b := newBench(t) - tr := &Tryer{Tries: kv, Judge: b.ex, Say: func(context.Context, string, checkermsg.Event) error { - t.Error("a try of one level and some tests said an event: it has no candidate") - return nil - }} - raw, _, _, _ := kv.Get(ctx, id) - tr.Put(ctx, id, raw) - tr.Wait() - if open, _ := OpenTries(memTries{kv}); len(open) != 0 { - t.Errorf("open = %v", open) - } - tests := b.steps.tool("test") - if len(tests) != 1 || tests[0].args["level"] != buildstep.LevelIntegration || tests[0].args["run"] != "TestBus|TestStore" { - t.Fatalf("tests = %+v, want the integration level alone with the run pattern", tests) - } - if n := len(b.steps.tool("digest")); n != 0 { - t.Errorf("%d digests for a try of some tests", n) - } - if keys, _ := b.kept.Keys(ctx); len(keys) != 0 { - t.Errorf("kept %v from a try of some tests", keys) - } - if got := readTry(t, kv, id); got.State != TryPass || !strings.Contains(got.Said, "only the tests TestBus|TestStore") { - t.Errorf("try = %+v", got) - } - t.Run("a try of one level keeps only that level", func(t *testing.T) { - kv := newMemKV() - id, _ := AskTry(memTries{kv}, tryTrunks, TryAsk{Repository: repoA, Head: head1, Level: buildstep.LevelUnit}, time.Now()) - b := newBench(t) - tr := &Tryer{Tries: kv, Judge: b.ex} - raw, _, _, _ := kv.Get(ctx, id) - tr.Put(ctx, id, raw) - tr.Wait() - keys, _ := b.kept.Keys(ctx) - if got := readTry(t, kv, id); got.State != TryPass || len(keys) == 0 { - t.Fatalf("try = %+v, kept %v", got, keys) - } - for _, k := range keys { - if !strings.HasPrefix(k, buildstep.LevelUnit+".") { - t.Errorf("a try of the unit level kept %s", k) - } - } - }) -} - -func TestAFailingTryNamesWhatFailedAndAStepThatCannotRunIsAnError(t *testing.T) { - ctx := context.Background() - kv := newMemKV() - b := newBench(t) - b.test = func(c stepCall) (any, error) { return captured[Tested](t, "go-test-failing"), nil } - id, _ := AskTry(memTries{kv}, tryTrunks, TryAsk{Repository: repoA, Head: head1}, time.Now()) - tr := &Tryer{Tries: kv, Judge: b.ex} - raw, _, _, _ := kv.Get(ctx, id) - tr.Put(ctx, id, raw) - tr.Wait() - if got := readTry(t, kv, id); got.State != TryFail || len(got.Failed) != 2 || !strings.Contains(got.Failed[0], "unit: fixture/failing/bad.TestThreeIsFour") || - !strings.Contains(got.Failed[1], "integration: fixture/failing/bad.TestThreeIsFour") { // both levels ran (the operator, 2026-11-02) - t.Errorf("try = %+v", got) - } - // A whole try that could not judge the manifests and the composition is no pass; a failed composition is named beside - // the failed tests (the group's check does as much), and a candidate of other heads is not the try's. - for _, row := range []struct { - name string - cand *fakeTryCandidates - comp *rules.Composed - state, said string - }{ - {name: "the indexer wrote no candidate", cand: &fakeTryCandidates{err: errors.New("the indexer wrote no candidate within 5m0s")}, state: TryError, said: "the indexer wrote no candidate within 5m0s"}, - {name: "a node that gave no composition answer", cand: &fakeTryCandidates{}, comp: &rules.Composed{Composer: "x", Nodes: []string{"g14"}}, - state: TryError, said: "g14: " + nodeengineclient.NoAnswer}, - {name: "a composition refused on a node", cand: &fakeTryCandidates{}, comp: ptr(refusedOn("x", "g14", "web: needs a state mail does not keep")), - state: TryFail, said: "not composed on g14: web: needs a state mail does not keep"}, - } { - kv := newMemKV() - b := newBench(t) - comps, _ := wholeBench(b, meshcatalog.CandidatesByGroupValue{}) - b.ex.Candidates = row.cand - if row.comp != nil { - comps.v = *row.comp - } - id, _ := AskTry(memTries{kv}, tryTrunks, TryAsk{Repository: repoA, Head: head1}, time.Now()) - var ends []string - tr := &Tryer{Tries: kv, Judge: b.ex, Say: func(_ context.Context, event string, e checkermsg.Event) error { - if event == checkermsg.Ended { - ends = append(ends, e.State) - } - return nil - }} - raw, _, _, _ := kv.Get(ctx, id) - tr.Put(ctx, id, raw) - tr.Wait() - if len(ends) != 1 || ends[0] != row.state { // every end says its state: error as well as fail - t.Errorf("%s: ends said = %v, want once %s", row.name, ends, row.state) - } - if got := readTry(t, kv, id); got.State != row.state || !strings.Contains(strings.Join(got.Failed, " | ")+got.Said, row.said) { - t.Errorf("%s: try = %s, failed %v, said %q, want %s naming %q", row.name, got.State, got.Failed, got.Said, row.state, row.said) - } - } - // No build node is no error since R4g: the try's ask waits in the check stream until a node pulls it (ADR 0525 §4). -} - -func TestATryLeftRunningIsTakenOver(t *testing.T) { - ctx := context.Background() - // Whether the start was said is in the try's own state (Told), so a checker that starts later says the end of a try it did - // not start, whatever way the try ended. - for _, row := range []struct { - name string - told bool - failFirst bool // the stream does not acknowledge the first end said - after func(t *testing.T, kv *memKV, id string) - ends []string - }{ - {name: "the first publish of the end is not acknowledged", told: true, failFirst: true, ends: []string{TryPass}}, - {name: "left running after its start was said", told: true, ends: []string{TryPass}}, - {name: "left running with no start said", told: false, ends: []string{TryPass}}, - {name: "ended by hand after the start was said", told: true, ends: []string{TryError}, after: func(t *testing.T, kv *memKV, id string) { - if _, err := EndTry(endable{kv}, id, "stuck", time.Now()); err != nil { - t.Fatal(err) - } - }}, - } { - t.Run(row.name, func(t *testing.T) { - kv := newMemKV() - id, _ := AskTry(memTries{kv}, tryTrunks, TryAsk{Repository: repoA, Head: head1}, time.Now()) - // Left running by a checker that stopped. - raw, rev, _, _ := kv.Get(ctx, id) - cur, _ := DecodeTry(raw) - cur.State, cur.Told = TryRunning, row.told - data, _ := encodeTry(cur) - if _, err := kv.Update(ctx, id, data, rev); err != nil { - t.Fatal(err) - } - if row.after != nil { - row.after(t, kv, id) - } - b := newBench(t) - wholeBench(b, meshcatalog.CandidatesByGroupValue{}) - var ends []string - failed := false - tr := &Tryer{Tries: kv, Judge: b.ex, Say: func(_ context.Context, event string, e checkermsg.Event) error { - if event == checkermsg.Ended { - if row.failFirst && !failed { - failed = true - return errors.New("the stream did not acknowledge") - } - ends = append(ends, e.State) - } - return nil - }} - tr.Reconsider(ctx) - tr.Wait() - if row.failFirst && !readTry(t, kv, id).Told { - t.Errorf("an end the stream did not acknowledge cleared Told: it is never said again") - } - tr.Reconsider(ctx) // said once: the second look finds nothing owed - tr.Wait() - if row.after == nil { - if got := readTry(t, kv, id); got.State != TryPass { - t.Errorf("the try left running = %+v, want taken over and passed", got) - } - } - if !slices.Equal(ends, row.ends) || readTry(t, kv, id).Told { - t.Errorf("ends said = %v, want %v, and nothing owed after", ends, row.ends) - } - }) - } - // An ended try is kept TryKeep and removed by the next Reconsider after. - t.Run("an ended try is kept seven days", func(t *testing.T) { - kv := newMemKV() - id, _ := AskTry(memTries{kv}, tryTrunks, TryAsk{Repository: repoA, Head: head1}, time.Now()) - raw, rev, _, _ := kv.Get(ctx, id) - cur, _ := DecodeTry(raw) - ended := time.Now() - cur.State, cur.Ended = TryPass, ended - data, _ := encodeTry(cur) - if _, err := kv.Update(ctx, id, data, rev); err != nil { - t.Fatal(err) - } - now := ended.Add(TryKeep - time.Hour) - tr := &Tryer{Tries: kv, Now: func() time.Time { return now }} - tr.Reconsider(ctx) - if _, _, found, _ := kv.Get(ctx, id); !found { - t.Fatal("the try was removed before TryKeep") - } - now = ended.Add(TryKeep + time.Hour) - tr.Reconsider(ctx) - if _, _, found, _ := kv.Get(ctx, id); found { - t.Error("the try was kept past TryKeep") - } - }) -} diff --git a/modules/mesh-delivery-checker/internal/check/verdictevent.go b/modules/mesh-delivery-checker/internal/check/verdictevent.go deleted file mode 100644 index 1fcfcc16..00000000 --- a/modules/mesh-delivery-checker/internal/check/verdictevent.go +++ /dev/null @@ -1,44 +0,0 @@ -package check - -import ( - "context" - - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshdeliverycheckerclient" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshdeliverychecker" -) - -// EventVerdict is the checker's event that says a pull request's check ended, with the generated files its steps found out -// of step with their seat definitions (design 26 *Out of step*; ADR 0620): on the checker's own family asks (its stream -// asks), so the indexer learns them from the event and runs no generator, and a waiter on the stream checks does not wake. -const EventVerdict = meshdeliverychecker.HolderEventVerdict - -// VerdictEvent is the body of verdict, as the seat definition of mesh-delivery-checker says it. -type VerdictEvent = meshdeliverychecker.VerdictHolderEvent - -// VerdictSayer publishes a verdict event. -type VerdictSayer interface { - Say(ctx context.Context, v VerdictEvent) error -} - -// sayVerdict says, for each pull request of a check that ended in pass or fail, one verdict event naming its head and its -// out-of-step files. A try owes no pull request anything and says none (ADR 0501 §5). A publish that fails is said in the -// log: the verdict and the status are written already, and the next check of the heads says it again. -func (ch *Checker) sayVerdict(ctx context.Context, cs *Case, v meshdeliverychecker.VerdictsByGroupHeadsValue, out Outcome) { - if ch.Says == nil || cs.Try != nil || (v.State != meshdeliverycheckerclient.VerdictPass && v.State != meshdeliverycheckerclient.VerdictFail) { - return - } - for _, p := range cs.Pulls { - key := pullKey(Pull{Repository: p.Repository, Number: p.Number}) - e := VerdictEvent{Repository: p.Repository, Pull: int64(p.Number), Head: p.Head, Verdict: v.State, OutOfStep: out.OutOfStep[key]} - for _, s := range cs.SeriesChanges(key) { - e.Series = append(e.Series, meshdeliverychecker.VerdictHolderEventSeriesItem{Module: s.Module, Artifact: s.Artifact, From: s.From, To: s.To}) - } - if err := ch.Says.Say(ctx, e); err != nil { - ch.logf("%s: the verdict of %s#%d was written, and its event could not be said: %v", cs.Key, p.Repository, p.Number, err) - } - } -} - -// AsksStream is the checker's stream that carries verdict, one that keeps its history (ADR 0592 §6): the bus names it -// ASKS. -const AsksStream = "asks" diff --git a/modules/mesh-delivery-checker/manifest_test.go b/modules/mesh-delivery-checker/manifest_test.go deleted file mode 100644 index 1b393318..00000000 --- a/modules/mesh-delivery-checker/manifest_test.go +++ /dev/null @@ -1,325 +0,0 @@ -package manifest - -import ( - "bytes" - "encoding/json" - checker "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshdeliverychecker" - "io/fs" - "os" - "path/filepath" - "reflect" - "slices" - "strings" - "testing" - - "mesh-delivery-checker/internal/check" -) - -// The controller's manifest reader is mesh-controller internal/catalogue (Manifest, manifest.go: Consumes :521, -// Invokes :590, Streams :613, Reads :659; StreamDeclaration, streams.go), an internal package of another repository. -// These tests decode the manifest strictly into the fields those types name (DisallowUnknownFields) and hold the -// rules of issues 1678 and 1683 (ADR 0453 §4, ADR 0484). The merge gate's module check proves the controller takes the manifest. - -type state struct { - Name string `json:"name"` - History int `json:"history,omitempty"` - TTL int `json:"ttl-seconds,omitempty"` - MaxMiB int `json:"max-mib,omitempty"` -} - -type artifact struct { - Name string `json:"name"` - Kind string `json:"kind"` - Language string `json:"language"` - System string `json:"system"` - From string `json:"from"` - Binary string `json:"binary"` - Loads []string `json:"loads"` - Paths []string `json:"paths"` - Series string `json:"series"` -} - -type stream struct { - Name string `json:"name"` - Events []string `json:"events"` - MaxAgeDays int `json:"max-age-days,omitempty"` - MaxMiB int `json:"max-mib,omitempty"` - Retention string `json:"retention,omitempty"` -} - -type manifest struct { - Claims []struct { - Name string `json:"name"` - Scope string `json:"scope"` - Serves []string `json:"serves"` - } `json:"claims"` - Streams []stream `json:"streams"` - Tools []string `json:"tools"` - Module string `json:"module"` - Version string `json:"version"` - Slug string `json:"slug"` - Consumes []string `json:"consumes"` - State []state `json:"state"` - Reads []string `json:"reads"` - Uses []string `json:"uses"` - Invokes []string `json:"invokes"` - Config map[string]struct { - Type string `json:"type"` - Description string `json:"description"` - Pattern string `json:"pattern"` - Default any `json:"default"` - Minimum *float64 `json:"minimum"` - Maximum *float64 `json:"maximum"` - Trusted bool `json:"trusted"` - } `json:"config"` - OwnSecrets map[string]string `json:"own-secrets"` - SecretsOwner string `json:"secrets-owner"` - Resources []map[string]any `json:"resources"` - Build struct { - Artifacts []artifact `json:"artifacts"` - } `json:"build"` -} - -func load(t *testing.T) (manifest, map[string]json.RawMessage) { - t.Helper() - raw, err := os.ReadFile("module.json") - if err != nil { - t.Fatal(err) - } - var m manifest - dec := json.NewDecoder(bytes.NewReader(raw)) - dec.DisallowUnknownFields() - if err := dec.Decode(&m); err != nil { - t.Fatalf("the controller's reader refuses a key this manifest has: %v", err) - } - var top map[string]json.RawMessage - if err := json.Unmarshal(raw, &top); err != nil { - t.Fatal(err) - } - return m, top -} - -func sorted(s []string) []string { - s = slices.Clone(s) - slices.Sort(s) - return s -} - -func TestManifestDeclarations(t *testing.T) { // 1678/AC1 - m, top := load(t) - // 1373: checker_ask_again asks the delivery view's build_usage for the build seats' backlog; the list below is the rest. - if !slices.Contains(m.Invokes, "mesh-delivery-view.build_usage") { - t.Error("invokes lack mesh-delivery-view.build_usage, which checker_ask_again asks for the build seats' streams") - } - m.Invokes = slices.DeleteFunc(slices.Clone(m.Invokes), func(s string) bool { return s == "mesh-delivery-view.build_usage" }) - if m.Module != "mesh-delivery-checker" { - t.Errorf("module = %q", m.Module) - } - // The histories of the checker's four seat states (checked against internal/check names below); the names follow the seat mesh-delivery-checker. - if want := []state{{Name: "asks", History: 1}, {Name: "hearing", History: 1}, {Name: "inputs", TTL: 86400}, {Name: "compositions", TTL: 259200, MaxMiB: 256}, {Name: "kept", History: 1}, {Name: "owed", History: 5}, {Name: "previews", History: 5}, {Name: "tries", History: 1}, {Name: "verdicts", History: 5}, {Name: "first-views", History: 1}, {Name: "findings", History: 1}, {Name: "could-not-run", History: 1}}; !reflect.DeepEqual(m.State, want) { - t.Errorf("state = %+v, want %+v", m.State, want) - } - // The build modules are no names (design 47 G A-82): the steps and toolchains of the build seats are read as the seat's holder's states. - if want := []string{"mesh-delivery-builder.builds", "mesh-delivery-watchman.presence", "node-engine.have", - "seat:mesh-module-assigner.assignments", "seat:node-build-go.steps", "seat:node-build-go.toolchains", "seat:node-build-node.steps", "seat:node-build-node.toolchains"}; !reflect.DeepEqual(sorted(m.Reads), want) { - t.Errorf("reads = %v, want %v", m.Reads, want) - } - // DLV-M2 (ADR 0615 §1, ADR 0596): the indexer's candidates, modules, manifests, packages and predefined keys and the - // assigner's assignments are asked by their read tools and followed by their views families, never read. - for _, r := range m.Reads { - if strings.HasPrefix(r, "mesh-delivery-indexer.") || strings.HasPrefix(r, "mesh-delivery-assigner.") { - t.Errorf("reads %s: the indexer's and the assigner's state is read by their tools and views families alone", r) - } - } - // 1887/A5b: the checker reads nothing of the controller's plans-building (ADR 0483 superseded by ADR 0525 §7), calls no - // build module's tool and holds no capacity: it puts check asks on the Go and Node build seats (ADR 0525 §1, §4). - // The forge's file read through the seat git, never a module's tool (milestone 47/G W6.14), the build seats' drop, and of - // the node seat node-engine its one verb compose-candidate, asked of every placed node (ADR 0593 §7), never its other verbs. - if want := []string{"mesh-delivery-indexer.indexer_read_candidates", "mesh-delivery-indexer.indexer_read_manifests", - "mesh-delivery-indexer.indexer_read_modules", "mesh-delivery-indexer.indexer_read_packages", "mesh-delivery-indexer.indexer_read_predefined", - "mesh-delivery-indexer.indexer_read_seat_definitions", - "seat:git.file", "seat:mesh-catalog.registrations", "seat:mesh-catalog.revision", "seat:mesh-catalog.seat-definitions", "seat:mesh-delivery.source", "seat:mesh-config.renames", "seat:mesh-hand-acts.hand-act", "seat:mesh-module-assigner.assignments", "seat:node-build-go.drop", "seat:node-build-node.drop", "seat:node-engine.compose-candidate", - // The image build seat's drop too: a check of a module built by it is asked of it, and dropped of it (buildrun.SeatDrops). - "seat:node-build-image.drop", - // A-290, A-291: a step's answer its key keeps as an object, read through each build seat's verb output. - "seat:node-build-go.output", "seat:node-build-node.output", "seat:node-build-image.output", - // A-231: the check asks on each build seat's queues check and recheck. - "seat:node-build-go.accept.check", "seat:node-build-go.accept.recheck", "seat:node-build-node.accept.check", - "seat:node-build-node.accept.recheck", "seat:node-build-image.accept.check", "seat:node-build-image.accept.recheck"}; !reflect.DeepEqual(sorted(m.Invokes), sorted(want)) { - t.Errorf("invokes = %v, want the seat git's file, the seats' drop and compose-candidate", m.Invokes) - } - if want := []string{"node-build-go", "node-build-node"}; !reflect.DeepEqual(sorted(m.Uses), want) { - t.Errorf("uses = %v, want the Go and Node build seats", m.Uses) - } - // The checker is woken by a build seat's report of a toolchain, as the builder is: the bucket may not exist when it starts. - // Design 47 G §717, §614: the catalog half, whose claimant's seat-holders view names the holder of the assignments. - if want := []string{"mesh-catalog.catalog-revision", "mesh-catalog.registration-changed", "mesh-catalog.seat-definition-changed", "mesh-catalog.seat-definition-removed", "mesh-conditions.findings-asked", "mesh-delivery-indexer.views.candidates", "mesh-delivery-indexer.views.manifests", "mesh-delivery-indexer.views.modules", - "mesh-delivery-indexer.views.packages", "mesh-delivery-indexer.views.predefined", "mesh-delivery-indexer.views.seat-definitions", "mesh-delivery.source-moved", "node-build-go.toolchain-reported", "node-build-node.toolchain-reported", "node-engine.running", "seat:mesh-module-assigner.views.assignments", "seat:mesh-module-assigner.views.seat-holders"}; !reflect.DeepEqual(sorted(m.Consumes), want) { - t.Errorf("consumes = %v, want %v", m.Consumes, want) - } - if b, ok := m.OwnSecrets["broker"]; !ok || len(m.OwnSecrets) != 1 || b != "${dir:state}/broker" { - t.Errorf("own-secrets = %v, want exactly broker", m.OwnSecrets) - } - if m.SecretsOwner != "mesh-delivery-checker" { - t.Errorf("secrets-owner = %q", m.SecretsOwner) - } - // The checker says each time it wrote a preview or a status, so the indexer's and the forge bridge's watches find the buckets (ADR 0484 clauses 2 and 3). - // Its family asks (design 26): verdict, apart from checks so a waiter on a verdict does not wake on a check; a stream that keeps its history, the predefined form of an event family - // (ADR 0592 §6, the manifest validator). - if want := []stream{{Name: "checks", Events: []string{"preview.**", "owed.**", "try.**"}}, {Name: "asks", Events: []string{"verdict"}, Retention: "history"}, {Name: "mesh-delivery-checker-findings", Events: []string{"finding-written.*", "finding-cleared.*", "findings-stated.*"}, MaxAgeDays: 7, MaxMiB: 16}}; !reflect.DeepEqual(m.Streams, want) { - t.Errorf("streams = %+v, want %+v", m.Streams, want) - } - // Only the checker's account publishes try.* on its stream checks: the stream is declared by its owner alone, and no other - // module of the repository declares a stream carrying a try event (the indexer and the others only consume them). - siblings, err := filepath.Glob("../*/module.json") - if err != nil || len(siblings) < 2 { - t.Fatalf("the sibling manifests = %v, %v", siblings, err) - } - for _, f := range siblings { - raw, err := os.ReadFile(f) - if err != nil { - t.Fatal(err) - } - var other struct { - Module string `json:"module"` - Streams []stream `json:"streams"` - } - if err := json.Unmarshal(raw, &other); err != nil { - t.Fatalf("%s: %v", f, err) - } - for _, st := range other.Streams { - for _, e := range st.Events { - if strings.HasPrefix(e, "try.") && other.Module != m.Module { - t.Errorf("%s declares the stream %s with %s: only the checker's account publishes try events", other.Module, st.Name, e) - } - } - } - } - // The read tools (issue 1686) are served by the tools bundle, not by the checker's process. - // The try's tools (ADR 0501 §5; the end by hand, issue 734) beside them: mesh-controller's try calls them. A lost check - // is asked again by hand (checker_ask_again). - if want := []string{"checker_ask_again", "checker_composition_requests", "checker_composition_requests_drop", "checker_first_view_again", "checker_first_views", "checker_inputs", "checker_kept", "checker_previews", "checker_pull", "checker_status", "checker_tries", "checker_try", "checker_try_end", "checker_try_read", "checker_verdicts"}; !reflect.DeepEqual(sorted(m.Tools), want) { - t.Errorf("tools = %v, want %v", m.Tools, want) - } - // The try is the checker's own seat's verbs (ADR 0547 §10, issue 774), served beside the tools by the same code; so is - // input, a checking program's input the Go build module asks (issue 1921, ADR 0596 §2). - if len(m.Claims) != 1 || m.Claims[0].Name != "mesh-delivery-checker" || m.Claims[0].Scope != "mesh" || - !reflect.DeepEqual(m.Claims[0].Serves, []string{"try", "try-read", "try-end", "input"}) { - t.Errorf("claims = %+v, want the mesh seat mesh-delivery-checker serving try, try-read, try-end and input", m.Claims) - } - for _, k := range []string{"logs", "emits", "provides", "requires", "defines-seats", "seat", "seats", "bus"} { // config: compose-answer-bound (ADR 0593 §7) - if _, ok := top[k]; ok { - t.Errorf("the manifest declares %q: the checker has none", k) - } - } - // D-11 (ADR 0634 §1): the holders and buckets internal/check names, no contract naming a holder, are the manifest's: a state - // the checker reads is a `reads` (.) and a state of the indexer it follows a `consumes` of its views family. - for bucket, read := range map[string]string{ - check.PresenceBucket: "mesh-delivery-watchman.presence", check.HaveBucket: "node-engine.have"} { - if strings.Replace(bucket, "_", ".", 1) != read || !slices.Contains(m.Reads, read) { - t.Errorf("the bucket %s is not the declared read %s", bucket, read) - } - } - for bucket, view := range map[string]string{check.CandidatesBucket: "candidates", check.ModulesBucket: "modules", check.ManifestsBucket: "manifests"} { - if bucket != check.IndexerModule+"_"+view || !slices.Contains(m.Consumes, check.IndexerModule+".views."+view) { - t.Errorf("the bucket %s is not a followed view of the indexer's %s", bucket, view) - } - } - if !slices.Contains(m.Consumes, check.IndexerModule+".views."+check.IndexerPredefinedState) { - t.Errorf("the indexer's state %s is followed, and not declared", check.IndexerPredefinedState) - } - for own, history := range map[string]int{checker.StateVerdicts: 5, checker.StateKept: 1, checker.StateOwed: 5, checker.StatePreviews: 5} { - if !slices.ContainsFunc(m.State, func(st state) bool { return st.Name == own && st.History == history }) { - t.Errorf("the state %s is not a state of the manifest at history %d", own, history) - } - } -} - -func TestManifestProcess(t *testing.T) { // 1678/AC1 - m, _ := load(t) - var procs []map[string]any - for _, r := range m.Resources { - if r["type"] == "process" { - procs = append(procs, r) - } - if r["type"] == "tool" || r["type"] == "seat" { - t.Errorf("resource %v: the checker serves no tool and holds no seat", r) - } - } - if len(procs) != 1 { - t.Fatalf("%d process resources, want one", len(procs)) - } - p := procs[0] - if p["artifact"] != "program" || !reflect.DeepEqual(p["run"], []any{"./mesh-delivery-checker"}) { - t.Errorf("process = %v", p) - } - env, _ := p["env"].(map[string]any) - if len(env) != 2 || env["MESH_BROKER_FILE"] != "${dir:state}/broker" || env["MESH_CHECKER_SETTINGS"] != "${dir:state}/settings.json" { - t.Errorf("env = %v, want the broker file and the settings file", p["env"]) - } - // Its settings hold its answer bound (ADR 0593 §7: compose-answer-bound, 60 s, the checker's) and its wait for the - // candidate's builds (ADR 0603 §10: build-wait-bound, 1800 s), never a capacity of its own (ADR 0525 §4). - for _, r := range m.Resources { - if r["id"] == "settings" && !reflect.DeepEqual(r["takes-config"], []any{"compose-answer-bound", "build-wait-bound"}) { - t.Errorf("the settings resource %v takes other than compose-answer-bound and build-wait-bound", r) - } - } - if c, ok := m.Config["build-wait-bound"]; !ok || c.Default != float64(1800) || c.Trusted { - t.Errorf("build-wait-bound = %+v, want 1800 by default, not trusted", c) - } - if c, ok := m.Config["compose-answer-bound"]; !ok || c.Default != float64(60) || c.Trusted { - t.Errorf("compose-answer-bound = %+v, want 60 by default, not trusted", c) - } - if _, bus := p["bus"]; bus { - t.Errorf("the process declares a bus: it runs on its own broker credential") - } - // The settings template is packed as the files archive (novox/hq ADR 0349 §2), or the indexer's judge refuses it. - // Issue 1966's bootstrap: the package artifact checkermsg is out of the manifest until the new builder runs; the - // follow-up puts it back with its assertion (ADR 0634 section 2: four artifacts, the fourth the package checkermsg). - if len(m.Build.Artifacts) != 3 { - t.Fatalf("artifacts = %+v, want the program, the tools and the files archive", m.Build.Artifacts) - } - if a := m.Build.Artifacts[2]; a.Name != "files" || a.Kind != "archive" || a.From != "files" { - t.Errorf("files artifact = %+v, want an archive from files/", a) - } - if a := m.Build.Artifacts[1]; a.Name != "tools" || a.Kind != "bundle" || a.Language != "go" || a.Binary != "mesh-delivery-checker-tools" || - !reflect.DeepEqual(a.Loads, []string{"mesh-delivery-checker-tools"}) { - t.Errorf("tools artifact = %+v", a) - } - if st, err := os.Stat(m.Build.Artifacts[1].From); err != nil || !st.IsDir() { - t.Errorf("the tools' source %s: %v", m.Build.Artifacts[1].From, err) - } - a := m.Build.Artifacts[0] - if st, err := os.Stat(a.From); err != nil || !st.IsDir() || a.Binary != "mesh-delivery-checker" || !strings.HasSuffix(a.From, a.Binary) || a.Kind != "bundle" || a.Language != "go" { - t.Errorf("artifact = %+v", a) - } -} - -func TestServesNoRequestSubjectAndHoldsNoTicker(t *testing.T) { // 1678/AC6 (ADR 0437 §8: no timer, a wait is a context's bound) - forbidden := []string{"Subscribe(", "QueueSubscribe", "ChanSubscribe", "time.NewTicker", "time.Tick", "time.NewTimer", "time.AfterFunc", "time.After(", "time.Sleep"} - var files int - for _, root := range []string{"cmd", "internal"} { - err := filepath.WalkDir(root, func(path string, d fs.DirEntry, err error) error { - if err != nil || d.IsDir() || !strings.HasSuffix(path, ".go") || strings.HasSuffix(path, "_test.go") { - return err - } - files++ - src, err := os.ReadFile(path) - if err != nil { - return err - } - for _, f := range forbidden { - if strings.Contains(string(src), f) { - t.Errorf("%s holds %s: the checker serves no request subject and holds no timer", path, f) - } - } - return nil - }) - if err != nil { - t.Fatal(err) - } - } - if files < 1 { - t.Fatalf("read %d source files, want the program's", files) - } -} diff --git a/modules/mesh-delivery-checker/module.json b/modules/mesh-delivery-checker/module.json deleted file mode 100644 index 9116b3ff..00000000 --- a/modules/mesh-delivery-checker/module.json +++ /dev/null @@ -1,214 +0,0 @@ -{ - "module": "mesh-delivery-checker", - "version": "0.1", - "slug": "checker", - "claims": [ - { - "name": "mesh-delivery-checker", - "scope": "mesh", - "serves": [ - "try", - "try-read", - "try-end", - "input" - ] - } - ], - "consumes": [ - "mesh-catalog.catalog-revision", - "mesh-catalog.registration-changed", - "mesh-delivery.source-moved", - "seat:mesh-module-assigner.views.seat-holders", - "mesh-catalog.seat-definition-changed", - "mesh-catalog.seat-definition-removed", - "mesh-delivery-indexer.views.candidates", - "mesh-delivery-indexer.views.manifests", - "mesh-delivery-indexer.views.modules", - "mesh-delivery-indexer.views.packages", - "mesh-delivery-indexer.views.predefined", - "mesh-delivery-indexer.views.seat-definitions", - "mesh-conditions.findings-asked", - "seat:mesh-module-assigner.views.assignments", - "node-build-go.toolchain-reported", - "node-build-node.toolchain-reported", - "node-engine.running" - ], - "streams": [ - { "name": "checks", "events": ["preview.**", "owed.**", "try.**"] }, - { "name": "asks", "events": ["verdict"], "retention": "history" }, - { "name": "mesh-delivery-checker-findings", "events": ["finding-written.*", "finding-cleared.*", "findings-stated.*"], "max-age-days": 7, "max-mib": 16 } - ], - "state": [ - { "name": "asks", "history": 1 }, - { "name": "hearing", "history": 1 }, - { "name": "inputs", "ttl-seconds": 86400 }, - { "name": "compositions", "ttl-seconds": 259200, "max-mib": 256 }, - { "name": "kept", "history": 1 }, - { "name": "owed", "history": 5 }, - { "name": "previews", "history": 5 }, - { "name": "tries", "history": 1 }, - { "name": "verdicts", "history": 5 }, - { "name": "first-views", "history": 1 }, - { "name": "findings", "history": 1 }, - { "name": "could-not-run", "history": 1 } - ], - "reads": [ - "mesh-delivery-builder.builds", - "mesh-delivery-watchman.presence", - "node-engine.have", - "seat:mesh-module-assigner.assignments", - "seat:node-build-go.steps", - "seat:node-build-go.toolchains", - "seat:node-build-node.steps", - "seat:node-build-node.toolchains" - ], - "uses": [ - "node-build-go", - "node-build-node" - ], - "tools": [ - "checker_ask_again", - "checker_composition_requests", - "checker_composition_requests_drop", - "checker_inputs", - "checker_kept", - "checker_previews", - "checker_pull", - "checker_status", - "checker_first_views", - "checker_first_view_again", - "checker_tries", - "checker_try", - "checker_try_end", - "checker_try_read", - "checker_verdicts" - ], - "invokes": [ - "mesh-delivery-indexer.indexer_read_candidates", - "mesh-delivery-indexer.indexer_read_manifests", - "mesh-delivery-indexer.indexer_read_modules", - "mesh-delivery-indexer.indexer_read_packages", - "mesh-delivery-indexer.indexer_read_predefined", - "mesh-delivery-indexer.indexer_read_seat_definitions", - "seat:git.file", - "seat:mesh-catalog.revision", - "seat:mesh-catalog.registrations", - "seat:mesh-delivery.source", - "seat:mesh-catalog.seat-definitions", - "seat:mesh-config.renames", - "mesh-delivery-view.build_usage", - "seat:mesh-hand-acts.hand-act", - "seat:mesh-module-assigner.assignments", - "seat:node-build-go.drop", - "seat:node-build-node.drop", - "seat:node-engine.compose-candidate", - "seat:node-build-image.drop", - "seat:node-build-go.output", - "seat:node-build-node.output", - "seat:node-build-image.output", - "seat:node-build-go.accept.check", - "seat:node-build-go.accept.recheck", - "seat:node-build-node.accept.check", - "seat:node-build-node.accept.recheck", - "seat:node-build-image.accept.check", - "seat:node-build-image.accept.recheck" - ], - - "own-secrets": { - "broker": "${dir:state}/broker" - }, - "secrets-owner": "mesh-delivery-checker", - "config": { - "compose-answer-bound": { - "type": "number", - "description": "seconds a check waits for each placed node's engine to answer compose-candidate (novox/hq ADR 0593 §7, §9); a node that has not answered by then is named in the verdict as not composed on that node: no answer, and the check passes with that warning.", - "minimum": 1, - "maximum": 600, - "trusted": false, - "default": 60 - }, - "build-wait-bound": { - "type": "number", - "description": "seconds a check waits for the builder's builds of its candidate to end before it composes with them (novox/hq ADR 0603 §10); a build failed fails the check, naming it, and a build not ended by then is named in the verdict and the check composes without it.", - "minimum": 60, - "maximum": 7200, - "trusted": false, - "default": 1800 - } - }, - "resources": [ - { - "id": "account", - "type": "user", - "name": "mesh-delivery-checker", - "shell": "/usr/bin/nologin", - "home": "/var/lib/mesh-delivery-checker" - }, - { - "id": "state", - "type": "directory", - "mode": "0700", - "owner": "mesh-delivery-checker", - "place": ".", - "unknown": "program" - }, - { - "id": "settings", - "type": "file", - "path": "${dir:state}/settings.json", - "mode": "0600", - "owner": "mesh-delivery-checker", - "takes-config": [ - "compose-answer-bound", - "build-wait-bound" - ], - "merge": "json", - "template": "files/settings.json" - }, - { - "id": "checker", - "type": "process", - "name": "mesh-delivery-checker", - "artifact": "program", - "run": [ - "./mesh-delivery-checker" - ], - "env": { - "MESH_BROKER_FILE": "${dir:state}/broker", - "MESH_CHECKER_SETTINGS": "${dir:state}/settings.json" - }, - "user": "mesh-delivery-checker", - "health": { - "kind": "unit" - } - } - ], - "build": { - "artifacts": [ - { - "name": "program", - "kind": "bundle", - "language": "go", - "system": "arch", - "from": "cmd/mesh-delivery-checker", - "binary": "mesh-delivery-checker" - }, - { - "name": "tools", - "kind": "bundle", - "language": "go", - "system": "arch", - "from": "cmd/mesh-delivery-checker-tools", - "binary": "mesh-delivery-checker-tools", - "loads": [ - "mesh-delivery-checker-tools" - ] - }, - { - "name": "files", - "kind": "archive", - "from": "files" - } - ] - } -} diff --git a/modules/mesh-delivery-checker/reads-outside b/modules/mesh-delivery-checker/reads-outside deleted file mode 100644 index f6b2d871..00000000 --- a/modules/mesh-delivery-checker/reads-outside +++ /dev/null @@ -1 +0,0 @@ -These tests read files outside this directory (the whole catalogue, the repository, or its root files): mesh-build-go never keeps this package's verdict (issue 1935). diff --git a/modules/mesh-delivery-checker/rules/facts.go b/modules/mesh-delivery-checker/rules/facts.go deleted file mode 100644 index b913e864..00000000 --- a/modules/mesh-delivery-checker/rules/facts.go +++ /dev/null @@ -1,306 +0,0 @@ -// Package rules is the checker's judging rules, the checking program's: given the facts of one check (what the build -// modules, the manifest validator and the composer answered, and what failed in the asking), the verdict (novox/hq ADR -// 0644, ADR 0656; design 47's bootstrap delivery). The running checker asks, waits, keeps and records; it gathers the -// facts and has them judged by the checking program built from the change's heads (cmd/mesh-checking-program), which -// imports this package, so a change to a rule is judged by its own rule. -// -// It is the checker module's own package (novox/hq ADR 0634 §1): no seat carries it and no other module imports it. -package rules - -import ( - "encoding/json" - "fmt" - "path" - "sort" - - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshdeliverycheckerclient" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshdeliverychecker" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep" -) - -// FactsVersion is the version of Facts this program reads. A checking program built from a later change reads the facts -// a running checker of this version writes, so a version is added to, never changed; a program refuses one it does not -// read, naming it (DecodeFacts). -const FactsVersion = 1 - -// Facts are everything one check judges, in the order the running checker met it. -type Facts struct { - V int `json:"v"` - // Group and Heads name the check (meshdeliverychecker.VerdictsByGroupHeadsValue's Group and Heads); Trunk is each repository's trunk head merged. - Group string `json:"group"` - Heads string `json:"heads"` - Trunk map[string]string `json:"trunk,omitempty"` - Members []Member `json:"members"` - // SeatDigests are, by seat, the digests (SeatDigest) of the definitions the running checker's reader holds: the - // `-seats` answer leaves out every head definition that is the same (milestone 47/G, the lead's ruling on review - // finding 3: a whole list is over a run answer's bound). None from a checker that hands none: then every head - // definition is answered. - SeatDigests map[string]string `json:"seat-digests,omitempty"` - // Series are the changes of the members' modules' series, as structures, put in the verdict whatever it is (DLV-C4). - Series []meshdeliverychecker.VerdictsByGroupHeadsValueSeriesItem `json:"series,omitempty"` - // Steps are, in the order met, each level a build module answered and each failure the asking met. - Steps []Step `json:"steps,omitempty"` - // CloneMS is how much of the steps' time their levels' running did not take (meshdeliverychecker.VerdictsByGroupHeadsValueTook.Clone). - CloneMS int64 `json:"clone-ms,omitempty"` - // Composition is how the check composed, after every step; nil when it was not composed (a narrowed try, a checker - // that composes nothing): its composition is then not run, unsaid. - Composition *Composition `json:"composition,omitempty"` - // Notes are the running checker's notes of the check, for a reader. - Notes []string `json:"notes,omitempty"` -} - -// Member is one pull request of the check. -type Member struct { - Repository string `json:"repository"` - Number int `json:"number"` - Head string `json:"head"` - Trunk string `json:"trunk,omitempty"` -} - -// Step is one fact of the check, in the order met: the node that ran it, and one of a level its build module answered -// (Level, as the build module gave it), what its fetch read of compiled programs (Programs), the manifest validator's -// answers (Manifests), the module graph's ordering edges (Graph) or a failure the asking met (Failed: a step not asked, refused or not answered, a conflict, worded -// by the running checker). A step with none only says which node ran it. -type Step struct { - Repository string `json:"repository"` - Number int `json:"number"` - Module string `json:"module,omitempty"` - // Language is the language of the toolchain the build module that ran the step builds with (a level's counts differ by it). - Language string `json:"language,omitempty"` - Node string `json:"node,omitempty"` - Level *buildstep.LevelAnswer `json:"level,omitempty"` - Failed *FailedFirst `json:"failed,omitempty"` - Programs *Programs `json:"programs,omitempty"` - Manifests *Manifests `json:"manifests,omitempty"` - // Graph is the module graph's ordering edges, as the change leaves them and as the trunk has them (JudgeGraph). - Graph *Graph `json:"graph,omitempty"` - // Renames is what a module brings and drops of `renamed-from` and how the seat mesh-config answered (JudgeRenames). - Renames *Renames `json:"renames,omitempty"` - // Unparsed is what the indexer keeps of a pull request's seat definitions that do not parse (JudgeUnparsed). - Unparsed *Unparsed `json:"unparsed,omitempty"` -} - -// LevelFact is a level answer as the facts carry it: only what the rules read (Tally.Level), so a group's facts stay -// within the run input's bound (buildstep.RunInputOf). The digest, the unmet packages and the level's judged program -// are left out, the kept packages are one count, and each test result keeps only the fields Tested names, without its -// packages, bounds and judged program (review round 1 of milestone 47/B0). An answer this cannot read is carried as given, -// for the rules to refuse it. -func LevelFact(la buildstep.LevelAnswer) *buildstep.LevelAnswer { - out := &buildstep.LevelAnswer{Level: la.Level} - kept := 0 - for _, k := range la.Kept { - kept += k.Tests - } - if len(la.Kept) > 0 { - out.Kept = []buildstep.KeptTaken{{Tests: kept}} - } - for _, raw := range la.Tests { - var res Tested - if err := json.Unmarshal(raw, &res); err != nil { - out.Tests = append(out.Tests, raw) - continue - } - res.Packages, res.JudgedBy, res.Bound, res.SetupBound, res.OverWhich = nil, "", 0, 0, "" - small, err := json.Marshal(res) - if err != nil { - small = raw - } - out.Tests = append(out.Tests, small) - } - return out -} - -// DecodeFacts reads facts, refusing a version this program does not read, naming it. -func DecodeFacts(data []byte) (Facts, error) { - var f Facts - if err := json.Unmarshal(data, &f); err != nil { - return Facts{}, fmt.Errorf("rules: the facts are not JSON of their shape: %w", err) - } - if f.V != FactsVersion { - return Facts{}, fmt.Errorf("rules: facts of version %d, this checking program reads version %d", f.V, FactsVersion) - } - return f, nil -} - -// Counts are one level's counts across a check's members. -type Counts struct { - Run, Kept, Skipped int - Elapsed, Setup float64 - Lint float64 - Over bool - Slowest []TestTime -} - -// Tally is a check's counts by level. -type Tally map[string]*Counts - -// NewTally is a tally of both levels, at nothing. -func NewTally() Tally { - return Tally{buildstep.LevelUnit: {}, buildstep.LevelIntegration: {}} -} - -// Level judges one level of a member's check step as it was answered: the kept ones taken are counted, and every test -// result is read and counted, also after one that did not pass, so the verdict names every failed test of the level -// (issue 1921). It answers the level's failure (nil when it passed), its running time (its tests' and setup's) and the -// results read, for the running checker to keep the passes from. -func (t Tally) Level(repository string, number int, module, language, node string, la buildstep.LevelAnswer) (*meshdeliverychecker.VerdictsByGroupHeadsValue, float64, []Tested) { - a := t[la.Level] - if a == nil { - return failAt(node, fmt.Sprintf("the check of %s#%d answered the level %q, which is no level", repository, number, la.Level)), 0, nil - } - for _, k := range la.Kept { - a.Kept += k.Tests - } - elapsed := 0.0 - var results, failed []Tested - for _, raw := range la.Tests { - var res Tested - if err := json.Unmarshal(raw, &res); err != nil { - return failAt(node, fmt.Sprintf("the %s level of %s#%d answered what is not a result: %v", la.Level, repository, number, err)), elapsed, results - } - results = append(results, res) - elapsed += res.Elapsed + res.Setup + res.Lint - if language == LanguageTypeScript { - if !res.NoTests { - a.Run++ // a Node package is counted whole: its build module counts no tests (ADR 0484 clause 10) - } - } else { - a.Run += res.Tests - a.Skipped += res.Skipped - a.Slowest = append(a.Slowest, res.Slowest...) - } - a.Elapsed += res.Elapsed - a.Setup += res.Setup - a.Lint += res.Lint - a.Over = a.Over || res.OverBound - if !res.Passed { - failed = append(failed, res) - } - } - if len(failed) > 0 { - return LevelFailure(repository, module, language, la.Level, failed...), elapsed, results - } - return nil, elapsed, results -} - -// Judge is the verdict of the facts (Judged without its notes). -func Judge(f Facts) meshdeliverychecker.VerdictsByGroupHeadsValue { return Judged(f).Verdict } - -// Judged is the answer of the facts: every failure in the order met, joined and settled, or a pass; the levels' -// counts, times, machines and the levels over their bound; then the composition taken in; and the notes the rules give -// a reader (the manifest validator's warnings and acceptances). -func Judged(f Facts) Answer { - var notes []string - tally := NewTally() - var failures []*meshdeliverychecker.VerdictsByGroupHeadsValue - nodes := map[string]bool{} - for _, s := range f.Steps { - if s.Node != "" { - nodes[s.Node] = true - } - switch { - case s.Failed != nil: - failures = append(failures, &meshdeliverychecker.VerdictsByGroupHeadsValue{State: meshdeliverycheckerclient.VerdictFail, Failed: s.Failed}) - case s.Level != nil: - if v, _, _ := tally.Level(s.Repository, s.Number, s.Module, s.Language, s.Node, *s.Level); v != nil { - failures = append(failures, v) - } - case s.Programs != nil: - if ff := JudgePrograms(s.Node, *s.Programs); ff != nil { - failures = append(failures, &meshdeliverychecker.VerdictsByGroupHeadsValue{State: meshdeliverycheckerclient.VerdictFail, Failed: ff}) - } - case s.Graph != nil: - ff, said := JudgeGraph(*s.Graph, s.Module) - notes = append(notes, said...) - if ff != nil { - failures = append(failures, &meshdeliverychecker.VerdictsByGroupHeadsValue{State: meshdeliverycheckerclient.VerdictFail, Failed: ff}) - } - case s.Renames != nil: - ffs, said := JudgeRenames(*s.Renames) - notes = append(notes, said...) - for _, ff := range ffs { - failures = append(failures, &meshdeliverychecker.VerdictsByGroupHeadsValue{State: meshdeliverycheckerclient.VerdictFail, Failed: &ff}) - } - case s.Unparsed != nil: - for _, ff := range JudgeUnparsed(*s.Unparsed) { - failures = append(failures, &meshdeliverychecker.VerdictsByGroupHeadsValue{State: meshdeliverycheckerclient.VerdictFail, Failed: &ff}) - } - case s.Manifests != nil: - ff, said := JudgeManifests(*s.Manifests, s.Module) - notes = append(notes, said...) - if ff != nil { - failures = append(failures, &meshdeliverychecker.VerdictsByGroupHeadsValue{State: meshdeliverycheckerclient.VerdictFail, Failed: ff}) - } - } - } - v := meshdeliverychecker.VerdictsByGroupHeadsValue{State: meshdeliverycheckerclient.VerdictPass} - if joined := Settled(JoinFailures(failures...)); joined != nil { - v = *joined - } - v.Group, v.Heads, v.Trunk, v.Series = f.Group, f.Heads, f.Trunk, f.Series - Outcome(&v, tally, f.CloneMS, nodes) - if f.Composition != nil { - JudgeComposition(&v, *f.Composition) - } - return Answer{V: AnswerVersion, Verdict: v, Notes: notes} -} - -// Outcome fills a verdict's levels (on a pass, or when it names none), times, machines and levels over their bound from -// the tally, and says its composition is not yet run (ADR 0484 clause 6). -func Outcome(v *meshdeliverychecker.VerdictsByGroupHeadsValue, tally Tally, cloneMS int64, nodes map[string]bool) { - if v.State == meshdeliverycheckerclient.VerdictPass || len(v.Levels) == 0 { - v.Levels = map[string]meshdeliverychecker.VerdictsByGroupHeadsValueLevelsValue{} - for level, a := range tally { - v.Levels[level] = meshdeliverychecker.VerdictsByGroupHeadsValueLevelsValue{Run: int64(a.Run), Kept: int64(a.Kept), Skipped: int64(a.Skipped)} - } - } - ms := func(s float64) int64 { return int64(s * 1000) } - u, i := tally[buildstep.LevelUnit], tally[buildstep.LevelIntegration] - v.Took = &meshdeliverychecker.VerdictsByGroupHeadsValueTook{Clone: cloneMS, Unit: ms(u.Elapsed), Lint: ms(u.Lint), IntegrationSetup: ms(i.Setup), IntegrationRun: ms(i.Elapsed)} - v.Machines = nil - for node := range nodes { - v.Machines = append(v.Machines, node) - } - sort.Strings(v.Machines) - v.OverBound = nil - for _, level := range []string{buildstep.LevelUnit, buildstep.LevelIntegration} { - if tally[level].Over { - v.OverBound = append(v.OverBound, level) - } - } - v.Composition = &meshdeliverychecker.VerdictsByGroupHeadsValueComposition{State: meshdeliverycheckerclient.CompositionNotRun} -} - -// Slowest are, of each level over its bound, its three slowest tests, worded for the status line. -func Slowest(tally Tally) []string { - var slow []string - for _, level := range []string{buildstep.LevelUnit, buildstep.LevelIntegration} { - a := tally[level] - if !a.Over { - continue - } - sort.SliceStable(a.Slowest, func(x, y int) bool { return a.Slowest[x].Elapsed > a.Slowest[y].Elapsed }) - for n, s := range a.Slowest { - if n == 3 { - break - } - slow = append(slow, fmt.Sprintf("%s %s %.1fs", level, path.Base(s.Package)+"."+s.Test, s.Elapsed)) - } - } - return slow -} - -func failAt(machine, words string) *meshdeliverychecker.VerdictsByGroupHeadsValue { - return &meshdeliverychecker.VerdictsByGroupHeadsValue{State: meshdeliverycheckerclient.VerdictFail, Failed: &FailedFirst{Machine: machine, Words: words}} -} - -// AnswerVersion is the version of Answer this program writes. -const AnswerVersion = 1 - -// Answer is what the checking program answers on the last line of its standard output: its version, the verdict and the -// notes its rules give a reader of the check. -type Answer struct { - V int `json:"v"` - Verdict meshdeliverychecker.VerdictsByGroupHeadsValue `json:"verdict"` - Notes []string `json:"notes,omitempty"` -} diff --git a/modules/mesh-delivery-checker/rules/graph.go b/modules/mesh-delivery-checker/rules/graph.go deleted file mode 100644 index 9e370d4f..00000000 --- a/modules/mesh-delivery-checker/rules/graph.go +++ /dev/null @@ -1,114 +0,0 @@ -package rules - -import ( - "fmt" - "slices" - "strings" -) - -// The module graph's cycle rule (novox/hq ADR 0603 §2, ADR 0614 §3, §6), judged by the checking program (ADR 0656 §5): -// the check refuses a change whose module graph has a cycle and names it; a cycle the trunk already has among the same -// modules is the trunk's, said in the notes. The running checker gathers the graph's ordering edges of the catalogue as -// the change leaves it and as the trunk has it, worked out with the contract's graph (sdk/graph: bases, the provisions -// and bus state a module awaits, the verb edges the graph keeps), as module names and the edge's kind, never the -// manifests themselves, so the facts stay within the run input's bound. - -// The kinds of an ordering edge. -const ( - EdgeBase = "base" - EdgeAwaits = "awaits" - EdgeInvokes = "invokes" -) - -// Edge is one ordering edge: From waits for To. Only is EdgeChange when only the change's graph has it, EdgeTrunk when -// only the trunk's does, empty when both have it. -type Edge struct { - From string `json:"from"` - To string `json:"to"` - Kind string `json:"kind"` - Only string `json:"only,omitempty"` -} - -// Where only one graph has an edge. -const ( - EdgeChange = "change" - EdgeTrunk = "trunk" -) - -// Graph is the module graph's facts: every ordering edge of either graph, between modules of the catalogue. Trunk says -// whether the trunk's graph was read; when it was not, every edge is the change's and no cycle is the trunk's. -type Graph struct { - Edges []Edge `json:"edges"` - Trunk bool `json:"trunk"` -} - -// JudgeGraph is the cycle rule over the graph's facts: the failure of a cycle the change makes, or the note of no cycle -// or of a cycle the trunk already has. -func JudgeGraph(g Graph, machine string) (*FailedFirst, []string) { - cycle := firstCycle(g.Edges, func(e Edge) bool { return e.Only != EdgeTrunk || !g.Trunk }) - if cycle == nil { - return nil, []string{"the change's module graph has no cycle"} - } - words := strings.Join(cycle, " -> ") - if g.Trunk { - among := firstCycle(g.Edges, func(e Edge) bool { - return e.Only != EdgeChange && slices.Contains(cycle, e.From) && slices.Contains(cycle, e.To) - }) - if among != nil { - return nil, []string{"the module graph has the cycle " + words + ", which the trunk already has among the same modules (ADR 0603 §2)"} - } - } - return &FailedFirst{Machine: machine, Words: fmt.Sprintf("the change's module graph has the cycle %s: these modules would "+ - "each wait for the other for good, through their bases, the provisions and bus state they await, or the verbs they invoke (ADR 0603 §2, ADR 0614 §6)", words)}, nil -} - -// firstCycle is the first cycle of the edges kept, as the modules it passes through with the first named again at its -// end, visiting the modules and each one's edges in sorted order (as sdk/graph's Cycle does), or nil for none. -func firstCycle(edges []Edge, keep func(Edge) bool) []string { - next := map[string][]string{} - for _, e := range edges { - if keep(e) && !slices.Contains(next[e.From], e.To) { - next[e.From] = append(next[e.From], e.To) - } - } - var names []string - for name, to := range next { - slices.Sort(to) - names = append(names, name) - } - slices.Sort(names) - const ( - unseen = iota - onPath - done - ) - state := map[string]int{} - var path []string - var visit func(string) []string - visit = func(name string) []string { - state[name] = onPath - path = append(path, name) - for _, to := range next[name] { - switch state[to] { - case onPath: - i := slices.Index(path, to) - return append(slices.Clone(path[i:]), to) - case unseen: - if c := visit(to); c != nil { - return c - } - } - } - path = path[:len(path)-1] - state[name] = done - return nil - } - for _, name := range names { - if state[name] == unseen { - if c := visit(name); c != nil { - return c - } - } - } - return nil -} diff --git a/modules/mesh-delivery-checker/rules/judged.go b/modules/mesh-delivery-checker/rules/judged.go deleted file mode 100644 index e981fc24..00000000 --- a/modules/mesh-delivery-checker/rules/judged.go +++ /dev/null @@ -1,288 +0,0 @@ -package rules - -import ( - "fmt" - nec "git.novox.be/novox/mesh-contracts/go/clients/nodeengineclient" - ne "git.novox.be/novox/mesh-contracts/go/seats/nodeengine" - "maps" - "slices" - "sort" - "strings" - - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshdeliverycheckerclient" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshdeliverychecker" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshwants" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/composer" -) - -// The facts the manifest validator, the fetch's programs and the composer answered, and the rules that judge them -// (milestone 47/B0, D1b): the running checker asks and records; these rules give the verdict. - -// CatalogSeat is the seat the indexer holds: the module whose manifest claims it is the indexer, found by the claim and -// never by its name (novox/hq ADR 0633 clause 6, ADR 0601 §4). -const CatalogSeat = "mesh-catalog" - -// BetweenManifests is the manifest validator's name for what it judges between manifests (the catalogue as a whole). -const BetweenManifests = "(between manifests)" - -// Manifests are the manifest validator's answers on the manifests a check touches (ADR 0578 §2, ADR 0579 §2, ADR 0633 -// clause 6): its change and trunk cases where it judged (At), and, when a touched module claims the seat mesh-catalog, -// that indexer and the trunk validator's change case on it (IndexerAt names where it judged). -type Manifests struct { - Touched []string `json:"touched"` - At string `json:"at"` - Change composer.CaseVerdict `json:"change"` - Trunk composer.CaseVerdict `json:"trunk"` - Indexer string `json:"indexer,omitempty"` - IndexerAt string `json:"indexer-at,omitempty"` - OfIndexer *composer.CaseVerdict `json:"of-indexer,omitempty"` -} - -// Programs are what one member's fetch read of the change's compiled programs (issue 1577): Files nil when the build -// module reported none (an older module: not refused, the running checker warns), else each changed file that is one. -type Programs struct { - Key string `json:"key"` - Files *[]ProgramFile `json:"files"` -} - -// ProgramFile is a changed file that is a compiled program, its format (ELF, Mach-O or PE) and, when it was added in an -// earlier commit of the branch and removed later, that commit: the build step's own (buildstep.Program). -type ProgramFile = buildstep.Program - -// Composition is how the check's composition went (ADR 0593 §7, §9; ADR 0603 §10; ADR 0548 §5): kept from the check it -// carries, not run (NotRun says why), or composed by the engines; BuildsFailed are the candidate's builds that failed -// before it composed, worded by the running checker; Waits are what it composed without waiting on, as warnings. -type Composition struct { - Kept *meshdeliverychecker.VerdictsByGroupHeadsValueComposition `json:"kept,omitempty"` - NotRun string `json:"not-run,omitempty"` - BuildsFailed []FailedFirst `json:"builds-failed,omitempty"` - Waits []string `json:"waits,omitempty"` - Composed *Composed `json:"composed,omitempty"` - FPSet string `json:"fp-set,omitempty"` -} - -// Composed are the engines' answers to one composition: the nodes placed, each answering node's answer, each silent -// node with why (for the journal only), what composed (the node-engine's commit), the composer's own warnings and how -// long it took in milliseconds. -type Composed struct { - Group string `json:"group"` - Heads string `json:"heads"` - Composer string `json:"composer"` - Nodes []string `json:"nodes"` - Answers map[string]ne.ComposeCandidateAnswer `json:"answers,omitempty"` - Silent map[string]string `json:"silent,omitempty"` - Warnings []string `json:"warnings,omitempty"` - Took int64 `json:"took,omitempty"` -} - -// JudgeManifests is the failure of the manifests' facts (nil when they pass) and the notes a reader gets: the trunk -// validator refusing, holding or setting aside the new indexer's manifest fails first (ADR 0633 clause 6); else a new or -// changed manifest is judged in full, a held one is refused, and of one the change leaves as it is a problem the trunk -// already had is a warning while one the change causes fails the check (ADR 0579 §2). -func JudgeManifests(m Manifests, machine string) (*FailedFirst, []string) { - var notes []string - if m.Indexer != "" { - var problems []string - ok := false - var iv composer.ManifestRead - if m.OfIndexer != nil { - iv, ok = m.OfIndexer.Manifests[m.Indexer] - } - switch { - case !ok: - problems = append(problems, "the manifest validator gave no verdict") - case iv.Refused != "": - problems = append(problems, strings.Split(iv.Refused, "\n")...) - case !iv.Accepted: - problems = append(problems, "the manifest validator holds it, with no verdict yet") - case iv.SetAside != "": - problems = append(problems, "the manifest validator does not know its fields "+iv.SetAside+", so it waits") - } - if len(problems) > 0 { - return &FailedFirst{Machine: machine, Words: fmt.Sprintf("the indexer %s, the holder of the seat %s, would never run: the trunk's manifest validator at %s does not accept its manifest: %s", - m.Indexer, CatalogSeat, m.IndexerAt, strings.Join(problems, "; "))}, nil - } - notes = append(notes, fmt.Sprintf("the new indexer's manifest of %s is accepted by the trunk's manifest validator at %s", m.Indexer, m.IndexerAt)) - } - var refused, warned []string - for _, module := range slices.Sorted(maps.Keys(m.Change.Manifests)) { - r := m.Change.Manifests[module] - if r.Accepted { - continue - } - if r.Refused == "" { // held: a verdict not given is not one given (ADR 0633 clause 6) - if slices.Contains(m.Touched, module) { - refused = append(refused, fmt.Sprintf("the indexer's judge at %s holds the manifest of %s: it gave no verdict", m.At, module)) - } - continue - } - had := map[string]bool{} - for _, p := range strings.Split(m.Trunk.Manifests[module].Refused, "\n") { - had[p] = true - } - var caused, old []string - for _, p := range strings.Split(r.Refused, "\n") { - if slices.Contains(m.Touched, module) || !had[p] { - caused = append(caused, p) - } else { - old = append(old, p) - } - } - if len(caused) > 0 { - what := "the manifest of " + module - if module == BetweenManifests { - what = "the catalogue" - } - refused = append(refused, fmt.Sprintf("the indexer's judge at %s refuses %s: %s", m.At, what, strings.Join(caused, "; "))) - } - if len(old) > 0 { - warned = append(warned, module+": "+strings.Join(old, "; ")) - } - } - if len(warned) > 0 { - notes = append(notes, "warnings of the indexer's judge on manifests the change leaves as they are (ADR 0579 §2): "+strings.Join(warned, " | ")) - } - if len(refused) > 0 { - return &FailedFirst{Machine: machine, Words: strings.Join(refused, "\n")}, notes - } - return nil, append(notes, fmt.Sprintf("the manifests of %s are accepted by the indexer's judge at %s", strings.Join(m.Touched, ", "), m.At)) -} - -// JudgePrograms fails a member whose change adds or modifies a compiled program, naming each file (issue 1577); a fetch -// that reported none, or found none, passes. -func JudgePrograms(machine string, p Programs) *FailedFirst { - if p.Files == nil { - return nil - } - var found []string - for _, f := range *p.Files { - if f.Commit != "" { - found = append(found, fmt.Sprintf("%s: a compiled program added in %s and removed later: it stays in history; squash the branch (issue 1577)", f.Path, short12(f.Commit))) - continue - } - found = append(found, f.Path+": a compiled program is build output: remove it and add it to .gitignore (issue 1577)") - } - if len(found) == 0 { - return nil - } - return &FailedFirst{Machine: machine, Words: fmt.Sprintf("%s: %s", p.Key, strings.Join(found, "; "))} -} - -func short12(s string) string { - if len(s) > 12 { - return s[:12] - } - return s -} - -// JudgeEngines is the check's composition verdict from the engines' answers (ADR 0593 §7, §9): failed when any node's -// answer is refused, naming each node and each module refused with its words (the first refusing node is the machine); -// passed otherwise. Every placed node without an answer is named with nec.NoAnswer as a warning. -func JudgeEngines(c Composed) meshwants.CompositionsByGroupHeadsValue { - v := meshwants.CompositionsByGroupHeadsValue{Group: c.Group, Heads: c.Heads, State: meshdeliverycheckerclient.CompositionPass, Sdk: c.Composer, Took: c.Took} - sorted := append([]string(nil), c.Nodes...) - sort.Strings(sorted) - var fails []string - for _, node := range sorted { - a, answered := c.Answers[node] - if !answered { - v.Warnings = append(v.Warnings, node+": "+nec.NoAnswer) - continue - } - if a.Verdict == nec.NotJudged { - // Composed in the sandbox and not judged (ADR 0593 §9): named as no answer, with the composer's words; decided - // by the verdict, never by the words (ADR 0601 §4's kind). - v.Warnings = append(v.Warnings, node+": "+nec.NoAnswer+" ("+a.Refused+")") - continue - } - v.Machines = append(v.Machines, node) - if a.Verdict != nec.Refused { - continue - } - if v.Machine == "" { - v.Machine = node - } - var words []string - if a.Refused != "" { - words = append(words, a.Refused) - } - for _, m := range append(append([]ne.Module(nil), a.Modules...), a.Own) { - if m.State == nec.ModuleRefused { - words = append(words, m.Module+": "+m.Words) - } - } - if len(words) == 0 { - words = append(words, "refused, naming no module") - } - fails = append(fails, "not composed on "+node+": "+strings.Join(words, "; ")) - } - if len(fails) > 0 { - v.State, v.Words = meshdeliverycheckerclient.CompositionFail, strings.Join(fails, "; ") - } - if len(sorted) == 0 { - v.Warnings = append(v.Warnings, "no node is placed, so the change was composed on none") - } - v.Warnings = append(v.Warnings, c.Warnings...) - return v -} - -// JudgeComposition takes the composition's facts into the verdict: a failed build of the candidate fails it, named after -// the tests' failures; a failed composition fails it, naming its machine; a passed one with warnings says them. -func JudgeComposition(v *meshdeliverychecker.VerdictsByGroupHeadsValue, c Composition) { - if c.Kept != nil { - kept := *c.Kept - v.Composition = &kept - return - } - for _, f := range c.BuildsFailed { - if v.State != meshdeliverycheckerclient.VerdictFail { - v.State, v.Failed = meshdeliverycheckerclient.VerdictFail, &f - continue - } - AddFailure(v, f) - } - if c.NotRun != "" { - v.Composition = &meshdeliverychecker.VerdictsByGroupHeadsValueComposition{State: meshdeliverycheckerclient.CompositionNotRun, Words: c.NotRun} - return - } - if c.Composed == nil { - return - } - comp := JudgeEngines(*c.Composed) - comp.Warnings = append(comp.Warnings, c.Waits...) // ADR 0603 §10 - v.Composition = compositionOf(comp) - if v.Took == nil { - v.Took = &meshdeliverychecker.VerdictsByGroupHeadsValueTook{} - } - v.Took.Composition = comp.Took - if comp.State == meshdeliverycheckerclient.CompositionPass && len(comp.Warnings) > 0 && v.Composition != nil { - v.Composition.Words = strings.Join(comp.Warnings, "; ") // passed with a warning (ADR 0593 §9) - } - if comp.State == meshdeliverycheckerclient.CompositionFail { - machine := comp.Machine - if machine == "" { - machine = "the composition" - } - f := FailedFirst{Machine: machine, Words: comp.Words} - if v.State == meshdeliverycheckerclient.VerdictFail { - AddFailure(v, f) // the tests failed too: the composition is named after them (the operator, 2026-11-02) - } else { - v.State, v.Failed = meshdeliverycheckerclient.VerdictFail, &f - } - } - if v.Composition != nil && v.Composition.State != meshdeliverycheckerclient.CompositionNotRun { - v.Composition.Fpset = c.FPSet // a carry keeps it while the fingerprints stay the same (ADR 0548 §5) - } -} - -// compositionWaits is the state of the assigner's composition answer that waits for what it composes from. -const compositionWaits = "waits" - -// compositionOf is what the verdict carries of a composition answer c: nil while c waits (the check is still running). -func compositionOf(c meshwants.CompositionsByGroupHeadsValue) *meshdeliverychecker.VerdictsByGroupHeadsValueComposition { - if c.State == compositionWaits { - return nil - } - return &meshdeliverychecker.VerdictsByGroupHeadsValueComposition{State: c.State, Words: c.Words, Sdk: c.Sdk, Machines: c.Machines} -} diff --git a/modules/mesh-delivery-checker/rules/language.go b/modules/mesh-delivery-checker/rules/language.go deleted file mode 100644 index ac7e4474..00000000 --- a/modules/mesh-delivery-checker/rules/language.go +++ /dev/null @@ -1,8 +0,0 @@ -package rules - -// LanguageTypeScript is the language of the toolchain whose build module counts a package whole, not its tests (ADR 0484 clause -// 10): the `on` of a build seat's acting rule, never the name of a build module (design 47 G A-82). -const LanguageTypeScript = "typescript" - -// LanguageGo is the language of the toolchain of the build module that judges the Go repositories and the manifests. -const LanguageGo = "go" diff --git a/modules/mesh-delivery-checker/rules/names.go b/modules/mesh-delivery-checker/rules/names.go deleted file mode 100644 index 5915cdd8..00000000 --- a/modules/mesh-delivery-checker/rules/names.go +++ /dev/null @@ -1,38 +0,0 @@ -package rules - -import checker "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshdeliverychecker" - -// FailedFirst names what failed: a test (its package and name) or a machine, with the words of the failure. It is the shape -// of the verdict's `failed` and of each entry of its `failures` (the seat's two types of it have the same fields), so the -// rules judge with one and convert at the verdict's edge (failureItems, failedList). -type FailedFirst = checker.VerdictsByGroupHeadsValueFailed - -func failureItems(list []FailedFirst) []checker.VerdictsByGroupHeadsValueFailuresItem { - if list == nil { - return nil - } - out := make([]checker.VerdictsByGroupHeadsValueFailuresItem, len(list)) - for i, f := range list { - out[i] = checker.VerdictsByGroupHeadsValueFailuresItem(f) - } - return out -} - -func failedList(items []checker.VerdictsByGroupHeadsValueFailuresItem) []FailedFirst { - if items == nil { - return nil - } - out := make([]FailedFirst, len(items)) - for i, f := range items { - out[i] = FailedFirst(f) - } - return out -} - -// failedOf is the first failure a verdict names: the zero value of a verdict that names none. -func failedOf(v checker.VerdictsByGroupHeadsValue) FailedFirst { - if v.Failed == nil { - return FailedFirst{} - } - return *v.Failed -} diff --git a/modules/mesh-delivery-checker/rules/program.go b/modules/mesh-delivery-checker/rules/program.go deleted file mode 100644 index 9cc8b87b..00000000 --- a/modules/mesh-delivery-checker/rules/program.go +++ /dev/null @@ -1,54 +0,0 @@ -package rules - -import ( - "encoding/json" - "errors" - "flag" - "fmt" - "io" - "io/fs" -) - -// Program is the checking program's work (cmd/mesh-checking-program; novox/hq ADR 0644, ADR 0656): over its arguments, -// its input (read only when asked for the verdict) and the heads laid for it (nil when none are), the one JSON line it -// answers, or why it refuses. `-seats` answers the seat list of the heads (SeatsOf), `-verdict` the verdict of the -// facts in the input (Judged), refusing facts of a version it does not read. -func Program(args []string, input func() ([]byte, error), heads fs.FS) ([]byte, error) { - set := flag.NewFlagSet("mesh-checking-program", flag.ContinueOnError) - set.SetOutput(io.Discard) - verdict := set.Bool("verdict", false, "answer the verdict of the facts in the input") - seats := set.Bool("seats", false, "answer the seat list of the heads laid for it") - if err := set.Parse(args); err != nil { - return nil, err - } - switch { - case *seats: - if heads == nil { - return nil, errors.New("no heads are laid for it") - } - data, err := input() - if err != nil { - return nil, fmt.Errorf("the input cannot be read: %w", err) - } - facts, err := DecodeFacts(data) - if err != nil { - return nil, err - } - answer, err := SeatsOf(heads, facts) - if err != nil { - return nil, err - } - return json.Marshal(answer) - case *verdict: - data, err := input() - if err != nil { - return nil, fmt.Errorf("the input cannot be read: %w", err) - } - facts, err := DecodeFacts(data) - if err != nil { - return nil, err - } - return json.Marshal(Judged(facts)) - } - return nil, errors.New("nothing asked: give -verdict or -seats") -} diff --git a/modules/mesh-delivery-checker/rules/refusals.go b/modules/mesh-delivery-checker/rules/refusals.go deleted file mode 100644 index 88142158..00000000 --- a/modules/mesh-delivery-checker/rules/refusals.go +++ /dev/null @@ -1,99 +0,0 @@ -package rules - -import ( - "fmt" - "maps" - "slices" - "strings" - - "git.novox.be/novox/mesh-contracts/go/seats/meshconfig" -) - -// The refusals of what the running checker asked of other seats for a check (milestone 47/G): it asks and records the -// answers as facts, and these rules decide what fails. - -// RenamesSeat is the verb a change that brings or drops a `renamed-from` is asked of (design 32). -var RenamesSeat = "seat:" + meshconfig.Seat + "." + meshconfig.VerbRenames - -// Renames is what one module of a member brings and drops of `renamed-from` (key to the old key), and how the seat -// mesh-config's verb renames answered for it: Answer when it answered; else Unasked says why it was not asked or did not -// answer, NotServed that its holder does not serve the verb. Unread says the module's manifests could not be read. -type Renames struct { - Module string `json:"module"` - Key string `json:"key"` - Brought map[string]string `json:"brought,omitempty"` - Dropped map[string]string `json:"dropped,omitempty"` - Answer *meshconfig.RenamesAnswer `json:"answer,omitempty"` - Unasked string `json:"unasked,omitempty"` - NotServed bool `json:"not-served,omitempty"` - Unread string `json:"unread,omitempty"` -} - -// JudgeRenames fails a rename the seat cannot move the value of, and the drop of a `renamed-from` while its window is -// open on a node; it says which module the seat answered for. -func JudgeRenames(r Renames) (failed []FailedFirst, notes []string) { - at := func(words string) { failed = append(failed, FailedFirst{Machine: meshconfig.Seat, Words: words}) } - switch { - case r.Unread != "": - at(fmt.Sprintf("%s (%s): its config renames cannot be judged: %s", r.Module, r.Key, r.Unread)) - return failed, nil - case r.NotServed: - for _, key := range slices.Sorted(maps.Keys(r.Brought)) { - at(fmt.Sprintf("%s (%s) renames %s from %s: refused, %s, so the value cannot be moved", r.Module, r.Key, key, r.Brought[key], r.Unasked)) - } - for _, key := range slices.Sorted(maps.Keys(r.Dropped)) { - at(fmt.Sprintf("%s (%s) drops renamed-from %s of %s: refused, %s, so whether its window is open is not known", r.Module, r.Key, r.Dropped[key], key, r.Unasked)) - } - return failed, nil - case r.Answer == nil && r.Unasked == "": - at(fmt.Sprintf("%s (%s) changes a renamed-from, and this checker cannot ask %s", r.Module, r.Key, RenamesSeat)) - return failed, nil - case r.Answer == nil: - at(fmt.Sprintf("%s (%s) changes a renamed-from, and the check cannot ask %s: %s", r.Module, r.Key, RenamesSeat, r.Unasked)) - return failed, nil - } - for _, key := range slices.Sorted(maps.Keys(r.Dropped)) { - for _, n := range r.Answer.Renames { - if n.Module == r.Module && n.From == r.Dropped[key] && n.To == key && len(n.Open) > 0 { - open := slices.Sorted(slices.Values(n.Open)) - at(fmt.Sprintf("%s (%s) drops renamed-from %s of %s while its rename window is open on %s", r.Module, r.Key, n.From, key, strings.Join(open, ", "))) - } - } - } - return failed, []string{fmt.Sprintf("%s.%s answered for %s (%s)", meshconfig.Seat, meshconfig.VerbRenames, r.Module, r.Key)} -} - -// SeatDefinitionsMachine names what refused a seat definition in a verdict's failure. -const SeatDefinitionsMachine = "seat-definitions" - -// UnparsedSeat is one seat definition of a pull request's head that does not parse, as the indexer keeps it in its state -// seat-definitions: the seat (the contracts module's name when its index did not parse), its module's directory and the -// indexer's words of why. -type UnparsedSeat struct { - Seat string `json:"seat"` - Module string `json:"module"` - Directory string `json:"directory"` - Why string `json:"why"` -} - -// Unparsed is what the indexer keeps of one pull request's seat definitions that do not parse; Unread says why its state -// could not be read. -type Unparsed struct { - Key string `json:"key"` - Seats []UnparsedSeat `json:"seats,omitempty"` - Unread string `json:"unread,omitempty"` -} - -// JudgeUnparsed fails a pull request whose head's seat definition does not parse, naming the seat and where it lives -// (design 26; the lead's ruling on A2i's finding 1), and one whose seat definitions cannot be read, since none is then -// known to parse. -func JudgeUnparsed(u Unparsed) []FailedFirst { - if u.Unread != "" { - return []FailedFirst{{Machine: SeatDefinitionsMachine, Words: fmt.Sprintf("%s: the indexer's seat definitions of it cannot be read, so none is known to parse: %s", u.Key, u.Unread)}} - } - var out []FailedFirst - for _, s := range u.Seats { - out = append(out, FailedFirst{Machine: SeatDefinitionsMachine, Words: fmt.Sprintf("%s: the seat definition of %s (module %s, %s) does not parse: %s", u.Key, s.Seat, s.Module, s.Directory, s.Why)}) - } - return out -} diff --git a/modules/mesh-delivery-checker/rules/results.go b/modules/mesh-delivery-checker/rules/results.go deleted file mode 100644 index a0a3af40..00000000 --- a/modules/mesh-delivery-checker/rules/results.go +++ /dev/null @@ -1,63 +0,0 @@ -package rules - -import "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep" - -// The shapes of a test step's answer, as the build modules' code writes them (mesh-catalog modules/mesh-build-go -// cmd/mesh-build-go levels.go TestResult; modules/mesh-build-node cmd/mesh-build-node check.go TestResult). Only the -// fields the rules read are named; the rest is ignored. - -// GoPackage is one package of a Go test result. -type GoPackage struct { - Dir string `json:"dir"` - Package string `json:"package"` - Passed bool `json:"passed"` - Elapsed float64 `json:"elapsed"` - Tests int `json:"tests"` - NoTests bool `json:"no_tests,omitempty"` - // Skipped is how many of the package's tests skipped; an older build module names none. - Skipped int `json:"skipped,omitempty"` -} - -// Failure is a test that failed, or a package that failed with no test to name: the build modules' failure contract -// (buildstep.Failure, issue 1901), its cause never empty and never a passing line from a build module that keeps it. -type Failure = buildstep.Failure - -// TestTime is one test and the seconds it took. -type TestTime struct { - Package string `json:"package"` - Test string `json:"test"` - Elapsed float64 `json:"elapsed"` -} - -// Tested is the answer of a test step of either build module (the Go one names packages and counts tests; the Node one -// names the package directory as Module and counts none). -type Tested struct { - Level string `json:"level"` - Module string `json:"module,omitempty"` - Passed bool `json:"passed"` - Why string `json:"why,omitempty"` - NoTests bool `json:"no_tests,omitempty"` - Tests int `json:"tests"` - Skipped int `json:"skipped"` - Packages []GoPackage `json:"packages,omitempty"` - Elapsed float64 `json:"elapsed"` - Setup float64 `json:"setup,omitempty"` - // Lint is the unit level's gofmt and go vet time, before its tests (mesh-build-go, ADR 0529 §1). - Lint float64 `json:"lint,omitempty"` - Bound float64 `json:"bound"` - SetupBound float64 `json:"setup_bound,omitempty"` - Slowest []TestTime `json:"slowest,omitempty"` - Failed []Failure `json:"failed,omitempty"` - OverBound bool `json:"over_bound"` - OverWhich string `json:"over_which,omitempty"` - // JudgedBy is the program that ran the step (ADR 0535 §5): "installed", or "candidate " under runner - // workspace; absent from a build module that does not take the runner. - JudgedBy string `json:"judged_by,omitempty"` - // By is the build module that answered and the SDK it was built with (buildstep.By); absent from a build module from - // before the failure contract. - By string `json:"by,omitempty"` - // OutOfStep are the generated files the step's regenerate-and-compare found out of step with their seat definitions, - // each a repository-relative path (design 26): the running checker names them in its verdict event. Absent from a - // build module that does not compare. - OutOfStep []string `json:"out-of-step,omitempty"` -} diff --git a/modules/mesh-delivery-checker/rules/seats.go b/modules/mesh-delivery-checker/rules/seats.go deleted file mode 100644 index 50040e14..00000000 --- a/modules/mesh-delivery-checker/rules/seats.go +++ /dev/null @@ -1,343 +0,0 @@ -package rules - -import ( - "bytes" - "context" - "crypto/sha256" - "encoding/hex" - "encoding/json" - "errors" - "fmt" - "io/fs" - "maps" - "path" - "slices" - "strings" - - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/seatdefs" -) - -// The seat list a check judges and composes against (novox/hq ADR 0636 §1, §4, ADR 0644 §1; the lead's rulings Q2 on -// milestones 47/B0 and 47/G): the checking program built from the heads reads the definitions the heads' contracts -// modules carry, by the domain SDK's one reading (sdk/seatdefs), the indexer's too, and answers them; the running checker -// lays them by seat over the list its reader holds from the seat mesh-catalog (verb seat-definitions) and reads no file -// of the heads. The reader's list is not in the program's input: it is large, and the answer carries only what the heads -// change. - -// SeatsVersion is the version of SeatsAnswer this program writes. -const SeatsVersion = 1 - -// SeatsAnswer is the checking program's `-seats` answer: every seat definition the heads carry, resolved, as the requests' -// field `seats` carries them, sorted by seat, that is new or differs from the reader's (Facts.SeatDigests); how many -// were the same and left out of it (Same); and each definition left out, with why. -type SeatsAnswer struct { - V int `json:"v"` - Seats []json.RawMessage `json:"seats"` - Same int `json:"same,omitempty"` - Left []LeftOut `json:"left,omitempty"` -} - -// SeatDigest is a definition's digest, the same for the same definition whatever its bytes' order and spacing: the sha256 -// of its JSON with every object's keys sorted, numbers as written. Bytes that are not JSON are digested as given. -func SeatDigest(raw json.RawMessage) string { - d := json.NewDecoder(bytes.NewReader(raw)) - d.UseNumber() - var v any - canonical := []byte(raw) - if d.Decode(&v) == nil { - if out, err := json.Marshal(v); err == nil { - canonical = out - } - } - sum := sha256.Sum256(canonical) - return hex.EncodeToString(sum[:]) -} - -// LeftOut is a seat definition the list does not take from the heads: its file and why. -type LeftOut struct { - Path string `json:"path"` - Why string `json:"why"` -} - -// SeatsOf is the seat definitions of the facts' members' heads that are new or differ from the reader's (Facts.SeatDigests). heads holds each member's head at its repository's path; a contracts module is a manifest there whose package artifact names -// `generated-from` (seatdefs.Of). A seat of the mesh's own a module that is not its domain's defines (seatdefs.Refusal), -// and a seat two modules define where neither hands it over, are left out, said; a definition that does not parse is an -// error. -// Heads with no contracts module give an empty list. -func SeatsOf(heads fs.FS, f Facts) (SeatsAnswer, error) { - out := SeatsAnswer{V: SeatsVersion} - type taken struct { - raw json.RawMessage - module, file string - } - by := map[string]taken{} - refused := map[string]bool{} - repositories := map[string]string{} - for _, m := range f.Members { - repositories[m.Repository] = m.Head - } - for _, repository := range slices.Sorted(maps.Keys(repositories)) { - if _, err := fs.Stat(heads, repository); errors.Is(err, fs.ErrNotExist) { - continue // no head of it is laid: it carries no definition here - } - sub, err := fs.Sub(heads, repository) - if err != nil { - return SeatsAnswer{}, err - } - manifests, err := manifestsIn(sub) - if err != nil { - return SeatsAnswer{}, err - } - forge := localForge(sub) - for _, c := range seatdefs.ContractsModules(manifests) { - defs, unparsed, err := forge.Read(context.Background(), repository, repositories[repository], c) - if err != nil { - return SeatsAnswer{}, fmt.Errorf("the seat definitions of %s at the head of %s cannot be read: %w", c.Module, repository, err) - } - // A head's definition that does not parse, or names another seat than its directory's, leaves the group's seats - // unknown: no list is made, so no manifest is judged by a list without it (design 26). - for _, seat := range slices.Sorted(maps.Keys(unparsed)) { - return SeatsAnswer{}, fmt.Errorf("the seat definition of %s (module %s) at the head of %s is not taken: %s", seat, c.Module, repository, unparsed[seat]) - } - for _, seat := range slices.Sorted(maps.Keys(defs)) { - d, file := defs[seat], defFile(repository, c, seat) - if why := seatdefs.Refusal(c.Module, d); why != "" { - out.Left = append(out.Left, LeftOut{Path: file, Why: why}) - continue - } - if prev, twice := by[seat]; twice || refused[seat] { - switch { - case refused[seat]: - out.Left = append(out.Left, LeftOut{Path: file, Why: "the seat " + seat + " is defined in more than one place"}) - continue - case seatdefs.HandsOver(prev.module, c.Module, d): - case seatdefs.HandsOver(c.Module, prev.module, d): - continue - default: - why := "the seat " + seat + " is defined in more than one place: " + prev.file + ", " + file - out.Left = append(out.Left, LeftOut{Path: prev.file, Why: why}, LeftOut{Path: file, Why: why}) - delete(by, seat) - refused[seat] = true - continue - } - } - raw, err := json.Marshal(d) - if err != nil { - out.Left = append(out.Left, LeftOut{Path: file, Why: err.Error()}) - continue - } - by[seat] = taken{raw: raw, module: c.Module, file: file} - } - } - } - out.Seats = make([]json.RawMessage, 0, len(by)) - for _, seat := range slices.Sorted(maps.Keys(by)) { - if held, ok := f.SeatDigests[seat]; ok && held == SeatDigest(by[seat].raw) { - out.Same++ // the reader holds it as the heads carry it: the checker's own list keeps it - continue - } - raw := by[seat].raw - // The answer is the judging view of a seat, what the manifest validator and the composer read (the lead's ruling after - // the group check of 616c42434ac2), with digests or without: no verb's or message's schema, which neither reads, and - // which the build seat's step state, keeping this answer, would refuse where a property is named like a credential - // (mesh-vault's verb input `credentials`). - raw = withoutMessageSchemas(raw) - if f.SeatDigests == nil { - // A checker from before G hands no digests, so every definition is answered: whole they are over a run answer's - // bound, so every description but the seat's own is left out too, which decides no verdict; review round 2 of G. - raw = withoutInnerDescriptions(raw) - } - out.Seats = append(out.Seats, raw) - } - return out, nil -} - -// defFile is a seat's definition file in a head, by its repository's path. -func defFile(repository string, c seatdefs.Module, seat string) string { - return path.Join(repository, c.Defs, "seats", seat, "seat.json") -} - -// manifestsIn are the raw manifests of a head by their directory (the root's is "."), the generated contracts, the tests' -// data and the packages' dependencies left out. -func manifestsIn(head fs.FS) (map[string]string, error) { - out := map[string]string{} - err := fs.WalkDir(head, ".", func(p string, d fs.DirEntry, err error) error { - if err != nil { - return err - } - if d.IsDir() && (d.Name() == ".git" || d.Name() == "testdata" || d.Name() == "node_modules") { - return fs.SkipDir - } - if !d.IsDir() && d.Name() == "module.json" { - raw, err := fs.ReadFile(head, p) - if err != nil { - return err - } - out[path.Dir(p)] = string(raw) - } - return nil - }) - return out, err -} - -// localForge is the domain SDK's reading bound to a head laid on disk: a directory or a file the head does not hold is -// none. -func localForge(head fs.FS) seatdefs.Forge { - return seatdefs.Forge{ - Files: func(_ context.Context, _, _ string, dirs []string) (map[string]map[string]string, error) { - out := map[string]map[string]string{} - for _, dir := range dirs { - files := map[string]string{} - err := fs.WalkDir(head, dir, func(p string, d fs.DirEntry, err error) error { - if err != nil { - return err - } - if !d.IsDir() { - files[strings.TrimPrefix(p, dir+"/")] = "" - } - return nil - }) - if errors.Is(err, fs.ErrNotExist) { - continue - } - if err != nil { - return nil, err - } - out[dir] = files - } - return out, nil - }, - File: func(_ context.Context, _, _, file string) ([]byte, error) { - raw, err := fs.ReadFile(head, file) - if errors.Is(err, fs.ErrNotExist) { - return nil, nil - } - return raw, err - }, - } -} - -// withoutMessageSchemas is a definition whose verbs' input and answer, and whose accepted messages', events' and holder -// events' bodies, are each the empty schema, and whose types (`defs`) are only those something it keeps still refers to -// (a state's key forms, a provision's form, another kept type). Every other field is kept as written; bytes that are not -// a JSON object are given back as they are. -func withoutMessageSchemas(raw json.RawMessage) json.RawMessage { - d := json.NewDecoder(bytes.NewReader(raw)) - d.UseNumber() - var def map[string]any - if d.Decode(&def) != nil { - return raw - } - empty := func(list any, fields ...string) { - items, _ := list.([]any) - for _, it := range items { - m, ok := it.(map[string]any) - if !ok { - continue - } - for _, f := range fields { - if _, has := m[f]; has { - m[f] = map[string]any{} - } - } - } - } - empty(def["verbs"], "input", "answer") - for _, field := range []string{"accepts", "events", "holder-events"} { - empty(def[field], "body") - } - if defs, ok := def["defs"].(map[string]any); ok { - rest := maps.Clone(def) - delete(rest, "defs") - kept := map[string]bool{} - todo := typesReferred(rest) - for len(todo) > 0 { - name := todo[len(todo)-1] - todo = todo[:len(todo)-1] - if kept[name] || defs[name] == nil { - continue - } - kept[name] = true - todo = append(todo, typesReferred(defs[name])...) - } - maps.DeleteFunc(defs, func(name string, _ any) bool { return !kept[name] }) - if len(defs) == 0 { - delete(def, "defs") - } - } - out, err := json.Marshal(def) - if err != nil { - return raw - } - return out -} - -// typesReferred are the names of the definition's types (`{"$ref": "#/defs/"}`) v refers to, anywhere in it. -func typesReferred(v any) []string { - var out []string - var walk func(any) - walk = func(v any) { - switch t := v.(type) { - case map[string]any: - if ref, ok := t["$ref"].(string); ok { - if name, found := strings.CutPrefix(ref, "#/defs/"); found { - out = append(out, name) - } - } - for _, x := range t { - walk(x) - } - case []any: - for _, x := range t { - walk(x) - } - } - } - walk(v) - return out -} - -// schemaData are the keywords of a schema whose value is data, never a schema: what they hold is kept as written. -var schemaData = map[string]bool{"examples": true, "enum": true, "const": true, "default": true} - -// withoutInnerDescriptions is a definition with only the seat's own description kept: every other `description` string, -// of a verb, an event or anything inside their schemas, is left out, every other field kept (a property named -// description is a schema, kept; a schema's data keywords are kept whole). Bytes that are not a JSON object are given -// back as they are. -func withoutInnerDescriptions(raw json.RawMessage) json.RawMessage { - d := json.NewDecoder(bytes.NewReader(raw)) - d.UseNumber() - var def map[string]any - if d.Decode(&def) != nil { - return raw - } - var walk func(v any) - walk = func(v any) { - switch t := v.(type) { - case map[string]any: - for k, val := range t { - if _, prose := val.(string); prose && k == "description" { - delete(t, k) - continue - } - if !schemaData[k] { - walk(val) - } - } - case []any: - for _, e := range t { - walk(e) - } - } - } - for k, val := range def { - if k != "description" { - walk(val) - } - } - out, err := json.Marshal(def) - if err != nil { - return raw - } - return out -} diff --git a/modules/mesh-delivery-checker/rules/words.go b/modules/mesh-delivery-checker/rules/words.go deleted file mode 100644 index 57c232d0..00000000 --- a/modules/mesh-delivery-checker/rules/words.go +++ /dev/null @@ -1,281 +0,0 @@ -package rules - -import ( - "fmt" - "strings" - - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshdeliverycheckerclient" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshdeliverychecker" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep" -) - -// The words rules: how a failed test, a failed package and a list of failures are worded in a verdict (issue 1901, issue -// 1921). Moved whole from the running checker's package (milestone 47/B0): they are the checking program's. - -// FailedName names a failure: its package and test. -func FailedName(f Failure) string { - if f.Test == "" { - return f.Package - } - return f.Package + "." + f.Test -} - -// MaxWords is the most a failed test's words in a verdict hold (issue 1901). **The words keep the failure's last lines**, -// where a test says why it failed: the first line is often something it logged before (the group r4g verdict kept a -// "judged against" line and lost the t.Fatalf after it), and the 120 characters kept before cut a docker command's echo -// before docker's own error. Four kilobytes holds a long message and is small beside a verdict's other parts. -const MaxWords = 4096 - -// FailureWords is a failure's words: its output's last lines up to MaxWords, with the line the build module told apart as -// the test's error first when the output does not start with it, so the first line of the words is the cause and the -// status line, which is cut short, names it. **A failure's words are never "PASS" or "ok"** (issue 1901, its third -// meeting: a package that failed after its tests passed was worded "PASS"): go test's summary lines are dropped, and with -// no cause told apart (an older build module) the cause is the output's first "panic:", "fatal error:" or "signal:" -// line, read before the output is cut, or the words say the tests passed and the program failed after them. -func FailureWords(f Failure) string { - return FailureWordsAfter(f, "") -} - -// FailureWordsAfter is FailureWords with the line loud put first, within the same MaxWords: what the checker itself says of -// the failure (that the build module hid it), which the status line then names. -func FailureWordsAfter(f Failure, loud string) string { - out, passed := DropSummary(strings.TrimSpace(f.Output)) - cause := strings.TrimSpace(f.Cause) - if cause == "" { - cause = CauseIn(out) - } - switch { - case cause == "" && out == "" && passed: - cause = "the tests passed, then the test program exited with a failure: an os.Exit or a panic in TestMain or after the tests" - case cause == "" && out == "": - // The build module on main sends a package that stopped (a timeout, an exit, a kill) as its "FAIL" line alone. - cause = "the package failed with no test to name and no panic, signal or build error in its output (an older build module sent no cause)" - } - if len(cause) > MaxCause { - cause = strings.ToValidUTF8(cause[:MaxCause], "") + "..." - } - // The words keep MaxWords exactly: the loud line, the cause and their newlines, the marker and the kept lines. - budget := MaxWords - if cause != "" { - budget -= len(cause) + 1 - } - if loud != "" { - budget -= len(loud) + 1 - } - if len(out) > budget { - const marker = "... " - tail := out[len(out)-(budget-len(marker)):] - // Start on a whole line, and a whole character. - if i := strings.IndexByte(tail, '\n'); i >= 0 { - tail = strings.TrimLeft(tail[i:], "\n") - } - out = marker + strings.ToValidUTF8(tail, "") - } - if cause != "" && !strings.HasPrefix(FirstLine(out), cause) { - out = strings.TrimRight(cause+"\n"+out, "\n") - } - if loud != "" { - out = strings.TrimRight(loud+"\n"+out, "\n") - } - return out -} - -// HidWords is the checker's loud line for a failure the build module sent hiding its cause (issue 1901, its thorough -// fix): with no cause, or a passing line as its cause, under the failure contract (buildstep.Hidden). It names the build -// module and the version it says it is (Tested.By, " with mesh-sdk "); one from before the contract -// says nothing of itself. "" when the failure keeps the contract. The check fails either way: only its words change. -func HidWords(module, by string, f Failure) string { - why := buildstep.Hidden(f) - if why == "" { - return "" - } - version := "a version before the failure contract" - if module == "" { - module = "an unnamed build module" - } - if m, v, ok := strings.Cut(by, " with "); ok && m != "" { - module, version = m, v - } - return fmt.Sprintf("the build module hid the failure (%s at %s): %s", module, version, why) -} - -// MaxCause is the most a cause in a failure's words holds: one long line (the 1901 review: a cause of a kilobyte could -// push the words past MaxWords). -const MaxCause = 1024 - -// DropSummary drops go test's summary lines from a failure's output ("PASS", "FAIL", "ok ", "FAIL "), and says -// whether a "PASS" was among them: the package's tests passed before it failed. -func DropSummary(out string) (string, bool) { - passed := false - lines := strings.Split(out, "\n") - kept := lines[:0] - for _, l := range lines { - // go's exact forms only (review round 1): "PASS" or "FAIL" alone, "ok \t\t