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:
@@ -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,
|
||||
@@ -29,6 +31,17 @@ import {
|
||||
MAX_APPROVAL_RESOURCE_LINES,
|
||||
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,
|
||||
@@ -43,6 +56,7 @@ import {
|
||||
attachmentDisplayName,
|
||||
attachmentError,
|
||||
attachmentFiles,
|
||||
backgroundTasksRunningLabel,
|
||||
chatBottomDistancePx,
|
||||
chatCommandEffect,
|
||||
chatCommandForEnter,
|
||||
@@ -69,6 +83,7 @@ import {
|
||||
historyResync,
|
||||
lineDiff,
|
||||
mergeHistoryPage,
|
||||
mergeShellFrame,
|
||||
mergeToolPart,
|
||||
newChatThread,
|
||||
parseChatInput,
|
||||
@@ -77,7 +92,9 @@ import {
|
||||
prettyToolInput,
|
||||
queuedAfterFrame,
|
||||
reasoningLabel,
|
||||
resumedThread,
|
||||
runningAfterFrame,
|
||||
runningBackgroundShells,
|
||||
runningToolElapsedMillis,
|
||||
runningToolStamps,
|
||||
sessionActivity,
|
||||
@@ -89,6 +106,9 @@ import {
|
||||
sessionTitle,
|
||||
sessionWorkLabel,
|
||||
settledThread,
|
||||
shellCommandSummary,
|
||||
shellOutputState,
|
||||
shellsLoaded,
|
||||
threadElapsedMillis,
|
||||
threadPhase,
|
||||
threadRunningTools,
|
||||
@@ -1324,3 +1344,166 @@ test("applyChatPermission keeps the answer for the same request and clears it fo
|
||||
assert.equal(thread.permission.request_id, "req-2");
|
||||
assert.equal(thread.permissionAnswer, "");
|
||||
});
|
||||
|
||||
// --- 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);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user