test: clean up voice-call event timers

This commit is contained in:
Peter Steinberger
2026-04-23 05:55:34 +01:00
parent 9f437549d3
commit 4aa35d85fa

View File

@@ -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> = {}): 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<CallManagerContext> = {}): CallManager
initialMessageInFlight: new Set(),
...overrides,
};
contexts.push(ctx);
return ctx;
}
function createProvider(overrides: Partial<VoiceCallProvider> = {}): VoiceCallProvider {