Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/fixed-decision-pill-auth-flash.md
Original file line number Diff line number Diff line change
@@ -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.
124 changes: 124 additions & 0 deletions src/pkg/dashboard/stage_tracker_auth_pending_ctx_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
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);
// ("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(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('<button[^>]*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.
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);
`)
}
23 changes: 22 additions & 1 deletion src/pkg/dashboard/static-src/js/gh-auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
19 changes: 17 additions & 2 deletions src/pkg/dashboard/static-src/js/tracker-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
42 changes: 39 additions & 3 deletions src/pkg/dashboard/static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -22496,16 +22496,31 @@ <h2 class="config-title" id="activity-monitor-labels-title">All labels</h2>
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;
Expand Down Expand Up @@ -66911,7 +66926,23 @@ <h4>${model.editIndex === null ? 'Add Event trigger' : 'Edit Event trigger'}</h4
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');
Expand Down Expand Up @@ -66975,6 +67006,7 @@ <h4>${model.editIndex === null ? 'Add Event trigger' : 'Edit Event trigger'}</h4
if (avatarWrap) avatarWrap.hidden = true;
}
if (typeof renderPublicKnowledgeControls === 'function') renderPublicKnowledgeControls();
repaintTracker();
}

/* renderMyHivesMenuItem (#9696): point the user menu's "My hives" entry at
Expand Down Expand Up @@ -67126,7 +67158,11 @@ <h4>${model.editIndex === null ? 'Add Event trigger' : 'Edit Event trigger'}</h4
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) {
Expand Down
Loading