From c1cc474a577bb3486f46c491e793e6e38bff38a4 Mon Sep 17 00:00:00 2001 From: Josh Lehman Date: Fri, 13 Mar 2026 11:42:03 -0700 Subject: [PATCH] test: fix stale compact hooks mocks Regeneration-Prompt: | Fix the broken test imports in src/agents/pi-embedded-runner/compact.hooks.test.ts without touching production code. The immediate failure was a stale vi.mock for ../../utils/message-channel.js that no longer exposed INTERNAL_MESSAGE_CHANNEL, so the mock should spread the real module exports via importOriginal and override only normalizeMessageChannel. After that change, the suite still could not import because the @mariozechner/pi-coding-agent mock also shadowed newer exports, so apply the same partial-mock pattern there. Verify pnpm vitest run src/agents/pi-embedded-runner/compact.hooks.test.ts and pnpm vitest run src/plugins/wired-hooks-compaction.test.ts both pass. --- .../pi-embedded-runner/compact.hooks.test.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/agents/pi-embedded-runner/compact.hooks.test.ts b/src/agents/pi-embedded-runner/compact.hooks.test.ts index e3ef243b429..665c155e18b 100644 --- a/src/agents/pi-embedded-runner/compact.hooks.test.ts +++ b/src/agents/pi-embedded-runner/compact.hooks.test.ts @@ -91,8 +91,10 @@ vi.mock("@mariozechner/pi-ai/oauth", () => ({ getOAuthProviders: vi.fn(() => []), })); -vi.mock("@mariozechner/pi-coding-agent", () => { +vi.mock("@mariozechner/pi-coding-agent", async (importOriginal) => { + const actual = await importOriginal(); return { + ...actual, createAgentSession: vi.fn(async () => { const session = { sessionId: "session-1", @@ -277,9 +279,13 @@ vi.mock("../../config/channel-capabilities.js", () => ({ resolveChannelCapabilities: vi.fn(() => undefined), })); -vi.mock("../../utils/message-channel.js", () => ({ - normalizeMessageChannel: vi.fn(() => undefined), -})); +vi.mock("../../utils/message-channel.js", async (importOriginal) => { + const actual = await importOriginal(); + return { + ...actual, + normalizeMessageChannel: vi.fn(() => undefined), + }; +}); vi.mock("../pi-embedded-helpers.js", () => ({ ensureSessionHeader: vi.fn(async () => {}),