Files
mesh-delivery/modules/mesh-delivery-pipeline/internal/pipeline/failed_test.go
T
jschoubben 38ad9ed84d R10: a step's output is read where its build seat's holder keeps it
runner_step_output (pipeline, mover, step) reads the step from the state
pipelines and asks the verb output of the build seat's holder on the node
its step key names, by the step's ask, once per artifact the step ran for;
a step that reads a shared run is answered by that run's ask. The runner
keeps no output of its own: the objects step-outputs go, with the step's
and the log entry's output and show's outputs; the runner seat's form
rises to 4. The manifest invokes the three build seats' output.

Builds: design 47 H2 §791; H-A-412 (1)
2026-11-22 01:34:54 +01:00

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)
}
}