mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-08 03:22:55 +00:00
test(voice-call): install state runtime for events
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user