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:
2026-10-19 07:33:49 +01:00
14 changed files with 1840 additions and 39 deletions
+8
View File
@@ -208,6 +208,14 @@ export async function launchChrome({ width = 1440, height = 900, chromePath } =
{ what: `load of ${nextUrl}` },
);
},
/**
* Install a script that runs in every document created from now on, before
* the page's own scripts — the CDP hook a UI check uses to wrap a global
* (for example to record the page's WebSocket) before the app boots.
*/
async addInitScript(source) {
await session("Page.addScriptToEvaluateOnNewDocument", { source });
},
/** Set an input's value and fire input/change so the app sees it. */
async fill(selector, value) {
const ok = await api.evaluate(`(() => {
+286
View File
@@ -16,6 +16,11 @@ import {
MAX_RENDERED_DIFF_LINES,
TOOL_DETAIL_MAX_LENGTH,
TOOL_LONG_RUNNING_MILLIS,
TURN_PHASE_THINKING,
TURN_PHASE_TOOL,
TURN_PHASE_WAITING,
TURN_THINKING_WINDOW_MILLIS,
applyChatEvent,
attachmentDisplayName,
attachmentError,
attachmentFiles,
@@ -30,17 +35,22 @@ import {
chatNoMatchMessage,
chatOpensAtNewest,
chatShowJumpToLatest,
chatStreamState,
closeChatConfirmation,
composerAction,
composerCanSend,
composerSendEnabled,
composerSubmit,
deltaPartId,
directoryLabel,
filterSessions,
formatToolDuration,
groupSessionsByDirectory,
historyResync,
lineDiff,
mergeHistoryPage,
mergeToolPart,
newChatThread,
parseChatInput,
partRendering,
prettyToolInput,
@@ -48,6 +58,7 @@ import {
reasoningLabel,
runningAfterFrame,
runningToolElapsedMillis,
runningToolStamps,
sessionActivity,
sessionActivityBadge,
sessionChipLabel,
@@ -56,6 +67,11 @@ import {
sessionStatusLabel,
sessionTitle,
sessionWorkLabel,
settledThread,
threadElapsedMillis,
threadPhase,
threadRunningTools,
threadToolElapsedMillis,
toolCallCount,
toolCallRow,
toolCallsAnnouncement,
@@ -71,6 +87,8 @@ import {
toolsRunning,
transcriptRows,
turnElapsedMillis,
turnPhase,
turnPhaseLabel,
} from "../src/chat.js";
import { ChangeLineKind } from "../src/changes.js";
@@ -882,3 +900,271 @@ test("chatCommandEffect reports the exact Android error strings", () => {
text: "Can't start a new session here: the server reported no directory for this chat.",
});
});
// --- C5: live stream folding ------------------------------------------------
// Every frame below is the server's `chat_event` shape (internal/protocol/chat.go
// ChatEventFrame). The synthetic frames prove the pure fold; the ui-smoke replays
// the same shapes against the real page.
const evt = (kind, extra = {}) => ({ session_id: "s1", kind, ...extra });
test("a text delta appends to the part the first frame started", () => {
let thread = newChatThread("s1");
thread = applyChatEvent(thread, evt("text", { message_id: "a1", part: { id: "a1#text#0" }, delta: "Hel" }), 1000);
thread = applyChatEvent(thread, evt("text", { message_id: "a1", part: { id: "a1#text#0" }, delta: "lo" }), 1001);
assert.equal(thread.messages.length, 1);
assert.equal(thread.messages[0].role, "assistant");
assert.equal(thread.messages[0].parts.length, 1);
assert.equal(thread.messages[0].parts[0].text, "Hello");
assert.equal(thread.running, true);
assert.equal(thread.runningSince, 1000);
assert.equal(thread.lastDeltaAt, 1001);
});
test("a text delta and a reasoning delta sharing a bare id land in separate parts", () => {
let thread = newChatThread("s1");
thread = applyChatEvent(thread, evt("text", { message_id: "a1", part: { id: "x" }, delta: "answer" }), 1000);
thread = applyChatEvent(thread, evt("reasoning", { message_id: "a1", part: { id: "x" }, delta: "think" }), 1001);
const parts = thread.messages[0].parts;
assert.equal(parts.length, 2);
const text = parts.find((part) => part.type === "text");
const reasoning = parts.find((part) => part.type === "reasoning");
assert.equal(text.id, "x");
assert.equal(text.text, "answer");
assert.equal(reasoning.id, "x#reasoning");
assert.equal(reasoning.text, "think");
// The id derivation is the one the broker uses once the kinds are distinct.
assert.equal(deltaPartId(parts, "text", "x"), "x");
assert.equal(deltaPartId(parts, "reasoning", "x"), "x#reasoning");
});
test("tool frames merge field by field without blanking what an earlier frame taught", () => {
let thread = newChatThread("s1");
thread = applyChatEvent(
thread,
evt("tool", {
message_id: "a1",
part: { type: "tool", id: "t1", name: "read", state: { status: "running", input: { filePath: "a.js" } } },
}),
1000,
);
// A later frame carries the result but no name and no input: both are retained.
thread = applyChatEvent(
thread,
evt("tool", {
message_id: "a1",
part: { type: "tool", id: "t1", state: { status: "completed", content: [{ type: "text", text: "done" }] } },
}),
1001,
);
// A final frame carries the error but no content: the content is retained too.
thread = applyChatEvent(
thread,
evt("tool", {
message_id: "a1",
part: { type: "tool", id: "t1", state: { status: "error", error: { message: "boom" } } },
}),
1002,
);
const tool = thread.messages[0].parts.find((part) => part.type === "tool");
assert.equal(tool.name, "read");
assert.deepEqual(tool.state.input, { filePath: "a.js" });
assert.equal(tool.state.content[0].text, "done");
assert.equal(tool.state.error.message, "boom");
assert.equal(tool.state.status, "error");
// And the pure merge keeps a non-empty incoming field while retaining the prior.
const merged = mergeToolPart(
{ type: "tool", id: "t1", name: "read", executed: true, state: { status: "running", input: { a: 1 } } },
{ type: "tool", id: "t1", name: "", state: { status: "", input: { b: 2 } } },
);
assert.equal(merged.name, "read");
assert.equal(merged.executed, true);
assert.equal(merged.state.status, "running");
assert.deepEqual(merged.state.input, { b: 2 });
});
test("a repeated user message id adds no second turn and keeps a non-blank client", () => {
let thread = newChatThread("s1");
const frame = evt("user", { message_id: "u9", part: { text: "hi there" }, client: "Pixel" });
thread = applyChatEvent(thread, frame, 1000);
thread = applyChatEvent(thread, frame, 1001);
assert.equal(thread.messages.filter((message) => message.role === "user").length, 1);
assert.equal(thread.messages[0].client, "Pixel");
assert.equal(thread.messages[0].parts[0].text, "hi there");
// Another id with no text or no id at all is ignored.
thread = applyChatEvent(thread, evt("user", { message_id: "u10", part: { text: "" } }), 1002);
thread = applyChatEvent(thread, evt("user", { part: { text: "no id" } }), 1003);
assert.equal(thread.messages.length, 1);
});
test("step started runs the turn and step ended settles it", () => {
let thread = newChatThread("s1");
thread = applyChatEvent(thread, evt("step", { step: { status: "started", index: 1 } }), 1000);
assert.equal(thread.running, true);
assert.equal(thread.runningSince, 1000);
// A tool call in flight leaves a stamp; ending the step clears running and the stamp.
thread = applyChatEvent(
thread,
evt("tool", { message_id: "a1", part: { type: "tool", id: "t1", state: { status: "running" } } }),
1001,
);
assert.equal(thread.toolStartedAt.t1, 1001);
thread = applyChatEvent(thread, evt("step", { step: { status: "ended" } }), 2000);
assert.equal(thread.running, false);
assert.equal(thread.runningSince, 0);
assert.deepEqual(thread.toolStartedAt, {});
assert.equal(thread.lastDeltaAt, 0);
});
test("any frame clears the queued flag", () => {
for (const frame of [
evt("text", { message_id: "a1", part: { id: "p" }, delta: "x" }),
evt("step", { step: { status: "started" } }),
evt("usage", { usage: { input_tokens: 1 } }),
evt("shell", { shell: { id: "sh1", status: "running" } }),
]) {
const queued = { ...newChatThread("s1"), queued: true };
assert.equal(applyChatEvent(queued, frame, 1000).queued, false);
}
});
test("a shell frame never marks the thread running", () => {
const thread = applyChatEvent(
newChatThread("s1"),
evt("shell", { shell: { id: "sh1", status: "running", command: "go test ./..." } }),
1000,
);
assert.equal(thread.running, false);
assert.equal(thread.runningSince, 0);
});
test("a usage frame changes nothing", () => {
const before = newChatThread("s1");
const after = applyChatEvent(before, evt("usage", { usage: { input_tokens: 5, cost: 0.01 } }), 1000);
assert.deepEqual(after, before);
});
test("settling a thread (a socket drop) clears running, its stamps and queued", () => {
let thread = newChatThread("s1");
thread = applyChatEvent(thread, evt("text", { message_id: "a1", part: { id: "p" }, delta: "x" }), 1000);
thread = applyChatEvent(
thread,
evt("tool", { message_id: "a1", part: { type: "tool", id: "t1", state: { status: "running" } } }),
1001,
);
assert.equal(thread.running, true);
assert.equal(thread.toolStartedAt.t1, 1001);
const settled = settledThread(thread);
assert.equal(settled.running, false);
assert.equal(settled.runningSince, 0);
assert.deepEqual(settled.toolStartedAt, {});
assert.equal(settled.lastDeltaAt, 0);
assert.equal(settled.queued, false);
// The conversation itself is untouched by settling.
assert.equal(settled.messages.length, 1);
});
test("historyResync replaces the turn wholesale and settles it", () => {
const held = {
...newChatThread("s1"),
messages: [assistant("a1", [{ type: "text", text: "stale" }])],
nextCursor: "old",
hasMore: true,
loaded: true,
running: true,
runningSince: 555,
toolStartedAt: { t1: 555 },
lastDeltaAt: 600,
};
const page = {
messages: [user("u1", "hi"), assistant("a2", [{ type: "text", text: "fresh" }])],
nextCursor: "",
hasMore: false,
};
const resynced = historyResync(held, page);
assert.deepEqual(resynced.messages, page.messages);
assert.ok(!resynced.messages.some((message) => message.id === "a1"));
assert.equal(resynced.nextCursor, "");
assert.equal(resynced.hasMore, false);
assert.equal(resynced.loaded, true);
assert.equal(resynced.running, false);
assert.equal(resynced.runningSince, 0);
assert.deepEqual(resynced.toolStartedAt, {});
assert.equal(resynced.lastDeltaAt, 0);
});
test("the chat stream badge uses the live / reconnecting / not live words", () => {
assert.deepEqual(chatStreamState("connected", true), { tone: "live", label: "live" });
assert.equal(chatStreamState("connected", false).label, "not live");
assert.equal(chatStreamState("connecting", true).label, "reconnecting");
assert.equal(chatStreamState("disconnected", true).label, "reconnecting");
assert.equal(chatStreamState("idle", false).label, "not live");
});
test("the turn phase names what is happening", () => {
assert.equal(turnPhase([], 1000), TURN_PHASE_THINKING);
assert.equal(turnPhaseLabel(TURN_PHASE_THINKING), "Thinking…");
assert.equal(turnPhase([{ type: "tool", id: "t", state: { status: "running" } }], 100000), TURN_PHASE_TOOL);
assert.equal(turnPhaseLabel(TURN_PHASE_TOOL), "Running a tool…");
assert.equal(turnPhase([], null), TURN_PHASE_WAITING);
assert.equal(turnPhase([], TURN_THINKING_WINDOW_MILLIS), TURN_PHASE_WAITING);
assert.equal(turnPhaseLabel(TURN_PHASE_WAITING), "Waiting…");
});
test("only a call at or past 60s reads as long", () => {
assert.equal(toolLongRunning(TOOL_LONG_RUNNING_MILLIS - 1), false);
assert.equal(toolLongRunning(TOOL_LONG_RUNNING_MILLIS), true);
assert.equal(TOOL_LONG_RUNNING_MILLIS, 60000);
});
test("a live turn interleaving reasoning, text and tool frames folds to one agent row", () => {
let thread = newChatThread("live");
const frames = [
evt("reasoning", { message_id: "a1", part: { id: "r0" }, delta: "think" }),
evt("text", { message_id: "a1", part: { id: "t0" }, delta: "Hel" }),
evt("tool", { message_id: "a1", part: { type: "tool", id: "tool1", name: "read", state: { status: "running" } } }),
evt("tool", {
message_id: "a1",
part: { type: "tool", id: "tool1", state: { status: "completed", content: [{ type: "text", text: "ok" }] } },
}),
evt("reasoning", { message_id: "a2", part: { id: "r0" }, delta: "more" }),
evt("text", { message_id: "a2", part: { id: "t0" }, delta: "lo" }),
];
for (const frame of frames) thread = applyChatEvent(thread, frame, 1000);
const rows = transcriptRows(thread.messages);
const agentRows = rows.filter((row) => row.kind === "agent");
assert.equal(agentRows.length, 1);
assert.equal(agentRows[0].key, "a1");
assert.deepEqual(agentRows[0].turn.reasoningSteps, ["think", "more"]);
assert.equal(agentRows[0].turn.tools.length, 1);
assert.equal(agentRows[0].turn.answer, "Hel\n\nlo");
assert.equal(threadRunningTools(thread.messages).length, 0);
});
test("the running indicator's elapsed and per-tool timing use the thread's own stamps", () => {
let thread = newChatThread("s1");
thread = applyChatEvent(thread, evt("step", { step: { status: "started" } }), 1000);
thread = applyChatEvent(
thread,
evt("tool", {
message_id: "a1",
part: { type: "tool", id: "t1", name: "shell", state: { status: "running", input: { command: "go build" } } },
}),
1500,
);
assert.equal(threadElapsedMillis(thread, 3000), 2000);
assert.equal(formatToolDuration(threadToolElapsedMillis(thread, thread.messages[0].parts[0], 3000)), "1.5s");
assert.equal(threadPhase(thread, 3000), TURN_PHASE_TOOL);
// runningToolStamps keeps a stamp it already had and drops one that settled.
assert.deepEqual(runningToolStamps({ t1: 42 }, thread.messages, 9999), { t1: 42 });
assert.deepEqual(runningToolStamps({ t1: 42 }, [], 9999), {});
});
+22 -1
View File
@@ -90,9 +90,11 @@ test("an error reply surfaces the server text as a ProtocolError", async () => {
await assert.rejects(() => client.call({ type: "get_run" }), ProtocolError);
});
test("an unsolicited envelope with no matching id is dropped, not misattributed", async () => {
test("an unsolicited envelope is surfaced as a frame event and not misattributed", async () => {
const { client, ws } = connectedClient();
ws.reply = undefined;
const frames = [];
client.addEventListener("frame", (event) => frames.push(event.detail));
const pending = client.call({ type: "ping" });
let settled = false;
@@ -102,10 +104,29 @@ test("an unsolicited envelope with no matching id is dropped, not misattributed"
ws.push({ type: "pipelines", pipelines: [] }); // no id
await flush();
assert.equal(settled, false);
assert.deepEqual(frames, [{ type: "pipelines", pipelines: [] }]);
const frame = ws.sent.at(-1);
ws.push({ id: frame.id, type: "pong" });
assert.equal((await pending).type, "pong");
// A matched reply is not also broadcast as an unsolicited frame.
assert.equal(frames.length, 1);
});
test("a server-pushed chat_event frame reaches a frame listener", async () => {
const { client, ws } = connectedClient();
const frames = [];
client.addEventListener("frame", (event) => frames.push(event.detail));
ws.push({
type: "chat_event",
chat_event: { session_id: "ses_1", message_id: "a1", kind: "text", delta: "hi" },
});
await flush();
assert.equal(frames.length, 1);
assert.equal(frames[0].type, "chat_event");
assert.equal(frames[0].chat_event.session_id, "ses_1");
});
test("a malformed frame is ignored and does not reject a pending call", async () => {
+87
View File
@@ -105,6 +105,67 @@ test("validate throws when the reply has no graph", async () => {
await assert.rejects(() => repo.validate("empty"), ProtocolError);
});
/** The new pipeline detail a `submitted` reply carries in these tests. */
const SUBMITTED_DETAIL = { id: 91, name: "Release helper", version: 1 };
test("submit sends exactly {type:'submit',name,source,create_only:true} and returns the detail", async () => {
const { repo, ws } = connected();
ws.reply = (frame) => ({ id: frame.id, type: "submitted", detail: SUBMITTED_DETAIL });
const detail = await repo.submit("Release helper", "the source");
assert.deepEqual(lastFrame(ws), {
type: "submit",
name: "Release helper",
source: "the source",
create_only: true,
});
assert.deepEqual(detail, SUBMITTED_DETAIL);
});
test("submit trims the name before sending it", async () => {
const { repo, ws } = connected();
ws.reply = (frame) => ({ id: frame.id, type: "submitted", detail: SUBMITTED_DETAIL });
await repo.submit(" Release helper ", "the source");
assert.deepEqual(lastFrame(ws), {
type: "submit",
name: "Release helper",
source: "the source",
create_only: true,
});
});
test("submit refuses a blank name without sending anything", async () => {
const { repo, ws } = connected();
ws.reply = () => ({ id: "unused", type: "submitted", detail: SUBMITTED_DETAIL });
await assert.rejects(() => repo.submit(" ", "the source"), {
name: "ProtocolError",
message: "Enter a pipeline name.",
});
assert.equal(ws.sent.length, 0);
});
test("submit rejects a server error envelope with the server's own text", async () => {
const { repo, ws } = connected();
ws.reply = (frame) => ({ id: frame.id, type: "error", error: 'a pipeline named "Release helper" already exists' });
await assert.rejects(() => repo.submit("Release helper", "the source"), {
name: "ProtocolError",
message: 'a pipeline named "Release helper" already exists',
});
});
test("submit throws when the reply has no pipeline detail", async () => {
const { repo, ws } = connected();
ws.reply = (frame) => ({ id: frame.id, type: "submitted", name: "Release helper" });
await assert.rejects(() => repo.submit("Release helper", "the source"), {
name: "ProtocolError",
message: "The server returned no pipeline detail.",
});
});
test("search sends exactly {type:'search',search:{query,kind:'',limit:0}} and returns search_results", async () => {
const { repo, ws } = connected();
const payload = { query: "release", results: [{ kind: "run" }], cap: 50, scanned_steps: 3 };
@@ -309,3 +370,29 @@ test("nativeChatMessageId mirrors the Android id: msg_ + alphanumerics, capped",
assert.equal(nativeChatMessageId("a".repeat(300)).length, "msg_".length + 120);
assert.match(newChatOperationId(), /^web-chat-[a-z0-9]+-[a-z0-9]+$/);
});
test("subscribeChat sends exactly {type:'chat_subscribe',chat_subscribe:{session_id}}", async () => {
const { repo, ws } = connected();
ws.reply = (frame) => ({ id: frame.id, type: "chat_subscribe" });
await repo.subscribeChat("ses_eae413f50ffeLQDExlg8cYnscN");
assert.deepEqual(lastFrame(ws), {
type: "chat_subscribe",
chat_subscribe: { session_id: "ses_eae413f50ffeLQDExlg8cYnscN" },
});
});
test("subscribeChat rejects a blank session id without sending anything", async () => {
const { repo, ws } = connected();
await assert.rejects(() => repo.subscribeChat(" "), ProtocolError);
assert.equal(ws.sent.length, 0);
});
test("subscribeChat surfaces a server refusal as a ProtocolError", async () => {
const { repo, ws } = connected();
ws.reply = (frame) => ({ id: frame.id, type: "error", error: "unknown command: chat_subscribe" });
await assert.rejects(() => repo.subscribeChat("ses_1"), {
name: "ProtocolError",
message: "unknown command: chat_subscribe",
});
});
+64
View File
@@ -4,6 +4,18 @@ import { test } from "node:test";
import assert from "node:assert/strict";
import {
CREATE_CANCEL,
CREATE_CLOSE,
CREATE_CONFIRM,
CREATE_NAME_LABEL,
CREATE_NOTE,
CREATE_SENDING,
createConfirmLabel,
createDismissLabel,
createFormTitle,
createFormValid,
createSuccessMessage,
createdPipelineName,
effectiveStageType,
stageCountText,
templateCard,
@@ -85,3 +97,55 @@ test("templateGraphNote picks the unparsed or parsed note", () => {
assert.equal(templateGraphNote(null), TEMPLATE_UNPARSED_GRAPH_NOTE);
assert.equal(templateGraphNote({ stages: [] }), TEMPLATE_GRAPH_NOTE);
});
test("createFormTitle names the template, a blank name falling back to the key", () => {
assert.equal(createFormTitle({ key: "task", name: "Complete a task" }), "Create from Complete a task");
assert.equal(createFormTitle({ key: "task", name: "" }), "Create from task");
assert.equal(createFormTitle({ key: "task", name: " " }), "Create from task");
});
test("createFormValid rejects blank/whitespace, sending and an existing creation", () => {
assert.equal(createFormValid("a pipeline"), true);
assert.equal(createFormValid(""), false);
assert.equal(createFormValid(" "), false);
assert.equal(createFormValid(null), false);
assert.equal(createFormValid("a pipeline", { sending: true }), false);
assert.equal(createFormValid("a pipeline", { created: "a pipeline" }), false);
assert.equal(createFormValid("a pipeline", { created: "" }), false);
// Defaults: a non-blank name with no options is valid.
assert.equal(createFormValid("a pipeline", {}), true);
});
test("createConfirmLabel switches Create / Creating…", () => {
assert.equal(createConfirmLabel(false), CREATE_CONFIRM);
assert.equal(createConfirmLabel(true), CREATE_SENDING);
});
test("createDismissLabel is Cancel until a creation, then Close", () => {
assert.equal(createDismissLabel(null), CREATE_CANCEL);
assert.equal(createDismissLabel(undefined), CREATE_CANCEL);
assert.equal(createDismissLabel("Made"), CREATE_CLOSE);
});
test("createSuccessMessage is the exact success line", () => {
assert.equal(createSuccessMessage("Release helper"), 'Created "Release helper". It is in the Pipelines list.');
});
test("createdPipelineName prefers the returned name, else the trimmed submitted name", () => {
assert.equal(createdPipelineName({ name: "Server name" }, "Typed name"), "Server name");
assert.equal(createdPipelineName({ name: " " }, " Typed name "), "Typed name");
assert.equal(createdPipelineName(null, " Typed name "), "Typed name");
assert.equal(createdPipelineName({}, ""), "");
});
test("the create dialog's fixed wording is the app's", () => {
assert.equal(CREATE_NAME_LABEL, "New pipeline name (required)");
assert.equal(
CREATE_NOTE,
"Creates a new draft pipeline on the server from this template's source; it is not run.",
);
assert.equal(CREATE_CONFIRM, "Create");
assert.equal(CREATE_SENDING, "Creating…");
assert.equal(CREATE_CANCEL, "Cancel");
assert.equal(CREATE_CLOSE, "Close");
});
+340 -2
View File
@@ -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}`);