Merge branch 'main' into web-chat-composer
# Conflicts: # web/src/app.js # web/src/client.js # web/src/protocol.js # web/test/chat.test.mjs # web/test/repository.test.mjs # web/test/ui-smoke.mjs
This commit is contained in:
+340
-2
@@ -2,11 +2,16 @@
|
||||
// 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]
|
||||
// node test/ui-smoke.mjs [--port 8091] [--pipelines 127.0.0.1:8080] [--out DIR] [--scratch]
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
// `--scratch` drives ONLY the P5 create-from-template flow (captures 51/52/53)
|
||||
// against a scratch server and skips the live suite, which needs the operator's
|
||||
// real runs and chat session. The default run never sends a `submit`: the live
|
||||
// server's pipeline list is never mutated.
|
||||
import { spawn } from "node:child_process";
|
||||
import { mkdir, rm } from "node:fs/promises";
|
||||
import net from "node:net";
|
||||
@@ -38,6 +43,9 @@ const pipelines = flag(process.argv, "--pipelines", process.env.PIPELINES_TARGET
|
||||
const out = resolve(
|
||||
flag(process.argv, "--out", process.env.WEB_UI_OUT ?? join(tmpdir(), "pipelines-web-ui")),
|
||||
);
|
||||
// Scratch mode: only the P5 create-from-template flow runs, against a throwaway
|
||||
// server with its own database. The default (live) run sends no submit.
|
||||
const scratch = process.argv.includes("--scratch");
|
||||
|
||||
// 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
|
||||
@@ -124,6 +132,87 @@ async function openRunDetail(runId) {
|
||||
}
|
||||
}
|
||||
|
||||
// --- P5: create a pipeline from a template (scratch server only) -----------
|
||||
// The scratch server has no real runs and no live chat, so this is the whole
|
||||
// point of a `--scratch` run. It opens a template, opens the create action,
|
||||
// captures the blank/disabled dialog, fills a unique name, creates it, captures
|
||||
// the success dialog and then the Pipelines list holding the new row. It sends a
|
||||
// real validate + submit, but only ever against the scratch database.
|
||||
async function runScratchCreate() {
|
||||
step("P5: creating a pipeline from a template (scratch server)");
|
||||
await ensureConnected();
|
||||
await page.clickText("nav.tabs button.tab", "Templates");
|
||||
await page.waitForSelector(".cards button.card", { timeout: 25000 });
|
||||
await page.click(".cards button.card");
|
||||
await page.waitForSelector(".detail .tabstrip", { timeout: 25000 });
|
||||
await page.waitForSelector(".template-create-open", { timeout: 15000 });
|
||||
|
||||
const actionLabel = await text(".template-create-open");
|
||||
if (actionLabel !== "Create pipeline from this template") {
|
||||
throw new Error(`create action label: ${actionLabel}`);
|
||||
}
|
||||
await page.click(".template-create-open");
|
||||
await page.waitForSelector(".template-create-dialog", { timeout: 15000 });
|
||||
|
||||
const blank = await page.evaluate(`(() => ({
|
||||
title: document.querySelector(".template-create-title")?.textContent ?? "",
|
||||
label: document.querySelector(".template-create-label")?.textContent ?? "",
|
||||
note: document.querySelector(".template-create-note")?.textContent ?? "",
|
||||
confirm: document.querySelector(".template-create-confirm")?.textContent ?? "",
|
||||
dismiss: document.querySelector(".template-create-cancel")?.textContent ?? "",
|
||||
confirmDisabled: document.querySelector(".template-create-confirm")?.disabled ?? null,
|
||||
fieldDisabled: document.querySelector(".template-create-name")?.disabled ?? null,
|
||||
}))()`);
|
||||
if (!blank.title.startsWith("Create from ")) throw new Error(`create dialog title: ${blank.title}`);
|
||||
if (blank.label !== "New pipeline name (required)") throw new Error(`create field label: ${blank.label}`);
|
||||
if (blank.note !== "Creates a new draft pipeline on the server from this template's source; it is not run.") {
|
||||
throw new Error(`create note: ${blank.note}`);
|
||||
}
|
||||
if (blank.confirm !== "Create") throw new Error(`create confirm: ${blank.confirm}`);
|
||||
if (blank.dismiss !== "Cancel") throw new Error(`create dismiss: ${blank.dismiss}`);
|
||||
if (blank.confirmDisabled !== true) throw new Error("Create was enabled with a blank name");
|
||||
if (blank.fieldDisabled !== false) throw new Error("the name field started disabled");
|
||||
console.log(` blank dialog: "${blank.title}" — Create disabled, field enabled, Cancel offered`);
|
||||
await shot("51-template-create-dialog.png");
|
||||
|
||||
const newName = `Scratch create ${Date.now()}`;
|
||||
await page.fill(".template-create-name", newName);
|
||||
await eventually(
|
||||
() => page.evaluate(`!document.querySelector(".template-create-confirm")?.disabled`),
|
||||
{ timeout: 5000, what: "Create to enable after a non-blank name" },
|
||||
);
|
||||
await page.click(".template-create-confirm");
|
||||
await page.waitForText(`Created "${newName}". It is in the Pipelines list.`, { timeout: 25000 });
|
||||
const success = await page.evaluate(`(() => ({
|
||||
text: document.querySelector(".template-create-success")?.textContent ?? "",
|
||||
dismiss: document.querySelector(".template-create-cancel")?.textContent ?? "",
|
||||
fieldDisabled: document.querySelector(".template-create-name")?.disabled ?? null,
|
||||
}))()`);
|
||||
if (success.text !== `Created "${newName}". It is in the Pipelines list.`) {
|
||||
throw new Error(`create success line: ${success.text}`);
|
||||
}
|
||||
if (success.dismiss !== "Close") throw new Error(`dismiss after success: ${success.dismiss}`);
|
||||
if (success.fieldDisabled !== true) throw new Error("the name field was not locked after a success");
|
||||
console.log(` created: ${JSON.stringify(success.text)}; dismiss now reads ${success.dismiss}`);
|
||||
await shot("52-template-created.png");
|
||||
|
||||
// Cancel now reads Close: dismissing it leaves the Templates view, then the
|
||||
// refreshed Pipelines list must hold the new row.
|
||||
await page.click(".template-create-cancel");
|
||||
await eventually(() => page.evaluate(`!document.querySelector(".template-create-dialog")`), {
|
||||
timeout: 5000,
|
||||
what: "the create dialog to close",
|
||||
});
|
||||
await page.clickText("nav.tabs button.tab", "Pipelines");
|
||||
await page.waitForText(newName, { timeout: 25000 });
|
||||
const listed = await page.evaluate(
|
||||
`document.querySelector("#pipelineRows")?.textContent.includes(${JSON.stringify(newName)}) ?? false`,
|
||||
);
|
||||
if (!listed) throw new Error("the created pipeline is not in the Pipelines list");
|
||||
console.log(" the created pipeline appears in the scratch server's Pipelines list");
|
||||
await shot("53-pipeline-created-list.png");
|
||||
}
|
||||
|
||||
// --- Omni-search (S1/S2) ---------------------------------------------------
|
||||
// The page's own search UI drives every one of the helpers below; nothing is
|
||||
// stubbed. `searchTargets` opens the panel (if it is not already open), types the
|
||||
@@ -281,6 +370,30 @@ try {
|
||||
browser = await launchChrome({ width: 1440, height: 900 });
|
||||
page = await browser.openPage(`http://127.0.0.1:${port}/`);
|
||||
|
||||
// C5 evidence needs to replay exact `chat_event` frames against the real page
|
||||
// (a real live turn is not available on demand without disrupting the operator's
|
||||
// server). A tiny WebSocket shim is installed before the page's own scripts on
|
||||
// every document from now on: it constructs the real socket and records it on
|
||||
// `window`, so the smoke can hand frames to the socket's own `onmessage` and the
|
||||
// app folds them through its real path. Every other frame (the subscribe ack, the
|
||||
// history reply) still comes from the real server.
|
||||
step("installing the WebSocket recorder shim before the page scripts");
|
||||
await page.addInitScript(`(() => {
|
||||
const Native = window.WebSocket;
|
||||
if (!Native || window.__pipelinesSocketShim) return;
|
||||
window.__pipelinesSocketShim = true;
|
||||
window.__pipelinesSockets = [];
|
||||
function Shim(url, protocols) {
|
||||
const ws = protocols === undefined ? new Native(url) : new Native(url, protocols);
|
||||
window.__pipelinesSockets.push(ws);
|
||||
window.__pipelinesSocket = ws;
|
||||
return ws;
|
||||
}
|
||||
Shim.prototype = Native.prototype;
|
||||
for (const key of ["CONNECTING", "OPEN", "CLOSING", "CLOSED"]) Shim[key] = Native[key];
|
||||
window.WebSocket = Shim;
|
||||
})()`);
|
||||
|
||||
// Deterministic dismissals: the attention set is read from localStorage once at
|
||||
// boot, so clear the key and reload before connecting so the surface derives
|
||||
// from an empty set regardless of any stale profile state.
|
||||
@@ -292,8 +405,23 @@ try {
|
||||
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 });
|
||||
// A scratch server starts with no pipelines at all, so the pipeline row that
|
||||
// proves the live list rendered is skipped there; the connection banner is
|
||||
// still awaited either way.
|
||||
if (!scratch) await page.waitForSelector(".row-title", { timeout: 25000 });
|
||||
await page.waitForText("connected", { timeout: 25000 });
|
||||
|
||||
// Scratch mode runs only the P5 create flow above and skips the live suite,
|
||||
// which needs the operator's real pipelines, runs and chat session. The guard
|
||||
// below wraps the live steps without reindenting them, keeping this diff
|
||||
// reviewable; both branches share this file's cleanup in the `finally`.
|
||||
if (scratch) {
|
||||
await runScratchCreate();
|
||||
console.log("\nUI SMOKE PASS");
|
||||
for (const shot of shots) console.log(` ${shot}`);
|
||||
}
|
||||
|
||||
if (!scratch) {
|
||||
const pipelineCount = await page.evaluate(
|
||||
`document.querySelectorAll("#pipelineRows button.row").length`,
|
||||
);
|
||||
@@ -3016,8 +3144,218 @@ try {
|
||||
await shot("64-chat-throwaway-closed.png");
|
||||
throwawaySessionId = null;
|
||||
|
||||
// C5: the shared live stream. A real live turn needs a prompt the operator's
|
||||
// server may not be running, so the real page is subscribed to the real
|
||||
// session and then exact `chat_event` frames are replayed through the socket's
|
||||
// own `onmessage` (see the shim installed before the page's scripts). The
|
||||
// subscribe ack and every history reply are real server traffic; only the
|
||||
// frames replayed below are synthetic, and this log says so explicitly.
|
||||
step("C5: the live stream — subscribe, replayed chat_event frames, stream state");
|
||||
await ensureConnected();
|
||||
await page.evaluate(`document.querySelector("#chatJump")?.click()`);
|
||||
|
||||
const chatBadge = () =>
|
||||
page.evaluate(
|
||||
`document.querySelector(".chat-context .live-badge .live-word")?.textContent ?? ""`,
|
||||
);
|
||||
const chatLive = await chatBadge();
|
||||
if (chatLive !== "live") {
|
||||
throw new Error(`chat stream badge should read "live" while subscribed, got ${JSON.stringify(chatLive)}`);
|
||||
}
|
||||
console.log(` chat stream badge while subscribed: "${chatLive}" (real chat_subscribe ack + real history)`);
|
||||
|
||||
const sessionId = openedId;
|
||||
const replayFrames = (frames) =>
|
||||
page.evaluate(`(() => {
|
||||
const ws = window.__pipelinesSocket;
|
||||
if (!ws || typeof ws.onmessage !== "function") return false;
|
||||
for (const frame of ${JSON.stringify(frames)}) {
|
||||
ws.onmessage({ data: JSON.stringify({ type: "chat_event", chat_event: frame }) });
|
||||
}
|
||||
return true;
|
||||
})()`);
|
||||
const agentCount = () => page.evaluate(`document.querySelectorAll("#chatTranscript .chat-turn-agent").length`);
|
||||
const indicator = () =>
|
||||
page.evaluate(`(() => {
|
||||
const el = document.querySelector("#chatRunning");
|
||||
if (!el) return null;
|
||||
return {
|
||||
spinner: !!el.querySelector(".spinner"),
|
||||
label: el.querySelector(".chat-running-label")?.textContent ?? "",
|
||||
elapsed: el.querySelector(".chat-running-elapsed")?.textContent ?? "",
|
||||
tools: [...el.querySelectorAll(".chat-running-tool")].map((line) => ({
|
||||
text: line.querySelector(".chat-running-tool-text")?.textContent ?? "",
|
||||
long: line.querySelector(".chat-tool-long")?.textContent ?? "",
|
||||
longTinted: line.classList.contains("chat-running-tool-long"),
|
||||
})),
|
||||
};
|
||||
})()`);
|
||||
|
||||
const applyFrames = async (frames, label) => {
|
||||
const ok = await replayFrames(frames);
|
||||
if (!ok) throw new Error(`C5: the socket shim did not expose the live socket to replay ${label}`);
|
||||
await eventually(() => page.evaluate(`!!document.querySelector("#chatTranscript")`), {
|
||||
what: "the transcript to render",
|
||||
});
|
||||
};
|
||||
|
||||
const agentBefore = await agentCount();
|
||||
const sessionFrame = (extra) => ({ session_id: sessionId, ...extra });
|
||||
|
||||
// 1. Reasoning and text deltas on one assistant message id: the answer grows
|
||||
// inside the existing agent bubble.
|
||||
await applyFrames(
|
||||
[
|
||||
sessionFrame({ message_id: "cap-live-1", kind: "reasoning", part: { id: "cap-live-1#reasoning#0" }, delta: "Planning the live capture." }),
|
||||
sessionFrame({ message_id: "cap-live-1", kind: "text", part: { id: "cap-live-1#text#0" }, delta: "The live turn is " }),
|
||||
sessionFrame({ message_id: "cap-live-1", kind: "text", part: { id: "cap-live-1#text#0" }, delta: "growing." }),
|
||||
],
|
||||
"the reasoning/text deltas",
|
||||
);
|
||||
const liveTurn = await page.evaluate(`(() => {
|
||||
const transcript = document.querySelector("#chatTranscript");
|
||||
const bubbles = [...transcript.querySelectorAll(".chat-turn-agent")];
|
||||
return {
|
||||
agents: bubbles.length,
|
||||
answers: bubbles.filter((b) => b.textContent.includes("The live turn is growing.")).length,
|
||||
reasoning: bubbles.some((b) => b.textContent.includes("Planning the live capture.")),
|
||||
};
|
||||
})()`);
|
||||
console.log(
|
||||
` replayed 3 frames (reasoning + 2 text deltas) → ${liveTurn.answers} agent bubble carries ` +
|
||||
`"The live turn is growing." + reasoning (transcript agent bubbles ${agentBefore} -> ${liveTurn.agents})`,
|
||||
);
|
||||
if (liveTurn.answers !== 1 || !liveTurn.reasoning || liveTurn.agents !== agentBefore) {
|
||||
throw new Error(`C5: the replayed deltas did not grow one agent bubble: ${JSON.stringify(liveTurn)}`);
|
||||
}
|
||||
await shot("56-chat-live-turn.png");
|
||||
|
||||
// 2. A running tool: the indicator's headline is `Running a tool…` with a
|
||||
// running-tool line and a live `· {elapsed}`.
|
||||
await applyFrames(
|
||||
[sessionFrame({ message_id: "cap-live-1", kind: "tool", part: { type: "tool", id: "cap-tool-1", name: "shell", state: { status: "running", input: { command: "npm run build" } } } })],
|
||||
"the running tool",
|
||||
);
|
||||
await new Promise((resolve) => setTimeout(resolve, 1300));
|
||||
const runningIndicator = await indicator();
|
||||
if (
|
||||
!runningIndicator ||
|
||||
!runningIndicator.spinner ||
|
||||
runningIndicator.label !== "Running a tool…" ||
|
||||
!/^· \d/.test(runningIndicator.elapsed) ||
|
||||
runningIndicator.tools.length < 1
|
||||
) {
|
||||
throw new Error(`C5: the running indicator is wrong: ${JSON.stringify(runningIndicator)}`);
|
||||
}
|
||||
console.log(
|
||||
` running indicator: spinner=${runningIndicator.spinner}, "${runningIndicator.label}", "${runningIndicator.elapsed}", ` +
|
||||
`${runningIndicator.tools.length} running-tool line(s) — "${runningIndicator.tools[0].text}"`,
|
||||
);
|
||||
await shot("57-chat-running.png");
|
||||
|
||||
// 3. A second running tool that started 61 s ago (protocol `time.ran`): the
|
||||
// `· long` mark, tinted with the error hue. Two assistant message ids are in
|
||||
// play now and the turn is still one bubble.
|
||||
await applyFrames(
|
||||
[
|
||||
sessionFrame({
|
||||
message_id: "cap-live-2",
|
||||
kind: "reasoning",
|
||||
part: { id: "cap-live-2#reasoning#0" },
|
||||
delta: "Streaming the second step.",
|
||||
}),
|
||||
sessionFrame({
|
||||
message_id: "cap-live-2",
|
||||
kind: "tool",
|
||||
part: { type: "tool", id: "cap-tool-2", name: "shell", state: { status: "running", input: { command: "npm run long" } }, time: { ran: Date.now() - 61000 } },
|
||||
}),
|
||||
],
|
||||
"the long-running tool",
|
||||
);
|
||||
const longCall = await indicator();
|
||||
const longLine = longCall?.tools.find((line) => line.long !== "");
|
||||
if (!longLine || !longLine.longTinted || !longLine.long.includes("long")) {
|
||||
throw new Error(`C5: no tinted long-running tool line: ${JSON.stringify(longCall)}`);
|
||||
}
|
||||
const agentsWithTwoIds = await agentCount();
|
||||
console.log(` long-call line: "${longLine.text}${longLine.long}" tinted=${longLine.longTinted}`);
|
||||
if (agentsWithTwoIds !== agentBefore) {
|
||||
throw new Error(`C5: two assistant message ids fragmented the live turn into ${agentsWithTwoIds} bubbles`);
|
||||
}
|
||||
await shot("58-chat-long-call.png");
|
||||
|
||||
// 4. Finish the tools and end the step: the indicator disappears and the same
|
||||
// single agent bubble stands, settled.
|
||||
await applyFrames(
|
||||
[
|
||||
sessionFrame({ message_id: "cap-live-1", kind: "tool", part: { type: "tool", id: "cap-tool-1", state: { status: "completed", content: [{ type: "text", text: "build ok" }] } } }),
|
||||
sessionFrame({ message_id: "cap-live-2", kind: "tool", part: { type: "tool", id: "cap-tool-2", state: { status: "completed", content: [{ type: "text", text: "long ok" }] } } }),
|
||||
sessionFrame({ message_id: "cap-live-2", kind: "step", step: { status: "ended" } }),
|
||||
],
|
||||
"the completed tools and the ended step",
|
||||
);
|
||||
const settled = await page.evaluate(`(() => {
|
||||
const transcript = document.querySelector("#chatTranscript");
|
||||
return {
|
||||
indicator: !!document.querySelector("#chatRunning"),
|
||||
agents: transcript.querySelectorAll(".chat-turn-agent").length,
|
||||
answers: [...transcript.querySelectorAll(".chat-turn-agent")].filter((b) => b.textContent.includes("The live turn is growing.")).length,
|
||||
};
|
||||
})()`);
|
||||
if (settled.indicator) throw new Error("C5: the running indicator survived the ended step");
|
||||
if (settled.agents !== agentBefore || settled.answers !== 1) {
|
||||
throw new Error(`C5: the settled turn is not the same single agent bubble: ${JSON.stringify(settled)}`);
|
||||
}
|
||||
console.log(
|
||||
` after the tools completed and the step ended: no indicator, still ${settled.agents} agent bubble ` +
|
||||
`carrying the live answer (unchanged from ${agentBefore})`,
|
||||
);
|
||||
await shot("59-chat-settled.png");
|
||||
|
||||
// The stream-state words. Dropping the socket unexpectedly reads `reconnecting`
|
||||
// while the client comes back; the reconnect re-subscribes the open chat and
|
||||
// refreshes its history wholesale, so the replayed turn above is gone — which is
|
||||
// exactly the promised wholesale replacement.
|
||||
await page.evaluate(`window.__pipelinesSocket && window.__pipelinesSocket.close(4000, "smoke drop")`);
|
||||
await eventually(
|
||||
() => page.evaluate(`document.querySelector(".chat-context .live-badge .live-word")?.textContent === "reconnecting"`),
|
||||
{ timeout: 10000, what: "the chat badge to read reconnecting" },
|
||||
);
|
||||
console.log(` chat stream badge after an unexpected drop: "${await chatBadge()}"`);
|
||||
await ensureConnected(30000);
|
||||
await eventually(
|
||||
() => page.evaluate(`document.querySelector(".chat-context .live-badge .live-word")?.textContent === "live"`),
|
||||
{ timeout: 30000, what: "the chat badge to return to live after reconnect" },
|
||||
);
|
||||
// The badge turns live as soon as the subscription is re-attached; the history
|
||||
// refresh that replaces the conversation follows it, so wait for the replayed
|
||||
// marker to actually disappear rather than racing the fetch.
|
||||
await eventually(
|
||||
() =>
|
||||
page.evaluate(
|
||||
`!document.querySelector("#chatTranscript")?.textContent?.includes("The live turn is growing.")`,
|
||||
),
|
||||
{ timeout: 20000, what: "the reconnect to replace the conversation with fresh history" },
|
||||
);
|
||||
console.log(
|
||||
' after reconnect: chat badge "live" again and history replaced the replayed turn wholesale (marker gone)',
|
||||
);
|
||||
|
||||
// The third word: disconnecting entirely reads `not live`.
|
||||
await page.click("#connectBtn");
|
||||
await eventually(
|
||||
() => page.evaluate(`document.querySelector(".chat-context .live-badge .live-word")?.textContent === "not live"`),
|
||||
{ timeout: 15000, what: "the chat badge to read not live while idle" },
|
||||
);
|
||||
console.log(` chat stream badge after Disconnect: "${await chatBadge()}"`);
|
||||
|
||||
console.log(
|
||||
" NOTE: the chat_subscribe ack and every chat_history reply above came from the real server; only the chat_event frames were replayed",
|
||||
);
|
||||
|
||||
console.log("\nUI SMOKE PASS");
|
||||
for (const shot of shots) console.log(` ${shot}`);
|
||||
}
|
||||
} catch (error) {
|
||||
failed = true;
|
||||
console.error(`\nUI SMOKE FAIL: ${error.message}`);
|
||||
|
||||
Reference in New Issue
Block a user