package thin import ( "context" "encoding/json" "os" "path/filepath" "testing" "time" "amadan.net/oficina/equipo/internal/runner/provider" ) // The log keeps a containment refusal's fixed category (2026-11-20: // production logged only provider_account_containment). func TestSanitizeKeepsContainmentReason(t *testing.T) { root := t.TempDir() home := filepath.Join(root, "claude-1") id := provider.Identity{AccountID: "token:claude-1", HomeID: "h", ProviderVersion: provider.ClaudeVersion} raw, _ := json.Marshal(id) if os.Mkdir(home, 0700) != nil || os.WriteFile(filepath.Join(home, provider.IdentityFile), raw, 0600) != nil || os.WriteFile(filepath.Join(home, provider.TokenFile), []byte("sk-ant-oat01-canary"), 0600) != nil { t.Fatal("home") } b := provider.Binding{ID: "claude-1", Home: home, AccountID: id.AccountID, Provider: "claude", Token: true, Expected: id, RuntimeRoot: filepath.Join(root, "homes")} l, err := provider.OpenRuntimeCopy(context.Background(), b, func(context.Context, provider.Binding) (provider.Identity, error) { return id, nil }, time.Second) if err != nil { t.Fatal(err) } defer l.Close() if err = os.WriteFile(filepath.Join(l.Binding().Home, provider.TokenFile), []byte("x"), 0600); err != nil { t.Fatal(err) } if got := sanitize(l.CheckCopy(context.Background())); got != "provider_account_containment: runtime_token_credential" { t.Fatalf("logged %q", got) } if got := sanitize(provider.ErrPolicy); got != "provider_policy_rejected" { t.Fatalf("logged %q", got) } }