feat: add more tests for tool built-ins (#5)

This commit is contained in:
Charles Packer
2025-10-25 11:33:30 -07:00
committed by GitHub
parent dd773bf285
commit da2c50cbeb
19 changed files with 792 additions and 1 deletions

View File

@@ -0,0 +1,59 @@
import { afterEach, describe, expect, test } from "bun:test";
import { grep } from "../../tools/impl/Grep";
import { TestDirectory } from "../helpers/testFs";
describe("Grep tool", () => {
let testDir: TestDirectory;
afterEach(() => {
testDir?.cleanup();
});
test("finds pattern in files (requires ripgrep)", async () => {
testDir = new TestDirectory();
testDir.createFile("test1.txt", "Hello World");
testDir.createFile("test2.txt", "Goodbye World");
testDir.createFile("test3.txt", "No match here");
try {
const result = await grep({
pattern: "World",
path: testDir.path,
output_mode: "files_with_matches",
});
expect(result.output).toContain("test1.txt");
expect(result.output).toContain("test2.txt");
expect(result.output).not.toContain("test3.txt");
} catch (error) {
// Ripgrep might not be available in test environment
if (error instanceof Error && error.message.includes("ENOENT")) {
console.log("Skipping grep test - ripgrep not available");
} else {
throw error;
}
}
});
test("case insensitive search with -i flag", async () => {
testDir = new TestDirectory();
testDir.createFile("test.txt", "Hello WORLD");
try {
const result = await grep({
pattern: "world",
path: testDir.path,
"-i": true,
output_mode: "content",
});
expect(result.output).toContain("WORLD");
} catch (error) {
if (error instanceof Error && error.message.includes("ENOENT")) {
console.log("Skipping grep test - ripgrep not available");
} else {
throw error;
}
}
});
});