| 1 | package thintest |
| 2 | |
| 3 | import ( |
| 4 | "net/http" |
| 5 | "net/url" |
| 6 | "strings" |
| 7 | "testing" |
| 8 | |
| 9 | "amadan.net/oficina/equipo/internal/wire" |
| 10 | ) |
| 11 | |
| 12 | // The provider's email wins (token profile, 2026-11-12): a token row the |
| 13 | // owner stated an email for, whose profile then names the account, shows |
| 14 | // the provider's email as a plain label (the shared connection label: |
| 15 | // no "(added by you)", not "signed in by link") on Connections and |
| 16 | // Usage, and asks for none. The stated email stays stored: when the |
| 17 | // provider stops naming the account, it shows as the owner's again. |
| 18 | func TestPagesTokenProfileEmailWins(t *testing.T) { |
| 19 | r, runner, token, _ := tokenRowRig(t) |
| 20 | owner := r.inst.Cookie() |
| 21 | const page = "/conversation/settings/connections" |
| 22 | if status, _ := r.post(owner, "/conversation/connections/"+token+"/email", url.Values{"email": {"me@example.com"}}); status != http.StatusSeeOther { |
| 23 | t.Fatalf("the owner's email: %d", status) |
| 24 | } |
| 25 | send := func(frame, label string) { |
| 26 | t.Helper() |
| 27 | hello := held(wire.HeldConnection{LocalID: "claude-9", Person: Owner, Provider: "claude", Kind: wire.KindToken, Label: label, State: wire.ConnHealthy}) |
| 28 | hello.Generation = runner.Welcome.Generation |
| 29 | if err := runner.Send(r.ctx, frame, wire.FrameHello, hello); err != nil { |
| 30 | t.Fatal(err) |
| 31 | } |
| 32 | r.wait("the label "+label, func(c *Conversation) bool { return c.Connections[token].Label == label }) |
| 33 | } |
| 34 | send("h-named", "acct@example.com") |
| 35 | row := rowHTML(t, r.get(owner, page, 200), token) |
| 36 | if !strings.Contains(row, "acct@example.com") { |
| 37 | t.Fatalf("the provider's email is not on the row: %s", row) |
| 38 | } |
| 39 | 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"} { |
| 40 | if strings.Contains(row, gone) { |
| 41 | t.Fatalf("the named row still shows %q: %s", gone, row) |
| 42 | } |
| 43 | } |
| 44 | usage := r.get(owner, "/usage", 200) |
| 45 | if !strings.Contains(usage, "Claude (acct@example.com)") { |
| 46 | t.Fatalf("Usage does not name the provider's email plainly: %s", usage) |
| 47 | } |
| 48 | for _, gone := range []string{"me@example.com", "(added by you)", "signed in by link", "Add the account email"} { |
| 49 | if strings.Contains(usage, gone) { |
| 50 | t.Fatalf("Usage still shows %q", gone) |
| 51 | } |
| 52 | } |
| 53 | send("h-unnamed", "") |
| 54 | if row = rowHTML(t, r.get(owner, page, 200), token); !strings.Contains(row, "me@example.com") || !strings.Contains(row, "(added by you)") { |
| 55 | t.Fatalf("the stated email was not kept: %s", row) |
| 56 | } |
| 57 | if usage = r.get(owner, "/usage", 200); !strings.Contains(usage, "me@example.com") || !strings.Contains(usage, "(added by you)") { |
| 58 | t.Fatal("Usage lost the stated email") |
| 59 | } |
| 60 | } |
| 61 | |