From 51fdf17867c0917e29ce4f501e44b36a87abb15d Mon Sep 17 00:00:00 2001 From: zeroaltitude Date: Sat, 7 Mar 2026 10:16:02 -0700 Subject: [PATCH] fix: drain postHookActions even with no registered handlers Remove early return in triggerInternalHook that skipped the post-hook drain when allHandlers was empty. This was a latent footgun: any postHookActions pre-populated on the event before calling triggerInternalHook would be silently dropped if no handlers were registered for that event type. Update test to verify post-hooks now drain in the no-handlers case. --- src/hooks/internal-hooks.test.ts | 10 ++++++---- src/hooks/internal-hooks.ts | 4 ---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/hooks/internal-hooks.test.ts b/src/hooks/internal-hooks.test.ts index c0a87b014bb..a2b51c803c7 100644 --- a/src/hooks/internal-hooks.test.ts +++ b/src/hooks/internal-hooks.test.ts @@ -529,13 +529,15 @@ describe("hooks", () => { expect(event.postHookActions).toEqual([]); }); - it("does not run post-hook actions when no handlers are registered", async () => { + it("drains post-hook actions even when no handlers are registered", async () => { const event = createInternalHookEvent("command", "new", "test-session"); + let ran = false; event.postHookActions.push(() => { - throw new Error("should not run"); + ran = true; }); - // triggerInternalHook returns early when no handlers — post-hooks don't run - await expect(triggerInternalHook(event)).resolves.not.toThrow(); + // No handlers registered — post-hooks should still drain + await triggerInternalHook(event); + expect(ran).toBe(true); }); }); diff --git a/src/hooks/internal-hooks.ts b/src/hooks/internal-hooks.ts index a8d0736fbf0..2feb80e8af1 100644 --- a/src/hooks/internal-hooks.ts +++ b/src/hooks/internal-hooks.ts @@ -279,10 +279,6 @@ export async function triggerInternalHook(event: InternalHookEvent): Promise