Files
oh-my-pi/packages/coding-agent/test/tools/grep-invalid-regex.test.ts
T
can1357 ae1650d689 refactor: renamed search and find tools to grep and glob
- Renamed the `find` and `search` tools to `glob` and `grep` respectively across the codebase to improve command clarity.
- Implemented full-stack support for the renamed tools, including CLI arguments, system prompts, SDK exports, and tool registration.
- Added automated migration logic in `settings` to transform legacy `find` and `search` configuration keys to their new equivalents.
- Updated the `collab-web` renderer registry to ensure backwards compatibility with legacy tool outputs.
2026-06-27 00:57:55 +02:00

49 lines
1.3 KiB
TypeScript

import { afterEach, beforeEach, describe, expect, it } from "bun:test";
import * as fs from "node:fs/promises";
import * as os from "node:os";
import * as path from "node:path";
import { Settings } from "@oh-my-pi/pi-coding-agent/config/settings";
import { GrepTool, type ToolSession } from "@oh-my-pi/pi-coding-agent/tools";
import { ToolError } from "@oh-my-pi/pi-coding-agent/tools/tool-errors";
function createTestSession(cwd: string, overrides: Partial<ToolSession> = {}): ToolSession {
return {
cwd,
hasUI: false,
getSessionFile: () => null,
getSessionSpawns: () => "*",
settings: Settings.isolated(),
...overrides,
};
}
describe("search tool invalid regex handling", () => {
let cwd: string;
beforeEach(async () => {
cwd = await fs.mkdtemp(path.join(os.tmpdir(), "pi-search-invalid-regex-"));
await Bun.write(path.join(cwd, "sample.txt"), "hello world\n");
});
afterEach(async () => {
await fs.rm(cwd, { recursive: true, force: true });
});
it("wraps invalid regex pattern errors in a ToolError", async () => {
const tool = new GrepTool(createTestSession(cwd));
let caught: unknown;
try {
await tool.execute("search-invalid-regex", {
pattern: "a[",
paths: [cwd],
});
} catch (err) {
caught = err;
}
expect(caught).toBeInstanceOf(ToolError);
expect((caught as Error).message).toMatch(/regex/i);
});
});