126 lines
5.2 KiB
Go
126 lines
5.2 KiB
Go
package pipeline_test
|
|
|
|
import (
|
|
"encoding/json"
|
|
"os"
|
|
"slices"
|
|
"testing"
|
|
|
|
seat "git.novox.be/novox/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{}
|
|
for _, s := range m.State {
|
|
states = append(states, s.Name)
|
|
keyTTL[s.Name] = s.KeyTTL
|
|
}
|
|
for _, s := range m.Streams {
|
|
streams = append(streams, s.Name)
|
|
}
|
|
for _, o := range m.Objects {
|
|
objects = append(objects, o.Name)
|
|
}
|
|
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", "bounds", "toolchains", "findings", "first-views"})},
|
|
// §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"]},
|
|
// §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},
|
|
{"finding stream 7 days 16 MiB", len(m.Streams) == 1 && m.Streams[0].MaxAgeDays == 7 && m.Streams[0].MaxMiB == 16 &&
|
|
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"},
|
|
{"old objects section", equalSets(objects, []string{seat.StateStepOutputs})},
|
|
{"step-outputs 1 GiB", len(m.Objects) == 1 && m.Objects[0].MaxMiB == 1024},
|
|
// §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", "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", "mesh-wants.step-ended", "mesh-catalog.registration-changed",
|
|
"mesh-catalog.catalog-revision", "mesh-conditions.findings-asked"})},
|
|
// 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", "seat:mesh-catalog.revision", "seat:mesh-hand-acts.hand-act",
|
|
// RN3 (§53, §334): a publication's dependents behind.
|
|
"seat:mesh-catalog.outdated",
|
|
// 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"})},
|
|
{"uses operator-channel", equalSets(m.Uses, []string{"operator-channel"})},
|
|
{"first-view tools", equalSets(m.Tools, []string{"pipeline_first_views", "pipeline_first_view_again"})},
|
|
// 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("../../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)
|
|
}
|
|
}
|
|
}
|
|
|
|
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)
|
|
}
|