Files
mathias 6967d12d1d
CD / Detect unsubstituted template (push) Successful in 1s
CD / Lint / Test / Vet (push) Successful in 6s
CD / var-go/oath (push) Has been skipped
CD / Build & Import (push) Successful in 18s
CD / Deploy via GitOps (push) Has been skipped
feat(atlas): weight replay pacing on CI/CD stages by real job durations (#5)
TDD: Job.Seconds() + StageSeconds() derive real CI/CD dwell time from the
latest run's per-job created_at/updated_at (last job in pipeline order =
deploy/stage 07, everything before it = CI/stage 06).

Frontend: weightedSpineDist() redistributes the pixel-time-budget the
06/07 segments already had, splitting it by real CI:CD duration ratio
instead of raw pixel width. Falls back to the exact prior constant-speed
sweep when no run data is available (weights default to segment pixel
length) or when a job is skipped (0 duration) — no behavior change for
stages 00-05/08, which still have no live timing source (same gap as #5's
ledger item).

Verified: real duration values flow through /api/atlas.json (ci_duration_s:
18 observed against a real run), full page screenshot confirms no visual
regression.
2026-07-20 23:22:53 +02:00

83 lines
2.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. Plain is the jargon-free default text; Desc is
// the technical detail shown on demand.
type Node struct {
Title string `json:"t"`
PlainTitle string `json:"plain_t,omitempty"`
Plain string `json:"plain,omitempty"`
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"`
URL string `json:"url,omitempty"`
}
// Stage is one column of the pipeline. PlainTitle/Plain are the plain-language
// default layer; Title/Path/Nodes[].Desc are the technical layer. TransLabel/
// Trans annotate the outgoing transition (the arrow to the next stage): what
// moves work forward and what must be true to advance. When Generate is set,
// Nodes are derived from a live source at Build time.
type Stage struct {
No string `json:"no"`
Short string `json:"short,omitempty"`
Title string `json:"title"`
PlainTitle string `json:"plain_title,omitempty"`
Plain string `json:"plain,omitempty"`
Path string `json:"path,omitempty"`
Cls string `json:"cls,omitempty"`
Generate string `json:"generate,omitempty"`
TransLabel string `json:"trans_label,omitempty"`
Trans string `json:"trans,omitempty"`
Nodes []Node `json:"nodes"`
}
// Atlas is the full data model the frontend renders.
type Atlas struct {
Version string `json:"version,omitempty"`
Substrate []Host `json:"substrate"`
NS string `json:"ns,omitempty"`
Timeline []RunDot `json:"timeline,omitempty"`
CIDurationS float64 `json:"ci_duration_s,omitempty"`
CDDurationS float64 `json:"cd_duration_s,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 || len(jobs) == 0 {
continue // no CI job list available — keep the authored plain placeholder
}
nodes := make([]Node, 0, len(jobs))
for _, j := range jobs {
nodes = append(nodes, Node{Title: j, Plain: "An automated check that must pass."})
}
a.Stages[i].Nodes = nodes
}
return a, nil
}