test: trim singleton cold-start reloads
This commit is contained in:
parent
0a842de354
commit
6526074c85
@ -1,4 +1,4 @@
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
||||
import {
|
||||
clearFastTestEnv,
|
||||
loadRunCronIsolatedAgentTurn,
|
||||
@ -8,11 +8,7 @@ import {
|
||||
runWithModelFallbackMock,
|
||||
} from "./run.test-harness.js";
|
||||
|
||||
type RunModule = typeof import("./run.js");
|
||||
type SandboxConfigModule = typeof import("../../agents/sandbox/config.js");
|
||||
|
||||
let runCronIsolatedAgentTurn: RunModule["runCronIsolatedAgentTurn"];
|
||||
let resolveSandboxConfigForAgent: SandboxConfigModule["resolveSandboxConfigForAgent"];
|
||||
const runCronIsolatedAgentTurn = await loadRunCronIsolatedAgentTurn();
|
||||
|
||||
function makeJob(overrides?: Record<string, unknown>) {
|
||||
return {
|
||||
@ -85,10 +81,7 @@ function expectDefaultSandboxPreserved(
|
||||
describe("runCronIsolatedAgentTurn sandbox config preserved", () => {
|
||||
let previousFastTestEnv: string | undefined;
|
||||
|
||||
beforeEach(async () => {
|
||||
vi.resetModules();
|
||||
runCronIsolatedAgentTurn = await loadRunCronIsolatedAgentTurn();
|
||||
({ resolveSandboxConfigForAgent } = await import("../../agents/sandbox/config.js"));
|
||||
beforeEach(() => {
|
||||
previousFastTestEnv = clearFastTestEnv();
|
||||
resetRunCronIsolatedAgentTurnHarness();
|
||||
});
|
||||
@ -132,6 +125,7 @@ describe("runCronIsolatedAgentTurn sandbox config preserved", () => {
|
||||
|
||||
expect(runWithModelFallbackMock).toHaveBeenCalledTimes(1);
|
||||
const runCfg = runWithModelFallbackMock.mock.calls[0]?.[0]?.cfg;
|
||||
const { resolveSandboxConfigForAgent } = await import("../../agents/sandbox/config.js");
|
||||
const resolvedSandbox = resolveSandboxConfigForAgent(runCfg, "specialist");
|
||||
|
||||
expectDefaultSandboxPreserved(runCfg);
|
||||
|
||||
@ -1,58 +1,72 @@
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
const completeMock = vi.fn();
|
||||
const minimaxUnderstandImageMock = vi.fn();
|
||||
const ensureOpenClawModelsJsonMock = vi.fn(async () => {});
|
||||
const getApiKeyForModelMock = vi.fn(async () => ({
|
||||
const hoisted = vi.hoisted(() => ({
|
||||
completeMock: vi.fn(),
|
||||
minimaxUnderstandImageMock: vi.fn(),
|
||||
ensureOpenClawModelsJsonMock: vi.fn(async () => {}),
|
||||
getApiKeyForModelMock: vi.fn(async () => ({
|
||||
apiKey: "oauth-test", // pragma: allowlist secret
|
||||
source: "test",
|
||||
mode: "oauth",
|
||||
}));
|
||||
const resolveApiKeyForProviderMock = vi.fn(async () => ({
|
||||
})),
|
||||
resolveApiKeyForProviderMock: vi.fn(async () => ({
|
||||
apiKey: "oauth-test", // pragma: allowlist secret
|
||||
source: "test",
|
||||
mode: "oauth",
|
||||
})),
|
||||
requireApiKeyMock: vi.fn((auth: { apiKey?: string }) => auth.apiKey ?? ""),
|
||||
setRuntimeApiKeyMock: vi.fn(),
|
||||
discoverModelsMock: vi.fn(),
|
||||
}));
|
||||
const requireApiKeyMock = vi.fn((auth: { apiKey?: string }) => auth.apiKey ?? "");
|
||||
const setRuntimeApiKeyMock = vi.fn();
|
||||
const discoverModelsMock = vi.fn();
|
||||
type ImageModule = typeof import("./image.js");
|
||||
const {
|
||||
completeMock,
|
||||
minimaxUnderstandImageMock,
|
||||
ensureOpenClawModelsJsonMock,
|
||||
getApiKeyForModelMock,
|
||||
resolveApiKeyForProviderMock,
|
||||
requireApiKeyMock,
|
||||
setRuntimeApiKeyMock,
|
||||
discoverModelsMock,
|
||||
} = hoisted;
|
||||
|
||||
let describeImageWithModel: ImageModule["describeImageWithModel"];
|
||||
|
||||
describe("describeImageWithModel", () => {
|
||||
beforeEach(async () => {
|
||||
vi.resetModules();
|
||||
vi.clearAllMocks();
|
||||
vi.doMock("@mariozechner/pi-ai", async (importOriginal) => {
|
||||
vi.mock("@mariozechner/pi-ai", async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import("@mariozechner/pi-ai")>();
|
||||
return {
|
||||
...actual,
|
||||
complete: completeMock,
|
||||
};
|
||||
});
|
||||
vi.doMock("../../agents/minimax-vlm.js", () => ({
|
||||
|
||||
vi.mock("../../agents/minimax-vlm.js", () => ({
|
||||
isMinimaxVlmProvider: (provider: string) =>
|
||||
provider === "minimax" || provider === "minimax-portal",
|
||||
isMinimaxVlmModel: (provider: string, modelId: string) =>
|
||||
(provider === "minimax" || provider === "minimax-portal") && modelId === "MiniMax-VL-01",
|
||||
minimaxUnderstandImage: minimaxUnderstandImageMock,
|
||||
}));
|
||||
vi.doMock("../../agents/models-config.js", () => ({
|
||||
|
||||
vi.mock("../../agents/models-config.js", () => ({
|
||||
ensureOpenClawModelsJson: ensureOpenClawModelsJsonMock,
|
||||
}));
|
||||
vi.doMock("../../agents/model-auth.js", () => ({
|
||||
|
||||
vi.mock("../../agents/model-auth.js", () => ({
|
||||
getApiKeyForModel: getApiKeyForModelMock,
|
||||
resolveApiKeyForProvider: resolveApiKeyForProviderMock,
|
||||
requireApiKey: requireApiKeyMock,
|
||||
}));
|
||||
vi.doMock("../../agents/pi-model-discovery-runtime.js", () => ({
|
||||
|
||||
vi.mock("../../agents/pi-model-discovery-runtime.js", () => ({
|
||||
discoverAuthStorage: () => ({
|
||||
setRuntimeApiKey: setRuntimeApiKeyMock,
|
||||
}),
|
||||
discoverModels: discoverModelsMock,
|
||||
}));
|
||||
({ describeImageWithModel } = await import("./image.js"));
|
||||
|
||||
const { describeImageWithModel } = await import("./image.js");
|
||||
|
||||
describe("describeImageWithModel", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
minimaxUnderstandImageMock.mockResolvedValue("portal ok");
|
||||
discoverModelsMock.mockReturnValue({
|
||||
find: vi.fn(() => ({
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user