@agnishc/edb-gemini-proxy 0.10.8 → 0.10.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -0
- package/package.json +1 -1
- package/src/format.test.ts +73 -0
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import * as os from "node:os";
|
|
2
|
+
import { describe, expect, it } from "vitest";
|
|
3
|
+
import { formatToolCall } from "./format.js";
|
|
4
|
+
|
|
5
|
+
const HOME = os.homedir();
|
|
6
|
+
|
|
7
|
+
describe("formatToolCall", () => {
|
|
8
|
+
it("formats read_file", () => {
|
|
9
|
+
expect(formatToolCall("read_file", { path: "/tmp/foo.ts" })).toBe("read /tmp/foo.ts");
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
it("shortens home paths", () => {
|
|
13
|
+
const userPath = `${HOME}/project/src/index.ts`;
|
|
14
|
+
expect(formatToolCall("read_file", { path: userPath })).toBe(`read ~${userPath.slice(HOME.length)}`);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it("formats write_file", () => {
|
|
18
|
+
expect(formatToolCall("write_file", { path: "/tmp/foo.ts" })).toBe("write file /tmp/foo.ts");
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it("formats edit_file", () => {
|
|
22
|
+
expect(formatToolCall("edit_file", { path: "/tmp/foo.ts" })).toBe("edit file /tmp/foo.ts");
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it("formats run_shell_command with truncation", () => {
|
|
26
|
+
const longCmd = `echo ${"x".repeat(80)}`;
|
|
27
|
+
const result = formatToolCall("run_shell_command", { command: longCmd });
|
|
28
|
+
expect(result.startsWith("$")).toBe(true);
|
|
29
|
+
expect(result.endsWith("…")).toBe(true);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it("formats short shell commands", () => {
|
|
33
|
+
expect(formatToolCall("run_shell_command", { command: "ls -la" })).toBe("$ ls -la");
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it("formats list_directory", () => {
|
|
37
|
+
expect(formatToolCall("list_directory", { path: "/tmp" })).toBe("ls /tmp");
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it("formats list_directory with default path", () => {
|
|
41
|
+
expect(formatToolCall("list_directory", {})).toBe("ls .");
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it("formats grep_search with pattern", () => {
|
|
45
|
+
expect(formatToolCall("grep_search", { pattern: "TODO" })).toBe("grep TODO");
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it("truncates long grep patterns", () => {
|
|
49
|
+
const longPattern = "x".repeat(50);
|
|
50
|
+
const result = formatToolCall("grep_search", { pattern: longPattern });
|
|
51
|
+
expect(result.startsWith("grep ")).toBe(true);
|
|
52
|
+
expect(result.endsWith("…")).toBe(true);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it("formats web_search", () => {
|
|
56
|
+
expect(formatToolCall("web_search", { query: "how to code" })).toBe("search: how to code");
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it("truncates long search queries", () => {
|
|
60
|
+
const longQuery = "x".repeat(80);
|
|
61
|
+
const result = formatToolCall("web_search", { query: longQuery });
|
|
62
|
+
expect(result.startsWith("search: ")).toBe(true);
|
|
63
|
+
expect(result.length).toBeLessThan(65);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it("falls back to JSON for unknown tools", () => {
|
|
67
|
+
expect(formatToolCall("unknown_tool", { key: "val" })).toBe('unknown_tool {"key":"val"}');
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it("handles missing params gracefully", () => {
|
|
71
|
+
expect(formatToolCall("read_file", {})).toBe("read ...");
|
|
72
|
+
});
|
|
73
|
+
});
|