diff --git a/changelog.d/fixed-14928-tracker-trail-undefined.md b/changelog.d/fixed-14928-tracker-trail-undefined.md new file mode 100644 index 0000000000..e855446096 --- /dev/null +++ b/changelog.d/fixed-14928-tracker-trail-undefined.md @@ -0,0 +1 @@ +- The Activity Monitor hover's "Trail:" clause names each hop by stage word (e.g. "CI / Review → Needs author → Needs human decision") instead of "undefined → undefined → …": the renderer read a `stage` field the `/api/stage-tracker` history entries never carried (they emit `number`/`slug`). Hops that cannot be named are left out and the clause is omitted when fewer than two remain ([#14928](https://github.com/hivecommons/hive/issues/14928)). diff --git a/src/pkg/dashboard/stage_tracker_motion_test.go b/src/pkg/dashboard/stage_tracker_motion_test.go index 4f68caaf13..b6ec46ab7e 100644 --- a/src/pkg/dashboard/stage_tracker_motion_test.go +++ b/src/pkg/dashboard/stage_tracker_motion_test.go @@ -433,6 +433,8 @@ func TestStageTrackerMotionRowStamp(t *testing.T) { jsFunc(t, html, "stageTrackerRegressionHandled"), jsFunc(t, html, "stageTrackerRegressionText"), jsFunc(t, html, "stageTrackerStaleLabelsText"), + jsFunc(t, html, "stageTrackerHopName"), + jsFunc(t, html, "stageTrackerTrailText"), jsFunc(t, html, "stageTrackerTooltip"), jsFunc(t, html, "stageTrackerChipsHtml"), jsFunc(t, html, "stageTrackerHeadColsHtml"), @@ -546,6 +548,8 @@ func TestStageTrackerMotionPreviewSample(t *testing.T) { jsFunc(t, html, "stageTrackerRegressionHandled"), jsFunc(t, html, "stageTrackerRegressionText"), jsFunc(t, html, "stageTrackerStaleLabelsText"), + jsFunc(t, html, "stageTrackerHopName"), + jsFunc(t, html, "stageTrackerTrailText"), jsFunc(t, html, "stageTrackerTooltip"), jsFunc(t, html, "stageTrackerChipsHtml"), jsFunc(t, html, "stageTrackerHeadColsHtml"), diff --git a/src/pkg/dashboard/stage_tracker_pills_gate_test.go b/src/pkg/dashboard/stage_tracker_pills_gate_test.go index 1d420f9186..7af0a1fb8b 100644 --- a/src/pkg/dashboard/stage_tracker_pills_gate_test.go +++ b/src/pkg/dashboard/stage_tracker_pills_gate_test.go @@ -199,6 +199,8 @@ func TestStageTrackerDeferredPillsJS(t *testing.T) { jsFunc(t, html, "stageTrackerRegressionHandled"), jsFunc(t, html, "stageTrackerRegressionText"), jsFunc(t, html, "stageTrackerStaleLabelsText"), + jsFunc(t, html, "stageTrackerHopName"), + jsFunc(t, html, "stageTrackerTrailText"), jsFunc(t, html, "stageTrackerTooltip"), jsFunc(t, html, "stageTrackerChipsHtml"), jsFunc(t, html, "stageTrackerNeedsAttention"), diff --git a/src/pkg/dashboard/stage_tracker_repo_grouping_test.go b/src/pkg/dashboard/stage_tracker_repo_grouping_test.go index 7c67bcf3c8..ff87da8b61 100644 --- a/src/pkg/dashboard/stage_tracker_repo_grouping_test.go +++ b/src/pkg/dashboard/stage_tracker_repo_grouping_test.go @@ -148,6 +148,8 @@ func stageTrackerRepoGroupingHarness(t *testing.T, html string) string { jsFunc(t, html, "stageTrackerRegressionHandled"), jsFunc(t, html, "stageTrackerRegressionText"), jsFunc(t, html, "stageTrackerStaleLabelsText"), + jsFunc(t, html, "stageTrackerHopName"), + jsFunc(t, html, "stageTrackerTrailText"), jsFunc(t, html, "stageTrackerTooltip"), jsFunc(t, html, "stageTrackerChipsHtml"), jsFunc(t, html, "stageTrackerHeadColsHtml"), diff --git a/src/pkg/dashboard/stage_tracker_trail.test.js b/src/pkg/dashboard/stage_tracker_trail.test.js new file mode 100644 index 0000000000..fcbfb0dd2d --- /dev/null +++ b/src/pkg/dashboard/stage_tracker_trail.test.js @@ -0,0 +1,79 @@ +// The Activity Monitor hover's "Trail:" clause names the item's recent hops +// by stage word (hivecommons/hive#14787 showed "undefined → undefined → …" +// because the renderer read a field the payload never carried). The helpers +// are lifted straight out of index.html so this test runs against the +// shipped source; the fixture is the live /api/stage-tracker shape. +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(/const STAGE_TRACKER_TRAIL_HOPS = \d+;/, 'STAGE_TRACKER_TRAIL_HOPS'), + pick(/function stageTrackerHopName\(h\) \{[\s\S]*?\n \}\n/, 'stageTrackerHopName'), + pick(/function stageTrackerTrailText\(item\) \{[\s\S]*?\n \}\n/, 'stageTrackerTrailText'), +].join('\n'); + +const stages = [ + { number: 10, short: 'Actionable', label: 'stage/010-actionable' }, + { number: 50, short: 'CI / Review', label: 'stage/050-review-pending' }, + { number: 71, short: 'Needs author', label: 'stage/071-needs-author' }, + { number: 85, short: 'Needs human decision', label: 'stage/085-needs-decision' }, + { number: 90, label: 'stage/090-ready-for-human-merge' }, +]; + +function load(tracker) { + return new Function('_stageTracker', src + '; return { hopName: stageTrackerHopName, trail: stageTrackerTrailText };')(tracker); +} + +// The hops /api/stage-tracker emitted for hivecommons/hive#14787 (StageTrackerHop: number, slug, at, reason, from). +const live14787 = { kind: 'pr', number: 14787, stage: 85, modifiers: ['needs-human'], history: [ + { number: 50, slug: 'review-pending', at: '2026-10-27T21:27:53-04:00', reason: 'required-check-pending:Sign-off survives the squash' }, + { number: 85, slug: 'needs-decision', at: '2026-10-27T21:38:16-04:00', reason: 'parked on a person: needs-human', from: 50 }, + { number: 50, slug: 'review-pending', at: '2026-10-27T21:38:50-04:00', reason: 'required-check-pending:build-and-test', from: 85 }, + { number: 71, slug: 'needs-author', at: '2026-10-27T21:53:36-04:00', reason: 'check-failing:coverage', from: 50 }, + { number: 50, slug: 'review-pending', at: '2026-10-27T21:57:26-04:00', reason: 'label:needs-human', from: 71 }, + { number: 71, slug: 'needs-author', at: '2026-10-27T22:19:45-04:00', reason: 'reviewer-verdict:changes_requested', from: 50 }, + { number: 50, slug: 'review-pending', at: '2026-10-27T23:59:38-04:00', reason: 'label:needs-human', from: 71 }, + { number: 85, slug: 'needs-decision', at: '2026-10-28T00:19:25-04:00', reason: 'label:needs-human', from: 50 }, +] }; + +test('the trail names the last hops of the live payload by stage word', () => { + const { trail } = load({ stages }); + assert.strictEqual(trail(live14787), 'CI / Review → Needs author → CI / Review → Needs human decision'); + assert.ok(!trail(live14787).includes('undefined')); +}); + +test('a hop that cannot be named is left out, never printed as undefined', () => { + const { hopName, trail } = load({ stages }); + assert.strictEqual(hopName({ number: 999 }), ''); + assert.strictEqual(hopName({}), ''); + assert.strictEqual(hopName(null), ''); + assert.strictEqual(hopName({ number: 0 }), 'Open'); + assert.strictEqual(hopName({ number: 90 }), 'stage/090-ready-for-human-merge', 'label stands in when there is no short word'); + assert.strictEqual(hopName({ number: 999, slug: 'brand-new' }), 'brand-new', 'the slug stands in for a stage the table does not know'); + assert.strictEqual(trail({ history: [{ number: 50 }, { number: 999 }, { number: 85 }] }), 'CI / Review → Needs human decision'); +}); + +test('the clause is omitted when fewer than two hops can be named', () => { + const { trail } = load({ stages }); + assert.strictEqual(trail({ history: [{ number: 50 }] }), ''); + assert.strictEqual(trail({ history: [{ number: 50 }, { number: 999 }] }), ''); + assert.strictEqual(trail({ history: [] }), ''); + assert.strictEqual(trail({}), ''); + assert.strictEqual(trail(null), ''); +}); + +test('before the stage table loads the slug carries the trail', () => { + const { trail } = load(null); + assert.strictEqual(trail(live14787), 'review-pending → needs-author → review-pending → needs-decision'); + assert.strictEqual(trail({ history: [{ number: 50 }, { number: 85 }] }), '', 'bare numbers with no table name nothing'); +}); diff --git a/src/pkg/dashboard/stage_tracker_trail_test.go b/src/pkg/dashboard/stage_tracker_trail_test.go new file mode 100644 index 0000000000..b1dd6bb2a0 --- /dev/null +++ b/src/pkg/dashboard/stage_tracker_trail_test.go @@ -0,0 +1,70 @@ +package dashboard + +import ( + "encoding/json" + "regexp" + "strings" + "testing" + "time" + + "github.com/hivecommons/hive/pkg/stagelabels" +) + +// The tooltip's trail is built from the payload's history entries, so the +// fields the SPA reads must be the ones the server writes. hivecommons/hive +// #14787 hovered as "Trail: undefined → undefined → undefined → undefined" +// because index.html read h.stage while StageTrackerHop emits number/slug. +func TestStageTrackerTrailFieldsMatchSPA(t *testing.T) { + now := time.Date(2026, 10, 28, 1, 0, 0, 0, time.UTC) + clock := now + store := stagelabels.NewStore("", func() time.Time { return clock }) + key := stagelabels.Key("hivecommons/hive", 14787) + store.Observe(key, stagelabels.ReviewPending, "required-check-pending:build-and-test") + clock = now.Add(10 * time.Minute) + store.Observe(key, stagelabels.NeedsAuthor, "check-failing:coverage") + clock = now.Add(20 * time.Minute) + store.Observe(key, stagelabels.ReviewPending, "label:needs-human") + clock = now.Add(30 * time.Minute) + store.Observe(key, stagelabels.NeedsDecision, "parked on a person: needs-human") + rec, _ := store.Get(key) + + hops := stageTrackerHistory(rec) + if len(hops) != 4 { + t.Fatalf("history = %d hops, want 4: %+v", len(hops), hops) + } + raw, err := json.Marshal(hops) + if err != nil { + t.Fatal(err) + } + var wire []map[string]any + if err := json.Unmarshal(raw, &wire); err != nil { + t.Fatal(err) + } + wantNums := []float64{50, 71, 50, 85} + wantSlugs := []string{"review-pending", "needs-author", "review-pending", "needs-decision"} + for i, h := range wire { + if h["number"] != wantNums[i] || h["slug"] != wantSlugs[i] || h["at"] == nil { + t.Fatalf("hop %d on the wire = %v, want number %v slug %q and an at", i, h, wantNums[i], wantSlugs[i]) + } + if _, ok := h["stage"]; ok { + t.Fatalf("hop %d carries a stage field the SPA must not depend on: %v", i, h) + } + } + + html := indexHTML(t) + hopName := jsFunc(t, html, "stageTrackerHopName") + for _, field := range []string{"h.number", "h.slug"} { + if !strings.Contains(hopName, field) { + t.Fatalf("stageTrackerHopName does not read %s — the trail would print undefined:\n%s", field, hopName) + } + } + tip := jsFunc(t, html, "stageTrackerTooltip") + if !strings.Contains(tip, "stageTrackerTrailText(item)") { + t.Fatalf("stageTrackerTooltip must build its trail through stageTrackerTrailText:\n%s", tip) + } + // No tracker tooltip code may stringify a history hop field directly — + // that is exactly how "undefined" reached the hover. + if m := regexp.MustCompile(`String\(h\.(stage|number|slug)\)`).FindString(tip + jsFunc(t, html, "stageTrackerTrailText")); m != "" { + t.Fatalf("tooltip stringifies a hop field without naming it: %s", m) + } +} diff --git a/src/pkg/dashboard/stage_tracker_ui_test.go b/src/pkg/dashboard/stage_tracker_ui_test.go index b056463918..31718b5d0c 100644 --- a/src/pkg/dashboard/stage_tracker_ui_test.go +++ b/src/pkg/dashboard/stage_tracker_ui_test.go @@ -156,6 +156,8 @@ func TestStageTrackerRows(t *testing.T) { jsFunc(t, html, "stageTrackerRegressionHandled"), jsFunc(t, html, "stageTrackerRegressionText"), jsFunc(t, html, "stageTrackerStaleLabelsText"), + jsFunc(t, html, "stageTrackerHopName"), + jsFunc(t, html, "stageTrackerTrailText"), jsFunc(t, html, "stageTrackerTooltip"), jsFunc(t, html, "stageTrackerChipsHtml"), jsFunc(t, html, "stageTrackerHeadColsHtml"), @@ -204,6 +206,8 @@ const stages = [ { number: 95, label: 'Pre-merge soak', short: 'Soaking', description: 'Lane admitted; the pre-merge soak window is running before the merge is attempted' }, { number: 100, label: 'Merge queue', short: 'Merge queue' }, { number: 110, label: 'Merged', short: 'Merged' }, ]; +// The stage table the tooltip's trail names its hops from (fetchStageTracker fills it live). +var _stageTracker = { stages }; // needs-rebase always lands a PR in 070/071/072 (automerge_stage_labels.go), so a // fixture pairing it with 050/060 would draw a contradictory row. const rebaseCoherent = (it) => { if ((it.modifiers || []).includes('needs-rebase')) assert.ok(![50, 60].includes(Number(it.stage)), 'fixture #' + it.number + ' pairs needs-rebase with stage ' + it.stage); (it.linked_prs || []).forEach(rebaseCoherent); }; @@ -415,7 +419,7 @@ assert.strictEqual(stageTrackerHeadline({ stage: 95, kind: 'issue', soak_remaini assert.strictEqual(stageTrackerAnchor(95, stages, 'pr'), STAGE_TRACKER_MERGE_COLUMN, '095 anchors on the merge gate column'); // PR returned to contributor: detour badge rides Review; chip cap = author kind + first modifier (+N). -row = stageTrackerRowHtml({ repo: 'acme/console', number: 102, kind: 'pr', title: 'Fix flaky', stage: 72, lane: 'contributor', tier: 'trusted', author: 'karibhou', author_kind: 'clanker', author_kind_source: 'inferred', modifiers: ['needs-rebase', 'needs-human'], caption: 'Returned to @karibhou', history: [{stage:50},{stage:60},{stage:72}] }, stages, ctx); +row = stageTrackerRowHtml({ repo: 'acme/console', number: 102, kind: 'pr', title: 'Fix flaky', stage: 72, lane: 'contributor', tier: 'trusted', author: 'karibhou', author_kind: 'clanker', author_kind_source: 'inferred', modifiers: ['needs-rebase', 'needs-human'], caption: 'Returned to @karibhou', history: [{number:50,slug:'review-pending'},{number:60,slug:'reviewed'},{number:72,slug:'returned-to-contributor',from:60}] }, stages, ctx); assert.deepStrictEqual(segStates(row), [D, D, D, D, 'active detoured', T, 'todo cap']); assert.ok(row.includes('Returned to contributor')); // Invariant: a PR never occupies the issue slot. A PR with no linked issue @@ -432,7 +436,7 @@ assert.ok(prCol(row)[0].includes('ham-author-ico ham-author-clanker') && prCol(r assert.strictEqual(titles(row, 'Fix flaky'), 1, 'title appears once'); assert.strictEqual(chips(row), 1, 'author kind is an icon, not a chip'); assert.ok(row.includes('ham-mod-needs-human">needs human +1'), row); -assert.ok(tooltip(row).includes('Flags: needs-rebase, needs-human') && tooltip(row).includes('Trail: 050 → 060 → 072'), tooltip(row)); +assert.ok(tooltip(row).includes('Flags: needs-rebase, needs-human') && tooltip(row).includes('Trail: CI / Review → Reviewed → Returned to contributor'), tooltip(row)); // PR reviewed (060): Review done, Merge gate lit, no detour. row = stageTrackerRowHtml({ repo: 'acme/console', number: 107, kind: 'pr', stage: 60 }, stages, ctx); @@ -441,7 +445,7 @@ row = stageTrackerRowHtml({ repo: 'acme/console', number: 109, kind: 'pr', stage assert.ok(row.includes('Ready for auto merge') && strip(row).includes('title="Awaiting merge admission — not yet admitted — soak 20m left · Next move: hive"'), 'chevron tooltip carries 080: ' + row); // PR regressed from the queue back to review-pending: Review lit, "Sent back" in the tooltip. -row = stageTrackerRowHtml({ repo: 'acme/console', number: 103, kind: 'pr', stage: 70, modifiers: ['regressed', 'needs-rebase'], history: [{stage:80},{stage:100},{stage:70}] }, stages, ctx); +row = stageTrackerRowHtml({ repo: 'acme/console', number: 103, kind: 'pr', stage: 70, modifiers: ['regressed', 'needs-rebase'], history: [{number:80,slug:'awaiting-merge-admission'},{number:100,slug:'merge-queue'},{number:70,slug:'fixing',from:100,regressed:true}] }, stages, ctx); assert.deepStrictEqual(segStates(row), [D, D, D, D, 'active detoured', T, 'todo cap']); assert.ok(tooltip(row).startsWith('Sent back')); assert.ok(row.includes('ham-mod-regressed'), 'regressed outranks needs-rebase for the single chip'); @@ -500,10 +504,34 @@ row = stageTrackerRowHtml({ repo: 'acme/console', number: 108, kind: 'pr', stage assert.ok(row.includes('aria-label="Next move: clanker"') && row.includes('Returned to contributorNeeds authorPR in progressWhere to get help return text; } + // The name of one trail hop. The payload's history entries carry + // {number, slug, at, ...} (StageTrackerHop); the strip word for the + // number wins, the slug stands in before the stage table is loaded, and + // '' means the hop cannot be named and is left out of the trail. + function stageTrackerHopName(h) { + if (!h || typeof h !== 'object') return ''; + const raw = h.number !== undefined ? h.number : h.stage; + const num = Number(raw); + if (raw !== undefined && raw !== null && raw !== '' && !isNaN(num)) { + if (num === 0) return 'Open'; + const st = ((_stageTracker && _stageTracker.stages) || []).find(s => Number(s.number) === num); + if (st && (st.short || st.label)) return st.short || st.label; + } + return h.slug ? String(h.slug) : ''; + } + + // "Trail: CI / Review → Needs human decision" — the last few hops of the + // item's history by stage name; '' when fewer than two hops can be named. + function stageTrackerTrailText(item) { + const hist = Array.isArray(item && item.history) ? item.history : []; + const names = hist.slice(-STAGE_TRACKER_TRAIL_HOPS).map(stageTrackerHopName).filter(Boolean); + return names.length > 1 ? names.join(' → ') : ''; + } + // Row tooltip: headline, reason, repo, author, flags, since, recent hops. function stageTrackerTooltip(item, nowMs) { const ak = item.author_kind || ''; const mods = Array.isArray(item.modifiers) ? item.modifiers : []; const sinceMs = Date.parse(item.stage_since || ''); - const trail = Array.isArray(item.history) && item.history.length > 1 - ? item.history.slice(-STAGE_TRACKER_TRAIL_HOPS).map(h => String(h.stage).padStart(3, '0')).join(' → ') : ''; + const trail = stageTrackerTrailText(item); const openHeld = (Number(item.stage) || 0) === 0 && mods.indexOf('hold') >= 0; const lines = openHeld ? [stageTrackerHeadline(item) + (item.caption || item.reason ? ' · ' + (item.caption || item.reason) : '') + (item.repo ? ' · ' + item.repo : '')]