Files
cad-atlas/internal/atlas/model.go
T
mathiasandClaude Opus 4.8 a9c72d6ca8
CD / Detect unsubstituted template (push) Successful in 0s
CD / Lint / Test / Vet (push) Successful in 5s
CD / Build & Import (push) Successful in 14s
CD / Deploy via GitOps (push) Successful in 1s
feat(atlas): Phase B — data-driven /api/atlas.json, CI stage generated from cd.yml
The atlas no longer hand-maintains its content. Authored data lives in one place
(internal/atlas/atlas.json); the Go layer overlays sourced facts and serves the
result at /api/atlas.json; the frontend fetches + renders (inline arrays kept only
as an offline fallback). First generated source: the CI/CD stage's nodes are parsed
from the repo's own .gitea/workflows/cd.yml — so the viz shows the pipeline that
actually runs (guard/check/build/deploy), dropping the aspirational var-go/oath-gate
node that isn't wired yet. That's the point: it can't drift from the real pipeline.

New internal/atlas package (JobsFromWorkflow, Build) built test-first. Adds
gopkg.in/yaml.v3 (justified: parsing the workflow YAML; stdlib has no YAML).

Verified: go build/vet/lint(0)/test green; /api/atlas.json → 9 stages, CI = real
jobs; frontend renders from the fetch (screenshot).

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

67 lines
1.8 KiB
Go

package atlas
import (
"encoding/json"
"fmt"
)
// Host is a substrate machine/entry (koala, iguana, …).
type Host struct {
Name string `json:"n"`
Spec string `json:"k"`
}
// Node is a card within a stage.
type Node struct {
Title string `json:"t"`
Desc string `json:"d,omitempty"`
Pill string `json:"pill,omitempty"`
Cls string `json:"cls,omitempty"`
Tags []string `json:"tags,omitempty"`
Risk bool `json:"risk,omitempty"`
Gate bool `json:"gate,omitempty"`
}
// Stage is one column of the pipeline. When Generate is set, its Nodes are
// derived from a source at Build time rather than taken from the authored data.
type Stage struct {
No string `json:"no"`
Title string `json:"title"`
Path string `json:"path,omitempty"`
Cls string `json:"cls,omitempty"`
Generate string `json:"generate,omitempty"`
Nodes []Node `json:"nodes"`
}
// Atlas is the full data model the frontend renders.
type Atlas struct {
Substrate []Host `json:"substrate"`
NS string `json:"ns,omitempty"`
Stages []Stage `json:"stages"`
}
// Build unmarshals the authored atlas JSON and overlays generated facts from
// real sources, so sourced parts can't drift. Currently: any stage marked
// `"generate":"ci-jobs"` gets its Nodes replaced by the workflow's job list.
func Build(atlasJSON, workflow []byte) (Atlas, error) {
var a Atlas
if err := json.Unmarshal(atlasJSON, &a); err != nil {
return Atlas{}, fmt.Errorf("parse atlas data: %w", err)
}
for i := range a.Stages {
if a.Stages[i].Generate != "ci-jobs" {
continue
}
jobs, err := JobsFromWorkflow(workflow)
if err != nil {
return Atlas{}, fmt.Errorf("stage %s: %w", a.Stages[i].No, err)
}
nodes := make([]Node, 0, len(jobs))
for _, j := range jobs {
nodes = append(nodes, Node{Title: j})
}
a.Stages[i].Nodes = nodes
}
return a, nil
}