Files
pipelines/internal/pipeline/chat_shown_run_map_test.go
T
alan 7872e57d40 Run card mini-map and stage strip; graph edge hover highlight
The show_run card carries the run's graph and per-stage progress (bounded by
the graph, not the run length) and draws a still mini-map with the run graph
plus a stage strip with status, visits and time. Hovering or tapping an edge
in the pipeline and run graphs highlights it, its label and endpoints, with a
tooltip naming from -> to, the outcome and, for runs, how often it was taken.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 12:56:51 +00:00

81 lines
2.8 KiB
Go

package pipeline
import (
"context"
"path/filepath"
"strings"
"testing"
)
func TestRunShownMapCompactsVisitsAndTotalsStages(t *testing.T) {
ctx := context.Background()
store, err := Open(filepath.Join(t.TempDir(), "map.db"))
if err != nil {
t.Fatal(err)
}
defer store.Close()
if _, err := store.Submit(ctx, "graph", Template([]string{"a", "b", "c"}, true)); err != nil {
t.Fatal(err)
}
pipelines, _ := store.List(ctx)
definition, _ := store.Get(ctx, pipelines[0].ID, 1)
id, _, err := store.CreateRun(ctx, definition, "map", "workspace", false, nil, nil)
if err != nil {
t.Fatal(err)
}
// a → b loops back to a 20 times, then b → c, and c is still running.
type step struct{ stage, status, outcome, target, started, finished string }
var steps []step
for i := 0; i < 20; i++ {
steps = append(steps,
step{"a", "completed", "success", "b", "2026-12-01 10:00:00", "2026-12-01 10:00:10"},
step{"b", "completed", "retry", "a", "2026-12-01 10:00:10", "2026-12-01 10:00:15"})
}
steps = append(steps,
step{"a", "completed", "success", "b", "2026-12-01 10:00:00", "2026-12-01 10:00:10"},
step{"b", "completed", "success", "c", "2026-12-01 10:00:10", "2026-12-01 10:00:15"},
step{"c", "running", "", "", "2026-12-01 10:05:00", ""})
tx, err := store.db.BeginTx(ctx, nil)
if err != nil {
t.Fatal(err)
}
for i, s := range steps {
var finished any
if s.finished != "" {
finished = s.finished
}
if _, err := tx.ExecContext(ctx, `INSERT INTO run_steps(run_id,sequence,stage_key,status,outcome,target,input_json,output_json,diagnostic,transcript,started_at,finished_at)
VALUES(?,?,?,?,?,?,'{}','{}','PRIVATE','PRIVATE',?,?)`, id, i+1, s.stage, s.status, s.outcome, s.target, s.started, finished); err != nil {
t.Fatal(err)
}
}
if err := tx.Commit(); err != nil {
t.Fatal(err)
}
got, err := store.RunShownMap(ctx, id)
if err != nil || got == nil {
t.Fatalf("map = %+v, %v", got, err)
}
if len(got.Stages) != 3 || got.Stages[0].Key != "a" || got.Stages[0].Edges["success"] != "b" {
t.Fatalf("stages = %+v", got.Stages)
}
a, b, c := got.Stages[0], got.Stages[1], got.Stages[2]
if a.Visits != 21 || a.Seconds != 210 || a.Status != "completed" || a.RunningSince != 0 {
t.Fatalf("stage a = %+v", a)
}
if b.Visits != 21 || b.Seconds != 105 {
t.Fatalf("stage b = %+v", b)
}
if c.Visits != 1 || c.Status != "running" || c.Seconds != 0 || c.RunningSince == 0 {
t.Fatalf("stage c = %+v", c)
}
// Bounded by the graph: the latest visit of each stage and of each route.
var routes []string
for _, visit := range got.Visits {
routes = append(routes, visit.Stage+">"+visit.Outcome+">"+visit.Target)
}
if want := "b>retry>a a>success>b b>success>c c>>"; strings.Join(routes, " ") != want {
t.Fatalf("visits = %q, want %q", strings.Join(routes, " "), want)
}
}