diff --git a/extensions/voice-call/src/manager/events.test.ts b/extensions/voice-call/src/manager/events.test.ts index f979fb1d92e..46cbe744d18 100644 --- a/extensions/voice-call/src/manager/events.test.ts +++ b/extensions/voice-call/src/manager/events.test.ts @@ -1,17 +1,32 @@ import fs from "node:fs"; import os from "node:os"; import path from "node:path"; -import { describe, expect, it } from "vitest"; +import { afterEach, describe, expect, it } from "vitest"; import { VoiceCallConfigSchema } from "../config.js"; import type { VoiceCallProvider } from "../providers/base.js"; import type { HangupCallInput, NormalizedEvent } from "../types.js"; import type { CallManagerContext } from "./context.js"; import { processEvent } from "./events.js"; +const contexts: CallManagerContext[] = []; + +afterEach(() => { + for (const ctx of contexts.splice(0)) { + for (const timer of ctx.maxDurationTimers.values()) { + clearTimeout(timer); + } + ctx.maxDurationTimers.clear(); + for (const waiter of ctx.transcriptWaiters.values()) { + clearTimeout(waiter.timeout); + } + ctx.transcriptWaiters.clear(); + fs.rmSync(ctx.storePath, { recursive: true, force: true }); + } +}); + function createContext(overrides: Partial = {}): CallManagerContext { - const storePath = path.join(os.tmpdir(), `openclaw-voice-call-events-test-${Date.now()}`); - fs.mkdirSync(storePath, { recursive: true }); - return { + const storePath = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-voice-call-events-test-")); + const ctx: CallManagerContext = { activeCalls: new Map(), providerCallIdMap: new Map(), processedEventIds: new Set(), @@ -30,6 +45,8 @@ function createContext(overrides: Partial = {}): CallManager initialMessageInFlight: new Set(), ...overrides, }; + contexts.push(ctx); + return ctx; } function createProvider(overrides: Partial = {}): VoiceCallProvider {