| 1 | package codex |
| 2 | |
| 3 | import ( |
| 4 | "amadan.net/oficina/equipo/internal/runner/provider" |
| 5 | "encoding/json" |
| 6 | "os" |
| 7 | "testing" |
| 8 | ) |
| 9 | |
| 10 | func TestSpecialistCatalogAuthority(t *testing.T) { |
| 11 | for _, mutation := range []string{"bytes", "code_mode", "collaboration", "template", "question"} { |
| 12 | t.Run(mutation, func(t *testing.T) { |
| 13 | f := fixtureFor(t) |
| 14 | in := f.inputs |
| 15 | in.Action = "implement" |
| 16 | profile, _ := provider.Profile(in.Action) |
| 17 | in.Tools = profile.MCPTools() |
| 18 | in, err := PolicyInputs(f.lease.Binding(), in, "gpt-6-astra") |
| 19 | if err != nil { |
| 20 | t.Fatal(err) |
| 21 | } |
| 22 | if mutation == "question" { |
| 23 | var settings map[string]any |
| 24 | _ = json.Unmarshal(in.Settings, &settings) |
| 25 | settings["tools"].(map[string]any)["experimental_request_user_input"] = map[string]any{"enabled": true} |
| 26 | in.Settings = marshal(settings) |
| 27 | } else if mutation != "bytes" { |
| 28 | var catalog struct{ Models []map[string]any } |
| 29 | if json.Unmarshal(in.Catalog, &catalog) != nil { |
| 30 | t.Fatal("catalog") |
| 31 | } |
| 32 | switch mutation { |
| 33 | case "code_mode": |
| 34 | catalog.Models[0]["tool_mode"] = "code_mode_only" |
| 35 | case "collaboration": |
| 36 | catalog.Models[0]["multi_agent_version"] = "v2" |
| 37 | case "template": |
| 38 | catalog.Models[0]["model_messages"] = map[string]string{"instructions_template": "changed"} |
| 39 | } |
| 40 | in.Catalog = marshal(catalog) |
| 41 | } |
| 42 | p, err := provider.BuildPolicy(f.lease.Binding(), in) |
| 43 | if err != nil { |
| 44 | t.Fatal(err) |
| 45 | } |
| 46 | if mutation == "bytes" { |
| 47 | if _, err = f.l.validatePolicy(f.lease.Binding(), p); err != nil { |
| 48 | t.Fatal(err) |
| 49 | } |
| 50 | for _, mount := range p.Mounts { |
| 51 | if mount.Target == provider.CoordinatorCatalogPath { |
| 52 | if err = os.WriteFile(mount.Source, []byte(`{"models":[]}`), 0600); err != nil { |
| 53 | t.Fatal(err) |
| 54 | } |
| 55 | } |
| 56 | } |
| 57 | if p.ValidateSources(f.lease.Binding()) == nil { |
| 58 | t.Fatal("changed mounted bytes accepted") |
| 59 | } |
| 60 | } else if _, err = f.l.validatePolicy(f.lease.Binding(), p); err == nil { |
| 61 | t.Fatal("changed constructor catalog accepted") |
| 62 | } |
| 63 | }) |
| 64 | } |
| 65 | } |
| 66 | |