|
1 | 1 | import fs from "node:fs"; |
2 | 2 | import os from "node:os"; |
3 | 3 | import path from "node:path"; |
4 | | -import { afterEach, describe, expect, it } from "vitest"; |
| 4 | +import type { OpenKeyedStoreOptions } from "openclaw/plugin-sdk/plugin-state-runtime"; |
| 5 | +import { |
| 6 | +createPluginStateSyncKeyedStoreForTests, |
| 7 | +resetPluginStateStoreForTests, |
| 8 | +} from "openclaw/plugin-sdk/plugin-state-test-runtime"; |
| 9 | +import { afterEach, beforeEach, describe, expect, it } from "vitest"; |
5 | 10 | import { VoiceCallConfigSchema } from "../config.js"; |
6 | 11 | import type { VoiceCallProvider } from "../providers/base.js"; |
| 12 | +import { clearVoiceCallStateRuntime, setVoiceCallStateRuntime } from "../runtime-state.js"; |
7 | 13 | import type { AnswerCallInput, HangupCallInput, NormalizedEvent } from "../types.js"; |
8 | 14 | import type { CallManagerContext } from "./context.js"; |
9 | 15 | import { processEvent } from "./events.js"; |
10 | 16 | import { flushPendingCallRecordWritesForTest } from "./store.js"; |
11 | 17 | |
12 | 18 | const contexts: CallManagerContext[] = []; |
13 | 19 | |
| 20 | +function installStateRuntime(): void { |
| 21 | +setVoiceCallStateRuntime({ |
| 22 | +state: { |
| 23 | +resolveStateDir: () => "", |
| 24 | +openKeyedStore: (() => { |
| 25 | +throw new Error("openKeyedStore is not used by voice-call event tests"); |
| 26 | +}) as never, |
| 27 | +openSyncKeyedStore: (options: OpenKeyedStoreOptions) => |
| 28 | +createPluginStateSyncKeyedStoreForTests("voice-call", options), |
| 29 | +}, |
| 30 | +}); |
| 31 | +} |
| 32 | + |
| 33 | +beforeEach(() => { |
| 34 | +resetPluginStateStoreForTests(); |
| 35 | +installStateRuntime(); |
| 36 | +}); |
| 37 | + |
14 | 38 | afterEach(async () => { |
15 | 39 | for (const ctx of contexts.splice(0)) { |
16 | 40 | for (const timer of ctx.maxDurationTimers.values()) { |
@@ -24,6 +48,8 @@ afterEach(async () => {
|
24 | 48 | await flushPendingCallRecordWritesForTest(); |
25 | 49 | fs.rmSync(ctx.storePath, { recursive: true, force: true }); |
26 | 50 | } |
| 51 | +clearVoiceCallStateRuntime(); |
| 52 | +resetPluginStateStoreForTests(); |
27 | 53 | }); |
28 | 54 | |
29 | 55 | function createContext(overrides: Partial<CallManagerContext> = {}): CallManagerContext { |
|