Elffuss BraidHub

kikocis/continue public

main · 2.2 KiBRawPermalink
1import { describe, it, expect, beforeEach, vi } from "vitest";
2
3import { checkToolPermission } from "./permissionChecker.js";
4import { yamlConfigToPolicies } from "./permissionsYamlLoader.js";
5
6// Mock fs module
7vi.mock("fs");
8
9describe("YAML Permissions - Edit Tool Bug", () => {
10 beforeEach(() => {
11 vi.clearAllMocks();
12 });
13
14 it("should allow Edit tool when it is in the allow list", () => {
15 // Test the exact YAML content from the user
16 const yamlContent = `allow:
17 - Edit
18ask: []
19exclude: []`;
20
21 // Parse the YAML config
22 const config = {
23 allow: ["Edit"],
24 ask: [],
25 exclude: [],
26 };
27
28 // Convert to policies
29 const policies = yamlConfigToPolicies(config);
30 console.log("Converted policies:", policies);
31
32 // The policies should have Edit as allowed
33 expect(policies).toEqual([{ tool: "Edit", permission: "allow" }]);
34
35 // Test permission check with tool call named "Edit"
36 const toolCall1 = {
37 name: "Edit",
38 arguments: { filepath: "test.txt" },
39 };
40 const result1 = checkToolPermission(toolCall1, { policies });
41 console.log('Permission check for "Edit":', result1);
42 expect(result1.permission).toBe("allow");
43
44 // Legacy names should NOT work anymore
45 const toolCall2 = {
46 name: "search_and_replace_in_file",
47 arguments: { filepath: "test.txt" },
48 };
49 const result2 = checkToolPermission(toolCall2, { policies });
50 console.log('Permission check for "search_and_replace_in_file":', result2);
51 expect(result2.permission).toBe("ask"); // Should not match, falls back to ask
52
53 // Legacy names should NOT work anymore
54 const toolCall3 = {
55 name: "edit_file",
56 arguments: { filepath: "test.txt" },
57 };
58 const result3 = checkToolPermission(toolCall3, { policies });
59 console.log('Permission check for "edit_file":', result3);
60 expect(result3.permission).toBe("ask"); // Should not match, falls back to ask
61 });
62
63 it("should use exact tool names without normalization", () => {
64 // Tools are now used exactly as they are named, no normalization
65 const editName = "Edit";
66 const multiEditName = "MultiEdit";
67
68 expect(editName).toBe("Edit");
69 expect(multiEditName).toBe("MultiEdit");
70 });
71});