| 1 | package codex |
| 2 | |
| 3 | import ( |
| 4 | "encoding/json" |
| 5 | "os" |
| 6 | "strings" |
| 7 | "testing" |
| 8 | |
| 9 | "amadan.net/oficina/equipo/internal/runner/provider" |
| 10 | ) |
| 11 | |
| 12 | func TestCodexRuntimeSettings(t *testing.T) { |
| 13 | for _, action := range []string{"implement", "coordinate"} { |
| 14 | t.Run(action, func(t *testing.T) { |
| 15 | f := fixtureFor(t) |
| 16 | in := f.inputs |
| 17 | in.Action = action |
| 18 | profile, _ := provider.Profile(action) |
| 19 | in.Tools = profile.MCPTools() |
| 20 | in, err := PolicyInputs(f.lease.Binding(), in, f.launch.Selection.Model) |
| 21 | if err != nil { |
| 22 | t.Fatal(err) |
| 23 | } |
| 24 | if !configSubset([]byte(`{"skills":{"bundled":{"enabled":false}},"features":{"memories":false,"goals":false,"plugins":false,"remote_plugin":false,"tool_suggest":false}}`), in.Settings) { |
| 25 | t.Fatal("skills or memories not disabled") |
| 26 | } |
| 27 | if !strings.Contains(strings.Join(in.Argv, " "), `skills={"bundled"={"enabled"=false}}`) { |
| 28 | t.Fatal("skills missing from argv") |
| 29 | } |
| 30 | p, err := provider.BuildPolicy(f.lease.Binding(), in) |
| 31 | if err != nil { |
| 32 | t.Fatal(err) |
| 33 | } |
| 34 | for _, key := range []string{"skills", "memories", "goals", "plugins", "remote_plugin", "tool_suggest"} { |
| 35 | t.Run(key, func(t *testing.T) { |
| 36 | var got map[string]any |
| 37 | json.Unmarshal(in.Settings, &got) |
| 38 | if key == "skills" { |
| 39 | got[key].(map[string]any)["bundled"].(map[string]any)["enabled"] = true |
| 40 | } else { |
| 41 | got["features"].(map[string]any)[key] = true |
| 42 | } |
| 43 | readback := marshal(map[string]any{"config": got, "origins": map[string]any{}, "layers": []any{map[string]any{"name": map[string]any{"type": "sessionFlags"}, "version": "fixture", "config": json.RawMessage(in.Settings)}}}) |
| 44 | if validateConfig(readback, p) == nil { |
| 45 | t.Fatal("enabled capability accepted") |
| 46 | } |
| 47 | }) |
| 48 | } |
| 49 | }) |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | func TestCodexRecordedDisabledRuntime(t *testing.T) { |
| 54 | raw, err := os.ReadFile("testdata/disabled-skills-0.165.0.json") |
| 55 | if err != nil { |
| 56 | t.Fatal(err) |
| 57 | } |
| 58 | var frames []struct { |
| 59 | ID int |
| 60 | Result json.RawMessage |
| 61 | } |
| 62 | if err = json.Unmarshal(raw, &frames); err != nil { |
| 63 | t.Fatal(err) |
| 64 | } |
| 65 | if len(frames) != 4 { |
| 66 | t.Fatal("incomplete recording") |
| 67 | } |
| 68 | if !configSubset([]byte(`{"account":null,"requiresOpenaiAuth":true}`), frames[1].Result) { |
| 69 | t.Fatal("recording is not unauthenticated") |
| 70 | } |
| 71 | if !configSubset([]byte(`{"config":{"skills":{"bundled":{"enabled":false}},"features":{"memories":false}}}`), frames[2].Result) { |
| 72 | t.Fatal("disabled config not recorded") |
| 73 | } |
| 74 | if !sameJSON(frames[3].Result, []byte(`{"data":[{"cwd":"/workspace","skills":[],"errors":[]}]}`)) { |
| 75 | t.Fatal("skills exposed") |
| 76 | } |
| 77 | } |
| 78 | |