test: share embedded runner e2e mocks

This commit is contained in:
Peter Steinberger
2026-04-18 23:41:54 +01:00
parent a0919685be
commit cbe124689d
3 changed files with 34 additions and 32 deletions

View File

@@ -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),

View File

@@ -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");

View 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(),
}));
}