From 42679b6315fa1b030b4d4667311653c14a4204cc Mon Sep 17 00:00:00 2001 From: Andrew Anderson Date: Thu, 5 Nov 2026 07:57:56 -0500 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=90=9B=20fix:=20decision=20pills=20no?= =?UTF-8?q?=20longer=20flash=20disabled=20while=20the=20viewer's=20role=20?= =?UTF-8?q?loads?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On a hard reload the stage tracker's first paint ran before the auth fetch had named the viewer, so stageTrackerActionCtx read the missing role as 'read' and every role-gated decision option rendered aria-disabled with a sign-in reason until the next tracker poll. - stageTrackerAuthPending: unknown is not read. While auth is pending the ctx is optimistic (user/canHuman true, canHold null), so the pills render enabled and a click that beats auth gets the server's 403. - showGHAuthState marks auth known on both paths (and checkGHAuth when both endpoints fail) and repaints the tracker once when the user/role actually changed. - Logged-out viewers still see the disabled pills with the sign-in reason once auth is known. Fixes hivecommons/hive#16754 Signed-off-by: Andrew Anderson --- changelog.d/fixed-decision-pill-auth-flash.md | 1 + .../stage_tracker_auth_pending_ctx_test.go | 118 ++++++++++++++++++ src/pkg/dashboard/static-src/js/gh-auth.js | 23 +++- .../static-src/js/tracker-actions.js | 19 ++- src/pkg/dashboard/static/index.html | 42 ++++++- 5 files changed, 197 insertions(+), 6 deletions(-) create mode 100644 changelog.d/fixed-decision-pill-auth-flash.md create mode 100644 src/pkg/dashboard/stage_tracker_auth_pending_ctx_test.go diff --git a/changelog.d/fixed-decision-pill-auth-flash.md b/changelog.d/fixed-decision-pill-auth-flash.md new file mode 100644 index 0000000000..aad3354fdb --- /dev/null +++ b/changelog.d/fixed-decision-pill-auth-flash.md @@ -0,0 +1 @@ +- Dashboard: the Activity Monitor decision pills ("Let hive decide", "Approve and let hive merge", "Merge now as maintainer") no longer flash grey and unclickable on a page reload while the viewer's role is still loading; the tracker treats an unknown viewer as pending rather than read-only and repaints once auth resolves. diff --git a/src/pkg/dashboard/stage_tracker_auth_pending_ctx_test.go b/src/pkg/dashboard/stage_tracker_auth_pending_ctx_test.go new file mode 100644 index 0000000000..9c20b40628 --- /dev/null +++ b/src/pkg/dashboard/stage_tracker_auth_pending_ctx_test.go @@ -0,0 +1,118 @@ +package dashboard + +import ( + "strings" + "testing" +) + +// Owner report: a hard reload of the dashboard flashed the decision pills +// ("Let hive decide", "Approve and let hive merge", "Merge now as +// maintainer") grey and unclickable, then they came back a poll later. The +// tracker's first paint ran before the auth fetch had named the viewer, so +// stageTrackerActionCtx read the missing role as 'read' and every +// role-gated option rendered aria-disabled with a sign-in reason. Unknown is +// not read: while auth is pending the ctx is optimistic (like canHold === +// null), and showGHAuthState repaints the tracker once the answer lands. +// The helpers run under node the way stage_tracker_row_actions_test.go does. + +func stageTrackerAuthPendingPreamble(t *testing.T, html string) string { + t.Helper() + return strings.Join([]string{ + stageTrackerDecisionPopPreamble(t, html), + jsFunc(t, html, "dashboardRoleAtLeast"), + jsFunc(t, html, "stageTrackerAuthPending"), + jsFunc(t, html, "stageTrackerActionCtx"), + jsFunc(t, html, "hiveAuthResolved"), + jsFunc(t, html, "showGHAuthState"), + // showGHAuthState's header DOM, the profile URL helper and the + // tracker re-render it schedules, as stubs that record calls. + `const authEls = {}; +global.document.getElementById = id => (authEls[id] = authEls[id] || { style: {}, hidden: false, textContent: '', src: '', alt: '', href: '', setAttribute() {}, removeAttribute() {} }); +global.ghProfileURL = u => 'https://github.com/' + u; +let repaints = 0; +global.renderStageTracker = () => { repaints++; }; +_stageTracker = { items: [] }; +global.window = {};`, + }, "\n") +} + +func TestStageTrackerActionCtxWhileAuthPending(t *testing.T) { + html := indexHTML(t) + runStageTrackerRowActionsScript(t, stageTrackerAuthPendingPreamble(t, html)+stageTrackerDecisionPopFixture+` +const mergeDecision = { question: 'Ready for human merge', asked_by: 'the hive', since: '2026-10-27T10:30:00Z', options: [ + { action: 'decide:queue-merge', label: 'Approve and let hive merge', enabled: true }, + { action: 'decide:merge-now', label: 'Merge now as maintainer', enabled: true }, + { action: 'decide:delegate', label: 'Let hive decide', enabled: true }, +] }; +const mergePR = Object.assign({}, pr, { number: 9, url: 'https://github.com/o/r/pull/9', manual_merge: true, decision_needed: mergeDecision }); + +// Before auth answers: nothing names the viewer, so the ctx is pending and +// optimistic — no option is greyed with a role or sign-in reason. +assert.strictEqual(stageTrackerAuthPending(), true); +let actx = stageTrackerActionCtx('o/r'); +assert.strictEqual(actx.authPending, true); +assert.strictEqual(actx.user, true); +assert.strictEqual(actx.canHold, null); +assert.strictEqual(actx.canHuman, true); +let opts = stageTrackerDecisionOptions(mergePR, actx); +assert.deepStrictEqual(opts.map(o => o.id), ['decide:queue-merge', 'decide:merge-now', 'decide:delegate']); +assert.ok(opts.every(o => o.enabled), JSON.stringify(opts)); +assert.ok(opts.every(o => o.why !== STAGE_TRACKER_WHY_ROLE && o.why !== STAGE_TRACKER_WHY_WRITE), JSON.stringify(opts)); +// Options the server itself rules out stay disabled with the server's reason. +opts = stageTrackerDecisionOptions(pr, actx); +assert.strictEqual(opts.find(o => o.id === 'decide:approve').enabled, false); +assert.ok(opts.find(o => o.id === 'decide:approve').why.indexOf('requested changes') >= 0); +// The popover's lead button is not aria-disabled while pending. +const pop = stageTrackerDecisionPopHtml(mergePR, stageTrackerDecisionOptions(mergePR, actx), Date.parse('2026-10-27T12:30:00Z'), ''); +assert.ok(pop.indexOf('aria-disabled') < 0, pop); +assert.ok(pop.indexOf('data-ham-act="decide:queue-merge"') >= 0, pop); +// The row pill and the selection bar follow the same actx. +const pill = stageTrackerLeadPillHtml(mergePR, stageTrackerFlatActions(stageTrackerRowActions(mergePR, actx))['decide:queue-merge']); +assert.ok(pill.indexOf('aria-disabled') < 0, pill); +const bar = stageTrackerSelBarHtml([mergePR], stageTrackerSelectionActions([mergePR], () => actx)); +assert.ok(bar.indexOf('aria-disabled') < 0, bar); + +// Auth lands as a merger: the actx is real, the pills stay enabled, and the +// tracker is repainted exactly once for the change. +showGHAuthState(true, 'alice', 'https://github.com/alice.png', 'merger'); +assert.strictEqual(window._hiveAuthKnown, true); +assert.strictEqual(stageTrackerAuthPending(), false); +assert.strictEqual(repaints, 1); +actx = stageTrackerActionCtx('o/r'); +assert.strictEqual(actx.authPending, undefined); +assert.strictEqual(actx.user, true); +assert.strictEqual(actx.canHuman, true); +assert.strictEqual(actx.login, 'alice'); +opts = stageTrackerDecisionOptions(mergePR, actx); +assert.ok(opts.every(o => o.enabled), JSON.stringify(opts)); +// A re-check that changes nothing does not repaint. +showGHAuthState(true, 'alice', 'https://github.com/alice.png', 'merger'); +assert.strictEqual(repaints, 1); + +// A viewer the server names as read-only: merge options carry the role reason. +global.window = { _hiveUser: 'bob', _hiveRole: 'read', _hiveAuthKnown: true }; +actx = stageTrackerActionCtx('o/r'); +assert.strictEqual(actx.canHuman, false); +opts = stageTrackerDecisionOptions(mergePR, actx); +assert.strictEqual(opts.find(o => o.id === 'decide:merge-now').enabled, false); +assert.strictEqual(opts.find(o => o.id === 'decide:merge-now').why, STAGE_TRACKER_WHY_ROLE); + +// Logged out, once auth is known: every option greyed with the sign-in reason. +global.window = {}; +showGHAuthState(false); +assert.strictEqual(window._hiveAuthKnown, true); +assert.strictEqual(stageTrackerAuthPending(), false); +assert.strictEqual(repaints, 2, 'pending → known-anonymous is a change worth one repaint'); +actx = stageTrackerActionCtx('o/r'); +assert.strictEqual(actx.user, false); +assert.strictEqual(actx.canHold, false); +opts = stageTrackerDecisionOptions(mergePR, actx); +assert.ok(opts.every(o => !o.enabled), JSON.stringify(opts)); +assert.strictEqual(opts.find(o => o.id === 'decide:delegate').why, STAGE_TRACKER_WHY_WRITE); +assert.strictEqual(opts.find(o => o.id === 'decide:merge-now').why, STAGE_TRACKER_WHY_ROLE); +// Giving up on auth (both endpoints failed) also ends the pending state. +global.window = {}; +hiveAuthResolved()(); +assert.strictEqual(stageTrackerAuthPending(), false); +`) +} diff --git a/src/pkg/dashboard/static-src/js/gh-auth.js b/src/pkg/dashboard/static-src/js/gh-auth.js index 11cad69b07..35e4c6bf6c 100644 --- a/src/pkg/dashboard/static-src/js/gh-auth.js +++ b/src/pkg/dashboard/static-src/js/gh-auth.js @@ -47,7 +47,23 @@ return 'data:image/svg+xml;charset=utf-8,' + encodeURIComponent(svg); } + /* The viewer's identity is known once showGHAuthState has run on either + path (or checkGHAuth gave up). Until then the stage tracker treats the + viewer as unknown rather than 'read' (stageTrackerAuthPending), so a + hard reload does not flash the decision pills disabled; when the + answer lands, repaint the tracker once — only if something changed. */ + function hiveAuthResolved() { + const before = (window._hiveAuthKnown ? 'k' : '') + '|' + String(window._hiveUser || '') + '|' + String(window._hiveRole || ''); + window._hiveAuthKnown = true; + return function() { + const after = 'k|' + String(window._hiveUser || '') + '|' + String(window._hiveRole || ''); + if (after === before) return; + if (typeof renderStageTracker === 'function' && typeof _stageTracker !== 'undefined' && _stageTracker) renderStageTracker(); + }; + } + function showGHAuthState(loggedIn, username, avatarURL, role, displayName) { + const repaintTracker = hiveAuthResolved(); if (username) window._hiveUser = username; if (role) window._hiveRole = role; const banner = document.getElementById('gh-auth-banner'); @@ -111,6 +127,7 @@ if (avatarWrap) avatarWrap.hidden = true; } if (typeof renderPublicKnowledgeControls === 'function') renderPublicKnowledgeControls(); + repaintTracker(); } /* renderMyHivesMenuItem (#9696): point the user menu's "My hives" entry at @@ -262,7 +279,11 @@ const resp = await fetch('/api/gh-user-auth/status'); const data = await resp.json(); showGHAuthState(data.logged_in, data.username, data.avatar_url); - } catch (e) {} + } catch (e) { + /* Neither endpoint answered: the viewer is anonymous as far as the + page can tell. Say so, or the tracker waits on auth forever. */ + hiveAuthResolved()(); + } } function showSetupDetails(which) { diff --git a/src/pkg/dashboard/static-src/js/tracker-actions.js b/src/pkg/dashboard/static-src/js/tracker-actions.js index 9dcb6f83e6..2b0d586576 100644 --- a/src/pkg/dashboard/static-src/js/tracker-actions.js +++ b/src/pkg/dashboard/static-src/js/tracker-actions.js @@ -187,16 +187,31 @@ const data = typeof stageTrackerTerminalView === 'function' ? stageTrackerTerminalView(_stageTracker, Date.now()) : _stageTracker; return keys.map(k => stageTrackerItemByKey(data, k)).filter(Boolean); } + // Pure: whether the viewer's identity is still loading — the auth + // fetch (showGHAuthState) has not answered yet and nothing else has + // named a user or role. Unknown is not "read": on a hard reload the + // tracker's first paint lands before auth resolves, and gating the + // pills on 'read' here made them flash disabled for a poll interval + // (hivecommons/hive#16754). + function stageTrackerAuthPending() { + if (typeof window === 'undefined') return false; + return !window._hiveAuthKnown && window._hiveRole === undefined && !window._hiveUser; + } // What the signed-in viewer may do on this repo. Hold permission is // looked up lazily (the server answers 403 either way); needs-human is - // merger/owner only. + // merger/owner only. While the viewer's identity is still loading the + // ctx is optimistic — like canHold === null, unknown renders enabled + // and the server's 403 is the answer to a click that beat auth; the + // repaint showGHAuthState schedules settles the pills within the tick. function stageTrackerActionCtx(repo) { + const governor = (window._lastStatus && window._lastStatus.governor) || null; + if (stageTrackerAuthPending()) return { user: true, canHold: null, canHuman: true, authPending: true, login: '', governor }; const role = window._hiveRole || 'read'; const owner = dashboardRoleAtLeast(role, 'owner'); const user = !!window._hiveUser || owner; if (typeof ensureRepoHoldPermission === 'function') ensureRepoHoldPermission(repo); const canHold = owner || (typeof repoHoldPermissionKnown === 'function' && repoHoldPermissionKnown(repo)) ? true : (user ? null : false); - return { user, canHold, canHuman: user && dashboardRoleAtLeast(role, 'merger'), login: String(window._hiveUser || ''), governor: (window._lastStatus && window._lastStatus.governor) || null }; + return { user, canHold, canHuman: user && dashboardRoleAtLeast(role, 'merger'), login: String(window._hiveUser || ''), governor }; } // Pure: the item a row's "Decide…" acts on. A PR parked at 085 (the // "Needs human decision" pill on the Merge queue column) decides itself; diff --git a/src/pkg/dashboard/static/index.html b/src/pkg/dashboard/static/index.html index 7a179d8f2b..bb78e717d8 100644 --- a/src/pkg/dashboard/static/index.html +++ b/src/pkg/dashboard/static/index.html @@ -22496,16 +22496,31 @@

All labels

const data = typeof stageTrackerTerminalView === 'function' ? stageTrackerTerminalView(_stageTracker, Date.now()) : _stageTracker; return keys.map(k => stageTrackerItemByKey(data, k)).filter(Boolean); } + // Pure: whether the viewer's identity is still loading — the auth + // fetch (showGHAuthState) has not answered yet and nothing else has + // named a user or role. Unknown is not "read": on a hard reload the + // tracker's first paint lands before auth resolves, and gating the + // pills on 'read' here made them flash disabled for a poll interval + // (hivecommons/hive#16754). + function stageTrackerAuthPending() { + if (typeof window === 'undefined') return false; + return !window._hiveAuthKnown && window._hiveRole === undefined && !window._hiveUser; + } // What the signed-in viewer may do on this repo. Hold permission is // looked up lazily (the server answers 403 either way); needs-human is - // merger/owner only. + // merger/owner only. While the viewer's identity is still loading the + // ctx is optimistic — like canHold === null, unknown renders enabled + // and the server's 403 is the answer to a click that beat auth; the + // repaint showGHAuthState schedules settles the pills within the tick. function stageTrackerActionCtx(repo) { + const governor = (window._lastStatus && window._lastStatus.governor) || null; + if (stageTrackerAuthPending()) return { user: true, canHold: null, canHuman: true, authPending: true, login: '', governor }; const role = window._hiveRole || 'read'; const owner = dashboardRoleAtLeast(role, 'owner'); const user = !!window._hiveUser || owner; if (typeof ensureRepoHoldPermission === 'function') ensureRepoHoldPermission(repo); const canHold = owner || (typeof repoHoldPermissionKnown === 'function' && repoHoldPermissionKnown(repo)) ? true : (user ? null : false); - return { user, canHold, canHuman: user && dashboardRoleAtLeast(role, 'merger'), login: String(window._hiveUser || ''), governor: (window._lastStatus && window._lastStatus.governor) || null }; + return { user, canHold, canHuman: user && dashboardRoleAtLeast(role, 'merger'), login: String(window._hiveUser || ''), governor }; } // Pure: the item a row's "Decide…" acts on. A PR parked at 085 (the // "Needs human decision" pill on the Merge queue column) decides itself; @@ -66911,7 +66926,23 @@

${model.editIndex === null ? 'Add Event trigger' : 'Edit Event trigger'}

${model.editIndex === null ? 'Add Event trigger' : 'Edit Event trigger'}${model.editIndex === null ? 'Add Event trigger' : 'Edit Event trigger'} Date: Thu, 5 Nov 2026 08:05:19 -0500 Subject: [PATCH 2/2] test: selection-bar assertion checks the role-gated chips, not row state Signed-off-by: Andrew Anderson --- src/pkg/dashboard/stage_tracker_auth_pending_ctx_test.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/pkg/dashboard/stage_tracker_auth_pending_ctx_test.go b/src/pkg/dashboard/stage_tracker_auth_pending_ctx_test.go index 9c20b40628..23e439b737 100644 --- a/src/pkg/dashboard/stage_tracker_auth_pending_ctx_test.go +++ b/src/pkg/dashboard/stage_tracker_auth_pending_ctx_test.go @@ -69,8 +69,14 @@ assert.ok(pop.indexOf('data-ham-act="decide:queue-merge"') >= 0, pop); // The row pill and the selection bar follow the same actx. const pill = stageTrackerLeadPillHtml(mergePR, stageTrackerFlatActions(stageTrackerRowActions(mergePR, actx))['decide:queue-merge']); assert.ok(pill.indexOf('aria-disabled') < 0, pill); +// ("Release hold" is greyed as not applicable — the row is not held — which +// is the row's state, not the viewer's; the role-gated chips are live.) const bar = stageTrackerSelBarHtml([mergePR], stageTrackerSelectionActions([mergePR], () => actx)); -assert.ok(bar.indexOf('aria-disabled') < 0, bar); +assert.ok(bar.indexOf(STAGE_TRACKER_WHY_ROLE) < 0 && bar.indexOf(STAGE_TRACKER_WHY_WRITE) < 0, bar); +for (const id of ['decide:delegate', 'needs-human', 'hold']) { + const chip = bar.match(new RegExp(']*data-arg0="' + id + '"[^>]*>')); + assert.ok(chip && chip[0].indexOf('aria-disabled') < 0, id + ' chip: ' + (chip ? chip[0] : 'missing')); +} // Auth lands as a merger: the actx is real, the pills stay enabled, and the // tracker is repainted exactly once for the change.