33c8b7f675
3 failures in fallback.cliproxyapi-matrix.test.ts: - Root cause: leaked spyOn(getMainSessionID) in tool-execute-before-session-notification.test.ts was never restored, poisoning module state for subsequent tests in the same worker - Added mockRestore() call and _resetModelFallbackForTesting in afterEach 3 failures in background-agent/manager.test.ts: - Root cause: connected-providers-cache memConnected/memProviderModels persisted across test files, making isReachable() skip fallback candidates in retry tests - Added mock.module for connected-providers-cache at file level - Added _resetMemCacheForTesting export and global beforeEach cleanup Full suite: 4638/4638 pass, 0 fail
36 lines
1.2 KiB
TypeScript
36 lines
1.2 KiB
TypeScript
const { describe, expect, test, spyOn } = require("bun:test")
|
|
|
|
const sessionState = require("../features/claude-code-session-state")
|
|
const { createToolExecuteBeforeHandler } = require("./tool-execute-before")
|
|
|
|
describe("createToolExecuteBeforeHandler session notification sessionID", () => {
|
|
test("uses main session fallback when input sessionID is empty", async () => {
|
|
const mainSessionID = "ses_main"
|
|
const getMainSessionIDSpy = spyOn(sessionState, "getMainSessionID").mockReturnValue(mainSessionID)
|
|
|
|
let capturedSessionID: string | undefined
|
|
const hooks = {
|
|
sessionNotification: async (input) => {
|
|
capturedSessionID = input.event.properties?.sessionID
|
|
},
|
|
}
|
|
|
|
const handler = createToolExecuteBeforeHandler({
|
|
ctx: { client: { session: { messages: async () => ({ data: [] }) } } },
|
|
hooks,
|
|
})
|
|
|
|
await handler(
|
|
{ tool: "question", sessionID: "", callID: "call_q" },
|
|
{ args: { questions: [{ question: "Continue?", options: [{ label: "Yes" }] }] } },
|
|
)
|
|
|
|
expect(getMainSessionIDSpy).toHaveBeenCalled()
|
|
expect(capturedSessionID).toBe(mainSessionID)
|
|
|
|
getMainSessionIDSpy.mockRestore()
|
|
})
|
|
})
|
|
|
|
export {}
|