diff --git a/src/cli/run/events.test.ts b/src/cli/run/events.test.ts index 334d518e..2afc216f 100644 --- a/src/cli/run/events.test.ts +++ b/src/cli/run/events.test.ts @@ -1,4 +1,4 @@ -import { describe, it, expect, spyOn } from "bun:test" +import { afterEach, beforeEach, describe, it, expect, spyOn } from "bun:test" import { createEventState, processEvents, serializeError, type EventState } from "./events" import type { RunContext, EventPayload } from "./types" @@ -100,12 +100,21 @@ describe("event handling", () => { const events = toAsyncIterable([payload]) - // when - await processEvents(ctx, events, state) + const baselineCallCount = errorSpy.mock.calls.length - // then - expect(errorSpy).not.toHaveBeenCalled() - errorSpy.mockRestore() + try { + // when + await processEvents(ctx, events, state) + + // then + const newCalls = errorSpy.mock.calls.slice(baselineCallCount) + const hasEventTrace = newCalls.some((call) => + String(call?.[0] ?? "").includes("custom.event"), + ) + expect(hasEventTrace).toBe(false) + } finally { + errorSpy.mockRestore() + } }) it("logs full event traces when verbose is enabled", async () => { @@ -121,14 +130,21 @@ describe("event handling", () => { const events = toAsyncIterable([payload]) - // when - await processEvents(ctx, events, state) + const baselineCallCount = errorSpy.mock.calls.length - // then - expect(errorSpy).toHaveBeenCalledTimes(1) - const firstCall = errorSpy.mock.calls[0] - expect(String(firstCall?.[0] ?? "")).toContain("custom.event") - errorSpy.mockRestore() + try { + // when + await processEvents(ctx, events, state) + + // then + const newCalls = errorSpy.mock.calls.slice(baselineCallCount) + const hasEventTrace = newCalls.some((call) => + String(call?.[0] ?? "").includes("custom.event"), + ) + expect(hasEventTrace).toBe(true) + } finally { + errorSpy.mockRestore() + } }) it("session.idle sets mainSessionIdle to true for matching session", async () => {