| 1 | package codex |
| 2 | |
| 3 | import ( |
| 4 | "encoding/json" |
| 5 | "errors" |
| 6 | "slices" |
| 7 | "strings" |
| 8 | "testing" |
| 9 | |
| 10 | "amadan.net/oficina/equipo/internal/runner/provider" |
| 11 | ) |
| 12 | |
| 13 | // On Codex a glance gets the coordinator's surface with no Equipo tool |
| 14 | // enabled, its workspace read-only, the network off, and the small model |
| 15 | // (gpt-6-luna, the pinned 0.165.0 build's "fast and affordable" model in |
| 16 | // its bundled catalog) at low effort; any tool asked for is refused. |
| 17 | func TestGlanceLaunchCodexHasNoTools(t *testing.T) { |
| 18 | b := provider.Binding{Provider: "codex", CredentialHome: "/private/account", Home: "/private/run", RuntimeRoot: "/private/runtime"} |
| 19 | profile, err := provider.Profile(provider.GlanceAction) |
| 20 | if err != nil { |
| 21 | t.Fatal(err) |
| 22 | } |
| 23 | in := provider.PolicyInputs{Action: provider.GlanceAction, Tools: profile.MCPTools(), DeniedPaths: []string{"/private/state"}} |
| 24 | got, err := PolicyInputs(b, in, "gpt-6-astra") |
| 25 | if err != nil { |
| 26 | t.Fatal(err) |
| 27 | } |
| 28 | var settings map[string]any |
| 29 | if json.Unmarshal(got.Settings, &settings) != nil { |
| 30 | t.Fatal("settings") |
| 31 | } |
| 32 | if settings["model"] != GlanceModel || settings["web_search"] != "disabled" { |
| 33 | t.Fatalf("model %v web_search %v", settings["model"], settings["web_search"]) |
| 34 | } |
| 35 | perm := settings["permissions"].(map[string]any)["equipo"].(map[string]any) |
| 36 | if perm["network"].(map[string]any)["enabled"] != false || perm["filesystem"].(map[string]any)["/workspace"] != "read" { |
| 37 | t.Fatalf("permissions %v", perm) |
| 38 | } |
| 39 | server := settings["mcp_servers"].(map[string]any)["equipo"].(map[string]any) |
| 40 | if raw, _ := json.Marshal(server["enabled_tools"]); string(raw) != `[]` { |
| 41 | t.Fatalf("enabled tools %s", raw) |
| 42 | } |
| 43 | features := settings["features"].(map[string]any) |
| 44 | for _, off := range []string{"shell_tool", "unified_exec", "apply_patch_freeform", "web_search", "code_mode", "plugins"} { |
| 45 | if features[off] != false { |
| 46 | t.Fatalf("feature %s %v", off, features[off]) |
| 47 | } |
| 48 | } |
| 49 | if !slices.Equal(got.NativeTools, provider.CoordinatorNativeTools("codex")) { |
| 50 | t.Fatalf("native tools %v", got.NativeTools) |
| 51 | } |
| 52 | if !strings.Contains(string(got.Catalog), `"slug":"`+GlanceModel+`"`) || !strings.Contains(string(got.Catalog), `"shell_type":"disabled"`) { |
| 53 | t.Fatalf("catalog %s", got.Catalog) |
| 54 | } |
| 55 | var thread struct{ Model string } |
| 56 | if json.Unmarshal(got.ThreadPolicy, &thread) != nil || thread.Model != GlanceModel { |
| 57 | t.Fatalf("thread %s", got.ThreadPolicy) |
| 58 | } |
| 59 | var params map[string]any |
| 60 | if json.Unmarshal(TurnParams(provider.Policy{TurnPolicy: got.TurnPolicy}, "th", "hi"), ¶ms) != nil || params["effort"] != "low" { |
| 61 | t.Fatalf("turn %v", params) |
| 62 | } |
| 63 | // Validation renders the policy again from its manifest, where no |
| 64 | // tools read back as null: the same glance, accepted. |
| 65 | back := in |
| 66 | back.Tools = nil |
| 67 | if again, err := PolicyInputs(b, back, GlanceModel); err != nil || !sameJSON(again.Settings, got.Settings) || !sameJSON(again.ThreadPolicy, got.ThreadPolicy) { |
| 68 | t.Fatalf("a glance read back from its manifest: %v", err) |
| 69 | } |
| 70 | for _, tool := range []string{"mcp__equipo__ask_person", "mcp__equipo__look", "mcp__equipo__submit_findings", "mcp__equipo__git_show"} { |
| 71 | more := in |
| 72 | more.Tools = []string{tool} |
| 73 | if _, err := PolicyInputs(b, more, "gpt-6-astra"); !errors.Is(err, provider.ErrPolicy) { |
| 74 | t.Fatalf("a glance with %s: %v", tool, err) |
| 75 | } |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | // Only the glance runs gpt-6-luna; every other action keeps the |
| 80 | // connection's model. |
| 81 | func TestOnlyGlanceUsesTheSmallModelCodex(t *testing.T) { |
| 82 | if GlanceModel != "gpt-6-luna" || provider.GlanceModel("codex") != GlanceModel { |
| 83 | t.Fatalf("glance model %q", GlanceModel) |
| 84 | } |
| 85 | b := provider.Binding{Provider: "codex", CredentialHome: "/private/account", Home: "/private/run", RuntimeRoot: "/private/runtime"} |
| 86 | for _, action := range []string{"coordinate", "converse", "assist", "implement", "inspect", "review", provider.ResearchStepAction, "answer", provider.GlanceAction} { |
| 87 | profile, err := provider.Profile(action) |
| 88 | if err != nil { |
| 89 | t.Fatal(err) |
| 90 | } |
| 91 | got, err := PolicyInputs(b, provider.PolicyInputs{Action: action, Tools: profile.MCPTools(), DeniedPaths: []string{"/private/state"}}, "gpt-6-astra") |
| 92 | if err != nil { |
| 93 | t.Fatalf("%s: %v", action, err) |
| 94 | } |
| 95 | var settings struct{ Model string } |
| 96 | json.Unmarshal(got.Settings, &settings) |
| 97 | want := "gpt-6-astra" |
| 98 | if action == provider.GlanceAction { |
| 99 | want = GlanceModel |
| 100 | } |
| 101 | if settings.Model != want { |
| 102 | t.Fatalf("%s runs %s", action, settings.Model) |
| 103 | } |
| 104 | } |
| 105 | } |
| 106 | |