package runner import ( "encoding/json" "os" "path/filepath" "slices" "testing" "amadan.net/oficina/equipo/internal/runner/provider" ) // A token connection's home, where its token rests, is denied to every // launch's policy (the model's own and every other connection's), like // any dedicated home; the bindings file accepts kind token for Claude // only; and its launches stage it as a token home. func TestTokenBinding(t *testing.T) { c := configFixture(t) root := filepath.Dir(c.StateDir) identity := provider.Identity{AccountID: "t@example.com", HomeID: "h1", ProviderVersion: provider.ClaudeVersion} token := AccountBinding{ID: "claude-2", LocalID: "claude-2", PersonID: "p@example.com", Provider: "claude", Family: "claude", Model: "claude-opus-5-5", AccountID: "t@example.com", ProviderHome: filepath.Join(root, "accounts", "claude-2"), Kind: "token", ExpectedIdentity: identity} other := token other.ID, other.LocalID, other.AccountID, other.ProviderHome, other.Kind = "claude-1", "claude-1", "o@example.com", filepath.Join(root, "accounts", "claude-1"), "subscription" other.ExpectedIdentity = provider.Identity{AccountID: "o@example.com", HomeID: "h2", ProviderVersion: provider.ClaudeVersion} bs := []AccountBinding{other, token} for _, b := range bs { policy, err := bindingPolicy(c, bs, b) if err != nil || !slices.Contains(policy.DeniedPaths, token.ProviderHome) { t.Fatalf("the token home is not denied to %s: %v", b.ID, err) } } write := func(bs []AccountBinding) { raw, _ := json.Marshal(bs) if err := os.WriteFile(c.AccountBindingsPath, raw, 0600); err != nil { t.Fatal(err) } } write(bs) if got, err := loadDirectBindings(c.AccountBindingsPath); err != nil || len(got) != 2 { t.Fatalf("token binding refused: %v", err) } codex := token codex.Provider, codex.Family = "codex", "gpt" write([]AccountBinding{codex}) if _, err := loadDirectBindings(c.AccountBindingsPath); err == nil { t.Fatal("a Codex token binding was accepted") } direct, err := c.DirectBinding(token) if err != nil || !direct.Token { t.Fatalf("a token binding stages as a login home: %v", err) } if direct, _ = c.DirectBinding(other); direct.Token { t.Fatal("a login binding stages as a token home") } }