Merge branch 'main' into web-chat-approvals

Resolve C10 vs C11 in the shared shell:
- keep both send hooks in the smoke's WebSocket shim (recording +
  scripted replies + synthetic approval acknowledgement) instead of the
  second assignment overwriting the first;
- close the .chat-approval CSS rule so the C11 background-task rules are
  not swallowed by it (the list lost its 3-row cap and scrolling);
- assert the folding invariant directly (no adjacent agent bubbles)
  instead of 'agent bubbles <= user prompts', which the growing operator
  session now legitimately breaks;
- exercise the resource clamp by scroll overflow instead of a clone
  measurement that the clamped frame makes unreliable.
This commit is contained in:
2026-10-19 11:26:26 +01:00
8 changed files with 1326 additions and 46 deletions
+101 -1
View File
@@ -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");
@@ -441,3 +441,103 @@ test("chatReply refuses blank ids or a decision outside once/always/reject witho
await assert.rejects(() => repo.chatReply("s1", "req-1", ""), ProtocolError);
assert.equal(ws.sent.length, 0);
});
// --- 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.",
});
});