mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-10 00:31:22 +00:00
test: trim more agent e2e partial mocks
This commit is contained in:
@@ -23,16 +23,18 @@ const { computeBackoffMock, sleepWithAbortMock } = vi.hoisted(() => ({
|
||||
sleepWithAbortMock: vi.fn(async (_ms: number, _abortSignal?: AbortSignal) => undefined),
|
||||
}));
|
||||
|
||||
vi.mock("./pi-embedded-runner/run/attempt.js", async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import("./pi-embedded-runner/run/attempt.js")>();
|
||||
vi.mock("./pi-embedded-runner/run/attempt.js", async () => {
|
||||
const actual = await vi.importActual<typeof import("./pi-embedded-runner/run/attempt.js")>(
|
||||
"./pi-embedded-runner/run/attempt.js",
|
||||
);
|
||||
return {
|
||||
...actual,
|
||||
runEmbeddedAttempt: (params: unknown) => runEmbeddedAttemptMock(params),
|
||||
};
|
||||
});
|
||||
|
||||
vi.mock("../infra/backoff.js", async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import("../infra/backoff.js")>();
|
||||
vi.mock("../infra/backoff.js", async () => {
|
||||
const actual = await vi.importActual<typeof import("../infra/backoff.js")>("../infra/backoff.js");
|
||||
return {
|
||||
...actual,
|
||||
computeBackoff: (
|
||||
@@ -43,8 +45,8 @@ vi.mock("../infra/backoff.js", async (importOriginal) => {
|
||||
};
|
||||
});
|
||||
|
||||
vi.mock("./models-config.js", async (importOriginal) => {
|
||||
const mod = await importOriginal<typeof import("./models-config.js")>();
|
||||
vi.mock("./models-config.js", async () => {
|
||||
const mod = await vi.importActual<typeof import("./models-config.js")>("./models-config.js");
|
||||
return {
|
||||
...mod,
|
||||
ensureOpenClawModelsJson: vi.fn(async () => ({ wrote: false })),
|
||||
@@ -68,8 +70,10 @@ const installRunEmbeddedMocks = () => {
|
||||
resolveModelAsync: async (provider: string, modelId: string) =>
|
||||
createResolvedEmbeddedRunnerModel(provider, modelId),
|
||||
}));
|
||||
vi.doMock("../plugins/provider-runtime.js", async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import("../plugins/provider-runtime.js")>();
|
||||
vi.doMock("../plugins/provider-runtime.js", async () => {
|
||||
const actual = await vi.importActual<typeof import("../plugins/provider-runtime.js")>(
|
||||
"../plugins/provider-runtime.js",
|
||||
);
|
||||
return {
|
||||
...actual,
|
||||
prepareProviderRuntimeAuth: vi.fn(async () => undefined),
|
||||
|
||||
@@ -20,8 +20,8 @@ const disposeSessionMcpRuntimeMock = vi.fn<(sessionId: string) => Promise<void>>
|
||||
});
|
||||
let refreshRuntimeAuthOnFirstPromptError = false;
|
||||
|
||||
vi.mock("@mariozechner/pi-ai", async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import("@mariozechner/pi-ai")>();
|
||||
vi.mock("@mariozechner/pi-ai", async () => {
|
||||
const actual = await vi.importActual<typeof import("@mariozechner/pi-ai")>("@mariozechner/pi-ai");
|
||||
|
||||
const buildAssistantMessage = (model: { api: string; provider: string; id: string }) => ({
|
||||
role: "assistant" as const,
|
||||
@@ -101,8 +101,10 @@ const installRunEmbeddedMocks = () => {
|
||||
vi.doMock("./pi-bundle-mcp-tools.js", () => ({
|
||||
disposeSessionMcpRuntime: (sessionId: string) => disposeSessionMcpRuntimeMock(sessionId),
|
||||
}));
|
||||
vi.doMock("./pi-embedded-runner/model.js", async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import("./pi-embedded-runner/model.js")>();
|
||||
vi.doMock("./pi-embedded-runner/model.js", async () => {
|
||||
const actual = await vi.importActual<typeof import("./pi-embedded-runner/model.js")>(
|
||||
"./pi-embedded-runner/model.js",
|
||||
);
|
||||
return {
|
||||
...actual,
|
||||
resolveModelAsync: async (provider: string, modelId: string) =>
|
||||
@@ -119,15 +121,17 @@ const installRunEmbeddedMocks = () => {
|
||||
stopRuntimeAuthRefreshTimer: vi.fn(),
|
||||
}),
|
||||
}));
|
||||
vi.doMock("../plugins/provider-runtime.js", async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import("../plugins/provider-runtime.js")>();
|
||||
vi.doMock("../plugins/provider-runtime.js", async () => {
|
||||
const actual = await vi.importActual<typeof import("../plugins/provider-runtime.js")>(
|
||||
"../plugins/provider-runtime.js",
|
||||
);
|
||||
return {
|
||||
...actual,
|
||||
prepareProviderRuntimeAuth: vi.fn(async () => undefined),
|
||||
};
|
||||
});
|
||||
vi.doMock("./models-config.js", async (importOriginal) => {
|
||||
const mod = await importOriginal<typeof import("./models-config.js")>();
|
||||
vi.doMock("./models-config.js", async () => {
|
||||
const mod = await vi.importActual<typeof import("./models-config.js")>("./models-config.js");
|
||||
return {
|
||||
...mod,
|
||||
ensureOpenClawModelsJson: vi.fn(async () => ({ wrote: false })),
|
||||
|
||||
@@ -59,8 +59,10 @@ const installRunEmbeddedMocks = () => {
|
||||
vi.doMock("./pi-embedded-runner/run/attempt.js", () => ({
|
||||
runEmbeddedAttempt: (params: unknown) => runEmbeddedAttemptMock(params),
|
||||
}));
|
||||
vi.doMock("../plugins/provider-runtime.js", async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import("../plugins/provider-runtime.js")>();
|
||||
vi.doMock("../plugins/provider-runtime.js", async () => {
|
||||
const actual = await vi.importActual<typeof import("../plugins/provider-runtime.js")>(
|
||||
"../plugins/provider-runtime.js",
|
||||
);
|
||||
return {
|
||||
...actual,
|
||||
prepareProviderRuntimeAuth: async (params: {
|
||||
@@ -92,8 +94,8 @@ const installRunEmbeddedMocks = () => {
|
||||
throw new Error("compact should not run in auth profile rotation tests");
|
||||
}),
|
||||
}));
|
||||
vi.doMock("./models-config.js", async (importOriginal) => {
|
||||
const mod = await importOriginal<typeof import("./models-config.js")>();
|
||||
vi.doMock("./models-config.js", async () => {
|
||||
const mod = await vi.importActual<typeof import("./models-config.js")>("./models-config.js");
|
||||
return {
|
||||
...mod,
|
||||
ensureOpenClawModelsJson: vi.fn(async () => ({ wrote: false })),
|
||||
|
||||
@@ -12,8 +12,8 @@ type SpawnCall = {
|
||||
|
||||
const spawnCalls: SpawnCall[] = [];
|
||||
|
||||
vi.mock("node:child_process", async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import("node:child_process")>();
|
||||
vi.mock("node:child_process", async () => {
|
||||
const actual = await vi.importActual<typeof import("node:child_process")>("node:child_process");
|
||||
return {
|
||||
...actual,
|
||||
spawn: (command: string, args: string[]) => {
|
||||
@@ -42,8 +42,8 @@ vi.mock("node:child_process", async (importOriginal) => {
|
||||
};
|
||||
});
|
||||
|
||||
vi.mock("./skills.js", async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import("./skills.js")>();
|
||||
vi.mock("./skills.js", async () => {
|
||||
const actual = await vi.importActual<typeof import("./skills.js")>("./skills.js");
|
||||
return {
|
||||
...actual,
|
||||
syncSkillsToWorkspace: vi.fn(async () => undefined),
|
||||
|
||||
@@ -575,8 +575,10 @@ vi.mock("../channel-web.js", () => ({
|
||||
loginWeb: vi.fn(async () => {}),
|
||||
}));
|
||||
|
||||
vi.mock("../channels/plugins/catalog.js", async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import("../channels/plugins/catalog.js")>();
|
||||
vi.mock("../channels/plugins/catalog.js", async () => {
|
||||
const actual = await vi.importActual<typeof import("../channels/plugins/catalog.js")>(
|
||||
"../channels/plugins/catalog.js",
|
||||
);
|
||||
return {
|
||||
...actual,
|
||||
listChannelPluginCatalogEntries: ((...args) => {
|
||||
@@ -589,8 +591,10 @@ vi.mock("../channels/plugins/catalog.js", async (importOriginal) => {
|
||||
};
|
||||
});
|
||||
|
||||
vi.mock("../plugins/manifest-registry.js", async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import("../plugins/manifest-registry.js")>();
|
||||
vi.mock("../plugins/manifest-registry.js", async () => {
|
||||
const actual = await vi.importActual<typeof import("../plugins/manifest-registry.js")>(
|
||||
"../plugins/manifest-registry.js",
|
||||
);
|
||||
return {
|
||||
...actual,
|
||||
loadPluginManifestRegistry: manifestRegistryMocks.loadPluginManifestRegistry,
|
||||
@@ -606,8 +610,8 @@ vi.mock("./onboard-helpers.js", () => ({
|
||||
detectBinary: vi.fn(async () => false),
|
||||
}));
|
||||
|
||||
vi.mock("./channel-setup/plugin-install.js", async (importOriginal) => {
|
||||
const actual = await importOriginal();
|
||||
vi.mock("./channel-setup/plugin-install.js", async () => {
|
||||
const actual = await vi.importActual("./channel-setup/plugin-install.js");
|
||||
return {
|
||||
...(actual as Record<string, unknown>),
|
||||
ensureChannelSetupPluginInstalled: vi.fn(async ({ cfg }: { cfg: OpenClawConfig }) => ({
|
||||
|
||||
Reference in New Issue
Block a user