web: background-tasks bar — running shells, capped list, bounded output (C11)
Add the background-tasks bar to an open conversation: heading
"Background tasks" plus "{n} running", shown only while at least one
shell is running. Rows are capped at 3 (BACKGROUND_TASK_VISIBLE_ROWS)
and the list scrolls beyond; each row is a play glyph, "Running", a
one-line shellCommandSummary and "Details" while selected. Tapping a
row toggles its detail pane ("Command"/"Task identity"/"Status:
running" plus the bounded output: spinner, error + "Retry",
"Output unavailable for this task.", "No output yet.", or the
monospace output and "Output is bounded to 64 KiB." with "Refresh").
Fold shell frames without ever marking the turn running, merge a blank
command from the previous frame, list only running shells (an exited
shell is never a task) and drop/relearn shells on reconnect via
chat_shells. Refresh always rereads the bounded 64 KiB page from cursor
0. Update PARITY.md C11 with its captures and the replayed-vs-real note.
Checks: node --check on every touched file; cd web && node --test test/
(456 pass).
This commit is contained in:
@@ -5,6 +5,8 @@ import { test } from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
|
||||
import {
|
||||
BACKGROUND_TASKS_TITLE,
|
||||
BACKGROUND_TASK_VISIBLE_ROWS,
|
||||
CHAT_COMMANDS,
|
||||
CHAT_COMMAND_GLYPH,
|
||||
CHAT_FOLLOW_THRESHOLD_PX,
|
||||
@@ -14,6 +16,17 @@ import {
|
||||
ChatTurn,
|
||||
MAX_ATTACHMENT_BYTES,
|
||||
MAX_RENDERED_DIFF_LINES,
|
||||
OBSERVED_SHELL_LIMIT,
|
||||
SHELL_DETAILS_LABEL,
|
||||
SHELL_EXITED,
|
||||
SHELL_OUTPUT_EMPTY,
|
||||
SHELL_OUTPUT_ERROR,
|
||||
SHELL_OUTPUT_LABELS,
|
||||
SHELL_OUTPUT_LOADING,
|
||||
SHELL_OUTPUT_READY,
|
||||
SHELL_OUTPUT_UNAVAILABLE,
|
||||
SHELL_ROW_LABEL,
|
||||
SHELL_RUNNING,
|
||||
TOOL_DETAIL_MAX_LENGTH,
|
||||
TOOL_LONG_RUNNING_MILLIS,
|
||||
TURN_PHASE_THINKING,
|
||||
@@ -24,6 +37,7 @@ import {
|
||||
attachmentDisplayName,
|
||||
attachmentError,
|
||||
attachmentFiles,
|
||||
backgroundTasksRunningLabel,
|
||||
chatBottomDistancePx,
|
||||
chatCommandEffect,
|
||||
chatCommandForEnter,
|
||||
@@ -49,6 +63,7 @@ import {
|
||||
historyResync,
|
||||
lineDiff,
|
||||
mergeHistoryPage,
|
||||
mergeShellFrame,
|
||||
mergeToolPart,
|
||||
newChatThread,
|
||||
parseChatInput,
|
||||
@@ -56,7 +71,9 @@ import {
|
||||
prettyToolInput,
|
||||
queuedAfterFrame,
|
||||
reasoningLabel,
|
||||
resumedThread,
|
||||
runningAfterFrame,
|
||||
runningBackgroundShells,
|
||||
runningToolElapsedMillis,
|
||||
runningToolStamps,
|
||||
sessionActivity,
|
||||
@@ -68,6 +85,9 @@ import {
|
||||
sessionTitle,
|
||||
sessionWorkLabel,
|
||||
settledThread,
|
||||
shellCommandSummary,
|
||||
shellOutputState,
|
||||
shellsLoaded,
|
||||
threadElapsedMillis,
|
||||
threadPhase,
|
||||
threadRunningTools,
|
||||
@@ -1168,3 +1188,166 @@ test("the running indicator's elapsed and per-tool timing use the thread's own s
|
||||
assert.deepEqual(runningToolStamps({ t1: 42 }, thread.messages, 9999), { t1: 42 });
|
||||
assert.deepEqual(runningToolStamps({ t1: 42 }, [], 9999), {});
|
||||
});
|
||||
|
||||
// --- C11: background tasks (shells) -----------------------------------------
|
||||
// The pure model the background-tasks bar is built on: running-only filtering,
|
||||
// the visible-row cap, the one-line command summary, shell-frame folding and the
|
||||
// detail pane's state selection and wording. Mirror of
|
||||
// ChatFormat.runningBackgroundShells/shellCommandSummary, ChatStore.applyShell/
|
||||
// shellsLoaded and ChatTranscript.BackgroundProcessBar/-Detail.
|
||||
|
||||
const shell = (overrides = {}) => ({ id: "sh1", status: "running", command: "go test ./...", ...overrides });
|
||||
|
||||
test("runningBackgroundShells lists only non-blank running shells, in order", () => {
|
||||
const shells = [
|
||||
shell({ id: "a", command: "one" }),
|
||||
shell({ id: "b", status: SHELL_EXITED, command: "two" }),
|
||||
shell({ id: "", command: "three" }),
|
||||
shell({ id: "d", status: "running", command: "four" }),
|
||||
shell({ id: "e", status: undefined }),
|
||||
];
|
||||
assert.deepEqual(
|
||||
runningBackgroundShells(shells).map((s) => s.id),
|
||||
["a", "d"],
|
||||
);
|
||||
assert.deepEqual(runningBackgroundShells([]), []);
|
||||
assert.deepEqual(runningBackgroundShells(undefined), []);
|
||||
});
|
||||
|
||||
test("the visible-row cap is three and never truncates the model", () => {
|
||||
assert.equal(BACKGROUND_TASK_VISIBLE_ROWS, 3);
|
||||
const running = Array.from({ length: 5 }, (_, i) => shell({ id: `s${i}` }));
|
||||
// The cap is a view/CSS concern; every running shell stays in the model.
|
||||
assert.equal(runningBackgroundShells(running).length, 5);
|
||||
});
|
||||
|
||||
test("shellCommandSummary collapses whitespace, names a blank command and elides past 72", () => {
|
||||
assert.equal(SHELL_ROW_LABEL, "Running");
|
||||
assert.equal(shellCommandSummary(""), "background process");
|
||||
assert.equal(shellCommandSummary(" "), "background process");
|
||||
assert.equal(shellCommandSummary(null), "background process");
|
||||
assert.equal(shellCommandSummary(" go test\n./...\t-x "), "go test ./... -x");
|
||||
// Exactly 72 characters is not elided.
|
||||
const seventyTwo = "a".repeat(TOOL_DETAIL_MAX_LENGTH);
|
||||
assert.equal(shellCommandSummary(seventyTwo), seventyTwo);
|
||||
// Longer: 71 kept characters, trailing whitespace trimmed, then one ellipsis.
|
||||
const long = `${"b".repeat(TOOL_DETAIL_MAX_LENGTH)} tail`;
|
||||
const elided = shellCommandSummary(long);
|
||||
assert.equal(elided, `${"b".repeat(TOOL_DETAIL_MAX_LENGTH - 1)}…`);
|
||||
assert.equal(elided.length, TOOL_DETAIL_MAX_LENGTH);
|
||||
assert.ok(elided.endsWith("…"));
|
||||
// A 71-char word followed by a space then more trims the trailing space first.
|
||||
const word = `${"c".repeat(TOOL_DETAIL_MAX_LENGTH - 1)} rest`;
|
||||
assert.equal(shellCommandSummary(word), `${"c".repeat(TOOL_DETAIL_MAX_LENGTH - 1)}…`);
|
||||
});
|
||||
|
||||
test("mergeShellFrame keeps a blank command from the previous frame and caps the list", () => {
|
||||
const first = mergeShellFrame([], shell({ id: "a", command: "go build" }));
|
||||
assert.deepEqual(first, [shell({ id: "a", command: "go build" })]);
|
||||
|
||||
// A later frame that omits the command never blanks the retained one.
|
||||
const merged = mergeShellFrame(first, shell({ id: "a", command: "" }));
|
||||
assert.equal(merged.length, 1);
|
||||
assert.equal(merged[0].command, "go build");
|
||||
|
||||
// A frame that carries a command replaces it; the position is preserved.
|
||||
const renamed = mergeShellFrame(merged, shell({ id: "a", command: "go vet" }));
|
||||
assert.equal(renamed[0].command, "go vet");
|
||||
|
||||
// A blank id (or null shell) is ignored outright.
|
||||
assert.equal(mergeShellFrame(renamed, shell({ id: "" })).length, 1);
|
||||
assert.deepEqual(mergeShellFrame(renamed, null), renamed);
|
||||
|
||||
// The retained list is capped at OBSERVED_SHELL_LIMIT, keeping the newest.
|
||||
let many = [];
|
||||
for (let i = 0; i < OBSERVED_SHELL_LIMIT + 4; i += 1) {
|
||||
many = mergeShellFrame(many, shell({ id: `s${i}`, command: `c${i}` }));
|
||||
}
|
||||
assert.equal(many.length, OBSERVED_SHELL_LIMIT);
|
||||
assert.equal(many.at(-1).id, `s${OBSERVED_SHELL_LIMIT + 3}`);
|
||||
assert.equal(many[0].id, "s4");
|
||||
});
|
||||
|
||||
test("shellsLoaded replaces the live set but retains exits this client observed", () => {
|
||||
const existing = [
|
||||
shell({ id: "r1", status: SHELL_RUNNING, command: "old run" }),
|
||||
shell({ id: "e1", status: SHELL_EXITED, command: "finished" }),
|
||||
];
|
||||
const loaded = shellsLoaded(existing, [shell({ id: "r2", status: SHELL_RUNNING, command: "new run" })]);
|
||||
assert.deepEqual(loaded.map((s) => s.id), ["e1", "r2"]);
|
||||
// r1 is neither in the snapshot nor a locally observed exit, so it drops out.
|
||||
assert.ok(!loaded.some((s) => s.id === "r1"));
|
||||
// An exit the client never saw exit is not invented.
|
||||
assert.ok(!loaded.some((s) => s.id === "r1"));
|
||||
});
|
||||
|
||||
test("shellOutputState picks the detail pane's branch in the app's order", () => {
|
||||
assert.equal(shellOutputState(null), null);
|
||||
assert.equal(shellOutputState(undefined), null);
|
||||
assert.equal(shellOutputState({}), null);
|
||||
assert.equal(shellOutputState({ loading: true }), SHELL_OUTPUT_LOADING);
|
||||
assert.equal(shellOutputState({ error: "boom" }), SHELL_OUTPUT_ERROR);
|
||||
// Error outranks a page if both were set.
|
||||
assert.equal(shellOutputState({ error: "boom", page: { output: "x" } }), SHELL_OUTPUT_ERROR);
|
||||
assert.equal(shellOutputState({ page: { unavailable: true } }), SHELL_OUTPUT_UNAVAILABLE);
|
||||
assert.equal(shellOutputState({ page: { output: "" } }), SHELL_OUTPUT_EMPTY);
|
||||
assert.equal(shellOutputState({ page: { output: "line\n" } }), SHELL_OUTPUT_READY);
|
||||
assert.equal(shellOutputState({ page: { output: "x", truncated: true } }), SHELL_OUTPUT_READY);
|
||||
});
|
||||
|
||||
test("the detail pane's wording is the app's verbatim copy", () => {
|
||||
assert.equal(BACKGROUND_TASKS_TITLE, "Background tasks");
|
||||
assert.equal(backgroundTasksRunningLabel(3), "3 running");
|
||||
assert.equal(SHELL_DETAILS_LABEL, "Details");
|
||||
assert.deepEqual(SHELL_OUTPUT_LABELS, {
|
||||
COMMAND: "Command",
|
||||
UNAVAILABLE: "Unavailable",
|
||||
TASK_IDENTITY: "Task identity",
|
||||
STATUS_RUNNING: "Status: running",
|
||||
OUTPUT_UNAVAILABLE: "Output unavailable for this task.",
|
||||
NO_OUTPUT: "No output yet.",
|
||||
OUTPUT: "Output",
|
||||
OUTPUT_BOUNDED: "Output is bounded to 64 KiB.",
|
||||
RETRY: "Retry",
|
||||
REFRESH: "Refresh",
|
||||
});
|
||||
});
|
||||
|
||||
test("a shell frame folds into the thread and never marks the turn running", () => {
|
||||
const folded = applyChatEvent(
|
||||
newChatThread("s1"),
|
||||
evt("shell", { shell: { id: "sh1", status: "running", command: "sleep 5" } }),
|
||||
1000,
|
||||
);
|
||||
assert.equal(folded.running, false);
|
||||
assert.equal(folded.runningSince, 0);
|
||||
assert.deepEqual(folded.shells, [{ id: "sh1", status: "running", command: "sleep 5" }]);
|
||||
|
||||
// A shell frame that ends the shell removes it from the running set at once.
|
||||
const exited = applyChatEvent(
|
||||
folded,
|
||||
evt("shell", { shell: { id: "sh1", status: "exited", command: "" } }),
|
||||
1001,
|
||||
);
|
||||
assert.equal(exited.shells[0].status, "exited");
|
||||
assert.equal(exited.shells[0].command, "sleep 5");
|
||||
assert.equal(runningBackgroundShells(exited.shells).length, 0);
|
||||
});
|
||||
|
||||
test("a step that ends does not clear a background shell that outlives the turn", () => {
|
||||
let thread = applyChatEvent(
|
||||
newChatThread("s1"),
|
||||
evt("shell", { shell: { id: "sh1", status: "running", command: "sleep 5" } }),
|
||||
1000,
|
||||
);
|
||||
thread = applyChatEvent(thread, evt("step", { step: { status: "started" } }), 1000);
|
||||
thread = applyChatEvent(thread, evt("step", { step: { status: "ended" } }), 2000);
|
||||
assert.equal(thread.running, false);
|
||||
assert.equal(runningBackgroundShells(thread.shells).length, 1);
|
||||
// settledThread alone keeps the shell; only the reconnect repair drops it.
|
||||
assert.equal(settledThread(thread).shells.length, 1);
|
||||
const resumed = resumedThread(thread);
|
||||
assert.deepEqual(resumed.shells, []);
|
||||
assert.equal(resumed.selectedShellId, null);
|
||||
assert.equal(resumed.shellOutput, null);
|
||||
});
|
||||
|
||||
@@ -5,7 +5,7 @@ import { test } from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
|
||||
import { PipelinesClient, ProtocolError } from "../src/client.js";
|
||||
import { PipelinesRepository, nativeChatMessageId, newChatOperationId } from "../src/repository.js";
|
||||
import { PipelinesRepository, SHELL_OUTPUT_LIMIT, nativeChatMessageId, newChatOperationId } from "../src/repository.js";
|
||||
import { validateServerUrl } from "../src/serverUrl.js";
|
||||
|
||||
const VALID = validateServerUrl("ws://host:8080/connect");
|
||||
@@ -396,3 +396,104 @@ test("subscribeChat surfaces a server refusal as a ProtocolError", async () => {
|
||||
message: "unknown command: chat_subscribe",
|
||||
});
|
||||
});
|
||||
|
||||
// --- C11: background shells -------------------------------------------------
|
||||
|
||||
test("chatShells sends the session as chat_query and returns the list", async () => {
|
||||
const { repo, ws } = connected();
|
||||
ws.reply = (frame) => ({
|
||||
id: frame.id,
|
||||
type: "chat_shells",
|
||||
chat_shells: [{ id: "sh1", status: "running", command: "go test ./..." }],
|
||||
});
|
||||
|
||||
const shells = await repo.chatShells("ses_eae413f50ffeLQDExlg8cYnscN");
|
||||
assert.deepEqual(lastFrame(ws), {
|
||||
type: "chat_shells",
|
||||
chat_query: { session_id: "ses_eae413f50ffeLQDExlg8cYnscN" },
|
||||
});
|
||||
assert.deepEqual(shells, [{ id: "sh1", status: "running", command: "go test ./..." }]);
|
||||
});
|
||||
|
||||
test("chatShells returns [] when the reply carries none", async () => {
|
||||
const { repo, ws } = connected();
|
||||
ws.reply = (frame) => ({ id: frame.id, type: "chat_shells" });
|
||||
assert.deepEqual(await repo.chatShells("ses_1"), []);
|
||||
});
|
||||
|
||||
test("chatShells refuses a blank session id without sending anything", async () => {
|
||||
const { repo, ws } = connected();
|
||||
await assert.rejects(() => repo.chatShells(" "), {
|
||||
name: "ProtocolError",
|
||||
message: "Select a chat session first.",
|
||||
});
|
||||
assert.equal(ws.sent.length, 0);
|
||||
});
|
||||
|
||||
test("chatShellOutput sends chat_shell_output_query with cursor 0 and the 64 KiB limit", async () => {
|
||||
const { repo, ws } = connected();
|
||||
ws.reply = (frame) => ({
|
||||
id: frame.id,
|
||||
type: "chat_shell_output",
|
||||
chat_shell_output: { shell: { id: "sh1", status: "running" }, output: "hello", cursor: 5, size: 5 },
|
||||
});
|
||||
|
||||
const page = await repo.chatShellOutput("ses_1", "sh1");
|
||||
assert.deepEqual(lastFrame(ws), {
|
||||
type: "chat_shell_output",
|
||||
chat_shell_output_query: { session_id: "ses_1", shell_id: "sh1", cursor: 0, limit: 64 << 10 },
|
||||
});
|
||||
assert.equal(SHELL_OUTPUT_LIMIT, 65536);
|
||||
assert.equal(page.output, "hello");
|
||||
});
|
||||
|
||||
test("a refresh always rereads from cursor 0, never appending", async () => {
|
||||
const { repo, ws } = connected();
|
||||
ws.reply = (frame) => ({
|
||||
id: frame.id,
|
||||
type: "chat_shell_output",
|
||||
chat_shell_output: { shell: { id: "sh1", status: "running" }, output: "full page", truncated: true },
|
||||
});
|
||||
await repo.chatShellOutput("ses_1", "sh1", { cursor: 0, limit: SHELL_OUTPUT_LIMIT });
|
||||
await repo.chatShellOutput("ses_1", "sh1", { cursor: 0, limit: SHELL_OUTPUT_LIMIT });
|
||||
const frames = ws.sent.filter((frame) => frame.type === "chat_shell_output");
|
||||
assert.equal(frames.length, 2);
|
||||
for (const frame of frames) {
|
||||
assert.equal(frame.chat_shell_output_query.cursor, 0);
|
||||
assert.equal(frame.chat_shell_output_query.limit, 65536);
|
||||
}
|
||||
});
|
||||
|
||||
test("chatShellOutput refuses blank ids and out-of-bounds reads", async () => {
|
||||
const { repo, ws } = connected();
|
||||
await assert.rejects(() => repo.chatShellOutput("", "sh1"), {
|
||||
name: "ProtocolError",
|
||||
message: "Select a shell first.",
|
||||
});
|
||||
await assert.rejects(() => repo.chatShellOutput("ses_1", " "), {
|
||||
name: "ProtocolError",
|
||||
message: "Select a shell first.",
|
||||
});
|
||||
await assert.rejects(() => repo.chatShellOutput("ses_1", "sh1", { cursor: -1 }), {
|
||||
name: "ProtocolError",
|
||||
message: "Shell output bounds are invalid.",
|
||||
});
|
||||
await assert.rejects(() => repo.chatShellOutput("ses_1", "sh1", { limit: 0 }), {
|
||||
name: "ProtocolError",
|
||||
message: "Shell output bounds are invalid.",
|
||||
});
|
||||
await assert.rejects(() => repo.chatShellOutput("ses_1", "sh1", { limit: SHELL_OUTPUT_LIMIT + 1 }), {
|
||||
name: "ProtocolError",
|
||||
message: "Shell output bounds are invalid.",
|
||||
});
|
||||
assert.equal(ws.sent.length, 0);
|
||||
});
|
||||
|
||||
test("chatShellOutput throws when the reply carries no page", async () => {
|
||||
const { repo, ws } = connected();
|
||||
ws.reply = (frame) => ({ id: frame.id, type: "chat_shell_output" });
|
||||
await assert.rejects(() => repo.chatShellOutput("ses_1", "sh1"), {
|
||||
name: "ProtocolError",
|
||||
message: "The server returned no shell output page.",
|
||||
});
|
||||
});
|
||||
|
||||
@@ -387,6 +387,33 @@ try {
|
||||
const ws = protocols === undefined ? new Native(url) : new Native(url, protocols);
|
||||
window.__pipelinesSockets.push(ws);
|
||||
window.__pipelinesSocket = ws;
|
||||
// A controlled reply hook (C11): when set, a matching request is answered
|
||||
// with the synthetic reply on the page's own socket instead of reaching the
|
||||
// server. Every other frame is sent natively, so real chat traffic is
|
||||
// untouched; a run that never sets the hook behaves exactly as before.
|
||||
const nativeSend = ws.send.bind(ws);
|
||||
ws.send = function (data) {
|
||||
let frame = null;
|
||||
try {
|
||||
frame = JSON.parse(data);
|
||||
} catch (_) {
|
||||
frame = null;
|
||||
}
|
||||
if (frame) {
|
||||
(window.__pipelinesSentTypes = window.__pipelinesSentTypes || []).push(frame.type);
|
||||
const reply = window.__pipelinesIntercept ? window.__pipelinesIntercept(frame) : null;
|
||||
if (reply) {
|
||||
const delay = (window.__pipelinesInterceptDelay ?? 0) || 0;
|
||||
setTimeout(() => {
|
||||
try {
|
||||
if (typeof ws.onmessage === "function") ws.onmessage({ data: JSON.stringify(reply) });
|
||||
} catch (_) {}
|
||||
}, delay);
|
||||
return;
|
||||
}
|
||||
}
|
||||
return nativeSend(data);
|
||||
};
|
||||
return ws;
|
||||
}
|
||||
Shim.prototype = Native.prototype;
|
||||
@@ -2357,8 +2384,16 @@ try {
|
||||
if (openedId !== expectedSession) {
|
||||
console.log(` -- the live server's first session is ${openedId}, not the expected ${expectedSession}`);
|
||||
}
|
||||
// Record the frames the page sends, so the C11 chat_shells fetch on open is
|
||||
// asserted rather than assumed.
|
||||
await page.evaluate(`(() => { window.__pipelinesSentTypes = []; return true; })()`);
|
||||
await page.click(`#chatRows .chat-row[data-session="${openedId}"]`);
|
||||
await page.waitForSelector("#chatTranscript", { timeout: 25000 });
|
||||
await eventually(
|
||||
() => page.evaluate(`(window.__pipelinesSentTypes || []).includes("chat_shells")`),
|
||||
{ timeout: 15000, what: "chat_shells to be fetched when the conversation opens (C11)" },
|
||||
);
|
||||
console.log(" chat_shells fetched when the conversation opened (real request)");
|
||||
|
||||
const transcript = await page.evaluate(`(() => {
|
||||
const el = document.querySelector("#chatTranscript");
|
||||
@@ -3368,6 +3403,343 @@ try {
|
||||
" NOTE: the chat_subscribe ack and every chat_history reply above came from the real server; only the chat_event frames were replayed",
|
||||
);
|
||||
|
||||
// C11: the background-tasks bar. The live server has no running shell to read
|
||||
// safely, so the bar is driven from synthetic `shell` frames replayed through
|
||||
// the page's own socket handler (the same shim) and the bounded output pages are
|
||||
// answered by a controlled reply hook on that socket. Every other frame — the
|
||||
// chat_shells list, the subscribe ack and history — still comes from the real
|
||||
// server. This log states the split plainly.
|
||||
step("C11: the background-tasks bar (replayed shell frames + bounded output pages)");
|
||||
// The C5 section ends on a deliberate Disconnect (idle), which the browser's
|
||||
// `online` handler deliberately does not auto-recover; use the header's own
|
||||
// Reconnect/Connect control to bring the page back before the bar is captured.
|
||||
const c11Reconnected = await page.evaluate(`(() => {
|
||||
if (document.querySelector(".conn-banner")?.classList.contains("conn-ok")) return true;
|
||||
const control = document.querySelector("#reconnectBtn") || document.querySelector("#connectBtn");
|
||||
if (control) {
|
||||
control.click();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
})()`);
|
||||
if (!c11Reconnected) throw new Error("C11: no header control to reconnect the page");
|
||||
await ensureConnected(30000);
|
||||
// The conversation pane persists across the reconnect; bring it back explicitly
|
||||
// if a render left another view, clicking through the page's own controls.
|
||||
const c11Transcript = await page.evaluate(`!!document.querySelector("#chatTranscript")`);
|
||||
if (!c11Transcript) {
|
||||
await page.evaluate(`(() => {
|
||||
const tab = [...document.querySelectorAll("nav.tabs button.tab")].find((b) => b.textContent.trim() === "Chat");
|
||||
if (tab) tab.click();
|
||||
return !!tab;
|
||||
})()`);
|
||||
await page.waitForSelector("#chatRows .chat-row", { timeout: 25000 });
|
||||
await page.evaluate(
|
||||
`document.querySelector('#chatRows .chat-row[data-session="${sessionId}"]')?.click()`,
|
||||
);
|
||||
}
|
||||
await page.waitForSelector("#chatTranscript", { timeout: 25000 });
|
||||
await page.evaluate(`document.querySelector("#chatJump")?.click()`);
|
||||
|
||||
// The bounded output pages the page will read are replayed synthetic wire
|
||||
// replies; the request shape (chat_shell_output_query, cursor 0, limit 65536)
|
||||
// is the client's own and is unit-tested in repository.test.mjs.
|
||||
await page.evaluate(`(() => {
|
||||
window.__pipelinesInterceptDelay = 0;
|
||||
window.__pipelinesPages = {
|
||||
"cap-run": { shell: { id: "cap-run", status: "running", command: "go test ./... -count=1" }, output: "ok \\tpipelines\\t0.42s\\n", cursor: 0, size: 20 },
|
||||
"cap-empty": { shell: { id: "cap-empty", status: "running", command: "true" }, output: "", cursor: 0, size: 0 },
|
||||
"cap-unavail": { shell: { id: "cap-unavail", status: "running", command: "sleep 30" }, unavailable: true },
|
||||
"cap-trunc": { shell: { id: "cap-trunc", status: "running", command: "yes | head -c 200000" }, output: "x".repeat(400), cursor: 400, size: 200000, truncated: true },
|
||||
"cap-slow": { shell: { id: "cap-slow", status: "running", command: "sleep 60" }, output: "slow page\\n" },
|
||||
};
|
||||
window.__pipelinesIntercept = (frame) => {
|
||||
if (frame.type !== "chat_shell_output") return null;
|
||||
const query = frame.chat_shell_output_query || {};
|
||||
(window.__pipelinesShellReads = window.__pipelinesShellReads || []).push({
|
||||
shell_id: query.shell_id,
|
||||
cursor: query.cursor,
|
||||
limit: query.limit,
|
||||
});
|
||||
const page = window.__pipelinesPages[query.shell_id];
|
||||
if (!page) return null;
|
||||
return { id: frame.id, type: "chat_shell_output", chat_shell_output: page };
|
||||
};
|
||||
return true;
|
||||
})()`);
|
||||
|
||||
const shellFrame = (id, command, status) => ({ session_id: sessionId, kind: "shell", shell: { id, status, command } });
|
||||
const replayShells = (frames) =>
|
||||
page.evaluate(`(() => {
|
||||
const ws = window.__pipelinesSocket;
|
||||
if (!ws || typeof ws.onmessage !== "function") return false;
|
||||
for (const frame of ${JSON.stringify(
|
||||
[
|
||||
shellFrame("cap-run", "go test ./... -count=1", "running"),
|
||||
shellFrame("cap-empty", "true", "running"),
|
||||
shellFrame("cap-unavail", "sleep 30", "running"),
|
||||
shellFrame("cap-trunc", "yes | head -c 200000", "running"),
|
||||
shellFrame("cap-slow", "sleep 60", "running"),
|
||||
],
|
||||
)}) {
|
||||
ws.onmessage({ data: JSON.stringify({ type: "chat_event", chat_event: frame }) });
|
||||
}
|
||||
return true;
|
||||
})()`);
|
||||
|
||||
const ok = await replayShells();
|
||||
if (!ok) throw new Error("C11: the socket shim did not expose the live socket for the shell frames");
|
||||
await eventually(() => page.evaluate(`!!document.querySelector("#chatBackgroundTasks")`), {
|
||||
timeout: 10000,
|
||||
what: "the background-tasks bar to render",
|
||||
});
|
||||
|
||||
// A transient ping failure during the section's own reconnect can leave the
|
||||
// page-level `Error:` banner up (a pre-existing surface from onConnected's
|
||||
// ping). Clicking the active tab is the page's own way to clear it, and the
|
||||
// conversation and the bar are rebuilt from thread state, so the capture shows
|
||||
// the feature rather than a stale unrelated error.
|
||||
const clearBanner = () =>
|
||||
page.evaluate(`(() => {
|
||||
if (!document.querySelector(".banner.error")) return true;
|
||||
const tab = [...document.querySelectorAll("nav.tabs button.tab")].find((b) => b.classList.contains("active"));
|
||||
if (tab) tab.click();
|
||||
return !document.querySelector(".banner.error");
|
||||
})()`);
|
||||
|
||||
const c11Bar = await page.evaluate(`(() => {
|
||||
const el = document.querySelector("#chatBackgroundTasks");
|
||||
if (!el) return null;
|
||||
const list = el.querySelector(".chat-bg-tasks-list");
|
||||
const rows = [...el.querySelectorAll(".chat-bg-task")];
|
||||
return {
|
||||
title: el.querySelector(".chat-bg-tasks-title")?.textContent ?? "",
|
||||
count: el.querySelector(".chat-bg-tasks-count")?.textContent ?? "",
|
||||
rows: rows.length,
|
||||
scrollable: list ? list.scrollHeight > list.clientHeight + 1 : false,
|
||||
listHeight: list ? list.clientHeight : 0,
|
||||
rowHeight: rows[0] ? Math.round(rows[0].getBoundingClientRect().height) : 0,
|
||||
commands: rows.map((r) => r.querySelector(".chat-bg-task-command")?.textContent ?? ""),
|
||||
glyphs: el.querySelectorAll(".chat-bg-task-glyph").length,
|
||||
statuses: rows.map((r) => r.querySelector(".chat-bg-task-status")?.textContent ?? ""),
|
||||
};
|
||||
})()`);
|
||||
if (!c11Bar) throw new Error("C11: the background-tasks bar did not render");
|
||||
if (c11Bar.title !== "Background tasks") throw new Error(`C11: bar title ${JSON.stringify(c11Bar.title)}`);
|
||||
if (c11Bar.count !== "5 running") throw new Error(`C11: bar count ${JSON.stringify(c11Bar.count)}`);
|
||||
if (c11Bar.rows !== 5) throw new Error(`C11: expected 5 rows, got ${c11Bar.rows}`);
|
||||
if (!c11Bar.scrollable) throw new Error(`C11: a 5-row list did not scroll (height ${c11Bar.listHeight}px)`);
|
||||
if (c11Bar.listHeight > c11Bar.rowHeight * 3 + 16) {
|
||||
throw new Error(`C11: the list is not capped near three rows (${c11Bar.listHeight}px for ${c11Bar.rowHeight}px rows)`);
|
||||
}
|
||||
if (c11Bar.glyphs !== 5) throw new Error(`C11: every row should carry a play glyph, got ${c11Bar.glyphs}`);
|
||||
if (!c11Bar.statuses.every((word) => word === "Running")) {
|
||||
throw new Error(`C11: row statuses: ${JSON.stringify(c11Bar.statuses)}`);
|
||||
}
|
||||
console.log(
|
||||
` background-tasks bar "${c11Bar.title}" (${c11Bar.count}); ${c11Bar.rows} rows, ` +
|
||||
`3-row cap (list ${c11Bar.listHeight}px, row ${c11Bar.rowHeight}px), scrolling: ${c11Bar.scrollable}`,
|
||||
);
|
||||
console.log(
|
||||
" NOTE: the shell frames above are replayed synthetic chat_event frames; every other frame (chat_shells, subscribe, history) came from the real server",
|
||||
);
|
||||
await clearBanner();
|
||||
await shot("65-chat-background-tasks.png");
|
||||
|
||||
// A selected task's detail pane: the exact label order and wording, and the
|
||||
// bounded output page it read from its own request. Rows are clicked through
|
||||
// their own handler (and scrolled into view) so a row below the three-row fold
|
||||
// is reachable without a coordinate click landing on the clipped list. A
|
||||
// spurious socket drop can fail a single bounded read (the client refuses to
|
||||
// send while reconnecting), so each read is retried a bounded number of times
|
||||
// through the page's own controls after the socket settles.
|
||||
const clickShellRow = (id) =>
|
||||
page.evaluate(`(() => {
|
||||
const el = document.querySelector('#chatBackgroundTasks .chat-bg-task[data-shell="${id}"]');
|
||||
if (!el) return false;
|
||||
el.scrollIntoView({ block: "center" });
|
||||
el.click();
|
||||
return true;
|
||||
})()`);
|
||||
|
||||
const openShell = async (shellId, readyExpr, what) => {
|
||||
for (let attempt = 1; attempt <= 3; attempt += 1) {
|
||||
// A transient drop can clear the connection and (on reconnect) the replayed
|
||||
// shells; settle the socket and re-establish the bar before selecting.
|
||||
await ensureConnected(30000).catch(() => {});
|
||||
if (!(await page.evaluate(`!!document.querySelector("#chatBackgroundTasks")`))) {
|
||||
await replayShells();
|
||||
await eventually(() => page.evaluate(`!!document.querySelector("#chatBackgroundTasks")`), {
|
||||
timeout: 5000,
|
||||
what: "the bar to render again after a reconnect",
|
||||
});
|
||||
}
|
||||
const selected = await page.evaluate(
|
||||
`document.querySelector("#chatBackgroundTasks .chat-bg-task.selected")?.dataset.shell ?? ""`,
|
||||
);
|
||||
// Selecting the already-selected row is the documented toggle, so close it
|
||||
// first to force a fresh bounded read.
|
||||
if (selected === shellId && !(await clickShellRow(shellId))) {
|
||||
throw new Error(`C11: the ${shellId} row was not present`);
|
||||
}
|
||||
if (!(await clickShellRow(shellId))) throw new Error(`C11: the ${shellId} row was not present`);
|
||||
try {
|
||||
await eventually(() => page.evaluate(readyExpr), { timeout: 8000, what });
|
||||
return;
|
||||
} catch {
|
||||
console.log(` ${shellId}: the read did not land (attempt ${attempt}); settling the socket and retrying`);
|
||||
await page.evaluate(`window.dispatchEvent(new Event("online"))`);
|
||||
}
|
||||
}
|
||||
throw new Error(`C11: ${what} never rendered for ${shellId}`);
|
||||
};
|
||||
|
||||
await openShell(
|
||||
"cap-run",
|
||||
`!!document.querySelector("#chatBackgroundTasks .chat-bg-task-output")`,
|
||||
"the output pane for cap-run",
|
||||
);
|
||||
const c11Detail = await page.evaluate(`(() => {
|
||||
const detail = document.querySelector("#chatBackgroundTasks .chat-bg-task-detail");
|
||||
return {
|
||||
labels: [...detail.querySelectorAll(".chat-bg-task-label")].map((n) => n.textContent),
|
||||
command: detail.querySelector(".chat-bg-task-command-full")?.textContent ?? "",
|
||||
id: detail.querySelector(".chat-bg-task-id")?.textContent ?? "",
|
||||
idMono: !!detail.querySelector(".chat-bg-task-id.monospace"),
|
||||
status: detail.querySelector(".chat-bg-task-status-line")?.textContent ?? "",
|
||||
output: detail.querySelector(".chat-bg-task-output")?.textContent ?? "",
|
||||
refresh: detail.querySelector(".chat-bg-task-refresh")?.textContent ?? "",
|
||||
selected: document.querySelector("#chatBackgroundTasks .chat-bg-task.selected")?.dataset.shell ?? "",
|
||||
detailsWord: document.querySelector("#chatBackgroundTasks .chat-bg-task.selected .chat-bg-task-details")?.textContent ?? "",
|
||||
};
|
||||
})()`);
|
||||
if (!c11Detail.labels.includes("Command")) throw new Error(`C11: missing Command label: ${JSON.stringify(c11Detail.labels)}`);
|
||||
if (!c11Detail.labels.includes("Task identity")) throw new Error(`C11: missing Task identity label`);
|
||||
if (!c11Detail.labels.includes("Output")) throw new Error(`C11: missing Output label`);
|
||||
if (c11Detail.command !== "go test ./... -count=1") throw new Error(`C11: command ${JSON.stringify(c11Detail.command)}`);
|
||||
if (c11Detail.id !== "cap-run" || !c11Detail.idMono) throw new Error(`C11: task identity ${JSON.stringify(c11Detail.id)} mono=${c11Detail.idMono}`);
|
||||
if (c11Detail.status !== "Status: running") throw new Error(`C11: status ${JSON.stringify(c11Detail.status)}`);
|
||||
if (!c11Detail.output.includes("ok")) throw new Error(`C11: output ${JSON.stringify(c11Detail.output)}`);
|
||||
if (c11Detail.refresh !== "Refresh") throw new Error(`C11: refresh control ${JSON.stringify(c11Detail.refresh)}`);
|
||||
if (c11Detail.selected !== "cap-run") throw new Error(`C11: selected row ${JSON.stringify(c11Detail.selected)}`);
|
||||
if (c11Detail.detailsWord !== "Details") throw new Error(`C11: details word ${JSON.stringify(c11Detail.detailsWord)}`);
|
||||
console.log(
|
||||
` selected task detail: labels [${c11Detail.labels.join(", ")}], command "${c11Detail.command}", ` +
|
||||
`id "${c11Detail.id}" (monospace), "${c11Detail.status}", output ${JSON.stringify(c11Detail.output)}`,
|
||||
);
|
||||
await clearBanner();
|
||||
await shot("66-chat-background-task-detail.png");
|
||||
|
||||
// Refresh always rereads the bounded page from cursor 0 and never appends: the
|
||||
// page's own Refresh control issues a second read with the same bounds (the
|
||||
// intercepted request is the page's real wire frame).
|
||||
await page.evaluate(`window.__pipelinesShellReads = []`);
|
||||
await page.evaluate(`document.querySelector("#chatBackgroundTasks .chat-bg-task-refresh").click()`);
|
||||
await eventually(
|
||||
() =>
|
||||
page.evaluate(
|
||||
`(window.__pipelinesShellReads || []).some((r) => r.shell_id === "cap-run" && r.cursor === 0 && r.limit === 65536)`,
|
||||
),
|
||||
{ timeout: 8000, what: "the Refresh re-read at cursor 0 / 64 KiB" },
|
||||
);
|
||||
const refreshReads = await page.evaluate(`window.__pipelinesShellReads`);
|
||||
console.log(
|
||||
` Refresh re-read: ${refreshReads.length} read(s), ` +
|
||||
refreshReads.map((r) => `{shell:${r.shell_id},cursor:${r.cursor},limit:${r.limit}}`).join(", "),
|
||||
);
|
||||
|
||||
// The empty page, the server-reported unavailable page and a truncated page.
|
||||
const noteIs = (expected) =>
|
||||
`document.querySelector("#chatBackgroundTasks .chat-bg-task-note")?.textContent === ${JSON.stringify(expected)}`;
|
||||
await openShell("cap-empty", noteIs("No output yet."), "the No output yet. note");
|
||||
console.log(" cap-empty: \"No output yet.\"");
|
||||
await clearBanner();
|
||||
await shot("67-chat-background-task-empty.png");
|
||||
await openShell("cap-unavail", noteIs("Output unavailable for this task."), "the unavailable note");
|
||||
console.log(" cap-unavail: \"Output unavailable for this task.\"");
|
||||
await clearBanner();
|
||||
await shot("68-chat-background-task-unavailable.png");
|
||||
|
||||
await openShell("cap-trunc", noteIs("Output is bounded to 64 KiB."), "the 64 KiB bound note");
|
||||
const c11Truncated = await page.evaluate(`(() => {
|
||||
const detail = document.querySelector("#chatBackgroundTasks .chat-bg-task-detail");
|
||||
return {
|
||||
note: detail.querySelector(".chat-bg-task-note")?.textContent ?? "",
|
||||
length: detail.querySelector(".chat-bg-task-output")?.textContent.length ?? 0,
|
||||
refresh: !!detail.querySelector(".chat-bg-task-refresh"),
|
||||
};
|
||||
})()`);
|
||||
if (c11Truncated.note !== "Output is bounded to 64 KiB.") throw new Error(`C11: truncated note ${JSON.stringify(c11Truncated.note)}`);
|
||||
if (c11Truncated.length !== 400) throw new Error(`C11: truncated output length ${c11Truncated.length}`);
|
||||
if (!c11Truncated.refresh) throw new Error("C11: a truncated page should still offer Refresh");
|
||||
console.log(` cap-trunc: "${c11Truncated.note}" (${c11Truncated.length}-char page, Refresh offered)`);
|
||||
await clearBanner();
|
||||
await shot("69-chat-background-task-truncated.png");
|
||||
|
||||
// The loading spinner: the same select, with the replayed page delayed.
|
||||
await page.evaluate(`window.__pipelinesInterceptDelay = 1500`);
|
||||
if (!(await clickShellRow("cap-slow"))) throw new Error("C11: the cap-slow row was not present");
|
||||
await eventually(
|
||||
() => page.evaluate(`!!document.querySelector("#chatBackgroundTasks .chat-bg-task-detail .spinner")`),
|
||||
{ timeout: 5000, what: "the loading spinner for cap-slow" },
|
||||
);
|
||||
const loading = await page.evaluate(`(() => ({
|
||||
spinner: !!document.querySelector("#chatBackgroundTasks .chat-bg-task-detail .spinner"),
|
||||
status: document.querySelector("#chatBackgroundTasks .chat-bg-task-status-line")?.textContent ?? "",
|
||||
output: !!document.querySelector("#chatBackgroundTasks .chat-bg-task-output"),
|
||||
}))()`);
|
||||
if (!loading.spinner || loading.output) throw new Error(`C11: loading pane ${JSON.stringify(loading)}`);
|
||||
console.log(` cap-slow: spinner while loading ("${loading.status}")`);
|
||||
await clearBanner();
|
||||
await shot("70-chat-background-task-loading.png");
|
||||
for (let attempt = 1; attempt <= 3; attempt += 1) {
|
||||
let loaded = true;
|
||||
try {
|
||||
await eventually(
|
||||
() => page.evaluate(`!!document.querySelector("#chatBackgroundTasks .chat-bg-task-output")`),
|
||||
{ timeout: 8000, what: "the slow page to arrive" },
|
||||
);
|
||||
} catch {
|
||||
loaded = false;
|
||||
}
|
||||
if (loaded) break;
|
||||
console.log(` cap-slow: the page did not arrive (attempt ${attempt}); settling and retrying`);
|
||||
await page.evaluate(`window.dispatchEvent(new Event("online"))`);
|
||||
await ensureConnected(30000).catch(() => {});
|
||||
if (!(await page.evaluate(`!!document.querySelector("#chatBackgroundTasks")`))) await replayShells();
|
||||
await page.evaluate(`document.querySelector("#chatBackgroundTasks .chat-bg-task-retry")?.click()`);
|
||||
}
|
||||
await page.evaluate(`window.__pipelinesInterceptDelay = 0`);
|
||||
|
||||
// The last exit clears the bar: replay an exited frame for every task and assert
|
||||
// the bar disappears (an exited shell is never listed as a task).
|
||||
await page.evaluate(`(() => {
|
||||
const ws = window.__pipelinesSocket;
|
||||
const ids = ["cap-run", "cap-empty", "cap-unavail", "cap-trunc", "cap-slow"];
|
||||
for (const id of ids) {
|
||||
ws.onmessage({ data: JSON.stringify({ type: "chat_event", chat_event: { session_id: ${JSON.stringify(sessionId)}, kind: "shell", shell: { id, status: "exited", command: "" } } }) });
|
||||
}
|
||||
return true;
|
||||
})()`);
|
||||
await eventually(() => page.evaluate(`!document.querySelector("#chatBackgroundTasks")`), {
|
||||
timeout: 5000,
|
||||
what: "the bar to disappear with the last exit",
|
||||
});
|
||||
console.log(" all shells exited: the background-tasks bar is gone");
|
||||
await clearBanner();
|
||||
await shot("71-chat-background-tasks-exited.png");
|
||||
|
||||
// The list is re-learned on a stream reconnect: a real chat_shells request is
|
||||
// sent after the drop (real traffic), so a gap that swallowed an exit is repaired.
|
||||
await page.evaluate(`window.__pipelinesSentTypes = []`);
|
||||
await page.evaluate(`window.__pipelinesSocket && window.__pipelinesSocket.close(4000, "c11 drop")`);
|
||||
await ensureConnected(30000);
|
||||
await eventually(
|
||||
() => page.evaluate(`(window.__pipelinesSentTypes || []).includes("chat_shells")`),
|
||||
{ timeout: 20000, what: "chat_shells after the stream reconnect" },
|
||||
);
|
||||
console.log(" chat_shells re-fetched after the stream reconnect (real request)");
|
||||
|
||||
console.log("\nUI SMOKE PASS");
|
||||
for (const shot of shots) console.log(` ${shot}`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user