Files
openclaw/extensions/qqbot/src/test-support/runtime.ts
2026-07-13 12:44:33 -07:00

56 lines
1.8 KiB
TypeScript

// Qqbot plugin module implements runtime behavior.
import type { PluginRuntime } from "openclaw/plugin-sdk/core";
import type { OpenKeyedStoreOptions } from "openclaw/plugin-sdk/plugin-state-runtime";
import {
createPluginStateKeyedStoreForTests,
createPluginStateSyncKeyedStoreForTests,
resetPluginStateStoreForTests,
} from "openclaw/plugin-sdk/plugin-state-test-runtime";
import { setQQBotRuntime } from "../bridge/runtime.js";
function stateEnv(stateDir: string, env?: NodeJS.ProcessEnv): NodeJS.ProcessEnv {
return {
...(env ?? process.env),
OPENCLAW_STATE_DIR: stateDir,
};
}
export function installQQBotRuntimeForStateTests(stateDir: string): void {
resetPluginStateStoreForTests();
setQQBotRuntime({
version: "test",
state: {
resolveStateDir: () => stateDir,
openKeyedStore: <T>(options: OpenKeyedStoreOptions) =>
createPluginStateKeyedStoreForTests<T>("qqbot", {
...options,
env: stateEnv(stateDir, options.env),
}),
openSyncKeyedStore: <T>(options: OpenKeyedStoreOptions) =>
createPluginStateSyncKeyedStoreForTests<T>("qqbot", {
...options,
env: stateEnv(stateDir, options.env),
}),
openChannelIngressQueue: () => {
throw new Error("openChannelIngressQueue is not configured for QQBot state tests");
},
},
} as unknown as PluginRuntime);
}
export function resetQQBotStateTestRuntime(): void {
resetPluginStateStoreForTests();
const unavailable = (): never => {
throw new Error("QQBot state test runtime is not installed");
};
setQQBotRuntime({
version: "test",
state: {
resolveStateDir: unavailable,
openKeyedStore: unavailable,
openSyncKeyedStore: unavailable,
openChannelIngressQueue: unavailable,
},
} as unknown as PluginRuntime);
}