Files
pipelines/web/test/ui-smoke.mjs
T

836 lines
39 KiB
JavaScript

// Live browser check for the web client: serve the page, open it in headless
// Chrome, connect to a running Pipelines server through the page's own proxy,
// and capture what actually rendered.
//
// node test/ui-smoke.mjs [--port 8091] [--pipelines 127.0.0.1:8080] [--out DIR]
//
// This is the UI evidence a review stage produces: real screenshots of the
// rendered client, not a claim. It needs a running Pipelines server (the live one
// or a scratch one) and the installed Chrome; it has no npm dependencies.
import { spawn } from "node:child_process";
import { mkdir, rm } from "node:fs/promises";
import { tmpdir } from "node:os";
import { dirname, join, resolve } from "node:path";
import { fileURLToPath } from "node:url";
import { eventually, launchChrome } from "./browser.mjs";
const ROOT = resolve(dirname(fileURLToPath(import.meta.url)), "..");
function flag(argv, name, fallback) {
const i = argv.indexOf(name);
return i !== -1 && argv[i + 1] ? argv[i + 1] : fallback;
}
const port = Number(flag(process.argv, "--port", process.env.WEB_UI_PORT ?? 8091));
const pipelines = flag(process.argv, "--pipelines", process.env.PIPELINES_TARGET ?? "127.0.0.1:8080");
const out = resolve(
flag(process.argv, "--out", process.env.WEB_UI_OUT ?? join(tmpdir(), "pipelines-web-ui")),
);
// The page must connect through its own proxy (the server rejects a cross-origin
// upgrade), but serve.mjs only proxies /connect — not /artifacts. Point the URL
// field at the real Pipelines server after connecting so artifact tiles and the
// viewer resolve to real files; that is exactly the URL a correctly configured
// page would carry.
const artifactServerUrl = `ws://${pipelines}/connect`;
const shots = [];
let serve = null;
let browser = null;
let page = null;
let failed = false;
function step(label) {
console.log(`• ${label}`);
}
async function shot(name) {
const path = `${out}/${name}`;
shots.push(await page.screenshot(path));
console.log(` capture ${path}`);
return path;
}
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 });
step(`serving web/ on 127.0.0.1:${port} (proxy /connect -> ${pipelines})`);
serve = spawn(process.execPath, ["serve.mjs", "--port", String(port), "--pipelines", pipelines], {
cwd: ROOT,
stdio: ["ignore", "pipe", "pipe"],
});
let serveLog = "";
serve.stdout.on("data", (chunk) => (serveLog += chunk.toString()));
serve.stderr.on("data", (chunk) => (serveLog += chunk.toString()));
await eventually(
async () => {
if (serve.exitCode != null) throw new Error(`serve.mjs exited: ${serveLog.trim().slice(-300)}`);
const res = await fetch(`http://127.0.0.1:${port}/`).catch(() => null);
return res?.ok;
},
{ what: "the page to be served" },
);
step("launching headless Chrome");
browser = await launchChrome({ width: 1440, height: 900 });
page = await browser.openPage(`http://127.0.0.1:${port}/`);
step("connecting the page to the server through its own proxy");
await page.fill("#url", `ws://127.0.0.1:${port}/connect`);
await page.click("#connectBtn");
await page.waitForSelector(".row-title", { timeout: 25000 });
await page.waitForText("connected", { timeout: 25000 });
const pipelineCount = await page.evaluate(
`document.querySelectorAll("#pipelineRows button.row").length`,
);
if (!pipelineCount) throw new Error("connected but no pipelines rendered");
console.log(` pipelines rendered: ${pipelineCount}`);
// 1. The list with its filter menu open: the name field, the Runs section, the
// Last run status multi-select and the Clear filters reset (P1 + P2).
step("capturing the pipeline list with the filter menu open");
await page.click("#filterToggle");
await page.waitForSelector(".filter-panel");
await shot("01-pipelines-controls.png");
// 2. The sort menu, and exercising it changes the ordering (P2).
step("capturing and exercising the sort menu");
await page.click("#sortToggle");
await page.waitForSelector(".sort-panel");
await shot("02-pipelines-sort.png");
await page.clickText(".sort-panel .sort-option", "Name A\u2013Z");
const sorted = await text("#sortToggle");
if (!sorted.includes("Name A\u2013Z")) throw new Error(`sort did not apply: ${sorted}`);
await page.click("#sortToggle");
await page.waitForSelector(".sort-panel");
await page.clickText(".sort-panel button", "Reset");
const reset = await text("#sortToggle");
if (!reset.includes("Server order")) throw new Error(`sort reset failed: ${reset}`);
// 3. The name facet narrows live; an unmatched name shows the name-only empty state.
step("narrowing by name and capturing the name-only empty state");
await page.click("#filterToggle");
await page.waitForSelector(".filter-panel");
await page.fill("#pipelineNameFilter", "Android");
const narrowed = await page.evaluate(
`document.querySelectorAll("#pipelineRows button.row").length`,
);
if (!narrowed || narrowed >= pipelineCount) {
throw new Error(`name filter did not narrow (${narrowed} of ${pipelineCount})`);
}
console.log(` name filter narrowed ${pipelineCount} -> ${narrowed}`);
await page.fill("#pipelineNameFilter", "zzz-no-such-pipeline");
await page.waitForText('No pipelines match "zzz-no-such-pipeline".');
await shot("03-pipelines-empty-name.png");
await page.click(".empty button");
await page.waitForSelector("#pipelineRows button.row");
// 4. A run facet with no matches shows the general empty state and a reset.
step("capturing the run-facet empty state");
await page.click("#status-interrupted");
await page.waitForText("No pipelines match the current filters.");
await shot("04-pipelines-empty-filters.png");
await page.click(".empty button");
await page.waitForSelector("#pipelineRows button.row");
await page.click("#filterToggle");
// 5. Pipeline detail: Summary (name, subtitle, content hash, created/updated).
// 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" })`);
await shot("05-pipeline-summary.png");
// 6. The Versions section is collapsed by default; expanding shows its rows.
step("expanding the Versions section");
await page.click(".section-toggle");
await page.waitForSelector(".versions-list");
await page.evaluate(`document.querySelector(".versions-list")?.scrollIntoView({ block: "start" })`);
await shot("06-pipeline-summary-versions.png");
// 7. Source tab: the rendered pipeline source in a monospace block.
step("opening the Source tab");
await page.clickText(".detail-tabs button", "Source");
await page.waitForSelector(".source-code");
await page.evaluate(`document.querySelector(".detail")?.scrollIntoView({ block: "start" })`);
await shot("07-pipeline-source.png");
// 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 });
await page.waitForSelector(".metrics .metric", { timeout: 25000 });
const usageLabels = await page.evaluate(
`[...document.querySelectorAll(".metrics .metric-label")].map((n) => n.textContent)`,
);
for (const label of ["Total", "Succeeded", "Failed", "Canceled", "Interrupted", "Active"]) {
if (!usageLabels.includes(label)) throw new Error(`usage metric missing: ${label}`);
}
const dayHeaders = await page.evaluate(
`[...document.querySelectorAll(".list.runs .day-header")].map((n) => n.textContent)`,
);
if (!dayHeaders.length) throw new Error("no day header rendered");
if (!dayHeaders.includes("Today")) {
throw new Error(`the list does not start with Today: ${dayHeaders.join(" | ")}`);
}
const fullDateHeader = dayHeaders.find((label) => /^\d{1,2} \w{3} \d{4}$/.test(label));
if (!fullDateHeader) throw new Error(`no full-date day header: ${dayHeaders.join(" | ")}`);
shots.push(await page.screenshot(`${out}/09-runs-day-groups.png`));
console.log(` usage: ${usageLabels.join(", ")}`);
console.log(` day headers: ${dayHeaders.slice(0, 3).join(" | ")}`);
step(`scrolling the list to the older day group (${fullDateHeader})`);
const scrolledTo = await page.evaluate(`(() => {
const scroll = document.querySelector(".run-scroll");
const header = [...document.querySelectorAll(".list.runs .day-header")]
.find((n) => /^\\d{1,2} \\w{3} \\d{4}$/.test(n.textContent));
if (!scroll || !header) return null;
scroll.scrollTop += header.getBoundingClientRect().top - scroll.getBoundingClientRect().top;
return header.textContent;
})()`);
if (!scrolledTo) throw new Error("could not scroll to the older day group");
shots.push(await page.screenshot(`${out}/10-runs-older-day-group.png`));
console.log(` scrolled to: ${scrolledTo}`);
step("opening the filter menu: it must stay in the viewport and be reachable");
await page.click("#runFilterBtn");
await page.waitForSelector("#runFilterMenu");
const menuLabels = await page.evaluate(
`[...document.querySelectorAll("#runFilterMenu .filter-check span")].map((n) => n.textContent)`,
);
for (const label of [
"queued",
"running",
"waiting",
"succeeded",
"failed",
"canceled",
"interrupted",
"Any pipeline",
"Any time",
"Today",
"Last 7 days",
"Last 30 days",
]) {
if (!menuLabels.includes(label)) throw new Error(`filter menu missing: ${label}`);
}
const menuActions = await page.evaluate(
`[...document.querySelectorAll("#runFilterMenu .menu-actions button")].map((n) => n.textContent)`,
);
for (const label of ["Clear filters", "Done"]) {
if (!menuActions.includes(label)) throw new Error(`filter menu action missing: ${label}`);
}
// The gate is reachability, not DOM presence: with a busy history the menu is
// taller than the viewport, so it must be bounded and scroll its own box rather
// than being clipped by an ancestor with no way for a user to reach the actions.
const reach = await page.evaluate(`(() => {
const menu = document.querySelector("#runFilterMenu");
const overflowY = getComputedStyle(menu).overflowY;
const rect = menu.getBoundingClientRect();
menu.scrollTop = menu.scrollHeight;
const actions = menu.querySelector(".menu-actions").getBoundingClientRect();
return {
overflowY,
height: Math.round(rect.height),
viewport: window.innerHeight,
fitsViewport: rect.height <= window.innerHeight && rect.bottom <= window.innerHeight + 1,
actionsReachable: actions.bottom <= window.innerHeight + 1 && actions.top >= -1,
};
})()`);
if (reach.overflowY !== "auto" && reach.overflowY !== "scroll") {
throw new Error(`the filter menu does not scroll its own box: overflow-y=${reach.overflowY}`);
}
if (!reach.fitsViewport) {
throw new Error(`the filter menu overflows the viewport: ${JSON.stringify(reach)}`);
}
if (!reach.actionsReachable) {
throw new Error(`the filter menu actions are unreachable: ${JSON.stringify(reach)}`);
}
shots.push(await page.screenshot(`${out}/11-runs-filter-menu.png`));
console.log(` filter menu ${reach.height}px tall in a ${reach.viewport}px viewport; actions reachable`);
step("applying a status filter");
await page.evaluate(
`document.querySelector('#runFilterMenu input[data-status="failed"]').click()`,
);
const filterLabel = await page.evaluate(`document.querySelector("#runFilterBtn").textContent`);
if (!filterLabel.includes("(1)")) {
throw new Error(`filter control is missing the active count: ${filterLabel}`);
}
await page.click("#runFilterBtn"); // close the menu so the list is unobstructed
const filteredChips = await page.evaluate(
`[...document.querySelectorAll(".list.runs .run-row .run-row-head .chip")].map((n) => n.textContent)`,
);
if (!filteredChips.length) throw new Error("the status filter produced no rows");
if (!filteredChips.every((chip) => chip === "failed")) {
throw new Error(`filtered rows are not all failed: ${filteredChips.join(",")}`);
}
shots.push(await page.screenshot(`${out}/12-runs-filtered.png`));
console.log(` filtered rows: ${filteredChips.length}, all failed`);
step("filtering to a state with no runs: the filtered-empty state + Clear filters");
await page.click("#runFilterBtn");
await page.waitForSelector("#runFilterMenu");
await page.evaluate(
`document.querySelector('#runFilterMenu input[data-status="failed"]').click()`,
);
await page.evaluate(
`document.querySelector('#runFilterMenu input[data-status="interrupted"]').click()`,
);
await page.click("#runFilterBtn"); // close the menu to see the list
await page.waitForSelector(".list.runs .empty-state");
const emptyMessage = await page.evaluate(
`document.querySelector(".list.runs .empty-state span")?.textContent ?? ""`,
);
if (emptyMessage !== "No runs match the current filters.") {
throw new Error(`unexpected filtered-empty message: ${emptyMessage}`);
}
const clearAction = await page.evaluate(
`document.querySelector(".list.runs .empty-state button")?.textContent ?? null`,
);
if (clearAction !== "Clear filters") {
throw new Error(`the filtered-empty state should offer Clear filters, got: ${clearAction}`);
}
shots.push(await page.screenshot(`${out}/13-runs-filtered-empty.png`));
console.log(` empty state: ${emptyMessage} (+ ${clearAction})`);
step("clearing the filters from the empty state and changing the sort");
await page.click(".list.runs .empty-state button");
await page.waitForSelector(".list.runs .day-header", { timeout: 25000 });
const resetLabel = await page.evaluate(`document.querySelector("#runFilterBtn").textContent`);
if (resetLabel.includes("(")) throw new Error(`Clear filters did not reset the count: ${resetLabel}`);
await page.click("#runSortBtn");
await page.waitForSelector("#runSortMenu");
const sortItems = await page.evaluate(
`[...document.querySelectorAll("#runSortMenu .menu-item")].map((n) => n.textContent)`,
);
for (const label of [
"Newest first",
"Oldest first",
"Longest duration",
"Shortest duration",
"Pipeline name",
"Status",
"Reset",
]) {
if (!sortItems.includes(label)) throw new Error(`sort menu missing: ${label}`);
}
shots.push(await page.screenshot(`${out}/14-runs-sort-menu.png`));
await page.clickText("#runSortMenu .menu-item", "Pipeline name");
const sortLabel = await page.evaluate(`document.querySelector("#runSortBtn").textContent`);
if (!sortLabel.includes("Pipeline name")) {
throw new Error(`the sort control did not change: ${sortLabel}`);
}
await page.waitForSelector(".list.runs .run-row", { timeout: 25000 });
shots.push(await page.screenshot(`${out}/15-runs-sorted.png`));
console.log(` sort control now: ${sortLabel}`);
step("opening a run detail");
await page.click(".list.runs .run-row");
await page.waitForSelector(".detail h2", { timeout: 25000 });
await shot("16-run-detail.png");
step("opening the Templates gallery");
await page.clickText("nav.tabs button.tab", "Templates");
await page.waitForSelector(".cards button.card", { timeout: 25000 });
shots.push(await page.screenshot(`${out}/17-templates-gallery.png`));
const templateCount = await page.evaluate(`document.querySelectorAll(".cards button.card").length`);
console.log(` templates rendered: ${templateCount}`);
step("opening a template detail (Summary)");
await page.click(".cards button.card");
await page.waitForSelector(".detail .tabstrip", { timeout: 25000 });
await page.waitForText("Key", { timeout: 25000 });
shots.push(await page.screenshot(`${out}/18-template-detail-summary.png`));
step("opening the template Source tab");
await page.clickText(".detail .tabstrip button.minitab", "Source");
await page.waitForText("Definition source", { timeout: 25000 });
shots.push(await page.screenshot(`${out}/19-template-source.png`));
// Artifact URLs resolve against whatever the URL field holds. Point it at the
// real server (the socket stays on the proxy, see the note above) so the tiles
// and the viewer load real files rather than proxying a path serve.mjs does
// not forward.
step("returning to Runs and opening run 430 (Summary tab)");
await page.fill("#url", artifactServerUrl);
await page.clickText("nav.tabs button.tab", "Runs");
await page.waitForSelector(".list.runs .run-row", { timeout: 25000 });
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).
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"])) {
throw new Error(`run tabs are wrong: ${runTabs.join(",")}`);
}
console.log(` run tabs: ${runTabs.join(" / ")}`);
// The run identity line, in the exact recorded/completed vocabulary.
const identity = await page.evaluate(`document.querySelector(".run-identity")?.textContent ?? ""`);
if (!/^run 430 · \d+ recorded visits? · \d+ completed visits?$/.test(identity)) {
throw new Error(`run identity line is wrong: ${identity}`);
}
const runTitle = await page.evaluate(
`document.querySelector(".run-detail-title")?.textContent ?? ""`,
);
console.log(` summary: ${runTitle} — ${identity}`);
shots.push(await page.screenshot(`${out}/20-run-430-summary.png`));
// The run-level artifacts gallery (R8), collapsed by default in Summary.
step("expanding run 430's summary artifacts section (R8)");
await page.clickText(".run-detail .section-toggle", "Artifacts");
await page.waitForSelector(".run-detail .artifact-gallery .artifact-tile", { timeout: 25000 });
const runTiles = await page.evaluate(
`document.querySelectorAll(".run-detail .artifact-gallery .artifact-tile").length`,
);
console.log(` run 430 run-level gallery tiles: ${runTiles}`);
if (runTiles !== 18) throw new Error(`expected 18 run-level artifact tiles, got ${runTiles}`);
await page.rect(".run-detail .artifact-gallery");
shots.push(await page.screenshot(`${out}/04-run-430-artifacts.png`));
step("opening an image artifact in the full-screen viewer");
await page.click(".run-detail .artifact-gallery .artifact-tile img");
await page.waitForSelector(".artifact-viewer", { timeout: 15000 });
await page.waitForText("Close viewer", { timeout: 15000 });
const position = await page.evaluate(
`document.querySelector(".viewer-position")?.textContent ?? ""`,
);
console.log(` viewer position: ${position}`);
// Best effort: give the full-resolution image a moment to decode.
await eventually(
() =>
page.evaluate(
`(() => { const i = document.querySelector(".viewer-image"); return !!i && i.complete && i.naturalWidth > 0; })()`,
),
{ timeout: 8000, what: "the viewer image" },
).catch(() => console.log(" (viewer image still loading)"));
shots.push(await page.screenshot(`${out}/05-artifact-viewer.png`));
await page.click(".viewer-close");
await eventually(() => page.evaluate(`!document.querySelector(".artifact-viewer")`), {
timeout: 5000,
what: "the viewer to close",
});
// R6: one collapsed field section per recorded input/output entry.
step("opening the Input tab and expanding a field section");
await page.clickText(".detail .detail-tabs .detail-tab", "Input");
await page.waitForSelector(".detail .run-tab-body .collapsible .section-toggle", { timeout: 15000 });
const inputEmpty = await page.evaluate(
`document.querySelector(".detail .run-tab-body .run-empty")?.textContent ?? ""`,
);
if (inputEmpty !== "") throw new Error(`run 430 input unexpectedly empty: ${inputEmpty}`);
await page.click(".detail .run-tab-body .collapsible .section-toggle");
await page.waitForSelector(".detail .run-tab-body .field-block", { timeout: 15000 });
const inputTitles = await page.evaluate(
`[...document.querySelectorAll(".detail .run-tab-body .section-title")].map((n) => n.textContent)`,
);
console.log(` input fields: ${inputTitles.join(", ")}`);
shots.push(await page.screenshot(`${out}/21-run-430-input.png`));
step("opening the Output tab and expanding a field section");
await page.clickText(".detail .detail-tabs .detail-tab", "Output");
await page.waitForSelector(".detail .run-tab-body .collapsible .section-toggle", { timeout: 15000 });
await page.click(".detail .run-tab-body .collapsible .section-toggle");
await page.waitForSelector(".detail .run-tab-body .field-block", { timeout: 15000 });
const outputTitles = await page.evaluate(
`[...document.querySelectorAll(".detail .run-tab-body .section-title")].map((n) => n.textContent)`,
);
console.log(` output fields: ${outputTitles.join(", ")}`);
shots.push(await page.screenshot(`${out}/22-run-430-output.png`));
// R7: one compact row per visit, in step order.
step("opening the Timeline tab");
await page.clickText(".detail .detail-tabs .detail-tab", "Timeline");
await page.waitForSelector(".detail .timeline-row", { timeout: 15000 });
const timelineRows = await page.evaluate(
`[...document.querySelectorAll(".detail .timeline-row .timeline-title")].map((n) => n.textContent)`,
);
console.log(` timeline: ${timelineRows.join(" | ")}`);
if (timelineRows.length !== 3) throw new Error(`expected 3 timeline rows, got ${timelineRows.length}`);
if (timelineRows[0] !== "reviewer · visit 3") {
throw new Error(`first timeline row is wrong: ${timelineRows[0]}`);
}
shots.push(await page.screenshot(`${out}/23-run-430-timeline.png`));
// R3: the stage pane: headline rows, Verdict block and the visit's gallery.
step("opening the ui_reviewer stage pane: headline, Verdict and its artifact gallery");
await page.click('.detail .timeline-row[data-stage-key="ui_reviewer"]');
await page.waitForSelector(".stage-pane", { timeout: 15000 });
await page.waitForText("Verdict", { timeout: 15000 });
const headline = await page.evaluate(
`[...document.querySelectorAll(".stage-pane-body > .kv-row > .kv-key")].map((n) => n.textContent)`,
);
console.log(` pane headline: ${headline.join(", ")}`);
for (const label of ["Status", "Outcome", "Duration", "Visit", "Target", "Session"]) {
if (!headline.includes(label)) throw new Error(`stage pane headline missing: ${label}`);
}
const verdictTitle = await page.evaluate(
`document.querySelector(".stage-pane .verdict-title")?.textContent ?? ""`,
);
const verdictOption = await page.evaluate(
`document.querySelector(".stage-pane .verdict .outcome-chip")?.textContent ?? ""`,
);
if (verdictTitle !== "Verdict") throw new Error(`verdict heading is wrong: ${verdictTitle}`);
console.log(` verdict: ${verdictTitle} — ${verdictOption}`);
await page.clickText(".stage-pane .section-toggle", "Artifacts");
await page.waitForSelector(".stage-pane .artifact-tile", { timeout: 15000 });
const paneTiles = await page.evaluate(`document.querySelectorAll(".stage-pane .artifact-tile").length`);
console.log(` ui_reviewer visit 2 pane tiles: ${paneTiles}`);
shots.push(await page.screenshot(`${out}/24-run-430-stage-artifacts.png`));
// Escape closes the pane and returns focus to the timeline row that opened it.
step("closing the pane with Escape returns focus to the timeline row");
await page.evaluate(
`document.dispatchEvent(new KeyboardEvent("keydown", { key: "Escape", bubbles: true }))`,
);
await eventually(() => page.evaluate(`!document.querySelector(".stage-pane")`), {
timeout: 5000,
what: "the stage pane to close on Escape",
});
const restored = await page.evaluate(
`(() => { const el = document.activeElement; return el ? el.getAttribute("data-stage-key") ?? "" : ""; })()`,
);
if (restored !== "ui_reviewer") throw new Error(`focus did not return to the timeline row: ${restored}`);
console.log(` focus returned to timeline row: ${restored}`);
// R9: the visit's exported session file, opened from the pane's Session section.
step("opening the reviewer stage pane and its Session export link (R9)");
await page.click('.detail .timeline-row[data-stage-key="reviewer"]');
await page.waitForSelector(".stage-pane", { timeout: 15000 });
await page.clickText(".stage-pane .section-toggle", "Session");
await page.waitForSelector(".stage-pane .session-link", { timeout: 15000 });
const sessionHref = await page.evaluate(
`document.querySelector(".stage-pane .session-link")?.getAttribute("href") ?? ""`,
);
if (!/session\.html$/.test(sessionHref)) {
throw new Error(`the session export link did not resolve: ${sessionHref}`);
}
console.log(` session export link: ${sessionHref}`);
shots.push(await page.screenshot(`${out}/06-session-export-link.png`));
await page.click(".stage-pane-back");
await eventually(() => page.evaluate(`!document.querySelector(".stage-pane")`), {
timeout: 5000,
what: "the stage pane to close on Back",
});
// The verdict-bearing stage pane on the failed run 440.
step("opening run 440 and capturing its verdict-bearing stage pane");
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", "Timeline");
await page.waitForSelector(".detail .timeline-row", { timeout: 15000 });
await page.click(".detail .timeline-row");
await page.waitForSelector(".stage-pane", { timeout: 15000 });
await page.waitForText("Verdict", { timeout: 15000 });
const verdict440 = await page.evaluate(
`document.querySelector(".stage-pane .verdict .outcome-chip")?.textContent ?? ""`,
);
console.log(` run 440 verdict: ${verdict440}`);
shots.push(await page.screenshot(`${out}/25-run-440-verdict.png`));
await page.evaluate(
`document.dispatchEvent(new KeyboardEvent("keydown", { key: "Escape", bubbles: true }))`,
);
await eventually(() => page.evaluate(`!document.querySelector(".stage-pane")`), {
timeout: 5000,
what: "the run 440 pane to close",
});
// The Timeline empty state, on a run that recorded no visits (R7).
step("opening run 428: the Timeline empty state");
await page.click('.list.runs .run-row-meta[data-run-id="428"]');
await page.waitForSelector(".detail .detail-tabs", { timeout: 25000 });
await page.clickText(".detail .detail-tabs .detail-tab", "Timeline");
await page.waitForSelector(".detail .run-tab-body .run-empty", { timeout: 15000 });
const emptyTimeline = await page.evaluate(
`document.querySelector(".detail .run-tab-body .run-empty")?.textContent ?? ""`,
);
if (emptyTimeline !== "No visits recorded.") {
throw new Error(`timeline empty state is wrong: ${emptyTimeline}`);
}
console.log(` timeline empty state: ${emptyTimeline}`);
shots.push(await page.screenshot(`${out}/26-run-428-timeline-empty.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(`(() => {
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 (runningId == null) {
console.log(" -- no running run available; skipped the output empty state");
} else {
await page.click(`.list.runs .run-row-meta[data-run-id="${runningId}"]`);
await page.waitForSelector(".detail .detail-tabs", { timeout: 25000 });
await page.clickText(".detail .detail-tabs .detail-tab", "Output");
await page.waitForSelector(".detail .run-tab-body .run-empty", { timeout: 15000 });
const emptyOutput = await page.evaluate(
`document.querySelector(".detail .run-tab-body .run-empty")?.textContent ?? ""`,
);
if (emptyOutput !== "No output recorded.") {
throw new Error(`output empty state is wrong: ${emptyOutput}`);
}
console.log(` output empty state (run ${runningId}): ${emptyOutput}`);
shots.push(await page.screenshot(`${out}/27-run-output-empty.png`));
}
console.log("\nUI SMOKE PASS");
for (const shot of shots) console.log(` ${shot}`);
} catch (error) {
failed = true;
console.error(`\nUI SMOKE FAIL: ${error.message}`);
if (page) {
try {
shots.push(await page.screenshot(`${out}/failure.png`));
console.error(` failure capture: ${shots.at(-1)}`);
console.error((await page.text()).split("\n").slice(0, 25).join("\n"));
} catch {
// the page may be gone; the error above is the real signal
}
}
} finally {
await page?.close().catch(() => {});
await browser?.close().catch(() => {});
serve?.kill("SIGTERM");
await eventually(async () => serve?.exitCode != null, { timeout: 5000, what: "serve exit" }).catch(
() => {},
);
if (!failed) await rm(`${out}/failure.png`, { force: true }).catch(() => {});
}
process.exit(failed ? 1 : 0);