The finding pipeline-failed has scope delivery and id <module>.<branch>, one per mover whose required step failed or could not run, naming the pipeline and the steps, owned by the commit's author as before; that module's next passed pipeline on that branch clears it. Unit tests 84 to 84 (the newer-revision test replaced). Builds: design 47 H §770; lead answers H-A-19, H-A-59 Claude-Session: https://claude.ai/code/session_01JG73KHUnBze48rdua8u2sy
160 lines
6.3 KiB
Go
160 lines
6.3 KiB
Go
package pipeline
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"strings"
|
|
"testing"
|
|
|
|
condseat "git.novox.be/novox/mesh-contracts/health-and-repair/go/seats/meshconditions"
|
|
seat "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshpipelinerunner"
|
|
nodebuildgo "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/nodebuildgo"
|
|
)
|
|
|
|
// heldFindings is a finding writer in memory, by key.
|
|
type heldFindings struct {
|
|
held map[string]condseat.Finding
|
|
cleared []string
|
|
}
|
|
|
|
func newHeld() *heldFindings { return &heldFindings{held: map[string]condseat.Finding{}} }
|
|
|
|
func (h *heldFindings) Write(_ context.Context, f condseat.Finding) error {
|
|
h.held[f.Scope+"."+f.ID+"."+f.Kind] = f
|
|
return nil
|
|
}
|
|
|
|
func (h *heldFindings) Clear(_ context.Context, scope, id, kind, _ string) error {
|
|
delete(h.held, scope+"."+id+"."+kind)
|
|
h.cleared = append(h.cleared, id)
|
|
return nil
|
|
}
|
|
|
|
func (h *heldFindings) Held() []condseat.Finding {
|
|
var out []condseat.Finding
|
|
for _, f := range h.held {
|
|
out = append(out, f)
|
|
}
|
|
return out
|
|
}
|
|
|
|
// A required step that failed or could not run is the finding pipeline-failed of its mover, id <module>.<branch> in the scope
|
|
// delivery, owned by the commit's author as the forge records it; one whose author is not known has no owner and says why, and
|
|
// the next step end of that mover writes it (design 47 G §33, §540, A-191; H §770, H-A-59); an optional step that failed says
|
|
// nothing.
|
|
func TestAFailedRequiredStepIsTheFindingOfItsCommit(t *testing.T) {
|
|
for _, c := range []struct {
|
|
name, step, outcome string
|
|
author string
|
|
authorErr error
|
|
wantFinding bool
|
|
wantOwner string
|
|
}{
|
|
{"required failed", "lint", "failed", "alice", nil, true, "forge:alice"},
|
|
{"required could not run", "lint", "could not run", "alice", nil, true, "forge:alice"},
|
|
{"no pull request merged it", "lint", "failed", "", errors.New("not found"), true, ""},
|
|
{"optional failed", "unit", "failed", "alice", nil, false, ""},
|
|
{"required passed", "lint", "passed", "alice", nil, false, ""},
|
|
} {
|
|
t.Run(c.name, func(t *testing.T) {
|
|
h, store, _, _, _, _ := fixture()
|
|
p := store[pkey]
|
|
p.p.Movers[0].Repository = "novox/app"
|
|
store[pkey] = p
|
|
f := newHeld()
|
|
h.Failures = &Failures{Findings: f, Observer: "mesh-delivery-pipeline", Now: h.Now,
|
|
Author: func(repository, commit string) (string, error) {
|
|
if repository != "novox/app" || commit != "c1" {
|
|
t.Errorf("the author of %s in %s was asked", commit, repository)
|
|
}
|
|
return c.author, c.authorErr
|
|
}}
|
|
ask := map[string]string{"lint": "a1", "unit": "a2"}[c.step]
|
|
if _, err := h.OnStepEnded(goSeat, goSeat.Prefix+"n1", ended(ask, c.step, c.outcome)); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
got, ok := f.held["delivery.app.main.pipeline-failed"]
|
|
if ok != c.wantFinding {
|
|
t.Fatalf("finding written: %v, want %v (%v)", ok, c.wantFinding, f.held)
|
|
}
|
|
if !ok {
|
|
return
|
|
}
|
|
if got.Owner != c.wantOwner || got.Observer != "mesh-delivery-pipeline" || got.Subject.ID != "app.main" {
|
|
t.Fatalf("finding %+v, want owner %q", got, c.wantOwner)
|
|
}
|
|
for _, name := range []string{"app", "main", "c1", "lint", pkey} {
|
|
if !strings.Contains(got.Explanation, name) {
|
|
t.Errorf("the explanation does not name %q: %s", name, got.Explanation)
|
|
}
|
|
}
|
|
if c.wantOwner == "" && !strings.Contains(got.Explanation, "no owner") {
|
|
t.Errorf("an ownerless finding does not say why: %s", got.Explanation)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
// The owner of a failed head whose author could not be read is written at the next step end of that commit (A-191).
|
|
func TestTheOwnerOfAFailedHeadIsWrittenAtTheNextStepEnd(t *testing.T) {
|
|
h, store, _, _, _, _ := fixture()
|
|
f := newHeld()
|
|
known := false
|
|
h.Failures = &Failures{Findings: f, Now: h.Now, Author: func(string, string) (string, error) {
|
|
if !known {
|
|
return "", errors.New("the forge did not answer")
|
|
}
|
|
return "bob", nil
|
|
}}
|
|
if _, err := h.OnStepEnded(goSeat, goSeat.Prefix+"n1", ended("a1", "lint", "failed")); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if f.held["delivery.app.main.pipeline-failed"].Owner != "" {
|
|
t.Fatalf("an owner before the author is known: %+v", f.held)
|
|
}
|
|
known = true
|
|
p := store[pkey]
|
|
p.p.Steps[1].Status = seat.StepResultStatusRequired
|
|
store[pkey] = p
|
|
if _, err := h.OnStepEnded(goSeat, goSeat.Prefix+"n1", ended("a2", "unit", "failed")); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got := f.held["delivery.app.main.pipeline-failed"].Owner; got != "forge:bob" {
|
|
t.Fatalf("owner %q, want forge:bob", got)
|
|
}
|
|
}
|
|
|
|
// R15/AC1 (design 47 H §770): a pipeline with two failing movers raises two findings, one per mover, id <module>.<branch>;
|
|
// a later pipeline passing one of them clears that one alone.
|
|
func TestEachFailingMoverIsAFindingAndItsNextPassedPipelineClearsIt(t *testing.T) {
|
|
h, store, _, _ := twoMovers(t)
|
|
f := newHeld()
|
|
h.Failures = &Failures{Findings: f, Now: h.Now, Author: func(string, string) (string, error) { return "alice", nil }}
|
|
for _, ev := range []StepEnded{ended("a1", "lint", "failed"), libEnded("failed")} {
|
|
if _, err := h.OnStepEnded(goSeat, goSeat.Prefix+"n1", ev); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
if _, ok := f.held["delivery.app.main.pipeline-failed"]; !ok || len(f.held) != 2 {
|
|
t.Fatalf("findings %v, want one for app and one for lib", f.held)
|
|
}
|
|
if lib := f.held["delivery.lib.main.pipeline-failed"]; !strings.Contains(lib.Explanation, pkey) || !strings.Contains(lib.Summary, "unit") {
|
|
t.Errorf("lib's finding %+v, want the pipeline and the step named", lib)
|
|
}
|
|
// A later pipeline moving lib alone passes: lib's finding clears, app's stands.
|
|
store["main.6"] = struct {
|
|
p seat.Pipeline
|
|
rev uint64
|
|
}{seat.Pipeline{V: 1, Pipeline: "main.6", Branch: "main", Source: 6, Outcome: seat.PipelineOutcomeRunning,
|
|
Steps: []seat.StepResult{{Module: "lib", Artifact: "lib:lib", Step: seat.StepResultStepUnit, Status: seat.StepResultStatusRequired,
|
|
Outcome: seat.StepResultOutcomeRunning, Ask: "b2", Seat: nodebuildgo.Seat}}, Movers: []seat.Mover{{Module: "lib", Commit: "c4", Fingerprint: "src2:dd"}}}, 1}
|
|
ev := libEnded("passed")
|
|
ev.ID, ev.Ask, ev.Pipeline, ev.Commit, ev.Fingerprint = "b2", "b2", "main.6", "c4", "src2:dd"
|
|
if _, err := h.OnStepEnded(goSeat, goSeat.Prefix+"n1", ev); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if _, stands := f.held["delivery.app.main.pipeline-failed"]; !stands || len(f.held) != 1 {
|
|
t.Fatalf("findings %v, want app's alone after lib's pipeline passed", f.held)
|
|
}
|
|
}
|