Skip to content
Closed
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/added-activity-monitor-decision-trail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Activity Monitor rows with a recorded operator action show a persistent, keyboard-focusable ✓ decision trail, turn amber after 30 minutes without a stage change, and can be filtered by awaiting a decision, acted, or acted and still stuck.
4 changes: 3 additions & 1 deletion src/pkg/dashboard/stage_tracker_motion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func TestStageTrackerMotionWiring(t *testing.T) {
`function stageTrackerAnimateMoves(root)`,
`function stageTrackerMotionEffect(setting, reduced)`,
`stageTrackerNoteMerges(data); stageTrackerNoteOpened(data); stageTrackerNoteMoves(data); }`,
`const ctx = { nowMs, stages, moves: _stageTrackerMoves };`,
`const ctx = { nowMs, stages, moves: _stageTrackerMoves, operatorItems: new Map(d.items.map(it => [stageTrackerItemKey(it), it])) };`,
`if (Object.keys(_stageTrackerMoves).length) { stageTrackerAnimateMoves(el); _stageTrackerMoves = {}; }`,
`window.matchMedia('(prefers-reduced-motion: reduce)').matches`,
`@media (prefers-reduced-motion: reduce) { .ham-anim-layer { display: none; } }`,
Expand Down Expand Up @@ -455,6 +455,7 @@ func TestStageTrackerMotionRowStamp(t *testing.T) {
jsFunc(t, html, "stageTrackerMoveAttrs"),
jsFunc(t, html, "stageTrackerRefOf"),
jsFunc(t, html, "stageTrackerRowToolsHtml"),
stageTrackerOperatorJS(t, html),
jsFunc(t, html, "stageTrackerRowHtml"),
jsFunc(t, html, "stageTrackerPRIssueSlot"),
}, "\n") + `
Expand Down Expand Up @@ -574,6 +575,7 @@ func TestStageTrackerMotionPreviewSample(t *testing.T) {
jsFunc(t, html, "stageTrackerShortAgo"),
jsFunc(t, html, "stageTrackerRefOf"),
jsFunc(t, html, "stageTrackerRowToolsHtml"),
stageTrackerOperatorJS(t, html),
jsFunc(t, html, "stageTrackerRowHtml"),
jsFunc(t, html, "stageTrackerPRIssueSlot"),
jsFunc(t, html, "stageTrackerItemKey"),
Expand Down
130 changes: 130 additions & 0 deletions src/pkg/dashboard/stage_tracker_operator_action.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
// Exercise the shipped pure helpers, without a browser or server ledger.
const test = require('node:test');
const assert = require('node:assert/strict');
const fs = require('node:fs');
const path = require('node:path');
const html = fs.readFileSync(path.join(__dirname, 'static/index.html'), 'utf8');
const css = fs.readFileSync(path.join(__dirname, 'static/components.css'), 'utf8');
function pick(name) {
const match = html.match(new RegExp('function ' + name + '\\([^]*?\\n \\}\\n'));
assert.ok(match, name + ' missing');
return match[0];
}
const names = ['stageTrackerOperatorStuck', 'stageTrackerDecisionMatches', 'stageTrackerOperatorStage',
'stageTrackerOperatorTooltip', 'stageTrackerOperatorBadgeHtml', 'stageTrackerOperatorPRBadge',
'stageTrackerHeadline', 'stageTrackerHoldLabels', 'stageTrackerSoakLeft', 'stageTrackerHumanMergeReasonWord'];
const esc = text => String(text).replace(/&/g, '&amp;').replace(/"/g, '&quot;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
const constant = html.match(/const STAGE_TRACKER_OPERATOR_STUCK_MS = [^;]+;/);
assert.ok(constant);
const helpers = new Function('esc', constant[0] + '\n' + names.map(pick).join('\n') + '\nreturn {' + names.join(',') + '};')(esc);
const { stageTrackerOperatorTooltip: tooltip, stageTrackerOperatorStuck: stuck,
stageTrackerDecisionMatches: matches, stageTrackerOperatorBadgeHtml: badge,
stageTrackerOperatorPRBadge: prBadge } = helpers;
const now = Date.parse('2026-10-28T16:00:00Z');
function item(minutes = 12, stage = 85, action = {}) {
return { stage, caption: 'Waiting for an approval', last_operator_action: {
action: 'decide:approve', at: new Date(now - minutes * 60000).toISOString(), stage: 85, outcome: 'ok', ...action,
} };
}

test('decision trail orders waiting, choice/time, then hive result in human words', () => {
assert.equal(tooltip(item(), now), 'Waiting on: Needs a human decision. You chose: Approve, 12 min ago. Hive: action recorded; waiting for progress.');
assert.equal(tooltip({}, now), '');
assert.equal(tooltip(null, now), '');
assert.doesNotMatch(tooltip(item(), now), /stage\/|085|decide:/);
});

test('moved-on receipt persists, without an amber warning', () => {
const moved = item(90, 110);
assert.match(tooltip(moved, now), /Addressed — now at Merged/);
assert.equal(stuck(moved, now), false);
assert.match(badge(moved, now), />✓<\/span>/);
assert.doesNotMatch(badge(moved, now), /ham-operator-stuck/);
});

test('amber uses a strict single threshold and human caption, not a reason token', () => {
assert.equal(stuck(item(30), now), false);
assert.equal(stuck(item(30), now + 1), true);
const delayed = { ...item(42), caption: 'Approval recorded\nwaiting for review', reason: 'raw-stage-token' };
assert.match(tooltip(delayed, now), /Still at Needs a human decision 42 min after you asked — hive says: Approval recorded waiting for review\./);
assert.doesNotMatch(tooltip(delayed, now), /\n|raw-stage-token/);
assert.match(badge(delayed, now), /ham-operator-stuck/);
assert.match(tooltip({ ...item(42), caption: '' }, now), /no further progress reported/);
});

test('failed outcomes and malformed timestamps are honest, single-line copy', () => {
assert.match(tooltip(item(42, 85, { outcome: 'Permission denied\nPlease sign in' }), now), /Hive: action failed: Permission denied Please sign in\./);
const invalid = item(42, 85, { at: 'not-a-time' });
assert.equal(stuck(invalid, now), false);
assert.match(tooltip(invalid, now), /time unavailable/);
assert.equal(stuck(item(42, 85, { stage: undefined }), now), false);
assert.equal(stuck(item(-5), now), false);
assert.equal(stuck({}, now), false);
});

test('all submitted actions receive plain labels', () => {
for (const action of ['hold', 'release', 'retry', 'needs-human', 'accept-triage', 'decide:delegate',
'decide:direction', 'decide:close-superseded', 'decide:close-wontfix']) {
assert.doesNotMatch(tooltip(item(12, 85, { action }), now), /Submit an action|decide:/);
}
});

test('decision buckets share the badge predicate and distinguish acted from awaiting', () => {
for (const stage of [15, 17, 45, 85, 90]) assert.equal(matches({ stage }, 'awaiting', now), true);
assert.equal(matches({ stage: 50, modifiers: ['needs-decision'] }, 'awaiting', now), true);
assert.equal(matches({ stage: 50 }, 'awaiting', now), false);
assert.equal(matches(item(), 'awaiting', now), false);
assert.equal(matches({}, 'acted', now), false);
assert.equal(matches({}, 'stuck', now), false);
for (const row of [item(), item(42), item(42, 110)]) {
assert.equal(matches(row, 'acted', now), true);
assert.equal(matches(row, 'stuck', now), stuck(row, now));
}
});

test('badge is focusable, escaped, and absent for legacy payloads', () => {
assert.equal(badge({}, now), '');
const row = item(42, 85, { outcome: '<denied> "try again"' });
const rendered = badge(row, now);
const tip = esc(tooltip(row, now));
assert.ok(rendered.includes('title="' + tip + '" aria-label="' + tip + '"'));
assert.match(rendered, /tabindex="0"/);
assert.doesNotMatch(rendered, /<denied>|style=|animation|blink/);
assert.match(css, /\.ham-badge\.ham-operator-stuck\s*\{ color: var\(--amber\); \}/);
});

test('nested PR receipts use the full tracker item, not an issue action', () => {
const pr = item(42);
const ctx = { operatorItems: new Map([['org/repo/pr#7', pr]]) };
assert.equal(prBadge({ number: 7 }, { repo: 'org/repo' }, now, ctx), badge(pr, now));
assert.equal(prBadge({ number: 8 }, { repo: 'org/repo', ...item() }, now, ctx), '');
assert.ok(pick('stageTrackerSubRowHtml').includes('stageTrackerOperatorPRBadge'));
const row = pick('stageTrackerRowHtml');
assert.ok(row.includes('stageTrackerOperatorPRBadge'));
assert.equal((row.match(/stageTrackerOperatorBadgeHtml\(item, nowMs\)/g) || []).length, 3);
});

test('quiet payloads re-render once a minute so amber and the stuck filter age without a new response', () => {
let clock = now;
let renders = 0;
const tick = new Function('_stageTracker', 'Date', 'renderStageTracker', 'document',
'let _stageTrackerOperatorMinute = -1;\n' + pick('stageTrackerTickClock') + '\nreturn stageTrackerTickClock;')(
{ items: [item()] }, { now: () => clock }, () => renders++, { querySelector: () => null });
tick();
tick();
assert.equal(renders, 1);
clock += 60000;
tick();
assert.equal(renders, 2);
});

test('decision filter is normalized, saved with other filters, synced and reset', () => {
assert.match(pick('stageTrackerDefaultFilter'), /decision: ''/);
assert.match(pick('stageTrackerNormalizeFilter'), /\['', 'awaiting', 'acted', 'stuck'\]/);
assert.match(pick('stageTrackerFilterActive'), /!!f\.decision/);
assert.match(pick('stageTrackerMatches'), /stageTrackerDecisionMatches\(item, f\.decision/);
assert.match(pick('hamFilter'), /case 'decision': f\.decision = f\.decision === value \? '' : value/);
assert.match(pick('hamFilter'), /stageTrackerSaveFilter\(\)/);
assert.match(pick('stageTrackerSaveFilter'), /localStorage\.setItem/);
assert.match(pick('stageTrackerSyncToolbar'), /b\.dataset\.arg1 === f\.decision/);
});
21 changes: 21 additions & 0 deletions src/pkg/dashboard/stage_tracker_operator_action_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package dashboard

import (
"strings"
"testing"
)

// stageTrackerOperatorJS supplies the decision helpers used by both row
// rendering and filtering. Keep the fixtures on the shipped implementation.
func stageTrackerOperatorJS(t *testing.T, html string) string {
t.Helper()
return strings.Join([]string{
jsConstLine(t, html, "STAGE_TRACKER_OPERATOR_STUCK_MS"),
jsFunc(t, html, "stageTrackerOperatorStuck"),
jsFunc(t, html, "stageTrackerDecisionMatches"),
jsFunc(t, html, "stageTrackerOperatorStage"),
jsFunc(t, html, "stageTrackerOperatorTooltip"),
jsFunc(t, html, "stageTrackerOperatorBadgeHtml"),
jsFunc(t, html, "stageTrackerOperatorPRBadge"),
}, "\n")
}
1 change: 1 addition & 0 deletions src/pkg/dashboard/stage_tracker_repo_grouping_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ func stageTrackerRepoGroupingHarness(t *testing.T, html string) string {
stageTrackerActedJS(t, html),
jsFunc(t, html, "stageTrackerNormalizeFilter"),
jsFunc(t, html, "stageTrackerFilterActive"),
stageTrackerOperatorJS(t, html),
jsFunc(t, html, "stageTrackerMatches"),
jsFunc(t, html, "stageTrackerSort"),
jsFunc(t, html, "stageTrackerPage"),
Expand Down
35 changes: 29 additions & 6 deletions src/pkg/dashboard/stage_tracker_ui_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package dashboard

import (
"os"
"os/exec"
"path/filepath"
"strings"
"testing"
)
Expand Down Expand Up @@ -132,6 +134,7 @@ func TestStageTrackerRows(t *testing.T) {
stageTrackerActedJS(t, html),
jsFunc(t, html, "stageTrackerNormalizeFilter"),
jsFunc(t, html, "stageTrackerFilterActive"),
stageTrackerOperatorJS(t, html),
jsFunc(t, html, "stageTrackerMatches"),
jsFunc(t, html, "stageTrackerSort"),
jsFunc(t, html, "stageTrackerPage"),
Expand Down Expand Up @@ -788,10 +791,7 @@ assert.ok(/<span class="ham-since( ham-stalled)?">[^<]*<\/span>/.test(row) && !/
row = stageTrackerRowHtml({ repo: 'acme/console', number: 106, kind: 'pr', stage: 110 }, stages, ctx);
assert.ok(/<li class="ham-seg active cap merged" title="Merged — [^"]*" aria-current="step">/.test(row) && titled(strip(row)).length === 1, row);
`
// Over stdin: the lifted fixture exceeds Linux's per-argument limit.
cmd := exec.Command(node, "-")
cmd.Stdin = strings.NewReader(script)
if out, err := cmd.CombinedOutput(); err != nil {
if out, err := runNodeScript(t, node, script); err != nil {
t.Fatalf("node Hive activity monitor fixture failed: %v\n%s", err, out)
}
}
Expand Down Expand Up @@ -853,6 +853,7 @@ func TestStageTrackerFilterSortPage(t *testing.T) {
stageTrackerActedJS(t, html),
jsFunc(t, html, "stageTrackerNormalizeFilter"),
jsFunc(t, html, "stageTrackerFilterActive"),
stageTrackerOperatorJS(t, html),
jsFunc(t, html, "stageTrackerMatches"),
jsFunc(t, html, "stageTrackerVisible"),
jsFunc(t, html, "stageTrackerRowCount"),
Expand Down Expand Up @@ -917,6 +918,18 @@ assert.deepStrictEqual(nums(stageTrackerVisible(items, F({ attention: true }), c
assert.deepStrictEqual(nums(stageTrackerVisible(items, F({ repo: 'a/c', kind: 'pr' }), ctx)), [4]);
assert.deepStrictEqual(nums(stageTrackerVisible(items, F({ attention: true, author: 'human' }), ctx)), [], 'filters compose');

// Decision filters run through the same shipped predicate as the row badge.
const decisions = [
{ kind: 'pr', repo: 'a/b', number: 30, stage: 85 },
{ kind: 'pr', repo: 'a/b', number: 31, stage: 85, last_operator_action: { stage: 85, at: ago(31 * 60000) } },
{ kind: 'pr', repo: 'a/b', number: 32, stage: 110, last_operator_action: { stage: 85, at: ago(H) } },
];
assert.deepStrictEqual(nums(stageTrackerVisible(decisions, F({ decision: 'awaiting' }), ctx)), [30]);
assert.deepStrictEqual(nums(stageTrackerVisible(decisions, F({ decision: 'acted' }), ctx)), [31, 32]);
assert.deepStrictEqual(nums(stageTrackerVisible(decisions, F({ decision: 'stuck' }), ctx)), [31]);
assert.strictEqual(stageTrackerFilterActive(F({ decision: 'acted' })), true);
assert.strictEqual(stageTrackerNormalizeFilter({ decision: 'bogus' }).decision, '');

// A PR nested under a listed issue shares that issue's row; when a filter
// (label chips, the Pull requests tab, …) drops the issue the PR must still
// render as its own row — an item never disappears because its issue did.
Expand Down Expand Up @@ -1034,8 +1047,18 @@ assert.strictEqual(stageTrackerNormalizeFilter({ needsHuman: 'yes' }).needsHuman
assert.strictEqual(stageTrackerNormalizeFilter({ onHold: 1 }).onHold, true);
assert.strictEqual(stageTrackerLabelDialogData(stageTrackerLabelFacets(parked, F({ needsHuman: true, onHold: true }))).selected, 2);
`
cmd := exec.Command(node, "-e", script)
if out, err := cmd.CombinedOutput(); err != nil {
if out, err := runNodeScript(t, node, script); err != nil {
t.Fatalf("node Hive activity monitor fixture failed: %v\n%s", err, out)
}
}

// runNodeScript runs script from a temp file: a large fixture passed via
// `node -e` can exceed the Linux single-argument limit (128KiB).
func runNodeScript(t *testing.T, node, script string) ([]byte, error) {
t.Helper()
path := filepath.Join(t.TempDir(), "fixture.js")
if err := os.WriteFile(path, []byte(script), 0o600); err != nil {
t.Fatal(err)
}
return exec.Command(node, path).CombinedOutput()
}
11 changes: 11 additions & 0 deletions src/pkg/dashboard/static/components.css
Original file line number Diff line number Diff line change
Expand Up @@ -826,3 +826,14 @@ a.nav-chip:active,
.py-1-px-4 { padding: var(--sp-1) var(--sp-4); }
.py-2-px-4 { padding: var(--sp-2) var(--sp-4); }
.d-block { display: block; }

/* Persistent decision receipt, separate from the progress arrow's motion. */
.ham-badge.ham-operator-badge {
color: var(--green);
border-color: currentColor;
}
.ham-badge.ham-operator-stuck { color: var(--amber); }
.ham-operator-badge:focus-visible {
outline: var(--focus-ring-width) solid color-mix(in srgb, var(--brand) var(--component-border-emphasis), transparent);
outline-offset: var(--sp-1);
}
Loading
Loading