Render run list miniatures from compact per-stage route evidence

This commit is contained in:
2026-10-20 18:21:24 +01:00
parent 855de19a35
commit 34939edd0e
14 changed files with 501 additions and 40 deletions
+11
View File
@@ -543,6 +543,17 @@ rapid changes are coalesced to at most a few frames per second per run.
once-per-second poll: the Android app consumes these pushes instead, while the
TUI still polls in this release.
Run-list summaries and subscribe snapshots additionally carry compact
`graph_evidence: {complete: true, visits: [...]}`. Each visit contains only
`sequence`, `stage`, `status`, `outcome` and `target`: the last visit of each
stage and each distinct taken route, ordered by sequence. Repeated loops do not
grow the summary indefinitely, and private step inputs, outputs, transcripts
and diagnostics are excluded from this projection. Live `run_event.graph_visits`
preserves changed visits across coalescing (unlike the single latest `step`).
Clients merge these by sequence and retain last-stage/distinct-route evidence.
Missing evidence from an older peer means unknown, not that every stage shares
the overall run result. These fields are additive; older peers ignore them.
In the run inspector, `n`/`p` select the next/previous recorded execution visit,
including repeated visits in loops, from any pane. Selection stops at the last
visit or overview; it does not wrap. The selected stage has a full-row highlight;
@@ -0,0 +1,121 @@
package pipeline
import (
"context"
"database/sql"
"encoding/json"
"fmt"
"path/filepath"
"strings"
"testing"
)
type graphQueryCounter struct {
*sql.DB
calls int
}
func (q *graphQueryCounter) QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error) {
q.calls++
if len(args) > 100 {
return nil, fmt.Errorf("unbounded batch: %d", len(args))
}
for _, private := range []string{"input_json", "output_json", "transcript", "diagnostic", "session_id"} {
if strings.Contains(query, private) {
return nil, fmt.Errorf("private projection: %s", private)
}
}
return q.DB.QueryContext(ctx, query, args...)
}
func TestRunGraphEvidenceBatchesCompactsAndReopens(t *testing.T) {
ctx := context.Background()
path := filepath.Join(t.TempDir(), "evidence.db")
store, err := Open(path)
if err != nil {
t.Fatal(err)
}
defer func() { store.Close() }()
if _, err := store.Submit(ctx, "graph", Template([]string{"a", "b", "c", "never"}, true)); err != nil {
t.Fatal(err)
}
pipelines, _ := store.List(ctx)
definition, _ := store.Get(ctx, pipelines[0].ID, 1)
var first int64
// Cross two batch boundaries, retaining the complete empty evidence of queued
// runs. A single connection also catches accidental nested detail reads.
store.db.SetMaxOpenConns(1)
for i := 0; i < 205; i++ {
id, _, err := store.CreateRun(ctx, definition, fmt.Sprintf("graph-%d", i), "workspace", false, nil, nil)
if err != nil {
t.Fatal(err)
}
if i == 0 {
first = id
}
}
tx, err := store.db.BeginTx(ctx, nil)
if err != nil {
t.Fatal(err)
}
for sequence := 1; sequence <= 200; sequence++ {
stage, status, outcome, target := "a", "completed", "success", "b"
if sequence == 198 {
stage, target = "b", "c"
}
if sequence == 199 {
stage, outcome, target = "c", "retry", "a"
}
if sequence == 200 {
status, outcome, target = "failed", "", ""
}
_, err := tx.ExecContext(ctx, `INSERT INTO run_steps(run_id,sequence,stage_key,status,outcome,target,input_json,output_json,diagnostic,transcript) VALUES(?,?,?,?,?,?,'{"secret":"PRIVATE-INPUT"}','{}','PRIVATE-DIAGNOSTIC','PRIVATE-TRANSCRIPT')`, first, sequence, stage, status, outcome, target)
if err != nil {
t.Fatal(err)
}
}
if err := tx.Commit(); err != nil {
t.Fatal(err)
}
// No new table or column migration is required: projection works after an
// existing database is closed and reopened, including historical rows.
if err := store.Close(); err != nil {
t.Fatal(err)
}
store, err = Open(path)
if err != nil {
t.Fatal(err)
}
runs, err := store.ListRuns(ctx)
if err != nil {
t.Fatal(err)
}
if len(runs) != 205 {
t.Fatal(len(runs))
}
counter := &graphQueryCounter{DB: store.db}
if err := loadRunGraphEvidence(ctx, counter, runs); err != nil {
t.Fatal(err)
}
if counter.calls != 3 {
t.Fatalf("graph projection made %d queries for 205 runs; want 3, not N+1", counter.calls)
}
for _, run := range runs {
if run.GraphEvidence == nil || !run.GraphEvidence.Complete {
t.Fatalf("missing complete evidence: %+v", run)
}
if run.ID != first && len(run.GraphEvidence.Visits) != 0 {
t.Fatal("fabricated queued visit")
}
if run.ID == first {
visits := run.GraphEvidence.Visits
if len(visits) != 4 || visits[0].Sequence != 197 || visits[3].Sequence != 200 || visits[3].Status != "failed" {
t.Fatalf("lost latest stage or loop routes: %+v", visits)
}
encoded, _ := json.Marshal(run.GraphEvidence)
if strings.Contains(string(encoded), "PRIVATE") || strings.Contains(string(encoded), "input") || strings.Contains(string(encoded), "diagnostic") {
t.Fatal(string(encoded))
}
}
}
}
+67 -2
View File
@@ -6,6 +6,7 @@ import (
"database/sql"
"encoding/json"
"fmt"
"strings"
"git.a-wan.net/alan/pipelines/internal/protocol"
)
@@ -43,7 +44,12 @@ func scanRun(row interface{ Scan(...any) error }, r *protocol.RunSummary) error
}
func (s *Store) ListRuns(ctx context.Context) ([]protocol.RunSummary, error) {
rows, err := s.db.QueryContext(ctx, runSelect+" ORDER BY r.id DESC")
tx, err := s.db.BeginTx(ctx, &sql.TxOptions{ReadOnly: true})
if err != nil {
return nil, err
}
defer tx.Rollback()
rows, err := tx.QueryContext(ctx, runSelect+" ORDER BY r.id DESC")
if err != nil {
return nil, err
}
@@ -56,7 +62,66 @@ func (s *Store) ListRuns(ctx context.Context) ([]protocol.RunSummary, error) {
}
items = append(items, r)
}
return items, rows.Err()
if err := rows.Err(); err != nil {
return nil, err
}
if err := rows.Close(); err != nil {
return nil, err
}
if err := loadRunGraphEvidence(ctx, tx, items); err != nil {
return nil, err
}
if err := tx.Commit(); err != nil {
return nil, err
}
return items, nil
}
// One projection query per bounded batch, not a GetRun per row. Window ranks
// collapse arbitrarily long loops while preserving every distinct taken route
// and the last status of each stage. Only the five public graph facts are read.
type runGraphQuerier interface {
QueryContext(context.Context, string, ...any) (*sql.Rows, error)
}
func loadRunGraphEvidence(ctx context.Context, tx runGraphQuerier, runs []protocol.RunSummary) error {
const batchSize = 100
for start := 0; start < len(runs); start += batchSize {
end := min(start+batchSize, len(runs))
args := make([]any, 0, end-start)
byID := make(map[int64]*protocol.RunGraphEvidence, end-start)
for i := start; i < end; i++ {
evidence := &protocol.RunGraphEvidence{Complete: true, Visits: []protocol.RunGraphVisit{}}
runs[i].GraphEvidence = evidence
byID[runs[i].ID] = evidence
args = append(args, runs[i].ID)
}
rows, err := tx.QueryContext(ctx, `WITH visits AS (
SELECT run_id,sequence,stage_key,status,outcome,target,
ROW_NUMBER() OVER (PARTITION BY run_id,stage_key ORDER BY sequence DESC) AS stage_rank,
ROW_NUMBER() OVER (PARTITION BY run_id,stage_key,outcome,target ORDER BY sequence DESC) AS route_rank
FROM run_steps WHERE run_id IN (`+strings.TrimSuffix(strings.Repeat("?,", len(args)), ",")+`))
SELECT run_id,sequence,stage_key,status,outcome,target FROM visits
WHERE stage_rank=1 OR (route_rank=1 AND outcome<>'' AND target<>'') ORDER BY run_id,sequence`, args...)
if err != nil {
return err
}
for rows.Next() {
var id int64
var visit protocol.RunGraphVisit
if err := rows.Scan(&id, &visit.Sequence, &visit.Stage, &visit.Status, &visit.Outcome, &visit.Target); err != nil {
rows.Close()
return err
}
byID[id].Visits = append(byID[id].Visits, visit)
}
err = rows.Err()
rows.Close()
if err != nil {
return err
}
}
return nil
}
func (s *Store) RunByKey(ctx context.Context, key string) (int64, error) {
+9 -4
View File
@@ -15,7 +15,8 @@ const (
// RunEventFrame is the server-pushed run_event delta. It carries only the values
// that changed, never the whole run: the run's identity, status, outcome, current
// stage, completed-step count and timestamps, plus at most one changed step.
// stage, completed-step count and timestamps, plus the latest changed step and
// compact routing facts for all changed visits preserved during coalescing.
// Every field is optional so an older peer ignores what it does not know and a
// client can fold the frame into its cached run.
//
@@ -24,9 +25,13 @@ const (
// from the frame instead of re-reading the whole list. They repeat on every
// frame (pipeline identity never changes mid-run).
type RunEventFrame struct {
NotifyMode string `json:"notify_mode,omitempty"`
RunID int64 `json:"run_id"`
Workspace string `json:"workspace,omitempty"`
// GraphEvidence seeds a complete compact snapshot; GraphVisits preserves
// changed visits even when Step is replaced during frame coalescing.
GraphEvidence *RunGraphEvidence `json:"graph_evidence,omitempty"`
GraphVisits []RunGraphVisit `json:"graph_visits,omitempty"`
NotifyMode string `json:"notify_mode,omitempty"`
RunID int64 `json:"run_id"`
Workspace string `json:"workspace,omitempty"`
// PipelineID, Name, Title and Version identify the run's pipeline and its
// operator-facing title, so a new run's row can be built without a fetch.
PipelineID int64 `json:"pipeline_id,omitempty"`
+21 -4
View File
@@ -134,10 +134,11 @@ type SessionExportRecovery struct {
}
type RunSummary struct {
NotifyMode string `json:"notify_mode,omitempty"`
ID int64 `json:"id"`
PipelineID int64 `json:"pipeline_id"`
Name string `json:"name"`
GraphEvidence *RunGraphEvidence `json:"graph_evidence,omitempty"`
NotifyMode string `json:"notify_mode,omitempty"`
ID int64 `json:"id"`
PipelineID int64 `json:"pipeline_id"`
Name string `json:"name"`
// Title is the operator-facing, bounded single-line description of what the
// run is for, generated from its prompt. It is never empty for a new run;
// historical rows predating the title column may omit it.
@@ -165,6 +166,22 @@ type RunSummary struct {
OutputFormat string `json:"output_format,omitempty"`
}
// RunGraphVisit contains only routing and lifecycle facts, never private step
// inputs, outputs, diagnostics, sessions or transcripts. Repeated loop visits
// are compacted to the latest stage visit and the latest visit of each route.
type RunGraphVisit struct {
Sequence int `json:"sequence"`
Stage string `json:"stage"`
Status string `json:"status"`
Outcome string `json:"outcome"`
Target string `json:"target"`
}
type RunGraphEvidence struct {
Complete bool `json:"complete"`
Visits []RunGraphVisit `json:"visits"`
}
// Label is the operator-facing name of a run: the generated Title when the
// server stored one, otherwise the pipeline Name (historical rows predate
// titles). It is the single definition shared by the CLI and TUI.
+79
View File
@@ -0,0 +1,79 @@
package server
import (
"context"
"encoding/json"
"git.a-wan.net/alan/pipelines/internal/protocol"
"strings"
"testing"
"time"
)
func TestGraphEvidenceSubscribeSnapshot(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
defer cancel()
store, handler, ids := eventStore(t, ctx, "a", "b", "c")
definition, err := store.Get(ctx, ids[0], 1)
if err != nil {
t.Fatal(err)
}
id, _, err := store.CreateRun(ctx, definition, "graph-snapshot", "workspace", false, nil, nil)
if err != nil {
t.Fatal(err)
}
for index, key := range []string{"a", "b", "c"} {
sequence := index + 1
if err := store.BeginStep(ctx, id, sequence, key, map[string]any{"prompt": "PRIVATE-PROMPT"}); err != nil {
t.Fatal(err)
}
status, outcome, target := "completed", "success", "b"
if key == "b" {
target = "c"
}
if key == "c" {
status, outcome, target = "failed", "", ""
}
if err := store.FinishStep(ctx, id, protocol.RunStep{Sequence: sequence, Status: status, Outcome: outcome, Target: target, Transcript: "PRIVATE-TRANSCRIPT"}); err != nil {
t.Fatal(err)
}
}
hub := newRunEventHub()
defer hub.unsubscribeClient("snapshot-test")
var messages []protocol.Message
if !handleRunEvents(protocol.Message{Type: protocol.Subscribe}, hub, handler.runner, "snapshot-test", func(message protocol.Message) error { messages = append(messages, message); return nil }) {
t.Fatal("unhandled subscribe")
}
if len(messages) != 2 || messages[0].RunEvent == nil || messages[1].Type != protocol.Subscribe {
t.Fatalf("snapshot/ack: %+v", messages)
}
evidence := messages[0].RunEvent.GraphEvidence
if evidence == nil || !evidence.Complete || len(evidence.Visits) != 3 || evidence.Visits[2].Status != "failed" {
t.Fatalf("missing persisted graph evidence: %+v", evidence)
}
encoded, _ := json.Marshal(messages[0])
if strings.Contains(string(encoded), "PRIVATE") {
t.Fatal(string(encoded))
}
}
func TestCoalescedGraphVisitsRetainEveryStage(t *testing.T) {
hub := newRunEventHub()
hub.interval = time.Hour
sub := hub.subscribe("graph-test", "", nil, func(protocol.Message) error { return nil })
defer sub.close()
// Hold subsequent frames in the coalescer without relying on wall-clock races.
hub.emit(protocol.RunEventFrame{RunID: 1, Status: "running"}, false)
for sequence, stage := range []string{"a", "b", "c"} {
hub.emit(protocol.RunEventFrame{RunID: 1, Step: &protocol.RunStepDelta{Sequence: sequence + 1, Stage: stage, Status: "completed", Outcome: "success", Target: "next", Diagnostic: "PRIVATE"}}, false)
}
hub.mu.Lock()
pending := hub.runs[1].pending
hub.stopTimerLocked(hub.runs[1])
hub.mu.Unlock()
if pending == nil || len(pending.GraphVisits) != 3 || pending.Step.Stage != "c" {
t.Fatalf("coalescing lost evidence: %+v", pending)
}
if pending.GraphVisits[0].Stage != "a" || pending.GraphVisits[1].Stage != "b" {
t.Fatal(pending.GraphVisits)
}
}
+5
View File
@@ -173,6 +173,9 @@ func (h *runEventHub) remove(sub *runSubscription) {
// A terminal transition flushes any pending delta first, then the terminal frame
// immediately, so a client always observes the final state as its own frame.
func (h *runEventHub) emit(frame protocol.RunEventFrame, terminal bool) {
if step := frame.Step; step != nil {
frame.GraphVisits = append(frame.GraphVisits, protocol.RunGraphVisit{Sequence: step.Sequence, Stage: step.Stage, Status: step.Status, Outcome: step.Outcome, Target: step.Target})
}
if h == nil || frame.RunID <= 0 {
return
}
@@ -470,6 +473,7 @@ func mergeRunEventFrame(into, in *protocol.RunEventFrame) {
if in.Step != nil {
into.Step = in.Step
}
into.GraphVisits = append(into.GraphVisits, in.GraphVisits...)
}
// handleRunEvents dispatches one subscribe/unsubscribe request and reports
@@ -505,6 +509,7 @@ func handleRunEvents(request protocol.Message, events *runEventHub, runs *runner
continue
}
frame := protocol.RunEventFrame{
GraphEvidence: summary.GraphEvidence,
NotifyMode: summary.NotifyMode,
RunID: summary.ID,
Workspace: summary.Workspace,
+16 -7
View File
@@ -11,18 +11,27 @@ Status legend: `todo` · `partial` (some of it works) · `done` (working + captu
### List miniature follow-up (2026-10-20)
Workflow and run miniatures now share the existing graph layout, right-aligned
inside their SVG as well as their row, with a 6px extra trailing inset. Runs use
the shared status palette; recorded visits/routes override the aggregate tint,
and known untaken branches are hollow/dashed. With summaries only, the tint is
the **run status**, not a claim that every stage executed. Topology comes from
inside their SVG as well as their row, with a 6px extra trailing inset. Run LIST
nodes now use each stage's last visit: success green, failure red, running
accent, waiting amber and queued a distinct muted tint. Unvisited/unknown nodes
are neutral hollow/dashed; **no aggregate run-status tint is inherited**.
Taken edges use recorded outcome/target routes, including loops and branches.
The additive `graph_evidence` summary projection reads only five routing/status
fields from `run_steps`, compacts repeated loops, and batches 100 run IDs per
query (not N detail fetches). Subscribe snapshots seed the same evidence;
coalesced live frames preserve every changed visit in `graph_visits` and the
client maintains last-stage/distinct-route evidence without a detail fetch.
Older summaries remain honestly unknown. Topology comes from
the run's own graph, an exact-version pipeline summary, or one cached
`get_pipeline(id, version)` read per endpoint/version (never `get_run` per row,
never a fallback to latest). Unavailable graphs stay absent. No server changes.
never a fallback to latest). Unavailable graphs stay absent. No schema migration
or new private input/output/transcript payload is needed.
Scratch browser extension `test/miniatures-browser.mjs` verifies 390/420/1100px
alignment, distinct status colors, wrapped titles, separate applied filters and
alignment, two successful stages before failure plus never-visited branches,
waiting/running/queued states, legacy unknown evidence, wrapped titles, separate applied filters and
no document overflow; captures and `geometry.json` are in
`/private/var/folders/jp/q0qvjyg54fl_c5vhhk1ylz2m0000gn/T/opencode/status-miniature-captures/`.
`/private/var/folders/jp/q0qvjyg54fl_c5vhhk1ylz2m0000gn/T/opencode/per-stage-run-miniatures-captures/`.
These are deterministic fixture captures, not a new live-server parity claim.
Collapsed desktop navigation additionally gives Expand its own 40px flow slot
+1 -1
View File
@@ -435,7 +435,7 @@
.pipeline-mini-node { fill: currentColor; opacity: 0.55; }
.run-mini .pipeline-mini-node { opacity: 0.85; }
.run-mini .pipeline-mini-edge { opacity: 0.8; }
.run-mini .mini-untaken { color: var(--muted); opacity: 0.4; stroke-dasharray: 2 2; }
.run-mini .mini-untaken { color: var(--color-muted); opacity: 0.4; stroke-dasharray: 2 2; }
.run-mini .pipeline-mini-node.mini-untaken { fill: none; stroke: currentColor; stroke-width: 1; }
.row.selected .pipeline-mini { color: var(--color-accent); }
.row:hover .pipeline-mini { color: var(--color-text); }
+14 -7
View File
@@ -10,6 +10,8 @@ const NS = "http://www.w3.org/2000/svg";
const STATUSES = new Set(["succeeded", "failed", "running", "waiting", "queued",
"interrupted", "canceled", "blocked", "skipped"]);
export function miniatureColor(status) {
if (status === "waiting") return "var(--warn)";
if (status === "running") return "var(--accent)";
return `var(--status-${STATUSES.has(status) ? status : "unknown"})`;
}
@@ -20,20 +22,22 @@ export function miniatureModel(graph, run = null) {
edges: Object.fromEntries(Object.entries(stage.edges ?? {}).filter(([, target]) => keys.has(target))),
})) };
const layout = layoutGraph(shape, METRICS);
const evidence = run && Array.isArray(run.steps) ? runGraphState(run) : null;
const visits = new Map((run?.steps ?? []).map((step) => [step.stage, step]));
const steps = Array.isArray(run?.steps) ? run.steps : run?.graph_evidence?.visits;
const evidence = Array.isArray(steps) ? runGraphState({ ...run, steps }) : null;
const visits = new Map((steps ?? []).map((step) => [step.stage, step]));
return { ...layout, evidence: evidence != null,
complete: Array.isArray(run?.steps) || run?.graph_evidence?.complete === true,
nodes: layout.nodes.map((node) => {
const step = visits.get(node.key);
// A recorded current stage is evidence even in a compact list summary.
const current = run?.executing && run.current_stage === node.key;
const status = current ? run.status : step?.status;
const status = step?.status ?? (current ? run.status : null);
const color = status === "completed" ? edgeStrokeColor(step.outcome) : status ? miniatureColor(status) : null;
return { ...node, color,
untaken: evidence != null && !step && !current };
untaken: Boolean(run) && !step && !current };
}),
edges: layout.edges.map((edge) => ({ ...edge,
untaken: evidence != null && !edgeIsExecuted(edge, evidence),
untaken: Boolean(run) && (!evidence || !edgeIsExecuted(edge, evidence)),
color: evidence && edgeIsExecuted(edge, evidence) ? edgeStrokeColor(edge.outcome) : null,
})),
};
@@ -53,6 +57,7 @@ export function renderMiniGraph(graph, run = null) {
if (edge.points.length < 2) continue;
const line = document.createElementNS(NS, "polyline");
line.setAttribute("class", `pipeline-mini-edge${edge.untaken ? " mini-untaken" : ""}`);
line.setAttribute("data-route", `${edge.source}:${edge.outcome}:${edge.target}`);
line.setAttribute("points", edge.points.map((p) => `${p.x},${p.y}`).join(" "));
if (edge.color) line.style.color = edge.color;
svg.append(line);
@@ -60,14 +65,16 @@ export function renderMiniGraph(graph, run = null) {
for (const node of model.nodes) {
const rect = document.createElementNS(NS, "rect");
rect.setAttribute("class", `pipeline-mini-node${node.untaken ? " mini-untaken" : ""}`);
rect.setAttribute("data-stage", node.key);
for (const key of ["x", "y", "width", "height"]) rect.setAttribute(key, String(node[key]));
rect.setAttribute("rx", "3");
if (node.color) rect.style.color = node.color;
svg.append(rect);
}
const wrap = h("span", { class: `pipeline-mini${run ? " run-mini" : ""}`,
"aria-hidden": "true", "data-evidence": model.evidence ? "visits" : "summary" }, svg);
if (run) wrap.style.color = miniatureColor(run.status);
"aria-hidden": "true", "data-evidence": model.evidence ? model.complete ? "visits" : "partial" : "unknown" }, svg);
// Unknown/unvisited graph elements must never inherit the aggregate result.
if (run) wrap.style.color = "var(--color-muted)";
return wrap;
}
+32 -1
View File
@@ -215,7 +215,10 @@ function applyRunStateFields(current, frame) {
cancel_requested: before.cancel_requested || frame.cancel_requested === true,
cleanup_unconfirmed: before.cleanup_unconfirmed || frame.cleanup_unconfirmed === true,
};
// Detail already maintains full visits below; compact evidence is list-only.
const graphEvidence = Array.isArray(current.steps) ? current.graph_evidence : mergeGraphEvidence(current.graph_evidence, frame);
const changed =
graphEvidence !== current.graph_evidence ||
merged.notify_mode !== before.notify_mode ||
!sameResourceWait(merged.resource_wait, before.resource_wait) ||
merged.status !== before.status ||
@@ -227,7 +230,33 @@ function applyRunStateFields(current, frame) {
merged.executing !== before.executing ||
merged.cancel_requested !== before.cancel_requested ||
merged.cleanup_unconfirmed !== before.cleanup_unconfirmed;
return changed ? { ...current, ...merged } : current;
return changed ? { ...current, ...merged, ...(graphEvidence ? { graph_evidence: graphEvidence } : {}) } : current;
}
// Reuse the detail's monotonic visit merge, then compact by last stage visit and
// distinct route. Keep completeness separate: a delta from an older server or
// a mid-run first frame cannot prove that earlier stages were never visited.
function mergeGraphEvidence(current, frame) {
if (!frame.graph_evidence && !frame.graph_visits?.length && !frame.step) return current;
let visits = current?.visits ?? [];
const incoming = [...(frame.graph_evidence?.visits ?? []), ...(frame.graph_visits ?? []),
...(frame.step ? [frame.step] : [])];
for (const step of incoming) {
const { sequence, stage, status, outcome, target } = step;
visits = upsertStep(visits, { sequence, stage, status, outcome, target });
}
const latest = new Map();
const routes = new Map();
for (const visit of visits) {
latest.set(visit.stage, visit.sequence);
if (visit.outcome && visit.target) routes.set(JSON.stringify([visit.stage, visit.outcome, visit.target]), visit.sequence);
}
visits = visits.filter((visit) => latest.get(visit.stage) === visit.sequence ||
(visit.outcome && visit.target && routes.get(JSON.stringify([visit.stage, visit.outcome, visit.target])) === visit.sequence));
// Explicit allowlist: graph evidence never copies diagnostic/private fields.
visits = visits.map(({ sequence, stage, status, outcome, target }) => ({ sequence, stage, status, outcome, target }));
const result = { complete: Boolean(current?.complete || frame.graph_evidence?.complete), visits };
return JSON.stringify(result) === JSON.stringify(current) ? current : result;
}
/**
@@ -240,7 +269,9 @@ export function newRunSummaryFromFrame(frame) {
const pipelineId = Number(frame?.pipeline_id);
const name = String(frame?.name ?? "");
if (!(pipelineId > 0) || blank(name)) return null;
const graphEvidence = mergeGraphEvidence(null, frame);
return {
...(graphEvidence ? { graph_evidence: graphEvidence } : {}),
resource_wait: frame.resource_wait ?? null,
id: Number(frame.run_id),
pipeline_id: pipelineId,
+35
View File
@@ -0,0 +1,35 @@
import { test } from "node:test";
import assert from "node:assert/strict";
import { foldRunEvent } from "../src/runEvents.js";
import { miniatureModel } from "../src/miniGraph.js";
test("coalesced live visits update list nodes and routes without a detail fetch", () => {
const identity = { run_id: 1, pipeline_id: 7, name: "Run", version: 2 };
let runs = foldRunEvent([], { ...identity, status: "running", graph_evidence: { complete: true, visits: [] } }).runs;
const visits = [
{ sequence: 1, stage: "a", status: "completed", outcome: "success", target: "b" },
{ sequence: 2, stage: "b", status: "completed", outcome: "success", target: "c" },
{ sequence: 3, stage: "c", status: "running", diagnostic: "PRIVATE" },
];
runs = foldRunEvent(runs, { ...identity, status: "running", current_stage: "c", graph_visits: visits, step: visits[2] }).runs;
runs = foldRunEvent(runs, { ...identity, status: "failed", step: { sequence: 3, stage: "c", status: "failed" } }).runs;
const model = miniatureModel({ stages: [
{ key: "a", edges: { success: "b", error: "never" } },
{ key: "b", edges: { success: "c" } }, { key: "c", edges: {} }, { key: "never", edges: {} },
] }, runs[0]);
assert.deepEqual(model.nodes.map((n) => n.color), ["var(--ok)", "var(--ok)", "var(--status-failed)", null]);
assert.equal(model.edges.filter((e) => !e.untaken).length, 2);
assert.equal(JSON.stringify(runs[0].graph_evidence).includes("PRIVATE"), false);
const same = foldRunEvent(runs, { ...identity, status: "running", graph_visits: visits }).runs;
assert.equal(same, runs);
});
test("partial legacy deltas do not manufacture complete history; loops compact", () => {
let runs = [{ id: 1, status: "running" }];
for (let sequence = 1; sequence <= 100; sequence++) {
runs = foldRunEvent(runs, { run_id: 1, step: { sequence, stage: "a", status: "completed", outcome: "success", target: "a" } }).runs;
}
assert.equal(runs[0].graph_evidence.complete, false);
assert.equal(runs[0].graph_evidence.visits.length, 1);
assert.equal(runs[0].graph_evidence.visits[0].sequence, 100);
});
+29 -3
View File
@@ -12,18 +12,44 @@ test("miniatures retain real stage routes, without terminals or fabricated visit
assert.deepEqual(model.nodes.map((n) => n.key).sort(), ["a", "b", "c"]);
assert.equal(model.edges.length, 2);
assert.equal(model.evidence, false);
assert.ok(model.nodes.every((n) => n.color === null && !n.untaken));
assert.ok(model.nodes.every((n) => n.color === null && n.untaken));
});
test("compact list evidence preserves successes before failure and last loop status", () => {
const loopGraph = { stages: [
{ key: "a", edges: { success: "b", error: "never" } },
{ key: "b", edges: { success: "c" } },
{ key: "c", edges: { retry: "a", error: "never" } },
{ key: "never", edges: {} },
] };
const visits = [
{ sequence: 1, stage: "a", status: "completed", outcome: "success", target: "b" },
{ sequence: 2, stage: "b", status: "completed", outcome: "success", target: "c" },
{ sequence: 3, stage: "c", status: "completed", outcome: "retry", target: "a" },
{ sequence: 4, stage: "a", status: "failed", outcome: "", target: "" },
];
const model = miniatureModel(loopGraph, { status: "failed", graph_evidence: { complete: true, visits } });
assert.equal(model.nodes.find((n) => n.key === "a").color, "var(--status-failed)");
assert.equal(model.nodes.find((n) => n.key === "b").color, "var(--ok)");
assert.equal(model.nodes.find((n) => n.key === "never").color, null);
assert.equal(model.nodes.find((n) => n.key === "never").untaken, true);
assert.equal(model.edges.filter((e) => !e.untaken).length, 3);
assert.ok(model.edges.filter((e) => e.outcome === "error").every((e) => e.untaken));
for (const status of ["waiting", "running", "queued"]) {
const next = miniatureModel(loopGraph, { status, current_stage: "a", executing: status !== "waiting",
graph_evidence: { complete: true, visits: [...visits.slice(0, 3), { sequence: 4, stage: "a", status }] } });
assert.equal(next.nodes.find((n) => n.key === "a").color, miniatureColor(status));
}
});
test("visited stages/routes use evidence; unvisited branches remain hollow", () => {
const model = miniatureModel(graph, { status: "waiting", executing: true, current_stage: "b",
steps: [{ stage: "a", status: "completed", outcome: "success", target: "b" }] });
assert.equal(model.nodes.find((n) => n.key === "a").color, "var(--ok)");
assert.equal(model.nodes.find((n) => n.key === "b").color, "var(--status-waiting)");
assert.equal(model.nodes.find((n) => n.key === "b").color, "var(--warn)");
assert.equal(model.nodes.find((n) => n.key === "c").untaken, true);
assert.equal(model.edges.find((e) => e.outcome === "success").color, "var(--ok)");
assert.equal(model.edges.find((e) => e.outcome === "error").untaken, true);
for (const status of ["succeeded", "failed", "running", "waiting", "interrupted", "queued", "canceled"]) {
assert.equal(miniatureColor(status), `var(--status-${status})`);
assert.equal(miniatureColor(status), status === "waiting" ? "var(--warn)" : status === "running" ? "var(--accent)" : `var(--status-${status})`);
}
});
test("cache deduplicates pinned reads, rejects latest mismatches and scopes by endpoint", async () => {
+61 -11
View File
@@ -62,17 +62,22 @@ try {
const graph = { stages: [{ key:'plan', edges:{success:'build',error:'reject'} },
{key:'build',edges:{success:'finish'}},{key:'reject',edges:{error:'#failure'}},
{key:'finish',edges:{success:'#success'}}] };
const statuses = ['succeeded','failed','running','interrupted','waiting','queued'];
const statuses = ['succeeded','failed','running','interrupted','waiting','queued','failed'];
const visits = (status) => status === 'queued' ? [] : [
{sequence:1,stage:'plan',status:'completed',outcome:'success',target:'build'},
{sequence:2,stage:'build',status:'completed',outcome:'success',target:'finish'},
{sequence:3,stage:'finish',status:status==='succeeded'?'completed':status,
outcome:status==='succeeded'?'success':'',target:status==='succeeded'?'#success':''}];
const state = { view:'runs', url:'scratch', loading:false, selectedRunId:1,
openMenu:null, runFilters:{...defaultRunFilters(),pipelineId:7}, runSort:'server_order',
pipelineFilters:{...EMPTY_PIPELINE_FILTERS},pipelineSort:'server_order', pipelinesLoaded:true,
runsLoaded:true, pipelines:[{id:7,name:'Pinned workflow',version:3,stages:4,shape:graph}],
runs:statuses.map((status,i)=>({id:i+1,pipeline_id:7,version:2,name:'Pinned workflow',
title:'A wrapped run title that preserves the complete task context across narrow screens '+status,
status,executing:['running','waiting'].includes(status),current_stage:'build',
created_at:new Date().toISOString(),steps:i===0?[
{stage:'plan',status:'completed',outcome:'success',target:'build'},
{stage:'build',status:'completed',outcome:'success',target:'finish'}]:undefined})) };
status,executing:['running','queued'].includes(status),current_stage:status==='queued'?'plan':'finish',
completed_steps:status==='queued'||i===6?0:status==='succeeded'?3:2,
created_at:new Date().toISOString(),
...(i===6?{current_stage:'',executing:false}:{graph_evidence:{complete:true,visits:visits(status)}})})) };
let runs, pipelines;
const renderContent=()=>document.querySelector('#content').replaceChildren(
state.view==='runs'?runs.renderRunList():pipelines.renderPipelineList());
@@ -93,9 +98,13 @@ try {
rows:rows.map(row=>{const mini=row.querySelector('.pipeline-mini');const r=row.getBoundingClientRect();
const m=mini.getBoundingClientRect();const svg=mini.querySelector('svg');const node=svg.querySelector('rect');
const status=row.querySelector('.status-icon')?.dataset.status;
const swatch=document.createElement('span');swatch.style.color='var(--status-'+status+')';mini.append(swatch);
const swatch=document.createElement('span');swatch.style.color=status==='waiting'?'var(--warn)':status==='running'?'var(--accent)':'var(--status-'+status+')';mini.append(swatch);
const expectedColor=getComputedStyle(swatch).color;swatch.remove();
return {inset:r.right-m.right,align:svg.getAttribute('preserveAspectRatio'),status,expectedColor,
const nodes=[...svg.querySelectorAll('rect')].map(n=>({stage:n.dataset.stage,
color:getComputedStyle(n).color,fill:getComputedStyle(n).fill,untaken:n.classList.contains('mini-untaken')}));
const edges=[...svg.querySelectorAll('polyline')].map(n=>({route:n.dataset.route,
color:getComputedStyle(n).color,untaken:n.classList.contains('mini-untaken')}));
return {id:Number(row.dataset.runId),nodes,edges,evidence:mini.dataset.evidence,inset:r.right-m.right,align:svg.getAttribute('preserveAspectRatio'),status,expectedColor,
color:getComputedStyle(mini).color,nodeColor:getComputedStyle(node).color,
right:m.right,rowRight:r.right, rowWidth:r.width,parentWidth:row.parentElement.clientWidth,
selected:row.classList.contains('selected')};}),
@@ -109,19 +118,60 @@ try {
if (view === 'runs') {
assert.equal(geometry.titleWrap, true);
assert.equal(geometry.filterSeparate, true);
assert.notEqual(geometry.rows[0].color, geometry.rows[1].color);
assert.notEqual(geometry.rows[2].color, geometry.rows[4].color);
assert.ok(geometry.rows.every((row)=>row.color===row.expectedColor));
const node=(row,stage)=>row.nodes.find(n=>n.stage===stage);
const byId=(id)=>geometry.rows.find(row=>row.id===id);
const failed=byId(2);
assert.equal(node(failed,'plan').color,node(failed,'build').color);
assert.notEqual(node(failed,'build').color,node(failed,'finish').color);
assert.equal(node(failed,'finish').color,failed.expectedColor);
assert.equal(node(failed,'reject').fill,'none');
assert.equal(node(failed,'reject').untaken,true);
assert.equal(failed.edges.filter(e=>!e.untaken).length,2);
assert.ok(failed.edges.filter(e=>e.route.includes(':error:')).every(e=>e.untaken));
assert.equal(byId(7).evidence,'unknown');
assert.ok(byId(7).nodes.every(n=>n.untaken && n.fill==='none'));
for (const row of geometry.rows.filter(row=>row.id!==7)) {
assert.equal(row.evidence,'visits');
if (['running','waiting','queued'].includes(row.status)) {
assert.equal(node(row,row.status==='queued'?'plan':'finish').color,row.expectedColor);
}
}
assert.notEqual(node(byId(3),'finish').color,node(byId(5),'finish').color);
const selected=geometry.rows.find(row=>row.selected);
assert.equal(selected.rowWidth,selected.parentWidth);
}
results.push({view,...geometry});
await page.screenshot(resolve(out, `${view}-${width}.png`));
if (view === 'runs') {
await page.evaluate(`document.querySelector('.run-row[data-run-id="1"]').scrollIntoView({block:'end'})`);
await page.evaluate(`document.querySelector('.run-row[data-run-id="2"]').scrollIntoView({block:'center'})`);
await page.screenshot(resolve(out, `runs-evidence-${width}.png`));
}
}
for (const status of ['waiting','failed']) {
await page.evaluate(`(async () => {
const {foldRunEvent}=await import('/src/runEvents.js');
window.beforeLiveRuns??=fixtureState.runs;
fixtureState.view='runs';
fixtureState.runs=foldRunEvent(fixtureState.runs,{run_id:3,status:${JSON.stringify(status)},
current_stage:'finish',step:{sequence:3,stage:'finish',status:${JSON.stringify(status)}}}).runs;
paintFixture();
document.querySelector('.run-row[data-run-id="3"]').scrollIntoView({block:'center'});
})()`);
const live = await page.evaluate(`(() => {
const mini=document.querySelector('.run-row[data-run-id="3"] .run-mini');
const nodes=[...mini.querySelectorAll('rect')];
return {colors:nodes.map(n=>getComputedStyle(n).color),
taken:mini.querySelectorAll('polyline:not(.mini-untaken)').length,
unknown:mini.querySelectorAll('rect.mini-untaken').length};
})()`);
assert.equal(live.colors[0],live.colors[1]);
assert.equal(live.taken,2);
assert.equal(live.unknown,1);
assert.notEqual(live.colors[0],live.colors[3]);
await page.screenshot(resolve(out, `runs-live-${status}-${width}.png`));
results.push({view:'live-'+status,width,...live});
}
await page.evaluate(`fixtureState.runs=beforeLiveRuns;beforeLiveRuns=null;paintFixture()`);
}
await writeFile(resolve(out, 'geometry.json'), JSON.stringify(results,null,2));
await page.close();