package thintest import ( "net/http" "net/url" "strings" "testing" "amadan.net/oficina/equipo/internal/wire" ) // The provider's email wins (token profile, 2026-11-12): a token row the // owner stated an email for, whose profile then names the account, shows // the provider's email as a plain label (the shared connection label: // no "(added by you)", not "signed in by link") on Connections and // Usage, and asks for none. The stated email stays stored: when the // provider stops naming the account, it shows as the owner's again. func TestPagesTokenProfileEmailWins(t *testing.T) { r, runner, token, _ := tokenRowRig(t) owner := r.inst.Cookie() const page = "/conversation/settings/connections" if status, _ := r.post(owner, "/conversation/connections/"+token+"/email", url.Values{"email": {"me@example.com"}}); status != http.StatusSeeOther { t.Fatalf("the owner's email: %d", status) } send := func(frame, label string) { t.Helper() hello := held(wire.HeldConnection{LocalID: "claude-9", Person: Owner, Provider: "claude", Kind: wire.KindToken, Label: label, State: wire.ConnHealthy}) hello.Generation = runner.Welcome.Generation if err := runner.Send(r.ctx, frame, wire.FrameHello, hello); err != nil { t.Fatal(err) } r.wait("the label "+label, func(c *Conversation) bool { return c.Connections[token].Label == label }) } send("h-named", "acct@example.com") row := rowHTML(t, r.get(owner, page, 200), token) if !strings.Contains(row, "acct@example.com") { t.Fatalf("the provider's email is not on the row: %s", row) } for _, gone := range []string{"me@example.com", "(added by you)", "signed in by link", "Add the account email", "Change the account email", "data-account-email"} { if strings.Contains(row, gone) { t.Fatalf("the named row still shows %q: %s", gone, row) } } usage := r.get(owner, "/usage", 200) if !strings.Contains(usage, "Claude (acct@example.com)") { t.Fatalf("Usage does not name the provider's email plainly: %s", usage) } for _, gone := range []string{"me@example.com", "(added by you)", "signed in by link", "Add the account email"} { if strings.Contains(usage, gone) { t.Fatalf("Usage still shows %q", gone) } } send("h-unnamed", "") if row = rowHTML(t, r.get(owner, page, 200), token); !strings.Contains(row, "me@example.com") || !strings.Contains(row, "(added by you)") { t.Fatalf("the stated email was not kept: %s", row) } if usage = r.get(owner, "/usage", 200); !strings.Contains(usage, "me@example.com") || !strings.Contains(usage, "(added by you)") { t.Fatal("Usage lost the stated email") } }