Merge branch 'main' into web-run-tabs

This commit is contained in:
2026-10-19 03:32:34 +01:00
6 changed files with 2052 additions and 6 deletions
+226 -4
View File
@@ -54,6 +54,71 @@ async function shot(name) {
const text = (selector) =>
page.evaluate(`document.querySelector(${JSON.stringify(selector)})?.textContent ?? ""`);
// The mounted graph's current transform, read back so the pan/zoom clamp checks
// assert the real rendered state rather than a claim.
const graphState = () =>
page.evaluate(`(() => {
const content = document.querySelector(".graph-content");
const viewport = document.querySelector(".graph-viewport");
if (!content || !viewport) return null;
const m = /translate\\(([-0-9.]+)px, ([-0-9.]+)px\\) scale\\(([-0-9.]+)\\)/.exec(
content.style.transform,
);
if (!m) return null;
return {
tx: Number(m[1]),
ty: Number(m[2]),
scale: Number(m[3]),
width: parseFloat(content.style.width),
height: parseFloat(content.style.height),
viewportWidth: viewport.clientWidth,
viewportHeight: viewport.clientHeight,
};
})()`);
// Dispatch real wheel events at the viewport centre (the page handler is
// `{ passive: false }` and prevents default, so a synthetic event exercises the
// same clamp path a user gesture does).
const wheel = (deltaY, times) =>
page.evaluate(`(() => {
const viewport = document.querySelector(".graph-viewport");
const r = viewport.getBoundingClientRect();
for (let i = 0; i < ${times}; i += 1) {
viewport.dispatchEvent(new WheelEvent("wheel", {
bubbles: true,
cancelable: true,
deltaY: ${deltaY},
clientX: r.left + r.width / 2,
clientY: r.top + r.height / 2,
}));
}
return true;
})()`);
// Dispatch a real pointer drag across the viewport.
const drag = (dx, dy) =>
page.evaluate(`(() => {
const viewport = document.querySelector(".graph-viewport");
const r = viewport.getBoundingClientRect();
const fire = (type, x, y) => viewport.dispatchEvent(new PointerEvent(type, {
bubbles: true,
cancelable: true,
pointerId: 7,
button: 0,
buttons: type === "pointerup" ? 0 : 1,
clientX: x,
clientY: y,
}));
const startX = r.left + r.width / 2;
const startY = r.top + r.height / 2;
fire("pointerdown", startX, startY);
for (let i = 1; i <= 20; i += 1) {
fire("pointermove", startX + (${dx} * i) / 20, startY + (${dy} * i) / 20);
}
fire("pointerup", startX + ${dx}, startY + ${dy});
return true;
})()`);
try {
await mkdir(out, { recursive: true });
@@ -138,8 +203,22 @@ try {
await page.click("#filterToggle");
// 5. Pipeline detail: Summary (name, subtitle, content hash, created/updated).
step("opening a pipeline detail (Summary)");
await page.click("#pipelineRows button.row");
// Prefer a multi-stage pipeline so the Graph tab below has a real layout to
// render; fall back to whatever the server lists first.
step("opening a multi-stage pipeline detail (Summary)");
const openedPipeline = await page.evaluate(`(() => {
const rows = [...document.querySelectorAll("#pipelineRows button.row")];
const wanted = rows.find((row) => row.textContent.includes("Plan and land")) ?? rows[0];
if (!wanted) return null;
wanted.setAttribute("data-test-click", "1");
return wanted.textContent.includes("Plan and land") ? "Plan and land" : "first row";
})()`);
if (!openedPipeline) throw new Error("no pipeline row to open");
console.log(` opened pipeline: ${openedPipeline}`);
await page.click("[data-test-click='1']");
await page.evaluate(
`document.querySelector("[data-test-click='1']")?.removeAttribute("data-test-click")`,
);
await page.waitForSelector(".detail h2");
await page.waitForSelector(".monospace");
await page.evaluate(`document.querySelector(".detail")?.scrollIntoView({ block: "start" })`);
@@ -159,12 +238,155 @@ try {
await page.evaluate(`document.querySelector(".detail")?.scrollIntoView({ block: "start" })`);
await shot("07-pipeline-source.png");
// 8. Graph tab: the guidance note only; the rendered graph is P6.
step("opening the Graph tab (guidance note only)");
// 8. Graph tab (P6): the guidance note plus the rendered workflow graph —
// stage nodes in declaration order, labelled outcome edges, the success and
// failure terminals — then an opened definition pane, the zoom/pan clamps and
// the expanded panel. Every assertion below is a real behaviour of the page.
step("opening the Graph tab: the rendered workflow graph (P6)");
await page.clickText(".detail-tabs button", "Graph");
await page.waitForSelector(".graph-note");
await page.waitForSelector(".graph-viewport");
await page.waitForSelector(".graph-node");
// Auto-fit runs on the first layout (after the host is attached), so wait for
// the whole graph to sit inside the viewport before asserting.
await eventually(
async () => {
const current = await graphState();
if (!current || !(current.scale > 0)) return false;
const scaledWidth = current.width * current.scale;
const scaledHeight = current.height * current.scale;
return (
current.tx >= -0.5 &&
current.ty >= -0.5 &&
current.tx + scaledWidth <= current.viewportWidth + 0.5 &&
current.ty + scaledHeight <= current.viewportHeight + 0.5
);
},
{ what: "the graph to be auto-fitted into the viewport" },
);
const note = await text(".graph-note");
if (!note.includes("Mouse wheel to zoom, drag to pan, click a stage for details.")) {
throw new Error(`unexpected graph guidance note: ${note}`);
}
const graphCounts = await page.evaluate(`(() => ({
nodes: document.querySelectorAll(".graph-node").length,
stages: document.querySelectorAll(".graph-node:not([class*='terminal'])").length,
edges: document.querySelectorAll(".graph-edge-path").length,
labels: [...document.querySelectorAll(".graph-edge-label")].map((n) => n.textContent),
failure: !!document.querySelector(".graph-node-terminal-failure"),
success: !!document.querySelector(".graph-node-terminal-success"),
}))()`);
if (!graphCounts.stages || !graphCounts.edges || !graphCounts.labels.length) {
throw new Error(`the graph did not render nodes/edges/labels: ${JSON.stringify(graphCounts)}`);
}
if (!graphCounts.failure || !graphCounts.success) {
throw new Error(`the graph is missing a terminal: ${JSON.stringify(graphCounts)}`);
}
const fitted = await graphState();
if (!(fitted && fitted.scale > 0 && fitted.scale <= 1 + 1e-6)) {
throw new Error(`the graph was not auto-fitted: ${JSON.stringify(fitted)}`);
}
console.log(
` graph: ${graphCounts.stages} stages, ${graphCounts.edges} edges, ` +
`${graphCounts.nodes} nodes, labels ${graphCounts.labels.join(",")}; fitted at ${fitted.scale.toFixed(2)}`,
);
await shot("08-pipeline-graph.png");
// Clicking empty space must do nothing; clicking a stage opens its pane.
step("checking empty-space click and opening a stage's definition pane");
await page.evaluate(`document.querySelector(".graph-viewport")?.click()`);
const paneOnEmpty = await page.evaluate(
`(() => { const p = document.querySelector(".graph-pane"); return !!p && !p.hidden; })()`,
);
if (paneOnEmpty) throw new Error("clicking empty space opened the stage pane");
await page.click(".graph-node-model");
await page.waitForSelector(".graph-pane:not([hidden])");
const pane = await page.evaluate(`(() => {
const p = document.querySelector(".graph-pane");
return {
text: p.textContent,
key: document.querySelector(".graph-node-model")?.dataset.key ?? "",
type: document.querySelector(".graph-type-chip")?.textContent ?? "",
fields: document.querySelectorAll(".graph-pane .graph-field").length,
};
})()`);
if (!pane.key || !pane.text.includes(pane.key)) {
throw new Error(`the pane did not name the stage key (${pane.key}): ${pane.text.slice(0, 120)}`);
}
if (!pane.type) throw new Error("the pane did not show the stage type");
if (!pane.text.includes("Stage definition") || !pane.fields) {
throw new Error(`the pane has no Stage definition fields: ${pane.text.slice(0, 120)}`);
}
await page.rect(".graph-pane");
await shot("08a-pipeline-graph-stage-pane.png");
console.log(` stage pane: ${pane.key} (${pane.type}), ${pane.fields} definition field(s)`);
// Wheel zoom clamps to [0.3, 3.0]; a drag can never leave an empty viewport.
step("exercising wheel-zoom clamps, drag clamping and Fit");
await wheel(400, 60);
const zoomedOut = await graphState();
if (!(Math.abs(zoomedOut.scale - 0.3) < 1e-6)) {
throw new Error(`zoom-out was not clamped to 0.3: ${zoomedOut.scale}`);
}
await wheel(-400, 60);
const zoomedIn = await graphState();
if (!(Math.abs(zoomedIn.scale - 3.0) < 1e-6)) {
throw new Error(`zoom-in was not clamped to 3.0: ${zoomedIn.scale}`);
}
await drag(4000, 3000);
const panned = await graphState();
const visibleX =
Math.min(panned.tx + panned.width * panned.scale, panned.viewportWidth) -
Math.max(panned.tx, 0);
const visibleY =
Math.min(panned.ty + panned.height * panned.scale, panned.viewportHeight) -
Math.max(panned.ty, 0);
if (visibleX < 39.5 || visibleY < 39.5) {
throw new Error(`panning left an empty viewport: visible ${visibleX}x${visibleY}`);
}
await page.clickText(".graph-control", "Fit graph to view");
const refitted = await graphState();
if (!(refitted.scale >= 0.3 && refitted.scale <= 1 + 1e-6)) {
throw new Error(`Fit did not re-fit the graph: ${refitted.scale}`);
}
console.log(
` zoom clamp 0.3..3.0 ok; after a 4000x3000 drag the viewport still shows ` +
`${Math.round(visibleX)}x${Math.round(visibleY)}px; Fit re-fitted to ${refitted.scale.toFixed(2)}`,
);
step("expanding the graph panel");
await page.clickText(".graph-control", "Expand graph");
await page.waitForText("Collapse graph");
const expandedHeight = await page.evaluate(
`document.querySelector(".graph-viewport").clientHeight`,
);
await page.rect(".graph-viewport");
await shot("08b-pipeline-graph-expanded.png");
console.log(` expanded graph viewport height: ${expandedHeight}px`);
await page.clickText(".graph-control", "Collapse graph");
step("checking a node with no stage shows the app's empty pane message");
const noDetails = await page.evaluate(`(async () => {
const { mount } = await import("/src/graph.js");
const host = document.createElement("div");
host.style.cssText = "position:fixed;left:-2400px;top:0;width:600px;height:300px";
document.body.append(host);
const graph = { stages: [{ key: "alpha", type: "model", edges: { success: "#success" } }] };
const handle = mount(host, graph, {});
host.querySelector(".graph-node-terminal-failure").click();
const text = host.querySelector(".graph-pane").textContent;
handle.unmount();
const emptyAfterUnmount = host.childElementCount === 0;
host.remove();
return { text, emptyAfterUnmount };
})()`);
if (!noDetails.text.includes("No details recorded for this node.")) {
throw new Error(`a stage-less node did not show the empty message: ${noDetails.text}`);
}
if (!noDetails.emptyAfterUnmount) throw new Error("unmount left the graph DOM behind");
console.log(" a node with no stage reads: No details recorded for this node.");
step("switching to Runs: day-grouped list + usage roll-up");
await page.clickText("nav.tabs button.tab", "Runs");
await page.waitForSelector(".list.runs .day-header", { timeout: 25000 });