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,43 @@
import { afterEach, describe, expect, test } from "bun:test";
import { readFileSync } from "node:fs";
import { multi_edit } from "../../tools/impl/MultiEdit";
import { TestDirectory } from "../helpers/testFs";
describe("MultiEdit tool", () => {
let testDir: TestDirectory;
afterEach(() => {
testDir?.cleanup();
});
test("applies multiple edits to a file", async () => {
testDir = new TestDirectory();
const file = testDir.createFile("test.txt", "foo bar baz");
await multi_edit({
file_path: file,
edits: [
{ old_string: "foo", new_string: "FOO" },
{ old_string: "bar", new_string: "BAR" },
],
});
expect(readFileSync(file, "utf-8")).toBe("FOO BAR baz");
});
test("applies edits sequentially", async () => {
testDir = new TestDirectory();
const file = testDir.createFile("test.txt", "aaa bbb");
const result = await multi_edit({
file_path: file,
edits: [
{ old_string: "aaa", new_string: "xxx" },
{ old_string: "bbb", new_string: "yyy" },
],
});
expect(readFileSync(file, "utf-8")).toBe("xxx yyy");
expect(result.edits_applied).toBe(2);
});
});