mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 12:40:43 +00:00
test: share embedded runner e2e mocks
This commit is contained in:
@@ -11,6 +11,7 @@ import {
|
||||
createResolvedEmbeddedRunnerModel,
|
||||
makeEmbeddedRunnerAttempt,
|
||||
} from "./test-helpers/pi-embedded-runner-e2e-fixtures.js";
|
||||
import { installEmbeddedRunnerBaseE2eMocks } from "./test-helpers/pi-embedded-runner-e2e-mocks.js";
|
||||
|
||||
const runEmbeddedAttemptMock = vi.fn<(params: unknown) => Promise<EmbeddedRunAttemptResult>>();
|
||||
const { computeBackoffMock, sleepWithAbortMock } = vi.hoisted(() => ({
|
||||
@@ -54,20 +55,7 @@ vi.mock("./models-config.js", async () => {
|
||||
});
|
||||
|
||||
const installRunEmbeddedMocks = () => {
|
||||
vi.doMock("../plugins/hook-runner-global.js", () => ({
|
||||
getGlobalHookRunner: vi.fn(() => undefined),
|
||||
}));
|
||||
vi.doMock("../context-engine/init.js", () => ({
|
||||
ensureContextEnginesInitialized: vi.fn(),
|
||||
}));
|
||||
vi.doMock("../context-engine/registry.js", () => ({
|
||||
resolveContextEngine: vi.fn(async () => ({
|
||||
dispose: async () => undefined,
|
||||
})),
|
||||
}));
|
||||
vi.doMock("./runtime-plugins.js", () => ({
|
||||
ensureRuntimePluginsLoaded: vi.fn(),
|
||||
}));
|
||||
installEmbeddedRunnerBaseE2eMocks();
|
||||
vi.doMock("./pi-embedded-runner/model.js", () => ({
|
||||
resolveModelAsync: async (provider: string, modelId: string) =>
|
||||
createResolvedEmbeddedRunnerModel(provider, modelId),
|
||||
|
||||
@@ -13,6 +13,7 @@ import {
|
||||
immediateEnqueue,
|
||||
makeEmbeddedRunnerAttempt,
|
||||
} from "./test-helpers/pi-embedded-runner-e2e-fixtures.js";
|
||||
import { installEmbeddedRunnerBaseE2eMocks } from "./test-helpers/pi-embedded-runner-e2e-mocks.js";
|
||||
|
||||
const runEmbeddedAttemptMock = vi.fn();
|
||||
const disposeSessionMcpRuntimeMock = vi.fn<(sessionId: string) => Promise<void>>(async () => {
|
||||
@@ -82,24 +83,7 @@ vi.mock("@mariozechner/pi-ai", async () => {
|
||||
});
|
||||
|
||||
const installRunEmbeddedMocks = () => {
|
||||
vi.doMock("../plugins/hook-runner-global.js", () => ({
|
||||
getGlobalHookRunner: vi.fn(() => undefined),
|
||||
getGlobalPluginRegistry: vi.fn(() => null),
|
||||
hasGlobalHooks: vi.fn(() => false),
|
||||
initializeGlobalHookRunner: vi.fn(),
|
||||
resetGlobalHookRunner: vi.fn(),
|
||||
}));
|
||||
vi.doMock("../context-engine/init.js", () => ({
|
||||
ensureContextEnginesInitialized: vi.fn(),
|
||||
}));
|
||||
vi.doMock("../context-engine/registry.js", () => ({
|
||||
resolveContextEngine: vi.fn(async () => ({
|
||||
dispose: async () => undefined,
|
||||
})),
|
||||
}));
|
||||
vi.doMock("./runtime-plugins.js", () => ({
|
||||
ensureRuntimePluginsLoaded: vi.fn(),
|
||||
}));
|
||||
installEmbeddedRunnerBaseE2eMocks({ hookRunner: "full" });
|
||||
vi.doMock("./command/session.js", async () => {
|
||||
const actual =
|
||||
await vi.importActual<typeof import("./command/session.js")>("./command/session.js");
|
||||
|
||||
30
src/agents/test-helpers/pi-embedded-runner-e2e-mocks.ts
Normal file
30
src/agents/test-helpers/pi-embedded-runner-e2e-mocks.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { vi } from "vitest";
|
||||
|
||||
export function installEmbeddedRunnerBaseE2eMocks(options?: {
|
||||
hookRunner?: "minimal" | "full";
|
||||
}): void {
|
||||
vi.doMock("../../plugins/hook-runner-global.js", () =>
|
||||
options?.hookRunner === "full"
|
||||
? {
|
||||
getGlobalHookRunner: vi.fn(() => undefined),
|
||||
getGlobalPluginRegistry: vi.fn(() => null),
|
||||
hasGlobalHooks: vi.fn(() => false),
|
||||
initializeGlobalHookRunner: vi.fn(),
|
||||
resetGlobalHookRunner: vi.fn(),
|
||||
}
|
||||
: {
|
||||
getGlobalHookRunner: vi.fn(() => undefined),
|
||||
},
|
||||
);
|
||||
vi.doMock("../../context-engine/init.js", () => ({
|
||||
ensureContextEnginesInitialized: vi.fn(),
|
||||
}));
|
||||
vi.doMock("../../context-engine/registry.js", () => ({
|
||||
resolveContextEngine: vi.fn(async () => ({
|
||||
dispose: async () => undefined,
|
||||
})),
|
||||
}));
|
||||
vi.doMock("../runtime-plugins.js", () => ({
|
||||
ensureRuntimePluginsLoaded: vi.fn(),
|
||||
}));
|
||||
}
|
||||
Reference in New Issue
Block a user