Files
mesh-catalog/modules/mesh-build-node/cmd/mesh-build-node/kit_test.go
T
jschoubben 804f5c4ab4 failurekit: G8 kit-checked, a build module whose tests do not run the reproducible case is refused
Every build module claiming a node-build-* seat must hold a test that calls
conformance.Reproducible; mesh-build-node's tests now run it over its bundle
build, as mesh-build-go's and mesh-build-image's do. A row of the check's test
(a module with the rest of the kit and no reproducible case) is refused.

Builds: design 47 H2 H-A-591 (4), H-A-593 (3)
2026-11-25 17:39:00 +01:00

139 lines
6.2 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 90 s after its second by default, a span past the tool runner's restart (design 47 H2 §799; H-A-390, H-A-603).
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) != 90*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())
})
}
// H-A-591 (4), H-A-593 (3): the kit's `reproducible` case. The module's own build step packs a fixture bundle twice, in two
// workspace folders of other names and other file times (the compiler and the bundler stand in, as in every build test of this
// module, and write what they would from the same source), and the archive's digest is the same: nothing of the folder or
// the clock is in the pack.
func TestTheBuildOfABundleIsOneDigestInAnyFolder(t *testing.T) {
conformance.Reproducible(t, func(dir string) error {
workspaceWith(t, dir, map[string]string{"modules/m/module.json": strings.Replace(bundleManifest, "%s", "", 1),
"modules/m/tools/index.ts": "export {}"})
return nil
}, func(dir string) (map[string]string, error) {
m, f, _ := newMachine(t)
m.Work = dir
f.effect = esbuildEffect(t)
out, err := m.build(context.Background(), buildArgs())
if err != nil {
return nil, err
}
return map[string]string{"tools": out.(BuildResult).Digest}, nil
})
}