package codex import ( "encoding/json" "slices" "strings" "testing" "amadan.net/oficina/equipo/internal/runner/provider" ) // TestThinActionPolicies: the thin runner's coordinator (converse), Review // (inspect) and ask-the-implementer (answer) profiles render a Codex // policy, and the deny profile holds for each: network off, credential // and runner paths denied, the workspace read-only, the coordinator with // no shell, no patch and exactly its Equipo tools enabled. func TestThinActionPolicies(t *testing.T) { b := provider.Binding{Provider: "codex", CredentialHome: "/private/account", Home: "/private/run", RuntimeRoot: "/private/runtime"} for _, action := range []string{"converse", "inspect", "answer"} { t.Run(action, func(t *testing.T) { profile, _ := provider.Profile(action) in := provider.PolicyInputs{Action: action, Tools: profile.MCPTools(), DeniedPaths: []string{"/private/state"}} got, err := PolicyInputs(b, in, "gpt-6-astra") if err != nil { t.Fatalf("%s refused: %v", action, err) } var settings map[string]any if json.Unmarshal(got.Settings, &settings) != nil { t.Fatal("invalid settings") } perm := settings["permissions"].(map[string]any)["equipo"].(map[string]any) fs := perm["filesystem"].(map[string]any) if fs["/workspace"] != "read" { t.Fatalf("%s: workspace %v", action, fs["/workspace"]) } for _, denied := range []string{"/private/account", "/private/run", "/private/state", "/home/runner", "/tool", "/egress", "/config", "/proc"} { if fs[denied] != "deny" { t.Fatalf("%s: %s not denied", action, denied) } } if perm["network"].(map[string]any)["enabled"] != false { t.Fatalf("%s: network on", action) } features := settings["features"].(map[string]any) for _, off := range []string{"apps", "multi_agent", "remote_control", "memories", "plugins", "code_mode"} { if features[off] != false { t.Fatalf("%s: feature %s not off", action, off) } } server := settings["mcp_servers"].(map[string]any)["equipo"].(map[string]any) if action == "converse" { for _, off := range []string{"shell_tool", "unified_exec", "apply_patch_freeform", "web_search", "js_repl", "view_image"} { if features[off] != false { t.Fatalf("coordinator feature %s not off", off) } } var enabled []string raw, _ := json.Marshal(server["enabled_tools"]) json.Unmarshal(raw, &enabled) if !slices.Equal(enabled, provider.ConverseTools()) { t.Fatalf("coordinator tools %v", enabled) } if !strings.Contains(string(got.Catalog), `"shell_type":"disabled"`) || !strings.Contains(string(got.Catalog), `"apply_patch_tool_type":null`) { t.Fatalf("coordinator catalog %s", got.Catalog) } } // The inventory is exactly the profile's: one more tool, or one // from another profile, is refused. for _, extra := range []string{"mcp__equipo__submit_candidate", "mcp__equipo__start_task", "mcp__equipo__git_show"} { more := in more.Tools = append(append([]string{}, in.Tools...), extra) if _, err := PolicyInputs(b, more, "gpt-6-astra"); err == nil { t.Fatalf("%s accepted %s", action, extra) } } }) } }