From 0cee39dafbf3817c21f97468e7660dc779f3ceab Mon Sep 17 00:00:00 2001 From: Sisyphus Date: Sat, 27 Dec 2025 23:22:17 +0900 Subject: [PATCH] fix: properly mock utility functions in session-notification tests (#274) The test mock for ctx.$ was not handling tagged template literals correctly, causing it to ignore interpolated values. Additionally, utility functions that check for command availability (osascript, notify-send, etc.) were returning null in test environments, causing sendNotification to exit early. Changes: - Fixed template literal reconstruction in mock $ function - Added spyOn mocks for all utility path functions - All session-notification tests now passing (11/11) Fixes #273 Co-authored-by: sisyphus-dev-ai --- src/hooks/session-notification.test.ts | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/hooks/session-notification.test.ts b/src/hooks/session-notification.test.ts index 934e44c..ad6eb53 100644 --- a/src/hooks/session-notification.test.ts +++ b/src/hooks/session-notification.test.ts @@ -1,16 +1,20 @@ -import { describe, expect, test, beforeEach, afterEach } from "bun:test" +import { describe, expect, test, beforeEach, afterEach, spyOn } from "bun:test" import { createSessionNotification } from "./session-notification" import { setMainSession, subagentSessions } from "../features/claude-code-session-state" +import * as utils from "./session-notification-utils" describe("session-notification", () => { let notificationCalls: string[] function createMockPluginInput() { return { - $: async (cmd: TemplateStringsArray | string) => { + $: async (cmd: TemplateStringsArray | string, ...values: any[]) => { // #given - track notification commands (osascript, notify-send, powershell) - const cmdStr = typeof cmd === "string" ? cmd : cmd.join("") + const cmdStr = typeof cmd === "string" + ? cmd + : cmd.reduce((acc, part, i) => acc + part + (values[i] ?? ""), "") + if (cmdStr.includes("osascript") || cmdStr.includes("notify-send") || cmdStr.includes("powershell")) { notificationCalls.push(cmdStr) } @@ -26,8 +30,15 @@ describe("session-notification", () => { } beforeEach(() => { - // #given - reset state before each test notificationCalls = [] + + spyOn(utils, "getOsascriptPath").mockResolvedValue("/usr/bin/osascript") + spyOn(utils, "getNotifySendPath").mockResolvedValue("/usr/bin/notify-send") + spyOn(utils, "getPowershellPath").mockResolvedValue("powershell") + spyOn(utils, "getAfplayPath").mockResolvedValue("/usr/bin/afplay") + spyOn(utils, "getPaplayPath").mockResolvedValue("/usr/bin/paplay") + spyOn(utils, "getAplayPath").mockResolvedValue("/usr/bin/aplay") + spyOn(utils, "startBackgroundCheck").mockImplementation(() => {}) }) afterEach(() => {