67120947c2
Port the Android artifact derivation into a pure, DOM-free src/artifacts.js (presentedArtifacts with the retired session.md hidden everywhere, grouping by stage/visit, the header/summary/capture-note wording, kind and size formatting, viewer paging and sessionExportArtifact) and unit-test it. Wire it into src/app.js: a run-level artifacts gallery with per-(stage,visit) groups, per-visit summaries and tiles, a full-screen viewer overlay (paging, Escape/backdrop close) and the read-only session.html link. Every server string is set with textContent; captures/ stays untracked. Captured live against run 430 through test/ui-smoke.mjs: captures/04-run-430-artifacts.png, 05-artifact-viewer.png, 06-session-export-link.png. PARITY.md marks R8 and R9 done.
172 lines
7.0 KiB
JavaScript
172 lines
7.0 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}`);
|
|
}
|
|
|
|
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(".list button.row").length`,
|
|
);
|
|
if (!pipelineCount) throw new Error("connected but no pipelines rendered");
|
|
|
|
shots.push(await page.screenshot(`${out}/01-pipelines.png`));
|
|
console.log(` pipelines rendered: ${pipelineCount}`);
|
|
|
|
step("opening a pipeline detail");
|
|
await page.click(".list button.row");
|
|
await page.waitForSelector(".detail h2");
|
|
shots.push(await page.screenshot(`${out}/02-pipeline-detail.png`));
|
|
|
|
step("switching to Runs and opening a run detail");
|
|
await page.clickText("nav.tabs button.tab", "Runs");
|
|
await page.waitForSelector(".list button.row", { timeout: 25000 });
|
|
await page.click(".list button.row");
|
|
await page.waitForSelector(".detail h2", { timeout: 25000 });
|
|
shots.push(await page.screenshot(`${out}/03-run-detail.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(`opening run 430 and capturing its artifacts gallery`);
|
|
await page.fill("#url", artifactServerUrl);
|
|
await page.clickText(".list button.row", "#430");
|
|
await page.waitForSelector(".artifact-gallery .artifact-tile", { timeout: 25000 });
|
|
await page.waitForText("recorded", { timeout: 25000 });
|
|
const tileCount = await page.evaluate(
|
|
`document.querySelectorAll(".artifact-gallery .artifact-tile").length`,
|
|
);
|
|
if (!tileCount) throw new Error("run 430 rendered no artifact tiles");
|
|
console.log(` run 430 gallery tiles: ${tileCount}`);
|
|
await page.rect(".artifacts-header");
|
|
shots.push(await page.screenshot(`${out}/04-run-430-artifacts.png`));
|
|
|
|
step("opening an image artifact in the full-screen viewer");
|
|
await page.click(".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`));
|
|
|
|
step("closing the viewer and capturing the session export link (R9)");
|
|
await page.click(".viewer-close");
|
|
await eventually(
|
|
() => page.evaluate(`!document.querySelector(".artifact-viewer")`),
|
|
{ timeout: 5000, what: "the viewer to close" },
|
|
);
|
|
await page.rect(".session-link");
|
|
const sessionHref = await page.evaluate(
|
|
`document.querySelector(".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`));
|
|
|
|
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);
|