From 794846f9da10182ea4a5dab0c6758ec652b1a629 Mon Sep 17 00:00:00 2001 From: Andy Anderson Date: Tue, 17 Nov 2026 14:20:53 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Customers:=20Inbox-style=20layou?= =?UTF-8?q?t,=20less=20noise,=20no=20non-people=20suggested,=20attach=20a?= =?UTF-8?q?=20suggestion=20to=20an=20existing=20customer=20(#18816)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #18816 Signed-off-by: Andy Anderson --- .../fixed-18816-customers-layout-and-noise.md | 2 + dashboard/openapi.json | 18 +- src/cmd/hive/customers_sweep.go | 38 ++- src/cmd/hive/customers_sweep_test.go | 35 ++ src/cmd/hive/customerswire.go | 4 + src/docs/api-reference/customers.md | 24 +- src/docs/security-model.md | 11 +- src/pkg/customers/address.go | 78 +++++ src/pkg/customers/ingest.go | 37 ++ src/pkg/customers/nonperson_test.go | 235 +++++++++++++ src/pkg/customers/resolve.go | 23 ++ src/pkg/customers/service.go | 30 ++ src/pkg/dashboard/api_customers.go | 24 ++ src/pkg/dashboard/api_customers_test.go | 29 +- src/pkg/dashboard/customers_ui_test.go | 134 +++++++- .../dashboard/static-src/css/customers.css | 48 ++- src/pkg/dashboard/static-src/js/customers.js | 273 +++++++++++++-- src/pkg/dashboard/static/index.html | 321 ++++++++++++++++-- 18 files changed, 1268 insertions(+), 96 deletions(-) create mode 100644 changelog.d/fixed-18816-customers-layout-and-noise.md create mode 100644 src/pkg/customers/address.go create mode 100644 src/pkg/customers/nonperson_test.go diff --git a/changelog.d/fixed-18816-customers-layout-and-noise.md b/changelog.d/fixed-18816-customers-layout-and-noise.md new file mode 100644 index 0000000000..d767f747e0 --- /dev/null +++ b/changelog.d/fixed-18816-customers-layout-and-noise.md @@ -0,0 +1,2 @@ +- The Customers section is laid out like the Inbox and Calendar: each person is a card with an initial or source icon, the name as the title, a muted line, tags as chips and grouped actions that wrap under the content on narrow screens, with no sideways scrolling and long keys cut with a tooltip. "me" is a badge, "0 goals" is no longer printed on every row, and the evidence behind a suggestion sits under "Why is this suggested?" as readable links (at most five). Suggested people are grouped by source with "Show N more", and accepting, dismissing or answering a "Same person?" question keeps the group open, its expansion and the scroll position, and moves the focus to the next suggestion. A suggestion can now be added to an existing customer ("Add to existing..." on a suggestion, "Add a suggested person here" on a profile); it reuses the merge, so Undo merge takes it back (#18816). +- Customers discovery no longer suggests people who are already customers or who are not people. A hive user whose access-list name is a bare GitHub login (what a device-flow sign-in produces) is now linked to that GitHub login, so they are not suggested again, and a suggestion that points at an identity a customer owns expires. Calendar group and room addresses, mailing-list addresses, no-reply and service mailboxes and the hive's own `hive@` address are never suggested, and those already stored expire on the next sweep (#18816). diff --git a/dashboard/openapi.json b/dashboard/openapi.json index cb048f0152..459233080b 100644 --- a/dashboard/openapi.json +++ b/dashboard/openapi.json @@ -2400,7 +2400,23 @@ "Customers" ], "summary": "Accept a suggested person", - "description": "Turns a suggestion into a customer. This is the human decision that lets the hive build a profile of someone who never signed up. Owner or read-write. Audited as customer_accept.", + "description": "Turns a suggestion into a customer. This is the human decision that lets the hive build a profile of someone who never signed up. With the optional body {\"into\": \"\"} it attaches the suggestion to that existing customer instead: the identity becomes one of theirs (a manual decision, so it is not suggested again), no new person is created, the activity moves onto them on the next sweep, and POST /api/customers/{id}/unmerge undoes it. Owner or read-write. Audited as customer_accept, or customer_attach with the target's id.", + "requestBody": { + "required": false, + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "into": { + "type": "string", + "description": "Existing customer id, or me, to attach the suggestion to" + } + } + } + } + } + }, "parameters": [ { "name": "sid", diff --git a/src/cmd/hive/customers_sweep.go b/src/cmd/hive/customers_sweep.go index b4618818ac..ddb0f52253 100644 --- a/src/cmd/hive/customers_sweep.go +++ b/src/cmd/hive/customers_sweep.go @@ -3,6 +3,7 @@ package main import ( "context" "net/mail" + "net/url" "strings" "time" @@ -14,6 +15,7 @@ import ( "github.com/hivecommons/hive/pkg/github" "github.com/hivecommons/hive/pkg/inbox" "github.com/hivecommons/hive/pkg/mailallow" + "github.com/hivecommons/hive/pkg/mailin/wire" "github.com/hivecommons/hive/pkg/meetings" "github.com/hivecommons/hive/pkg/meetings/schedule" ) @@ -29,8 +31,8 @@ const ( // customersSweepInterval is how often discovery runs. Everything it // reads is local, so the cost of a pass is a few file reads. customersSweepInterval = 10 * time.Minute - // githubUserPrefix marks an access-list entry the hub authenticated - // with GitHub ("github:alice"): the name is a GitHub login. + // githubUserPrefix is the optional provider prefix of an access-list + // entry the hub authenticated with GitHub ("github:alice"). githubUserPrefix = "github:" ) @@ -142,6 +144,7 @@ func customersSweepInput(src customersSources) customers.SweepInput { if src.cfg == nil { return in } + in.OwnAddresses = customersOwnAddresses(src.cfg) in.Users, in.Links = customersUsers(src) in.Sightings = append(in.Sightings, customersGitHubSightings(src)...) in.Sightings = append(in.Sightings, customersLocalSightings(src)...) @@ -173,8 +176,11 @@ func customersUsers(src customersSources) ([]customers.HiveUser, []customers.Pro if role == config.RoleOwner { owners = append(owners, name) } - // The hub writes a GitHub-authenticated user as "github:". - if login, ok := strings.CutPrefix(strings.ToLower(name), githubUserPrefix); ok && login != "" { + // The hub writes a GitHub-authenticated user as "github:", + // and a device-flow login is the bare login: the access list + // treats the two as one user. Either way the name is a GitHub + // login, as long as it is shaped like one. + if login := customersGitHubLogin(name); login != "" { links = append(links, customers.ProvenLink{User: name, Identity: customers.Identity{ Kind: customers.KindGitHub, Value: login, Source: customersSourceAccessList, }}) @@ -198,6 +204,30 @@ func customersUsers(src customersSources) ([]customers.HiveUser, []customers.Pro return users, links } +// customersGitHubLogin is the GitHub login an access-list name stands for, or +// "" when it is not one: a name with another provider prefix, an address or +// anything else a login cannot be. +func customersGitHubLogin(name string) string { + login := strings.TrimPrefix(strings.ToLower(strings.TrimSpace(name)), githubUserPrefix) + if !customers.LooksLikeGitHubLogin(login) { + return "" + } + return login +} + +// customersOwnAddresses are this hive's own mail addresses: hive@. Mail and invites sent to it are never a person. +func customersOwnAddresses(cfg *config.Config) []string { + if cfg == nil { + return nil + } + u, err := url.Parse(strings.TrimSpace(cfg.Hub.DashboardURL)) + if err != nil || u.Hostname() == "" { + return nil + } + return []string{wire.LocalPart + "@" + strings.ToLower(u.Hostname())} +} + // customersIsPerson reports whether a GitHub login is a person rather than // a bot or this hive's own author account. func customersIsPerson(cfg *config.Config, login string) bool { diff --git a/src/cmd/hive/customers_sweep_test.go b/src/cmd/hive/customers_sweep_test.go index c56e859e93..b069f83457 100644 --- a/src/cmd/hive/customers_sweep_test.go +++ b/src/cmd/hive/customers_sweep_test.go @@ -108,6 +108,10 @@ func TestCustomersSweepInputMapsLocalState(t *testing.T) { "github:Olivia|github|olivia": customersSourceAccessList, "github:Olivia|github|olivia-gh": customersSourceOwner, "rita|email|rita@example.com": customersSourceProof, + // A bare access-list name is the GitHub login of a device-flow user. + "rita|github|rita": customersSourceAccessList, + "max|github|max": customersSourceAccessList, + "reed|github|reed": customersSourceAccessList, } if len(links) != len(wantLinks) { t.Fatalf("links = %v, want %v (an unproven email must not link)", links, wantLinks) @@ -370,3 +374,34 @@ func TestCustomersAuditResolver(t *testing.T) { t.Fatal("the audit resolver is not registered") } } + +// TestCustomersBareAccessListNameIsGitHubLogin pins the root cause of +// hive users showing up as suggested GitHub people: the access list holds a +// device-flow user as the bare login, not "github:", and only the +// prefixed form used to be linked. +func TestCustomersBareAccessListNameIsGitHubLogin(t *testing.T) { + for name, want := range map[string]string{ + "danathar": "danathar", "GitHub:Alice": "alice", "github:bob-1": "bob-1", " carol ": "carol", + "ibmid:abc": "", "dave@example.com": "", "has.dot": "", "under_score": "", "-lead": "", "a--b": "", "": "", "github:": "", + "x23456789012345678901234567890123456789x": "", + } { + if got := customersGitHubLogin(name); got != want { + t.Errorf("customersGitHubLogin(%q) = %q, want %q", name, got, want) + } + } +} + +func TestCustomersOwnAddresses(t *testing.T) { + cfg := &config.Config{} + cfg.Hub.DashboardURL = "https://Hosted-X.hive.example.dev/" + got := customersOwnAddresses(cfg) + if len(got) != 1 || got[0] != "hive@hosted-x.hive.example.dev" { + t.Fatalf("own addresses = %v", got) + } + if customersOwnAddresses(&config.Config{}) != nil || customersOwnAddresses(nil) != nil { + t.Fatal("an unknown host must give no own address") + } + if in := customersSweepInput(customersSources{cfg: cfg}); len(in.OwnAddresses) != 1 { + t.Fatalf("the sweep input lacks the own address: %v", in.OwnAddresses) + } +} diff --git a/src/cmd/hive/customerswire.go b/src/cmd/hive/customerswire.go index ff58f772ed..09e2488680 100644 --- a/src/cmd/hive/customerswire.go +++ b/src/cmd/hive/customerswire.go @@ -211,6 +211,10 @@ func installCustomersAgentContext(c *customersDashboard, setKickLookup func(sche } } +func (c *customersDashboard) AcceptInto(v dashboard.CustomersViewer, suggestionID, into string) (dashboard.CustomerResult, error) { + return customerResult(c.svc.AcceptInto(customersViewer(v), suggestionID, into)) +} + func (c *customersDashboard) Merge(v dashboard.CustomersViewer, id, from string) (dashboard.CustomerResult, error) { return customerResult(c.svc.Merge(customersViewer(v), id, from)) } diff --git a/src/docs/api-reference/customers.md b/src/docs/api-reference/customers.md index 6884013a65..5b6bbc5539 100644 --- a/src/docs/api-reference/customers.md +++ b/src/docs/api-reference/customers.md @@ -12,18 +12,18 @@ The rules are enforced twice: by the handlers and again by the store's service o | Method | Path | Auth | Purpose | Source | |---|---|---|---|---| -| `GET` | `/api/customers` | Signed-in user | The Customers section: `{enabled, full, owner, me, people, suggestions, default_tags, levels}`. `me` is the viewer's own profile, created on first read. `people` and `suggestions` are empty without the full view | `pkg/dashboard/api_customers.go:164` | -| `POST` | `/api/customers` | Full view | Add a customer by hand: `{name, identities?: [{kind, value}]}`. 409 when an identity belongs to another customer; a `hive_user` identity is refused. Audited as `customer_add` | `pkg/dashboard/api_customers.go:165` | -| `GET` | `/api/customers/{id}` | Signed-in user; self reaches only `me` | One profile, with edge counts and open "Same person?" hints for the full view. A viewer without the full view gets no notes, satisfaction, merge history, counts or hints. Opening someone else's profile is audited as `customer_profile_open` | `pkg/dashboard/api_customers.go:166` | -| `POST` | `/api/customers/{id}/edit` | Full view; self only as `/api/customers/me/edit` | One change: `{op, ...}` with `op` one of `name`, `notes`, `identity_add` (`kind`, `value`), `identity_remove` (`key`), `tag` (`tag`, `state` of `on`, `off` or `auto`), `goal_add` (`text`), `goal_edit` (`goal_id`, `text`), `goal_confirm`, `goal_reject` (`goal_id`), `satisfaction_set` (`level`), `satisfaction_confirm`, `satisfaction_reject`. Self may use the name, identity, tag and goal ops; an identity added by self is an unconfirmed claim that resolves nobody until the full view confirms it with `identity_add`. Audited as `customer_edit` with the person and the op, never the value | `pkg/dashboard/api_customers.go:167` | -| `DELETE` | `/api/customers/{id}` | Owner only | Forget: deletes the customer, their identities and every edge to them, and keeps one salted-hash tombstone per confirmed identity so discovery does not rebuild them. 200 `{forgotten, edges_removed}`. Audited as `customer_forget` | `pkg/dashboard/api_customers.go:168` | -| `POST` | `/api/customers/suggestions/{sid}/accept` | Full view | Turn a suggested person into a customer. Audited as `customer_accept` | `pkg/dashboard/api_customers.go:169` | -| `POST` | `/api/customers/suggestions/{sid}/dismiss` | Full view | Delete a suggestion and tombstone its key, so it is not offered again. Audited as `customer_dismiss` | `pkg/dashboard/api_customers.go:170` | -| `POST` | `/api/customers/hints/{hid}/answer` | Full view | Answer a "Same person?" question: `{same}`. `true` makes the suggested identity the customer's own and deletes the suggestion; `false` closes the question for good. A question between two customers is answered by merging them, so `true` on one is 400. Audited as `customer_hint_answer` | `pkg/dashboard/api_customers.go:171` | -| `POST` | `/api/customers/{id}/merge` | Full view | Fold the customer `{from}` into this one: identities, tags, goals and activity move across and the merge is recorded. 409 for two dashboard users. Audited as `customer_merge` | `pkg/dashboard/api_customers.go:172` | -| `POST` | `/api/customers/{id}/unmerge` | Full view | Undo a merge: `{from}` comes back as it stood, with exactly what the merge brought it. Audited as `customer_unmerge` | `pkg/dashboard/api_customers.go:173` | -| `POST` | `/api/customers/{id}/split` | Full view | Move identities `{identities: ["kind:value"], name?}` off this customer onto a new one, with the activity they produced; returns the new customer. Audited as `customer_split` | `pkg/dashboard/api_customers.go:174` | -| `GET` | `/api/customers/{id}/export` | Owner only | Everything held about one customer as a JSON download: the profile, merge history, hints and up to 10,000 activity references. Audited as `customer_export` | `pkg/dashboard/api_customers.go:175` | +| `GET` | `/api/customers` | Signed-in user | The Customers section: `{enabled, full, owner, me, people, suggestions, default_tags, levels}`. `me` is the viewer's own profile, created on first read. `people` and `suggestions` are empty without the full view | `pkg/dashboard/api_customers.go:174` | +| `POST` | `/api/customers` | Full view | Add a customer by hand: `{name, identities?: [{kind, value}]}`. 409 when an identity belongs to another customer; a `hive_user` identity is refused. Audited as `customer_add` | `pkg/dashboard/api_customers.go:175` | +| `GET` | `/api/customers/{id}` | Signed-in user; self reaches only `me` | One profile, with edge counts and open "Same person?" hints for the full view. A viewer without the full view gets no notes, satisfaction, merge history, counts or hints. Opening someone else's profile is audited as `customer_profile_open` | `pkg/dashboard/api_customers.go:176` | +| `POST` | `/api/customers/{id}/edit` | Full view; self only as `/api/customers/me/edit` | One change: `{op, ...}` with `op` one of `name`, `notes`, `identity_add` (`kind`, `value`), `identity_remove` (`key`), `tag` (`tag`, `state` of `on`, `off` or `auto`), `goal_add` (`text`), `goal_edit` (`goal_id`, `text`), `goal_confirm`, `goal_reject` (`goal_id`), `satisfaction_set` (`level`), `satisfaction_confirm`, `satisfaction_reject`. Self may use the name, identity, tag and goal ops; an identity added by self is an unconfirmed claim that resolves nobody until the full view confirms it with `identity_add`. Audited as `customer_edit` with the person and the op, never the value | `pkg/dashboard/api_customers.go:177` | +| `DELETE` | `/api/customers/{id}` | Owner only | Forget: deletes the customer, their identities and every edge to them, and keeps one salted-hash tombstone per confirmed identity so discovery does not rebuild them. 200 `{forgotten, edges_removed}`. Audited as `customer_forget` | `pkg/dashboard/api_customers.go:178` | +| `POST` | `/api/customers/suggestions/{sid}/accept` | Full view | Turn a suggested person into a customer. With the optional body `{into}` (an existing customer id, or `me`) it attaches the suggestion to that customer instead: the identity becomes one of theirs, pinned as a manual decision, no new person is created, the activity moves onto them on the next sweep, and `unmerge` undoes it with the id in the target's merge history. Audited as `customer_accept`, or `customer_attach` with the target's id and never a name | `pkg/dashboard/api_customers.go:179` | +| `POST` | `/api/customers/suggestions/{sid}/dismiss` | Full view | Delete a suggestion and tombstone its key, so it is not offered again. Audited as `customer_dismiss` | `pkg/dashboard/api_customers.go:180` | +| `POST` | `/api/customers/hints/{hid}/answer` | Full view | Answer a "Same person?" question: `{same}`. `true` makes the suggested identity the customer's own and deletes the suggestion; `false` closes the question for good. A question between two customers is answered by merging them, so `true` on one is 400. Audited as `customer_hint_answer` | `pkg/dashboard/api_customers.go:181` | +| `POST` | `/api/customers/{id}/merge` | Full view | Fold the customer `{from}` into this one: identities, tags, goals and activity move across and the merge is recorded. 409 for two dashboard users. Audited as `customer_merge` | `pkg/dashboard/api_customers.go:182` | +| `POST` | `/api/customers/{id}/unmerge` | Full view | Undo a merge: `{from}` comes back as it stood, with exactly what the merge brought it. Audited as `customer_unmerge` | `pkg/dashboard/api_customers.go:183` | +| `POST` | `/api/customers/{id}/split` | Full view | Move identities `{identities: ["kind:value"], name?}` off this customer onto a new one, with the activity they produced; returns the new customer. Audited as `customer_split` | `pkg/dashboard/api_customers.go:184` | +| `GET` | `/api/customers/{id}/export` | Owner only | Everything held about one customer as a JSON download: the profile, merge history, hints and up to 10,000 activity references. Audited as `customer_export` | `pkg/dashboard/api_customers.go:185` | | `POST` | `/api/graph` | Signed-in user | The customer graph over GraphQL, read-only (no mutations, so a read-only user may call it): `{query, operationName?, variables?}`, answered with a GraphQL `{data, errors}` document. Access follows the viewer exactly as above; see [the customer graph](#the-customer-graph). Audited as `customer_graph_query` with the operation name, node count and error count, never the query text | `pkg/dashboard/api_graph.go:47` | ## The customer graph diff --git a/src/docs/security-model.md b/src/docs/security-model.md index 7cfb9d93e2..8994c6f314 100644 --- a/src/docs/security-model.md +++ b/src/docs/security-model.md @@ -211,10 +211,13 @@ hash, so they are not rebuilt. Links between identities are made only on exact keys. A display name never links anyone. One link rests on an assumption you should know about. When the access -list holds a name such as `github:alice`, the hive treats `alice` as that -person's GitHub login. The hub put that entry there after it signed the person -in with GitHub, so the hive trusts it. If your access list is edited by hand, an -entry like that gives the named person's profile the matching GitHub activity. +list holds a name such as `github:alice`, or the bare login `alice` that a +GitHub device-flow sign-in produces (the access list treats the two as one +user), the hive treats `alice` as that person's GitHub login. A name with +another provider prefix, an address, a dot or an underscore is not read as a +login. The hub put that entry there after it signed the person in with GitHub, +so the hive trusts it. If your access list is edited by hand, an entry like +that gives the named person's profile the matching GitHub activity. A read-only user sees only their own profile. An identity they add is shown as unconfirmed. It links nothing until the owner or a read-write user confirms it. diff --git a/src/pkg/customers/address.go b/src/pkg/customers/address.go new file mode 100644 index 0000000000..8129c71a98 --- /dev/null +++ b/src/pkg/customers/address.go @@ -0,0 +1,78 @@ +package customers + +import "strings" + +// Addresses that are never a person. A calendar invite lists group, room and +// list addresses next to the people, and the hive's own mailbox sits on every +// invite it is sent. None of them is someone to build a profile of, so none +// is suggested. +var ( + // nonPersonDomains name domains, and their subdomains, whose addresses + // are calendars, rooms or mailing lists (hivecommons/hive#18742). + nonPersonDomains = []string{ + "calendar.google.com", + "googlegroups.com", + } + // nonPersonLocalParts are mailboxes that are service accounts. + nonPersonLocalParts = []string{ + "mailer-daemon", "postmaster", "notifications", "notification", "calendar-notification", "nobody", + } + // nonPersonLocalPrefixes start the local part of a no-reply or bounce + // mailbox. + nonPersonLocalPrefixes = []string{ + "noreply", "no-reply", "donotreply", "do-not-reply", "bounce", + } +) + +// IsNonPersonAddress reports whether an email address is a calendar group, a +// mailing list, a service or no-reply mailbox, or one of own (this hive's +// own addresses, such as hive@). The comparison ignores case. +func IsNonPersonAddress(addr string, own ...string) bool { + a := strings.ToLower(strings.TrimSpace(addr)) + at := strings.LastIndexByte(a, '@') + if at <= 0 { + return false + } + local, domain := a[:at], a[at+1:] + for _, o := range own { + if o != "" && strings.EqualFold(strings.TrimSpace(o), a) { + return true + } + } + for _, d := range nonPersonDomains { + if domain == d || strings.HasSuffix(domain, "."+d) { + return true + } + } + for _, l := range nonPersonLocalParts { + if local == l { + return true + } + } + for _, p := range nonPersonLocalPrefixes { + if strings.HasPrefix(local, p) { + return true + } + } + return false +} + +// githubLoginMax is the longest GitHub login. +const githubLoginMax = maxLoginLen + +// LooksLikeGitHubLogin reports whether a dashboard user name is shaped like a +// GitHub login: letters, digits and single hyphens, at most 39 characters. +// A name with a provider prefix other than github:, an address, a dot or an +// underscore is not. +func LooksLikeGitHubLogin(name string) bool { + n := strings.TrimSpace(name) + if n == "" || len(n) > githubLoginMax || strings.HasPrefix(n, "-") || strings.HasSuffix(n, "-") || strings.Contains(n, "--") { + return false + } + for i := 0; i < len(n); i++ { + if !isLoginByte(n[i]) { + return false + } + } + return true +} diff --git a/src/pkg/customers/ingest.go b/src/pkg/customers/ingest.go index 26eed38f9b..a71bcc7e4c 100644 --- a/src/pkg/customers/ingest.go +++ b/src/pkg/customers/ingest.go @@ -55,6 +55,9 @@ type SweepInput struct { Users []HiveUser Links []ProvenLink Sightings []Sighting + // OwnAddresses are this hive's own mail addresses (hive@), which + // are never suggested. + OwnAddresses []string } // SweepResult counts what a sweep did. @@ -106,6 +109,16 @@ func (s *Service) Sweep(in SweepInput) (SweepResult, error) { // B and C. Sightings become edges for customers and suggestions for // everyone else. + // A calendar group, a mailing list, a service mailbox and the hive's own + // address are never suggested; one a person already owns keeps its edges. + sightings := make([]Sighting, 0, len(in.Sightings)) + for _, sg := range in.Sightings { + if s.deniedIdentity(sg.Kind, sg.Value, in.OwnAddresses) { + continue + } + sightings = append(sightings, sg) + } + in.Sightings = sightings obs := make([]Observation, 0, len(in.Sightings)) for _, sg := range in.Sightings { obs = append(obs, sg.Observation) @@ -159,6 +172,15 @@ func (s *Service) Sweep(in SweepInput) (SweepResult, error) { if res.ExpiredSuggestions, err = s.store.ExpireSuggestions(exists); err != nil { return res, err } + // A suggestion stored before a rule existed, or for an identity a + // person has since come to own, expires here too. + stale, err := s.store.ExpireSuggestionsWhere(func(sg Suggestion) bool { + return IsNonPersonIdentity(sg.Kind, sg.Value, in.OwnAddresses) + }) + if err != nil { + return res, err + } + res.ExpiredSuggestions += stale if res.DroppedEvidence, err = s.store.PruneEvidence(exists); err != nil { return res, err } @@ -187,6 +209,21 @@ func (s *Service) Sweep(in SweepInput) (SweepResult, error) { return res, nil } +// IsNonPersonIdentity applies IsNonPersonAddress to an email identity. +func IsNonPersonIdentity(kind IdentityKind, value string, own []string) bool { + return kind == KindEmail && IsNonPersonAddress(value, own...) +} + +// deniedIdentity reports whether a sighting must not become a suggestion: it +// is a non-person address that no customer owns. +func (s *Service) deniedIdentity(kind IdentityKind, value string, own []string) bool { + if !IsNonPersonIdentity(kind, value, own) { + return false + } + _, owned := s.store.Lookup(kind, value) + return !owned +} + // githubPredicates are the edges that mean someone works in the repository. var githubPredicates = []string{ PredAuthored, PredAssigned, PredReviewed, PredMerged, PredClaimed, PredReported, diff --git a/src/pkg/customers/nonperson_test.go b/src/pkg/customers/nonperson_test.go new file mode 100644 index 0000000000..4f53f4115b --- /dev/null +++ b/src/pkg/customers/nonperson_test.go @@ -0,0 +1,235 @@ +package customers + +import ( + "errors" + "testing" +) + +func TestIsNonPersonAddress(t *testing.T) { + own := []string{"hive@hosted-x.hive.example.dev"} + for addr, want := range map[string]bool{ + "b43dc28a888d316aa1fe4a47bf3038cd1bca7bbb2b5cdbf5e7ecb9cc10672a95@group.calendar.google.com": true, + "room-1@resource.calendar.google.com": true, + "hivecommons-dev@googlegroups.com": true, + "Hive@Hosted-X.hive.example.dev": true, + "noreply@example.com": true, + "no-reply+x@example.com": true, + "do-not-reply@example.com": true, + "mailer-daemon@example.com": true, + "bounces-123@example.com": true, + "notifications@example.com": true, + "ada@example.com": false, + "hive@elsewhere.example.com": false, + "nic1@ibm.com": false, + "ada@notgooglegroups.com": false, + "not an address": false, + "": false, + "someone@calendar.google.com.example.org": false, + } { + if got := IsNonPersonAddress(addr, own...); got != want { + t.Errorf("IsNonPersonAddress(%q) = %v, want %v", addr, got, want) + } + } + if !LooksLikeGitHubLogin("danathar") || LooksLikeGitHubLogin("a@b.c") || LooksLikeGitHubLogin("ibmid:x") { + t.Error("LooksLikeGitHubLogin") + } +} + +// TestSweepNeverSuggestsNonPeopleAndExpiresStoredOnes: the deny rule keeps +// group, list, service and own addresses out of Suggested, and a suggestion +// stored before the rule expires through the sweep rather than being +// deleted blindly. A person who owns such an address keeps their edges. +func TestSweepNeverSuggestsNonPeopleAndExpiresStoredOnes(t *testing.T) { + svc := newSweepService(t, goneSet{}) + const group = "abc@group.calendar.google.com" + const own = "hive@hosted-x.hive.example.dev" + // Stored by an older sweep, before the rule. + if _, err := svc.Store().Observe([]Observation{ + {Kind: KindEmail, Value: group, Predicate: PredInvited, Artefact: EventRef("e1"), At: sweepAt}, + {Kind: KindEmail, Value: own, Predicate: PredInvited, Artefact: EventRef("e1"), At: sweepAt}, + {Kind: KindEmail, Value: "ada@example.com", Predicate: PredInvited, Artefact: EventRef("e1"), At: sweepAt}, + }); err != nil { + t.Fatal(err) + } + if n := len(svc.Store().Suggestions()); n != 3 { + t.Fatalf("setup: %d suggestions", n) + } + in := SweepInput{OwnAddresses: []string{own}, Sightings: []Sighting{ + sight(KindEmail, group, PredInvited, EventRef("e1"), "calendar"), + sight(KindEmail, own, PredInvited, EventRef("e1"), "calendar"), + sight(KindEmail, "list@googlegroups.com", PredInvited, EventRef("e1"), "calendar"), + sight(KindEmail, "ada@example.com", PredInvited, EventRef("e1"), "calendar"), + }} + res, err := svc.Sweep(in) + if err != nil { + t.Fatal(err) + } + got := svc.Store().Suggestions() + if len(got) != 1 || got[0].Value != "ada@example.com" { + t.Fatalf("suggestions = %+v, want only ada", got) + } + if res.ExpiredSuggestions != 2 { + t.Fatalf("expired = %d, want the 2 stored non-people", res.ExpiredSuggestions) + } + // Nothing was tombstoned: allowing the address again brings it back. + in.OwnAddresses = nil + in.Sightings = []Sighting{sight(KindEmail, own, PredInvited, EventRef("e1"), "calendar")} + if _, err := svc.Sweep(in); err != nil { + t.Fatal(err) + } + if _, ok := suggestionFor(svc, KindEmail, own); !ok { + t.Fatal("an expired suggestion must not be tombstoned") + } +} + +func suggestionFor(svc *Service, kind IdentityKind, value string) (Suggestion, bool) { + for _, sg := range svc.Store().Suggestions() { + if sg.Kind == kind && sg.Value == NormalizeIdentity(kind, value) { + return sg, true + } + } + return Suggestion{}, false +} + +// TestLinkedIdentityIsNeverSuggested: an identity a hive user owns is that +// person's, and a suggestion that predates the link is removed. +func TestLinkedIdentityIsNeverSuggested(t *testing.T) { + svc := newSweepService(t, goneSet{}) + if _, err := svc.Store().Observe([]Observation{ + {Kind: KindGitHub, Value: "danathar", Predicate: PredAuthored, Artefact: PRRef("o/r", 1), At: sweepAt}, + {Kind: KindEmail, Value: "me@example.com", Predicate: PredInvited, Artefact: EventRef("e1"), At: sweepAt}, + }); err != nil { + t.Fatal(err) + } + in := SweepInput{ + Users: []HiveUser{{Name: "danathar"}, {Name: "olivia", Maintainer: true, Rule: "owner"}}, + Links: []ProvenLink{ + {User: "danathar", Identity: Identity{Kind: KindGitHub, Value: "danathar", Source: "access_list"}}, + {User: "olivia", Identity: Identity{Kind: KindEmail, Value: "Me@Example.com", Source: "calendar_proof"}}, + }, + Sightings: []Sighting{ + sight(KindGitHub, "Danathar", PredAuthored, PRRef("o/r", 1), "github_poll"), + sight(KindEmail, "me@example.com", PredInvited, EventRef("e1"), "calendar"), + }, + } + res, err := svc.Sweep(in) + if err != nil { + t.Fatal(err) + } + if res.Linked != 2 || len(svc.Store().Suggestions()) != 0 { + t.Fatalf("linked=%d suggestions=%+v", res.Linked, svc.Store().Suggestions()) + } + // A suggestion left behind for an owned key (for example one stored + // before the identity was added by hand) expires on the next sweep. + st := svc.Store() + st.mu.Lock() + st.sugg["github:danathar"] = Suggestion{ID: "s_stale", Kind: KindGitHub, Value: "danathar", Evidence: []string{PRRef("o/r", 1)}} + st.mu.Unlock() + if _, err := svc.Sweep(in); err != nil { + t.Fatal(err) + } + if len(st.Suggestions()) != 0 { + t.Fatalf("an owned identity is still suggested: %+v", st.Suggestions()) + } +} + +func attachSetup(t *testing.T) (*Service, Suggestion) { + t.Helper() + svc := newSweepService(t, goneSet{}) + if _, err := svc.Sweep(SweepInput{ + Users: []HiveUser{{Name: "olivia", Maintainer: true, Rule: "owner"}}, + Sightings: []Sighting{ + sight(KindGitHub, "ada-gh", PredAuthored, PRRef("o/r", 5), "github_poll"), + }, + }); err != nil { + t.Fatal(err) + } + sg, ok := suggestionFor(svc, KindGitHub, "ada-gh") + if !ok { + t.Fatal("setup: no suggestion") + } + return svc, sg +} + +func TestAcceptIntoAttachesToAnExistingCustomer(t *testing.T) { + svc, sg := attachSetup(t) + ada, err := svc.Add(ownerV, "Ada", []Identity{{Kind: KindEmail, Value: "ada@example.com"}}) + if err != nil { + t.Fatal(err) + } + before := len(svc.Store().People()) + got, err := svc.AcceptInto(ownerV, sg.ID, ada.ID) + if err != nil { + t.Fatal(err) + } + if got.ID != ada.ID || got.Identity(KindGitHub) != "ada-gh" { + t.Fatalf("result = %+v", got.Person) + } + if len(svc.Store().People()) != before { + t.Fatalf("people %d -> %d: attaching must never create a duplicate", before, len(svc.Store().People())) + } + if _, ok := suggestionFor(svc, KindGitHub, "ada-gh"); ok { + t.Fatal("the suggestion is still in Suggested") + } + // The identity is a manual decision of Ada's and is not suggested again, + // and the next sweep writes the activity onto her. + var ident Identity + for _, i := range got.Identities { + if i.Kind == KindGitHub { + ident = i + } + } + if !ident.Manual { + t.Fatalf("identity = %+v, want manual", ident) + } + if _, err := svc.Sweep(SweepInput{Sightings: []Sighting{sight(KindGitHub, "ada-gh", PredAuthored, PRRef("o/r", 5), "github_poll")}}); err != nil { + t.Fatal(err) + } + if _, ok := suggestionFor(svc, KindGitHub, "ada-gh"); ok { + t.Fatal("a pinned identity was suggested again") + } + if c, _ := svc.index.Counts(ada.ID); c[PredAuthored] != 1 { + t.Fatalf("counts = %v, the activity did not move to Ada", c) + } + // Undo with the merge's own undo. + if len(got.MergedFrom) != 1 { + t.Fatalf("merge history = %+v", got.MergedFrom) + } + back, err := svc.Unmerge(ownerV, ada.ID, got.MergedFrom[0].Person.ID) + if err != nil { + t.Fatal(err) + } + if back.Identity(KindGitHub) != "" || len(back.MergedFrom) != 0 { + t.Fatalf("after undo Ada = %+v", back.Person) + } + if p, ok := svc.Store().Lookup(KindGitHub, "ada-gh"); !ok || p.ID == ada.ID { + t.Fatal("after undo the identity must belong to the restored person") + } +} + +func TestAcceptIntoMeAndRoles(t *testing.T) { + svc, sg := attachSetup(t) + // A read-only viewer cannot see suggestions, so cannot attach one. + if _, err := svc.AcceptInto(readV, sg.ID, MeID); !errors.Is(err, ErrForbidden) { + t.Fatalf("read-only AcceptInto = %v, want ErrForbidden", err) + } + if _, ok := suggestionFor(svc, KindGitHub, "ada-gh"); !ok { + t.Fatal("a refused attach consumed the suggestion") + } + // A read-write user may attach to their own Me. + got, err := svc.AcceptInto(rwV, sg.ID, MeID) + if err != nil || !got.Me || got.Identity(KindGitHub) != "ada-gh" { + t.Fatalf("read-write AcceptInto me = %+v, %v", got, err) + } + // Unknown targets and suggestions fail without creating anyone. + before := len(svc.Store().People()) + if _, err := svc.AcceptInto(ownerV, "s_missing", MeID); !errors.Is(err, ErrNotFound) { + t.Fatalf("missing suggestion = %v", err) + } + if _, err := svc.AcceptInto(ownerV, sg.ID, "p_missing"); !errors.Is(err, ErrNotFound) { + t.Fatalf("missing target = %v", err) + } + if len(svc.Store().People()) != before { + t.Fatal("a failed attach created a person") + } +} diff --git a/src/pkg/customers/resolve.go b/src/pkg/customers/resolve.go index b80fd75cee..6ae161b563 100644 --- a/src/pkg/customers/resolve.go +++ b/src/pkg/customers/resolve.go @@ -558,6 +558,29 @@ func (s *Store) ExpireSuggestions(exists func(artefact string) bool) (int, error return removed, nil } +// ExpireSuggestionsWhere deletes the suggestions drop names, and every +// suggestion whose identity a person owns: a suggestion is for someone +// nobody holds. Nothing is tombstoned, so a suggestion a later rule allows +// can come back. It returns how many were deleted. +func (s *Store) ExpireSuggestionsWhere(drop func(Suggestion) bool) (int, error) { + removed := 0 + err := s.change(func() error { + for key, sg := range s.sugg { + if _, owned := s.owner[key]; !owned && (drop == nil || !drop(sg)) { + continue + } + delete(s.sugg, key) + s.dropRefsLocked(sg.ID) + removed++ + } + return nil + }) + if err != nil { + return 0, err + } + return removed, nil +} + // Merge folds src into dst and deletes src. The merge is recorded on dst so // Unmerge can undo it exactly. Two dashboard users are never merged: each // keeps their own "me". diff --git a/src/pkg/customers/service.go b/src/pkg/customers/service.go index cee430a0d0..5b2d9d06c6 100644 --- a/src/pkg/customers/service.go +++ b/src/pkg/customers/service.go @@ -320,6 +320,36 @@ func (s *Service) Accept(v Viewer, suggestionID string) (PersonView, error) { return s.view(v, p, false, true), nil } +// AcceptInto attaches a suggested person to an existing customer (id may be +// "me") instead of making them a new one. It reuses the merge: the +// suggestion is accepted as a customer and folded into the target, so the +// identity becomes a manual one of the target's, the activity it produced +// moves onto the target on the next sweep, nobody is created twice, and +// Unmerge, with the id the result names in its merge history, undoes it. +// Full view only: a read-only user cannot see suggestions, and adds their +// own identities as unconfirmed claims instead. +func (s *Service) AcceptInto(v Viewer, suggestionID, intoID string) (PersonView, error) { + if !v.Full { + return PersonView{}, ErrForbidden + } + dst, dstMe, err := s.resolve(v, intoID) + if err != nil { + return PersonView{}, err + } + if len(dst.Identities) >= MaxIdentities { + return PersonView{}, fmt.Errorf("%w: too many identities", ErrInvalid) + } + p, err := s.store.Accept(suggestionID, v.User) + if err != nil { + return PersonView{}, err + } + merged, err := s.store.Merge(dst.ID, p.ID, v.User) + if err != nil { + return PersonView{}, err + } + return s.view(v, merged, dstMe, true), nil +} + // Dismiss turns a suggestion down. Full view only. func (s *Service) Dismiss(v Viewer, suggestionID string) error { if !v.Full { diff --git a/src/pkg/dashboard/api_customers.go b/src/pkg/dashboard/api_customers.go index 3b8830b3dd..39fc6c4723 100644 --- a/src/pkg/dashboard/api_customers.go +++ b/src/pkg/dashboard/api_customers.go @@ -111,6 +111,9 @@ type CustomersService interface { // Forget deletes a person and returns how many edges went with them. Forget(v CustomersViewer, id string) (edges int, err error) Accept(v CustomersViewer, suggestionID string) (CustomerResult, error) + // AcceptInto attaches a suggestion to the existing customer into + // (an id or "me") instead of making a new one; Unmerge undoes it. + AcceptInto(v CustomersViewer, suggestionID, into string) (CustomerResult, error) Dismiss(v CustomersViewer, suggestionID string) error // AnswerHint answers a "Same person?" question: same true makes the // suggested identity the customer's own, false closes the question for @@ -133,6 +136,13 @@ type CustomerMergeRequest struct { From string `json:"from"` } +// CustomerAcceptRequest is the optional body of +// POST /api/customers/suggestions/{sid}/accept: Into is an existing customer +// (an id, or "me") to attach the suggestion to instead of making a new one. +type CustomerAcceptRequest struct { + Into string `json:"into,omitempty"` +} + // CustomerSplitRequest is the body of POST /api/customers/{id}/split. type CustomerSplitRequest struct { Identities []string `json:"identities"` @@ -393,6 +403,20 @@ func (s *Server) handleCustomersAccept(w http.ResponseWriter, r *http.Request) { if !ok { return } + var body CustomerAcceptRequest + if r.ContentLength != 0 && !decodeCustomersBody(w, r, &body) { + return + } + if into := strings.TrimSpace(body.Into); into != "" { + res, err := svc.AcceptInto(v, r.PathValue("sid"), into) + if err != nil { + s.customersError(w, r, err) + return + } + s.auditFromRequest(r, "customer_attach", auditDetail("person", res.ID), "") + jsonResponse(w, res.View) + return + } res, err := svc.Accept(v, r.PathValue("sid")) if err != nil { s.customersError(w, r, err) diff --git a/src/pkg/dashboard/api_customers_test.go b/src/pkg/dashboard/api_customers_test.go index 075e4b8c75..99fd2cc653 100644 --- a/src/pkg/dashboard/api_customers_test.go +++ b/src/pkg/dashboard/api_customers_test.go @@ -64,6 +64,11 @@ func (f *fakeCustomersService) Accept(v CustomersViewer, sid string) (CustomerRe return f.result("p_accepted", v) } +func (f *fakeCustomersService) AcceptInto(v CustomersViewer, sid, into string) (CustomerResult, error) { + f.note("AcceptInto", v, sid+"->"+into) + return f.result(into, v) +} + func (f *fakeCustomersService) AnswerHint(v CustomersViewer, hid string, same bool) (CustomerResult, error) { f.note("AnswerHint", v, fmt.Sprintf("%s:%v", hid, same)) return f.result("p_hinted", v) @@ -148,6 +153,7 @@ var ( custEditOther = customersRoute{http.MethodPost, "/api/customers/p_other/edit", `{"op":"name","name":"N"}`} custForget = customersRoute{http.MethodDelete, "/api/customers/p_other", ""} custAccept = customersRoute{http.MethodPost, "/api/customers/suggestions/s_1/accept", ""} + custAttach = customersRoute{http.MethodPost, "/api/customers/suggestions/s_1/accept", `{"into":"p_other"}`} custDismiss = customersRoute{http.MethodPost, "/api/customers/suggestions/s_1/dismiss", ""} custMerge = customersRoute{http.MethodPost, "/api/customers/p_other/merge", `{"from":"p_src"}`} custUnmerge = customersRoute{http.MethodPost, "/api/customers/p_other/unmerge", `{"from":"p_src"}`} @@ -175,6 +181,10 @@ func TestCustomersRoleMatrix(t *testing.T) { {custEditOther, map[string]int{"owner": ok, "read-write": ok, "merger": ok, "read": forbidden, "unverified owner": forbidden, "read with no name": forbidden}}, {custAdd, map[string]int{"owner": ok, "read-write": ok, "merger": ok, "read": forbidden, "unverified owner": forbidden, "read with no name": forbidden}}, {custAccept, map[string]int{"owner": ok, "read-write": ok, "merger": ok, "read": forbidden, "unverified owner": forbidden, "read with no name": forbidden}}, + // Attaching a suggestion to an existing customer is the accept route + // with a body: the same roles, and a read-only user, who cannot see + // suggestions, is refused before the service is asked. + {custAttach, map[string]int{"owner": ok, "read-write": ok, "merger": ok, "read": forbidden, "unverified owner": forbidden, "read with no name": forbidden}}, {custDismiss, map[string]int{"owner": ok, "read-write": ok, "merger": ok, "read": forbidden, "unverified owner": forbidden, "read with no name": forbidden}}, {custHint, map[string]int{"owner": ok, "read-write": ok, "merger": ok, "read": forbidden, "unverified owner": forbidden, "read with no name": forbidden}}, {custMerge, map[string]int{"owner": ok, "read-write": ok, "merger": ok, "read": forbidden, "unverified owner": forbidden, "read with no name": forbidden}}, @@ -324,6 +334,7 @@ func TestCustomersAudit(t *testing.T) { {custRead, custEditMe}, {custReadWrite, custEditOther}, {custReadWrite, custAccept}, + {custReadWrite, custAttach}, {custReadWrite, custDismiss}, {custReadWrite, custHint}, {custReadWrite, custMerge}, @@ -345,20 +356,22 @@ func TestCustomersAudit(t *testing.T) { count++ } } - if count != 12 { - t.Fatalf("audited %d customer actions, want 12: %v", count, got) + if count != 13 { + t.Fatalf("audited %d customer actions, want 13: %v", count, got) } want := map[string]string{ "customer_profile_open": "olivia|person=p_other;", "customer_add": "olivia|person=p_new, identities=0;", "customer_forget": "olivia|person=p_other, edges=3;", "customer_accept": "rita|person=p_accepted;", - "customer_dismiss": "rita|suggestion=s_1;", - "customer_hint_answer": "rita|person=p_hinted, same=true;", - "customer_merge": "rita|person=p_other, from=p_src;", - "customer_unmerge": "rita|person=p_other, from=p_src;", - "customer_split": "rita|from=p_other, person=p_split, identities=1;", - "customer_export": "olivia|person=p_other;", + // Ids only: never the suggested person's login or address. + "customer_attach": "rita|person=p_other;", + "customer_dismiss": "rita|suggestion=s_1;", + "customer_hint_answer": "rita|person=p_hinted, same=true;", + "customer_merge": "rita|person=p_other, from=p_src;", + "customer_unmerge": "rita|person=p_other, from=p_src;", + "customer_split": "rita|from=p_other, person=p_split, identities=1;", + "customer_export": "olivia|person=p_other;", } for action, detail := range want { if got[action] != detail { diff --git a/src/pkg/dashboard/customers_ui_test.go b/src/pkg/dashboard/customers_ui_test.go index d1f90013bb..71cacc1757 100644 --- a/src/pkg/dashboard/customers_ui_test.go +++ b/src/pkg/dashboard/customers_ui_test.go @@ -92,18 +92,25 @@ func TestCustomersViewGates(t *testing.T) { "customersActivityHtml", "customersForgetHtml", "customersProfileHtml", "customersFormatTime", "customersTimelineGroups", "customersTimelineRowHtml", "customersTimelineHtml", "customersHintRowHtml", "customersMergeHtml", "customersGraphBodyHtml", "customersGraphHtml", + "customersInitial", "customersEvidenceLabel", "customersWhyHtml", "customersPickerHtml", "customersSuggestionGroups", + "customersSuggestionGroupHtml", "customersAttachHtml", "customersSuggestionOrder", "customersNeighbour", + "customersFocusSuggestion", "customersAfterSuggestion", "customersAccept", "customersDismiss", "customersShowMore", + "customersPickerOpen", "customersProfilePickerOpen", "customersPickerClose", "customersAttach", "customersHintAnswer", "graphcanvasRound", "graphcanvasLabel", "graphcanvasLayout", "graphcanvasSvg", } { fns = append(fns, jsFunc(t, html, name)) } consts := "" for _, name := range []string{"CUSTOMERS_KIND_LABELS", "CUSTOMERS_ADDABLE_KINDS", "CUSTOMERS_LEVEL_LABELS", "CUSTOMERS_LEVEL_PILL", "CUSTOMERS_ORIGIN_LABELS", "CUSTOMERS_REF_KIND_LABELS", + "CUSTOMERS_REF_GH", "CUSTOMERS_REF_WORDS", "CUSTOMERS_GROUP_SHOWN", "CUSTOMERS_SUGGESTED_GROUPS", "CUSTOMERS_OTHER_GROUP", "CUSTOMERS_KIND_ICONS", "GRAPHCANVAS_W", "GRAPHCANVAS_H", "GRAPHCANVAS_RING_ARTEFACT", "GRAPHCANVAS_RING_PEOPLE", "GRAPHCANVAS_MAX_ARTEFACTS", "GRAPHCANVAS_LABEL_MAX"} { consts += jsConstBlock(t, html, name) + "\n" } script := consts + ` const CUSTOMERS_EVIDENCE_SHOWN = 5; let _customersData = null; +let _customersOpen = null; +let _customersUi = { open: {}, expanded: {}, picker: '', profilePicker: false }; let _customersTimeline = { id: '', nodes: [], next: '', error: '', loading: false }; let _customersGraph = { id: '', on: false, nodes: null, error: '', loading: false }; function escapeHtml(s) { return String(s == null ? '' : s).replace(/&/g, '&').replace(//g, '>').replace(/"/g, '"'); } @@ -132,7 +139,7 @@ must(prof.includes('data-action="customersSatisfactionSet"') && prof.includes('d must(prof.includes('data-action="customersIdentityConfirm"'), 'owner cannot confirm a claimed identity'); must(prof.includes('data-action="customersHintAnswer" data-arg0="h_1" data-arg1="yes"') && prof.includes('data-arg0="h_1" data-arg1="no"') && prof.includes('ada@<x>.org'), 'a suggested-identity hint lacks Yes, No or an escaped identity'); must(!prof.includes('data-arg0="h_2" data-arg1="yes"') && prof.includes('data-arg0="h_2" data-arg1="no"'), 'a customer-to-customer hint offers Yes'); -must(prof.includes('data-action="customersGoalConfirm" data-arg0="g_2"') && prof.includes('gh:issue:o/r#1'), 'a suggested goal lacks Confirm or its evidence'); +must(prof.includes('data-action="customersGoalConfirm" data-arg0="g_2"') && prof.includes('Issue #1') && !prof.includes('gh:issue:o/r#1'), 'a suggested goal lacks Confirm or its readable evidence'); must(!prof.includes('data-action="customersGoalConfirm" data-arg0="g_1"'), 'a confirmed goal offers Confirm'); must(prof.includes('data-arg0="vip" data-arg1="auto"') && !prof.includes('data-arg0="maintainer" data-arg1="auto"'), 'Reset to automatic must show on manual tags only'); must(!prof.includes('data-arg0="hive_user:ada"'), 'the hive user identity offers Remove'); @@ -207,6 +214,7 @@ must(customersGraphBodyHtml(person).includes('Nothing to draw yet.'), 'an empty _customersGraph = { id: 'p_abc', on: true, nodes: null, error: 'Could not load the graph: boom', loading: false }; must(customersGraphBodyHtml(person).includes('Could not load the graph: boom'), 'a graph error is not shown'); _customersGraph = { id: '', on: false, nodes: null, error: '', loading: false }; +` + customersLayoutNoiseScript + ` must(customersLevelPill('unknown') === '' && customersLevelPill('satisfied').includes('data-status="ok"'), 'level pill'); ` cmd := exec.Command(node, "-e", script) @@ -291,3 +299,127 @@ func TestFeaturesTab_CustomersToggleMarkup(t *testing.T) { } } } + +// customersLayoutNoiseScript is the part of TestCustomersViewGates that pins +// the Customers layout and noise rules (hivecommons/hive#18742): no raw +// references on a suggested row, readable evidence links, at most five, a +// group per source with "Show N more", long keys truncated rather than +// wrapped, no "0 goals", the "me" marker as a badge, and the Suggested group +// staying open (with its expansion and the focus moving on) after an accept, +// a dismiss, an attach or a "Same person?" answer. +const customersLayoutNoiseScript = ` +// Raw references never print; links are readable and bounded. +const longKey = 'b43dc28a888d316aa1fe4a47bf3038cd1bca7bbb2b5cdbf5e7ecb9cc10672a95@group.calendar.google.com'; +const sug = { id: 's_1', kind: 'email', value: longKey, counts: { added: 1, organised: 1 }, last_seen: '2026-11-17T10:00:00Z', + evidence: ['gh:issue:hivecommons/hive#18726', 'gh:pr:hivecommons/hive#18738', 'event:93d1acd2360e10c0', 'inbox:email:m1', 'meeting:m2', 'gh:pr:hivecommons/hive#1'] }; +let row = customersSuggestionRowHtml(sug); +must(!row.includes('gh:issue') && !row.includes('gh:pr') && !row.includes('event:93d1') && !row.includes('customers-evidence'), 'a raw reference is printed on a suggested row: ' + row); +must(row.includes('Why is this suggested?') && row.includes('
Issue #18726') && row.includes('>PR #18738'), 'issue and PR links: ' + row); +must(row.includes('calendar invite') && row.includes('mail'), 'an event or mail is not named in words'); +must((row.match(/(calendar invite|mail|meeting|inbox file)<\/span>/g) || []).length <= CUSTOMERS_EVIDENCE_SHOWN, 'more than five references shown'); +must(!row.includes('#1'), 'the sixth reference was shown'); +must(row.includes('rel="noopener noreferrer"') && row.includes('target="_blank"'), 'links must not leak the opener'); +must(row.includes('class="customers-name" title="' + longKey + '"'), 'a long key lacks its full-value tooltip'); +must(row.includes('data-action="customersAccept"') && row.includes('data-action="customersPickerOpen"') && row.includes('Add to existing') && row.includes('data-action="customersDismiss"'), 'a suggested row lacks Accept, Add to existing or Dismiss'); +must(customersEvidenceLabel('gh:pr:bad repo#1').includes('activity') && !customersEvidenceLabel('gh:pr:o/r#1">