Skip to content

Commit bdd24fa

Browse files
committed
test(task): prevent teardown logging race
1 parent 910d057 commit bdd24fa

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

src/core/task/__tests__/Task.throttle.test.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,16 @@ describe("Task token usage throttling", () => {
6464
let mockProvider: any
6565
let mockApiConfiguration: ProviderSettings
6666
let task: Task
67+
let consoleLogSpy: ReturnType<typeof vi.spyOn>
6768

6869
beforeEach(() => {
6970
// Reset all mocks
7071
vi.clearAllMocks()
7172
vi.useFakeTimers()
73+
// Task.dispose() logs during afterEach. Under the full coverage suite, forwarding
74+
// those teardown logs can race with Vitest worker shutdown and leave
75+
// onUserConsoleLog RPC calls pending.
76+
consoleLogSpy = vi.spyOn(console, "log").mockImplementation(() => {})
7277

7378
// Mock provider
7479
mockProvider = {
@@ -97,10 +102,11 @@ describe("Task token usage throttling", () => {
97102
})
98103

99104
afterEach(() => {
100-
vi.useRealTimers()
101105
if (task && !task.abort) {
102106
task.dispose()
103107
}
108+
consoleLogSpy.mockRestore()
109+
vi.useRealTimers()
104110
})
105111

106112
test("should emit TaskTokenUsageUpdated immediately on first change", async () => {

0 commit comments

Comments
 (0)