Skip to content

Commit 6526074

Browse files
committed
test: trim singleton cold-start reloads
1 parent 0a842de commit 6526074

2 files changed

Lines changed: 65 additions & 57 deletions

File tree

src/cron/isolated-agent/run.sandbox-config-preserved.test.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
1+
import { afterEach, beforeEach, describe, expect, it } from "vitest";
22
import {
33
clearFastTestEnv,
44
loadRunCronIsolatedAgentTurn,
@@ -8,11 +8,7 @@ import {
88
runWithModelFallbackMock,
99
} from "./run.test-harness.js";
1010

11-
type RunModule = typeof import("./run.js");
12-
type SandboxConfigModule = typeof import("../../agents/sandbox/config.js");
13-
14-
let runCronIsolatedAgentTurn: RunModule["runCronIsolatedAgentTurn"];
15-
let resolveSandboxConfigForAgent: SandboxConfigModule["resolveSandboxConfigForAgent"];
11+
const runCronIsolatedAgentTurn = await loadRunCronIsolatedAgentTurn();
1612

1713
function makeJob(overrides?: Record<string, unknown>) {
1814
return {
@@ -85,10 +81,7 @@ function expectDefaultSandboxPreserved(
8581
describe("runCronIsolatedAgentTurn sandbox config preserved", () => {
8682
let previousFastTestEnv: string | undefined;
8783

88-
beforeEach(async () => {
89-
vi.resetModules();
90-
runCronIsolatedAgentTurn = await loadRunCronIsolatedAgentTurn();
91-
({ resolveSandboxConfigForAgent } = await import("../../agents/sandbox/config.js"));
84+
beforeEach(() => {
9285
previousFastTestEnv = clearFastTestEnv();
9386
resetRunCronIsolatedAgentTurnHarness();
9487
});
@@ -132,6 +125,7 @@ describe("runCronIsolatedAgentTurn sandbox config preserved", () => {
132125

133126
expect(runWithModelFallbackMock).toHaveBeenCalledTimes(1);
134127
const runCfg = runWithModelFallbackMock.mock.calls[0]?.[0]?.cfg;
128+
const { resolveSandboxConfigForAgent } = await import("../../agents/sandbox/config.js");
135129
const resolvedSandbox = resolveSandboxConfigForAgent(runCfg, "specialist");
136130

137131
expectDefaultSandboxPreserved(runCfg);

src/media-understanding/providers/image.test.ts

Lines changed: 61 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,72 @@
11
import { beforeEach, describe, expect, it, vi } from "vitest";
22

3-
const completeMock = vi.fn();
4-
const minimaxUnderstandImageMock = vi.fn();
5-
const ensureOpenClawModelsJsonMock = vi.fn(async () => {});
6-
const getApiKeyForModelMock = vi.fn(async () => ({
7-
apiKey: "oauth-test", // pragma: allowlist secret
8-
source: "test",
9-
mode: "oauth",
3+
const hoisted = vi.hoisted(() => ({
4+
completeMock: vi.fn(),
5+
minimaxUnderstandImageMock: vi.fn(),
6+
ensureOpenClawModelsJsonMock: vi.fn(async () => {}),
7+
getApiKeyForModelMock: vi.fn(async () => ({
8+
apiKey: "oauth-test", // pragma: allowlist secret
9+
source: "test",
10+
mode: "oauth",
11+
})),
12+
resolveApiKeyForProviderMock: vi.fn(async () => ({
13+
apiKey: "oauth-test", // pragma: allowlist secret
14+
source: "test",
15+
mode: "oauth",
16+
})),
17+
requireApiKeyMock: vi.fn((auth: { apiKey?: string }) => auth.apiKey ?? ""),
18+
setRuntimeApiKeyMock: vi.fn(),
19+
discoverModelsMock: vi.fn(),
1020
}));
11-
const resolveApiKeyForProviderMock = vi.fn(async () => ({
12-
apiKey: "oauth-test", // pragma: allowlist secret
13-
source: "test",
14-
mode: "oauth",
21+
const {
22+
completeMock,
23+
minimaxUnderstandImageMock,
24+
ensureOpenClawModelsJsonMock,
25+
getApiKeyForModelMock,
26+
resolveApiKeyForProviderMock,
27+
requireApiKeyMock,
28+
setRuntimeApiKeyMock,
29+
discoverModelsMock,
30+
} = hoisted;
31+
32+
vi.mock("@mariozechner/pi-ai", async (importOriginal) => {
33+
const actual = await importOriginal<typeof import("@mariozechner/pi-ai")>();
34+
return {
35+
...actual,
36+
complete: completeMock,
37+
};
38+
});
39+
40+
vi.mock("../../agents/minimax-vlm.js", () => ({
41+
isMinimaxVlmProvider: (provider: string) =>
42+
provider === "minimax" || provider === "minimax-portal",
43+
isMinimaxVlmModel: (provider: string, modelId: string) =>
44+
(provider === "minimax" || provider === "minimax-portal") && modelId === "MiniMax-VL-01",
45+
minimaxUnderstandImage: minimaxUnderstandImageMock,
1546
}));
16-
const requireApiKeyMock = vi.fn((auth: { apiKey?: string }) => auth.apiKey ?? "");
17-
const setRuntimeApiKeyMock = vi.fn();
18-
const discoverModelsMock = vi.fn();
19-
type ImageModule = typeof import("./image.js");
2047

21-
let describeImageWithModel: ImageModule["describeImageWithModel"];
48+
vi.mock("../../agents/models-config.js", () => ({
49+
ensureOpenClawModelsJson: ensureOpenClawModelsJsonMock,
50+
}));
51+
52+
vi.mock("../../agents/model-auth.js", () => ({
53+
getApiKeyForModel: getApiKeyForModelMock,
54+
resolveApiKeyForProvider: resolveApiKeyForProviderMock,
55+
requireApiKey: requireApiKeyMock,
56+
}));
57+
58+
vi.mock("../../agents/pi-model-discovery-runtime.js", () => ({
59+
discoverAuthStorage: () => ({
60+
setRuntimeApiKey: setRuntimeApiKeyMock,
61+
}),
62+
discoverModels: discoverModelsMock,
63+
}));
64+
65+
const { describeImageWithModel } = await import("./image.js");
2266

2367
describe("describeImageWithModel", () => {
24-
beforeEach(async () => {
25-
vi.resetModules();
68+
beforeEach(() => {
2669
vi.clearAllMocks();
27-
vi.doMock("@mariozechner/pi-ai", async (importOriginal) => {
28-
const actual = await importOriginal<typeof import("@mariozechner/pi-ai")>();
29-
return {
30-
...actual,
31-
complete: completeMock,
32-
};
33-
});
34-
vi.doMock("../../agents/minimax-vlm.js", () => ({
35-
isMinimaxVlmProvider: (provider: string) =>
36-
provider === "minimax" || provider === "minimax-portal",
37-
isMinimaxVlmModel: (provider: string, modelId: string) =>
38-
(provider === "minimax" || provider === "minimax-portal") && modelId === "MiniMax-VL-01",
39-
minimaxUnderstandImage: minimaxUnderstandImageMock,
40-
}));
41-
vi.doMock("../../agents/models-config.js", () => ({
42-
ensureOpenClawModelsJson: ensureOpenClawModelsJsonMock,
43-
}));
44-
vi.doMock("../../agents/model-auth.js", () => ({
45-
getApiKeyForModel: getApiKeyForModelMock,
46-
resolveApiKeyForProvider: resolveApiKeyForProviderMock,
47-
requireApiKey: requireApiKeyMock,
48-
}));
49-
vi.doMock("../../agents/pi-model-discovery-runtime.js", () => ({
50-
discoverAuthStorage: () => ({
51-
setRuntimeApiKey: setRuntimeApiKeyMock,
52-
}),
53-
discoverModels: discoverModelsMock,
54-
}));
55-
({ describeImageWithModel } = await import("./image.js"));
5670
minimaxUnderstandImageMock.mockResolvedValue("portal ok");
5771
discoverModelsMock.mockReturnValue({
5872
find: vi.fn(() => ({

0 commit comments

Comments
 (0)