53eeac3f31
- Add afterAll(() => { mock.restore() }) to 52 test files missing cleanup
- Rewrite create-tool-guard-hooks.test.ts to use spyOn instead of barrel mock
- Fix skill-mcp-manager OAuth tests with missing mockTokens/mockLogin definitions
- Fix start-work hook: show worktree active block on resume with existing worktree_path
- Extract createWorktreeActiveBlock to worktree-block.ts to avoid circular import
- Replace 80-line isolated test runner CI config with single `bun test` command
70 lines
1.8 KiB
TypeScript
70 lines
1.8 KiB
TypeScript
const { beforeEach, describe, expect, mock, test, afterAll } = require("bun:test")
|
|
|
|
const executeStopHooks = mock(async (context: { parentSessionId?: string }) => ({
|
|
block: false,
|
|
observedParentSessionId: context.parentSessionId,
|
|
}))
|
|
|
|
mock.module("../config", () => ({
|
|
clearClaudeHooksConfigCache: () => {},
|
|
loadClaudeHooksConfig: async () => null,
|
|
}))
|
|
|
|
mock.module("../config-loader", () => ({
|
|
clearPluginExtendedConfigCache: () => {},
|
|
loadPluginExtendedConfig: async () => ({}),
|
|
}))
|
|
|
|
mock.module("../stop", () => ({
|
|
executeStopHooks,
|
|
}))
|
|
|
|
afterAll(() => { mock.restore() })
|
|
|
|
const { createSessionEventHandler } = await import("./session-event-handler")
|
|
|
|
describe("createSessionEventHandler retry behavior", () => {
|
|
beforeEach(() => {
|
|
executeStopHooks.mockClear()
|
|
})
|
|
|
|
test("#given transient parent lookup failure #when the next idle succeeds #then stop hooks receive the later parent session id", async () => {
|
|
//#given
|
|
let getCallCount = 0
|
|
const handler = createSessionEventHandler(
|
|
{
|
|
directory: "/repo",
|
|
client: {
|
|
session: {
|
|
get: async () => {
|
|
getCallCount += 1
|
|
if (getCallCount === 1) {
|
|
throw new Error("temporary failure")
|
|
}
|
|
return { data: { parentID: "ses_parent" } }
|
|
},
|
|
prompt: async () => undefined,
|
|
},
|
|
},
|
|
} as never,
|
|
{},
|
|
)
|
|
|
|
//#when
|
|
await handler({ event: { type: "session.idle", properties: { sessionID: "ses_retry" } } })
|
|
await handler({ event: { type: "session.idle", properties: { sessionID: "ses_retry" } } })
|
|
|
|
//#then
|
|
expect(getCallCount).toBe(2)
|
|
expect(executeStopHooks).toHaveBeenLastCalledWith(
|
|
expect.objectContaining({
|
|
parentSessionId: "ses_parent",
|
|
}),
|
|
null,
|
|
{},
|
|
)
|
|
})
|
|
})
|
|
|
|
export {}
|