mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-14 10:41:23 +00:00
59 lines
1.6 KiB
TypeScript
59 lines
1.6 KiB
TypeScript
import { afterAll, beforeAll } from "vitest";
|
|
import type { OpenClawConfig } from "../../config/config.js";
|
|
import { defaultRuntime } from "../../runtime.js";
|
|
import type { FollowupRun } from "./queue.js";
|
|
|
|
export function createDeferred<T>() {
|
|
let resolve!: (value: T) => void;
|
|
let reject!: (reason?: unknown) => void;
|
|
const promise = new Promise<T>((res, rej) => {
|
|
resolve = res;
|
|
reject = rej;
|
|
});
|
|
return { promise, resolve, reject };
|
|
}
|
|
|
|
export function createQueueTestRun(params: {
|
|
prompt: string;
|
|
messageId?: string;
|
|
originatingChannel?: FollowupRun["originatingChannel"];
|
|
originatingTo?: string;
|
|
originatingAccountId?: string;
|
|
originatingThreadId?: string | number;
|
|
}): FollowupRun {
|
|
return {
|
|
prompt: params.prompt,
|
|
messageId: params.messageId,
|
|
enqueuedAt: Date.now(),
|
|
originatingChannel: params.originatingChannel,
|
|
originatingTo: params.originatingTo,
|
|
originatingAccountId: params.originatingAccountId,
|
|
originatingThreadId: params.originatingThreadId,
|
|
run: {
|
|
agentId: "agent",
|
|
agentDir: "/tmp",
|
|
sessionId: "sess",
|
|
sessionFile: "/tmp/session.json",
|
|
workspaceDir: "/tmp",
|
|
config: {} as OpenClawConfig,
|
|
provider: "openai",
|
|
model: "gpt-test",
|
|
timeoutMs: 10_000,
|
|
blockReplyBreak: "text_end",
|
|
},
|
|
};
|
|
}
|
|
|
|
export function installQueueRuntimeErrorSilencer(): void {
|
|
let previousRuntimeError: typeof defaultRuntime.error;
|
|
|
|
beforeAll(() => {
|
|
previousRuntimeError = defaultRuntime.error;
|
|
defaultRuntime.error = (() => {}) as typeof defaultRuntime.error;
|
|
});
|
|
|
|
afterAll(() => {
|
|
defaultRuntime.error = previousRuntimeError;
|
|
});
|
|
}
|