| 1 | package claude |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "encoding/json" |
| 6 | "slices" |
| 7 | "testing" |
| 8 | |
| 9 | "amadan.net/oficina/equipo/internal/runner/provider" |
| 10 | ) |
| 11 | |
| 12 | func TestPlanWorkflowProviderPolicies(t *testing.T) { |
| 13 | for _, action := range []string{"coordinate", "scope", "recommend", "investigate", "implement", "copy", "design", "review"} { |
| 14 | profile, err := provider.Profile(action) |
| 15 | if err != nil { |
| 16 | t.Fatal(err) |
| 17 | } |
| 18 | in := provider.PolicyInputs{Action: action, Tools: profile.MCPTools()} |
| 19 | b := provider.Binding{Provider: "claude", CredentialHome: "/private/account", Home: "/private/run", RuntimeRoot: "/private/runtime"} |
| 20 | got, err := PolicyInputs(b, in, profile.Specialist, "model") |
| 21 | if err != nil { |
| 22 | t.Fatalf("%s: %v", action, err) |
| 23 | } |
| 24 | for _, name := range profile.MCPTools() { |
| 25 | if !slices.Contains(got.Tools, name) { |
| 26 | t.Fatalf("%s missing %s", action, name) |
| 27 | } |
| 28 | } |
| 29 | var settings map[string]any |
| 30 | if json.Unmarshal(got.Settings, &settings) != nil { |
| 31 | t.Fatal("invalid settings") |
| 32 | } |
| 33 | if (action == "coordinate" || action == "scope" || action == "recommend" || action == "investigate" || action == "review") && (slices.Contains(got.Tools, "Write") || slices.Contains(got.Tools, "Edit")) { |
| 34 | t.Fatal("read-only profile writes") |
| 35 | } |
| 36 | |
| 37 | in.Tools = append(in.Tools, "mcp__equipo__submit_review") |
| 38 | if _, err = PolicyInputs(b, in, profile.Specialist, "model"); err == nil { |
| 39 | t.Fatal("broadened inventory accepted") |
| 40 | } |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | func TestPlanWorkflowProviderPoliciesLauncher(t *testing.T) { |
| 45 | for _, action := range []string{"coordinate", "scope", "recommend", "investigate", "implement", "copy", "design", "review"} { |
| 46 | t.Run(action, func(t *testing.T) { |
| 47 | f := fixtureFor(t, "Engineering") |
| 48 | p, _ := provider.Profile(action) |
| 49 | in := f.inputs |
| 50 | in.Action = action |
| 51 | in.Tools = p.MCPTools() |
| 52 | var err error |
| 53 | in, err = PolicyInputs(f.lease.Binding(), in, p.Specialist, f.launch.Selection.Model) |
| 54 | if err != nil { |
| 55 | t.Fatal(err) |
| 56 | } |
| 57 | f.launch.Policy, err = provider.BuildPolicy(f.lease.Binding(), in) |
| 58 | if err != nil { |
| 59 | t.Fatal(err) |
| 60 | } |
| 61 | session, events := openFixture(t, f) |
| 62 | if err = f.l.StartTurn(context.Background(), session, provider.Turn{ID: "plan-turn", AdmissionID: "plan-admission", Prompt: "fixture"}); err != nil { |
| 63 | t.Fatal(err) |
| 64 | } |
| 65 | for e := range events { |
| 66 | if e.Kind == "turn.completed" { |
| 67 | break |
| 68 | } |
| 69 | if e.Kind == "turn.failed" { |
| 70 | t.Fatal("fixture failed") |
| 71 | } |
| 72 | } |
| 73 | if err = f.l.Close(context.Background(), session); err != nil { |
| 74 | t.Fatal(err) |
| 75 | } |
| 76 | }) |
| 77 | } |
| 78 | } |
| 79 | |