Claude Code. Any Model. The most powerful AI coding agent now speaks every language.
test(team): cover recent steps on SlotRow and SessionRow
Jack Rudenko4d106058eb51
diff --git a/packages/cli/src/mcp-blackbox/channel-sessions.blackbox.test.ts b/packages/cli/src/mcp-blackbox/channel-sessions.blackbox.test.tsindex 5997f800..c1ef3071 100644--- a/packages/cli/src/mcp-blackbox/channel-sessions.blackbox.test.ts+++ b/packages/cli/src/mcp-blackbox/channel-sessions.blackbox.test.ts@@ -68,6 +68,7 @@ const SLOT_ROW_KEYS = ["last_activity_at","model","pane",+ "recent","provider","reason","reason_detail",diff --git a/packages/cli/src/mcp-blackbox/team-contract.blackbox.test.ts b/packages/cli/src/mcp-blackbox/team-contract.blackbox.test.tsindex 74f31132..00e9720e 100644--- a/packages/cli/src/mcp-blackbox/team-contract.blackbox.test.ts+++ b/packages/cli/src/mcp-blackbox/team-contract.blackbox.test.ts@@ -71,6 +71,7 @@ const SLOT_ROW_KEYS = ["last_activity_at","model","pane",+ "recent","provider","reason","reason_detail",diff --git a/packages/cli/src/mcp-contract.e2e.test.ts b/packages/cli/src/mcp-contract.e2e.test.tsindex c05dd596..3531ffbf 100644--- a/packages/cli/src/mcp-contract.e2e.test.ts+++ b/packages/cli/src/mcp-contract.e2e.test.ts@@ -37,6 +37,7 @@ const SLOT_ROW_KEYS = ["last_activity_at","model","pane",+ "recent","provider","reason","reason_detail",diff --git a/packages/cli/src/mcp-session/session-manager.test.ts b/packages/cli/src/mcp-session/session-manager.test.tsindex 346ad72b..4d42e0ce 100644--- a/packages/cli/src/mcp-session/session-manager.test.ts+++ b/packages/cli/src/mcp-session/session-manager.test.ts@@ -83,6 +83,7 @@ function sampleInfo(over: Partial<SessionInfo> = {}): SessionInfo {state: "EMPTY",shape: "one-shot",pane: "c1-x-sabcd1234-aaaaaa",+ recent: null,panePid: 4242,startedAt: "2026-10-06T00:00:00.000Z",completedAt: "2026-10-06T00:00:10.000Z",@@ -206,6 +207,7 @@ describe("exported session seams (pure)", () => {"idle_seconds","activity","pane",+ "recent","session_id","started_at","completed_at",@@ -228,6 +230,17 @@ describe("exported session seams (pure)", () => {expect(completed.reason_detail).toBeNull();});+ test.each(["RUNNING", "COMPLETED"] as const)(+ "sessionRowOf passes recent through for %s rows",+ (state) => {+ const recent = [+ { at: "2026-10-06T01:16:16.646Z", kind: "text" as const, tool: null, summary: "KIWI" },+ ];+ expect(sessionRowOf(sampleInfo({ state, recent })).recent).toEqual(recent);+ expect(sessionRowOf(sampleInfo({ state, recent: null })).recent).toBeNull();+ }+ );+test("G4: transport-owned, print-only and positional flags are refused before anything starts", async () => {const root = mkdtempSync(join(tmpdir(), "claudish-g4-"));try {@@ -322,6 +335,12 @@ describe("SessionManager disk reader", () => {expect(cancelled.exitCode).toBe(143);expect(cancelled.elapsedSeconds).toBe(60);expect(cancelled.panePid).toBeNull();+ expect(cancelled.recent).toBeNull();+ const diskRows = ["old-cancelled", "old-completed", "old-timeout", "old-finishing"].map((id) =>+ sessionRowOf(manager.getSession(id))+ );+ expect(diskRows).toHaveLength(4);+ expect(diskRows.every((row) => row.recent === null)).toBe(true);expect(manager.getSession("old-completed")).toMatchObject({ state: "COMPLETED", reason: null });expect(manager.getSession("old-timeout")).toMatchObject({state: "TIMEOUT",@@ -571,6 +590,36 @@ describe.skipIf(!MAGMUX)(T_PANE);+ test(+ "recent is null before a step, survives settle, and clears when the next turn opens",+ async () => {+ const manager = makeManager();+ const id = await create(manager, { model: "contract-fake-model" });+ await waitForState(manager, id, ["AWAITING_INPUT"]);+ expect(sessionRowOf(manager.getSession(id)).recent).toBeNull();+ expect(manager.sendInput(id, "first answer").success).toBe(true);+ await waitUntil(+ () =>+ manager.getSession(id).turnsCompleted === 1 &&+ manager.getSession(id).state === "AWAITING_INPUT",+ 15_000+ );+ const settled = sessionRowOf(manager.getSession(id)).recent;+ expect(settled).not.toBeNull();+ expect(+ settled?.some(+ (step) =>+ step.kind === "text" && step.summary === manager.getOutput(id).output.split("\n")[0]+ )+ ).toBe(true);+ expect(sessionRowOf(manager.getSession(id)).recent).toEqual(settled);+ expect(manager.sendInput(id, "hold the next turn @@HANG@@").success).toBe(true);+ await waitForState(manager, id, ["RUNNING"]);+ expect(sessionRowOf(manager.getSession(id)).recent).toBeNull();+ },+ T_PANE+ );+test("spawnModel changes argv while SessionInfo keeps the requested model; the argv is interactive",async () => {diff --git a/packages/cli/src/mcp-session/session-records.contract.test.ts b/packages/cli/src/mcp-session/session-records.contract.test.tsindex 3e277576..18fa3cc7 100644--- a/packages/cli/src/mcp-session/session-records.contract.test.ts+++ b/packages/cli/src/mcp-session/session-records.contract.test.ts@@ -145,6 +145,7 @@ describe("EMPTY is a failure to the monitor (§20.1)", () => {state: "EMPTY",shape: "one-shot",pane: "p",+ recent: null,panePid: 4242,startedAt: "2026-10-06T00:00:00.000Z",completedAt: "2026-10-06T00:00:05.000Z",diff --git a/packages/cli/src/pane/accounting.test.ts b/packages/cli/src/pane/accounting.test.tsindex 2bd12c2b..67af04a4 100644--- a/packages/cli/src/pane/accounting.test.ts+++ b/packages/cli/src/pane/accounting.test.ts@@ -54,6 +54,7 @@ function snap(over: Partial<PaneSnapshot> = {}): PaneSnapshot {shape: "one-shot",turnEndRecordMissing: false,agentCountMismatch: false,+ recent: null,...over,};}@@ -187,6 +188,7 @@ describe("toSlotRow (§8 B)", () => {idle_seconds: 7,activity: "Bash",pane: "c1-k0-t01-abcdef",+ recent: null,});expect(Object.keys(row).sort()).toEqual([@@ -196,6 +198,7 @@ describe("toSlotRow (§8 B)", () => {"last_activity_at","model","pane",+ "recent","provider","reason","reason_detail",@@ -272,12 +275,34 @@ describe("toSlotRow (§8 B)", () => {expect(toSlotRow(id, live, acct).activity).toBe("background: agent_count_mismatch");});- test("a pane that never spawned has pane null", () => {+ test.each(["RUNNING", "COMPLETED"] as const)(+ "%s rows pass recent through without dropping settled steps",+ (state) => {+ const recent = [+ {+ at: "2026-10-06T01:16:15.109Z",+ kind: "tool" as const,+ tool: "Read",+ summary: "/Users/example/work/task.md",+ },+ ];+ const snapshot = snap({ state, phase: state, recent });+ const row = toSlotRow(+ { slot: "06", model: "haiku", spawnModel: null },+ snapshot,+ mergeAccounting(snapshot, null)+ );+ expect(row.recent).toEqual(recent);+ }+ );++ test("a pane that never spawned has pane and recent null", () => {const row = toSlotRow({ slot: "04", model: "m", spawnModel: null },snap({ paneId: "", state: "FAILED", phase: "FAILED", reason: "pane_lost" }),mergeAccounting(snap(), null));expect(row.pane).toBeNull();+ expect(row.recent).toBeNull();});});diff --git a/packages/cli/src/pane/slot-steps.test.ts b/packages/cli/src/pane/slot-steps.test.tsnew file mode 100644index 00000000..a8fed154--- /dev/null+++ b/packages/cli/src/pane/slot-steps.test.ts@@ -0,0 +1,186 @@+import { describe, expect, test } from "bun:test";+import { RECENT_STEP_LIMIT, STEP_SUMMARY_MAX, oneLine, stepOf } from "./slot-steps.js";++const AT = "2026-10-06T01:16:08.448Z";+const TOKEN = `ghp_${"a".repeat(36)}`;++describe("SlotStep summaries", () => {+ test("exports the contract limits", () => {+ expect(RECENT_STEP_LIMIT).toBe(20);+ expect(STEP_SUMMARY_MAX).toBe(100);+ });++ test.each([+ ["text", { type: "text", text: "\n First line \nSecond line" }, "text", null, "First line"],+ [+ "thinking",+ { type: "thinking", thinking: "\r\n Think first \r\nNot this line" },+ "thinking",+ null,+ "Think first",+ ],+ [+ "question",+ {+ type: "tool_use",+ name: "AskUserQuestion",+ input: {+ questions: [+ { question: "" },+ { question: " Which fruit? \nNot this line" },+ { question: "Not this question" },+ ],+ },+ },+ "ask",+ "AskUserQuestion",+ "Which fruit?",+ ],+ ] as const)("%s uses its first non-empty line", (_label, block, kind, tool, summary) => {+ expect(stepOf(block, AT)).toEqual({ at: AT, kind, tool, summary });+ });++ test.each([+ ["Read", "file_path", "/Users/example/work/read.ts"],+ ["Edit", "file_path", "/Users/example/work/edit.ts"],+ ["Write", "file_path", "/home/example/work/write.ts"],+ ["Bash", "command", "printf first"],+ ["Grep", "pattern", "TODO.*recent"],+ ["Glob", "pattern", "**/*.test.ts"],+ ["WebSearch", "query", "transcript timestamps"],+ ["WebFetch", "url", "https://example.com/transcript"],+ ["Task", "description", "Inspect transcript"],+ ["Agent", "description", "Review transcript"],+ ])("%s uses only input.%s, not other input fields", (name, field, summary) => {+ const input = {+ file_path: "wrong path",+ command: "wrong command",+ pattern: "wrong pattern",+ query: "wrong query",+ url: "wrong url",+ description: "wrong description",+ content: "never include tool content",+ [field]: `\n ${summary} \nNot this line`,+ };+ expect(stepOf({ type: "tool_use", name, input }, AT)).toEqual({+ at: AT,+ kind: "tool",+ tool: name,+ summary,+ });+ });++ test("an unknown tool has an empty summary even when familiar fields are present", () => {+ expect(+ stepOf(+ {+ type: "tool_use",+ name: "CustomTool",+ input: { command: "private", description: "private", file_path: "/private" },+ },+ AT+ )+ ).toEqual({+ at: AT,+ kind: "tool",+ tool: "CustomTool",+ summary: "",+ });+ });++ test.each([undefined, null, 1, {}, "", " \n\t\r\n"])("oneLine(%j) is empty", (value) => {+ expect(oneLine(value)).toBe("");+ });++ test.each([+ null,+ "not a block",+ {},+ { type: "text", text: " \n\t" },+ { type: "text" },+ { type: "thinking", thinking: "\r\n " },+ { type: "redacted_thinking", data: "never show this" },+ { type: "image", source: { data: "never show this" } },+ { type: "tool_use", name: "" },+ { type: "tool_use" },+ { type: "tool_result", content: `result-only ${TOKEN}` },+ ])("non-step block %j produces no step", (block) => {+ expect(stepOf(block, AT)).toBeNull();+ });++ test.each(["Read", "Bash", "AskUserQuestion"])(+ "%s without its target has an empty summary",+ (name) => {+ expect(stepOf({ type: "tool_use", name }, AT)?.summary).toBe("");+ }+ );++ test.each([99, 100, 101, 200])("oneLine bounds a %i-character summary", (length) => {+ const summary = oneLine("x".repeat(length));+ expect(summary.length).toBe(Math.min(length, 100));+ expect(summary).toBe(length > 100 ? `${"x".repeat(99)}…` : "x".repeat(length));+ });++ test.each([+ { type: "text", text: "x".repeat(101) },+ { type: "thinking", thinking: "x".repeat(101) },+ { type: "tool_use", name: "Bash", input: { command: "x".repeat(101) } },+ {+ type: "tool_use",+ name: "AskUserQuestion",+ input: { questions: [{ question: "x".repeat(101) }] },+ },+ ])("every step kind truncates to exactly 100 characters with an ellipsis", (block) => {+ expect(stepOf(block, AT)?.summary).toBe(`${"x".repeat(99)}…`);+ });++ test("redacts a Bash Authorization credential without dropping the command or URL", () => {+ const command = `curl -H "Authorization: Bearer ${TOKEN}" https://x\nprintf hidden`;+ const step = stepOf({ type: "tool_use", name: "Bash", input: { command } }, AT)!;+ expect(step.summary).not.toContain(TOKEN);+ expect(step.summary).toContain("curl -H");+ expect(step.summary).toContain("https://x");+ expect(step.summary).not.toContain("printf hidden");+ });++ test.each([+ { type: "text", text: `credential ${TOKEN}` },+ { type: "thinking", thinking: `credential ${TOKEN}` },+ { type: "tool_use", name: "WebFetch", input: { url: `https://x/?token=${TOKEN}` } },+ {+ type: "tool_use",+ name: "AskUserQuestion",+ input: { questions: [{ question: `Use ${TOKEN}?` }] },+ },+ ])("redacts credentials in every summary kind", (block) => {+ const step = stepOf(block, AT)!;+ expect(step.summary).not.toContain(TOKEN);+ expect(step.summary.length).toBeGreaterThan(0);+ });++ test("redacts before truncation and keeps home-directory paths", () => {+ const line = `/Users/example/${TOKEN}/${"z".repeat(110)}`;+ const summary = oneLine(line);+ expect(summary).not.toContain(TOKEN);+ expect(summary.startsWith("/Users/example/")).toBe(true);+ expect(summary).toHaveLength(100);+ expect(summary.endsWith("…")).toBe(true);+ expect(oneLine(" /Users/example/src/index.ts ")).toBe("/Users/example/src/index.ts");+ expect(oneLine(" /home/example/src/index.ts ")).toBe("/home/example/src/index.ts");+ });++ test("AskUserQuestion skips whitespace-only questions before choosing the first non-empty question", () => {+ expect(+ stepOf(+ {+ type: "tool_use",+ name: "AskUserQuestion",+ input: {+ questions: [{ question: " \r\n\t " }, { question: "\n Which fruit?\nMore detail" }],+ },+ },+ AT+ )+ ).toEqual({ at: AT, kind: "ask", tool: "AskUserQuestion", summary: "Which fruit?" });+ });+});diff --git a/packages/cli/src/pane/transcript-recent.test.ts b/packages/cli/src/pane/transcript-recent.test.tsnew file mode 100644index 00000000..e3a5c816--- /dev/null+++ b/packages/cli/src/pane/transcript-recent.test.ts@@ -0,0 +1,194 @@+import { describe, expect, test } from "bun:test";+import { readFileSync } from "node:fs";+import { join } from "node:path";+import type { SlotStep } from "./contract.js";+import { RECENT_STEP_LIMIT } from "./slot-steps.js";+import { FIXTURES } from "./test-helpers/fixtures.js";+import {+ type Rec,+ textOf,+ transcriptRecords,+ witnessIndex,+} from "./test-helpers/transcript-fixtures.js";+import {+ applyRecord,+ applySubagentRecord,+ initialFollowerState,+ openTurnState,+ turnView,+} from "./transcript-follower.js";++const NAME = "tools-session";+const RECORDS = transcriptRecords(NAME);+const PROMPT =+ "Your task is in the file `/tmp/cc2/launch-XW9UoC/turn-1.md`. Read all of it with the Read tool (in parts if it is long), then do exactly what it says, treating its content as the user's message.";+const AT = witnessIndex(NAME, PROMPT);+const END = RECORDS.findIndex((r, i) => i > AT && r.subtype === "turn_duration");+const TURN = RECORDS.slice(AT, END + 1);+const READ_STEP: SlotStep = {+ at: "2026-10-06T01:16:15.109Z",+ kind: "tool",+ tool: "Read",+ summary: "/tmp/cc2/launch-XW9UoC/turn-1.md",+};+const TEXT_STEP: SlotStep = {+ at: "2026-10-06T01:16:16.646Z",+ kind: "text",+ tool: null,+ summary: "KIWI",+};++/** Replay unchanged real records; byte offsets increase even when a record is replayed. */+function reducer() {+ const state = initialFollowerState((p) => p);+ let offset = 0;+ const push = (record: Rec) => {+ offset += Buffer.byteLength(JSON.stringify(record)) + 1;+ applyRecord(state, record, offset);+ };+ for (const record of RECORDS.slice(0, AT)) push(record);+ const open = (index: number) =>+ openTurnState(state, { index, offset, witness: { kind: "text", text: PROMPT } });+ open(1);+ return { state, push, open, view: () => turnView(state.turns[0]!) };+}++describe("current-turn recent steps from real transcripts", () => {+ test("the capture has a file witness, a Read, a result and a multiline text answer", () => {+ expect(AT).toBeGreaterThan(0);+ expect(END).toBeGreaterThan(AT);+ expect(textOf(TURN[0]!)).toBe(PROMPT);+ expect(+ TURN.some(+ (r) =>+ r.type === "user" &&+ Array.isArray(r.message?.content) &&+ r.message.content.some((b: Rec) => b.type === "tool_result")+ )+ ).toBe(true);+ expect(+ TURN.find(+ (r) => r.type === "assistant" && r.message.content.some((b: Rec) => b.type === "text")+ )?.message.content[0].text+ ).toBe("KIWI\n5");+ });++ test("Read and text steps retain record order, input file_path, first line and exact timestamps", () => {+ const r = reducer();+ for (const record of TURN) r.push(record);+ expect(r.view().recent).toEqual([READ_STEP, TEXT_STEP]);+ for (const step of r.view().recent) {+ const record = TURN.find((record) => record.timestamp === step.at);+ expect(record?.type).toBe("assistant");+ expect(step.at).toBe(record?.timestamp);+ }+ });++ test("assistant blocks before the witness are excluded, including earlier turns", () => {+ const r = reducer();+ expect(r.view().recent).toEqual([]);+ const textRecord = TURN.find(+ (record) => record.type === "assistant" && textOf(record) === "KIWI\n5"+ )!;+ r.push(textRecord);+ expect(r.view().acceptedAt).toBeNull();+ expect(r.view().recent).toEqual([]);+ for (const record of TURN) r.push(record);+ expect(r.view().recent).toEqual([READ_STEP, TEXT_STEP]);+ });++ test("real sidechain records add no steps through either reducer entry point", () => {+ const sidechain: Rec[] = readFileSync(+ join(FIXTURES, "transcripts", "tools-session", "subagents", "agent-a6d024f5474e98666.jsonl"),+ "utf8"+ )+ .trim()+ .split("\n")+ .map((line) => JSON.parse(line));+ const assistants = sidechain.filter((record) => record.type === "assistant");+ expect(assistants.length).toBeGreaterThan(0);+ expect(assistants.every((record) => record.isSidechain === true)).toBe(true);+ expect(assistants.some((record) => textOf(record) === "OK")).toBe(true);+ const r = reducer();+ for (const record of TURN) r.push(record);+ for (const record of sidechain) {+ r.push(record);+ applySubagentRecord(r.state, record, 1_000_000);+ }+ expect(r.view().recent).toEqual([READ_STEP, TEXT_STEP]);+ });++ test("real isApiErrorMessage records add no steps", () => {+ const errors = transcriptRecords("api-error-hookless").filter(+ (record) => record.isApiErrorMessage+ );+ expect(errors).toHaveLength(1);+ const r = reducer();+ r.push(TURN[0]!);+ for (const record of errors) r.push(record);+ expect(r.view().apiError?.status).toBe(401);+ expect(r.view().recent).toEqual([]);+ for (const record of TURN.slice(1)) r.push(record);+ for (const record of errors) r.push(record);+ expect(r.view().recent).toEqual([READ_STEP, TEXT_STEP]);+ });++ test("tool_result records never add steps or summaries", () => {+ const r = reducer();+ let results = 0;+ for (const record of TURN) {+ const before = r.view().recent;+ r.push(record);+ if (+ record.type === "user" &&+ Array.isArray(record.message?.content) &&+ record.message.content.some((b: Rec) => b.type === "tool_result")+ ) {+ results++;+ expect(r.view().recent).toEqual(before);+ }+ }+ expect(results).toBeGreaterThan(0);+ expect(r.view().recent).toEqual([READ_STEP, TEXT_STEP]);+ });++ test("the 20-step limit drops the oldest steps, not the newest", () => {+ const r = reducer();+ for (const record of TURN) r.push(record);+ const expected = [READ_STEP, TEXT_STEP];+ const assistants = TURN.filter((record) => record.type === "assistant");+ // Replaying unmodified real assistant records is allowed by Brief H.+ for (let i = 0; i < 10; i++) {+ for (const record of assistants) r.push(record);+ expected.push(READ_STEP, TEXT_STEP);+ }+ // A distinct last step makes dropping the newest distinguishable from dropping the oldest.+ const plum = RECORDS.find(+ (record) => record.type === "assistant" && textOf(record) === "PLUM"+ )!;+ r.push(plum);+ expected.push({ at: plum.timestamp, kind: "text", tool: null, summary: "PLUM" });+ expect(expected).toHaveLength(23);+ expect(r.view().recent).toHaveLength(20);+ expect(r.view().recent).toEqual(expected.slice(-RECENT_STEP_LIMIT));+ expect(r.view().recent[0]).toEqual(TEXT_STEP);+ expect(r.view().recent.at(-1)?.summary).toBe("PLUM");+ });++ test("steps survive turn_duration and reset only when a new turn opens", () => {+ const r = reducer();+ for (const record of TURN.slice(0, -1)) r.push(record);+ expect(r.view().turnDurationAfterLast).toBeNull();+ expect(r.view().recent).toEqual([READ_STEP, TEXT_STEP]);+ r.push(TURN.at(-1)!);+ expect(r.view().turnDurationAfterLast).not.toBeNull();+ expect(r.view().recent).toEqual([READ_STEP, TEXT_STEP]);+ expect(r.view().recent).toEqual([READ_STEP, TEXT_STEP]); // polling does not consume steps+ r.open(2);+ expect(r.view().index).toBe(2);+ expect(r.view().recent).toEqual([]);+ r.push(TURN[0]!);+ expect(r.view().acceptedAt).not.toBeNull();+ expect(r.view().recent).toEqual([]);+ });+});diff --git a/packages/cli/src/team-status-payload.test.ts b/packages/cli/src/team-status-payload.test.tsindex aaca7041..3ead1a8e 100644--- a/packages/cli/src/team-status-payload.test.ts+++ b/packages/cli/src/team-status-payload.test.ts@@ -77,6 +77,23 @@ describe("teamStatusNote", () => {});describe("teamRunRowFromDisk", () => {+ test("disk rows have recent null in active and settled states", () => {+ const dir = mkdtempSync(join(tmpdir(), "team-disk-recent-"));+ try {+ const status: TeamStatus = {+ startedAt: "2026-10-06T00:00:00.000Z",+ models: { "01": slot("RUNNING", 0), "02": slot("COMPLETED", 12) },+ };+ const rows = teamRunRowFromDisk(dir, status).slots;+ expect(rows.map((row) => [row.slot, row.state, row.recent])).toEqual([+ ["01", "RUNNING", null],+ ["02", "COMPLETED", null],+ ]);+ } finally {+ rmSync(dir, { recursive: true, force: true });+ }+ });+test("a SETTLED run whose rows carry no completedAt still has a finished_at", () => {const dir = mkdtempSync(join(tmpdir(), "team-disk-row-"));try {