aed65a7431
# Conflicts: # web/src/app.js # web/styles.css
378 lines
16 KiB
JavaScript
378 lines
16 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")),
|
|
);
|
|
|
|
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 ?? ""`);
|
|
|
|
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).
|
|
step("opening a pipeline detail (Summary)");
|
|
await page.click("#pipelineRows button.row");
|
|
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: the guidance note only; the rendered graph is P6.
|
|
step("opening the Graph tab (guidance note only)");
|
|
await page.clickText(".detail-tabs button", "Graph");
|
|
await page.waitForSelector(".graph-note");
|
|
await shot("08-pipeline-graph.png");
|
|
|
|
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`));
|
|
|
|
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);
|