fix: add parameter validation to all tools to prevent undefined insertions (#14)
Co-authored-by: Letta <noreply@letta.com>
This commit is contained in:
@@ -65,4 +65,50 @@ describe("Edit tool", () => {
|
||||
expect(readFileSync(file, "utf-8")).toBe("qux bar qux baz qux");
|
||||
expect(result.replacements).toBe(3);
|
||||
});
|
||||
|
||||
test("throws error when file_path is missing", async () => {
|
||||
await expect(
|
||||
edit({
|
||||
old_string: "foo",
|
||||
new_string: "bar",
|
||||
} as any),
|
||||
).rejects.toThrow(/missing required parameter.*file_path/);
|
||||
});
|
||||
|
||||
test("throws error when old_string is missing", async () => {
|
||||
testDir = new TestDirectory();
|
||||
const file = testDir.createFile("test.txt", "Hello, World!");
|
||||
|
||||
await expect(
|
||||
edit({
|
||||
file_path: file,
|
||||
new_string: "bar",
|
||||
} as any),
|
||||
).rejects.toThrow(/missing required parameter.*old_string/);
|
||||
});
|
||||
|
||||
test("throws error when new_string is missing", async () => {
|
||||
testDir = new TestDirectory();
|
||||
const file = testDir.createFile("test.txt", "Hello, World!");
|
||||
|
||||
await expect(
|
||||
edit({
|
||||
file_path: file,
|
||||
old_string: "foo",
|
||||
} as any),
|
||||
).rejects.toThrow(/missing required parameter.*new_string/);
|
||||
});
|
||||
|
||||
test("throws error when using typo'd parameter name (new_str instead of new_string)", async () => {
|
||||
testDir = new TestDirectory();
|
||||
const file = testDir.createFile("test.txt", "Hello, World!");
|
||||
|
||||
await expect(
|
||||
edit({
|
||||
file_path: file,
|
||||
old_string: "World",
|
||||
new_str: "Bun",
|
||||
} as any),
|
||||
).rejects.toThrow(/missing required parameter.*new_string/);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user