Elffuss BraidHub

kikocis/continue public

main · 2.2 KiBRawPermalink
1import { generatePolicyRule } from "./policyWriter.js";
2
3describe("policyWriter", () => {
4 describe("generatePolicyRule", () => {
5 it("should return display name for regular tools", () => {
6 expect(generatePolicyRule("Read", { file_path: "/test" })).toBe("Read");
7 expect(
8 generatePolicyRule("Write", { file_path: "/test", content: "test" }),
9 ).toBe("Write");
10 expect(generatePolicyRule("List", { path: "/test" })).toBe("List");
11 expect(generatePolicyRule("Search", { pattern: "test" })).toBe("Search");
12 expect(generatePolicyRule("Grep", { pattern: "test" })).toBe("Grep"); // Unknown tool, passes through
13 });
14
15 it("should generate command-specific patterns for Bash tool", () => {
16 expect(generatePolicyRule("Bash", { command: "ls -la" })).toBe(
17 "Bash(ls*)",
18 );
19 expect(generatePolicyRule("Bash", { command: "git status" })).toBe(
20 "Bash(git*)",
21 );
22 expect(generatePolicyRule("Bash", { command: "npm install" })).toBe(
23 "Bash(npm*)",
24 );
25 });
26
27 it("should handle complex bash commands", () => {
28 expect(
29 generatePolicyRule("Bash", { command: "ls -la && echo test" }),
30 ).toBe("Bash(ls*)");
31 expect(
32 generatePolicyRule("Bash", {
33 command: "find . -name '*.ts' | head -10",
34 }),
35 ).toBe("Bash(find*)");
36 expect(
37 generatePolicyRule("Bash", { command: " grep -r test . " }),
38 ).toBe("Bash(grep*)");
39 });
40
41 it("should fallback to display name for bash tools without command", () => {
42 expect(generatePolicyRule("Bash", {})).toBe("Bash");
43 expect(generatePolicyRule("Bash", { command: "" })).toBe("Bash");
44 expect(generatePolicyRule("Bash", { command: " " })).toBe("Bash");
45 });
46
47 it("should use exact tool names without normalization", () => {
48 expect(generatePolicyRule("bash", { command: "ls" })).toBe("bash");
49 expect(generatePolicyRule("BASH", { command: "pwd" })).toBe("BASH");
50 expect(generatePolicyRule("read", { file_path: "/test" })).toBe("read");
51 expect(
52 generatePolicyRule("write", { file_path: "/test", content: "test" }),
53 ).toBe("write");
54 });
55 });
56});