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,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.",
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user