test(voice-call): install state runtime for events

This commit is contained in:
Peter Steinberger
2026-05-31 20:41:14 +01:00
parent 55fc3c10b0
commit 6f58a71582

View File

@@ -1,9 +1,15 @@
import fs from "node:fs";
import os from "node:os";
import path from "node:path";
import { afterEach, describe, expect, it } from "vitest";
import type { OpenKeyedStoreOptions } from "openclaw/plugin-sdk/plugin-state-runtime";
import {
createPluginStateSyncKeyedStoreForTests,
resetPluginStateStoreForTests,
} from "openclaw/plugin-sdk/plugin-state-test-runtime";
import { afterEach, beforeEach, describe, expect, it } from "vitest";
import { VoiceCallConfigSchema } from "../config.js";
import type { VoiceCallProvider } from "../providers/base.js";
import { clearVoiceCallStateRuntime, setVoiceCallStateRuntime } from "../runtime-state.js";
import type { AnswerCallInput, HangupCallInput, NormalizedEvent } from "../types.js";
import type { CallManagerContext } from "./context.js";
import { processEvent } from "./events.js";
@@ -11,6 +17,24 @@ import { flushPendingCallRecordWritesForTest } from "./store.js";
const contexts: CallManagerContext[] = [];
function installStateRuntime(): void {
setVoiceCallStateRuntime({
state: {
resolveStateDir: () => "",
openKeyedStore: (() => {
throw new Error("openKeyedStore is not used by voice-call event tests");
}) as never,
openSyncKeyedStore: (options: OpenKeyedStoreOptions) =>
createPluginStateSyncKeyedStoreForTests("voice-call", options),
},
});
}
beforeEach(() => {
resetPluginStateStoreForTests();
installStateRuntime();
});
afterEach(async () => {
for (const ctx of contexts.splice(0)) {
for (const timer of ctx.maxDurationTimers.values()) {
@@ -24,6 +48,8 @@ afterEach(async () => {
await flushPendingCallRecordWritesForTest();
fs.rmSync(ctx.storePath, { recursive: true, force: true });
}
clearVoiceCallStateRuntime();
resetPluginStateStoreForTests();
});
function createContext(overrides: Partial<CallManagerContext> = {}): CallManagerContext {