| 1 | package claude |
| 2 | |
| 3 | import ( |
| 4 | "encoding/json" |
| 5 | "slices" |
| 6 | "strings" |
| 7 | "testing" |
| 8 | |
| 9 | "amadan.net/oficina/equipo/internal/runner/provider" |
| 10 | ) |
| 11 | |
| 12 | // An answering session (ask the implementer) is read-only: Read, Glob |
| 13 | // and Grep, the runner's read-only git tools, a read-only workspace that |
| 14 | // settings also deny writing, no shell or write tool, and it streams. |
| 15 | func TestAnswerPolicyIsReadOnly(t *testing.T) { |
| 16 | profile, err := provider.Profile("answer") |
| 17 | if err != nil || !profile.ReadOnly || profile.Submission != "" { |
| 18 | t.Fatalf("profile %+v %v", profile, err) |
| 19 | } |
| 20 | in := provider.PolicyInputs{Action: "answer", Tools: profile.MCPTools()} |
| 21 | b := provider.Binding{Provider: "claude", CredentialHome: "/private/account", Home: "/private/run", RuntimeRoot: "/private/runtime"} |
| 22 | got, err := PolicyInputs(b, in, profile.Specialist, "model") |
| 23 | if err != nil { |
| 24 | t.Fatal(err) |
| 25 | } |
| 26 | want := []string{"Read", "Glob", "Grep", "mcp__equipo__permission", "mcp__equipo__git_log", "mcp__equipo__git_diff", "mcp__equipo__git_show"} |
| 27 | if !slices.Equal(got.Tools, want) { |
| 28 | t.Fatalf("tools %v, want %v", got.Tools, want) |
| 29 | } |
| 30 | argv := strings.Join(got.Argv, " ") |
| 31 | if !strings.Contains(argv, "--tools Read,Glob,Grep") || !strings.Contains(argv, "--include-partial-messages") { |
| 32 | t.Fatalf("argv %s", argv) |
| 33 | } |
| 34 | var settings struct { |
| 35 | Sandbox struct { |
| 36 | Filesystem struct { |
| 37 | DenyWrite []string `json:"denyWrite"` |
| 38 | } `json:"filesystem"` |
| 39 | } `json:"sandbox"` |
| 40 | Permissions struct { |
| 41 | Allow []string `json:"allow"` |
| 42 | } `json:"permissions"` |
| 43 | } |
| 44 | if err := json.Unmarshal(got.Settings, &settings); err != nil { |
| 45 | t.Fatal(err) |
| 46 | } |
| 47 | if !slices.Contains(settings.Sandbox.Filesystem.DenyWrite, "/workspace") { |
| 48 | t.Fatalf("workspace writable in settings: %v", settings.Sandbox.Filesystem.DenyWrite) |
| 49 | } |
| 50 | if !slices.Equal(settings.Permissions.Allow, profile.MCPTools()) { |
| 51 | t.Fatalf("allowed without a prompt: %v", settings.Permissions.Allow) |
| 52 | } |
| 53 | // Nothing else may be added: no submission, no question, no write. |
| 54 | for _, extra := range []string{"mcp__equipo__submit_candidate", "mcp__equipo__submit_review", "mcp__equipo__start_task"} { |
| 55 | in := provider.PolicyInputs{Action: "answer", Tools: append(profile.MCPTools(), extra)} |
| 56 | if _, err := PolicyInputs(b, in, profile.Specialist, "model"); err == nil { |
| 57 | t.Fatalf("answer accepted %s", extra) |
| 58 | } |
| 59 | } |
| 60 | if _, err := PolicyInputs(b, in, "Engineering", "model"); err == nil { |
| 61 | t.Fatal("answer ran as Engineering, with its write tools") |
| 62 | } |
| 63 | } |
| 64 | |