Files
mesh-catalog/modules/mesh-build-node/cmd/mesh-build-node/asks_say_test.go
T
jschoubben 09f66c5f5c N2: a build reports every module or package it resolved, with no prefix or scope (issue 721)
Mesh Go modules come from the seat go-package-registry, not the forge, so no
prefix or scope tells a mesh package apart. ModuleImports reports the module
path of every package the build resolved but the standard library's and the
module's own, and build_node_imports every npm package the bundles reach but
Node's own modules. The settings import-prefix and import-scope leave both
manifests and the ask.

Builds: design 47 H2 H-A-539 (withdraws H-A-534's form check and H-A-535)
2026-11-23 11:28:27 +01:00

75 lines
3.0 KiB
Go

package main
import (
"context"
"errors"
"slices"
"testing"
nodebuildgo "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/nodebuildgo"
sdkstep "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/steprun"
)
// Design 47 G §496, §602 (BG4, BN4, BI4): the module's puller says the seat's events on this node's subjects.
func TestPullerSaysTheSeatsEventsOnItsNodesSubject(t *testing.T) {
var subjects []string
m := &Module{Node: "ace", Capacity: func() int { return 0 },
SayEvent: func(subject string, _ any, _ string) error { subjects = append(subjects, subject); return nil }}
p := m.Puller(nil, steprun.NewFakeAsks())
if p.Say == nil {
t.Fatal("the puller says no event")
}
seat, _ := sdkstep.BuildSeat(sdkstep.AskNode)
for _, event := range []string{"ask-taken", "step-progress", "step-ended"} {
if err := p.Say(event, nil, "id"); err != nil {
t.Fatal(err)
}
}
for i, event := range []string{"ask-taken", "step-progress", "step-ended"} {
if want := "mesh.seat." + seat + ".event." + event + ".ace"; subjects[i] != want {
t.Errorf("%s said on %s, want %s", event, subjects[i], want)
}
}
}
// N1/AC1, N1/AC3 (design 47 H2 H-A-517, H-A-523, H-A-534): a done build of a TypeScript module says one imports-reported
// on the Node build seat's subject of the node, naming the mesh npm packages the imports step read; a failed build says
// none.
func TestADoneNodeBuildSaysItsImportSetAndAFailedOneNone(t *testing.T) {
var said []nodebuildgo.ImportsReported
var subjects []string
m := moduleWith(newStates(), "v26.10.0")
m.Outputs = kitObjects{} // a failed build keeps its error text as an output object, never on a bus here
m.SayEvent = func(subject string, body any, _ string) error {
subjects = append(subjects, subject)
said = append(said, body.(nodebuildgo.ImportsReported))
return nil
}
steps := append(fakeSteps(new([]string)), StepTool{Name: ImportsTool, Run: func(context.Context, map[string]any) (any, error) {
return ImportsResult{Imports: []string{"@novox/mesh-sdk"}}, nil
}})
a := nodeAsk(sdkstep.AskDelivery)
a.Build.Fp = "src2:0456"
if _, err := steprun.RunAsk(context.Background(), m.askSteps(steps), a); err != nil {
t.Fatal(err)
}
want := "mesh.seat.node-build-node.event.imports-reported.ace"
if len(said) != 1 || subjects[0] != want || said[0].Module != "gitea" || said[0].Fingerprint != "src2:0456" ||
said[0].Commit != askCommit || !slices.Equal(said[0].Imports, []string{"@novox/mesh-sdk"}) {
t.Fatalf("said %v on %v, want one imports-reported of gitea naming @novox/mesh-sdk on %s", said, subjects, want)
}
said = nil
for i := range steps {
if steps[i].Name == "build_node_build" {
steps[i].Run = func(context.Context, map[string]any) (any, error) { return nil, errors.New("tsc failed") }
}
}
if _, err := steprun.RunAsk(context.Background(), m.askSteps(steps), a); err == nil {
t.Fatal("the failed build passed")
}
if len(said) != 0 {
t.Errorf("a failed build said %v", said)
}
}