Files
oh-my-pi/packages/coding-agent/test/tools/index.test.ts
T
can1357 cb5bbbf382 refactor(coding-agent): flattened directory structure, eliminated core/ folder
- Eliminated core/ directory (252 files, 23 subdirs → distributed)
- Reduced max nesting from 9 levels to 5 levels
- Promoted tool subdirs to top level: exa/, lsp/, patch/, task/, web/
- Merged web-scrapers/ + web-search/ into web/{scrapers,search}/
- Flattened modes/interactive/ to modes/
- Split execution/ into: ipy/ (python), exec/ (bash), ssh/
- Renamed ipy/python-*.ts to ipy/*.ts (executor, kernel, etc.)
- Flattened cursor/exec-bridge.ts to cursor.ts
- Created logical groupings: config/, session/, extensibility/, export/
- Updated all imports across 500+ files
2026-01-23 12:24:47 +01:00

171 lines
4.8 KiB
TypeScript

import { describe, expect, it } from "bun:test";
import { BUILTIN_TOOLS, createTools, HIDDEN_TOOLS, type ToolSession } from "$c/tools/index";
process.env.OMP_PYTHON_SKIP_CHECK = "1";
function createTestSession(overrides: Partial<ToolSession> = {}): ToolSession {
return {
cwd: "/tmp/test",
hasUI: false,
getSessionFile: () => null,
getSessionSpawns: () => "*",
...overrides,
};
}
function createBaseSettings(overrides: Partial<NonNullable<ToolSession["settings"]>> = {}) {
return {
getImageAutoResize: () => true,
getLspFormatOnWrite: () => true,
getLspDiagnosticsOnWrite: () => true,
getLspDiagnosticsOnEdit: () => false,
getEditFuzzyMatch: () => true,
getBashInterceptorEnabled: () => true,
getBashInterceptorSimpleLsEnabled: () => true,
getBashInterceptorRules: () => [],
...overrides,
};
}
describe("createTools", () => {
it("creates all builtin tools by default", async () => {
const session = createTestSession();
const tools = await createTools(session);
const names = tools.map((t) => t.name);
// Core tools should always be present
expect(names).toContain("python");
expect(names).not.toContain("bash");
expect(names).toContain("calc");
expect(names).toContain("read");
expect(names).toContain("edit");
expect(names).toContain("write");
expect(names).toContain("grep");
expect(names).toContain("find");
expect(names).toContain("ls");
expect(names).toContain("lsp");
expect(names).toContain("notebook");
expect(names).toContain("task");
expect(names).toContain("todo_write");
expect(names).toContain("fetch");
expect(names).toContain("web_search");
});
it("includes bash and python when python mode is both", async () => {
const session = createTestSession({
settings: createBaseSettings({
getPythonToolMode: () => "both",
getPythonKernelMode: () => "session",
}),
});
const tools = await createTools(session);
const names = tools.map((t) => t.name);
expect(names).toContain("bash");
expect(names).toContain("python");
});
it("includes bash only when python mode is bash-only", async () => {
const session = createTestSession({
settings: createBaseSettings({
getPythonToolMode: () => "bash-only",
getPythonKernelMode: () => "session",
}),
});
const tools = await createTools(session);
const names = tools.map((t) => t.name);
expect(names).toContain("bash");
expect(names).not.toContain("python");
});
it("excludes lsp tool when session disables LSP", async () => {
const session = createTestSession({ enableLsp: false });
const tools = await createTools(session, ["read", "lsp", "write"]);
const names = tools.map((t) => t.name);
expect(names).toEqual(["read", "write"]);
});
it("excludes lsp tool when disabled", async () => {
const session = createTestSession({ enableLsp: false });
const tools = await createTools(session);
const names = tools.map((t) => t.name);
expect(names).not.toContain("lsp");
});
it("respects requested tool subset", async () => {
const session = createTestSession();
const tools = await createTools(session, ["read", "write"]);
const names = tools.map((t) => t.name);
expect(names).toEqual(["read", "write"]);
});
it("includes hidden tools when explicitly requested", async () => {
const session = createTestSession();
const tools = await createTools(session, ["report_finding"]);
const names = tools.map((t) => t.name);
expect(names).toEqual(["report_finding"]);
});
it("includes complete tool when required", async () => {
const session = createTestSession({ requireCompleteTool: true });
const tools = await createTools(session);
const names = tools.map((t) => t.name);
expect(names).toContain("complete");
});
it("excludes ask tool when hasUI is false", async () => {
const session = createTestSession({ hasUI: false });
const tools = await createTools(session);
const names = tools.map((t) => t.name);
expect(names).not.toContain("ask");
});
it("includes ask tool when hasUI is true", async () => {
const session = createTestSession({ hasUI: true });
const tools = await createTools(session);
const names = tools.map((t) => t.name);
expect(names).toContain("ask");
});
it("BUILTIN_TOOLS contains all expected tools", () => {
const expectedTools = [
"ask",
"bash",
"python",
"calc",
"ssh",
"edit",
"find",
"grep",
"ls",
"lsp",
"notebook",
"read",
"task",
"todo_write",
"fetch",
"web_search",
"write",
];
for (const tool of expectedTools) {
expect(BUILTIN_TOOLS).toHaveProperty(tool);
}
// Ensure we haven't missed any
expect(Object.keys(BUILTIN_TOOLS).sort()).toEqual(expectedTools.sort());
});
it("HIDDEN_TOOLS contains review tools", () => {
expect(Object.keys(HIDDEN_TOOLS).sort()).toEqual(["complete", "report_finding"]);
});
});