Render run list miniatures from compact per-stage route evidence
This commit is contained in:
@@ -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);
|
||||
});
|
||||
@@ -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 () => {
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user