test: stub heavy tools in agent tests
This commit is contained in:
@@ -3,6 +3,7 @@ import os from "node:os";
|
|||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
import { describe, expect, it, vi } from "vitest";
|
import { describe, expect, it, vi } from "vitest";
|
||||||
|
|
||||||
|
import "./test-helpers/fast-core-tools.js";
|
||||||
import { createClawdbotTools } from "./clawdbot-tools.js";
|
import { createClawdbotTools } from "./clawdbot-tools.js";
|
||||||
|
|
||||||
vi.mock("./tools/gateway.js", () => ({
|
vi.mock("./tools/gateway.js", () => ({
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ vi.mock("../config/config.js", async (importOriginal) => {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
import "./test-helpers/fast-core-tools.js";
|
||||||
import { createClawdbotTools } from "./clawdbot-tools.js";
|
import { createClawdbotTools } from "./clawdbot-tools.js";
|
||||||
|
|
||||||
describe("agents_list", () => {
|
describe("agents_list", () => {
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ vi.mock("../media/image-ops.js", () => ({
|
|||||||
resizeToJpeg: vi.fn(async () => Buffer.from("jpeg")),
|
resizeToJpeg: vi.fn(async () => Buffer.from("jpeg")),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
import "./test-helpers/fast-core-tools.js";
|
||||||
import { createClawdbotTools } from "./clawdbot-tools.js";
|
import { createClawdbotTools } from "./clawdbot-tools.js";
|
||||||
|
|
||||||
describe("nodes camera_snap", () => {
|
describe("nodes camera_snap", () => {
|
||||||
|
|||||||
@@ -75,6 +75,7 @@ vi.mock("../infra/provider-usage.js", () => ({
|
|||||||
formatUsageSummaryLine: () => null,
|
formatUsageSummaryLine: () => null,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
import "./test-helpers/fast-core-tools.js";
|
||||||
import { createClawdbotTools } from "./clawdbot-tools.js";
|
import { createClawdbotTools } from "./clawdbot-tools.js";
|
||||||
|
|
||||||
describe("session_status tool", () => {
|
describe("session_status tool", () => {
|
||||||
|
|||||||
@@ -4,9 +4,6 @@ const callGatewayMock = vi.fn();
|
|||||||
vi.mock("../gateway/call.js", () => ({
|
vi.mock("../gateway/call.js", () => ({
|
||||||
callGateway: (opts: unknown) => callGatewayMock(opts),
|
callGateway: (opts: unknown) => callGatewayMock(opts),
|
||||||
}));
|
}));
|
||||||
vi.mock("../plugins/tools.js", () => ({
|
|
||||||
resolvePluginTools: () => [],
|
|
||||||
}));
|
|
||||||
|
|
||||||
vi.mock("../config/config.js", async (importOriginal) => {
|
vi.mock("../config/config.js", async (importOriginal) => {
|
||||||
const actual = await importOriginal<typeof import("../config/config.js")>();
|
const actual = await importOriginal<typeof import("../config/config.js")>();
|
||||||
@@ -23,6 +20,7 @@ vi.mock("../config/config.js", async (importOriginal) => {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
import "./test-helpers/fast-core-tools.js";
|
||||||
import { createClawdbotTools } from "./clawdbot-tools.js";
|
import { createClawdbotTools } from "./clawdbot-tools.js";
|
||||||
|
|
||||||
const waitForCalls = async (getCount: () => number, count: number, timeoutMs = 2000) => {
|
const waitForCalls = async (getCount: () => number, count: number, timeoutMs = 2000) => {
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ vi.mock("../config/config.js", async (importOriginal) => {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
import "./test-helpers/fast-core-tools.js";
|
||||||
import { createClawdbotTools } from "./clawdbot-tools.js";
|
import { createClawdbotTools } from "./clawdbot-tools.js";
|
||||||
import { resetSubagentRegistryForTests } from "./subagent-registry.js";
|
import { resetSubagentRegistryForTests } from "./subagent-registry.js";
|
||||||
|
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ vi.mock("../config/config.js", async (importOriginal) => {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
import "./test-helpers/fast-core-tools.js";
|
||||||
import { createClawdbotTools } from "./clawdbot-tools.js";
|
import { createClawdbotTools } from "./clawdbot-tools.js";
|
||||||
import { resetSubagentRegistryForTests } from "./subagent-registry.js";
|
import { resetSubagentRegistryForTests } from "./subagent-registry.js";
|
||||||
|
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ vi.mock("../config/config.js", async (importOriginal) => {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
import "./test-helpers/fast-core-tools.js";
|
||||||
import { createClawdbotTools } from "./clawdbot-tools.js";
|
import { createClawdbotTools } from "./clawdbot-tools.js";
|
||||||
import { resetSubagentRegistryForTests } from "./subagent-registry.js";
|
import { resetSubagentRegistryForTests } from "./subagent-registry.js";
|
||||||
|
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ vi.mock("../config/config.js", async (importOriginal) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
import { emitAgentEvent } from "../infra/agent-events.js";
|
import { emitAgentEvent } from "../infra/agent-events.js";
|
||||||
|
import "./test-helpers/fast-core-tools.js";
|
||||||
import { createClawdbotTools } from "./clawdbot-tools.js";
|
import { createClawdbotTools } from "./clawdbot-tools.js";
|
||||||
import { resetSubagentRegistryForTests } from "./subagent-registry.js";
|
import { resetSubagentRegistryForTests } from "./subagent-registry.js";
|
||||||
|
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ vi.mock("../config/config.js", async (importOriginal) => {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
import "./test-helpers/fast-core-tools.js";
|
||||||
import { createClawdbotTools } from "./clawdbot-tools.js";
|
import { createClawdbotTools } from "./clawdbot-tools.js";
|
||||||
import { resetSubagentRegistryForTests } from "./subagent-registry.js";
|
import { resetSubagentRegistryForTests } from "./subagent-registry.js";
|
||||||
|
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ vi.mock("../config/config.js", async (importOriginal) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
import { emitAgentEvent } from "../infra/agent-events.js";
|
import { emitAgentEvent } from "../infra/agent-events.js";
|
||||||
|
import "./test-helpers/fast-core-tools.js";
|
||||||
import { createClawdbotTools } from "./clawdbot-tools.js";
|
import { createClawdbotTools } from "./clawdbot-tools.js";
|
||||||
import { resetSubagentRegistryForTests } from "./subagent-registry.js";
|
import { resetSubagentRegistryForTests } from "./subagent-registry.js";
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { describe, expect, it } from "vitest";
|
import { describe, expect, it } from "vitest";
|
||||||
import type { ClawdbotConfig } from "../config/config.js";
|
import type { ClawdbotConfig } from "../config/config.js";
|
||||||
|
import "./test-helpers/fast-coding-tools.js";
|
||||||
import { createClawdbotCodingTools } from "./pi-tools.js";
|
import { createClawdbotCodingTools } from "./pi-tools.js";
|
||||||
|
|
||||||
const defaultTools = createClawdbotCodingTools();
|
const defaultTools = createClawdbotCodingTools();
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import os from "node:os";
|
|||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
import sharp from "sharp";
|
import sharp from "sharp";
|
||||||
import { describe, expect, it } from "vitest";
|
import { describe, expect, it } from "vitest";
|
||||||
|
import "./test-helpers/fast-coding-tools.js";
|
||||||
import { createClawdbotCodingTools } from "./pi-tools.js";
|
import { createClawdbotCodingTools } from "./pi-tools.js";
|
||||||
|
|
||||||
const defaultTools = createClawdbotCodingTools();
|
const defaultTools = createClawdbotCodingTools();
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import fs from "node:fs/promises";
|
|||||||
import os from "node:os";
|
import os from "node:os";
|
||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
import { describe, expect, it } from "vitest";
|
import { describe, expect, it } from "vitest";
|
||||||
|
import "./test-helpers/fast-coding-tools.js";
|
||||||
import { createClawdbotCodingTools } from "./pi-tools.js";
|
import { createClawdbotCodingTools } from "./pi-tools.js";
|
||||||
|
|
||||||
describe("createClawdbotCodingTools", () => {
|
describe("createClawdbotCodingTools", () => {
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import os from "node:os";
|
|||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
import type { AgentTool } from "@mariozechner/pi-agent-core";
|
import type { AgentTool } from "@mariozechner/pi-agent-core";
|
||||||
import { describe, expect, it, vi } from "vitest";
|
import { describe, expect, it, vi } from "vitest";
|
||||||
|
import "./test-helpers/fast-coding-tools.js";
|
||||||
import { createClawdbotTools } from "./clawdbot-tools.js";
|
import { createClawdbotTools } from "./clawdbot-tools.js";
|
||||||
import { __testing, createClawdbotCodingTools } from "./pi-tools.js";
|
import { __testing, createClawdbotCodingTools } from "./pi-tools.js";
|
||||||
import { createSandboxedReadTool } from "./pi-tools.read.js";
|
import { createSandboxedReadTool } from "./pi-tools.read.js";
|
||||||
|
|||||||
22
src/agents/test-helpers/fast-coding-tools.ts
Normal file
22
src/agents/test-helpers/fast-coding-tools.ts
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
import { vi } from "vitest";
|
||||||
|
|
||||||
|
const stubTool = (name: string) => ({
|
||||||
|
name,
|
||||||
|
description: `${name} stub`,
|
||||||
|
parameters: { type: "object", properties: {} },
|
||||||
|
execute: vi.fn(),
|
||||||
|
});
|
||||||
|
|
||||||
|
vi.mock("../tools/image-tool.js", () => ({
|
||||||
|
createImageTool: () => stubTool("image"),
|
||||||
|
}));
|
||||||
|
|
||||||
|
vi.mock("../tools/web-tools.js", () => ({
|
||||||
|
createWebSearchTool: () => null,
|
||||||
|
createWebFetchTool: () => null,
|
||||||
|
}));
|
||||||
|
|
||||||
|
vi.mock("../../plugins/tools.js", () => ({
|
||||||
|
resolvePluginTools: () => [],
|
||||||
|
getPluginToolMeta: () => undefined,
|
||||||
|
}));
|
||||||
30
src/agents/test-helpers/fast-core-tools.ts
Normal file
30
src/agents/test-helpers/fast-core-tools.ts
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
import { vi } from "vitest";
|
||||||
|
|
||||||
|
const stubTool = (name: string) => ({
|
||||||
|
name,
|
||||||
|
description: `${name} stub`,
|
||||||
|
parameters: { type: "object", properties: {} },
|
||||||
|
execute: vi.fn(),
|
||||||
|
});
|
||||||
|
|
||||||
|
vi.mock("../tools/browser-tool.js", () => ({
|
||||||
|
createBrowserTool: () => stubTool("browser"),
|
||||||
|
}));
|
||||||
|
|
||||||
|
vi.mock("../tools/canvas-tool.js", () => ({
|
||||||
|
createCanvasTool: () => stubTool("canvas"),
|
||||||
|
}));
|
||||||
|
|
||||||
|
vi.mock("../tools/image-tool.js", () => ({
|
||||||
|
createImageTool: () => stubTool("image"),
|
||||||
|
}));
|
||||||
|
|
||||||
|
vi.mock("../tools/web-tools.js", () => ({
|
||||||
|
createWebSearchTool: () => null,
|
||||||
|
createWebFetchTool: () => null,
|
||||||
|
}));
|
||||||
|
|
||||||
|
vi.mock("../../plugins/tools.js", () => ({
|
||||||
|
resolvePluginTools: () => [],
|
||||||
|
getPluginToolMeta: () => undefined,
|
||||||
|
}));
|
||||||
Reference in New Issue
Block a user