Files
mesh-catalog/modules/mesh-build-node/cmd/mesh-build-node/steps_test.go
T
jschoubben 4ad5f40817 BLD7, BLD8: the Node and image build seats serve the verb steps
Node answers the type-check as lint always, unit where a package has a test
script and integration where it has test:integration, kept in detected-steps by
fingerprint as the Go module keeps it; the image answers none. The manifests
serve it. The step ask's end (step-ended) of BLD7 and BLD8 waits for BLD3 and
the build-step package of mesh-delivery-sdk.

Builds: design 47 G §22, §307, §326, §328

Claude-Session: https://claude.ai/code/session_01JG73KEq4zoDfM9WtYpcQgZ
2026-11-11 11:06:40 +01:00

54 lines
1.9 KiB
Go

package main
import (
"context"
"os"
"path/filepath"
"reflect"
"testing"
)
// Design 47 G §22, §307, §328 (BLD7): steps answers the type-check as lint always, the packages with a test script as
// unit, those with test:integration as integration, and leaves out a level with none.
func TestTheStepsOfATypeScriptArtifactAreFoundByItsScripts(t *testing.T) {
put := func(dir, name, body string) {
if err := os.MkdirAll(filepath.Join(dir), 0o755); err != nil {
t.Fatal(err)
}
if err := os.WriteFile(filepath.Join(dir, name), []byte(body), 0o644); err != nil {
t.Fatal(err)
}
}
for name, c := range map[string]struct {
pkg string
want []DetectedStep
}{
"both levels": {`{"scripts":{"test":"node t.js","test:integration":"node i.js"}}`,
[]DetectedStep{{Step: "lint"}, {Step: "unit", Packages: []string{"."}}, {Step: "integration", Packages: []string{"."}}}},
"unit only": {`{"scripts":{"test":"node t.js"}}`, []DetectedStep{{Step: "lint"}, {Step: "unit", Packages: []string{"."}}}},
"no script": {`{"scripts":{}}`, []DetectedStep{{Step: "lint"}}},
} {
dir := t.TempDir()
put(dir, "package.json", c.pkg)
got, err := detectSteps(dir)
if err != nil || !reflect.DeepEqual(got, c.want) {
t.Errorf("%s: steps = %+v (%v), want %+v", name, got, err, c.want)
}
}
}
// The verb is served beside the seat's others and refuses an ask that names no artifact.
func TestTheStepsVerbIsServedAndRefusesAnAskWithoutAnArtifact(t *testing.T) {
m, _, _ := newMachine(t)
served := false
for _, tool := range m.SeatTools(m.Puller(nil, nil)) {
served = served || tool.Name == Seat+".steps"
}
if !served {
t.Fatal("the module serves no verb steps")
}
if _, err := m.steps(context.Background(), map[string]any{"module": "m", "fetch": map[string]any{"repository": "novox/m", "commit": "0123456789abcdef0123456789abcdef01234567"}}); err == nil {
t.Error("an ask with no artifact was answered")
}
}