| 1 | import { describe, it, expect } from "vitest"; |
| 2 | |
| 3 | import { DEFAULT_TOOL_POLICIES } from "./defaultPolicies.js"; |
| 4 | |
| 5 | describe("defaultPolicies", () => { |
| 6 | it("should have correct permissions for read-only tools", () => { |
| 7 | const readOnlyTools = [ |
| 8 | "Read", |
| 9 | "List", |
| 10 | "Search", |
| 11 | "Fetch", |
| 12 | "Exit", |
| 13 | "Diff", |
| 14 | "Checklist", |
| 15 | ]; |
| 16 | |
| 17 | for (const tool of readOnlyTools) { |
| 18 | const policy = DEFAULT_TOOL_POLICIES.find((p) => p.tool === tool); |
| 19 | expect(policy, `Policy should exist for ${tool}`).toBeDefined(); |
| 20 | expect(policy?.permission, `${tool} should be allowed`).toBe("allow"); |
| 21 | } |
| 22 | }); |
| 23 | |
| 24 | it("should have correct permissions for write tools", () => { |
| 25 | const writeTools = ["Write", "Edit", "MultiEdit", "Bash"]; |
| 26 | |
| 27 | for (const tool of writeTools) { |
| 28 | const policy = DEFAULT_TOOL_POLICIES.find((p) => p.tool === tool); |
| 29 | expect(policy, `Policy should exist for ${tool}`).toBeDefined(); |
| 30 | expect(policy?.permission, `${tool} should require confirmation`).toBe( |
| 31 | "ask", |
| 32 | ); |
| 33 | } |
| 34 | }); |
| 35 | |
| 36 | it("should have a catch-all policy", () => { |
| 37 | const catchAllPolicy = DEFAULT_TOOL_POLICIES.find((p) => p.tool === "*"); |
| 38 | expect(catchAllPolicy).toBeDefined(); |
| 39 | expect(catchAllPolicy?.permission).toBe("ask"); |
| 40 | }); |
| 41 | |
| 42 | it("should include MultiEdit policy", () => { |
| 43 | const multiEditPolicy = DEFAULT_TOOL_POLICIES.find( |
| 44 | (p) => p.tool === "MultiEdit", |
| 45 | ); |
| 46 | expect(multiEditPolicy).toBeDefined(); |
| 47 | expect(multiEditPolicy?.permission).toBe("ask"); |
| 48 | }); |
| 49 | |
| 50 | it("should have policies in correct order", () => { |
| 51 | // The catch-all policy should be last |
| 52 | const catchAllIndex = DEFAULT_TOOL_POLICIES.findIndex( |
| 53 | (p) => p.tool === "*", |
| 54 | ); |
| 55 | expect(catchAllIndex).toBe(DEFAULT_TOOL_POLICIES.length - 1); |
| 56 | }); |
| 57 | }); |