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-14928-tracker-trail-undefined.md
Original file line number Diff line number Diff line change
@@ -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)).
4 changes: 4 additions & 0 deletions src/pkg/dashboard/stage_tracker_motion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down Expand Up @@ -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"),
Expand Down
2 changes: 2 additions & 0 deletions src/pkg/dashboard/stage_tracker_pills_gate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
2 changes: 2 additions & 0 deletions src/pkg/dashboard/stage_tracker_repo_grouping_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
79 changes: 79 additions & 0 deletions src/pkg/dashboard/stage_tracker_trail.test.js
Original file line number Diff line number Diff line change
@@ -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');
});
70 changes: 70 additions & 0 deletions src/pkg/dashboard/stage_tracker_trail_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
}
38 changes: 33 additions & 5 deletions src/pkg/dashboard/stage_tracker_ui_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down Expand Up @@ -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); };
Expand Down Expand Up @@ -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('<span class="ham-detour">Returned to contributor</span>'));
// Invariant: a PR never occupies the issue slot. A PR with no linked issue
Expand All @@ -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</span>'), 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);
Expand All @@ -441,7 +445,7 @@ row = stageTrackerRowHtml({ repo: 'acme/console', number: 109, kind: 'pr', stage
assert.ok(row.includes('<span class="ham-seg-t">Ready for auto merge</span>') && 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');
Expand Down Expand Up @@ -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('<span class="ham-detour">Returned to contributor</span><svg class="ham-ico ham-actor-ico"'), row);
// 071 needs-author: a human's red PR rides the Review column as its own
// detour, the person as the mover.
row = stageTrackerRowHtml({ repo: 'acme/console', number: 109, kind: 'pr', stage: 71, author: 'sam', author_kind: 'human', history: [{stage:50},{stage:71}] }, stages, ctx);
row = stageTrackerRowHtml({ repo: 'acme/console', number: 109, kind: 'pr', stage: 71, author: 'sam', author_kind: 'human', history: [{number:50,slug:'review-pending'},{number:71,slug:'needs-author',from:50}] }, stages, ctx);
assert.deepStrictEqual(segStates(row), [D, D, D, D, 'active detoured', T, 'todo cap']);
assert.ok(row.includes('aria-label="Next move: human"') && row.includes('<span class="ham-detour">Needs author</span><svg class="ham-ico ham-actor-ico"'), row);
assert.ok(tooltip(row).includes('Trail: 050 β†’ 071'), tooltip(row));
assert.ok(tooltip(row).includes('Trail: CI / Review β†’ Needs author'), tooltip(row));
// The trail names hops from the payload's {number, slug} entries (#14787
// showed "undefined β†’ undefined β†’ …" when it read a field the server never
// sent); the last STAGE_TRACKER_TRAIL_HOPS hops only; an unnamed hop is left
// out rather than printed as "undefined"; the clause is omitted when fewer
// than two hops can be named.
const live14787 = { kind: 'pr', number: 14787, stage: 85, modifiers: ['needs-human'], history: [
{ number: 50, slug: 'review-pending', at: '2026-10-27T21:27:53Z' }, { number: 85, slug: 'needs-decision', from: 50 },
{ number: 50, slug: 'review-pending', from: 85 }, { number: 71, slug: 'needs-author', from: 50 },
{ number: 50, slug: 'review-pending', from: 71 }, { number: 71, slug: 'needs-author', from: 50 },
{ number: 50, slug: 'review-pending', from: 71 }, { number: 85, slug: 'needs-decision', from: 50 }] };
assert.strictEqual(stageTrackerTrailText(live14787), 'CI / Review β†’ Needs author β†’ CI / Review β†’ Needs human decision');
assert.ok(!stageTrackerTooltip(live14787, now).includes('undefined'), stageTrackerTooltip(live14787, now));
assert.strictEqual(stageTrackerTrailText({ history: [{ number: 50 }, { number: 999 }, { number: 85 }] }), 'CI / Review β†’ Needs human decision', 'an unnamed hop is skipped');
assert.strictEqual(stageTrackerTrailText({ history: [{ number: 50 }, {}, { foo: 1 }] }), '', 'one nameable hop is no trail');
assert.strictEqual(stageTrackerTrailText({ history: [{ number: 50 }] }), '', 'a single hop is no trail');
assert.strictEqual(stageTrackerTrailText({ history: [] }), '');
assert.strictEqual(stageTrackerTrailText({}), '');
assert.strictEqual(stageTrackerTrailText({ history: [{ number: 0 }, { number: 10 }] }), 'Open β†’ Actionable', '000 reads as Open');
assert.ok(!stageTrackerTooltip({ kind: 'pr', number: 1, stage: 50, history: [{ number: 999 }, { number: 998 }] }, now).includes('Trail:'), 'no Trail clause when nothing can be named');
const savedStages = _stageTracker;
_stageTracker = null;
assert.strictEqual(stageTrackerTrailText(live14787), 'review-pending β†’ needs-author β†’ review-pending β†’ needs-decision', 'the slug stands in before the stage table loads');
assert.strictEqual(stageTrackerTrailText({ history: [{ number: 50 }, { number: 85 }] }), '', 'numbers alone, no table, no slug: nothing to name');
_stageTracker = savedStages;
row = stageTrackerRowHtml({ repo: 'acme/console', number: 7, kind: 'issue', stage: 40, linked_prs: [{ number: 108, author_kind: 'clanker', stage: 30 }] }, stages, ctx);
assert.ok(subs(row).length === 0 && strip(row).includes('aria-label="Next move: clanker"') && strip(row).includes('<span class="ham-seg-t">PR in progress</span><svg class="ham-ico ham-actor-ico"'), 'single covering PR: the issue strip lights PR in progress with the PR author as the mover: ' + row);
row = stageTrackerRowHtml({ repo: 'acme/console', number: 7, kind: 'issue', stage: 40, linked_prs: [{ number: 108, author_kind: 'clanker', stage: 30 }, { number: 109, author_kind: 'hive', stage: 50 }] }, stages, ctx);
Expand Down
Loading
Loading