diff --git a/changelog.d/added-15051-presence-indicator.md b/changelog.d/added-15051-presence-indicator.md new file mode 100644 index 0000000000..9814ad52ed --- /dev/null +++ b/changelog.d/added-15051-presence-indicator.md @@ -0,0 +1 @@ +- Activity Monitor: the waiting-on pill carries a presence indicator for the person the hive waits on ([#15051](https://github.com/hivecommons/hive/issues/15051)) — a filled dot when their clanker is online (the hive waits), a filled square when it is offline (adoption is next; the tooltip says when: "@hanthor's clanker: offline 26h — hive will adopt at 15:10 (in 38m)"), a hollow ring when no clanker is registered ("waiting for a human reply"). Every PR row waiting on a named person (071 / 072 / 017) now carries `presence{login, state, kind, since, last_seen, next, adopt_at}` from the same hub lookup and clock adoption uses; the Needs-human popover and per-PR sub-rows show the same indicator. Shape, not colour alone, carries the state; nothing moves under `prefers-reduced-motion`. diff --git a/src/docs/dashboard-sections.md b/src/docs/dashboard-sections.md index c40c1865bd..e3eb89e9bd 100644 --- a/src/docs/dashboard-sections.md +++ b/src/docs/dashboard-sections.md @@ -684,6 +684,8 @@ Fed by `GET /api/stage-tracker`. Every issue and pull request follows the same p **Adopted → #N (074 / 085).** An adopted pull request names the hive's superseding copy in its detour word (`adopted_by`). When that copy was closed without merging (hivecommons/hive#15052) the row does not fall back to *Needs human decision*: `adopted_by_state: "closed"` renders "Adopted → #N (closed) · recovering" while the hive opens a fresh copy from the same head, and the caption says so in plain words; once the new copy is on record the word reads "Adopted → #M". If two copies are closed within an hour the hive stops (`adopted_by_state: "closed-twice"`, park reason `adoption-child-closed-twice`): the row reads "Adopted → #N (closed twice) · needs a person" and the popover question asks you to reopen the last copy, give direction, or close the PR. +**Presence indicator on the waiting-on pill.** Every PR row that waits on a named person — `stage/071-needs-author`, `stage/072-returned-to-contributor` (before and after the nudge), `stage/017-possibly-existing` on a PR — carries `presence{login, state: online|offline|unknown, kind: clanker|human, since, last_seen, next: wait|adopt, adopt_at}`, read from the contributor hub's live presence (registered profile + relay heartbeat: the same lookup adoption consults, so the indicator and the adoption text never disagree) and projected through adoption's own clock ([hivecommons/hive#15051](https://github.com/hivecommons/hive/issues/15051)). The pill draws it just before the `@login`: a filled **dot** (`--cue-decision`, a soft breathe; none under `prefers-reduced-motion`) when the person's clanker — their connected contributor agent — is online, tooltip "@Danathar's clanker: online, last seen 2 min ago — hive is waiting for them"; a filled **square** (`--status-error`) when it is offline, "@hanthor's clanker: offline 26h — hive will adopt at 15:10 (in 38m)" (or "— hive is waiting for them" when `ask`/`never`/adoption-off holds the clock); a **hollow ring** when no clanker is registered here, "@zoe: no clanker registered — waiting for a human reply" with the pill reading `waiting on @zoe (human · no clanker)`. Shape, not colour alone, carries the state; the indicator has its own `aria-label` ("@hanthor: clanker offline — hive will adopt at …"). A row with presence but no adoption line (071, a 072 not yet nudged, a human's PR) gets a muted `waiting on @login` pill carrying the indicator; a nudged 072 row keeps its single amber adoption pill with the indicator inside it. The Needs-human popover shows the same line under the question when the waiting person is named, a per-PR sub-row under an issue mirrors it, and the row tooltip adds a `Presence:` line. It refreshes with the tracker like every other pill. + **Blocked pill.** An issue wearing `blocked` because the hive parked it on a pull request — its body carries `` (the review backlog's spin-off issues, `hive-open-issue comment --blocked-on-pr`) — names that PR: the payload carries `blocked_on_pr: {repo, number, url, state}`, the pill reads `blocked on #N` and links to the PR, its tooltip says `Blocked on PR owner/repo#N (open) — lifts when it merges; re-triage if closed unmerged`, the caption reads `Blocked on PR #N — lifts when it merges` instead of `No stage recorded yet`, and the row's title and chevron tooltip carry the blocker too ([#14952](https://github.com/hivecommons/hive/issues/14952): #14863 showed a bare grey pill and "blocked · since 7h" with nothing to say what it waited on). The state (`open`, `merged`, `closed`, or absent when nothing knows) comes only from what the hive already holds — the status snapshot's open PRs, the ForgeState cache, the recent-merge ring — never a GitHub call from the tracker build; a merged or closed-unmerged blocker says so (`merged; the blocked sweep lifts the label next` / `closed unmerged; the blocked sweep re-triages it next`). The server reads the marker from the issue body when it has one, else from the enumeration's `blocked on owner/repo#N` reason, so sidelined rows (which carry only the reason) name it too. A `blocked` issue with neither (a human-applied label) keeps the bare pill. This is distinct from `blocked_on`, the open GitHub "blocked by" dependencies of a sequenced sub-issue ([#14765](https://github.com/hivecommons/hive/issues/14765)); when a row has both, the chevron tooltip lists them together. **New row (`000-new`, the pre-stage state).** Every open issue and pull request in `project.repos` is on the list from the moment GitHub reports it — there is no gap between "opened" and "the hive has an opinion about it" ([#15094](https://github.com/hivecommons/hive/issues/15094)). The `issues.opened` / `pull_request.opened` webhook re-read inserts the item into the status payload straight away (`insertFrontendRepoItem`; the governor side keeps the same row in its cached snapshot so a republish does not drop it), the per-item replay re-applies that insert after a governor republish, and the enumeration poll is the fallback for a missed delivery. Until something places the item — a stage record, a `stage/*` label, a hold, a blocked marker, a bucket other than *reporter triage* / *unclassified* — the row is anchored in the **Open** column with the lit chevron reading **New** (`ham-open-new`, blue ✦ rather than amber) and a caption that names who moves it next and when: `New · waiting for the stage-label pass (→ 010 actionable), then the scanner (next pass in 7m)` for an issue the reporter gate has already admitted, `New · waiting for a maintainer's triage (add `triage/accepted`); the hive's next pass in 7m` for a human contributor's issue the reporter-trust gate is still holding (the label names come from `issues.filter.reporter_trust.untrusted_require_labels`), and `New · waiting for the stage-label pass (→ 050 review pending)` for a pull request. The *since* time is the item's `created_at`; "next pass" is the governor's next kick (`governor.nextKickAt`, so it counts down with the Governor tile and reads *due now* once it has passed). The payload carries it all as `new{since, next_mover (maintainer|hive), next_mover_text, next_pass_at, next_pass_in_seconds, gates[], text}`; the chevron tooltip lists the gates ahead — **triage** (the reporter gate: done when admitted, next when a triage label is still needed), **actionable** (the stage-label pass marks it 010), **claimed** (the scanner claims it, 020) — each marked ✓ done, → next or · later, and the row's actor icon reads *human* while the next mover is a maintainer and *hive* otherwise. A row that already wears a hold, `blocked`, a draft marker or any stage record is never *New*; neither is an issue at `015` once the stage-label pass has written it. diff --git a/src/docs/labels-and-control-signals.md b/src/docs/labels-and-control-signals.md index eca3ebbeb7..deac23a843 100644 --- a/src/docs/labels-and-control-signals.md +++ b/src/docs/labels-and-control-signals.md @@ -925,6 +925,21 @@ When a clanker-authored contributor PR goes red the hive does not just relabel i never adopt, and release an existing adoption of a maintainer's head. Under every setting a human-authored PR (no `author/clanker`) is never adopted. + The activity monitor shows the same presence the adoption rules read, so + the operator can anticipate the next move ([hivecommons/hive#15051](https://github.com/hivecommons/hive/issues/15051)): + every PR row waiting on a named person (071, 072, 017) carries + `presence{login, state, kind, since, last_seen, next, adopt_at}` and + its waiting-on pill an indicator before the `@login` — a filled **dot** + when the author's clanker is online (`next: wait`: the hive waits for + them through the online grace), a filled **square** when it is offline + (`next: adopt`; `adopt_at` is the projection of the rule below, and the + tooltip reads "@hanthor's clanker: offline 26h — hive will adopt at + 15:10 (in 38m)"), a **hollow ring** when no clanker is registered here + (a human's PR: "no clanker registered — waiting for a human reply", pill + `waiting on @zoe (human · no clanker)`; another hive's PR: the + unregistered clock). A held adoption (`ask` / `never`, or + `adoption.enabled: false`) keeps `next: wait` with no `adopt_at`, so the + indicator never promises an adoption the pill text denies. - `reason=contributor-offline` — the author has a contributor profile here and no relay heartbeat within `governor.labels.stage.presence_window`: adopted `governor.labels.stage.adoption.after_offline` (default 15m) diff --git a/src/pkg/dashboard/stage_tracker.go b/src/pkg/dashboard/stage_tracker.go index 4ce934baf9..117f81bc1f 100644 --- a/src/pkg/dashboard/stage_tracker.go +++ b/src/pkg/dashboard/stage_tracker.go @@ -412,6 +412,11 @@ type StageTrackerItem struct { // line the row shows instead of a bare "Returned to contributor" // (hivecommons/hive#14524). Adoption *StageTrackerAdoption `json:"adoption,omitempty"` + // Presence is, on a PR row waiting on a named person, whether that + // person's clanker is online / offline / not registered here and the + // hive's likely next move (wait or adopt, with the adopt-at time), so + // the waiting-on pill can carry an indicator (hivecommons/hive#15051). + Presence *StageTrackerPresence `json:"presence,omitempty"` // ClaimantKind is the author kind of whoever holds the live claim on a // claimed issue (human / clanker / hive), from the worker-claim ledger. ClaimantKind string `json:"claimant_kind,omitempty"` @@ -531,6 +536,8 @@ type StageTrackerLinkedPR struct { // parent shows a compact "↳ #N · under #M" reference instead of a // second identical row (hivecommons/hive#14921 drew twice). DrawnUnder int `json:"drawn_under,omitempty"` + // Presence mirrors the nested PR's own row field (hivecommons/hive#15051). + Presence *StageTrackerPresence `json:"presence,omitempty"` } // StageTrackerHold is the row's hold provenance (stagelabels.HoldProvenance @@ -1690,6 +1697,7 @@ func (s *Server) buildStageTracker(status *StatusPayload, store *stagelabels.Sto presence, maintainerPolicy := s.stageTrackerPresence(), s.stageTrackerMaintainerPolicy() sweep := s.stageTrackerSweepState() workers := stageTrackerWorkersFromStatus(status) + adoptionClock := s.stageTrackerAdoptionClock() finish := func(it *StageTrackerItem, labels []string, stage stagelabels.Stage, rec stagelabels.Record, hasRec bool, draft bool) { // "Needs human decision" is read from the item's current labels, not // a store record that outlived them: once the park label is gone @@ -1761,6 +1769,9 @@ func (s *Server) buildStageTracker(status *StatusPayload, store *stagelabels.Sto it.Caption = stageTrackerAdoptionCaption(it.Caption, it.Adoption) } } + if login := stageTrackerWaitingOn(*it, stage); login != "" { + it.Presence = stageTrackerPresenceFor(*it, login, stage, rec, hasRec, presence, adoptionClock, now) + } base, approver := stagelabels.HumanApprovedReason(it.Reason) it.HumanApprover = approver it.ManualMerge = stageTrackerManualMergeReason(base) @@ -2677,6 +2688,7 @@ func stageTrackerResolveLinkedPRs(items []StageTrackerItem) { lp.StageSince, lp.Caption = pr.StageSince, pr.Caption lp.SentinelAlert, lp.SentinelReason, lp.Head = pr.SentinelAlert, pr.SentinelReason, pr.Head lp.Adoption = pr.Adoption + lp.Presence = pr.Presence lp.HumanApprover, lp.ManualMerge = pr.HumanApprover, pr.ManualMerge lp.HumanMergeReason, lp.HumanMergeReasonText = pr.HumanMergeReason, pr.HumanMergeReasonText lp.BaseRef = pr.BaseRef diff --git a/src/pkg/dashboard/stage_tracker_adoption_test.go b/src/pkg/dashboard/stage_tracker_adoption_test.go index 971a50c48b..7103a6b88b 100644 --- a/src/pkg/dashboard/stage_tracker_adoption_test.go +++ b/src/pkg/dashboard/stage_tracker_adoption_test.go @@ -284,6 +284,7 @@ func TestStageTrackerAdoptionJS(t *testing.T) { jsFunc(t, html, "stageTrackerAdoptOffered"), jsFunc(t, html, "stageTrackerAdoptionChipText"), jsFunc(t, html, "stageTrackerAdoptionChipHtml"), + stageTrackerPresenceJS(t, html), ` const ask = { kind: 'pr', repo: 'hivecommons/hive', number: 14524, stage: 72, stage_label: 'stage/072-returned-to-contributor', author: 'hanthor', labels: [], adoption: { author: 'hanthor', due: true, blocked_by: 'author-is-maintainer', nudges: 2, author_online: false, author_maintainer: true, policy: 'ask', action: 'decide:adopt', text: 'waiting on @hanthor (maintainer, offline 26h) — adopt?' } }; diff --git a/src/pkg/dashboard/stage_tracker_presence.go b/src/pkg/dashboard/stage_tracker_presence.go new file mode 100644 index 0000000000..6deeba6a11 --- /dev/null +++ b/src/pkg/dashboard/stage_tracker_presence.go @@ -0,0 +1,189 @@ +package dashboard + +import ( + "strings" + "time" + + "github.com/hivecommons/hive/pkg/config" + "github.com/hivecommons/hive/pkg/github/automerge" + "github.com/hivecommons/hive/pkg/stagelabels" +) + +// Presence on a waiting-on row (hivecommons/hive#15051): when a PR row +// waits on a named person (071 Needs author, 072 Returned to contributor, +// 017 Possibly existing on a PR), the operator wants to know whether that +// person's clanker — their connected contributor agent — is there to +// answer, because that decides the hive's next move: a connected clanker +// means the hive waits; a disconnected one means adoption is the likely +// next move and the row can say when; no registered clanker means a human +// has to reply. The lookup is the one the adoption engine consults +// (automerge.ContributorPresenceSource via stageTrackerPresence) and the +// adopt-at clock follows automerge.adoptionDue's rules, so the indicator +// never contradicts the adoption text on the same row. + +// Presence states and kinds on the wire. +const ( + presenceStateOnline = "online" + presenceStateOffline = "offline" + presenceStateUnknown = "unknown" + + presenceKindClanker = "clanker" + presenceKindHuman = "human" + + presenceNextWait = "wait" + presenceNextAdopt = "adopt" +) + +// StageTrackerPresence is the `presence` field of a row that waits on a +// person. +type StageTrackerPresence struct { + // Login is the GitHub login the row waits on. + Login string `json:"login"` + // State is online / offline (a registered clanker, by its heartbeat) + // or unknown (no clanker registered here for this login). + State string `json:"state"` + // Kind is clanker when a contributor clanker is registered for the + // login or the PR was authored by one, else human. + Kind string `json:"kind"` + // Since is when the wait on this person began: the first nudge when + // one went out, else when the row entered its stage. + Since *time.Time `json:"since,omitempty"` + // LastSeen is the clanker's freshest heartbeat (absent when never seen). + LastSeen *time.Time `json:"last_seen,omitempty"` + // Next is the hive's likely next move: wait (for the person) or adopt + // (the adoption clock is running on a disconnected or unregistered + // clanker and nothing holds it). + Next string `json:"next"` + // AdoptAt is when the adoption engine would judge adoption due at the + // current head, when its clock is running (072, nudged, not held). + AdoptAt *time.Time `json:"adopt_at,omitempty"` +} + +// stageTrackerAdoptionClock is the slice of governor.labels.stage the +// adopt-at projection needs, mirroring what cmd/hive hands the adoption +// engine as automerge.StageLabelPolicy. +type stageTrackerAdoptionClock struct { + Enabled bool + GraceOnline time.Duration + AdoptAfterOffline time.Duration + AdoptAfterUnregistered time.Duration +} + +func (s *Server) stageTrackerAdoptionClock() stageTrackerAdoptionClock { + var stage config.StageLabelsConfig + if s != nil && s.deps != nil && s.deps.Config != nil { + stage = s.deps.Config.Governor.Labels.Stage + } + return stageTrackerAdoptionClock{ + Enabled: stage.Adoption.IsEnabled(), + GraceOnline: stage.EffectiveContributorGraceOnline(), + AdoptAfterOffline: stage.Adoption.EffectiveAfterOffline(), + AdoptAfterUnregistered: stage.Adoption.EffectiveAfterUnregistered(), + } +} + +// stageTrackerWaitingOn names the person a PR row waits on: its author at +// the stages whose caption says "@author must act". "" when the row waits +// on the hive, a gate or an unnamed maintainer. +func stageTrackerWaitingOn(it StageTrackerItem, stage stagelabels.Stage) string { + if it.Kind != "pr" || strings.TrimSpace(it.Author) == "" { + return "" + } + switch stage { + case stagelabels.NeedsAuthor, stagelabels.ReturnedToContributor, stagelabels.PossiblyExisting: + return strings.TrimSpace(it.Author) + } + return "" +} + +// stageTrackerPresenceFor builds the `presence` field for a row waiting on +// login. presence is the live lookup (nil when the server has none: the +// state is then unknown); rec is the row's stage record for the nudge +// clock; clock is the adoption timing policy. +func stageTrackerPresenceFor(it StageTrackerItem, login string, stage stagelabels.Stage, rec stagelabels.Record, hasRec bool, presence func(string) (automerge.ContributorPresence, bool), clock stageTrackerAdoptionClock, now time.Time) *StageTrackerPresence { + if login == "" { + return nil + } + out := &StageTrackerPresence{Login: login, State: presenceStateUnknown, Kind: presenceKindHuman, Next: presenceNextWait} + var p automerge.ContributorPresence + if presence != nil { + if got, ok := presence(login); ok { + p = got + } + } + switch { + case p.Registered && p.Online: + out.State, out.Kind = presenceStateOnline, presenceKindClanker + case p.Registered: + out.State, out.Kind = presenceStateOffline, presenceKindClanker + case it.AuthorKind != "" && it.AuthorKind != authorKindHuman: + // A clanker's PR whose author has no profile here: another hive + // posted it. Adoption treats it as unregistered. + out.Kind = presenceKindClanker + } + if !p.LastSeen.IsZero() { + t := p.LastSeen + out.LastSeen = &t + } + start := time.Time{} + if hasRec && rec.NudgeCount > 0 && !rec.NudgeStart().IsZero() { + start = rec.NudgeStart() + } else if it.StageSince != nil { + start = *it.StageSince + } + if !start.IsZero() { + t := start + out.Since = &t + } + // The adoption clock runs only where adoption itself does: a nudged + // clanker PR at 072 whose head has not moved since the nudge, not yet + // adopted, with nothing holding it. + if stage != stagelabels.ReturnedToContributor || !clock.Enabled || it.AuthorKind == authorKindHuman || out.Kind != presenceKindClanker { + return out + } + if !hasRec || rec.NudgeCount == 0 || rec.NudgeStart().IsZero() { + return out + } + head := it.Head + if head == "" { + head = rec.NudgeHead + } + if rec.NudgeHead != "" && head != rec.NudgeHead { + return out + } + if rec.AdoptedHead != "" && (rec.Adopted(head) || rec.AdoptedInPlace()) { + return out + } + if rec.AdoptionBlocked(head) != "" { + // Held (maintainer_policy ask / never): the adoption text says so; + // the engine will not adopt on its own. + return out + } + nudged := rec.NudgeStart() + var at time.Time + switch out.State { + case presenceStateOnline: + // Mirrors adoptionDue: an online clanker keeps the online grace; the + // hive waits for it meanwhile. + at = nudged.Add(orDefault(clock.GraceOnline, config.DefaultContributorGraceOnline)) + case presenceStateOffline: + since := nudged + if p.LastSeen.After(since) { + since = p.LastSeen + } + at = since.Add(orDefault(clock.AdoptAfterOffline, config.DefaultAdoptAfterOffline)) + out.Next = presenceNextAdopt + default: + at = nudged.Add(orDefault(clock.AdoptAfterUnregistered, config.DefaultAdoptAfterUnregistered)) + out.Next = presenceNextAdopt + } + out.AdoptAt = &at + return out +} + +func orDefault(d, def time.Duration) time.Duration { + if d <= 0 { + return def + } + return d +} diff --git a/src/pkg/dashboard/stage_tracker_presence.test.js b/src/pkg/dashboard/stage_tracker_presence.test.js new file mode 100644 index 0000000000..e82d64ff77 --- /dev/null +++ b/src/pkg/dashboard/stage_tracker_presence.test.js @@ -0,0 +1,141 @@ +// The presence indicator on the Activity Monitor's waiting-on pill +// (hivecommons/hive#15051): a row waiting on a person says whether their +// clanker is online (dot), offline (square) or not registered (hollow ring), +// and what the hive does next (wait / adopt at …). The helpers are lifted +// out of index.html so this runs against the shipped source; the fixtures +// are the live /api/stage-tracker shape with the new `presence` field. +const test = require('node:test'); +const assert = require('node:assert'); +const fs = require('node:fs'); +const path = require('node:path'); + +const html = fs.readFileSync(path.join(__dirname, 'static', 'index.html'), 'utf8'); + +function pick(re, what) { + const m = html.match(re); + assert.ok(m, what + ' not found in index.html'); + return m[0]; +} + +const src = [ + pick(/function agentNowAgo\(ms\) \{[\s\S]*?\n \}\n/, 'agentNowAgo'), + pick(/function stageTrackerAdoptionTip\(item\) \{[\s\S]*?\n \}\n/, 'stageTrackerAdoptionTip'), + pick(/function stageTrackerAdoptOffered\(item\) \{[\s\S]*?\n \}\n/, 'stageTrackerAdoptOffered'), + pick(/function stageTrackerAdoptionChipText\(item\) \{[\s\S]*?\n \}\n/, 'stageTrackerAdoptionChipText'), + pick(/function stageTrackerAdoptionChipHtml\(item\) \{[\s\S]*?\n \}\n/, 'stageTrackerAdoptionChipHtml'), + pick(/const STAGE_TRACKER_PRESENCE_STATES = \[[^\n]*\];/, 'STAGE_TRACKER_PRESENCE_STATES'), + pick(/const STAGE_TRACKER_PRESENCE_WORDS = \{[^\n]*\};/, 'STAGE_TRACKER_PRESENCE_WORDS'), + pick(/function stageTrackerPresenceOf\(item\) \{[\s\S]*?\n \}\n/, 'stageTrackerPresenceOf'), + pick(/function stageTrackerPresenceGone\(p, nowMs\) \{[\s\S]*?\n \}\n/, 'stageTrackerPresenceGone'), + pick(/function stageTrackerPresenceAdoptAt\(p, nowMs\) \{[\s\S]*?\n \}\n/, 'stageTrackerPresenceAdoptAt'), + pick(/function stageTrackerPresenceTip\(item, nowMs\) \{[\s\S]*?\n \}\n/, 'stageTrackerPresenceTip'), + pick(/function stageTrackerPresenceAria\(item, nowMs\) \{[\s\S]*?\n \}\n/, 'stageTrackerPresenceAria'), + pick(/function stageTrackerPresenceDotHtml\(item, nowMs\) \{[\s\S]*?\n \}\n/, 'stageTrackerPresenceDotHtml'), + pick(/function stageTrackerPresenceInPillHtml\(item, text\) \{[\s\S]*?\n \}\n/, 'stageTrackerPresenceInPillHtml'), + pick(/function stageTrackerPresenceChipText\(item\) \{[\s\S]*?\n \}\n/, 'stageTrackerPresenceChipText'), + pick(/function stageTrackerPresenceChipHtml\(item\) \{[\s\S]*?\n \}\n/, 'stageTrackerPresenceChipHtml'), +].join('\n'); + +// The clock the tooltips are rendered against, and the stubs the lifted +// helpers lean on (HTML escaping, the display-time-zone clock). +const NOW = Date.parse('2026-10-28T14:32:00Z'); +const stubs = ` + const esc = s => String(s).replace(/&/g, '&').replace(//g, '>').replace(/"/g, '"'); + const agentNowClockTime = (ms) => new Date(ms).toISOString().slice(11, 16) + ' UTC'; + const stageTrackerDecisionOf = () => null; + Date.now = () => ${NOW}; +`; +const api = new Function(stubs + src + `; return { of: stageTrackerPresenceOf, tip: stageTrackerPresenceTip, aria: stageTrackerPresenceAria, dot: stageTrackerPresenceDotHtml, + inPill: stageTrackerPresenceInPillHtml, chipText: stageTrackerPresenceChipText, chip: stageTrackerPresenceChipHtml, adoptionChip: stageTrackerAdoptionChipHtml };`)(); + +const iso = ms => new Date(ms).toISOString(); +const MIN = 60000, HOUR = 60 * MIN; + +// hivecommons/hive#14989 as the tracker emits it with @Danathar's clanker connected. +const online14989 = { repo: 'hivecommons/hive', number: 14989, kind: 'pr', stage: 71, author: 'Danathar', author_kind: 'clanker', + presence: { login: 'Danathar', state: 'online', kind: 'clanker', since: iso(NOW - 3 * HOUR), last_seen: iso(NOW - 2 * MIN), next: 'wait' } }; +// hivecommons/hive#14524 at 072, nudged, @hanthor's clanker gone 26h, adoption due in 38m. +const offline14524 = { repo: 'hivecommons/hive', number: 14524, kind: 'pr', stage: 72, author: 'hanthor', author_kind: 'clanker', + adoption: { author: 'hanthor', due: false, since: iso(NOW - 26 * HOUR), nudges: 2, author_online: false, author_registered: true, policy: 'adopt', text: 'waiting on @hanthor (offline 26h, 2 nudges)' }, + presence: { login: 'hanthor', state: 'offline', kind: 'clanker', since: iso(NOW - 26 * HOUR), last_seen: iso(NOW - 26 * HOUR), next: 'adopt', adopt_at: iso(NOW + 38 * MIN) } }; +// A human's PR at 071: nobody's clanker to wait for. +const human = { repo: 'hivecommons/hive', number: 15000, kind: 'pr', stage: 71, author: 'zoe', author_kind: 'human', + presence: { login: 'zoe', state: 'unknown', kind: 'human', since: iso(NOW - 40 * MIN), next: 'wait' } }; + +test('online clanker: filled dot, "hive is waiting for them", last seen in words', () => { + assert.strictEqual(api.tip(online14989, NOW), "@Danathar's clanker: online, last seen 2 min ago — hive is waiting for them"); + const dot = api.dot(online14989, NOW); + assert.match(dot, /class="ham-presence ham-presence-online"/); + assert.match(dot, /role="img"/); + assert.match(dot, /aria-label="@Danathar: clanker online — hive is waiting for them"/); + assert.match(dot, /data-ham-presence="online"/); + // The online grace still projects an adopt-at: the tooltip says so after the wait. + const graced = Object.assign({}, online14989, { presence: Object.assign({}, online14989.presence, { adopt_at: iso(NOW + 2 * HOUR) }) }); + assert.strictEqual(api.tip(graced, NOW), "@Danathar's clanker: online, last seen 2 min ago — hive is waiting for them; adopts at 16:32 UTC (in 2h) if nothing moves"); +}); + +test('offline clanker: filled square, offline span, adopt-at clock with countdown', () => { + assert.strictEqual(api.tip(offline14524, NOW), "@hanthor's clanker: offline 26h — hive will adopt at 15:10 UTC (in 38m)"); + assert.match(api.dot(offline14524, NOW), /ham-presence-offline/); + assert.match(api.dot(offline14524, NOW), /aria-label="@hanthor: clanker offline — hive will adopt at 15:10 UTC \(in 38m\)"/); + // Past due. + const due = Object.assign({}, offline14524, { presence: Object.assign({}, offline14524.presence, { adopt_at: iso(NOW - MIN) }) }); + assert.strictEqual(api.tip(due, NOW), "@hanthor's clanker: offline 26h — hive will adopt due now"); + // Held (maintainer_policy ask): no adopt_at, next=wait — the dot does not promise an adoption the text denies. + const held = Object.assign({}, offline14524, { presence: Object.assign({}, offline14524.presence, { next: 'wait', adopt_at: '' }) }); + assert.strictEqual(api.tip(held, NOW), "@hanthor's clanker: offline 26h — hive is waiting for them"); + // Long absences read in days. + const days = Object.assign({}, offline14524, { presence: Object.assign({}, offline14524.presence, { since: iso(NOW - 80 * HOUR), last_seen: iso(NOW - 80 * HOUR) }) }); + assert.match(api.tip(days, NOW), /offline 3d — /); +}); + +test('human without a clanker: hollow ring, "waiting for a human reply", pill says human · no clanker', () => { + assert.strictEqual(api.tip(human, NOW), '@zoe: no clanker registered — waiting for a human reply'); + const dot = api.dot(human, NOW); + assert.match(dot, /ham-presence-unknown/); + assert.match(dot, /aria-label="@zoe: human, no clanker — waiting for a human reply"/); + assert.strictEqual(api.chipText(human), 'waiting on @zoe (human · no clanker)'); + const chip = api.chip(human); + assert.match(chip, /^/); + assert.match(chip, /waiting on ]*><\/span>@zoe \(human · no clanker\)<\/span>$/); + // An unregistered clanker (another hive's PR) is unknown too, but adoption's clock runs. + const foreign = { presence: { login: 'bot-x', state: 'unknown', kind: 'clanker', since: iso(NOW - 10 * MIN), next: 'adopt', adopt_at: iso(NOW + 5 * MIN) } }; + assert.strictEqual(api.tip(foreign, NOW), '@bot-x: no clanker registered here — hive will adopt at 14:37 UTC (in 5m)'); +}); + +test('the indicator sits inside the adoption pill just before the @login and its line joins the tooltip', () => { + const chip = api.adoptionChip(offline14524); + assert.match(chip, /^]*><\/span>@hanthor<\/span>$/); + // A 071 row has no adoption line: the muted waiting pill carries the dot instead, never both. + assert.strictEqual(api.chip(offline14524), '', 'no second pill beside the adoption one'); + assert.match(api.chip(online14989), /^]*>waiting on ]*><\/span>@Danathar<\/span>$/); + // Text naming nobody gets the indicator in front. + assert.match(api.inPill(online14989, 'adopt?'), /^]*><\/span>adopt\?$/); +}); + +test('rows without presence, or with a malformed one, render as before', () => { + assert.strictEqual(api.of({ kind: 'pr' }), null); + assert.strictEqual(api.of({ presence: {} }), null); + assert.strictEqual(api.of({ presence: { state: 'online' } }), null, 'a login is required'); + assert.strictEqual(api.of(null), null); + assert.strictEqual(api.tip({ kind: 'pr' }, NOW), ''); + assert.strictEqual(api.dot({}, NOW), ''); + assert.strictEqual(api.chip({ kind: 'pr', stage: 71 }), ''); + assert.strictEqual(api.inPill({}, 'waiting on @x'), 'waiting on @x'); + // Unknown words fall back safely. + const odd = api.of({ presence: { login: 'q', state: 'asleep', kind: 'robot', next: 'later' } }); + assert.deepStrictEqual([odd.state, odd.kind, odd.next], ['unknown', 'human', 'wait']); + // The adoption pill without presence is unchanged. + const bare = { kind: 'pr', adoption: { author: 'hanthor', text: 'waiting on @hanthor (online, 1 nudge)' } }; + assert.strictEqual(api.adoptionChip(bare), 'waiting on @hanthor'); +}); + +test('style ratchet: the indicator uses classes and tokens, no inline styles; reduced motion stills the breathe', () => { + assert.ok(!/ham-presence[^\n]*style="/.test(html), 'no inline style on the indicator'); + assert.match(html, /\.ham-presence-online \{[^\n]*var\(--cue-decision\)/); + assert.match(html, /\.ham-presence-offline \{[^\n]*var\(--status-error\)/); + assert.match(html, /\.ham-presence-unknown \{[^\n]*border: var\(--line-width\) solid var\(--text-faint\)[^\n]*background: transparent/); + assert.match(html, /@media \(prefers-reduced-motion: reduce\) \{ \.ham-presence-online \{ animation: none; \} \}/); +}); diff --git a/src/pkg/dashboard/stage_tracker_presence_test.go b/src/pkg/dashboard/stage_tracker_presence_test.go new file mode 100644 index 0000000000..28fc5933e7 --- /dev/null +++ b/src/pkg/dashboard/stage_tracker_presence_test.go @@ -0,0 +1,325 @@ +package dashboard + +import ( + "encoding/json" + "strings" + "testing" + "time" + + "github.com/hivecommons/hive/pkg/config" + "github.com/hivecommons/hive/pkg/github" + "github.com/hivecommons/hive/pkg/github/automerge" + "github.com/hivecommons/hive/pkg/stagelabels" +) + +// hivecommons/hive#15051: a row waiting on a person carries `presence` — +// whether their clanker is online / offline / unregistered and whether the +// hive's next move is to wait or to adopt (and when) — derived from the +// same lookup and the same clock the adoption engine uses. + +func presenceOf(t *testing.T, s *Server, store *stagelabels.Store, status *StatusPayload, now time.Time, number int) *StageTrackerPresence { + t.Helper() + return trackerItem(t, s.buildStageTracker(status, store, now), "pr", number).Presence +} + +// Online clanker at 072 after the nudge: green, next=wait, adopt_at at the +// online grace (2h after the first nudge), the same as adoptionDue. +func TestStageTrackerPresenceOnlineWaits(t *testing.T) { + now := time.Date(2026, 10, 28, 16, 0, 0, 0, time.UTC) + seen := now.Add(-2 * time.Minute) + s, store, status := adoptionFixture(t, now, "", func(login string) (automerge.ContributorPresence, bool) { + return automerge.ContributorPresence{Registered: true, Online: true, LastSeen: seen}, true + }) + p := presenceOf(t, s, store, status, now, 14524) + if p == nil { + t.Fatal("no presence on a 072 row") + } + if p.Login != "hanthor" || p.State != "online" || p.Kind != "clanker" || p.Next != "wait" { + t.Fatalf("presence = %+v", p) + } + if p.LastSeen == nil || !p.LastSeen.Equal(seen) { + t.Fatalf("last_seen = %v", p.LastSeen) + } + if p.Since == nil || !p.Since.Equal(now.Add(-26*time.Hour)) { + t.Fatalf("since (first nudge) = %v", p.Since) + } + if p.AdoptAt == nil || !p.AdoptAt.Equal(now.Add(-26*time.Hour).Add(config.DefaultContributorGraceOnline)) { + t.Fatalf("adopt_at = %v", p.AdoptAt) + } + raw, _ := json.Marshal(trackerItem(t, s.buildStageTracker(status, store, now), "pr", 14524)) + for _, want := range []string{`"presence":{`, `"login":"hanthor"`, `"state":"online"`, `"kind":"clanker"`, `"next":"wait"`, `"adopt_at":"`} { + if !strings.Contains(string(raw), want) { + t.Errorf("payload lacks %s: %s", want, raw) + } + } +} + +// Offline clanker: red square, next=adopt, adopt_at = last heartbeat (when +// later than the nudge) + after_offline — adoptionDue's offline rule. +func TestStageTrackerPresenceOfflineAdopts(t *testing.T) { + now := time.Date(2026, 10, 28, 16, 0, 0, 0, time.UTC) + seen := now.Add(-3 * time.Hour) + s, store, status := adoptionFixture(t, now, "", offlinePresence(seen)) + s.deps.Config.Governor.Labels.Stage.Adoption.AfterOffline = "4h" + p := presenceOf(t, s, store, status, now, 14524) + if p == nil || p.State != "offline" || p.Kind != "clanker" || p.Next != "adopt" { + t.Fatalf("presence = %+v", p) + } + if p.AdoptAt == nil || !p.AdoptAt.Equal(seen.Add(4*time.Hour)) { + t.Fatalf("adopt_at = %v, want last_seen+4h", p.AdoptAt) + } + // A heartbeat older than the first nudge: the clock counts from the nudge. + s.presenceLookup = offlinePresence(now.Add(-40 * time.Hour)) + if p = presenceOf(t, s, store, status, now, 14524); p.AdoptAt == nil || !p.AdoptAt.Equal(now.Add(-26*time.Hour).Add(4*time.Hour)) { + t.Fatalf("adopt_at = %v, want nudge+4h", p.AdoptAt) + } + // The adoption text on the same row agrees: offline, no hold. + if a := trackerItem(t, s.buildStageTracker(status, store, now), "pr", 14524).Adoption; a == nil || a.AuthorOnline || a.BlockedBy != "" { + t.Fatalf("adoption disagrees with presence: %+v", a) + } +} + +// A clanker PR whose author has no profile here: unknown (grey hollow), +// kind clanker, adoption after after_unregistered from the first nudge. +func TestStageTrackerPresenceUnregisteredClanker(t *testing.T) { + now := time.Date(2026, 10, 28, 16, 0, 0, 0, time.UTC) + s, store, status := adoptionFixture(t, now, "", func(string) (automerge.ContributorPresence, bool) { + return automerge.ContributorPresence{}, true + }) + p := presenceOf(t, s, store, status, now, 14524) + if p == nil || p.State != "unknown" || p.Kind != "clanker" || p.Next != "adopt" || p.LastSeen != nil { + t.Fatalf("presence = %+v", p) + } + if p.AdoptAt == nil || !p.AdoptAt.Equal(now.Add(-26*time.Hour).Add(config.DefaultAdoptAfterUnregistered)) { + t.Fatalf("adopt_at = %v", p.AdoptAt) + } + // No lookup at all (no contribute hub): unknown too, and still a clanker. + s.presenceLookup = nil + if p = presenceOf(t, s, store, status, now, 14524); p == nil || p.State != "unknown" || p.Kind != "clanker" { + t.Fatalf("presence without a hub = %+v", p) + } +} + +// Held adoption (maintainer_policy ask / never): the engine will not adopt +// on its own, so next stays wait and no adopt_at is projected — the pill's +// "adopt?" text and the dot never disagree. +func TestStageTrackerPresenceHeldAdoptionWaits(t *testing.T) { + now := time.Date(2026, 10, 28, 16, 0, 0, 0, time.UTC) + s, store, status := adoptionFixture(t, now, config.AdoptionMaintainerPolicyAsk, offlinePresence(now.Add(-26*time.Hour))) + store.NoteAdoptionBlocked(stagelabels.Key("hivecommons/hive", 14524), "feed", stagelabels.AdoptBlockedAuthorMaintainer, now.Add(-25*time.Hour)) + p := presenceOf(t, s, store, status, now, 14524) + if p == nil || p.State != "offline" || p.Next != "wait" || p.AdoptAt != nil { + t.Fatalf("presence = %+v", p) + } + // Adoption switched off: same. + off := false + s2, store2, status2 := adoptionFixture(t, now, "", offlinePresence(now.Add(-26*time.Hour))) + s2.deps.Config.Governor.Labels.Stage.Adoption.Enabled = &off + if p = presenceOf(t, s2, store2, status2, now, 14524); p == nil || p.Next != "wait" || p.AdoptAt != nil { + t.Fatalf("presence with adoption off = %+v", p) + } +} + +// A human's PR is never adopted: kind human, state unknown (no clanker), +// next=wait, no adopt_at — on 071 as well as 072, where there is no +// adoption payload at all. +func TestStageTrackerPresenceHumanAuthor(t *testing.T) { + now := time.Date(2026, 10, 28, 16, 0, 0, 0, time.UTC) + s := newTestServer() + clock := now + store := stagelabels.NewStore("", func() time.Time { return clock }) + s.stageStore = store + s.presenceLookup = func(string) (automerge.ContributorPresence, bool) { return automerge.ContributorPresence{}, true } + s.deps = &Dependencies{Config: &config.Config{}} + clock = now.Add(-3 * time.Hour) + store.Observe(stagelabels.Key("hivecommons/hive", 14990), stagelabels.NeedsAuthor, "changes-requested") + store.Observe(stagelabels.Key("hivecommons/hive", 14991), stagelabels.ReturnedToContributor, "check-failing:ci") + clock = now + status := minimalPayload() + status.HiveID = "hive" + status.Repos = []FrontendRepo{{ + Name: "hive", Full: "hivecommons/hive", + OpenPrs: []any{ + FrontendPR{PullRequest: github.PullRequest{Number: 14990, Title: "Docs", Author: "zoe", HeadSHA: "aaa", Labels: []string{"stage/071-needs-author", "author/human"}}}, + FrontendPR{PullRequest: github.PullRequest{Number: 14991, Title: "Fix", Author: "zoe", HeadSHA: "bbb", Labels: []string{"stage/072-returned-to-contributor", "author/human"}}}, + }, + }} + s.UpdateStatus(status) + for _, n := range []int{14990, 14991} { + it := trackerItem(t, s.buildStageTracker(status, store, now), "pr", n) + p := it.Presence + if p == nil || p.Login != "zoe" || p.State != "unknown" || p.Kind != "human" || p.Next != "wait" || p.AdoptAt != nil { + t.Fatalf("#%d presence = %+v", n, p) + } + if p.Since == nil || !p.Since.Equal(now.Add(-3*time.Hour)) { + t.Fatalf("#%d since (stage entry) = %v", n, p.Since) + } + if it.Adoption != nil { + t.Fatalf("#%d human PR carries adoption: %+v", n, it.Adoption) + } + } + // A human who does run a registered clanker reads as a clanker. + s.presenceLookup = func(string) (automerge.ContributorPresence, bool) { + return automerge.ContributorPresence{Registered: true, Online: true, LastSeen: now}, true + } + if p := presenceOf(t, s, store, status, now, 14990); p == nil || p.State != "online" || p.Kind != "clanker" || p.Next != "wait" || p.AdoptAt != nil { + t.Fatalf("registered human presence = %+v", p) + } +} + +// Rows that wait on the hive or a gate carry no presence; an issue never +// does, but its sub-row mirrors the nested PR's. +func TestStageTrackerPresenceOnlyWhereAPersonIsWaitedOn(t *testing.T) { + now := time.Date(2026, 10, 28, 16, 0, 0, 0, time.UTC) + s := newTestServer() + clock := now + store := stagelabels.NewStore("", func() time.Time { return clock }) + s.stageStore = store + s.presenceLookup = func(string) (automerge.ContributorPresence, bool) { + return automerge.ContributorPresence{Registered: true, Online: true, LastSeen: now}, true + } + s.deps = &Dependencies{Config: &config.Config{}} + store.Observe(stagelabels.Key("hivecommons/hive", 14989), stagelabels.ReviewPending, "review gate: no review bundle") + store.Observe(stagelabels.Key("hivecommons/hive", 14992), stagelabels.NeedsAuthor, "changes-requested") + status := minimalPayload() + status.HiveID = "hive" + status.Repos = []FrontendRepo{{ + Name: "hive", Full: "hivecommons/hive", + ActionableIssues: []any{github.Issue{Number: 14986, Title: "Issue", Author: "clubanderson", AuthorIsHuman: true, Labels: []string{"stage/040-covered-by-pr"}}}, + OpenPrs: []any{ + FrontendPR{PullRequest: github.PullRequest{Number: 14989, Title: "Review", Author: "Danathar", HeadSHA: "ccc", Labels: []string{"stage/050-review-pending", "author/clanker"}}}, + FrontendPR{PullRequest: github.PullRequest{Number: 14992, Title: "Fix 14986", Author: "Danathar", HeadSHA: "ddd", Labels: []string{"stage/071-needs-author", "author/clanker"}, LinkedIssues: []github.PRLinkedIssue{{Number: 14986}}}}, + }, + }} + s.UpdateStatus(status) + tr := s.buildStageTracker(status, store, now) + if p := trackerItem(t, tr, "pr", 14989).Presence; p != nil { + t.Fatalf("review-pending row waits on the swarm, not a person: %+v", p) + } + pr := trackerItem(t, tr, "pr", 14992) + if pr.Presence == nil || pr.Presence.Login != "Danathar" || pr.Presence.State != "online" { + t.Fatalf("071 presence = %+v", pr.Presence) + } + issue := trackerItem(t, tr, "issue", 14986) + if issue.Presence != nil { + t.Fatalf("issue row carries presence: %+v", issue.Presence) + } + var mirrored *StageTrackerPresence + for _, lp := range issue.LinkedPRs { + if lp.Number == 14992 { + mirrored = lp.Presence + } + } + if mirrored == nil || mirrored.Login != "Danathar" || mirrored.State != "online" { + t.Fatalf("sub-row presence = %+v (linked %+v)", mirrored, issue.LinkedPRs) + } +} + +// stageTrackerPresenceJS lifts the SPA's presence helpers (and the clock +// words they lean on) out of index.html for the node-fed scripts. +func stageTrackerPresenceJS(t *testing.T, html string) string { + t.Helper() + return strings.Join([]string{ + jsFunc(t, html, "agentNowAgo"), + jsFunc(t, html, "agentNowClockTime"), + jsConstLine(t, html, "STAGE_TRACKER_PRESENCE_STATES"), + jsConstLine(t, html, "STAGE_TRACKER_PRESENCE_WORDS"), + jsFunc(t, html, "stageTrackerPresenceOf"), + jsFunc(t, html, "stageTrackerPresenceGone"), + jsFunc(t, html, "stageTrackerPresenceAdoptAt"), + jsFunc(t, html, "stageTrackerPresenceTip"), + jsFunc(t, html, "stageTrackerPresenceAria"), + jsFunc(t, html, "stageTrackerPresenceDotHtml"), + jsFunc(t, html, "stageTrackerPresenceInPillHtml"), + jsFunc(t, html, "stageTrackerPresenceChipText"), + jsFunc(t, html, "stageTrackerPresenceChipHtml"), + }, "\n") +} + +// The SPA, fed the live payload shape: the indicator's shape class and +// aria-label per state, the plain-words tooltip, its place inside the +// adoption pill, the muted waiting pill where there is no adoption line, +// and the popover's presence line. Node runs the lifted helpers on stdin. +func TestStageTrackerPresenceJS(t *testing.T) { + html := indexHTML(t) + script := strings.Join([]string{ + stageTrackerRowActionsPreamble(t, html), + jsFunc(t, html, "stageTrackerAdoptionTip"), + jsFunc(t, html, "stageTrackerAdoptOffered"), + jsFunc(t, html, "stageTrackerAdoptionChipText"), + jsFunc(t, html, "stageTrackerAdoptionChipHtml"), + jsFunc(t, html, "stageTrackerDecisionOf"), + jsFunc(t, html, "stageTrackerDecisionTriggerHtml"), + jsFunc(t, html, "stageTrackerDecisionPopHtml"), + stageTrackerPresenceJS(t, html), + ` +const NOW = Date.parse('2026-10-28T14:32:00Z'); +Date.now = () => NOW; +const iso = ms => new Date(ms).toISOString(); +const MIN = 60000, HOUR = 60 * MIN; +const online = { kind: 'pr', repo: 'hivecommons/hive', number: 14989, stage: 71, author: 'Danathar', author_kind: 'clanker', + presence: { login: 'Danathar', state: 'online', kind: 'clanker', since: iso(NOW - 3 * HOUR), last_seen: iso(NOW - 2 * MIN), next: 'wait' } }; +const offline = { kind: 'pr', repo: 'hivecommons/hive', number: 14524, stage: 72, author: 'hanthor', author_kind: 'clanker', + adoption: { author: 'hanthor', due: false, nudges: 2, author_online: false, author_registered: true, policy: 'adopt', text: 'waiting on @hanthor (offline 26h, 2 nudges)' }, + presence: { login: 'hanthor', state: 'offline', kind: 'clanker', since: iso(NOW - 26 * HOUR), last_seen: iso(NOW - 26 * HOUR), next: 'adopt', adopt_at: iso(NOW + 38 * MIN) } }; +const human = { kind: 'pr', repo: 'hivecommons/hive', number: 15000, stage: 71, author: 'zoe', author_kind: 'human', + presence: { login: 'zoe', state: 'unknown', kind: 'human', since: iso(NOW - 40 * MIN), next: 'wait' } }; +const ask = { kind: 'pr', repo: 'hivecommons/hive', number: 14524, stage: 72, author: 'hanthor', author_kind: 'clanker', + adoption: { author: 'hanthor', due: true, blocked_by: 'author-is-maintainer', nudges: 2, author_online: false, author_maintainer: true, policy: 'ask', action: 'decide:adopt', text: 'waiting on @hanthor (maintainer, offline 26h) — adopt?' }, + decision_needed: { question: '@hanthor maintains this repository and has been offline for 26h; adopt the PR?', asked_by: 'the hive', since: iso(NOW - 26 * HOUR), blocker: 'maintainer_policy is ask', options: [{ action: 'decide:adopt', label: 'Adopt (hive takes over)', enabled: true }] }, + presence: { login: 'hanthor', state: 'offline', kind: 'clanker', since: iso(NOW - 26 * HOUR), last_seen: iso(NOW - 26 * HOUR), next: 'wait' } }; + +assert.strictEqual(stageTrackerPresenceTip(online, NOW), "@Danathar's clanker: online, last seen 2 min ago — hive is waiting for them"); +assert.match(stageTrackerPresenceTip(offline, NOW), /^@hanthor's clanker: offline 26h — hive will adopt at \S+ .*\(in 38m\)$/); +assert.strictEqual(stageTrackerPresenceTip(human, NOW), '@zoe: no clanker registered — waiting for a human reply'); +assert.strictEqual(stageTrackerPresenceTip(ask, NOW), "@hanthor's clanker: offline 26h — hive is waiting for them", 'held adoption promises no adopt-at'); + +// Shape class + aria per state; role=img so the shape reads out. +for (const [item, state, word] of [[online, 'online', 'clanker online'], [offline, 'offline', 'clanker offline'], [human, 'unknown', 'human, no clanker']]) { + const dot = stageTrackerPresenceDotHtml(item, NOW); + assert.ok(dot.includes('class="ham-presence ham-presence-' + state + '"'), dot); + assert.ok(dot.includes('role="img"'), dot); + assert.ok(dot.includes('aria-label="@' + item.presence.login + ': ' + word + ' — '), dot); +} +// Inside the adoption pill, before the @login; the presence line joins the title and aria-label. +const chip = stageTrackerAdoptionChipHtml(offline); +assert.ok(/>waiting on ]*><\/span>@hanthor<\/span>$/.test(chip), chip); +assert.ok(chip.includes("title=\"waiting on @hanthor (offline 26h, 2 nudges) · @hanthor's clanker: offline 26h"), chip); +assert.ok(chip.includes("aria-label=\"Adoption — waiting on @hanthor (offline 26h, 2 nudges) · @hanthor's clanker"), chip); +assert.strictEqual(stageTrackerPresenceChipHtml(offline), '', 'one pill, not two'); +// The "adopt?" trigger carries the dot in front of its word. +const trig = stageTrackerAdoptionChipHtml(ask); +assert.ok(/