Files
mesh-delivery/modules/mesh-delivery-pipeline/manifest_test.go
T
jschoubben cec7d05651 pipeline runner: never ask a test step its build seat's steps says has nothing to run
In main.416 a contracts module's TypeScript package waited about 290 s for a
build node, per step, to answer nothing to run in 1 to 3 s. At placement the
runner now calls each artifact's build seat's verb steps (kept by the
artifact's fingerprint, answered in seconds) with the fetch its steps are
asked with, and ends every lint, unit or integration step of a kind it
answers none for as nothing to run at once: logged, said, asked of no
build node. The other steps are asked as before, beside the build step. A
steps call that fails asks the artifact's steps as before, said in one
journal line. A step placed again after a restart is placed from what its
first placing knew, so a test run keeps its asker.

The build step's record now carries asked-at, as the test steps' do, so
the pipelines page shows how long it waited.

Builds: design 47 H2 H-A-515, H-A-515 addendum, H-A-516
2026-11-23 10:38:30 +01:00

274 lines
13 KiB
Go

package pipeline_test
import (
"encoding/json"
"maps"
"os"
"slices"
"strings"
"testing"
seat "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshpipelinerunner"
"git.novox.be/novox/mesh-sdk/go/catalogue"
)
// TestManifest holds the runner's manifest to its design lines, row by row.
func TestManifest(t *testing.T) {
raw, err := os.ReadFile("module.json")
if err != nil {
t.Fatal(err)
}
m, err := catalogue.Decode(raw)
if err != nil {
t.Fatalf("the manifest does not read: %v", err)
}
var states, streams, objects []string
keyTTL := map[string]bool{}
stateMiB := map[string]int{}
for _, s := range m.State {
states = append(states, s.Name)
keyTTL[s.Name] = s.KeyTTL
stateMiB[s.Name] = s.MaxMiB
}
objectMiB := map[string]int{}
for _, s := range m.Streams {
streams = append(streams, s.Name)
}
for _, o := range m.Objects {
objects = append(objects, o.Name)
objectMiB[o.Name] = o.MaxMiB
}
var program catalogue.Artifact
if m.Build == nil {
t.Fatal("the manifest builds nothing")
}
for _, a := range m.Build.Artifacts {
if a.Name == "program" {
program = a
}
}
rows := []struct {
name string
ok bool
}{
// RN1/AC1 (§21): a foundation part asks no template; its kept data are in old sections.
{"no requires", len(m.Requires) == 0},
{"claims the seat serving every verb of its definition", len(m.Claims) == 1 && m.Claims[0].Name == seat.Seat &&
equalSets(m.Claims[0].Serves, seat.Verbs())},
// §27, §85, §330, §355, §77: the old state sections.
{"old state sections", equalSets(states, []string{seat.StatePipelines, seat.StateKept, "aged", "recoveries", "bounds", "test-runs", "toolchains", "findings", "first-views", "consumers", seat.StateQueue, "unfinished"})},
// design 47 H2 §786, §820: unfinished is a state of 8 MiB.
{"unfinished 8 MiB", stateMiB["unfinished"] == 8},
// design 47 H2 §814, §820; H-A-411 (2), H-A-437: every state names its cap, 8 MiB where its live fill allows, bounds
// 16 MiB (2.1 MiB live on 2026-11-22).
{"every state capped", !slices.Contains(slices.Collect(maps.Values(stateMiB)), 0) && stateMiB["bounds"] == 16 &&
stateMiB[seat.StateQueue] == 8 && stateMiB["findings"] == 8},
// §535, §647, A-77, A-104: an ask no holder takes is bound by a key with its own time to live.
{"bounds is key-ttl", keyTTL["bounds"]},
// §725, A-469w, A-470: test-runs holds its runs' bound keys, each with its own time to live; 64 MiB its ceiling.
{"test-runs is key-ttl of 64 MiB", keyTTL["test-runs"] && stateMiB["test-runs"] == 64},
// §748: the settings of the test runs, the widens and the queue, pipelines-at-once from 1 to 8 (default 1) and
// pipelines-waiting-cap (default 64), each written to its file.
{"the test runs' settings", runSettingsOf(raw)},
// RN25 (§469, §85): an old state section declares its cap, pipelines 256 MiB and kept 128 MiB.
{"pipelines 256 MiB", stateMiB[seat.StatePipelines] == 256},
{"kept 128 MiB", stateMiB[seat.StateKept] == 128},
// §470 (amending §27, §85): the step log is an old logs section kept 100 days, 128 MiB; RN24 (§383, §387): the finding
// stream its findings are said on is the one old stream.
{"old streams section", equalSets(streams, []string{"mesh-delivery-pipeline-findings"})},
{"step-log an old logs section of 100 days and 128 MiB", len(m.Logs) == 1 && m.Logs[0].Name == seat.StateStepLog &&
m.Logs[0].MaxAgeDays == 100 && m.Logs[0].MaxMiB == 128},
// design 47 H2 §783, H-A-411 (1): the findings history drops its oldest at 8 MiB, kept 7 days.
{"finding stream 7 days 8 MiB", len(m.Streams) == 1 && m.Streams[0].MaxAgeDays == 7 && m.Streams[0].MaxMiB == 8 &&
equalSets(m.Streams[0].Events, []string{"finding-written.*", "finding-cleared.*", "findings-stated.*"})},
// RN24 (§368): the version as MAJOR.MINOR, 0.1 with none published.
{"version 0.1", m.Version == "0.1"},
// design 47 H2 §810, §814; H-A-394 (1): it claims a seat, so its class is core.
{"class core", m.Class == catalogue.ClassCore},
// RN25 (§477, §533, §59): a foundation part whose seat has verbs and events declares its sent store, 256 MiB.
// design 47 H2 §791: step-outputs goes; a step's output is read where its build seat's holder keeps it.
{"old objects section", equalSets(objects, []string{catalogue.SentObjectsLocal})},
{"sent-objects 256 MiB", objectMiB[catalogue.SentObjectsLocal] == 256},
// §333, §54, §44, §53, §376, §24, §37, §4, §77: what the runner hears.
{"consumes", equalSets(m.Consumes, []string{
"mesh-delivery-indexer.take-in.taken", "mesh-builds.package-published", "mesh-builds.toolchain-agreed", "mesh-builds.step-ended",
"operator-channel.decided", "node-build-go.step-ended",
// design 47 H2 §777, §778: the bound of an ask on mesh-builds and mesh-wants counts from its holder's pull.
"mesh-builds.ask-taken", "mesh-wants.ask-taken", "node-build-node.step-ended",
"node-build-image.step-ended", "node-build-go.ask-taken", "node-build-node.ask-taken", "node-build-image.ask-taken",
"node-build-go.step-progress", "node-build-node.step-progress", "node-build-image.step-progress", "mesh-wants.step-ended", "mesh-wants.step-progress",
// H-A-514 addendum: the seat mesh-builds says step-progress of a build step that builds or waits for a package.
"mesh-builds.step-progress", "node-engine.running", "mesh-catalog.registration-changed",
"mesh-catalog.catalog-revision", "mesh-catalog.version-released", "mesh-conditions.findings-asked", "mesh-delivery.recovery-merged",
// A-186: the seat list its write verbs' callers are checked against, heard as it changes.
"mesh-catalog.seat-definition-changed", "mesh-catalog.seat-definition-removed",
// §647 as A-466z amends it: no holder is read from the seat-holders view.
"seat:mesh-module-assigner.views.seat-holders"})},
// RN2 (§21, §195, §200, §77): the registrations and the catalog half asked by their verbs, the first views read and
// asked again by hand (a hand act).
{"invokes", equalSets(m.Invokes, []string{"seat:mesh-catalog.registrations",
// A-186: the seat list, read by its verb.
"seat:mesh-catalog.seat-definitions", "seat:mesh-catalog.revision", "seat:mesh-hand-acts.hand-act",
// RN10 (§71, §441, A-207): the permissions a change widens, asked of the grants part.
"seat:mesh-grants.grants-for",
// RN11 (§33, A-191): the author of a failed head, read as the forge records it.
"seat:git.pull",
// design 47 H2 §815, H-A-408: a source-only check is fingerprinted by its commit's root tree.
"seat:git.trees",
// RN8 (§31, §350; A-182): a superseded step's ask dropped of the build seat that holds it.
"seat:node-build-go.drop", "seat:node-build-node.drop", "seat:node-build-image.drop",
// A-74, A-89: who holds the seat operator-channel, whose state asks holds the router's record of the approval ask.
"seat:mesh-module-assigner.assignments",
// A-102 (§22, §24): the accepted kinds the runner puts its steps on.
"seat:mesh-builds.step", "seat:mesh-wants.step", "seat:node-build-go.check.step", "seat:node-build-node.check.step",
"seat:node-build-image.check.step",
// H-A-328: whether a package a mover waits on is published, read when the wait is written.
"seat:mesh-builds.published",
// design 47 H2 §778: a step ended by its bound drops its ask through the seat's drop.
"seat:mesh-builds.drop", "seat:mesh-wants.drop",
// RN22 (§86, §415, A-207): a recovery's steps on the build seats' stream delivery.
"seat:node-build-go.delivery.step", "seat:node-build-node.delivery.step", "seat:node-build-image.delivery.step",
// A-231: the queues of the build seats it asks, check for the steps and delivery for a recovery's.
"seat:node-build-go.accept.check", "seat:node-build-go.accept.delivery", "seat:node-build-node.accept.check",
"seat:node-build-node.accept.delivery", "seat:node-build-image.accept.check", "seat:node-build-image.accept.delivery",
// design 47 H2 §791: runner_step_output reads a step's output where its build seat's holder keeps it.
"seat:node-build-go.output", "seat:node-build-node.output", "seat:node-build-image.output",
// design 47 H2 H-A-515 addendum: an artifact's steps read at placement, so a kind it has none of is never asked.
"seat:node-build-go.steps", "seat:node-build-node.steps", "seat:node-build-image.steps"})},
{"uses operator-channel", equalSets(m.Uses, []string{"operator-channel"})},
// RN25 (§539): the runner's tools carry the prefix runner_.
{"first-view tools", equalSets(m.Tools, []string{"runner_first_views", "runner_first_view_again", "runner_health", "runner_unlogged", "runner_unlogged_append",
"runner_start", "runner_run", "runner_accept", "runner_ask_again", "runner_place", "runner_end_again", "runner_waiting",
"runner_test_runs", "runner_test_runs_drop", "runner_unfinished", "runner_unfinished_drop", "runner_unfinished_place",
// design 47 H2 §789: a pipeline read in parts.
"runner_show", "runner_movers",
// design 47 H2 §791: a step's output read where it is kept.
"runner_step_output"})},
// A-305 (ADR 0227 rule 8, ADR 0240 rule 2): the process is judged by its unit, as every process of mesh-delivery,
// never by a tool of its own; runner_health stays a tool.
{"health is the unit", healthTool(raw) == "unit"},
// RN1/AC5 (§95, §130): the new assigner is delivered before the runner.
{"program needs the assigner's program", slices.Equal(program.Needs, []string{"mesh-delivery-assigner:program"})},
}
for _, r := range rows {
if !r.ok {
t.Errorf("%s: not as the design says", r.name)
}
}
}
// §610, A-75: no verb of the runner's definition names its callers, so the class's default holds for each.
func TestNoVerbNamesItsCallers(t *testing.T) {
raw, err := os.ReadFile("../mesh-delivery-contracts/seats/mesh-pipeline-runner/seat.json")
if err != nil {
t.Fatal(err)
}
var def struct {
Verbs []struct {
Name string `json:"name"`
Callers []string `json:"callers"`
} `json:"verbs"`
}
if err := json.Unmarshal(raw, &def); err != nil {
t.Fatal(err)
}
if len(def.Verbs) == 0 {
t.Fatal("the definition holds no verb")
}
for _, v := range def.Verbs {
if len(v.Callers) != 0 {
t.Errorf("the verb %s names callers %v; from G no verb does (§610)", v.Name, v.Callers)
}
}
}
// healthTool is the process resource's health kind and tool.
// healthTool is the process's health, its kind and its tool when it names one.
func healthTool(raw []byte) string {
var m struct {
Resources []struct {
Type string `json:"type"`
Health struct {
Kind string `json:"kind"`
Tool string `json:"tool"`
} `json:"health"`
} `json:"resources"`
}
if err := json.Unmarshal(raw, &m); err != nil {
return err.Error()
}
for _, r := range m.Resources {
if r.Type == "process" {
return strings.TrimSpace(r.Health.Kind + " " + r.Health.Tool)
}
}
return ""
}
func equalSets(a, b []string) bool {
x, y := slices.Clone(a), slices.Clone(b)
slices.Sort(x)
slices.Sort(y)
return slices.Equal(x, y)
}
// runSettingsOf says whether the manifest holds the test runs' three settings (design 47 G §725; A-469w, A-469x), Go
// durations, test-runs-kept 48h by default, each written into the file its environment names, and no cap setting: the cap is
// the state's max-mib (H-A-510 and its addendum).
func runSettingsOf(raw []byte) bool {
var m struct {
Config map[string]map[string]any `json:"config"`
Resources []struct {
Type string `json:"type"`
Path string `json:"path"`
Content string `json:"content"`
Env map[string]string `json:"env"`
} `json:"resources"`
}
if json.Unmarshal(raw, &m) != nil {
return false
}
want := map[string]string{"test-runs-kept": "string", "test-step-bound": "string", "run-untaken-bound": "string", "ask-unanswered-bound": "string", "widens-read-bound": "string", "revisions-kept": "number",
"pipelines-at-once": "number", "pipelines-waiting-cap": "number"}
// design 47 H2 §790, §781: stalled-bound is read through mesh-sdk's settings reader, by the process and the tools
// program alike, from the words the node-engine composes: no file of its own.
// design 47 H2 §775: the kept-call form's pace, read by mesh-sdk at the process's and the bundle's start; §777:
// ask-silent-bound goes.
words := map[string]string{"stalled-bound": "5m", "kept-call-pace-first": "1s", "kept-call-pace-max": "30s"}
for key, def := range words {
if m.Config[key]["type"] != "string" || m.Config[key]["default"] != def || m.Config[key]["runtime"] != true {
return false
}
}
if len(m.Config) != len(want)+len(words) || m.Config["test-runs-kept"]["default"] != "48h" ||
m.Config["pipelines-at-once"]["minimum"] != float64(1) || m.Config["pipelines-at-once"]["maximum"] != float64(8) ||
m.Config["pipelines-at-once"]["default"] != float64(1) || m.Config["pipelines-waiting-cap"]["default"] != float64(64) ||
m.Config["widens-read-bound"]["default"] != "30s" {
return false
}
env := map[string]bool{}
for _, r := range m.Resources {
for _, v := range r.Env {
env[v] = true
}
}
for _, r := range m.Resources {
if strings.Contains(r.Path, "test-runs-cap") {
return false
}
}
for key, kind := range want {
if m.Config[key]["type"] != kind {
return false
}
found := false
for _, r := range m.Resources {
found = found || (r.Type == "file" && r.Content == "${config:"+key+"}" && env[r.Path])
}
if !found {
return false
}
}
return true
}