web: URL routes, deep links and history navigation (L6)
This commit is contained in:
@@ -0,0 +1,288 @@
|
||||
// Unit tests for the pure URL route model (web/src/routes.js). No DOM and no
|
||||
// server: every case here is a claim the live UI smoke relies on.
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import {
|
||||
DEFAULT_ROUTE,
|
||||
parseRoute,
|
||||
sameRoute,
|
||||
serializeRoute,
|
||||
} from "../src/routes.js";
|
||||
|
||||
const defaultRoute = () => ({ ...DEFAULT_ROUTE });
|
||||
|
||||
test("default destination: empty, root, unknown and malformed paths", () => {
|
||||
for (const path of [
|
||||
undefined,
|
||||
null,
|
||||
"",
|
||||
"/",
|
||||
"///",
|
||||
"/nope",
|
||||
"/pipelinesx",
|
||||
"/runs/abc",
|
||||
"/runs/0",
|
||||
"/runs/-1",
|
||||
"/runs/1x",
|
||||
"/pipelines/x",
|
||||
"/pipelines/24/-1",
|
||||
"/pipelines/24/1x",
|
||||
"/pipelines/24/5/nope",
|
||||
"/pipelines/24/5/stage",
|
||||
"/runs/440/stage",
|
||||
// A trailing segment on a versionless stage branch is malformed, not a
|
||||
// dropped visit or an ignored extra: both stage branches require exactly
|
||||
// four segments (the versioned pipeline branch already rejected extras).
|
||||
"/runs/440/stage/planner/extra",
|
||||
"/runs/440/stage/planner/2",
|
||||
"/pipelines/24/stage/planner/extra",
|
||||
"/pipelines/24/stage/planner/2",
|
||||
"/runs/%E0%A4%A",
|
||||
"/pipelines/%E0%A4%A",
|
||||
"/templates/%E0%A4%A",
|
||||
"/runs/440/stage/%E0%A4%A",
|
||||
]) {
|
||||
assert.deepEqual(parseRoute(path), defaultRoute(), `path ${JSON.stringify(path)}`);
|
||||
}
|
||||
});
|
||||
|
||||
test("top-level destinations", () => {
|
||||
assert.deepEqual(parseRoute("/pipelines"), { kind: "pipelines" });
|
||||
assert.deepEqual(parseRoute("/runs"), { kind: "runs" });
|
||||
assert.deepEqual(parseRoute("/chat"), { kind: "chat" });
|
||||
assert.deepEqual(parseRoute("/settings"), { kind: "settings" });
|
||||
assert.deepEqual(parseRoute("/templates"), { kind: "templates" });
|
||||
});
|
||||
|
||||
test("trailing slashes are normalised and location-style strings accepted", () => {
|
||||
assert.deepEqual(parseRoute("/runs/"), { kind: "runs" });
|
||||
assert.deepEqual(parseRoute("/runs/440/"), { kind: "run", id: 440 });
|
||||
assert.deepEqual(parseRoute("http://127.0.0.1:8090/runs/440?visit=2"), {
|
||||
kind: "run",
|
||||
id: 440,
|
||||
});
|
||||
assert.deepEqual(parseRoute("http://127.0.0.1:8090/runs/440"), { kind: "run", id: 440 });
|
||||
assert.deepEqual(parseRoute("/runs/440?action=decide"), { kind: "run", id: 440, action: "decide" });
|
||||
});
|
||||
|
||||
test("pipeline detail: absent and zero versions are the same latest route", () => {
|
||||
const latest = { kind: "pipeline", id: 24, version: 0 };
|
||||
assert.deepEqual(parseRoute("/pipelines/24"), latest);
|
||||
assert.deepEqual(parseRoute("/pipelines/24/0"), latest);
|
||||
assert.deepEqual(parseRoute("/pipelines/24/5"), { kind: "pipeline", id: 24, version: 5 });
|
||||
assert.equal(serializeRoute(parseRoute("/pipelines/24")), "/pipelines/24");
|
||||
assert.equal(serializeRoute(parseRoute("/pipelines/24/0")), "/pipelines/24");
|
||||
assert.equal(serializeRoute(parseRoute("/pipelines/24/5")), "/pipelines/24/5");
|
||||
});
|
||||
|
||||
test("run detail and the optional decide action", () => {
|
||||
assert.deepEqual(parseRoute("/runs/440"), { kind: "run", id: 440 });
|
||||
assert.deepEqual(parseRoute("/runs/440?action=decide"), { kind: "run", id: 440, action: "decide" });
|
||||
assert.equal(serializeRoute({ kind: "run", id: 440 }), "/runs/440");
|
||||
assert.equal(serializeRoute({ kind: "run", id: 440, action: "decide" }), "/runs/440?action=decide");
|
||||
});
|
||||
|
||||
test("run stage: optional zero-based visit, invalid visit dropped", () => {
|
||||
assert.deepEqual(parseRoute("/runs/440/stage/planner"), {
|
||||
kind: "runStage",
|
||||
id: 440,
|
||||
stageKey: "planner",
|
||||
});
|
||||
assert.deepEqual(parseRoute("/runs/440/stage/planner", "?visit=2"), {
|
||||
kind: "runStage",
|
||||
id: 440,
|
||||
stageKey: "planner",
|
||||
visit: 2,
|
||||
});
|
||||
assert.deepEqual(parseRoute("/runs/440/stage/planner?visit=0"), {
|
||||
kind: "runStage",
|
||||
id: 440,
|
||||
stageKey: "planner",
|
||||
visit: 0,
|
||||
});
|
||||
// An invalid visit is dropped while the stage route is kept.
|
||||
for (const query of ["?visit=-1", "?visit=x", "?visit=", "?visit=1.5"]) {
|
||||
assert.deepEqual(parseRoute("/runs/440/stage/planner", query), {
|
||||
kind: "runStage",
|
||||
id: 440,
|
||||
stageKey: "planner",
|
||||
});
|
||||
}
|
||||
assert.equal(
|
||||
serializeRoute({ kind: "runStage", id: 440, stageKey: "planner" }),
|
||||
"/runs/440/stage/planner",
|
||||
);
|
||||
assert.equal(
|
||||
serializeRoute({ kind: "runStage", id: 440, stageKey: "planner", visit: 0 }),
|
||||
"/runs/440/stage/planner?visit=0",
|
||||
);
|
||||
assert.equal(
|
||||
serializeRoute({ kind: "runStage", id: 440, stageKey: "planner", visit: -1 }),
|
||||
"/runs/440/stage/planner",
|
||||
);
|
||||
});
|
||||
|
||||
test("pipeline stage routes, with and without an explicit version", () => {
|
||||
assert.deepEqual(parseRoute("/pipelines/24/5/stage/planner"), {
|
||||
kind: "pipelineStage",
|
||||
id: 24,
|
||||
version: 5,
|
||||
stageKey: "planner",
|
||||
});
|
||||
assert.deepEqual(parseRoute("/pipelines/24/stage/planner"), {
|
||||
kind: "pipelineStage",
|
||||
id: 24,
|
||||
version: 0,
|
||||
stageKey: "planner",
|
||||
});
|
||||
assert.deepEqual(parseRoute("/pipelines/24/0/stage/planner"), {
|
||||
kind: "pipelineStage",
|
||||
id: 24,
|
||||
version: 0,
|
||||
stageKey: "planner",
|
||||
});
|
||||
assert.equal(
|
||||
serializeRoute({ kind: "pipelineStage", id: 24, version: 5, stageKey: "planner" }),
|
||||
"/pipelines/24/5/stage/planner",
|
||||
);
|
||||
assert.equal(
|
||||
serializeRoute({ kind: "pipelineStage", id: 24, version: 0, stageKey: "planner" }),
|
||||
"/pipelines/24/stage/planner",
|
||||
);
|
||||
});
|
||||
|
||||
test("templates gallery and detail, including the /settings aliases", () => {
|
||||
assert.deepEqual(parseRoute("/templates"), { kind: "templates" });
|
||||
assert.deepEqual(parseRoute("/settings/templates"), { kind: "templates" });
|
||||
assert.deepEqual(parseRoute("/templates/plan"), { kind: "template", key: "plan" });
|
||||
assert.deepEqual(parseRoute("/settings/templates/plan"), { kind: "template", key: "plan" });
|
||||
assert.equal(serializeRoute({ kind: "template", key: "plan" }), "/templates/plan");
|
||||
assert.equal(
|
||||
serializeRoute(parseRoute("/settings/templates/plan")),
|
||||
"/templates/plan",
|
||||
);
|
||||
});
|
||||
|
||||
test("unknown query state is ignored; only action and visit are read", () => {
|
||||
assert.deepEqual(parseRoute("/runs/440", "?q=plan&kind=runs&sort=name"), {
|
||||
kind: "run",
|
||||
id: 440,
|
||||
});
|
||||
assert.deepEqual(parseRoute("/runs", "?q=plan&kind=pipelines&sort=newest"), { kind: "runs" });
|
||||
assert.deepEqual(parseRoute("/runs/440?visit=2"), { kind: "run", id: 440 });
|
||||
assert.deepEqual(parseRoute("/runs/440/stage/planner?visit=2&q=x"), {
|
||||
kind: "runStage",
|
||||
id: 440,
|
||||
stageKey: "planner",
|
||||
visit: 2,
|
||||
});
|
||||
});
|
||||
|
||||
test("stage and template keys are percent-encoded and round-trip", () => {
|
||||
const stageKey = "plan/land & go";
|
||||
const templateKey = "a b/c?d#e";
|
||||
// A dotted key stays one path segment; serve.mjs must not mistake it for an
|
||||
// asset when the shell is requested for a hard navigation.
|
||||
assert.deepEqual(parseRoute(serializeRoute({ kind: "pipelineStage", id: 7, version: 2, stageKey: "plan.v2" })), {
|
||||
kind: "pipelineStage",
|
||||
id: 7,
|
||||
version: 2,
|
||||
stageKey: "plan.v2",
|
||||
});
|
||||
const stage = parseRoute(serializeRoute({ kind: "runStage", id: 7, stageKey, visit: 3 }));
|
||||
assert.deepEqual(stage, { kind: "runStage", id: 7, stageKey, visit: 3 });
|
||||
assert.equal(
|
||||
serializeRoute({ kind: "pipelineStage", id: 7, version: 2, stageKey }),
|
||||
"/pipelines/7/2/stage/plan%2Fland%20%26%20go",
|
||||
);
|
||||
assert.deepEqual(parseRoute(serializeRoute({ kind: "template", key: templateKey })), {
|
||||
kind: "template",
|
||||
key: templateKey,
|
||||
});
|
||||
assert.equal(serializeRoute({ kind: "template", key: templateKey }), "/templates/a%20b%2Fc%3Fd%23e");
|
||||
});
|
||||
|
||||
test("serialisation is idempotent and parse(serialize(route)) preserves every route", () => {
|
||||
const routes = [
|
||||
{ kind: "pipelines" },
|
||||
{ kind: "runs" },
|
||||
{ kind: "chat" },
|
||||
{ kind: "settings" },
|
||||
{ kind: "templates" },
|
||||
{ kind: "template", key: "plan" },
|
||||
{ kind: "pipeline", id: 24, version: 0 },
|
||||
{ kind: "pipeline", id: 24, version: 5 },
|
||||
{ kind: "pipelineStage", id: 24, version: 0, stageKey: "planner" },
|
||||
{ kind: "pipelineStage", id: 24, version: 5, stageKey: "plan/land" },
|
||||
{ kind: "run", id: 440 },
|
||||
{ kind: "run", id: 440, action: "decide" },
|
||||
{ kind: "runStage", id: 440, stageKey: "planner" },
|
||||
{ kind: "runStage", id: 440, stageKey: "plan/land", visit: 0 },
|
||||
];
|
||||
for (const route of routes) {
|
||||
const url = serializeRoute(route);
|
||||
const parsed = parseRoute(url);
|
||||
assert.equal(serializeRoute(parsed), url, `route ${JSON.stringify(route)}`);
|
||||
assert.ok(sameRoute(parsed, route), `sameRoute ${JSON.stringify(route)}`);
|
||||
}
|
||||
});
|
||||
|
||||
test("sameRoute compares the canonical serialised form", () => {
|
||||
assert.ok(sameRoute({ kind: "pipeline", id: 24 }, { kind: "pipeline", id: 24, version: 0 }));
|
||||
assert.ok(
|
||||
sameRoute(
|
||||
parseRoute("/settings/templates/plan"),
|
||||
{ kind: "template", key: "plan" },
|
||||
),
|
||||
);
|
||||
assert.ok(!sameRoute({ kind: "run", id: 440 }, { kind: "run", id: 440, action: "decide" }));
|
||||
assert.ok(!sameRoute({ kind: "runs" }, { kind: "pipelines" }));
|
||||
});
|
||||
|
||||
test("a bad route object serialises to the default, never throws", () => {
|
||||
assert.equal(serializeRoute(null), "/pipelines");
|
||||
assert.equal(serializeRoute({}), "/pipelines");
|
||||
assert.equal(serializeRoute({ kind: "unknown" }), "/pipelines");
|
||||
assert.equal(serializeRoute({ kind: "pipeline" }), "/pipelines");
|
||||
assert.equal(serializeRoute({ kind: "runStage", id: 1 }), "/runs");
|
||||
});
|
||||
|
||||
test("the serialiser rejects ids/versions the parser would not accept", () => {
|
||||
// An invalid id cannot name an entity; the nearest canonical route is the list.
|
||||
for (const id of [0, -1, 1.5, NaN, Infinity, "abc", "", null]) {
|
||||
assert.equal(serializeRoute({ kind: "pipeline", id }), "/pipelines", `pipeline id ${String(id)}`);
|
||||
assert.equal(serializeRoute({ kind: "run", id }), "/runs", `run id ${String(id)}`);
|
||||
assert.equal(
|
||||
serializeRoute({ kind: "runStage", id, stageKey: "planner" }),
|
||||
"/runs",
|
||||
`runStage id ${String(id)}`,
|
||||
);
|
||||
}
|
||||
// An invalid or negative version falls back to the latest form, which parses
|
||||
// back to the same route instead of emitting a path the parser rejects.
|
||||
for (const version of [-1, 1.5, NaN, "abc", ""]) {
|
||||
assert.equal(
|
||||
serializeRoute({ kind: "pipeline", id: 24, version }),
|
||||
"/pipelines/24",
|
||||
`pipeline version ${String(version)}`,
|
||||
);
|
||||
assert.equal(
|
||||
serializeRoute({ kind: "pipelineStage", id: 24, version, stageKey: "planner" }),
|
||||
"/pipelines/24/stage/planner",
|
||||
`pipelineStage version ${String(version)}`,
|
||||
);
|
||||
assert.deepEqual(parseRoute(serializeRoute({ kind: "pipelineStage", id: 24, version, stageKey: "planner" })), {
|
||||
kind: "pipelineStage",
|
||||
id: 24,
|
||||
version: 0,
|
||||
stageKey: "planner",
|
||||
});
|
||||
}
|
||||
// A blank or non-string key cannot describe a stage/template.
|
||||
assert.equal(serializeRoute({ kind: "pipelineStage", id: 24, stageKey: "" }), "/pipelines");
|
||||
assert.equal(serializeRoute({ kind: "runStage", id: 440, stageKey: "" }), "/runs");
|
||||
assert.equal(serializeRoute({ kind: "template", key: "" }), "/templates");
|
||||
// A canonical numeric string is emitted as the number the parser reads back.
|
||||
assert.equal(serializeRoute({ kind: "run", id: "440" }), "/runs/440");
|
||||
assert.equal(serializeRoute({ kind: "pipeline", id: "24", version: "5" }), "/pipelines/24/5");
|
||||
});
|
||||
+448
-6
@@ -108,13 +108,38 @@ const showComposer = () =>
|
||||
// its `online` handler resets the backoff — and waits for the green banner
|
||||
// before the step reads anything.
|
||||
async function ensureConnected(timeout = 25000) {
|
||||
const ok = await page.evaluate(
|
||||
`document.querySelector(".conn-banner")?.classList.contains("conn-ok") ?? false`,
|
||||
);
|
||||
if (!ok) await page.evaluate(`window.dispatchEvent(new Event("online"))`);
|
||||
await page.waitForSelector(".conn-banner.conn-ok", { timeout });
|
||||
const deadline = Date.now() + timeout;
|
||||
while (Date.now() < deadline) {
|
||||
const ok = await page.evaluate(
|
||||
`document.querySelector(".conn-banner")?.classList.contains("conn-ok") ?? false`,
|
||||
);
|
||||
if (ok) return;
|
||||
// The page's own recovery path: an `online` event resets the client's
|
||||
// backoff and re-opens the configured endpoint. A dropped long-lived socket
|
||||
// can take a few tries on the shared server, so nudge until the deadline.
|
||||
await page.evaluate(`window.dispatchEvent(new Event("online"))`);
|
||||
await new Promise((resolve) => setTimeout(resolve, 1000));
|
||||
}
|
||||
// One last honest wait, so the failure names the banner selector.
|
||||
await page.waitForSelector(".conn-banner.conn-ok", { timeout: 2000 });
|
||||
}
|
||||
|
||||
/**
|
||||
* Hard-navigate to a page route and connect, exactly as a pasted link would: a
|
||||
* full document load parses the URL at boot and keeps it pending until the socket
|
||||
* comes up. The configured endpoint is already in localStorage from the live
|
||||
* run's first connection, so clicking Connect is the same user action.
|
||||
*/
|
||||
async function openDeepLink(path) {
|
||||
await page.goto(`http://127.0.0.1:${port}${path}`);
|
||||
await page.waitForSelector("#connectBtn", { timeout: 15000 });
|
||||
await page.click("#connectBtn");
|
||||
await ensureConnected(30000);
|
||||
}
|
||||
|
||||
/** The current path+query the page shows. */
|
||||
const currentLocation = () => page.evaluate(`location.pathname + location.search`);
|
||||
|
||||
// Open a run's detail. The connection is asserted first, and if the socket drops
|
||||
// between steps the page's reconnect does not replay the detail request, so the
|
||||
// click is retried once after re-establishing the connection.
|
||||
@@ -2126,7 +2151,9 @@ try {
|
||||
}
|
||||
|
||||
step("Closing search clears the query and leaves the view intact (S1)");
|
||||
await searchTargets("release", "field");
|
||||
// `plan` is known to return field hits (the emphasis step above uses it); the
|
||||
// close assertion only needs a query in flight, not a particular kind.
|
||||
await searchTargets(SEARCH_QUERY, "field");
|
||||
const beforeClose = await viewSnapshot();
|
||||
await page.click("#searchClose");
|
||||
await eventually(() => page.evaluate(`!document.querySelector("#searchInput")`), {
|
||||
@@ -4684,6 +4711,421 @@ try {
|
||||
);
|
||||
console.log(" chat_shells re-fetched after the stream reconnect (real request)");
|
||||
|
||||
// --- L6: URL routes, deep links and history -------------------------------
|
||||
// Every later hard navigation records uncaught errors/unhandled rejections, so
|
||||
// a route that throws can never pass as a rendered fallback.
|
||||
await page.addInitScript(`(() => {
|
||||
window.__pipelinesPageErrors = [];
|
||||
window.addEventListener("error", (event) => {
|
||||
window.__pipelinesPageErrors.push(String(event.message || event.error || "error"));
|
||||
});
|
||||
window.addEventListener("unhandledrejection", (event) => {
|
||||
window.__pipelinesPageErrors.push(String(event.reason || "unhandled rejection"));
|
||||
});
|
||||
})()`);
|
||||
|
||||
step("L6: deep links, URL routing and Back/Forward");
|
||||
await page.clickText("nav.tabs button.tab", "Runs");
|
||||
await page.waitForSelector(".list.runs .run-row", { timeout: 25000 });
|
||||
const discovered = await page.evaluate(`(() => {
|
||||
const rows = [...document.querySelectorAll(".list.runs .run-row")];
|
||||
const idOf = (row) =>
|
||||
Number(row.querySelector(".run-row-meta[data-run-id]")?.dataset.runId ?? 0);
|
||||
const ids = rows.map(idOf).filter((id) => id > 0);
|
||||
const waitingRow = rows.find((row) => row.querySelector(".chip-waiting"));
|
||||
return {
|
||||
ids,
|
||||
preferred: ids.includes(440) ? 440 : (ids[0] ?? 0),
|
||||
waiting: waitingRow ? idOf(waitingRow) : 0,
|
||||
};
|
||||
})()`);
|
||||
if (!discovered.preferred) throw new Error("L6: no real run id on the Runs list");
|
||||
console.log(
|
||||
` live run ids on the list: ${discovered.ids.join(", ")} (using ${discovered.preferred})`,
|
||||
);
|
||||
|
||||
// An in-page pipeline selection is a real pushState: the detail route records
|
||||
// the id and version, and the hard link below uses the id it found.
|
||||
await page.clickText("nav.tabs button.tab", "Pipelines");
|
||||
await page.waitForSelector("#pipelineRows button.row", { timeout: 25000 });
|
||||
const pipelineSelection = await page.evaluate(`(async () => {
|
||||
const rows = [...document.querySelectorAll("#pipelineRows button.row")];
|
||||
const row =
|
||||
rows.find((candidate) =>
|
||||
(candidate.querySelector(".row-title")?.textContent ?? "").includes("Plan and land"),
|
||||
) ?? rows[0];
|
||||
if (!row) return null;
|
||||
row.click();
|
||||
const deadline = Date.now() + 20000;
|
||||
while (Date.now() < deadline) {
|
||||
if (document.querySelector(".detail h2")) break;
|
||||
await new Promise((resolve) => setTimeout(resolve, 100));
|
||||
}
|
||||
return {
|
||||
path: location.search ? location.pathname + location.search : location.pathname,
|
||||
name: document.querySelector(".detail h2")?.textContent ?? "",
|
||||
};
|
||||
})()`);
|
||||
if (!pipelineSelection?.path) throw new Error("L6: the pipeline detail did not open");
|
||||
const pipelineId = Number((/^\/pipelines\/([0-9]+)/.exec(pipelineSelection.path) ?? [])[1] ?? 0);
|
||||
if (!pipelineId) throw new Error(`L6: pipeline detail route ${JSON.stringify(pipelineSelection.path)}`);
|
||||
console.log(
|
||||
` in-page pipeline selection pushed ${pipelineSelection.path} (${JSON.stringify(pipelineSelection.name)})`,
|
||||
);
|
||||
|
||||
// A hard navigation to a run route: boot parses the URL, the first connection
|
||||
// loads the runs list and then the run, and the detail owns the requested id.
|
||||
const runPath = `/runs/${discovered.preferred}`;
|
||||
await openDeepLink(runPath);
|
||||
await eventually(
|
||||
() =>
|
||||
page.evaluate(
|
||||
`document.querySelector(".run-detail .run-identity")?.textContent?.startsWith("run ${discovered.preferred} ") ?? false`,
|
||||
),
|
||||
{ timeout: 30000, what: `the deep-linked run ${discovered.preferred}` },
|
||||
);
|
||||
const deepRunUrl = await currentLocation();
|
||||
if (deepRunUrl !== runPath) throw new Error(`L6: run URL is ${deepRunUrl}, expected ${runPath}`);
|
||||
// The nav badge reads the pipeline count; a run deep link must not leave a
|
||||
// false `Pipelines (0)` beside a populated list.
|
||||
const runNav = await page.evaluate(
|
||||
`[...document.querySelectorAll("nav.tabs button.tab")].map((b) => b.textContent.trim())`,
|
||||
);
|
||||
const pipelinesTab = runNav.find((label) => label.startsWith("Pipelines")) ?? "";
|
||||
if (pipelinesTab === "Pipelines (0)") {
|
||||
throw new Error(`L6: the run deep link left a false Pipelines (0) in the nav: ${JSON.stringify(runNav)}`);
|
||||
}
|
||||
console.log(` hard navigation ${runPath} opened run ${discovered.preferred}'s detail; nav ${JSON.stringify(runNav)}`);
|
||||
await shot(`L6-deeplink-run-${discovered.preferred}.png`);
|
||||
|
||||
// The same for a pipeline route: /pipelines/:id means latest.
|
||||
const pipelinePath = `/pipelines/${pipelineId}`;
|
||||
await openDeepLink(pipelinePath);
|
||||
await eventually(
|
||||
() => page.evaluate(`!!document.querySelector(".detail h2")`),
|
||||
{ timeout: 30000, what: `the deep-linked pipeline ${pipelineId}` },
|
||||
);
|
||||
const deepPipeline = await page.evaluate(`(() => ({
|
||||
path: location.pathname + location.search,
|
||||
name: document.querySelector(".detail h2")?.textContent ?? "",
|
||||
}))()`);
|
||||
if (deepPipeline.path !== pipelinePath) {
|
||||
throw new Error(`L6: pipeline URL is ${deepPipeline.path}, expected ${pipelinePath}`);
|
||||
}
|
||||
if (pipelineSelection.name && deepPipeline.name !== pipelineSelection.name) {
|
||||
throw new Error(
|
||||
`L6: deep-linked pipeline rendered ${JSON.stringify(deepPipeline.name)}, expected ${JSON.stringify(pipelineSelection.name)}`,
|
||||
);
|
||||
}
|
||||
console.log(` hard navigation ${pipelinePath} opened ${JSON.stringify(deepPipeline.name)}`);
|
||||
await shot(`L6-deeplink-pipeline-${pipelineId}.png`);
|
||||
|
||||
// A pipeline-stage route opens the Graph tab and the named definition pane,
|
||||
// and brings that pane into view (the graph above it is taller than a viewport).
|
||||
const stagePath = `/pipelines/${pipelineId}/stage/planner`;
|
||||
await openDeepLink(stagePath);
|
||||
await eventually(
|
||||
() =>
|
||||
page.evaluate(
|
||||
`document.querySelector(".detail-tab.active")?.textContent === "Graph" &&
|
||||
!!document.querySelector(".graph-pane") && !document.querySelector(".graph-pane").hidden`,
|
||||
),
|
||||
{ timeout: 30000, what: "the deep-linked pipeline stage pane" },
|
||||
);
|
||||
const stageState = await page.evaluate(`(() => {
|
||||
const pane = document.querySelector(".graph-pane");
|
||||
const rect = pane.getBoundingClientRect();
|
||||
const head = document.querySelector(".graph-pane-head")?.getBoundingClientRect() ?? null;
|
||||
const close = document.querySelector(".graph-pane-close")?.getBoundingClientRect() ?? null;
|
||||
const topbar = document.querySelector(".topbar")?.getBoundingClientRect() ?? null;
|
||||
return {
|
||||
path: location.pathname + location.search,
|
||||
tab: document.querySelector(".detail-tab.active")?.textContent ?? "",
|
||||
title: document.querySelector(".graph-pane-title")?.textContent ?? "",
|
||||
top: Math.round(rect.top),
|
||||
viewport: window.innerHeight,
|
||||
topbarBottom: topbar ? Math.round(topbar.bottom) : 0,
|
||||
headTop: head ? Math.round(head.top) : null,
|
||||
headBottom: head ? Math.round(head.bottom) : null,
|
||||
closeTop: close ? Math.round(close.top) : null,
|
||||
};
|
||||
})()`);
|
||||
if (stageState.path !== stagePath) throw new Error(`L6: pipeline stage URL is ${stageState.path}`);
|
||||
if (stageState.tab !== "Graph") throw new Error(`L6: pipeline stage opened tab ${stageState.tab}`);
|
||||
if (!stageState.title) throw new Error("L6: the pipeline stage pane has no title");
|
||||
if (stageState.headTop == null || stageState.headTop < stageState.topbarBottom) {
|
||||
throw new Error(
|
||||
`L6: the opened stage pane head (top ${stageState.headTop}) is hidden under the sticky top bar (bottom ${stageState.topbarBottom})`,
|
||||
);
|
||||
}
|
||||
if (stageState.headBottom > stageState.viewport) {
|
||||
throw new Error(`L6: the opened stage pane head is below the viewport (bottom ${stageState.headBottom})`);
|
||||
}
|
||||
if (stageState.closeTop == null || stageState.closeTop < stageState.topbarBottom) {
|
||||
throw new Error(
|
||||
`L6: the stage pane Close control (top ${stageState.closeTop}) is hidden under the top bar (bottom ${stageState.topbarBottom})`,
|
||||
);
|
||||
}
|
||||
console.log(
|
||||
` hard navigation ${stagePath} opened the Graph tab and the ${JSON.stringify(stageState.title)} pane (head ${stageState.headTop}px, top bar ${stageState.topbarBottom}px)`,
|
||||
);
|
||||
await shot(`L6-deeplink-pipeline-${pipelineId}-stage.png`);
|
||||
|
||||
// The graph also selects its terminals, and the URL it pushes for one must
|
||||
// re-open the same pane (a terminal is not a named stage, but it is a node the
|
||||
// page itself writes a /stage/ URL for). Find a terminal in the live graph.
|
||||
const terminalKey = await page.evaluate(`(() => {
|
||||
const node = [...document.querySelectorAll(".graph-node[data-key]")]
|
||||
.find((n) => (n.dataset.key ?? "").startsWith("#"));
|
||||
return node?.dataset.key ?? "";
|
||||
})()`);
|
||||
if (terminalKey) {
|
||||
const terminalPath = `/pipelines/${pipelineId}/stage/${encodeURIComponent(terminalKey)}`;
|
||||
await openDeepLink(terminalPath);
|
||||
await eventually(
|
||||
() =>
|
||||
page.evaluate(
|
||||
`!!document.querySelector(".graph-pane") && !document.querySelector(".graph-pane").hidden`,
|
||||
),
|
||||
{ timeout: 30000, what: `the deep-linked terminal pane ${terminalKey}` },
|
||||
);
|
||||
const terminalState = await page.evaluate(`(() => ({
|
||||
path: location.pathname + location.search,
|
||||
title: document.querySelector(".graph-pane-title")?.textContent ?? "",
|
||||
headTop: Math.round(document.querySelector(".graph-pane-head")?.getBoundingClientRect().top ?? -1),
|
||||
topbarBottom: Math.round(document.querySelector(".topbar")?.getBoundingClientRect().bottom ?? 0),
|
||||
}))()`);
|
||||
if (terminalState.path !== terminalPath) {
|
||||
throw new Error(
|
||||
`L6: the terminal stage URL was rewritten to ${terminalState.path}, expected ${terminalPath}`,
|
||||
);
|
||||
}
|
||||
if (!terminalState.title) throw new Error("L6: the terminal stage pane has no title");
|
||||
if (terminalState.headTop < terminalState.topbarBottom) {
|
||||
throw new Error("L6: the terminal stage pane head is hidden under the top bar");
|
||||
}
|
||||
console.log(
|
||||
` hard navigation ${terminalPath} re-opened the ${JSON.stringify(terminalState.title)} terminal pane (URL unchanged)`,
|
||||
);
|
||||
await shot(`L6-deeplink-pipeline-${pipelineId}-terminal.png`);
|
||||
} else {
|
||||
console.log(" -- the live graph has no terminal node; skipped the terminal stage deep link");
|
||||
}
|
||||
|
||||
// In-page moves: Pipelines -> Runs -> a run detail, then Back/Forward. A window
|
||||
// marker proves the document was never reloaded.
|
||||
const marker = `L6-no-reload-${Date.now()}`;
|
||||
await page.evaluate(`window.__pipelinesNoReload = ${JSON.stringify(marker)}`);
|
||||
await page.clickText("nav.tabs button.tab", "Runs");
|
||||
await eventually(
|
||||
() =>
|
||||
page.evaluate(
|
||||
`location.pathname === "/runs" && !!document.querySelector(".list.runs .run-row")`,
|
||||
),
|
||||
{ timeout: 25000, what: "the Runs list after a pushState move" },
|
||||
);
|
||||
console.log(` pushState Pipelines -> Runs: ${await currentLocation()}`);
|
||||
|
||||
const runRowSelector = `.list.runs .run-row-meta[data-run-id="${discovered.preferred}"]`;
|
||||
const clickedRun = await page.evaluate(`(() => {
|
||||
const node = document.querySelector(${JSON.stringify(runRowSelector)});
|
||||
if (!node) return false;
|
||||
node.click();
|
||||
return true;
|
||||
})()`);
|
||||
if (!clickedRun) throw new Error(`L6: run ${discovered.preferred} was not on the Runs list`);
|
||||
await eventually(
|
||||
() =>
|
||||
page.evaluate(
|
||||
`location.pathname === "/runs/${discovered.preferred}" &&
|
||||
(document.querySelector(".run-detail .run-identity")?.textContent?.startsWith("run ${discovered.preferred} ") ?? false)`,
|
||||
),
|
||||
{ timeout: 30000, what: `run ${discovered.preferred} after a pushState selection` },
|
||||
);
|
||||
console.log(` pushState Runs -> run detail: ${await currentLocation()}`);
|
||||
|
||||
await page.evaluate(`history.back()`);
|
||||
await eventually(
|
||||
() =>
|
||||
page.evaluate(
|
||||
`location.pathname === "/runs" && !!document.querySelector(".list.runs .run-row")`,
|
||||
),
|
||||
{ timeout: 25000, what: "Back to the Runs list" },
|
||||
);
|
||||
const backState = await page.evaluate(`(() => ({
|
||||
path: location.pathname,
|
||||
marker: window.__pipelinesNoReload ?? null,
|
||||
staleDetail: !!document.querySelector(".run-detail .run-identity"),
|
||||
}))()`);
|
||||
if (backState.path !== "/runs") throw new Error(`L6: Back landed on ${backState.path}`);
|
||||
if (backState.staleDetail) throw new Error("L6: Back left a stale run detail rendered");
|
||||
if (backState.marker !== marker) throw new Error("L6: Back reloaded the document");
|
||||
console.log(` history.back() -> /runs, marker survived (${backState.marker})`);
|
||||
await shot("L6-history-back.png");
|
||||
|
||||
await page.evaluate(`history.forward()`);
|
||||
await eventually(
|
||||
() =>
|
||||
page.evaluate(
|
||||
`location.pathname === "/runs/${discovered.preferred}" &&
|
||||
(document.querySelector(".run-detail .run-identity")?.textContent?.startsWith("run ${discovered.preferred} ") ?? false)`,
|
||||
),
|
||||
{ timeout: 30000, what: "Forward back to the run detail" },
|
||||
);
|
||||
const forwardState = await page.evaluate(`(() => ({
|
||||
path: location.pathname,
|
||||
marker: window.__pipelinesNoReload ?? null,
|
||||
}))()`);
|
||||
if (forwardState.marker !== marker) throw new Error("L6: Forward reloaded the document");
|
||||
console.log(` history.forward() -> ${forwardState.path}, marker survived`);
|
||||
|
||||
// Leaving Runs while an executing run's poll is active must stop that poll: a
|
||||
// silent get_run loop for a detail the view no longer shows would otherwise run
|
||||
// forever. Conditional because the live server may have no executing run.
|
||||
const executingId = 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 (executingId != null) {
|
||||
await page.click(`.list.runs .run-row-meta[data-run-id="${executingId}"]`);
|
||||
await eventually(
|
||||
() =>
|
||||
page.evaluate(
|
||||
`(document.querySelector(".run-detail .run-identity")?.textContent?.startsWith("run ${executingId} ") ?? false)`,
|
||||
),
|
||||
{ timeout: 30000, what: `the executing run ${executingId}` },
|
||||
);
|
||||
await page.evaluate(`window.__pipelinesSentTypes = []`);
|
||||
await page.clickText("nav.tabs button.tab", "Pipelines");
|
||||
await eventually(() => page.evaluate(`location.pathname === "/pipelines"`), {
|
||||
timeout: 15000,
|
||||
what: "Pipelines after leaving the executing run",
|
||||
});
|
||||
await new Promise((resolve) => setTimeout(resolve, 2600));
|
||||
const leftoverPolls = await page.evaluate(
|
||||
`(window.__pipelinesSentTypes || []).filter((type) => type === "get_run").length`,
|
||||
);
|
||||
if (leftoverPolls > 0) {
|
||||
throw new Error(
|
||||
`L6: leaving Runs left the executing run's poll active (${leftoverPolls} get_run frame(s) after 2.6s)`,
|
||||
);
|
||||
}
|
||||
console.log(
|
||||
` left executing run ${executingId} for /pipelines; no get_run poll fired in the next 2.6s`,
|
||||
);
|
||||
} else {
|
||||
console.log(" -- no executing run available; skipped the leave-Runs poll check");
|
||||
}
|
||||
|
||||
// The decide deep link is exercised only against a genuinely waiting run; with
|
||||
// none, say so rather than claiming a capture of a state that never rendered.
|
||||
if (discovered.waiting) {
|
||||
await openDeepLink(`/runs/${discovered.waiting}?action=decide`);
|
||||
await eventually(() => page.evaluate(`!!document.querySelector(".decision-sheet")`), {
|
||||
timeout: 30000,
|
||||
what: `the decision sheet for waiting run ${discovered.waiting}`,
|
||||
});
|
||||
const decideUrl = await currentLocation();
|
||||
if (decideUrl !== `/runs/${discovered.waiting}`) {
|
||||
throw new Error(`L6: the decide action was not consumed to /runs/${discovered.waiting}: ${decideUrl}`);
|
||||
}
|
||||
console.log(
|
||||
` hard navigation /runs/${discovered.waiting}?action=decide opened the decision sheet, action consumed`,
|
||||
);
|
||||
await shot(`L6-deeplink-decide-${discovered.waiting}.png`);
|
||||
await page.evaluate(`document.querySelector(".decision-sheet .decision-cancel")?.click()`);
|
||||
await eventually(() => page.evaluate(`!document.querySelector(".decision-sheet")`), {
|
||||
timeout: 5000,
|
||||
what: "the decision sheet to close without sending",
|
||||
});
|
||||
} else {
|
||||
console.log(
|
||||
" NOTE: the ?action=decide path was not exercised live (no waiting run on the server); test/routes.test.mjs covers its parsing",
|
||||
);
|
||||
}
|
||||
|
||||
// A missing run falls back honestly: the list with real rows, /runs in the URL,
|
||||
// the server's refusal in the banner and no stale run identity.
|
||||
await openDeepLink("/runs/900000000");
|
||||
await eventually(
|
||||
() =>
|
||||
page.evaluate(
|
||||
`location.pathname === "/runs" && document.querySelectorAll(".list.runs .run-row").length > 0`,
|
||||
),
|
||||
{ timeout: 30000, what: "the missing-run fallback to the Runs list" },
|
||||
);
|
||||
const missingState = await page.evaluate(`(() => ({
|
||||
path: location.pathname + location.search,
|
||||
rows: document.querySelectorAll(".list.runs .run-row").length,
|
||||
staleDetail: !!document.querySelector(".run-detail .run-identity"),
|
||||
error: document.querySelector(".banner.error")?.textContent ?? "",
|
||||
pageErrors: window.__pipelinesPageErrors ?? [],
|
||||
}))()`);
|
||||
if (missingState.path !== "/runs") throw new Error(`L6: missing run fell back to ${missingState.path}`);
|
||||
if (!missingState.rows) throw new Error("L6: missing run rendered no run rows");
|
||||
if (missingState.staleDetail) throw new Error("L6: missing run left a stale run detail");
|
||||
if (!missingState.error) throw new Error("L6: missing run showed no server refusal");
|
||||
if (missingState.pageErrors.length) {
|
||||
throw new Error(`L6: page errors: ${missingState.pageErrors.join(" | ")}`);
|
||||
}
|
||||
console.log(
|
||||
` missing run -> /runs with ${missingState.rows} real rows, banner ${JSON.stringify(missingState.error.replace(/^Error:\\s*/, ""))}`,
|
||||
);
|
||||
await shot("L6-missing-run.png");
|
||||
|
||||
// The same honest fallback for a pipeline the server does not have.
|
||||
await openDeepLink("/pipelines/900000000");
|
||||
await eventually(
|
||||
() =>
|
||||
page.evaluate(
|
||||
`location.pathname === "/pipelines" && document.querySelectorAll("#pipelineRows button.row").length > 0`,
|
||||
),
|
||||
{ timeout: 30000, what: "the missing-pipeline fallback to the Pipelines list" },
|
||||
);
|
||||
const missingPipeline = await page.evaluate(`(() => ({
|
||||
path: location.pathname + location.search,
|
||||
rows: document.querySelectorAll("#pipelineRows button.row").length,
|
||||
staleDetail: !!document.querySelector(".detail h2"),
|
||||
error: document.querySelector(".banner.error")?.textContent ?? "",
|
||||
pageErrors: window.__pipelinesPageErrors ?? [],
|
||||
}))()`);
|
||||
if (missingPipeline.path !== "/pipelines") {
|
||||
throw new Error(`L6: missing pipeline fell back to ${missingPipeline.path}`);
|
||||
}
|
||||
if (!missingPipeline.rows) throw new Error("L6: missing pipeline rendered no pipeline rows");
|
||||
if (missingPipeline.staleDetail) throw new Error("L6: missing pipeline left a stale pipeline detail");
|
||||
if (!missingPipeline.error) throw new Error("L6: missing pipeline showed no server refusal");
|
||||
if (missingPipeline.pageErrors.length) {
|
||||
throw new Error(`L6: page errors: ${missingPipeline.pageErrors.join(" | ")}`);
|
||||
}
|
||||
console.log(
|
||||
` missing pipeline -> /pipelines with ${missingPipeline.rows} real rows, banner ${JSON.stringify(missingPipeline.error.replace(/^Error:\\s*/, ""))}`,
|
||||
);
|
||||
await shot("L6-missing-pipeline.png");
|
||||
|
||||
// A move made before the socket is up must become the destination the first
|
||||
// connection opens; only an untouched boot deep link is replayed. Load `/`,
|
||||
// choose Runs while disconnected, then connect and require URL and view to
|
||||
// agree (regression: the stale boot route used to win at connect time).
|
||||
await page.goto(`http://127.0.0.1:${port}/`);
|
||||
await page.waitForSelector("#connectBtn", { timeout: 15000 });
|
||||
await page.clickText("nav.tabs button.tab", "Runs");
|
||||
const preConnect = await currentLocation();
|
||||
if (preConnect !== "/runs") {
|
||||
throw new Error(`L6: a Runs choice before connecting left ${preConnect}, expected /runs`);
|
||||
}
|
||||
await page.click("#connectBtn");
|
||||
await ensureConnected(30000);
|
||||
await eventually(
|
||||
() =>
|
||||
page.evaluate(
|
||||
`location.pathname === "/runs" && !!document.querySelector(".list.runs .run-row")`,
|
||||
),
|
||||
{ timeout: 30000, what: "the pre-connect Runs choice after connecting" },
|
||||
);
|
||||
console.log(" a Runs choice made before connecting survived the first connection (/runs, list rendered)");
|
||||
|
||||
console.log("\nUI SMOKE PASS");
|
||||
for (const shot of shots) console.log(` ${shot}`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user