Files
cad-atlas/internal/atlas/build_test.go
T
mathiasandClaude Opus 4.8 ac086b65b9
CD / Detect unsubstituted template (push) Successful in 0s
CD / Lint / Test / Vet (push) Successful in 4s
CD / Build & Import (push) Successful in 14s
CD / Deploy via GitOps (push) Has been skipped
fix(atlas): UX polish — stage-06 plain nodes + shorter arrow labels (#7)
Stage 06 no longer renders bare in Plain: Build is now tolerant of a jobless/
absent workflow (keeps an authored plain placeholder instead of erroring), and
generated CI job nodes carry a plain hint. Shortened the two overlong transition
labels ("Order written, sealed, agent-ready" → "Sealed & agent-ready",
"Agents produced a change" → "Change proposed") so they stop clipping.

Build tolerance test-first. build/vet/lint(0)/test green; screenshot-verified.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-20 09:46:42 +02:00

86 lines
2.6 KiB
Go

package atlas_test
import (
"reflect"
"testing"
"git.d-ma.be/mathias/cad-atlas/internal/atlas"
)
func TestBuild_OverlaysCIStageNodesFromWorkflow(t *testing.T) {
atlasJSON := []byte(`{
"substrate": [{"n":"koala","k":"gpu"}],
"stages": [
{"no":"STAGE 06","title":"PR → CI","generate":"ci-jobs","nodes":[]},
{"no":"STAGE 01","title":"TELOS","nodes":[{"t":"Intention substrate"}]}
]}`)
workflow := []byte("jobs:\n check:\n a: 1\n build:\n b: 2\n deploy:\n c: 3\n")
a, err := atlas.Build(atlasJSON, workflow)
if err != nil {
t.Fatalf("Build: %v", err)
}
// CI stage nodes generated from the workflow's jobs, in order.
var titles []string
for _, n := range a.Stages[0].Nodes {
titles = append(titles, n.Title)
}
if want := []string{"check", "build", "deploy"}; !reflect.DeepEqual(titles, want) {
t.Fatalf("CI stage nodes = %v, want %v", titles, want)
}
// Non-generated stage is untouched.
if a.Stages[1].Nodes[0].Title != "Intention substrate" {
t.Fatalf("authored stage was altered: %+v", a.Stages[1])
}
// Substrate preserved.
if len(a.Substrate) != 1 || a.Substrate[0].Name != "koala" {
t.Fatalf("substrate not preserved: %+v", a.Substrate)
}
}
func TestDefault_HasPlainLayerAndTransitions(t *testing.T) {
a, err := atlas.Build(atlas.DataJSON, []byte("jobs:\n guard:\n a: 1\n"))
if err != nil {
t.Fatalf("Build embedded atlas: %v", err)
}
for _, s := range a.Stages {
if s.PlainTitle == "" {
t.Fatalf("stage %s missing plain_title", s.No)
}
if s.TransLabel == "" {
t.Fatalf("stage %s missing trans_label", s.No)
}
if s.Generate == "ci-jobs" {
continue // nodes are generated live, no authored plain
}
for _, n := range s.Nodes {
if n.Plain == "" {
t.Fatalf("stage %s node %q missing plain", s.No, n.Title)
}
}
}
}
func TestBuild_KeepsCIPlaceholderWhenNoJobs(t *testing.T) {
atlasJSON := []byte(`{"substrate":[],"stages":[
{"no":"STAGE 06","title":"PR → CI","generate":"ci-jobs","nodes":[{"t":"Automated checks","plain":"checks run here"}]}
]}`)
// A workflow with no jobs block must NOT error and must keep the placeholder.
a, err := atlas.Build(atlasJSON, []byte("name: cd\n"))
if err != nil {
t.Fatalf("Build should tolerate a no-jobs workflow, got: %v", err)
}
if len(a.Stages[0].Nodes) != 1 || a.Stages[0].Nodes[0].Title != "Automated checks" {
t.Fatalf("placeholder not kept: %+v", a.Stages[0].Nodes)
}
}
func TestBuild_ErrorsOnBadAtlasJSON(t *testing.T) {
if _, err := atlas.Build([]byte("{not json"), []byte("jobs:\n x:\n a: 1\n")); err == nil {
t.Fatal("expected error on bad atlas JSON, got nil")
}
}