Claude Code. Any Model. The most powerful AI coding agent now speaks every language.
fix(hooks): run hook tests on v11.1.0's session records and nesting rule after rebase onto v11.1.0
Jack Rudenko5fdca91b5cd6
diff --git a/packages/cli/src/cwd-env-control.test.ts b/packages/cli/src/cwd-env-control.test.tsindex 54428d25..81c206f6 100644--- a/packages/cli/src/cwd-env-control.test.ts+++ b/packages/cli/src/cwd-env-control.test.ts@@ -141,8 +141,9 @@ describe("a checkout's env files cannot choose the config hooks load from", () =});describe("a checkout's env files cannot mark the process as a pane child", () => {- // `-p` is refused with exit 64 only in a pane child; anywhere else this run fails- // fast with exit 1 on the missing OpenRouter key.+ // `-p` is refused with exit 64 in a pane child, and as a nested launch under the+ // flag alone; anywhere else this run fails fast with exit 1 on the missing+ // OpenRouter key.const PRINT = ["-p", "hi", "--model", "openrouter@x/y"];for (const [launchName, launch] of LAUNCHES) {@@ -150,13 +151,18 @@ describe("a checkout's env files cannot mark the process as a pane child", () =>const { repo } = hostileCheckout({ ".env": "CLAUDISH_PANE_CHILD=1\n" });const r = run(launch(PRINT), repo);expect(r.stderr).not.toContain("pane child refused");+ expect(r.stderr).not.toContain("nested session refused");expect(r.code).toBe(1);});}it("control: the marker in the real environment refuses -p with exit 64", () => {const { repo } = hostileCheckout({});- const r = run(LAUNCHES[0][1](PRINT), repo, { CLAUDISH_PANE_CHILD: "1" });+ // A pane child is the flag AND a pane cwd; the flag alone is a nested launch.+ const r = run(LAUNCHES[0][1](PRINT), repo, {+ CLAUDISH_PANE_CHILD: "1",+ CLAUDISH_PANE_CWD: repo,+ });expect(r.stderr).toContain("pane child refused");expect(r.code).toBe(64);});diff --git a/packages/cli/src/hooks/injection/in-process-sink.test.ts b/packages/cli/src/hooks/injection/in-process-sink.test.tsindex 5c903d50..561589c2 100644--- a/packages/cli/src/hooks/injection/in-process-sink.test.ts+++ b/packages/cli/src/hooks/injection/in-process-sink.test.ts@@ -135,7 +135,9 @@ describe("sinkFromEnv with a process sink", () => {const inProcess = new InProcessSink();setProcessSink(inProcess);const env = { [HOOK_INBOX_ENV]: "/tmp/never-written-inbox.jsonl" };- expect(sinkFromEnv({ ...env, CLAUDISH_PANE_CHILD: "1" })).toBeInstanceOf(InboxFileSink);+ expect(+ sinkFromEnv({ ...env, CLAUDISH_PANE_CHILD: "1", CLAUDISH_PANE_CWD: "/w" })+ ).toBeInstanceOf(InboxFileSink);// outside a pane child the variable is not an owner's: the process sink staysexpect(sinkFromEnv(env)).toBe(inProcess);});diff --git a/packages/cli/src/hooks/injection/sinks.test.ts b/packages/cli/src/hooks/injection/sinks.test.tsindex 8284a7b2..d72f0063 100644--- a/packages/cli/src/hooks/injection/sinks.test.ts+++ b/packages/cli/src/hooks/injection/sinks.test.ts@@ -99,7 +99,7 @@ describe("UnavailableSink and sinkFromEnv", () => {it("uses the inbox the owner named, else none", () => {const path = inbox();- const child = { CLAUDISH_PANE_CHILD: "1", [HOOK_INBOX_ENV]: path };+ const child = { CLAUDISH_PANE_CHILD: "1", CLAUDISH_PANE_CWD: "/w", [HOOK_INBOX_ENV]: path };const sink = sinkFromEnv(child);expect(sink).toBeInstanceOf(InboxFileSink);expect((sink as InboxFileSink).path).toBe(path);diff --git a/packages/cli/src/hooks/session/cross-process.integration.test.ts b/packages/cli/src/hooks/session/cross-process.integration.test.tsindex c2f375b2..1a065122 100644--- a/packages/cli/src/hooks/session/cross-process.integration.test.ts+++ b/packages/cli/src/hooks/session/cross-process.integration.test.ts@@ -1,6 +1,6 @@/*** Cross-process session hooks (hook-system architecture §2.3, §11.3 "Cross-process"):- * the owner (a real channel `SessionManager` in this process) + the REAL child claudish+ * the owner (a real MCP `SessionManager` in this process) + the REAL child claudish* (`src/index.ts` as `CLAUDISH_BIN`) in a real magmux pane + the fake Claude Code in* proxied mode (`FAKE_CLAUDE_PROXY=1`), whose every turn is a streaming `/v1/messages`* through the child's proxy to a stub upstream (`stub@fake-model` via `customEndpoints`@@ -13,8 +13,8 @@import { afterAll, describe, expect, spyOn, test } from "bun:test";import { existsSync, readFileSync, writeFileSync } from "node:fs";import { join } from "node:path";-import { SessionManager } from "../../channel/session-manager.js";import * as logger from "../../logger.js";+import { SessionManager } from "../../mcp-session/session-manager.js";import {MAGMUX,NO_MAGMUX_MESSAGE,diff --git a/packages/cli/src/pane/pane-hooks.integration.test.ts b/packages/cli/src/pane/pane-hooks.integration.test.tsindex fde03f4f..4aa015d8 100644--- a/packages/cli/src/pane/pane-hooks.integration.test.ts+++ b/packages/cli/src/pane/pane-hooks.integration.test.ts@@ -6,8 +6,8 @@* The binding is a test double whose `settle()` returns a promise the test resolves,* except where a row says "real binding" (H-21, H-21b, H-24, the cap and the* sessionStart rows), which run `createSessionHookBinding` over a real engine. The- * owner is the real channel `SessionManager` (observed through get_output,- * get_diagnostics, its frames and events.jsonl) or the real team orchestrator+ * owner is the real MCP `SessionManager` (observed through get_output,+ * get_diagnostics and events.jsonl, whose `state` records give the row events) or the real team orchestrator* (response-<slot>.md and the slot's status row). Every test ends with the* no-orphan check.*/@@ -17,8 +17,6 @@ import { randomUUID } from "node:crypto";import { chmodSync, existsSync, readFileSync, rmSync, writeFileSync } from "node:fs";import { tmpdir } from "node:os";import { join } from "node:path";-import { SessionManager } from "../channel/session-manager.js";-import type { ChannelEvent, SessionManagerOptions } from "../channel/types.js";import { HookEngine } from "../hooks/engine.js";import type { JournalEntry } from "../hooks/journal.js";import type { HookDefinition } from "../hooks/public.js";@@ -29,6 +27,8 @@ import {type SessionHookBinding,createSessionHookBinding,} from "../hooks/session/binding.js";+import { SessionManager, sessionEventFor } from "../mcp-session/session-manager.js";+import type { SessionManagerOptions } from "../mcp-session/types.js";import {type TeamHandle,type TeamRunOptions,@@ -176,7 +176,8 @@ interface Chan {t: PaneTestEnv;manager: SessionManager;id: string;- frames: ChannelEvent[];+ /** the row event of every state the session entered, from events.jsonl `state` records */+ rowEvents(): string[];info(): ReturnType<SessionManager["getSession"]>;output(): string;anomalies(): readonly string[];@@ -195,7 +196,6 @@ async function channel(o: {extraEnv?: Record<string, string>;}): Promise<Chan> {const t = env(o.script, o.extraEnv);- const frames: ChannelEvent[] = [];const b = o.binding;const manager = new SessionManager({maxSessions: 20,@@ -206,7 +206,6 @@ async function channel(o: {hookEngine: async () => o.engine ?? null,...(b ? { hookBinding: typeof b === "function" ? b : () => b } : {}),...(o.magmuxBinary ? { magmuxBinary: o.magmuxBinary } : {}),- onStateChange: (_id, ev) => void frames.push(ev),});const prompt = o.prompt === undefined ? "Reply with the first answer." : o.prompt;const id = await manager.createSession({@@ -219,7 +218,10 @@ async function channel(o: {t,manager,id,- frames,+ rowEvents: () =>+ eventsOf({ manager, id } as Chan)+ .filter((e) => e.type === "state")+ .map((e) => sessionEventFor({ state: e.to as SlotState, activity: null }).event),info: () => manager.getSession(id),output: () => manager.getOutput(id).output,anomalies: () => manager.getDiagnostics(id).anomalies,@@ -341,9 +343,9 @@ describe.skipIf(!MAGMUX)(`the settle hold (§11.5) ${MAGMUX ? "" : NO_MAGMUX_MESconst diag = c.manager.getDiagnostics(c.id);expect(diag.phase).toBe("SETTLING");expect(diag.anomalies.some((a) => a.startsWith("illegal_transition"))).toBe(false);- expect(c.frames.map((f) => f.type)).not.toContain("waiting_for_input");- // the frame for RUNNING is "running", never a tool frame named "hook"- expect(c.frames.some((f) => f.type === "tool_executing")).toBe(false);+ expect(c.rowEvents()).not.toContain("waiting_for_input");+ // the row event for RUNNING with activity "hook" is "running", never a tool named "hook"+ expect(sessionEventFor(info).event).toBe("running");} finally {await done(c);}@@ -697,7 +699,7 @@ wait $childconst end = await c.terminal();expect(end.state).toBe("COMPLETED");expect(c.anomalies()).toContain("hook_injection_dropped:send_not_accepted");- expect(c.frames.map((f) => f.type)).not.toContain("waiting_for_input");+ expect(c.rowEvents()).not.toContain("waiting_for_input");expect(lineCount(c.output(), "ANS-ONE")).toBe(1);expect(ctl.dropped).toEqual([{ text: "HOOK-PING", reason: "send_not_accepted" }]);} finally {@@ -839,7 +841,7 @@ wait $childconst end = await c.terminal();expect(end.state).toBe("COMPLETED");// no wait opened between chain turns- expect(c.frames.map((f) => f.type)).not.toContain("waiting_for_input");+ expect(c.rowEvents()).not.toContain("waiting_for_input");const waits = join(c.manager.getDiagnostics(c.id).sessionDir, "waits.jsonl");expect(existsSync(waits) ? readFileSync(waits, "utf8") : "").toBe("");} finally {@@ -1015,7 +1017,7 @@ wait $child"MORE-3",]);expect(c.anomalies()).toContain("hook_injection_dropped:capped");- expect(c.frames.map((f) => f.type)).not.toContain("waiting_for_input");+ expect(c.rowEvents()).not.toContain("waiting_for_input");} finally {await done(c);}@@ -1349,7 +1351,6 @@ wait $child.filter((e) => e.type === "anomaly").map((e) => e.key);expect(keys).not.toContain("prompt_not_read");- expect(c.frames.some((f) => f.extraMeta?.prompt_not_read === "true")).toBe(false);} finally {await done(c);}diff --git a/packages/cli/src/team-heartbeat-survival.test.ts b/packages/cli/src/team-heartbeat-survival.test.tsindex 61760f64..a04051c0 100644--- a/packages/cli/src/team-heartbeat-survival.test.ts+++ b/packages/cli/src/team-heartbeat-survival.test.ts@@ -65,6 +65,7 @@ describe("offline team slot anomaly projection", () => {captureSource: null,turnSource: "transcript",pendingInputs: 0,+ pendingHookInputs: 0,connected: true,startedAt: "2026-10-06T00:59:00.000Z",endedAt: null,@@ -93,6 +94,7 @@ describe("offline team slot anomaly projection", () => {snapshot: () => snap,ready: Promise.resolve(),terminal: terminal.promise,+ reaped: () => terminal.promise,turnAnswer: () => "PEAR",} as unknown as pane.PaneSession;});diff --git a/packages/cli/src/team-status-payload.test.ts b/packages/cli/src/team-status-payload.test.tsindex a7b9043b..7c3064a1 100644--- a/packages/cli/src/team-status-payload.test.ts+++ b/packages/cli/src/team-status-payload.test.ts@@ -176,6 +176,7 @@ describe("buildTeamStatusPayload", () => {captureSource: null,turnSource: "transcript",pendingInputs: 0,+ pendingHookInputs: 0,connected: true,startedAt: "2026-10-06T00:59:00.000Z",endedAt: null,