package provider import ( "context" "encoding/json" "errors" "os" "path/filepath" "strings" "testing" ) func TestAccountContainmentDiagnostics(t *testing.T) { for _, kind := range []string{"runtime-credential", "source-identity", "runtime-directory", "runtime-policy", "runtime-entry"} { t.Run(kind, func(t *testing.T) { b, r := accountFixture(t) l := openFixture(t, b, r) preflightFixture(t, l) want := "" switch kind { case "runtime-credential": if err := os.Chmod(filepath.Join(l.runtime, "auth.json"), 0644); err != nil { t.Fatal(err) } want = "runtime_credential" case "source-identity": if err := os.Chmod(filepath.Join(b.Home, IdentityFile), 0644); err != nil { t.Fatal(err) } want = "source_identity_file" case "runtime-directory": if err := os.Chmod(l.runtime, 0755); err != nil { t.Fatal(err) } defer os.Chmod(l.runtime, 0700) want = "runtime_directory" case "runtime-policy": if err := os.Mkdir(filepath.Join(l.runtime, "skills"), 0700); err != nil { t.Fatal(err) } want = "runtime_codex_skills" case "runtime-entry": writeFake(t, filepath.Join(l.runtime, "secret-sentinel"), "secret-sentinel") want = "runtime_unexpected_entry" } err := l.ValidatePolicy(context.Background()) if !errors.Is(err, ErrContainment) || !strings.Contains(err.Error(), want) || strings.Contains(err.Error(), "secret-sentinel") { t.Fatalf("opaque or unsafe diagnostic: %v", err) } }) } } // Replay only names and file kinds from the empty-home probe. No bundled // skill text or SQLite contents are needed to exercise the guard. func TestAccountRecordedCodexRuntimeRefused(t *testing.T) { raw, err := os.ReadFile("testdata/codex-empty-home-0.165.0.json") if err != nil { t.Fatal(err) } var inventory struct { Entries []struct { Path string Directory bool } } if err = json.Unmarshal(raw, &inventory); err != nil { t.Fatal(err) } b, r := accountFixture(t) l := openFixture(t, b, r) preflightFixture(t, l) for _, entry := range inventory.Entries { path := filepath.Join(l.runtime, entry.Path) if entry.Directory { err = os.MkdirAll(path, 0700) } else { err = os.WriteFile(path, []byte("fixture"), 0600) } if err != nil { t.Fatal(err) } } err = l.ValidatePolicy(context.Background()) if !errors.Is(err, ErrContainment) || !strings.Contains(err.Error(), "runtime_codex_plugins") { t.Fatalf("curated plugins not refused: %v", err) } }