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.
This commit is contained in:
parent
4040a25bb1
commit
51fdf17867
@ -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);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@ -279,10 +279,6 @@ export async function triggerInternalHook(event: InternalHookEvent): Promise<voi
|
||||
|
||||
const allHandlers = [...typeHandlers, ...specificHandlers];
|
||||
|
||||
if (allHandlers.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (const handler of allHandlers) {
|
||||
try {
|
||||
await handler(event);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user