mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-28 06:31:11 +00:00
test: speed up agent hotspot tests
This commit is contained in:
parent
0b301e9af4
commit
2aa375149f
6 changed files with 108 additions and 37 deletions
|
|
@ -24,15 +24,13 @@ import * as sessionHistoryModule from "./cli-runner/session-history.js";
|
|||
import { MAX_CLI_SESSION_HISTORY_MESSAGES } from "./cli-runner/session-history.js";
|
||||
import type { PreparedCliRunContext } from "./cli-runner/types.js";
|
||||
|
||||
vi.mock("../plugins/hook-runner-global.js", async () => {
|
||||
const actual = await vi.importActual<typeof import("../plugins/hook-runner-global.js")>(
|
||||
"../plugins/hook-runner-global.js",
|
||||
);
|
||||
return {
|
||||
...actual,
|
||||
getGlobalHookRunner: vi.fn(() => null),
|
||||
};
|
||||
});
|
||||
vi.mock("../plugins/hook-runner-global.js", () => ({
|
||||
getGlobalHookRunner: vi.fn(() => null),
|
||||
}));
|
||||
|
||||
vi.mock("../tts/tts.js", () => ({
|
||||
buildTtsSystemPromptHint: vi.fn(() => undefined),
|
||||
}));
|
||||
|
||||
const mockGetGlobalHookRunner = vi.mocked(getGlobalHookRunner);
|
||||
|
||||
|
|
|
|||
|
|
@ -15,35 +15,31 @@ import {
|
|||
shouldSkipLocalCliCredentialEpoch,
|
||||
} from "./prepare.js";
|
||||
|
||||
vi.mock("../../plugins/hook-runner-global.js", async () => {
|
||||
const actual = await vi.importActual<typeof import("../../plugins/hook-runner-global.js")>(
|
||||
"../../plugins/hook-runner-global.js",
|
||||
);
|
||||
return {
|
||||
...actual,
|
||||
getGlobalHookRunner: vi.fn(() => null),
|
||||
};
|
||||
});
|
||||
vi.mock("../../plugins/hook-runner-global.js", () => ({
|
||||
getGlobalHookRunner: vi.fn(() => null),
|
||||
}));
|
||||
|
||||
vi.mock("../video-generation-task-status.js", async () => {
|
||||
const actual = await vi.importActual<typeof import("../video-generation-task-status.js")>(
|
||||
"../video-generation-task-status.js",
|
||||
);
|
||||
return {
|
||||
...actual,
|
||||
buildActiveVideoGenerationTaskPromptContextForSession: vi.fn(() => undefined),
|
||||
};
|
||||
});
|
||||
vi.mock("../../tts/tts.js", () => ({
|
||||
buildTtsSystemPromptHint: vi.fn(() => undefined),
|
||||
}));
|
||||
|
||||
vi.mock("../music-generation-task-status.js", async () => {
|
||||
const actual = await vi.importActual<typeof import("../music-generation-task-status.js")>(
|
||||
"../music-generation-task-status.js",
|
||||
);
|
||||
return {
|
||||
...actual,
|
||||
buildActiveMusicGenerationTaskPromptContextForSession: vi.fn(() => undefined),
|
||||
};
|
||||
});
|
||||
vi.mock("../video-generation-task-status.js", () => ({
|
||||
VIDEO_GENERATION_TASK_KIND: "video_generation",
|
||||
buildActiveVideoGenerationTaskPromptContextForSession: vi.fn(() => undefined),
|
||||
buildVideoGenerationTaskStatusDetails: vi.fn(() => ({})),
|
||||
buildVideoGenerationTaskStatusText: vi.fn(() => ""),
|
||||
findActiveVideoGenerationTaskForSession: vi.fn(() => undefined),
|
||||
getVideoGenerationTaskProviderId: vi.fn(() => undefined),
|
||||
isActiveVideoGenerationTask: vi.fn(() => false),
|
||||
}));
|
||||
|
||||
vi.mock("../music-generation-task-status.js", () => ({
|
||||
MUSIC_GENERATION_TASK_KIND: "music_generation",
|
||||
buildActiveMusicGenerationTaskPromptContextForSession: vi.fn(() => undefined),
|
||||
buildMusicGenerationTaskStatusDetails: vi.fn(() => ({})),
|
||||
buildMusicGenerationTaskStatusText: vi.fn(() => ""),
|
||||
findActiveMusicGenerationTaskForSession: vi.fn(() => undefined),
|
||||
}));
|
||||
|
||||
const mockGetGlobalHookRunner = vi.mocked(getGlobalHookRunner);
|
||||
const mockBuildActiveVideoGenerationTaskPromptContextForSession = vi.mocked(
|
||||
|
|
|
|||
|
|
@ -234,6 +234,13 @@ vi.mock("../../../plugins/hook-runner-global.js", () => ({
|
|||
initializeGlobalHookRunner: hoisted.initializeGlobalHookRunnerMock,
|
||||
}));
|
||||
|
||||
vi.mock("../../../plugins/provider-runtime.js", () => ({
|
||||
resolveProviderReasoningOutputModeWithPlugin: () => undefined,
|
||||
resolveProviderSystemPromptContribution: () => undefined,
|
||||
resolveProviderTextTransforms: () => undefined,
|
||||
transformProviderSystemPrompt: ({ systemPrompt }: { systemPrompt: string }) => systemPrompt,
|
||||
}));
|
||||
|
||||
vi.mock("../../../infra/machine-name.js", () => ({
|
||||
getMachineDisplayName: async () => "test-host",
|
||||
}));
|
||||
|
|
@ -246,6 +253,10 @@ vi.mock("../../../infra/net/undici-global-dispatcher.js", () => ({
|
|||
hoisted.ensureGlobalUndiciStreamTimeoutsMock(...args),
|
||||
}));
|
||||
|
||||
vi.mock("../../../tts/tts.js", () => ({
|
||||
buildTtsSystemPromptHint: () => undefined,
|
||||
}));
|
||||
|
||||
vi.mock("../../bootstrap-files.js", async () => {
|
||||
const actual = await vi.importActual<typeof import("../../bootstrap-files.js")>(
|
||||
"../../bootstrap-files.js",
|
||||
|
|
|
|||
|
|
@ -29,6 +29,16 @@ vi.mock("../plugins/provider-runtime.js", () => ({
|
|||
resolveExternalAuthProfilesWithPlugins: () => [],
|
||||
}));
|
||||
|
||||
vi.mock("./auth-profiles/store.js", () => ({
|
||||
ensureAuthProfileStore: () => ({ version: 1, profiles: {} }),
|
||||
loadAuthProfileStoreForSecretsRuntime: () => ({ version: 1, profiles: {} }),
|
||||
}));
|
||||
|
||||
vi.mock("./pi-auth-discovery-core.js", () => ({
|
||||
addEnvBackedPiCredentials: (credentials: Record<string, unknown>) => ({ ...credentials }),
|
||||
scrubLegacyStaticAuthJsonEntriesForDiscovery: vi.fn(),
|
||||
}));
|
||||
|
||||
let resolvePiCredentialsForDiscovery: typeof import("./pi-auth-discovery.js").resolvePiCredentialsForDiscovery;
|
||||
|
||||
async function withAgentDir(run: (agentDir: string) => Promise<void>): Promise<void> {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import type { AgentTool } from "@mariozechner/pi-agent-core";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import {
|
||||
createNativeOpenAIResponsesModel,
|
||||
createParameterFreeTool,
|
||||
|
|
@ -8,7 +8,22 @@ import {
|
|||
import { logAgentRuntimeToolDiagnostics, normalizeAgentRuntimeTools } from "./tools.js";
|
||||
import type { AgentRuntimePlan } from "./types.js";
|
||||
|
||||
const mocks = vi.hoisted(() => ({
|
||||
logProviderToolSchemaDiagnostics: vi.fn(),
|
||||
normalizeProviderToolSchemas: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock("../pi-embedded-runner/tool-schema-runtime.js", () => ({
|
||||
logProviderToolSchemaDiagnostics: mocks.logProviderToolSchemaDiagnostics,
|
||||
normalizeProviderToolSchemas: mocks.normalizeProviderToolSchemas,
|
||||
}));
|
||||
|
||||
describe("AgentRuntimePlan tool policy helpers", () => {
|
||||
beforeEach(() => {
|
||||
mocks.logProviderToolSchemaDiagnostics.mockReset();
|
||||
mocks.normalizeProviderToolSchemas.mockReset();
|
||||
});
|
||||
|
||||
it("uses RuntimePlan-owned tool normalization when a plan is available", () => {
|
||||
const tools = [createParameterFreeTool()] as AgentTool[];
|
||||
const normalized = [{ ...tools[0], name: "normalized" }] as AgentTool[];
|
||||
|
|
@ -65,6 +80,13 @@ describe("AgentRuntimePlan tool policy helpers", () => {
|
|||
});
|
||||
|
||||
it("falls back to legacy provider schema normalization when no plan is available", () => {
|
||||
mocks.normalizeProviderToolSchemas.mockReturnValueOnce([
|
||||
{
|
||||
...createParameterFreeTool(),
|
||||
parameters: normalizedParameterFreeSchema(),
|
||||
},
|
||||
]);
|
||||
|
||||
const normalized = normalizeAgentRuntimeTools({
|
||||
tools: [createParameterFreeTool()] as AgentTool[],
|
||||
provider: "openai",
|
||||
|
|
@ -75,6 +97,14 @@ describe("AgentRuntimePlan tool policy helpers", () => {
|
|||
});
|
||||
|
||||
expect(normalized[0]?.parameters).toEqual(normalizedParameterFreeSchema());
|
||||
expect(mocks.normalizeProviderToolSchemas).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
provider: "openai",
|
||||
modelId: "gpt-5.4",
|
||||
modelApi: "openai-responses",
|
||||
workspaceDir: "/tmp/openclaw-runtime-plan-tools",
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it("routes diagnostics through RuntimePlan when a plan is available", () => {
|
||||
|
|
|
|||
|
|
@ -51,6 +51,32 @@ vi.mock("../../plugin-sdk/browser-bridge.js", () => ({
|
|||
stopBrowserBridgeServer: bridgeMocks.stopBrowserBridgeServer,
|
||||
}));
|
||||
|
||||
vi.mock("../../plugin-sdk/browser-profiles.js", () => ({
|
||||
DEFAULT_BROWSER_ACTION_TIMEOUT_MS: 60_000,
|
||||
DEFAULT_BROWSER_EVALUATE_ENABLED: true,
|
||||
DEFAULT_OPENCLAW_BROWSER_COLOR: "#FF4500",
|
||||
DEFAULT_OPENCLAW_BROWSER_PROFILE_NAME: "openclaw",
|
||||
resolveProfile: (
|
||||
resolved: { cdpHost: string; cdpIsLoopback: boolean; profiles?: Record<string, unknown> },
|
||||
profileName: string,
|
||||
) => {
|
||||
const profile = resolved.profiles?.[profileName] as { cdpPort?: number; color?: string };
|
||||
if (typeof profile?.cdpPort !== "number") {
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
name: profileName,
|
||||
cdpPort: profile.cdpPort,
|
||||
cdpUrl: `http://${resolved.cdpHost}:${profile.cdpPort}`,
|
||||
cdpHost: resolved.cdpHost,
|
||||
cdpIsLoopback: resolved.cdpIsLoopback,
|
||||
color: profile.color ?? "#FF4500",
|
||||
driver: "openclaw",
|
||||
attachOnly: true,
|
||||
};
|
||||
},
|
||||
}));
|
||||
|
||||
async function loadFreshBrowserModulesForTest() {
|
||||
vi.resetModules();
|
||||
({ BROWSER_BRIDGES } = await import("./browser-bridges.js"));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue