web: run detail Graph tab with executed styling and stage panes (R5)

Add the run detail's Graph tab (between Summary and Input), reusing the
shared src/graph.js renderer (P6) rather than a second renderer. In run
mode a visited stage is executed (solid fill + border), an unvisited one
hollow with a dashed muted border; a terminal is executed only when a
visit resolved to it; a route is executed only when a recorded visit
produced that outcome (solid with an arrowhead, success first, error
last, others alphabetical, `error*` for the fallback). The Executed /
Not executed legend shows only for a run. While the run executes the
current stage carries a pulsing halo (static under prefers-reduced-motion)
and a ticking elapsed badge; a finished run shows neither. Clicking a
stage opens the existing visit pane at that stage's latest visit, and
Back/Escape return focus. The empty state is the exact
"This server did not include the run graph."

extend src/graph.js with the run-mode inputs (runState-driven executed
styling, legend, active halo/elapsed badge); keep app.js to wiring.
Extend graph.test.mjs with focused run-mode unit tests and ui-smoke.mjs
with the run 438 / run 440 / live-run captures. Mark R5 done in
web/PARITY.md.

Checks: node --check on every touched file; cd web && node --test test/
(178 pass, 0 fail); cd web && node test/ui-smoke.mjs --out captures
(UI SMOKE PASS, captures 28-31).
This commit is contained in:
2026-10-19 04:05:37 +01:00
parent 2e9ff1704f
commit 94d4ff02d3
8 changed files with 569 additions and 32 deletions
+5 -4
View File
@@ -26,16 +26,16 @@ Status legend: `todo` · `partial` (some of it works) · `done` (working + captu
| P3 | Pipeline detail: stages, graph, versions, last run, content hash | `get_pipeline` | done — Summary/Graph/Source tabs; Summary shows content hash (monospace), latest version (`v{n}` or blank), created/updated, and a collapsed-by-default Versions section. Graph tab shows the browser guidance note plus the rendered workflow graph (P6) |
| P4 | Templates gallery + template detail | `list_templates`, `validate` | done |
| P5 | Create pipeline from a template (validate then submit) | `validate`, `submit` | todo |
| P6 | Workflow graph rendering (nodes, edges, stage panes) | `get_pipeline` | done (captured 2026-10-19: nodes + labelled outcome edges + success/failure terminals, an opened stage definition pane and the expanded view — `captures/08-pipeline-graph.png`, `captures/08a-pipeline-graph-stage-pane.png`, `captures/08b-pipeline-graph-expanded.png`). Reusable `src/graph.js` (`mount` + pure helpers: layout, edges, `error*`, lanes, fit/clamp/zoom, hit-test, stage-definition fields); definition view only, so R5's run-detail Graph tab stays todo. Pane labels match the app's own vocabulary (`Outcomes`, `Tools`) rather than the checklist's category words |
| P6 | Workflow graph rendering (nodes, edges, stage panes) | `get_pipeline` | done (captured 2026-10-19: nodes + labelled outcome edges + success/failure terminals, an opened stage definition pane and the expanded view — `captures/08-pipeline-graph.png`, `captures/08a-pipeline-graph-stage-pane.png`, `captures/08b-pipeline-graph-expanded.png`). Reusable `src/graph.js` (`mount` + pure helpers: layout, edges, `error*`, lanes, fit/clamp/zoom, hit-test, stage-definition fields); the definition view (every route executed, no legend) plus, since R5, a run-mode view driven by `runState` (executed/not-executed stages and routes, the Executed / Not executed legend, the live halo/elapsed badge). Pane labels match the app's own vocabulary (`Outcomes`, `Tools`) rather than the checklist's category words |
## Runs
| # | Feature | Protocol | Status |
| --- | --- | --- | --- |
| R1 | Run history list with status roll-up | `list_runs` | done |
| R2 | Filter by status, sort, "needs you" markers | client-side | partial (status/pipeline/time filter + sort implemented and captured; the per-row "needs you" mark has no Android counterpart and its wording is deferred to R15, still todo) |
| R3 | Run detail: run fields, steps/visits, targets, sessions | `get_run` | done — tabbed Summary / Input / Output / Timeline; the Timeline opens a per-visit stage pane with the headline rows (Status, Outcome, Duration, Visit `{v} / {max}`, Model target, Target, Session), the Verdict block (option chip + reason with inline artifact links) and the visit sections Artifacts / Session / Output / Input / This run / Stage definition. Captured 2026-10-19: `captures/20-run-430-summary.png`, `captures/23-run-430-timeline.png`, `captures/24-run-430-stage-artifacts.png`, `captures/25-run-440-verdict.png` |
| R3 | Run detail: run fields, steps/visits, targets, sessions | `get_run` | done — tabbed Summary / Graph / Input / Output / Timeline; the Timeline opens a per-visit stage pane with the headline rows (Status, Outcome, Duration, Visit `{v} / {max}`, Model target, Target, Session), the Verdict block (option chip + reason with inline artifact links) and the visit sections Artifacts / Session / Output / Input / This run / Stage definition. Captured 2026-10-19: `captures/20-run-430-summary.png`, `captures/23-run-430-timeline.png`, `captures/24-run-430-stage-artifacts.png`, `captures/25-run-440-verdict.png` |
| R4 | Summary tab incl. collapsible **Changes** viewer (raw + rendered diff) | `get_run` file changes | todo |
| R5 | Graph tab (per-stage panes, verdicts) | `get_run` | todo |
| R5 | Graph tab (per-stage panes, verdicts) | `get_run` | done — the run detail's Graph tab (between Summary and Input) mounts the shared `src/graph.js` renderer in run mode with the app's run note: a visited stage is executed (solid fill + border), an unvisited one hollow with a dashed muted border, a terminal executed only when a visit resolved to it, a route executed only when a visit produced that outcome (solid with an arrowhead; success first, error last, others alphabetical, `error*` for a fallback error route), the Executed / Not executed legend (runs only, never the definition view), and — while executing — the current stage's pulsing halo + elapsed badge (a static ring under `prefers-reduced-motion`; nothing for a finished run). Clicking a stage opens the existing visit pane at that stage's latest visit with its Verdict; Back/Escape close it and restore focus. The empty state is the exact `This server did not include the run graph.` (unit-tested; no live run currently carries a graph-less payload). Captured 2026-10-19: `captures/28-run-438-graph.png` (finished run 438: legend + executed styling + dashed untaken routes), `captures/29-run-438-graph-pane.png` (a graph-opened stage pane showing a Verdict), `captures/30-run-440-graph.png` (failed run 440: hollow/dashed not-executed stages) |
| R6 | Input / Output field sections per stage | `get_run` | done — one collapsed section per recorded entry, expanded as a monospace block (primitives verbatim, arrays `, `-joined, objects `k=v` `, `-joined), empty states "No input recorded." / "No output recorded.". Captured 2026-10-19: `captures/21-run-430-input.png`, `captures/22-run-430-output.png`, `captures/27-run-output-empty.png` |
| R7 | Timeline | `get_run` | done — one compact row per visit (`{stage} · visit {n}`, stage-outcome chip, paperclip when artifacts recorded, duration, description = first non-blank diagnostic line else `→ {target}`); empty state "No visits recorded.". Captured 2026-10-19: `captures/23-run-430-timeline.png`, `captures/26-run-428-timeline-empty.png` |
| R8 | Artifacts gallery + full-screen viewer (images inline, others download/open) | `GET /artifacts/…` | done (captured 2026-10-19: `captures/04-run-430-artifacts.png`, `captures/05-artifact-viewer.png`) |
@@ -52,7 +52,8 @@ choice: the visit's exported session is titled **Session** (the item text said
"Session export"; Android's `STAGE_SESSION_TITLE` is `Session`), and the step's
`session_id` renders as a **headline** row (Status, Outcome, Duration, Visit,
Model target, Target, Session), so it is not repeated in the "This run" evidence
section. R5 (Graph tab) deliberately leaves the tab's body unimplemented.
section. R5's Graph tab now renders that same shared graph in run mode (see the
row above), reusing the visit pane this section describes.
## Search
| # | Feature | Protocol | Status |
+69 -10
View File
@@ -24,6 +24,8 @@ import {
} from "./artifacts.js";
import {
PIPELINE_GRAPH_EMPTY,
RUN_GRAPH_MISSING,
RUN_GRAPH_NOTE,
mount as mountGraph,
} from "./graph.js";
import {
@@ -87,6 +89,7 @@ import {
runLabelFor,
runDurationText,
runTimeline,
runGraphState,
nodeLabel,
headlineFields,
runStepFields,
@@ -142,6 +145,10 @@ const state = {
// handle is dropped on every re-render so its listeners can never leak.
pipelineGraph: null,
pipelineGraphExpanded: false,
// The mounted run-mode graph (R5) on the run detail's Graph tab. Dropped on
// every re-render and on a run change, so its wheel/pointer/resize listeners
// and its elapsed timer can never leak.
runGraph: null,
versionsExpanded: false,
pipelinesLoaded: false,
runsLoaded: false,
@@ -268,6 +275,10 @@ function renderContent() {
state.pipelineGraph.unmount();
state.pipelineGraph = null;
}
if (state.runGraph) {
state.runGraph.unmount();
state.runGraph = null;
}
const nodes = [];
if (state.error) {
nodes.push(h("div", { class: "banner error" }, h("strong", { text: "Error: " }), state.error));
@@ -1081,12 +1092,13 @@ function closeMenu() {
}
/**
* The run detail: a tab strip (Summary / Input / Output / Timeline) over the
* selected tab's body, wired from the pure helpers in runDetail.js. Summary is
* the default and carries the run's identity, key/value rows and diagnostic;
* Input/Output are one collapsed section per recorded field; the Timeline is one
* compact row per visit that opens the stage pane. Every server string is set
* with textContent, never innerHTML.
* The run detail: a tab strip (Summary / Graph / Input / Output / Timeline) over
* the selected tab's body, wired from the pure helpers in runDetail.js. Summary
* is the default and carries the run's identity, key/value rows and diagnostic;
* the Graph tab mounts the shared workflow graph in run mode; Input/Output are
* one collapsed section per recorded field; the Timeline is one compact row per
* visit that opens the stage pane. Every server string is set with textContent,
* never innerHTML.
*/
function renderRunDetail() {
const d = state.runDetail;
@@ -1111,7 +1123,9 @@ function renderRunDetail() {
),
),
);
if (state.runTab === "input") {
if (state.runTab === "graph") {
pane.append(renderRunGraphTab(d));
} else if (state.runTab === "input") {
pane.append(renderRunFieldTab(d.input, "input", EMPTY_INPUT_MESSAGE));
} else if (state.runTab === "output") {
pane.append(renderRunFieldTab(d.output, "output", EMPTY_OUTPUT_MESSAGE));
@@ -1124,6 +1138,41 @@ function renderRunDetail() {
return pane;
}
/**
* The Graph tab (R5): the run's own guidance note plus the shared workflow graph
* mounted in run mode, or the app's exact missing-graph sentence when the server
* sent no stages. The active stage pulses with its elapsed time while the run
* executes; clicking a stage opens the existing visit pane at that stage's most
* recent visit. The mount handle is tracked in `state.runGraph` so a re-render
* (or a tab/run change) always unmounts the previous wheel/pointer/resize
* listeners and the elapsed timer.
*/
function renderRunGraphTab(d) {
const wrap = h("div", { class: "run-tab-body" });
const stages = d.graph?.stages ?? [];
if (!stages.length) {
wrap.append(h("div", { class: "run-empty muted", text: RUN_GRAPH_MISSING }));
return wrap;
}
wrap.append(h("p", { class: "graph-note muted", text: RUN_GRAPH_NOTE }));
const host = h("div", { class: "graph-host" });
wrap.append(host);
state.runGraph = mountGraph(host, d.graph, {
runState: runGraphState(d),
onStageTap: (key) => openStagePane(key, latestVisitIndex(d, key)),
});
return wrap;
}
/**
* The visit index the graph opens for a stage: its most recent recorded visit
* (`visits.size - 1`, never negative), exactly as RunGraphTab computes it.
*/
function latestVisitIndex(d, key) {
const visits = runTimeline(d.steps ?? []).visitsByStage.get(key) ?? [];
return Math.max(0, visits.length - 1);
}
/** The Summary tab: identity, chip row, key/value rows, diagnostic and gallery. */
function renderRunSummaryTab(d) {
const wrap = h("div", { class: "run-tab-body" });
@@ -1488,7 +1537,14 @@ function closeStagePane() {
const row = [...document.querySelectorAll(".timeline-row")].find(
(node) => node.dataset.stageKey === closing.stageKey && node.dataset.visitIndex === String(closing.visitIndex),
);
row?.focus();
// A pane opened from the Timeline returns to its row; one opened from the Graph
// returns to the stage node that opened it (there is no timeline row then).
const focusTarget =
row ??
[...document.querySelectorAll(".graph-node")].find(
(candidate) => candidate.dataset.key === closing.stageKey,
);
focusTarget?.focus();
}
/** Whether the configured server URL can resolve a server-relative artifact. */
@@ -1963,9 +2019,12 @@ async function selectPipeline(summary) {
async function selectRun(id, { silent = false } = {}) {
state.selectedRunId = id;
if (!silent) {
state.runDetail = null;
// A different run reseeds the detail: Summary tab, every section closed and
// no stage pane left over from the run the operator navigated away from.
// no stage pane left over from the run the operator navigated away from. Drop
// the mounted run graph first so a live run's timer can never outlive it.
state.runGraph?.unmount();
state.runGraph = null;
state.runDetail = null;
state.runTab = "summary";
state.runSections = new Set();
state.runStagePane = null;
+112 -9
View File
@@ -26,6 +26,7 @@
import { Protocol, isTerminal, resolveTarget } from "./protocol.js";
import { effectiveStageType } from "./templates.js";
import { formatDuration, secondsSince } from "./runs.js";
// Re-exported so a caller (and the unit tests) can reach the shared "blank is
// the model stage" rule from the graph module it belongs to without a second
@@ -61,6 +62,19 @@ const DRAG_THRESHOLD = 4;
/** The run tab's empty state when the server omitted the run graph (R5). */
export const RUN_GRAPH_MISSING = "This server did not include the run graph.";
/**
* The run tab's guidance note: the browser adaptation of RunGraphTab's own
* sentence, so the app's pinch/tap become mouse wheel/click while everything
* else (the live pulse, the settled finish, the executed/not-executed shapes)
* stays verbatim.
*/
export const RUN_GRAPH_NOTE =
"The running stage pulses with its elapsed time and executed routes flow; " +
"a finished run settles, and with animations off the running stage stays marked. " +
"Solid means executed, dashed and outlined not executed; executed success and " +
"failure routes are drawn thickest. Mouse wheel to zoom, drag to pan, " +
"click a stage for details.";
/**
* The pipeline detail's empty state when the parsed definition declares no
* stages. The template gallery has its own Android-authored analogue
@@ -203,6 +217,18 @@ export function edgeIsExecuted(edge, runState) {
return inSet(runState.takenRoutes, edge) || inSet(runState.takenRoutes, edge.id);
}
/**
* The key of the stage a run is executing right now, else null. Only a live run
* (still `executing`) has an active stage, so a finished run never carries a
* halo or an elapsed badge. Pure: drawing, the elapsed badge and the tests share
* one definition of "active".
*/
export function activeStage(runState) {
if (runState == null || !runState.executing) return null;
const key = runState.currentStage;
return key == null || key === "" ? null : key;
}
// ---------------------------------------------------------------------------
// Pure viewport maths (WorkflowGraph.kt)
// ---------------------------------------------------------------------------
@@ -895,19 +921,38 @@ function pathFromPoints(points) {
* space does nothing.
*
* Options:
* runState — omitted for the definition view (every route executed);
* R5 passes `{ visitedStages, takenRoutes }` to dash the
* routes a run did not take.
* runState — omitted for the definition view (every route executed and
* no legend); R5 passes the `runGraphState(run)` shape
* ({ visitedStages, takenRoutes, currentStage, executing,
* currentStageStartedAt }) to render the run: executed nodes
* solid, unvisited ones hollow/dashed, executed routes
* arrowed, the live stage's halo + elapsed badge and the
* Executed / Not executed legend.
* animationsEnabled — honour the caller's animation gate. Defaults to the
* page's `prefers-reduced-motion` setting; when false the
* active stage keeps a static ring instead of pulsing.
* expanded — start with the taller panel.
* onStageTap — called with the node key on a node click.
* onStageTap — called with the node key on a node click. When supplied
* (the run tab), the click opens the caller's own stage
* pane and no definition pane is drawn.
* onExpandedChange — called with the new expanded flag on toggle.
* metrics — layout metrics override (tests).
*
* Returns `{ unmount }`; call it before discarding the container so the wheel,
* pointer and resize listeners never leak.
* pointer, resize and elapsed-timer handles never leak.
*/
export function mount(container, graph, options = {}) {
const runState = options.runState ?? null;
const activeKey = activeStage(runState);
const reducedMotion =
typeof window !== "undefined" &&
typeof window.matchMedia === "function" &&
window.matchMedia("(prefers-reduced-motion: reduce)").matches;
// The caller may force animations off; otherwise the page's motion preference
// decides. A finished run never animates regardless (activeKey is null then).
const animationsEnabled =
options.animationsEnabled === undefined ? !reducedMotion : Boolean(options.animationsEnabled);
const pulse = activeKey != null && animationsEnabled;
const layout = layoutGraph(graph, options.metrics);
const stagesByKey = new Map((graph?.stages ?? []).map((stage) => [stage.key, stage]));
@@ -983,6 +1028,7 @@ export function mount(container, graph, options = {}) {
// Node layer: real buttons, positioned in graph space.
const nodeLayer = el("div", "graph-node-layer");
let elapsedBadge = null;
for (const node of layout.nodes) {
const kind = graphNodeKind(node.terminal, node.key, stagesByKey.get(node.key)?.type);
const button = el("button", `graph-node ${nodeKindClass(kind)}`, node.label);
@@ -998,13 +1044,25 @@ export function mount(container, graph, options = {}) {
? `${node.label}, open details`
: `Stage ${node.key}, ${node.type}, open details`,
);
if (!stageIsExecuted(node.key, runState)) button.classList.add("not-executed");
const executed = stageIsExecuted(node.key, runState);
if (runState != null) button.classList.add(executed ? "executed" : "not-executed");
if (node.key === activeKey) {
button.classList.add("active");
if (pulse) button.classList.add("pulsing");
const badge = el("span", "graph-elapsed");
badge.setAttribute("aria-hidden", "true");
button.append(badge);
elapsedBadge = badge;
}
button.addEventListener("click", (event) => {
if (dragged) {
event.preventDefault();
return;
}
selectNode(node.key);
// The run tab owns its own stage pane (the shared timeline visit pane), so
// a supplied handler replaces the definition pane rather than stacking on it.
if (typeof options.onStageTap === "function") options.onStageTap(node.key);
else selectNode(node.key);
});
nodeLayer.append(button);
}
@@ -1026,7 +1084,27 @@ export function mount(container, graph, options = {}) {
controls.append(fitButton, expandButton);
viewport.append(controls);
// The definition pane, hidden until a node is clicked.
// The legend, only under a run (never the definition-only view): a solid,
// arrowed swatch means "executed", a dashed, arrowless one "not executed",
// matching what the graph draws.
if (runState != null) {
const legend = el("div", "graph-legend");
legend.setAttribute("role", "note");
legend.setAttribute("aria-label", "Executed and not executed routes");
for (const entry of [
{ label: "Executed", executed: true },
{ label: "Not executed", executed: false },
]) {
const item = el("span", "graph-legend-entry");
item.append(el("span", `graph-legend-swatch ${entry.executed ? "executed" : "not-executed"}`));
item.append(el("span", "graph-legend-label", entry.label));
legend.append(item);
}
viewport.append(legend);
}
// The definition pane, hidden until a node is clicked (definition view only;
// the run tab opens its own pane through onStageTap instead).
const pane = el("div", "graph-pane");
pane.hidden = true;
root.append(viewport, pane);
@@ -1122,7 +1200,28 @@ export function mount(container, graph, options = {}) {
pane.replaceChildren(...children);
pane.hidden = false;
if (typeof options.onStageTap === "function") options.onStageTap(key);
}
// --- Elapsed badge (live run only) ---------------------------------------
function updateElapsed() {
if (!elapsedBadge) return;
const seconds = secondsSince(runState?.currentStageStartedAt, Date.now());
elapsedBadge.textContent = seconds == null ? "" : formatDuration(seconds);
}
let elapsedTimer = null;
if (elapsedBadge != null) {
updateElapsed();
// Tick only while the graph has a live stage with a known start; a still
// ring (reduced motion) and a finished run never wake up once a second.
if (
pulse &&
typeof setInterval === "function" &&
String(runState?.currentStageStartedAt ?? "").trim() !== ""
) {
elapsedTimer = setInterval(updateElapsed, 1000);
}
}
// --- Interactions --------------------------------------------------------
@@ -1230,6 +1329,10 @@ export function mount(container, graph, options = {}) {
return {
unmount() {
if (elapsedTimer != null) {
clearInterval(elapsedTimer);
elapsedTimer = null;
}
resizeObserver?.disconnect();
viewport.removeEventListener("pointerdown", onPointerDown);
viewport.removeEventListener("pointermove", onPointerMove);
+65 -5
View File
@@ -36,9 +36,9 @@ import { effectiveStageType } from "./templates.js";
/**
* The run-detail tabs, Summary first so it is the default selection. The Graph
* tab is present (Android `runDetailTabs`) but has no rendered body yet — it is
* the R5 item — so the renderer filters it out until then. The timeline keeps
* Android's stable key `steps` with the visible title `Timeline`.
* tab sits between Summary and Input (R5) and mounts the shared workflow graph
* in run mode. The timeline keeps Android's stable key `steps` with the visible
* title `Timeline`.
*/
export const RUN_DETAIL_TABS = [
{ key: "summary", label: "Summary" },
@@ -48,8 +48,8 @@ export const RUN_DETAIL_TABS = [
{ key: "steps", label: "Timeline" },
];
/** The tabs the browser currently renders (the Graph body is the R5 item). */
export const RENDERED_RUN_TABS = RUN_DETAIL_TABS.filter((tab) => tab.key !== "graph");
/** The tabs the browser renders: all of them, including the Graph body (R5). */
export const RENDERED_RUN_TABS = RUN_DETAIL_TABS;
// The empty-state sentences, exactly as the app spells them.
export const EMPTY_INPUT_MESSAGE = "No input recorded.";
@@ -330,6 +330,66 @@ export function graphEdges(graph) {
return result;
}
/**
* Which stages and routes a run actually recorded, for the graph's execution
* highlighting. Mirrors Android `RunGraphState.from` (GraphSemantics.kt:91-116):
* every step's stage key is a visited stage (insertion order), a step with a
* non-blank outcome and target contributes a taken route
* `{source, outcome, resolvedTarget}` (recorded as a `source\0outcome\0target`
* key the graph matches) and, when that resolved target is a terminal, marks the
* terminal visited too. `currentStage` is the run's own stage, else the last
* visit's stage, else null; `executing` mirrors the run; `currentStageStartedAt`
* is the running visit's start for the active stage, only while executing. Pure
* and DOM-free so the renderer and the tests share one definition.
*/
export function runGraphState(run) {
const visitedStages = [];
const seenStages = new Set();
const takenRoutes = [];
const seenRoutes = new Set();
const steps = run?.steps ?? [];
const visit = (key) => {
if (key == null || seenStages.has(key)) return;
seenStages.add(key);
visitedStages.push(key);
};
for (const step of steps) {
visit(step?.stage);
const outcome = String(step?.outcome ?? "");
const target = String(step?.target ?? "");
if (target.trim() !== "" && outcome.trim() !== "") {
const resolved = resolveTarget(outcome, target);
const route = `${step?.stage}\u0000${outcome}\u0000${resolved}`;
if (!seenRoutes.has(route)) {
seenRoutes.add(route);
takenRoutes.push(route);
}
if (isTerminal(resolved)) visit(resolved);
}
}
const lastStage = steps.length > 0 ? steps[steps.length - 1]?.stage : "";
const rawCurrent = String(run?.current_stage ?? "").trim() !== "" ? run.current_stage : lastStage;
const currentStage = String(rawCurrent ?? "").trim() !== "" ? String(rawCurrent) : null;
const executing = Boolean(run?.executing);
let currentStageStartedAt = null;
if (executing && currentStage != null) {
for (let index = steps.length - 1; index >= 0; index -= 1) {
const step = steps[index];
if (step?.stage === currentStage && step?.status === "running") {
const started = String(step?.started_at ?? "");
if (started.trim() !== "") currentStageStartedAt = started;
break;
}
}
}
return { visitedStages, takenRoutes, currentStage, executing, currentStageStartedAt };
}
// ---------------------------------------------------------------------------
// Stage pane (ui/graph/StageDetailPane.kt)
// ---------------------------------------------------------------------------
+68
View File
@@ -610,6 +610,74 @@ code { background: var(--surface-2); padding: 1px 6px; border-radius: 6px; font-
}
.graph-control:hover { border-color: var(--accent); color: var(--accent); }
/* The run-mode legend (R5), pinned top-start opposite the Fit/expand controls.
A solid, arrowed swatch means "executed"; a dashed, arrowless one "not
executed". Never shown for the definition-only view. */
.graph-legend {
position: absolute;
top: 8px;
left: 8px;
z-index: 2;
display: flex;
gap: 12px;
align-items: center;
padding: 4px 8px;
border: 1px solid var(--border);
border-radius: 8px;
background: color-mix(in srgb, var(--surface) 85%, transparent);
font-size: 12px;
color: var(--muted);
}
.graph-legend-entry { display: inline-flex; gap: 6px; align-items: center; }
.graph-legend-swatch {
position: relative;
width: 26px;
border-top: 3px solid var(--muted);
}
.graph-legend-swatch.executed { border-top-color: var(--text); }
/* A small filled arrowhead on the executed swatch, matching the drawn head. */
.graph-legend-swatch.executed::after {
content: "";
position: absolute;
top: -6px;
right: -1px;
border-left: 7px solid var(--text);
border-top: 4px solid transparent;
border-bottom: 4px solid transparent;
}
.graph-legend-swatch.not-executed { border-top-style: dashed; }
/* The live active stage (R5): a ring around the node plus a soft glow, pulsing
while the run executes and static when the user prefers reduced motion. */
.graph-node.active {
border-color: var(--accent);
box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 40%, transparent);
}
.graph-node.active.pulsing { animation: graph-halo-pulse 1.6s ease-in-out infinite; }
@keyframes graph-halo-pulse {
0%,
100% { box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 55%, transparent); }
50% { box-shadow: 0 0 0 7px color-mix(in srgb, var(--accent) 20%, transparent); }
}
@media (prefers-reduced-motion: reduce) {
.graph-node.active.pulsing { animation: none; }
}
/* The live elapsed-time badge on the active node. */
.graph-elapsed {
position: absolute;
bottom: -9px;
right: 6px;
padding: 0 5px;
border: 1px solid color-mix(in srgb, var(--accent) 45%, var(--border));
border-radius: 999px;
background: var(--surface);
color: var(--accent);
font-size: 10px;
font-weight: 600;
line-height: 16px;
}
/* The definition pane opened from a node click. */
.graph-pane {
display: grid;
+112
View File
@@ -14,6 +14,7 @@ import {
MAX_SCALE,
PIPELINE_GRAPH_EMPTY,
RUN_GRAPH_MISSING,
RUN_GRAPH_NOTE,
NO_NODE_DETAILS,
STAGE_DEFINITION_TITLE,
configLabel,
@@ -33,7 +34,11 @@ import {
clampOffset,
fitScale,
zoomAbout,
stageIsExecuted,
edgeIsExecuted,
activeStage,
} from "../src/graph.js";
import { runGraphState } from "../src/runDetail.js";
// ---------------------------------------------------------------------------
// Fixtures
@@ -369,12 +374,119 @@ test("terminalFields lists the incoming routes into a terminal", () => {
assert.deepEqual(terminalFields(twoStageGraph(), "#nope"), []);
});
// ---------------------------------------------------------------------------
// Run-mode execution state (R5: GraphSemantics RunGraphState.from)
// ---------------------------------------------------------------------------
test("runGraphState resolves visited stages, taken routes and reached terminals", () => {
const run = {
executing: false,
current_stage: "committer",
steps: [
{ stage: "implementer", sequence: 1, status: "completed", outcome: "success", target: "reviewer" },
{ stage: "reviewer", sequence: 2, status: "completed", outcome: "rejected", target: "implementer" },
{ stage: "implementer", sequence: 3, status: "completed", outcome: "success", target: "reviewer" },
{ stage: "committer", sequence: 4, status: "completed", outcome: "success", target: "#success" },
],
};
const state = runGraphState(run);
assert.deepEqual(state.visitedStages, ["implementer", "reviewer", "committer", "#success"]);
assert.equal(state.currentStage, "committer");
assert.equal(state.executing, false);
assert.equal(state.currentStageStartedAt, null);
assert.deepEqual(state.takenRoutes, [
"implementer\u0000success\u0000reviewer",
"reviewer\u0000rejected\u0000implementer",
"committer\u0000success\u0000#success",
]);
});
test("runGraphState marks a terminal only when a visit resolved to it", () => {
// A `#` target resolves by outcome: error -> #failure, everything else -> #success.
const failed = runGraphState({
executing: false,
steps: [{ stage: "impl", outcome: "error", target: "#" }],
});
assert.deepEqual(failed.visitedStages, ["impl", "#failure"]);
assert.equal(stageIsExecuted("#failure", failed), true);
assert.equal(stageIsExecuted("#success", failed), false);
const midRun = runGraphState({
executing: false,
steps: [{ stage: "impl", outcome: "success", target: "review" }],
});
assert.equal(stageIsExecuted("#success", midRun), false);
assert.equal(stageIsExecuted("#failure", midRun), false);
assert.equal(stageIsExecuted("review", midRun), false, "a target is not visited until a step lands on it");
});
test("stageIsExecuted is true for a visited stage and for the definition view", () => {
const state = runGraphState({
executing: false,
steps: [{ stage: "impl", outcome: "success", target: "review" }],
});
assert.equal(stageIsExecuted("impl", state), true);
assert.equal(stageIsExecuted("review", state), false);
// The definition view passes no runState, so every stage is executed.
assert.equal(stageIsExecuted("review", null), true);
});
test("edgeIsExecuted is true only for a route a recorded visit produced", () => {
const state = runGraphState({
executing: false,
steps: [
{ stage: "impl", outcome: "success", target: "review" },
{ stage: "review", outcome: "error", target: "#" },
],
});
const taken = { source: "impl", outcome: "success", target: "review" };
const byFallback = { source: "review", outcome: "error", target: "#failure" };
const untaken = { source: "impl", outcome: "blocked", target: "#failure" };
assert.equal(edgeIsExecuted(taken, state), true);
assert.equal(edgeIsExecuted(byFallback, state), true, "a resolved fallback route counts");
assert.equal(edgeIsExecuted(untaken, state), false);
// The definition view draws every route executed.
assert.equal(edgeIsExecuted(untaken, null), true);
});
test("activeStage resolves only while the run is executing", () => {
const live = runGraphState({
executing: true,
current_stage: "review",
steps: [
{ stage: "review", status: "running", started_at: "2026-01-01T00:00:00Z" },
],
});
assert.equal(activeStage(live), "review");
assert.equal(live.currentStageStartedAt, "2026-01-01T00:00:00Z");
const settled = runGraphState({
executing: false,
current_stage: "review",
steps: [
{ stage: "review", status: "running", started_at: "2026-01-01T00:00:00Z" },
],
});
assert.equal(activeStage(settled), null, "a finished run has no active stage");
assert.equal(settled.currentStageStartedAt, null);
assert.equal(activeStage(null), null, "the definition view has no active stage");
});
test("runGraphState falls back to the last visit's stage, else null", () => {
const state = runGraphState({ executing: false, steps: [{ stage: "a" }, { stage: "b" }] });
assert.equal(state.currentStage, "b");
assert.equal(runGraphState({ executing: false, steps: [] }).currentStage, null);
assert.equal(runGraphState({}).currentStage, null);
});
// ---------------------------------------------------------------------------
// Wording, exports and the no-innerHTML contract
// ---------------------------------------------------------------------------
test("the empty-state and pane wording matches the app's sentences", () => {
assert.equal(RUN_GRAPH_MISSING, "This server did not include the run graph.");
assert.ok(RUN_GRAPH_NOTE.includes("pulses"));
assert.ok(RUN_GRAPH_NOTE.includes("Mouse wheel to zoom"));
assert.equal(PIPELINE_GRAPH_EMPTY, "This pipeline has no stages.");
assert.equal(NO_NODE_DETAILS, "No details recorded for this node.");
assert.equal(STAGE_DEFINITION_TITLE, "Stage definition");
+2 -2
View File
@@ -79,10 +79,10 @@ test("RUN_DETAIL_TABS is the Android order, Summary first, Timeline keyed 'steps
RUN_DETAIL_TABS.map((tab) => tab.label),
["Summary", "Graph", "Input", "Output", "Timeline"],
);
// The Graph body is the R5 item; only the other four render today.
// The Graph body (R5) now renders too, so every tab is present.
assert.deepEqual(
RENDERED_RUN_TABS.map((tab) => tab.label),
["Summary", "Input", "Output", "Timeline"],
["Summary", "Graph", "Input", "Output", "Timeline"],
);
});
+136 -2
View File
@@ -590,11 +590,14 @@ try {
await page.click('.list.runs .run-row-meta[data-run-id="430"]');
await page.waitForSelector(".detail .detail-tabs", { timeout: 25000 });
// The run-detail tabs, in the app's order (the Graph body is the R5 item).
// The run-detail tabs, in the app's order (Summary / Graph / Input / Output /
// Timeline; the Graph body is R5 and now rendered).
const runTabs = await page.evaluate(
`[...document.querySelectorAll(".detail .detail-tabs .detail-tab")].map((n) => n.textContent)`,
);
if (JSON.stringify(runTabs) !== JSON.stringify(["Summary", "Input", "Output", "Timeline"])) {
if (
JSON.stringify(runTabs) !== JSON.stringify(["Summary", "Graph", "Input", "Output", "Timeline"])
) {
throw new Error(`run tabs are wrong: ${runTabs.join(",")}`);
}
console.log(` run tabs: ${runTabs.join(" / ")}`);
@@ -784,6 +787,137 @@ try {
console.log(` timeline empty state: ${emptyTimeline}`);
shots.push(await page.screenshot(`${out}/26-run-428-timeline-empty.png`));
// R5: the run-detail Graph tab — the shared workflow graph in run mode. Run 438
// is a finished run with several visits and the full outcome set: its graph
// shows the Executed / Not executed legend, solid executed nodes and arrowed
// executed routes, and dashed untaken routes. Clicking a stage opens the
// existing visit pane (with its Verdict) at that stage's latest visit. Run 440
// shows the hollow, dashed nodes for the stages the failed run never reached.
step("opening run 438 and capturing its Graph tab (R5)");
await page.click('.list.runs .run-row-meta[data-run-id="438"]');
await page.waitForSelector(".detail .detail-tabs", { timeout: 25000 });
await page.clickText(".detail .detail-tabs .detail-tab", "Graph");
await page.waitForSelector(".run-detail .graph-note", { timeout: 15000 });
const runGraphNote = await text(".run-detail .graph-note");
if (!runGraphNote.includes("pulses with its elapsed time")) {
throw new Error(`unexpected run graph note: ${runGraphNote}`);
}
await page.waitForSelector(".run-detail .graph-node", { timeout: 15000 });
await eventually(async () => {
const current = await graphState();
return current != null && current.scale > 0;
}, { what: "the run graph to lay out" });
const legend = await page.evaluate(
`[...document.querySelectorAll(".run-detail .graph-legend .graph-legend-label")].map((n) => n.textContent)`,
);
if (JSON.stringify(legend) !== JSON.stringify(["Executed", "Not executed"])) {
throw new Error(`the run graph legend is wrong: ${JSON.stringify(legend)}`);
}
const graph438 = await page.evaluate(`(() => ({
executedNodes: document.querySelectorAll(".run-detail .graph-node.executed").length,
notExecutedNodes: document.querySelectorAll(".run-detail .graph-node.not-executed").length,
executedEdges: document.querySelectorAll(".run-detail .graph-edge-path.executed").length,
notExecutedEdges: document.querySelectorAll(".run-detail .graph-edge-path.not-executed").length,
arrowedEdges: document.querySelectorAll('.run-detail .graph-edge-path[marker-end]').length,
active: document.querySelectorAll(".run-detail .graph-node.active").length,
}))()`);
if (!graph438.executedNodes || !graph438.executedEdges || !graph438.notExecutedEdges) {
throw new Error(`run 438 should show executed stages and both executed/untaken routes: ${JSON.stringify(graph438)}`);
}
if (graph438.arrowedEdges !== graph438.executedEdges) {
throw new Error(`only executed routes carry an arrowhead: ${JSON.stringify(graph438)}`);
}
if (graph438.active !== 0) {
throw new Error(`a finished run must have no active halo: ${JSON.stringify(graph438)}`);
}
console.log(
` run 438 graph: ${graph438.executedNodes} executed / ${graph438.notExecutedNodes} not-executed nodes, ` +
`${graph438.executedEdges} arrowed / ${graph438.notExecutedEdges} dashed routes, legend ${legend.join("/")}`,
);
await page.rect(".run-detail .graph-viewport");
shots.push(await page.screenshot(`${out}/28-run-438-graph.png`));
step("opening a stage's visit pane from the run 438 graph");
await page.evaluate(
`document.querySelector('.run-detail .graph-node[data-key="ui_reviewer"]').click()`,
);
await page.waitForSelector(".stage-pane", { timeout: 15000 });
await page.waitForText("Verdict", { timeout: 15000 });
const graphPane = await page.evaluate(`(() => ({
title: document.querySelector(".stage-pane-title")?.textContent ?? "",
verdict: document.querySelector(".stage-pane .verdict .outcome-chip")?.textContent ?? "",
}))()`);
if (graphPane.title !== "ui_reviewer") {
throw new Error(`the graph-opened pane named the wrong stage: ${graphPane.title}`);
}
if (!graphPane.verdict) throw new Error("the graph-opened pane did not show a verdict");
console.log(` graph-opened pane: ${graphPane.title} — verdict ${graphPane.verdict}`);
await page.rect(".stage-pane-sheet");
shots.push(await page.screenshot(`${out}/29-run-438-graph-pane.png`));
await page.click(".stage-pane-back");
await eventually(() => page.evaluate(`!document.querySelector(".stage-pane")`), {
timeout: 5000,
what: "the graph stage pane to close",
});
step("opening run 440 to capture the hollow, not-executed stages (R5)");
await page.click('.list.runs .run-row-meta[data-run-id="440"]');
await page.waitForSelector(".detail .detail-tabs", { timeout: 25000 });
await page.clickText(".detail .detail-tabs .detail-tab", "Graph");
await page.waitForSelector(".run-detail .graph-node", { timeout: 15000 });
const graph440 = await page.evaluate(`(() => ({
executedNodes: document.querySelectorAll(".run-detail .graph-node.executed").length,
notExecutedNodes: document.querySelectorAll(".run-detail .graph-node.not-executed").length,
hollow: [...document.querySelectorAll(".run-detail .graph-node.not-executed")].every(
(n) => getComputedStyle(n).borderStyle === "dashed",
),
}))()`);
if (!graph440.executedNodes || !graph440.notExecutedNodes) {
throw new Error(`run 440 should show visited and unvisited stages: ${JSON.stringify(graph440)}`);
}
if (!graph440.hollow) {
throw new Error(`an unvisited node is not hollow/dashed: ${JSON.stringify(graph440)}`);
}
console.log(` run 440 graph: ${graph440.executedNodes} executed / ${graph440.notExecutedNodes} not-executed (dashed) nodes`);
await page.rect(".run-detail .graph-viewport");
shots.push(await page.screenshot(`${out}/30-run-440-graph.png`));
// R5: a live run's Graph tab — the current stage carries the pulsing halo and
// a ticking elapsed badge; a finished run (above) carries neither. Best effort:
// the run may stop before we look, so skip rather than fail if none is running.
step("opening a live run's Graph tab (R5: halo + elapsed badge)");
const liveRunId = await page.evaluate(`(() => {
const row = [...document.querySelectorAll(".list.runs .run-row")].find((n) => n.querySelector(".chip-running"));
const meta = row?.querySelector(".run-row-meta[data-run-id]");
return meta ? Number(meta.getAttribute("data-run-id")) : null;
})()`);
if (liveRunId == null) {
console.log(" -- no running run available; skipped the live graph halo capture");
} else {
await page.click(`.list.runs .run-row-meta[data-run-id="${liveRunId}"]`);
await page.waitForSelector(".detail .detail-tabs", { timeout: 25000 });
await page.clickText(".detail .detail-tabs .detail-tab", "Graph");
await page.waitForSelector(".run-detail .graph-node", { timeout: 15000 });
const live = await eventually(
async () =>
page.evaluate(`(() => {
const active = document.querySelector(".run-detail .graph-node.active");
if (!active) return null;
return {
activeKey: active.dataset.key ?? "",
pulsing: active.classList.contains("pulsing"),
badge: active.querySelector(".graph-elapsed")?.textContent ?? "",
};
})()`),
{ timeout: 15000, what: "the live run's active stage" },
);
if (!live.badge) throw new Error(`the active stage showed no elapsed badge: ${JSON.stringify(live)}`);
console.log(` live run ${liveRunId}: active stage ${live.activeKey} (pulsing=${live.pulsing}), badge ${live.badge}`);
await page.rect(".run-detail .graph-viewport");
shots.push(await page.screenshot(`${out}/31-run-live-graph.png`));
}
// The Output empty state, on the running run that has not produced output yet.
step("opening the Output tab on a run with no output recorded");
const runningId = await page.evaluate(`(() => {