Files
mesh-catalog/modules/mesh-build-node/cmd/mesh-build-node/steps_test.go
T
jschoubben 247c422fbf BG9, BN9, BI3: the build seats' steps with drop writes the hand-act log first
A drop of a kept detected-steps key records the act with the caller the bus proved, then deletes the key; a log that
refuses deletes nothing and is answered error; a drop without why is refused; fetch is asked unless drop.

Builds: design 47 G §463, §480

Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h
2026-11-12 04:56:25 +01:00

80 lines
3.2 KiB
Go

package main
import (
"context"
"errors"
"os"
"path/filepath"
"reflect"
"strings"
"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")
}
}
// Design 47 G §463, §480 (BN9): steps with drop writes the hand-act log first, then deletes the key; a log that
// refuses deletes nothing; a drop without why is refused.
func TestTheStepsDropWritesTheHandActLogFirst(t *testing.T) {
var order []string
m := &Module{
ForgetDetected: func(key string) error { order = append(order, "delete "+key); return nil },
RecordAct: func(what, why string) error { order = append(order, "log "+why); return nil },
}
args := map[string]any{"module": "mod", "artifact": "mod:web", "drop": true, "why": "stale"}
got, err := m.dropDetected(args, "shanks.person")
if a, _ := got.(StepsAnswer); err != nil || a.Dropped != "mod:web" || !reflect.DeepEqual(order, []string{"log stale", "delete mod.web"}) {
t.Fatalf("drop = %+v, %v, order %v", got, err, order)
}
if _, err := m.dropDetected(map[string]any{"module": "mod", "artifact": "mod:web", "drop": true}, "shanks.person"); err == nil {
t.Error("a drop without why was taken")
}
order = nil
m.RecordAct = func(string, string) error { return errors.New("log down") }
got, err = m.dropDetected(args, "shanks.person")
if a, _ := got.(StepsAnswer); err != nil || !strings.Contains(a.Error, "hand-act log") || len(order) != 0 {
t.Fatalf("a refusing log: %+v, %v, order %v", got, err, order)
}
}