package codex import ( "encoding/json" "os" "testing" "amadan.net/oficina/equipo/internal/runner/provider" ) func liveConfig(t *testing.T) (map[string]any, provider.Policy) { t.Helper() raw, err := os.ReadFile("testdata/live-config-0.165.0.json") if err != nil { t.Fatal(err) } var frame struct{ Result map[string]any } if err = json.Unmarshal(raw, &frame); err != nil { t.Fatal(err) } settings := marshal(frame.Result["layers"].([]any)[0].(map[string]any)["config"]) manifest := marshal(map[string]any{"Action": "coordinate", "ProviderVersion": Version}) return frame.Result, provider.Policy{Settings: settings, Manifest: manifest, ManifestHash: provider.ManifestDigest(manifest)} } func TestCodexLiveConfigReadback(t *testing.T) { v, p := liveConfig(t) if err := validateConfig(marshal(v), p); err != nil { t.Fatal(err) } } func TestCodexLiveConfigStrict(t *testing.T) { for _, mode := range []string{"enabled-tool", "unknown-tool", "missing-feature", "changed-approval", "changed-layer", "extra-server", "other-action", "other-version"} { t.Run(mode, func(t *testing.T) { v, p := liveConfig(t) cfg := v["config"].(map[string]any) switch mode { case "enabled-tool": cfg["tools"].(map[string]any)["update_plan"] = map[string]any{"enabled": true} case "unknown-tool": cfg["tools"].(map[string]any)["unknown"] = map[string]any{"enabled": false} case "missing-feature": delete(cfg["features"].(map[string]any), "shell_tool") case "changed-approval": cfg["approvals_reviewer"] = "auto_review" case "changed-layer": v["layers"].([]any)[0].(map[string]any)["config"].(map[string]any)["tools"].(map[string]any)["update_plan"] = map[string]any{"enabled": true} case "extra-server": cfg["mcp_servers"].(map[string]any)["other"] = map[string]any{} case "other-action", "other-version": m := map[string]any{"Action": "coordinate", "ProviderVersion": Version} if mode == "other-action" { m["Action"] = "implement" } else { m["ProviderVersion"] = "other" } p.Manifest = marshal(m) p.ManifestHash = provider.ManifestDigest(p.Manifest) } if validateConfig(marshal(v), p) == nil { t.Fatal("unsafe readback accepted") } }) } } func TestSpecialistQuestionReadback(t *testing.T) { for _, mode := range []string{"valid", "enabled-layer", "missing-layer", "enabled-effective", "default-mode", "other-version"} { t.Run(mode, func(t *testing.T) { v, p := liveConfig(t) layer := v["layers"].([]any)[0].(map[string]any)["config"].(map[string]any) tools := layer["tools"].(map[string]any) delete(tools, "update_plan") p.Settings = marshal(layer) p.Manifest = marshal(map[string]any{"Action": "implement", "ProviderVersion": Version}) cfg := v["config"].(map[string]any) switch mode { case "enabled-layer": tools["experimental_request_user_input"] = map[string]any{"enabled": true} case "missing-layer": delete(tools, "experimental_request_user_input") case "enabled-effective": cfg["tools"].(map[string]any)["experimental_request_user_input"] = map[string]any{"enabled": true} case "default-mode": cfg["features"].(map[string]any)["default_mode_request_user_input"] = true case "other-version": p.Manifest = marshal(map[string]any{"Action": "implement", "ProviderVersion": "other"}) } p.ManifestHash = provider.ManifestDigest(p.Manifest) if got := validateConfig(marshal(v), p); (got == nil) != (mode == "valid") { t.Fatalf("readback mode %s: %v", mode, got) } }) } }