Files
mesh-catalog/modules/mesh-build-node/cmd/mesh-build-node/kit_test.go
T
jschoubben 1697b7041c BM4: each build module keeps a run's test output in its outputs objects
The Go build module's level answers its text in output (test2json's Output
lines), the Node build module's what its commands wrote; the delivery SDK's step
run keeps it as <node>.<ask> in the module's outputs objects, which each module
asks for in requires (1 GiB, kept 7 days) and reads through the verb output at
form 2. Each module's kit test runs the SDK's SeatVerbs.

Builds: design 47 H2 §791, §820; H-A-412 (1), H-A-412 second addendum (a), H-A-421, H-A-434
2026-11-22 01:32:40 +01:00

118 lines
5.1 KiB
Go

package main
import (
"context"
"encoding/json"
"errors"
"os"
"path/filepath"
"strings"
"testing"
"time"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/steprun"
"git.novox.be/novox/mesh-sdk/go/buscalls"
buildrun "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildrun"
sdkstep "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/steprun/conformance"
"git.novox.be/novox/mesh-sdk/go/forgekey"
)
// 1901/AC7: the module's own parse path (testFailures, as the test step calls it on a command that failed) keeps the
// failure contract on every captured node --test and tsc case of the SDK's conformance kit.
func TestTheTestStepKeepsTheFailureContract(t *testing.T) {
conformance.Run(t, conformance.NodeTest, func(o conformance.Output) []sdkstep.Failure {
return testFailures(".", "test", o.Dir, forgekey.Ran{Status: 1, Stdout: o.Stdout, Stderr: o.Stderr}, o.Report)
})
conformance.Run(t, conformance.TypeCheck, func(o conformance.Output) []sdkstep.Failure {
return testFailures(".", "type-check", o.Dir, forgekey.Ran{Status: 2, Stdout: o.Stdout, Stderr: o.Stderr}, "")
})
}
// 1890/AC7: the module's own start sweep (endLeftRunning, as main runs it) keeps the conformance kit's left-running
// case: a step a previous process left running is ended at once and said, whatever its age, and a step of this process
// is kept.
func TestTheStartSweepEndsWhatAPreviousProcessLeft(t *testing.T) {
conformance.LeftRunning(t, func(ctx context.Context, scan buildrun.Scan, node string, before time.Time, logf func(string, ...any)) {
(&Module{Node: node}).endLeftRunning(ctx, scan, before, logf)
})
}
// ADR 0664 §1 (issue 1748): the module's own paths from a failed fetch or install to its step's error say a network that did
// not answer as a transport fault, and a failure of the source (a package the registry lacks) as none.
func TestTheStepsSayAFailedNetworkAsATransportFault(t *testing.T) {
// A step whose fetch or publish met its holder away is given again after the module's again-delays, 15 s after its
// first run and 60 s after its second by default (design 47 H2 §799; H-A-390).
t.Run("again-delays is declared and read", func(t *testing.T) {
raw, err := os.ReadFile(filepath.Join("..", "..", "module.json"))
if err != nil {
t.Fatal(err)
}
var m struct {
Config map[string]json.RawMessage `json:"config"`
}
if err := json.Unmarshal(raw, &m); err != nil {
t.Fatal(err)
}
var c struct {
Default string `json:"default"`
Runtime bool `json:"runtime"`
}
decl, ok := m.Config[steprun.AgainDelaysSetting]
_ = json.Unmarshal(decl, &c)
delay, err := steprun.AgainDelays(c.Default)
if !ok || !c.Runtime || err != nil || delay(1) != 15*time.Second || delay(2) != 60*time.Second {
t.Fatalf("again-delays declared %v as %+v: %v", ok, c, err)
}
})
conformance.Passing(t, []string{conformance.GitFetch, conformance.NpmCI}, func(runner, words string) error {
switch runner {
case conformance.GitFetch:
run := func(context.Context, []string, string, ...string) forgekey.Ran {
return forgekey.Ran{Status: 128, Stderr: words}
}
return steprun.FetchCommit(context.Background(), run, t.TempDir(), "ssh://mesh-forge/o/r.git", strings.Repeat("a", 40), "")
default:
bad := &fakeNpm{ran: forgekey.Ran{Status: 1, Stderr: words}}
return toolchainIn(t, bad).Ensure(context.Background(), Recipe{Steps: "k", Lock: "k"}.Version())
}
})
}
// A-489b, design 47 G §24: the module's own steps can say a pipeline step's end, or
// every step ask the runner sends it is refused ("this build module says no step's end"), as the first live pipeline met.
func TestTheStepsCanSayAStepsEnd(t *testing.T) {
conformance.StepEnds(t, (&Module{Node: "kitnode"}).askSteps(nil))
// Design 47 H2 §791, §801, H-A-412, H-A-421: the seat's verbs current, output and answer keep the build-step part's form 2,
// and a pipeline step's run output is kept in the module's outputs objects and read back through output.
m := &Module{Node: "kitnode", Capacity: func() int { return 1 }, Outputs: kitObjects{}}
conformance.SeatVerbs(t, Seat, m.SeatTools(m.Puller(nil, steprun.NewFakeAsks())), m.askSteps(nil))
}
// kitObjects is an outputs store in memory, for the kit's SeatVerbs.
type kitObjects map[string][]byte
func (k kitObjects) Put(name string, data []byte, _ string) (buscalls.ObjectInfo, error) {
k[name] = data
return buscalls.ObjectInfo{Name: name}, nil
}
func (k kitObjects) Get(name string) (buscalls.ObjectData, error) {
d, ok := k[name]
if !ok {
return buscalls.ObjectData{}, errors.New("object not found")
}
return buscalls.ObjectData{Data: d}, nil
}
// A-489c (A-489a): the module's puller counts the runs its steps state says started, not the bus's deliveries (an ask given back before
// it ran is no run), so the poison rule never ends an ask that never ran.
func TestThePullerCountsRunsThatStarted(t *testing.T) {
conformance.RunsCounted(t, func(read func(string) (json.RawMessage, error)) *steprun.Puller {
m := &Module{Node: "kitnode", Capacity: func() int { return 1 }}
m.ReadSteps = StateRead{Get: read}
return m.Puller(nil, steprun.NewFakeAsks())
})
}