Skip to content

Claude Code. Any Model. The most powerful AI coding agent now speaks every language.

test(channel): assert session records instead of channel notifications

Jack Rudenkob4a1713ea18a
diff --git a/packages/cli/src/channel/channel-wire-format.test.ts b/packages/cli/src/channel/channel-wire-format.test.ts
index a25f7ae6..171b058f 100644
--- a/packages/cli/src/channel/channel-wire-format.test.ts
+++ b/packages/cli/src/channel/channel-wire-format.test.ts
@@ -1,67 +1,16 @@
-/**
- * Channel notification wire-format regression tests.
- *
- * These tests pin the exact JSON-RPC contract that the MCP server emits over
- * stdio for channel notifications. They run without any API key: the server's
- * CLAUDISH_BIN is the pane fake (pane/test-helpers/fake-interactive-child.ts),
- * which a real headless magmux runs as an interactive child; its transcript
- * drives the pane session's state machine, whose transitions fire
- * onStateChange callbacks, which invoke server.notification(), which serialize
- * JSON-RPC frames to stdout. The server env is hermetic (contract-mcp.ts
- * `serverEnv`) with its own pane root, and every test proves no pane is left.
- *
- * Why a dedicated test file:
- * - The OPENROUTER_API_KEY-gated lifecycle test in e2e-channel.test.ts
- * does similar checks but is skipped when the key is absent, so CI never
- * runs it. These tests run unconditionally (wherever magmux is installed).
- * - We use raw JSON-RPC over child process pipes (not the MCP Client SDK)
- * so we can assert the literal frame objects — that's the wire contract.
- *
- * What's pinned:
- * 1. The notification method name: "notifications/claude/channel"
- * 2. params.content is a string
- * 3. params.meta required keys: session_id, event, model, elapsed_seconds
- * 4. session_id is an 8-char hex string (from randomUUID().slice(0, 8))
- * 5. elapsed_seconds is serialized as a numeric string (not a number)
- * 6. jsonrpc: "2.0" framing
- *
- * If a future refactor changes any of these, these tests will fail loudly.
- */
+/** MCP capability regression tests using raw JSON-RPC over a hermetic server's stdio. */
import { afterEach, describe, expect, test } from "bun:test";
import { type ChildProcess, spawn } from "node:child_process";
import { dirname, join } from "node:path";
import { fileURLToPath } from "node:url";
-import {
- FAKE_MODEL,
- MAGMUX_AVAILABLE,
- McpServer,
- NO_MAGMUX_MESSAGE,
- type ToolResult,
- paneOrphans,
- serverEnv,
-} from "../test-helpers/contract-mcp.js";
-import { type TempLayout, makeTempLayout, waitFor } from "../test-helpers/contract-records.js";
+import { paneOrphans, serverEnv } from "../test-helpers/contract-mcp.js";
+import { type TempLayout, makeTempLayout } from "../test-helpers/contract-records.js";
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const SERVER_ENTRY = join(__dirname, "../index.ts");
-const TERMINAL_EVENTS = ["completed", "failed", "cancelled", "timeout"];
-
-// ─── Helper: drive an MCP server session and capture frames ─────────────────
-
-interface ChannelFrame {
- method: string;
- params: { content: string; meta: Record<string, string> };
- jsonrpc: string;
-}
-
-interface CapturedFrames {
- notifications: ChannelFrame[];
- createResult: ToolResult;
-}
-
const layouts: TempLayout[] = [];
afterEach(async () => {
@@ -73,192 +22,6 @@ afterEach(async () => {
}
});
-function channelFrames(server: McpServer): ChannelFrame[] {
- return server.notifications.filter(
- (n) => n.method === "notifications/claude/channel"
- ) as unknown as ChannelFrame[];
-}
-
-/**
- * Start a server, create one session, collect its channel frames until `until` holds
- * (default: a terminal event), then close the server (stdin EOF shuts it down).
- */
-async function captureSessionFrames(opts: {
- model?: string;
- prompt?: string;
- until?: (frames: ChannelFrame[]) => boolean;
- timeoutMs?: number;
-}): Promise<CapturedFrames> {
- const layout = makeTempLayout("wireformat");
- layouts.push(layout);
- const server = await McpServer.start({ env: serverEnv(layout), cwd: layout.cwd });
- try {
- const createResult = await server.callTool("create_session", {
- model: opts.model ?? FAKE_MODEL,
- prompt: opts.prompt ?? "Reply with a short answer.",
- timeout_seconds: 60,
- });
- expect(createResult.isError).toBe(false);
- const until =
- opts.until ??
- ((frames: ChannelFrame[]) =>
- frames.some((f) => TERMINAL_EVENTS.includes(f.params?.meta?.event)));
- await waitFor(() => until(channelFrames(server)), {
- what: "the expected channel frames",
- timeoutMs: opts.timeoutMs ?? 20_000,
- });
- // Brief grace period to capture any final frames
- await Bun.sleep(200);
- return { notifications: [...channelFrames(server)], createResult };
- } finally {
- await server.close();
- }
-}
-
-// ─── Tests ──────────────────────────────────────────────────────────────────
-
-describe.skipIf(!MAGMUX_AVAILABLE)(
- `Channel notification wire format${MAGMUX_AVAILABLE ? "" : ` (${NO_MAGMUX_MESSAGE})`}`,
- () => {
- test("emits well-formed notifications/claude/channel JSON-RPC frames", async () => {
- const captured = await captureSessionFrames({});
-
- // At least one notification should arrive (running + completed expected)
- expect(captured.notifications.length).toBeGreaterThan(0);
-
- for (const n of captured.notifications) {
- // Method name is exactly the contracted string
- expect(n.method).toBe("notifications/claude/channel");
-
- // JSON-RPC framing
- expect(n.jsonrpc).toBe("2.0");
-
- // params shape
- expect(n.params).toBeDefined();
- expect(typeof n.params.content).toBe("string");
- expect(n.params.meta).toBeDefined();
-
- // Required meta keys (current Claudish vocabulary)
- expect(n.params.meta.session_id).toMatch(/^[0-9a-f]{8}$/);
- expect(typeof n.params.meta.event).toBe("string");
- expect(n.params.meta.model).toBe(FAKE_MODEL);
-
- // elapsed_seconds is serialized as a string (not a number) —
- // this is intentional per the MCP server's bridge: see mcp-server.ts
- // where it calls String(event.elapsedSeconds).
- expect(typeof n.params.meta.elapsed_seconds).toBe("string");
- expect(n.params.meta.elapsed_seconds).toMatch(/^\d+$/);
-
- // SEP-1686 forward-compat fields (additive — see mcp-server.ts bridge
- // and ai-docs/sessions/.../sep-1686-migration-schema.md)
- // task_id mirrors session_id (will become the only field after migration)
- expect(n.params.meta.task_id).toBe(n.params.meta.session_id);
- // status carries the SEP-1686 5-value TaskStatus enum
- expect(["working", "input_required", "completed", "failed", "cancelled"]).toContain(
- n.params.meta.status
- );
- // ISO 8601 timestamps
- expect(n.params.meta.created_at).toMatch(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/);
- expect(n.params.meta.last_updated_at).toMatch(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/);
- }
- }, 40_000);
-
- test("SEP-1686 status mapping: 9-value event collapses to 5-value status correctly", async () => {
- const captured = await captureSessionFrames({});
- expect(captured.notifications.length).toBeGreaterThan(0);
-
- // Build (event, status) pairs and validate every observed pair against
- // the expected mapping defined in mcp-server.ts:EVENT_TO_TASK_STATUS.
- // RB1: `finishing` is no longer a channel event; `awaiting_permission` is (F5).
- const expectedMapping: Record<string, string> = {
- starting: "working",
- running: "working",
- tool_executing: "working",
- waiting_for_input: "input_required",
- awaiting_permission: "input_required",
- completed: "completed",
- failed: "failed",
- cancelled: "cancelled",
- timeout: "failed",
- };
-
- for (const n of captured.notifications) {
- const event = n.params.meta.event as string;
- const status = n.params.meta.status as string;
- const expected = expectedMapping[event];
- if (expected !== undefined) {
- expect(status).toBe(expected);
- } else {
- // Unknown event types fall through to "working" per
- // mapEventToTaskStatus's default. If a NEW event type ever leaks
- // through without an entry in EVENT_TO_TASK_STATUS, this catches it.
- expect(status).toBe("working");
- }
- }
- }, 40_000);
-
- test("a permission dialog emits awaiting_permission with status input_required", async () => {
- const captured = await captureSessionFrames({
- model: "fake-permission",
- prompt: "Edit the file.",
- until: (frames) => frames.some((f) => f.params?.meta?.event === "awaiting_permission"),
- });
- const frame = captured.notifications.find(
- (n) => n.params.meta.event === "awaiting_permission"
- );
- expect(frame).toBeDefined();
- expect(frame?.params.meta.status).toBe("input_required");
- expect(frame?.params.meta.model).toBe("fake-permission");
- expect(typeof frame?.params.content).toBe("string");
- }, 40_000);
-
- test("all notifications for one session share the same created_at timestamp", async () => {
- const captured = await captureSessionFrames({});
- expect(captured.notifications.length).toBeGreaterThan(0);
-
- // created_at is the session start time; all events from one session
- // must report the same value. last_updated_at varies per event.
- const createdAts = new Set(captured.notifications.map((n) => n.params.meta.created_at));
- expect(createdAts.size).toBe(1);
-
- // last_updated_at should differ across at least some events (they fire
- // at different moments). Typically running + completed, so at least
- // 2 distinct timestamps.
- const lastUpdates = new Set(captured.notifications.map((n) => n.params.meta.last_updated_at));
- expect(lastUpdates.size).toBeGreaterThan(0);
- }, 40_000);
-
- test("all notifications for one session share the same session_id", async () => {
- const captured = await captureSessionFrames({});
- expect(captured.notifications.length).toBeGreaterThan(0);
-
- const ids = new Set(captured.notifications.map((n) => n.params.meta.session_id));
- expect(ids.size).toBe(1);
- }, 40_000);
-
- test("session lifecycle ends with a terminal event (completed/failed/cancelled)", async () => {
- const captured = await captureSessionFrames({});
- expect(captured.notifications.length).toBeGreaterThan(0);
-
- const events = captured.notifications.map((n) => n.params.meta.event);
- const lastEvent = events[events.length - 1];
- expect(["completed", "failed", "cancelled"]).toContain(lastEvent);
- }, 40_000);
-
- test("create_session response payload contains session_id matching notifications", async () => {
- const captured = await captureSessionFrames({});
-
- const parsed = captured.createResult.json as { session_id: string };
- expect(parsed.session_id).toMatch(/^[0-9a-f]{8}$/);
-
- // session_id from create_session response must equal the one in
- // notifications — they describe the same session.
- const notifSid = captured.notifications[0]?.params.meta.session_id;
- expect(parsed.session_id).toBe(notifSid);
- }, 40_000);
- }
-);
-
describe("MCP capability declaration", () => {
async function initializeCapabilities(
toolMode: string
@@ -325,18 +88,11 @@ describe("MCP capability declaration", () => {
).result.capabilities;
}
- test("initialize response declares experimental.claude/channel capability", async () => {
- const caps = await initializeCapabilities("all");
- expect(caps.experimental).toBeDefined();
- expect(caps.experimental).toHaveProperty("claude/channel");
- }, 15_000);
-
- test("experimental capability is omitted when channel tools are disabled", async () => {
- // With CLAUDISH_MCP_TOOLS=low-level, channel tools are gated off and
- // the experimental.claude/channel capability should NOT be declared.
- const caps = await initializeCapabilities("low-level");
- // Either experimental is absent entirely, or it doesn't have claude/channel
- const hasChannel = !!caps.experimental && "claude/channel" in caps.experimental;
- expect(hasChannel).toBe(false);
- }, 15_000);
+ for (const toolMode of ["all", "low-level"]) {
+ test(`initialize response has no experimental capability for ${toolMode}`, async () => {
+ const caps = await initializeCapabilities(toolMode);
+ expect(caps).toHaveProperty("tools");
+ expect(caps).not.toHaveProperty("experimental");
+ }, 15_000);
+ }
});
diff --git a/packages/cli/src/channel/e2e-channel.test.ts b/packages/cli/src/channel/e2e-channel.test.ts
index 7e340d2a..1452595f 100644
--- a/packages/cli/src/channel/e2e-channel.test.ts
+++ b/packages/cli/src/channel/e2e-channel.test.ts
@@ -1,9 +1,9 @@
/**
- * E2E tests for channel mode using real Claude Code.
+ * E2E tests for session tools using real Claude Code.
*
* Spawns `claude -p` with `--mcp-config` pointing at our MCP server and
* validates the full flow: Claude Code connects to our server, discovers
- * tools, calls them, and receives channel notifications.
+ * tools, calls them, and polls session output.
*
* Tests are grouped by what they validate:
* Group 1: MCP server protocol (capabilities, tools) — via SDK client
@@ -42,7 +42,7 @@ const hasOpenRouterKey = SKIP_LIVE_E2E ? false : await hasCredential("openrouter
// ─── Group 1: MCP Protocol Tests (SDK Client) ───────────────────────────────
// Validates the MCP server itself works correctly at the protocol level.
-describe("Group 1: MCP Protocol — channel capability", () => {
+describe("Group 1: MCP Protocol — session tools", () => {
let client: Client;
let transport: StdioClientTransport;
@@ -69,16 +69,18 @@ describe("Group 1: MCP Protocol — channel capability", () => {
} catch {}
});
- test("declares experimental claude/channel capability", () => {
+ test("does not declare an experimental capability", () => {
const caps = client.getServerCapabilities();
- expect(caps?.experimental?.["claude/channel"]).toBeDefined();
+ expect(caps).toHaveProperty("tools");
+ expect(caps).not.toHaveProperty("experimental");
});
- test("provides instructions containing channel event docs", () => {
+ test("provides polling instructions without channel or notification docs", () => {
const instructions = client.getInstructions();
- expect(instructions).toContain("session_id");
- expect(instructions).toContain("input_required");
- expect(instructions).toContain("completed");
+ expect(instructions).toContain("list_sessions");
+ expect(instructions).toContain("get_output");
+ expect(instructions).not.toContain("<channel");
+ expect(instructions).not.toContain("notification");
});
test("lists the exact public tool list", async () => {
@@ -166,11 +168,6 @@ describe("Group 1: MCP Protocol — channel capability", () => {
test.skipIf(!hasOpenRouterKey)(
"create_session → poll → get_output lifecycle",
async () => {
- const notifications: any[] = [];
- client.fallbackNotificationHandler = async (n: any) => {
- if (n.method === "notifications/claude/channel") notifications.push(n.params);
- };
-
const res = await client.callTool({
name: "create_session",
arguments: {
@@ -217,28 +214,6 @@ describe("Group 1: MCP Protocol — channel capability", () => {
const out = await client.callTool({ name: "get_output", arguments: { session_id: sid } });
const output = JSON.parse((out.content as any)[0].text);
expect(output.output.length).toBeGreaterThan(0);
- expect(notifications.length).toBeGreaterThan(0);
-
- // All notifications must carry required meta fields
- for (const n of notifications) {
- expect(n.meta.session_id).toBe(sid);
- expect(n.meta.event).toBeDefined();
- expect(n.meta.model).toBeDefined();
- expect(n.meta.elapsed_seconds).toBeDefined();
- }
-
- // At least one "running" event (first output triggers starting → running)
- const events = notifications.map((n: any) => n.meta.event as string);
- expect(events).toContain("running");
-
- // Last event must be a terminal state
- const lastEvent = events[events.length - 1];
- expect(["completed", "failed"]).toContain(lastEvent);
-
- // No terminal event before a "running" event
- const firstRunningIdx = events.indexOf("running");
- const firstTerminalIdx = events.findIndex((e: string) => e === "completed" || e === "failed");
- expect(firstTerminalIdx).toBeGreaterThan(firstRunningIdx);
},
150_000
);
@@ -248,7 +223,7 @@ describe("Group 1: MCP Protocol — channel capability", () => {
// Validates that CLAUDISH_MCP_TOOLS env var correctly limits which tools are
// exposed by the MCP server.
-describe("Group 1b: MCP Protocol — channel-only tools", () => {
+describe("Group 1b: MCP Protocol — session-only tools", () => {
let client: Client;
let transport: StdioClientTransport;
@@ -258,12 +233,12 @@ describe("Group 1b: MCP Protocol — channel-only tools", () => {
args: ["run", SERVER_ENTRY, "--mcp"],
env: {
...process.env,
- CLAUDISH_MCP_TOOLS: "channel",
+ CLAUDISH_MCP_TOOLS: "session",
CLAUDISH_SESSIONS_DIR: SESSIONS_DIR,
},
stderr: "pipe",
});
- client = new Client({ name: "test-client-channel", version: "1.0.0" }, { capabilities: {} });
+ client = new Client({ name: "test-client-session", version: "1.0.0" }, { capabilities: {} });
await client.connect(transport);
}, 15000);
@@ -273,7 +248,7 @@ describe("Group 1b: MCP Protocol — channel-only tools", () => {
} catch {}
});
- test("lists only the 7 channel tools when CLAUDISH_MCP_TOOLS=channel", async () => {
+ test("lists only the 7 session tools when CLAUDISH_MCP_TOOLS=session", async () => {
const result = await client.listTools();
const names = result.tools.map((t) => t.name).sort();
expect(names).toEqual([
@@ -313,13 +288,70 @@ describe("Group 1b: MCP Protocol — low-level-only tools", () => {
} catch {}
});
- test("lists only the 4 low-level tools when CLAUDISH_MCP_TOOLS=low-level", async () => {
+ test("lists only the 3 low-level tools when CLAUDISH_MCP_TOOLS=low-level", async () => {
const result = await client.listTools();
const names = result.tools.map((t) => t.name).sort();
- expect(names).toEqual(["compare_models", "list_models", "run_prompt", "search_models"]);
+ expect(names).toEqual(["list_models", "run_prompt", "search_models"]);
});
});
+for (const [toolMode, expected] of [
+ [
+ "channel",
+ [
+ "cancel_session",
+ "capture_session",
+ "compare_models",
+ "create_session",
+ "get_diagnostics",
+ "get_output",
+ "list_models",
+ "list_sessions",
+ "preflight",
+ "report_error",
+ "run_prompt",
+ "search_models",
+ "send_input",
+ "team",
+ ],
+ ],
+ ["debug", ["compare_models"]],
+] as const) {
+ describe(`Group 1b: MCP Protocol — CLAUDISH_MCP_TOOLS=${toolMode}`, () => {
+ let client: Client;
+ let transport: StdioClientTransport;
+
+ beforeAll(async () => {
+ transport = new StdioClientTransport({
+ command: "bun",
+ args: ["run", SERVER_ENTRY, "--mcp"],
+ env: {
+ ...process.env,
+ CLAUDISH_MCP_TOOLS: toolMode,
+ CLAUDISH_SESSIONS_DIR: SESSIONS_DIR,
+ },
+ stderr: "pipe",
+ });
+ client = new Client(
+ { name: `test-client-${toolMode}`, version: "1.0.0" },
+ { capabilities: {} }
+ );
+ await client.connect(transport);
+ }, 15000);
+
+ afterAll(async () => {
+ try {
+ await transport.close();
+ } catch {}
+ });
+
+ test(`lists the exact tools for CLAUDISH_MCP_TOOLS=${toolMode}`, async () => {
+ const result = await client.listTools();
+ expect(result.tools.map((tool) => tool.name).sort()).toEqual([...expected]);
+ });
+ });
+}
+
// ─── Group 2: Real Claude Code Integration ───────────────────────────────────
// Spawns `claude -p` with our MCP server registered via --mcp-config.
// Validates that Claude Code sees our tools and can call them.
@@ -529,7 +561,7 @@ describe("Group 2: Real Claude Code — MCP tool discovery", () => {
);
test.skipIf(!claudeUsable)(
- "claude discovers channel tools (create_session, list_sessions)",
+ "claude discovers session tools (create_session, list_sessions)",
async () => {
const { stdout, exitCode } = await runClaudeWithMcp(
"Call the list_sessions tool from the claudish MCP server with include_completed=true. Output the raw JSON result.",
diff --git a/packages/cli/src/channel/event-task-status.test.ts b/packages/cli/src/channel/event-task-status.test.ts
deleted file mode 100644
index 2608555d..00000000
--- a/packages/cli/src/channel/event-task-status.test.ts
+++ /dev/null
@@ -1,46 +0,0 @@
-/**
- * Every channel event projects onto SEP-1686's `TaskStatus` explicitly. A missing
- * key does not throw: `mapEventToTaskStatus` falls through to "working", which is how
- * `timeout` once reported a dead session as alive and how `awaiting_permission`
- * reported a session waiting on its caller as busy. This walks the runtime list of
- * event types, so a new type needs a row here AND a key in the map.
- */
-
-import { describe, expect, test } from "bun:test";
-import { mapEventToTaskStatus } from "../mcp-server.js";
-import { CHANNEL_EVENT_TYPES, type ChannelEventType } from "./types.js";
-
-type TaskStatus = ReturnType<typeof mapEventToTaskStatus>;
-
-const EXPECTED = {
- starting: "working",
- running: "working",
- tool_executing: "working",
- waiting_for_input: "input_required",
- awaiting_permission: "input_required",
- completed: "completed",
- failed: "failed",
- cancelled: "cancelled",
- timeout: "failed",
-} as const satisfies Record<ChannelEventType, TaskStatus>;
-
-describe("EVENT_TO_TASK_STATUS", () => {
- for (const event of CHANNEL_EVENT_TYPES) {
- test(`${event} → ${EXPECTED[event]}`, () => {
- expect(mapEventToTaskStatus(event)).toBe(EXPECTED[event]);
- });
- }
-
- test("awaiting_permission asks the caller for input; it is not 'working'", () => {
- expect(mapEventToTaskStatus("awaiting_permission")).toBe("input_required");
- });
-
- test("finishing is no longer a channel event (RB1): it falls through like any unknown word", () => {
- expect((CHANNEL_EVENT_TYPES as readonly string[]).includes("finishing")).toBe(false);
- });
-
- test("the list and the table name the same events", () => {
- const listed: string[] = [...CHANNEL_EVENT_TYPES].sort();
- expect(listed).toEqual(Object.keys(EXPECTED).sort());
- });
-});
diff --git a/packages/cli/src/channel/session-manager.test.ts b/packages/cli/src/channel/session-manager.test.ts
index 8e431e60..d5a58f40 100644
--- a/packages/cli/src/channel/session-manager.test.ts
+++ b/packages/cli/src/channel/session-manager.test.ts
@@ -26,7 +26,6 @@ import { tmpdir } from "node:os";
import { dirname, join } from "node:path";
import { fileURLToPath } from "node:url";
-import { mapEventToTaskStatus } from "../mcp-server.js";
import { ContractErrorException, type SlotState, checkChildFlags } from "../pane/index.js";
import {
MAGMUX,
@@ -38,6 +37,7 @@ import {
} from "../pane/test-helpers/hermetic-env.js";
import { transcriptRecords } from "../pane/test-helpers/transcript-fixtures.js";
import { projectsDir, transcriptPathFor } from "../session/session-discovery.js";
+import { readWaitLines } from "../test-helpers/contract-records.js";
import {
SessionManager,
channelEventFor,
@@ -45,11 +45,11 @@ import {
sessionRowOf,
toMetaRecord,
} from "./session-manager.js";
-import type { ChannelEvent, SessionInfo, SessionManagerOptions } from "./types.js";
+import type { SessionInfo, SessionManagerOptions } from "./types.js";
const __dirname = dirname(fileURLToPath(import.meta.url));
const SIGNAL_CHILD_TS = join(__dirname, "test-helpers", "stats-buffer-signal-child.ts");
-const TERMINAL_EVENTS = ["completed", "failed", "cancelled", "timeout"];
+const TERMINAL_STATES = ["COMPLETED", "FAILED", "CANCELLED", "TIMEOUT", "EMPTY"];
const T_PANE = 30_000;
function waitUntil(predicate: () => boolean, timeoutMs = 10_000, intervalMs = 25): Promise<void> {
@@ -111,20 +111,6 @@ function sampleInfo(over: Partial<SessionInfo> = {}): SessionInfo {
// ─── pure ────────────────────────────────────────────────────────────────────
describe("exported channel seams (pure)", () => {
- test("timeout projects to SEP-1686 failed instead of falling through to working", () => {
- expect(mapEventToTaskStatus("timeout")).toBe("failed");
- expect(mapEventToTaskStatus("timeout")).not.toBe("working");
- expect(mapEventToTaskStatus("genuinely_unknown_event")).toBe("working");
- for (const [event, status] of [
- ["completed", "completed"],
- ["failed", "failed"],
- ["cancelled", "cancelled"],
- ["awaiting_permission", "input_required"],
- ] as const) {
- expect(mapEventToTaskStatus(event)).toBe(status);
- }
- });
-
test("channelEventFor maps every SlotState (§3.4)", () => {
const cases: Array<[SlotState, string | null, string, string | null]> = [
["STARTING", null, "starting", null],
@@ -210,6 +196,7 @@ describe("exported channel seams (pure)", () => {
"provider",
"state",
"reason",
+ "reason_detail",
"tokens_in",
"tokens_out",
"cost_usd",
@@ -229,12 +216,16 @@ describe("exported channel seams (pure)", () => {
expect(row.idle_seconds).toBeNull();
expect(row.activity).toBeNull();
expect(row.reason).toBe("shape_mismatch");
+ expect(row.reason_detail).toBe("no match");
const live = sessionRowOf(
sampleInfo({ state: "RUNNING", reason: null, idleSeconds: 5, activity: "Bash" })
);
expect(live.idle_seconds).toBe(5);
expect(live.activity).toBe("Bash");
- expect(sessionRowOf(sampleInfo({ state: "COMPLETED", reason: null })).reason).toBeNull();
+ expect(live.reason_detail).toBeNull();
+ const completed = sessionRowOf(sampleInfo({ state: "COMPLETED", reason: null }));
+ expect(completed.reason).toBeNull();
+ expect(completed.reason_detail).toBeNull();
});
test("G4: transport-owned, print-only and positional flags are refused before anything starts", async () => {
@@ -544,6 +535,17 @@ describe.skipIf(!MAGMUX)(
JSON.parse(readFileSync(join(sessionsDir, id, "meta.json"), "utf-8"))
);
+ const stateTargets = (id: string): SlotState[] => {
+ const path = join(sessionsDir, id, "events.jsonl");
+ if (!existsSync(path)) return [];
+ return readFileSync(path, "utf-8")
+ .split("\n")
+ .filter((line) => line.trim() !== "")
+ .map((line) => JSON.parse(line) as { type: string; to: SlotState })
+ .filter((line) => line.type === "state")
+ .map((line) => line.to);
+ };
+
test(
"createSession returns unique ids; a promptless session is STARTING, then AWAITING_INPUT once booted",
async () => {
@@ -725,24 +727,20 @@ describe.skipIf(!MAGMUX)(
);
test(
- "a credential on the child's final screen reaches no record: meta.json, output.log, frame, diagnostics",
+ "a credential on the child's final screen reaches no record: meta.json, output.log, diagnostics",
async () => {
const secret = "redaction-probe-not-a-real-credential"; // what the fake's exit_secret prints
- const frames: string[] = [];
- const manager = makeManager({
- onStateChange: (_sid, e) => frames.push(JSON.stringify(e)),
- });
+ const manager = makeManager();
const id = await create(manager, { model: "fake-exit_secret", prompt: "go" });
await waitForState(manager, id, ["FAILED"]);
const meta = await waitForMeta(id);
expect(meta.terminalReason).toBe("child_exited");
expect(String(meta.detail)).toContain("MY_SERVICE_TOKEN=***REDACTED***");
- await waitUntil(() => frames.some((f) => f.includes('"failed"')));
+ await waitUntil(() => existsSync(join(sessionsDir, id, "output.log")));
const outputLog = readFileSync(join(sessionsDir, id, "output.log"), "utf-8");
for (const text of [
JSON.stringify(meta),
outputLog,
- frames.join("\n"),
JSON.stringify(manager.getDiagnostics(id)),
JSON.stringify(manager.getSession(id)),
])
@@ -787,43 +785,39 @@ describe.skipIf(!MAGMUX)(
);
test(
- "10.4.0 edit: a one-shot session's frames are exactly running → completed",
+ "10.4.0 edit: a one-shot session's events.jsonl state transitions are exactly RUNNING → COMPLETED",
async () => {
- const events: Array<{ sessionId: string; event: ChannelEvent }> = [];
- const manager = makeManager({
- onStateChange: (sessionId, event) => events.push({ sessionId, event }),
- });
+ const manager = makeManager();
const id = await create(manager, { prompt: "trigger events" });
await waitForState(manager, id, ["COMPLETED"]);
- expect(events.map(({ event }) => event.type)).toEqual(["running", "completed"]);
- for (const observed of events) {
- expect(observed.sessionId).toBe(id);
- expect(observed.event.model).toBe("fake-answer");
- }
+ const meta = await waitForMeta(id);
+ expect(stateTargets(id)).toEqual(["RUNNING", "COMPLETED"]);
+ expect(meta.sessionId).toBe(id);
+ expect(meta.model).toBe("fake-answer");
},
T_PANE
);
test(
- "10.4.0 edit: a promptless session's first frame is waiting_for_input, after boot",
+ "10.4.0 edit: a promptless session's first events.jsonl state transition is AWAITING_INPUT, after boot",
async () => {
- const events: string[] = [];
- const manager = makeManager({ onStateChange: (_sid, e) => events.push(e.type) });
+ const manager = makeManager();
const id = await create(manager);
- expect(events).not.toContain("waiting_for_input");
+ expect(stateTargets(id)).not.toContain("AWAITING_INPUT");
await waitForState(manager, id, ["AWAITING_INPUT"]);
- await waitUntil(() => events.length > 0);
- expect(events[0]).toBe("waiting_for_input");
- expect(events).not.toContain("starting");
+ await waitUntil(() => stateTargets(id).length > 0);
+ const targets = stateTargets(id);
+ expect(targets[0]).toBe("AWAITING_INPUT");
+ expect(targets).not.toContain("STARTING");
+ expect(readWaitLines(join(sessionsDir, id))?.map((line) => line.wait)).toEqual(["open"]);
},
T_PANE
);
test(
- "G1/G2: a timeout stays TIMEOUT in memory, meta and on the wire, with a send queued while RUNNING",
+ "G1/G2: a timeout stays TIMEOUT in memory, meta and events.jsonl, with a send queued while RUNNING",
async () => {
- const events: ChannelEvent[] = [];
- const manager = makeManager({ onStateChange: (_sid, event) => events.push(event) });
+ const manager = makeManager();
const id = await create(manager, {
model: "contract-fake-model",
prompt: "work forever @@HANG@@",
@@ -838,9 +832,7 @@ describe.skipIf(!MAGMUX)(
await waitForState(manager, id, ["TIMEOUT"], 15_000);
const meta = await waitForMeta(id);
const info = manager.getSession(id);
- const terminalWireEvents = events
- .map((e) => e.type)
- .filter((x) => TERMINAL_EVENTS.includes(x));
+ const terminalStateTargets = stateTargets(id).filter((to) => TERMINAL_STATES.includes(to));
expect(info.state).toBe("TIMEOUT");
expect(info.reason).toBe("timeout");
@@ -850,7 +842,7 @@ describe.skipIf(!MAGMUX)(
// RB4: claudish ended the pane, so there is no child exit code.
expect(info.exitCode).toBeNull();
expect(meta.exitCode).toBeNull();
- expect(terminalWireEvents).toEqual(["timeout"]);
+ expect(terminalStateTargets).toEqual(["TIMEOUT"]);
},
T_PANE
);
diff --git a/packages/cli/src/channel/test-helpers/channel-diagnostic.ts b/packages/cli/src/channel/test-helpers/channel-diagnostic.ts
deleted file mode 100644
index 6a3ea50b..00000000
--- a/packages/cli/src/channel/test-helpers/channel-diagnostic.ts
+++ /dev/null
@@ -1,189 +0,0 @@
-#!/usr/bin/env bun
-/**
- * Channel notification diagnostic.
- *
- * Spawns the claudish MCP server with CLAUDISH_CHANNEL_TRACE=1 and drives a
- * full create_session → completion lifecycle while capturing:
- * - All stderr (our channel-trace markers + any errors)
- * - All stdout (raw JSON-RPC frames the server emits)
- *
- * Both streams are written to logs/channel-diagnostic-<timestamp>.log AND
- * mirrored to the console for live observation.
- *
- * Usage:
- * bun run packages/cli/src/channel/test-helpers/channel-diagnostic.ts [model] [prompt]
- *
- * Defaults:
- * model: z-ai/glm-4.5-air:free (free OpenRouter model — no cost)
- * prompt: "Reply with exactly: hello channel diagnostic"
- *
- * Exit codes:
- * 0 — session completed AND we observed wire-out frames + completed event
- * 1 — diagnostic failure (no frames, no completion, or transport error)
- */
-import { spawn } from "node:child_process";
-import { createWriteStream, mkdirSync } from "node:fs";
-import { join, resolve } from "node:path";
-
-const MODEL = process.argv[2] ?? "z-ai/glm-4.5-air:free";
-const PROMPT = process.argv[3] ?? "Reply with exactly: hello channel diagnostic";
-const TIMEOUT_MS = 90_000; // hard cap — fail-loud rather than hang
-
-const LOG_DIR = resolve(import.meta.dir, "../../../../../logs");
-mkdirSync(LOG_DIR, { recursive: true });
-const stamp = new Date().toISOString().replace(/[:.]/g, "-");
-const LOG_FILE = join(LOG_DIR, `channel-diagnostic-${stamp}.log`);
-const log = createWriteStream(LOG_FILE);
-
-function writeBoth(line: string) {
- process.stderr.write(line);
- log.write(line);
-}
-
-writeBoth("[diag] starting channel diagnostic\n");
-writeBoth(`[diag] model=${MODEL}\n`);
-writeBoth(`[diag] prompt=${PROMPT}\n`);
-writeBoth(`[diag] log file: ${LOG_FILE}\n`);
-
-const SERVER_ENTRY = resolve(import.meta.dir, "../../../src/index.ts");
-const proc = spawn("bun", ["run", SERVER_ENTRY, "--mcp"], {
- stdio: ["pipe", "pipe", "pipe"],
- env: {
- ...process.env,
- CLAUDISH_CHANNEL_TRACE: "1",
- // Force channel tools enabled regardless of default
- CLAUDISH_MCP_TOOLS: "all",
- // create_session children must exercise this tree, not an installed claudish.
- CLAUDISH_BIN: SERVER_ENTRY,
- },
-});
-
-let observedTraceLines = 0;
-let observedWireFrames = 0;
-let observedCompletion = false;
-let observedFailure = false;
-let stderrBuf = "";
-let stdoutBuf = "";
-
-proc.stderr.on("data", (chunk: Buffer) => {
- const text = chunk.toString("utf-8");
- stderrBuf += text;
- log.write(`STDERR: ${text}`);
- process.stderr.write(`\x1b[2m${text}\x1b[0m`); // dim color for stderr mirror
- if (text.includes("[channel-trace]")) {
- observedTraceLines += text.split("\n").filter((l) => l.includes("[channel-trace]")).length;
- }
- if (text.includes("WIRE-OUT")) {
- observedWireFrames += text.split("\n").filter((l) => l.includes("WIRE-OUT")).length;
- }
-});
-
-proc.stdout.on("data", (chunk: Buffer) => {
- const text = chunk.toString("utf-8");
- stdoutBuf += text;
- log.write(`STDOUT: ${text}`);
- // Line-by-line JSON-RPC parse for "completed" / "failed" notifications
- const lines = (stdoutBuf.match(/[^\n]+\n/g) ?? []) as string[];
- if (lines.length > 0) {
- stdoutBuf = stdoutBuf.slice(lines.join("").length);
- for (const line of lines) {
- try {
- const msg = JSON.parse(line);
- if (msg.method === "notifications/claude/channel") {
- const evt = msg.params?.meta?.event;
- writeBoth(`[diag] received notification event=${evt}\n`);
- if (evt === "completed") observedCompletion = true;
- if (evt === "failed") observedFailure = true;
- } else if (msg.id !== undefined && msg.result) {
- writeBoth(
- `[diag] received response id=${msg.id} keys=${Object.keys(msg.result).join(",")}\n`
- );
- } else if (msg.id !== undefined && msg.error) {
- writeBoth(
- `[diag] received ERROR id=${msg.id} code=${msg.error.code} msg=${msg.error.message}\n`
- );
- }
- } catch {
- // not JSON, skip
- }
- }
- }
-});
-
-function send(rpc: object) {
- const frame = `${JSON.stringify(rpc)}\n`;
- log.write(`SEND: ${frame}`);
- proc.stdin.write(frame);
-}
-
-// Step A: initialize
-send({
- jsonrpc: "2.0",
- id: 1,
- method: "initialize",
- params: {
- protocolVersion: "2024-11-05",
- clientInfo: { name: "channel-diagnostic", version: "1.0.0" },
- capabilities: {
- experimental: { "claude/channel": {} },
- },
- },
-});
-
-// Step B: notifications/initialized + tools/call create_session
-// Slight delay to let init complete
-setTimeout(() => {
- send({ jsonrpc: "2.0", method: "notifications/initialized" });
- setTimeout(() => {
- send({
- jsonrpc: "2.0",
- id: 2,
- method: "tools/call",
- params: {
- name: "create_session",
- arguments: {
- model: MODEL,
- prompt: PROMPT,
- timeout_seconds: 60,
- },
- },
- });
- }, 200);
-}, 500);
-
-// Hard timeout
-const killTimer = setTimeout(() => {
- writeBoth(`[diag] TIMEOUT after ${TIMEOUT_MS}ms — killing server\n`);
- proc.kill("SIGTERM");
- setTimeout(() => proc.kill("SIGKILL"), 2000);
-}, TIMEOUT_MS);
-
-proc.on("exit", (code) => {
- clearTimeout(killTimer);
- writeBoth(`[diag] server exited code=${code}\n`);
- writeBoth("\n=== DIAGNOSTIC SUMMARY ===\n");
- writeBoth(`trace lines observed: ${observedTraceLines}\n`);
- writeBoth(`wire frames observed: ${observedWireFrames}\n`);
- writeBoth(`completion event: ${observedCompletion}\n`);
- writeBoth(`failure event: ${observedFailure}\n`);
- writeBoth(`exit code: ${code}\n`);
- writeBoth(`log written to: ${LOG_FILE}\n`);
-
- // Diagnostic verdict
- if (observedTraceLines === 0) {
- writeBoth("\n❌ VERDICT: onStateChange callback never fired.\n");
- writeBoth(" Producer side broken — PaneSession or SessionManager not driving events.\n");
- } else if (observedWireFrames === 0) {
- writeBoth("\n❌ VERDICT: onStateChange fired but no JSON-RPC frame reached stdout.\n");
- writeBoth(" server.notification() is being called but transport is silently dropping.\n");
- } else if (!observedCompletion && !observedFailure) {
- writeBoth("\n⚠️ VERDICT: Frames flowed but no terminal event seen.\n");
- writeBoth(" Session may be hung or model produced no output.\n");
- } else {
- writeBoth("\n✅ VERDICT: Producer→bridge→wire pipeline confirmed working.\n");
- writeBoth(" If client sees no <channel> blocks, the issue is client-side handling.\n");
- }
-
- log.end();
- process.exit(observedTraceLines > 0 && observedWireFrames > 0 ? 0 : 1);
-});
diff --git a/packages/cli/src/channel/test-helpers/claudish-mock.ts b/packages/cli/src/channel/test-helpers/claudish-mock.ts
deleted file mode 100644
index ac62efe1..00000000
--- a/packages/cli/src/channel/test-helpers/claudish-mock.ts
+++ /dev/null
@@ -1,150 +0,0 @@
-#!/usr/bin/env bun
-import { randomUUID } from "node:crypto";
-/**
- * claudish-mock — minimal MCP server that mimics a Claudish channel session
- * for end-to-end Claude Code rendering validation.
- *
- * Purpose: prove (or disprove) that Claude Code surfaces
- * notifications/claude/channel as <channel source="claudish-mock"> blocks in
- * an interactive session. Avoids depending on a real model — pure scripted
- * timing means any failure must be in Claude Code's channel rendering path,
- * not in our session machinery.
- *
- * Tool: `start_mock_session`
- * Returns immediately with a session_id. Then over the next ~9 seconds,
- * pushes the documented sequence of channel notifications:
- * t=0.5s running (first model output)
- * t=2.0s tool_executing (Read)
- * t=3.5s tool_executing (Bash)
- * t=5.0s tool_executing (Edit)
- * t=6.5s tool_executing (Write)
- * t=8.0s completed
- *
- * Wire format matches the real claudish bridge byte-for-byte (capability,
- * method name, params shape, meta key naming) so this also serves as a
- * reference of what conformant emission looks like.
- */
-import { Server } from "@modelcontextprotocol/sdk/server/index.js";
-import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
-import { CallToolRequestSchema, ListToolsRequestSchema } from "@modelcontextprotocol/sdk/types.js";
-
-const SERVER_NAME = "claudish-mock";
-
-// Scripted sequence: each entry becomes a single notifications/claude/channel
-// frame, fired at the offset given (ms from session start).
-interface MockEvent {
- delayMs: number;
- type: string;
- content: string;
- extraMeta?: Record<string, string>;
-}
-
-const SCRIPT: MockEvent[] = [
- { delayMs: 500, type: "running", content: "Starting analysis of the codebase." },
- {
- delayMs: 2000,
- type: "tool_executing",
- content: "Read package.json",
- extraMeta: { tool: "Read" },
- },
- { delayMs: 3500, type: "tool_executing", content: "Running build", extraMeta: { tool: "Bash" } },
- {
- delayMs: 5000,
- type: "tool_executing",
- content: "Editing src/index.ts",
- extraMeta: { tool: "Edit" },
- },
- {
- delayMs: 6500,
- type: "tool_executing",
- content: "Writing CHANGELOG.md",
- extraMeta: { tool: "Write" },
- },
- { delayMs: 8000, type: "completed", content: "Mock session finished. All 6 events emitted." },
-];
-
-function trace(line: string): void {
- // Mirror to stderr for live observation. Claude Code captures MCP server
- // stderr internally so this only shows up in --debug logs.
- process.stderr.write(`[mock] ${line}\n`);
-}
-
-const server = new Server(
- { name: SERVER_NAME, version: "0.0.1" },
- {
- capabilities: {
- experimental: { "claude/channel": {} },
- tools: {},
- },
- instructions: `Mock channel server for testing. Call start_mock_session to begin a scripted sequence of channel events. Events arrive as <channel source="${SERVER_NAME}" event="..." session_id="..." ...> blocks. Quote each <channel> block VERBATIM as it arrives so we can verify they reach the agent.`,
- }
-);
-
-server.setRequestHandler(ListToolsRequestSchema, async () => ({
- tools: [
- {
- name: "start_mock_session",
- description:
- "Start a mock Claudish session that emits a scripted sequence of channel notifications " +
- "over ~9 seconds. Returns the session_id immediately; events arrive asynchronously.",
- inputSchema: {
- type: "object",
- properties: {},
- additionalProperties: false,
- },
- },
- ],
-}));
-
-server.setRequestHandler(CallToolRequestSchema, async (req) => {
- if (req.params.name !== "start_mock_session") {
- throw new Error(`unknown tool: ${req.params.name}`);
- }
-
- const sessionId = randomUUID().slice(0, 8);
- const startedAt = Date.now();
- trace(`session ${sessionId} started, scheduling ${SCRIPT.length} events`);
-
- for (const event of SCRIPT) {
- setTimeout(() => {
- const elapsed = Math.round((Date.now() - startedAt) / 1000);
- const params = {
- content: event.content,
- meta: {
- session_id: sessionId,
- event: event.type,
- model: "mock",
- elapsed_seconds: String(elapsed),
- ...(event.extraMeta ?? {}),
- },
- };
- trace(`emit sid=${sessionId} type=${event.type} t=${elapsed}s`);
- server.notification({
- method: "notifications/claude/channel",
- params,
- });
- }, event.delayMs);
- }
-
- return {
- content: [
- {
- type: "text",
- text: JSON.stringify(
- {
- session_id: sessionId,
- scheduled_events: SCRIPT.length,
- duration_seconds: SCRIPT[SCRIPT.length - 1].delayMs / 1000,
- note: "Notifications will arrive asynchronously as <channel> blocks.",
- },
- null,
- 2
- ),
- },
- ],
- };
-});
-
-const transport = new StdioServerTransport();
-await server.connect(transport);
-trace(`server connected, name=${SERVER_NAME}`);
diff --git a/packages/cli/src/channel/test-helpers/client-diagnostic.ts b/packages/cli/src/channel/test-helpers/client-diagnostic.ts
deleted file mode 100644
index 33f34180..00000000
--- a/packages/cli/src/channel/test-helpers/client-diagnostic.ts
+++ /dev/null
@@ -1,272 +0,0 @@
-#!/usr/bin/env bun
-/**
- * Client-side channel diagnostic.
- *
- * Spawns `claude -p` against our claudish MCP server (with CLAUDISH_CHANNEL_TRACE=1
- * enabled so we can see what the server emits). Asks Claude Code to create a
- * session and report on what it observes.
- *
- * Captures three streams in parallel:
- * 1. Server stderr — our [channel-trace] markers prove what frames we sent
- * 2. Client stdout — Claude Code's stream-json events: tool calls, tool
- * results, system messages. If channel notifications are surfaced, they
- * should appear somewhere here.
- * 3. Client stderr — Claude Code's own debug logs (--debug mcp captures
- * MCP-layer events including unknown notification handling).
- *
- * Comparing what the server sent vs what the client surfaced tells us
- * definitively whether Claude Code consumes notifications/claude/channel.
- */
-
-import { spawn } from "node:child_process";
-import { createWriteStream, mkdirSync, writeFileSync } from "node:fs";
-import { tmpdir } from "node:os";
-import { dirname, join, resolve } from "node:path";
-import { fileURLToPath } from "node:url";
-
-const __filename = fileURLToPath(import.meta.url);
-const __dirname = dirname(__filename);
-const SERVER_ENTRY = resolve(__dirname, "../../index.ts");
-
-const LOG_DIR = resolve(__dirname, "../../../../../logs");
-mkdirSync(LOG_DIR, { recursive: true });
-const stamp = new Date().toISOString().replace(/[:.]/g, "-");
-const LOG_FILE = join(LOG_DIR, `client-diagnostic-${stamp}.log`);
-const log = createWriteStream(LOG_FILE);
-
-function logBoth(s: string) {
- process.stderr.write(s);
- log.write(s);
-}
-
-logBoth("[client-diag] starting end-to-end client diagnostic\n");
-logBoth(`[client-diag] log file: ${LOG_FILE}\n`);
-
-// File where the MCP server will mirror its trace output. Claude Code
-// captures the server's stderr internally and never propagates it to us, so
-// without this file mirror we'd be blind to the server side.
-const SERVER_TRACE_FILE = join(LOG_DIR, `server-trace-${stamp}.log`);
-writeFileSync(SERVER_TRACE_FILE, "", "utf-8");
-
-// MCP config that wires our instrumented server into Claude Code
-const mcpConfig = {
- mcpServers: {
- claudish: {
- command: "bun",
- args: ["run", SERVER_ENTRY, "--mcp"],
- env: {
- CLAUDISH_MCP_TOOLS: "all",
- CLAUDISH_CHANNEL_TRACE: "1",
- CLAUDISH_CHANNEL_TRACE_FILE: SERVER_TRACE_FILE,
- OPENROUTER_API_KEY: process.env.OPENROUTER_API_KEY ?? "",
- // create_session children must exercise this tree, not an installed claudish.
- CLAUDISH_BIN: SERVER_ENTRY,
- },
- },
- },
-};
-
-const configPath = join(tmpdir(), `claudish-client-diag-${Date.now()}.json`);
-writeFileSync(configPath, JSON.stringify(mcpConfig), "utf-8");
-logBoth(`[client-diag] mcp config: ${configPath}\n`);
-
-// The prompt: ask Claude Code to create a session AND report on what it sees.
-// The prompt is crucial: it must elicit observable evidence of notifications.
-//
-// We use x-ai/grok-code-fast-1 because it actually returns output unlike the
-// :free models. We tell the agent EXPLICITLY not to cancel — earlier runs
-// showed it was happy to call cancel_session prematurely. We also tell it to
-// quote the channel notifications verbatim, which forces them to appear in
-// the output stream if the client does receive them.
-const PROMPT = `Use the create_session tool from the claudish MCP server with model "x-ai/grok-code-fast-1" and prompt "Reply with exactly the word: hello". DO NOT CANCEL THE SESSION. After create_session returns, the server will push notifications about the session lifecycle (events like running, tool_executing, completed). Quote VERBATIM every channel notification you observe — paste them as JSON or describe their event/content/meta fields exactly. If no notifications arrive within 60 seconds, report "NO NOTIFICATIONS RECEIVED". Then call list_sessions with include_completed=true and call get_output for the session. Output your findings in this exact format:\n\nNOTIFICATIONS_OBSERVED:\n<list each notification verbatim>\n\nFINAL_OUTPUT:\n<get_output result>`;
-
-logBoth(`[client-diag] prompt: ${PROMPT.slice(0, 100)}...\n`);
-
-const claudeArgs = [
- "-p",
- "--mcp-config",
- configPath,
- "--strict-mcp-config",
- "--bare",
- "--dangerously-skip-permissions",
- // Channels are gated: server must be named in --channels OR bypassed via
- // the development flag. Per official docs:
- // https://code.claude.com/docs/en/channels-reference#test-during-the-research-preview
- // Using the development flag because Claudish isn't on Anthropic's allowlist.
- "--dangerously-load-development-channels",
- "server:claudish",
- "--output-format",
- "stream-json",
- "--include-partial-messages",
- "--verbose",
- "--debug",
- "mcp",
- PROMPT,
-];
-
-logBoth(`[client-diag] claude args: ${claudeArgs.slice(0, 8).join(" ")} ...\n`);
-
-const claude = spawn("claude", claudeArgs, {
- stdio: ["ignore", "pipe", "pipe"],
- env: process.env,
-});
-
-interface Counters {
- serverChannelTraceLines: number;
- serverWireFrames: number;
- clientStreamEvents: number;
- clientToolCalls: number;
- clientToolResults: number;
- clientChannelMentions: number;
- clientSystemReminders: number;
- clientUnhandledMcpLogs: number;
-}
-
-const counts: Counters = {
- serverChannelTraceLines: 0,
- serverWireFrames: 0,
- clientStreamEvents: 0,
- clientToolCalls: 0,
- clientToolResults: 0,
- clientChannelMentions: 0,
- clientSystemReminders: 0,
- clientUnhandledMcpLogs: 0,
-};
-
-let stdoutBuf = "";
-
-claude.stdout.on("data", (chunk: Buffer) => {
- const text = chunk.toString("utf-8");
- log.write(`STDOUT: ${text}`);
- stdoutBuf += text;
-
- // Parse line-delimited JSON
- let nl: number;
- // biome-ignore lint/suspicious/noAssignInExpressions: canonical line-buffer drain idiom
- while ((nl = stdoutBuf.indexOf("\n")) !== -1) {
- const line = stdoutBuf.slice(0, nl);
- stdoutBuf = stdoutBuf.slice(nl + 1);
- if (!line.trim()) continue;
- counts.clientStreamEvents++;
- try {
- const event = JSON.parse(line);
- // Walk the event for evidence of channel notification reception
- const json = JSON.stringify(event);
- if (json.includes("notifications/claude/channel")) {
- counts.clientChannelMentions++;
- logBoth(`[client-diag] FOUND channel reference in stream: ${line.slice(0, 200)}\n`);
- }
- if (json.includes("<channel")) {
- counts.clientChannelMentions++;
- logBoth(`[client-diag] FOUND <channel> tag in stream: ${line.slice(0, 200)}\n`);
- }
- if (event.type === "system") {
- counts.clientSystemReminders++;
- }
- if (event.type === "assistant" || event.type === "user") {
- const blocks = event.message?.content ?? [];
- for (const b of Array.isArray(blocks) ? blocks : []) {
- if (b.type === "tool_use") {
- counts.clientToolCalls++;
- logBoth(
- `[client-diag] tool_use: ${b.name} input=${JSON.stringify(b.input).slice(0, 150)}\n`
- );
- }
- if (b.type === "tool_result") {
- counts.clientToolResults++;
- }
- }
- }
- } catch {
- // not JSON; ignore
- }
- }
-});
-
-claude.stderr.on("data", (chunk: Buffer) => {
- const text = chunk.toString("utf-8");
- log.write(`STDERR: ${text}`);
-
- // Server's [channel-trace] markers come through as nested stderr
- if (text.includes("[channel-trace]")) {
- for (const line of text.split("\n")) {
- if (line.includes("[channel-trace]")) {
- if (line.includes("WIRE-OUT")) counts.serverWireFrames++;
- else counts.serverChannelTraceLines++;
- }
- }
- }
- // Claude Code's own debug logging — look for evidence of MCP notification handling
- if (/unhandled|unknown.*notification|drop/i.test(text)) {
- counts.clientUnhandledMcpLogs++;
- logBoth(`[client-diag] CLIENT MCP LOG: ${text.trim().slice(0, 300)}\n`);
- }
-});
-
-const TIMEOUT_MS = 180_000;
-const killTimer = setTimeout(() => {
- logBoth("[client-diag] TIMEOUT — killing claude\n");
- claude.kill("SIGTERM");
- setTimeout(() => claude.kill("SIGKILL"), 3000);
-}, TIMEOUT_MS);
-
-claude.on("exit", (code) => {
- clearTimeout(killTimer);
- logBoth(`\n[client-diag] claude exited code=${code}\n`);
-
- // Read the server trace file — this is the ground truth for what the
- // server emitted, since Claude Code captures the server's stderr and we
- // can't see it via the host stderr stream.
- try {
- const fs = require("node:fs") as typeof import("node:fs");
- const traceContent = fs.readFileSync(SERVER_TRACE_FILE, "utf-8");
- const lines = traceContent.split("\n").filter((l) => l.includes("[channel-trace]"));
- counts.serverChannelTraceLines = lines.length;
- counts.serverWireFrames = lines.filter((l) => l.includes("WIRE-OUT")).length;
- logBoth(`\n[client-diag] server trace file: ${SERVER_TRACE_FILE}\n`);
- if (lines.length > 0) {
- logBoth("[client-diag] first 5 trace lines:\n");
- for (const l of lines.slice(0, 5)) logBoth(` ${l}\n`);
- }
- } catch (err) {
- logBoth(`[client-diag] failed to read server trace file: ${(err as Error).message}\n`);
- }
-
- logBoth("\n=== END-TO-END CLIENT DIAGNOSTIC SUMMARY ===\n");
- logBoth("SERVER SIDE (proves we sent frames):\n");
- logBoth(` channel-trace markers: ${counts.serverChannelTraceLines}\n`);
- logBoth(` wire-out frames: ${counts.serverWireFrames}\n`);
- logBoth("\nCLIENT SIDE (proves Claude Code processed them):\n");
- logBoth(` total stream events: ${counts.clientStreamEvents}\n`);
- logBoth(` MCP tool calls (by Claude):${counts.clientToolCalls}\n`);
- logBoth(` MCP tool results: ${counts.clientToolResults}\n`);
- logBoth(` channel mentions in stream:${counts.clientChannelMentions}\n`);
- logBoth(` system messages: ${counts.clientSystemReminders}\n`);
- logBoth(` unhandled-mcp log lines: ${counts.clientUnhandledMcpLogs}\n`);
-
- logBoth("\n=== VERDICT ===\n");
- if (counts.serverWireFrames === 0) {
- logBoth(`❌ Server didn't send frames. Test setup issue, not a client question.\n`);
- } else if (counts.clientChannelMentions > 0) {
- logBoth(
- `✅ Server sent ${counts.serverWireFrames} frames. Client surfaced them in the stream.\n`
- );
- logBoth(" Channel notifications ARE consumed by Claude Code.\n");
- } else if (counts.clientUnhandledMcpLogs > 0) {
- logBoth(
- `❌ Server sent ${counts.serverWireFrames} frames. Client logged "unhandled" warnings.\n`
- );
- logBoth(" Channel notifications reach Claude Code but are dropped (no handler).\n");
- } else {
- logBoth(
- `⚠️ Server sent ${counts.serverWireFrames} frames. Client showed NO evidence of receiving them.\n`
- );
- logBoth(" No channel mentions, no <channel> tags, no debug logs about them.\n");
- logBoth(" Either: Claude Code silently discards unknown methods, OR it consumes them\n");
- logBoth(` but doesn't pass them through to the agent's visible context.\n`);
- logBoth(` Inspect the log file directly to look for subtler signals: ${LOG_FILE}\n`);
- }
-
- log.end();
- process.exit(code ?? 0);
-});
diff --git a/packages/cli/src/mcp-blackbox/channel-sessions.blackbox.test.ts b/packages/cli/src/mcp-blackbox/channel-sessions.blackbox.test.ts
index c98ea7bc..5997f800 100644
--- a/packages/cli/src/mcp-blackbox/channel-sessions.blackbox.test.ts
+++ b/packages/cli/src/mcp-blackbox/channel-sessions.blackbox.test.ts
@@ -70,6 +70,7 @@ const SLOT_ROW_KEYS = [
"pane",
"provider",
"reason",
+ "reason_detail",
"slot",
"state",
"tokens_in",
@@ -156,9 +157,13 @@ function expectSessionRowTyped(row: Json): void {
} else {
expect(row.completed_at).toBeNull();
}
- if (["FAILED", "EMPTY", "CANCELLED", "TIMEOUT"].includes(row.state as string))
+ if (["FAILED", "EMPTY", "CANCELLED", "TIMEOUT"].includes(row.state as string)) {
expect(row.reason).not.toBeNull();
- else expect(row.reason).toBeNull();
+ expect(row.reason_detail === null || typeof row.reason_detail === "string").toBe(true);
+ } else {
+ expect(row.reason).toBeNull();
+ expect(row.reason_detail).toBeNull();
+ }
}
async function sessionRow(id: string): Promise<Json | undefined> {
@@ -358,9 +363,9 @@ describe.skipIf(!MAGMUX_AVAILABLE)("failure and timeout states (FR7)", () => {
);
});
-describe.skipIf(!MAGMUX_AVAILABLE)("diagnostics, channel frames, error forms", () => {
+describe.skipIf(!MAGMUX_AVAILABLE)("diagnostics, no channel notifications, error forms", () => {
test(
- "get_diagnostics names the state and the capture/turn source; channel frames fire for the session",
+ "get_diagnostics names the state and the capture/turn source; no channel notifications are sent",
async () => {
const id = await create({ prompt: "Reply with exactly PEAR" });
await waitState(id, TERMINAL_STATES);
@@ -374,18 +379,11 @@ describe.skipIf(!MAGMUX_AVAILABLE)("diagnostics, channel frames, error forms", (
for (const k of ["captureSource", "turnSource", "pane", "anomalies", "transcriptPath"])
expect(findField(diag.json, k)).not.toBeUndefined();
- // FR10/E: notifications/claude/channel frames fire on state transitions
- const frames = await waitFor(
- () => {
- const f = server.notifications.filter(
- (n) =>
- n.method === "notifications/claude/channel" && JSON.stringify(n.params).includes(id)
- );
- return f.length > 0 ? f : undefined;
- },
- { what: "a channel frame for the session", timeoutMs: 5_000 }
- );
- expect(frames.length).toBeGreaterThan(0);
+ // No notifications/claude/channel message is sent, including during server teardown.
+ await server.close();
+ expect(
+ server.notifications.filter((n) => n.method === "notifications/claude/channel")
+ ).toEqual([]);
},
T_TEST
);
diff --git a/packages/cli/src/mcp-e2e/jsonrpc-client.ts b/packages/cli/src/mcp-e2e/jsonrpc-client.ts
index 858d92b8..8867afad 100644
--- a/packages/cli/src/mcp-e2e/jsonrpc-client.ts
+++ b/packages/cli/src/mcp-e2e/jsonrpc-client.ts
@@ -211,7 +211,7 @@ export async function driveServer(opts: DriveOptions): Promise<DriveResult> {
params: {
protocolVersion: "2024-11-05",
clientInfo: { name: "mcp-e2e", version: "1.0.0" },
- capabilities: { experimental: { "claude/channel": {} } },
+ capabilities: {},
},
});
await sleep(600);