From 91e97fa0ff8471e8618f64b72c1e12c35d11f9fa Mon Sep 17 00:00:00 2001 From: Andrew Anderson Date: Thu, 29 Oct 2026 11:29:55 -0400 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=90=9B=20tracker:=20merge=20outcomes?= =?UTF-8?q?=20always=20render=20in=20the=20Merge=20gate=20column;=20pendin?= =?UTF-8?q?g=20CI=20is=20not=20'red'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A merge outcome (merging / merge-failed) on a row the lane set back to 060 was drawn in CI / Review because stageTrackerAnchor mapped stage 60 to column 50 regardless of merge_gate; the chip carried GitHub's raw error text (a PUT …/merge URL) and the caption read 'CI is red (check-pending)' and 'fell back to stage/060-reviewed'. - stageTrackerAnchor: a merge_gate state of merging / merge-failed anchors the row in the Merge gate column whatever its numeric stage. - Go: stageTrackerMergeRefusal translates GitHub's refusal into a kind, a plain sentence and (for 405 'required status checks are expected') the check count; the SPA renders a fixed short chip ('Waiting for CI · 4 checks', 'Merge failed · retrying', 'Merge failed · branch protection') with the raw text only after 'Details:' in the tooltip; .ham-gate-detail is clamped with an ellipsis. - stageTrackerCIStateWords: check-/status- tokens read 'CI running', 'CI green', 'CI failed: ' — pending is never red (Go caption and SPA gate words). - stageTrackerStageName: cues and tooltips name a stage in words ('back to Reviewed'), not by its slug — a minimal local fix; the copy sweep retires stage slugs globally. - automerge: the sweep remembers GitHub's 'required status checks are expected' 405 per head and skips the merge call as check-pending while the PR is still blocked, instead of re-PUTting /merge every pass. Fixes #15404 Signed-off-by: Andrew Anderson --- changelog.d/fixed-merge-gate-column.md | 1 + src/docs/dashboard-sections.md | 5 +- src/pkg/dashboard/stage_tracker.go | 12 +- src/pkg/dashboard/stage_tracker_ci_words.go | 37 +++++ .../stage_tracker_merge_failed_column_test.go | 135 ++++++++++++++++++ src/pkg/dashboard/stage_tracker_merge_gate.go | 9 ++ .../stage_tracker_merge_gate_test.go | 13 +- .../dashboard/stage_tracker_merge_refusal.go | 85 +++++++++++ .../stage_tracker_merge_refusal_test.go | 33 +++++ .../stage_tracker_merging_hold_test.go | 4 +- src/pkg/dashboard/stage_tracker_test.go | 54 ++++--- src/pkg/dashboard/static-src/css/tracker.css | 5 +- .../dashboard/static-src/js/tracker-motion.js | 6 +- .../dashboard/static-src/js/tracker-row.js | 18 ++- .../dashboard/static-src/js/tracker-words.js | 78 ++++++++-- src/pkg/dashboard/static/index.html | 107 +++++++++++--- .../automerge/automerge_contributor_lane.go | 2 +- .../automerge/automerge_merge_refusal.go | 56 +++++++- .../automerge/automerge_merge_refusal_test.go | 41 ++++++ src/pkg/github/automerge/automerge_sweep.go | 4 +- 20 files changed, 626 insertions(+), 79 deletions(-) create mode 100644 changelog.d/fixed-merge-gate-column.md create mode 100644 src/pkg/dashboard/stage_tracker_ci_words.go create mode 100644 src/pkg/dashboard/stage_tracker_merge_failed_column_test.go create mode 100644 src/pkg/dashboard/stage_tracker_merge_refusal.go create mode 100644 src/pkg/dashboard/stage_tracker_merge_refusal_test.go diff --git a/changelog.d/fixed-merge-gate-column.md b/changelog.d/fixed-merge-gate-column.md new file mode 100644 index 0000000000..d089f5d203 --- /dev/null +++ b/changelog.d/fixed-merge-gate-column.md @@ -0,0 +1 @@ +- Activity Monitor: a merge outcome ("Merging", "Merge failed", "Waiting for CI") always renders in the Merge gate column, whatever stage the lane fell back to; the merge-failed chip is a fixed short phrase (GitHub's refusal translated to plain words — "4 required checks haven't finished", "branch protection blocks it", "needs rebase", "not allowed" — with the raw text only in the tooltip's Details line, clamped by CSS), "retrying" while the sweep is on it; pending CI reads "CI running", never "CI is red"; cues say "back to Reviewed" instead of a stage slug; and the automerge sweep remembers GitHub's "required status checks are expected" refusal per head so it stops re-PUTting /merge every pass while the PR is still blocked (hivecommons/docs#512). diff --git a/src/docs/dashboard-sections.md b/src/docs/dashboard-sections.md index 5d480e43b0..7bb90d42b7 100644 --- a/src/docs/dashboard-sections.md +++ b/src/docs/dashboard-sections.md @@ -1155,7 +1155,10 @@ Every PR at the gate now carries `merge_gate: {state, reason, sweep_running, las | any of the above while a pass is evaluating this PR | the stage's word | *merge sweep running* | ⟳ (static) — *hive's merge sweep is running on this PR now.* | | 100 merge queue | **Merging** | — | ⟳ (static) — *Admitted and soaked; hive is merging it now (GitHub merge queue / merge window).* | | any stage while hive's merge call is in flight (`merge_gate.merging_since`, `merge_path`) | **Merging** | *merge call in flight*, then *merge landed* while the SPA holds the row | ⟳ (static) — *hive is merging it now (automerge sweep) — the merge call has been in flight since 3s ago.* | -| any stage after GitHub refused hive's merge call (`merge_gate.state: merge-failed`, `merge_failed`, `merge_failed_at`) | **Merge failed** | the refusal's first line — *405 Pull Request is not mergeable* | 🕓 clock — *hive tried to merge this (maintainer merge from the dashboard) 9s ago and GitHub refused: …. The lane re-evaluates it on its next pass.* | +| any stage after GitHub refused hive's merge call (`merge_gate.state: merge-failed`, `merge_failed`, `merge_failed_kind`, `merge_failed_text`, `merge_failed_at`) | **Merge failed** | the refusal translated to a short phrase — *branch protection*, *needs rebase*, *not allowed*, *review required*, or *retrying* while the sweep is on it; never GitHub's raw text | 🕓 clock — *hive tried to merge this (maintainer merge from the dashboard) 9s ago and GitHub refused — branch protection blocks it. The lane re-evaluates it on its next pass. Details: 405 Pull Request is not mergeable* | +| any stage after the merge call drew *N of M required status checks are expected* (`merge_failed_kind: checks-pending`, `merge_failed_checks`) | **Waiting for CI** | *4 checks* | ⟳ while the sweep is on it, else 🕓 — *hive tried to merge this (automerge sweep) 1m ago before its required checks had reported — 4 required checks haven't finished. It merges once they pass.* | + +A merge outcome (**Merging**, **Merge failed**, **Waiting for CI**) always lights the **Merge gate** column, whatever numeric stage the lane fell back to (hivecommons/docs#512 drew "Merge failed" in CI / Review because the PR sat at 060). | 110 | **Merged** (the ✓ cap) | — | — | #### Merging is held for the toast's lifetime diff --git a/src/pkg/dashboard/stage_tracker.go b/src/pkg/dashboard/stage_tracker.go index 174fdabbe8..3ba187a6c1 100644 --- a/src/pkg/dashboard/stage_tracker.go +++ b/src/pkg/dashboard/stage_tracker.go @@ -1319,8 +1319,13 @@ func humanizeStageReason(reason string) string { return "no verified claim links this PR to an issue" case "contributor-lane:claim-tier-untrusted": return "author's claim tier is below the auto-merge tiers" - case "ci-red", "check-runs": - return "CI is red" + case "ci-red": + return "CI failed" + case "check-runs", "status-check": + return "CI checks could not be read" + } + if words, ok := stageTrackerCIStateWords(r); ok { + return words } if strings.HasPrefix(lower, "mirrors pr #") { return "mirrors PR " + r[len("mirrors PR "):] @@ -1379,9 +1384,6 @@ func humanizeStageReason(reason string) string { if strings.HasPrefix(lower, "release-hold") { return "release hold" } - if strings.HasPrefix(lower, "status-") || strings.HasPrefix(lower, "check-") { - return "CI is red (" + r + ")" - } switch lower { case stageengineprstage.ContributorLaneReasonWorkflowPath: return "workflow path" diff --git a/src/pkg/dashboard/stage_tracker_ci_words.go b/src/pkg/dashboard/stage_tracker_ci_words.go new file mode 100644 index 0000000000..42a7190d00 --- /dev/null +++ b/src/pkg/dashboard/stage_tracker_ci_words.go @@ -0,0 +1,37 @@ +package dashboard + +import "strings" + +// stageTrackerCIStateWords renders a commit-CI reason token +// (github.CommitCIState.Reason: "check-pending", "status-pending", +// "check-", "status-", "check-failing:") as the +// state it names. Pending is not red: the tracker once captioned a 060 +// row "CI is red (check-pending)" while its checks were still running +// (hivecommons/docs#512). ok is false for anything that is not a CI token. +func stageTrackerCIStateWords(reason string) (words string, ok bool) { + r := strings.TrimSpace(reason) + lower := strings.ToLower(r) + var kind, rest string + switch { + case strings.HasPrefix(lower, "check-"): + kind, rest = "check", r[len("check-"):] + case strings.HasPrefix(lower, "status-"): + kind, rest = "status", r[len("status-"):] + default: + return "", false + } + if name, found := strings.CutPrefix(rest, "failing:"); found { + return "CI failed: " + name, true + } + switch strings.ToLower(rest) { + case "pending", "queued", "in_progress", "waiting", "requested", "expected": + return "CI running", true + case "success": + return "CI green", true + case "failure", "error": + return "CI failed", true + case "neutral", "skipped": + return "CI skipped (" + kind + " " + strings.ToLower(rest) + ")", true + } + return "CI failed (" + strings.ReplaceAll(strings.ToLower(rest), "_", " ") + ")", true +} diff --git a/src/pkg/dashboard/stage_tracker_merge_failed_column_test.go b/src/pkg/dashboard/stage_tracker_merge_failed_column_test.go new file mode 100644 index 0000000000..9f39f7e320 --- /dev/null +++ b/src/pkg/dashboard/stage_tracker_merge_failed_column_test.go @@ -0,0 +1,135 @@ +package dashboard + +import ( + "strings" + "testing" +) + +// TestStageTrackerMergeFailedColumnNode: the operator's row +// (hivecommons/docs#496 → docs#512, 2026-10-29 11:04 ET). The lane fell +// back to 060 after the automerge sweep's merge call drew GitHub's 405 "4 +// of 4 required status checks are expected", and the tracker drew the amber +// "⟳ Merge failed · merge sweep running ⬡" chip in CI / Review with the raw +// "PUT https://api.github.com/…" error spilling out of it. A merge outcome +// always lights the Merge gate column; the chip is a fixed short phrase +// (no URL, no verb, ≤ 5 words) with GitHub's words in the tooltip's +// Details line; pending CI is "CI running", never "red"; and the cue +// names the stage in plain words, not "stage/060-reviewed". +func TestStageTrackerMergeFailedColumnNode(t *testing.T) { + html := indexHTML(t) + for _, want := range []string{ + `if (mg && (mg.state === 'merging' || mg.state === 'merge-failed') && cur > STAGE_TRACKER_PR_COLUMN) return STAGE_TRACKER_MERGE_COLUMN;`, + `const anchor = stageTrackerAnchor(cur, stages, item.via_pr ? 'pr' : item.kind, item);`, + `stageTrackerAnchor(item.stage, stages, item.via_pr ? 'pr' : item.kind, item);`, + `label: (typeof stageTrackerStageName === 'function' && (stageTrackerStageName(tipStage) || stageTrackerStageName(st))) || tipStage.label || st.label || String(n)`, + `.ham-gate-detail { font-weight: normal; opacity: 0.85; white-space: nowrap; font-variant-numeric: tabular-nums; display: inline-block; vertical-align: bottom; max-width: 12em; overflow: hidden; text-overflow: ellipsis; }`, + } { + if !strings.Contains(html, want) { + t.Errorf("index.html missing merge-outcome column wiring %q", want) + } + } + runStageTrackerRowActionsScript(t, "function esc(s) { return String(s).replace(/&/g, '&').replace(/ new Date(ms).toISOString(); +const stages = [{ number: 50, label: 'stage/050-review-pending', short: 'CI / Review' }, { number: 60, label: 'stage/060-reviewed', short: '' }, { number: 80, label: 'stage/080-awaiting-merge', short: 'Merge gate' }]; +const raw = 'PUT https://api.github.com/repos/hivecommons/docs/pulls/512/merge: 405 4 of 4 required status checks are expected. []'; +const gate = (extra) => Object.assign({ state: 'merge-failed', reason: 'check-pending', sweep_running: true, merge_path: 'sweep', merge_failed: raw, merge_failed_at: iso(now - 60000), next_sweep_at: iso(now + 7000), last_sweep_at: iso(now - 22000) }, extra || {}); +const row = (mg) => ({ repo: 'hivecommons/docs', number: 512, kind: 'pr', stage: 60, stage_label: 'stage/060-reviewed', reason: 'check-pending', modifiers: [], merge_gate: mg }); +const words = s => s.trim().split(/\s+/).filter(w => w !== '·'); +const plain = s => !/http|\bPUT\b|api\.github\.com/i.test(s); + +// 1. Column: the merge outcome lights Merge gate (80), whatever stage the +// lane fell back to; the same stage without a merge call stays in CI / +// Review (50); a merged / open row is unaffected. +assert.strictEqual(stageTrackerAnchor(60, stages, 'pr', row(gate())), STAGE_TRACKER_MERGE_COLUMN, 'merge-failed at 060 → Merge gate'); +assert.strictEqual(stageTrackerAnchor(60, stages, 'pr', row(gate({ state: 'merging', merge_failed: '' }))), STAGE_TRACKER_MERGE_COLUMN, 'merging at 060 → Merge gate'); +assert.strictEqual(stageTrackerAnchor(50, stages, 'pr', row(gate())), STAGE_TRACKER_MERGE_COLUMN, 'merge-failed at 050 → Merge gate'); +assert.strictEqual(stageTrackerAnchor(60, stages, 'pr', row({ state: 'gate-pending', reason: 'check-pending' })), 50, 'no merge call: 060 stays in CI / Review'); +assert.strictEqual(stageTrackerAnchor(60, stages, 'pr'), 50, 'no item: unchanged'); +assert.strictEqual(stageTrackerAnchor(STAGE_TRACKER_TERMINAL, stages, 'pr', row(gate())), STAGE_TRACKER_TERMINAL); +assert.strictEqual(stageTrackerAnchor(30, stages, 'pr', row(gate())), 30, 'a stale gate on a PR back in progress does not jump it forward'); + +// 2. The chip for this exact payload (Go translated the 405): the sweep +// called too early, so it is "Waiting for CI · 4 checks", not a failure. +let info = stageTrackerMergeGateInfo(row(gate({ merge_failed_kind: 'checks-pending', merge_failed_text: "4 required checks haven't finished", merge_failed_checks: 4 })), now); +assert.strictEqual(info.word, 'Waiting for CI'); +assert.strictEqual(info.detail, '4 checks'); +assert.strictEqual(info.cue, 'running', 'the sweep is on it'); +assert.ok(info.tip.includes("before its required checks had reported — 4 required checks haven't finished"), info.tip); +assert.ok(info.tip.includes('Details: ' + raw), 'raw error only after Details: ' + info.tip); +assert.ok(!info.tip.startsWith('stage/'), info.tip); +// Older payload without the translated fields: the SPA classifies the raw text itself. +info = stageTrackerMergeGateInfo(row(gate()), now); +assert.strictEqual(info.word + ' · ' + info.detail, 'Waiting for CI · 4 checks', 'raw-only payload'); +assert.ok(info.tip.includes("4 required checks haven't finished"), info.tip); + +// 3. Every merge-failed chip is a fixed short phrase: no URL, no verb, ≤ 5 words. +const cases = [ + [gate(), 'Waiting for CI · 4 checks'], + [gate({ sweep_running: false }), 'Waiting for CI · 4 checks'], + [gate({ merge_failed: '405 Pull Request is not mergeable' }), 'Merge failed · retrying'], + [gate({ merge_failed: '405 Pull Request is not mergeable', sweep_running: false }), 'Merge failed · branch protection'], + [gate({ merge_failed: '409 Head branch was modified. Review and try the merge again.', sweep_running: false }), 'Merge failed · needs rebase'], + [gate({ merge_failed: '403 Resource not accessible by integration', sweep_running: false }), 'Merge failed · not allowed'], + [gate({ merge_failed: 'context deadline exceeded', sweep_running: false }), 'Merge failed · GitHub refused'], + [gate({ merge_failed: 'context deadline exceeded', merge_failed_kind: 'refused', merge_failed_text: 'GitHub refused the merge', sweep_running: false }), 'Merge failed · GitHub refused'], + [gate({ merge_failed: '405 At least 1 approving review is required', merge_failed_kind: 'review', merge_failed_text: "branch protection wants an approving review hive can't give", sweep_running: false }), 'Merge failed · review required'], + [gate({ merge_failed: '', sweep_running: false }), 'Merge failed · GitHub refused'], +]; +for (const [mg, want] of cases) { + const i = stageTrackerMergeGateInfo(row(mg), now); + const label = i.word + (i.detail ? ' · ' + i.detail : ''); + assert.strictEqual(label, want); + assert.ok(plain(label), 'no raw error in the chip: ' + label); + assert.ok(words(label).length <= 5, 'chip ≤ 5 words: ' + label); + const html = stageTrackerMergeGateWordHtml(row(mg), now); + assert.ok(html.includes('') && plain(html), html); + if (mg.merge_failed) assert.ok(i.tip.includes('Details: ' + mg.merge_failed), 'raw text rides the tooltip: ' + i.tip); +} +// A retry says what GitHub said in the tooltip. +info = stageTrackerMergeGateInfo(row(gate({ merge_failed: '405 Pull Request is not mergeable' })), now); +assert.ok(info.tip.includes('GitHub refused — branch protection blocks it') && info.tip.includes("merge sweep is retrying it now"), info.tip); +assert.strictEqual(info.cue, 'running'); + +// 4. Pending CI is not red. +assert.strictEqual(stageTrackerGateReasonText('check-pending'), 'CI running'); +assert.strictEqual(stageTrackerGateReasonText('required-check-pending:build'), 'CI running (build)'); +assert.strictEqual(stageTrackerGateReasonText('check-failing:unit'), 'CI failed: unit'); +assert.strictEqual(stageTrackerGateReasonText('required-check-failing'), 'CI failed'); + +// 5. The cue names the stage in words, never by its slug. +assert.strictEqual(stageTrackerStageName({ label: 'stage/060-reviewed' }), 'Reviewed'); +assert.strictEqual(stageTrackerStageName({ label: '060-reviewed', short: 'Review passed' }), 'Review passed'); +assert.strictEqual(stageTrackerStageName({ label: 'Claimed' }), 'Claimed'); +assert.strictEqual(stageTrackerStageName(null), ''); +const snap = (stage, label, caption) => ({ stage, label, caption: caption || '', mods: [] }); +assert.strictEqual(stageTrackerEventText(snap(80, 'stage/080-awaiting-merge'), snap(60, 'stage/060-reviewed', 'Review passed; waiting for merge admission — CI running'), stages), 'fell back to Reviewed — Review passed; waiting for merge admission — CI running'); +assert.strictEqual(stageTrackerEventText(snap(50, ''), snap(80, ''), stages), 'moved to Merge gate', 'short word when the table has one'); +console.log('ok'); +`) +} diff --git a/src/pkg/dashboard/stage_tracker_merge_gate.go b/src/pkg/dashboard/stage_tracker_merge_gate.go index 694f212e06..80f0f3648c 100644 --- a/src/pkg/dashboard/stage_tracker_merge_gate.go +++ b/src/pkg/dashboard/stage_tracker_merge_gate.go @@ -69,6 +69,14 @@ type StageTrackerMergeGate struct { // state merge-failed. MergeFailed string `json:"merge_failed,omitempty"` MergeFailedAt *time.Time `json:"merge_failed_at,omitempty"` + // MergeFailedKind / MergeFailedText / MergeFailedChecks: the refusal + // translated (stageTrackerMergeRefusal) — a kind token the SPA maps to + // a short chip detail, the plain sentence for the tooltip, and for + // checks-pending how many required checks are still expected. The raw + // MergeFailed text is for the tooltip's Details line only. + MergeFailedKind string `json:"merge_failed_kind,omitempty"` + MergeFailedText string `json:"merge_failed_text,omitempty"` + MergeFailedChecks int `json:"merge_failed_checks,omitempty"` } // stageTrackerMergeGateState maps a stage to its merge-gate state; "" off @@ -174,6 +182,7 @@ func stageTrackerMergeGateAttempt(mg *StageTrackerMergeGate, a github.MergeAttem mg.MergingSince = &since mg.MergePath = a.Path mg.MergeFailed = a.Error + mg.MergeFailedKind, mg.MergeFailedText, mg.MergeFailedChecks = stageTrackerMergeRefusal(a.Error) at := a.EndedAt mg.MergeFailedAt = &at } diff --git a/src/pkg/dashboard/stage_tracker_merge_gate_test.go b/src/pkg/dashboard/stage_tracker_merge_gate_test.go index 76ba1d7a7c..0d6fb96803 100644 --- a/src/pkg/dashboard/stage_tracker_merge_gate_test.go +++ b/src/pkg/dashboard/stage_tracker_merge_gate_test.go @@ -193,7 +193,7 @@ for (const [n, k] of [[60, 'gate-pending'], [80, 'ready'], [95, 'soaking'], [100 // Captured 15:11 ET: both rows at 060 reviewed, CI pending. #15042 had a // targeted sweep pass on it; #15054 was waiting for the next pass. const pr15042 = { repo: 'hivecommons/hive', number: 15042, kind: 'pr', base_ref: 'v6', author_kind: 'hive', stage: 60, stage_slug: 'reviewed', reason: 'check-pending', - caption: 'Review swarm approved; a gate is still pending — CI is red (check-pending)', + caption: 'Review swarm approved; a gate is still pending — CI running', merge_gate: { state: 'gate-pending', reason: 'check-pending', sweep_running: true, last_sweep_at: iso(now - 30000) } }; const pr15054 = { repo: 'hivecommons/hive', number: 15054, kind: 'pr', base_ref: 'v5', author_kind: 'clanker', stage: 60, stage_slug: 'reviewed', reason: 'required-check-pending:build-and-test', caption: 'Review swarm approved; a gate is still pending — check build-and-test still running', @@ -210,7 +210,7 @@ assert.strictEqual(a.cue, 'running'); assert.strictEqual(a.detail, 'CI in progre assert.strictEqual(a.tip, "Review passed, not yet admitted to auto merge — CI in progress; hive's merge sweep is running on this PR now."); // The pill uses the operator's wording; the tooltip keeps the lane's full reason. assert.strictEqual(b.cue, 'waiting'); assert.strictEqual(b.detail, 'CI in progress'); -assert.ok(b.tip.startsWith('Review passed, not yet admitted to auto merge — CI still running (build-and-test). hive re-checks the gate on its next sweep in 42s.'), b.tip); +assert.ok(b.tip.startsWith('Review passed, not yet admitted to auto merge — CI running (build-and-test). hive re-checks the gate on its next sweep in 42s.'), b.tip); assert.ok(b.tip.includes('A GitHub event on the PR (check run, review, push) triggers a pass sooner.') && b.tip.endsWith('Last checked 2m ago.'), b.tip); // Every row on the gate gets the glyph; the sentence is its title AND aria-label. @@ -245,8 +245,8 @@ assert.strictEqual(stageTrackerMergeGateInfo({ stage: 95, soak_remaining_seconds assert.strictEqual(stageTrackerSoakLeft({ merge_gate: { soak_remaining_seconds: 452 } }), ' — 8m left', 'the 095 chevron tooltip reads the mirrored field too'); // Reason words. -assert.strictEqual(stageTrackerGateReasonText('check-pending'), 'CI still running'); -assert.strictEqual(stageTrackerGateReasonText('required-check-failing:lint'), 'CI is red (lint)'); +assert.strictEqual(stageTrackerGateReasonText('check-pending'), 'CI running'); +assert.strictEqual(stageTrackerGateReasonText('required-check-failing:lint'), 'CI failed: lint'); assert.strictEqual(stageTrackerGateReasonText('conflicting'), 'branch has conflicts'); assert.strictEqual(stageTrackerGateReasonText('something-else'), 'something-else', 'unknown tokens pass through'); assert.strictEqual(stageTrackerGateReasonText(''), ''); @@ -291,6 +291,9 @@ func stageTrackerMergeGateInfoJS(t *testing.T, html string) string { jsConstLine(t, html, "STAGE_TRACKER_MERGE_PATH_WORDS") + "\n" + jsConstLine(t, html, "STAGE_TRACKER_MERGE_FAILED_SHORT_MAX") + "\n" + jsFunc(t, html, "stageTrackerMergeFailedShort") + "\n" + + jsConstLine(t, html, "STAGE_TRACKER_MERGE_REFUSAL_DETAIL") + "\n" + + jsFunc(t, html, "stageTrackerMergeRefusalFromRaw") + "\n" + + jsFunc(t, html, "stageTrackerMergeFailedInfo") + "\n" + jsConstLine(t, html, "STAGE_TRACKER_STAGE_PHRASE") + "\n" + jsFunc(t, html, "stageTrackerStagePhrase") + "\n" + jsFunc(t, html, "stageTrackerCoverReasonText") + "\n" + @@ -355,7 +358,7 @@ assert.ok(!leak.test(pill), 'pill label must not carry the cover reason: ' + pil const a = stageTrackerMergeGateInfo(issue15088, now), b = stageTrackerMergeGateInfo(pr15090, now); assert.deepStrictEqual([a.word, a.detail, a.cue, a.state], [b.word, b.detail, b.cue, b.state]); // The cover reason leads the tooltip — "· at ", not "(PR at )". -assert.ok(a.tip.startsWith('Open PR #15090 covers it · its PR is review passed · waiting for merge admission — Review passed, not yet admitted to auto merge — CI still running (build-and-test).'), a.tip); +assert.ok(a.tip.startsWith('Open PR #15090 covers it · its PR is review passed · waiting for merge admission — Review passed, not yet admitted to auto merge — CI running (build-and-test).'), a.tip); assert.ok(!/\(PR at/.test(a.tip), a.tip); const glyph = stageTrackerGateCueHtml(issue15088, now); assert.ok(glyph.includes('title="' + esc(a.tip) + '"') && glyph.includes('aria-label="' + esc(a.tip) + '"'), glyph); diff --git a/src/pkg/dashboard/stage_tracker_merge_refusal.go b/src/pkg/dashboard/stage_tracker_merge_refusal.go new file mode 100644 index 0000000000..dfe20aeb8a --- /dev/null +++ b/src/pkg/dashboard/stage_tracker_merge_refusal.go @@ -0,0 +1,85 @@ +package dashboard + +import ( + "regexp" + "strconv" + "strings" +) + +// Merge-refusal kinds (StageTrackerMergeGate.MergeFailedKind): what GitHub's +// refusal of the hive's merge call means, in a token the SPA maps to a +// short chip detail. The raw error text never reaches the chip +// (hivecommons/docs#512 drew "PUT https://api.github.com/repos/…" across +// the Merge gate column); it rides the tooltip's Details line only. +const ( + // MergeRefusalChecksPending: 405 "N of M required status checks are + // expected" — the head's required checks have not reported; the merge + // call was early, not refused for cause. + MergeRefusalChecksPending = "checks-pending" + // MergeRefusalProtection: 405 "not mergeable" / blocked by branch + // protection or a ruleset. + MergeRefusalProtection = "protection" + // MergeRefusalReview: 405 an approving review is required. + MergeRefusalReview = "review" + // MergeRefusalMethod: 405 the merge method is switched off. + MergeRefusalMethod = "method" + // MergeRefusalMergeQueue: 405 the base only merges through the queue. + MergeRefusalMergeQueue = "merge-queue" + // MergeRefusalHeadMoved: 409 the head (or base) moved under the call. + MergeRefusalHeadMoved = "head-moved" + // MergeRefusalForbidden: 403 the App may not merge here. + MergeRefusalForbidden = "forbidden" + // MergeRefusalOther: anything else. + MergeRefusalOther = "refused" +) + +var ( + // "PUT https://api.github.com/repos/o/r/pulls/1/merge: 405 …" (go-github's + // ErrorResponse) or a bare "405 …". + mergeRefusalStatusRE = regexp.MustCompile(`(?:^|[\s:])(\d{3})\s`) + mergeRefusalChecksRE = regexp.MustCompile(`(?i)(\d+)\s+of\s+(\d+)\s+required status checks? (?:are|is) expected|required status check ["']([^"']+)["'] is expected`) + mergeRefusalReviewRE = regexp.MustCompile(`(?i)\d+ approving reviews? (?:is|are) required|\d+ reviews? requesting changes|review is required`) + mergeRefusalMethodRE = regexp.MustCompile(`(?i)(?:merge commits|squash merges|rebase merges) are not allowed`) + mergeRefusalQueueRE = regexp.MustCompile(`(?i)through the merge queue`) + mergeRefusalMovedRE = regexp.MustCompile(`(?i)head branch was modified|base branch was modified|sha .* does not match|was modified\. review and try`) +) + +// stageTrackerMergeRefusal translates GitHub's refusal of a merge call into +// a kind, a plain sentence for the tooltip, and — for checks-pending — how +// many required checks are still expected. +func stageTrackerMergeRefusal(raw string) (kind, text string, checks int) { + raw = strings.TrimSpace(raw) + if raw == "" { + return "", "", 0 + } + status := 0 + if m := mergeRefusalStatusRE.FindStringSubmatch(raw); m != nil { + status, _ = strconv.Atoi(m[1]) + } + lower := strings.ToLower(raw) + switch { + case mergeRefusalChecksRE.MatchString(raw): + m := mergeRefusalChecksRE.FindStringSubmatch(raw) + if m[1] != "" { + checks, _ = strconv.Atoi(m[1]) + if checks == 1 { + return MergeRefusalChecksPending, "1 required check hasn't finished", 1 + } + return MergeRefusalChecksPending, m[1] + " required checks haven't finished", checks + } + return MergeRefusalChecksPending, "required check " + m[3] + " hasn't finished", 1 + case mergeRefusalQueueRE.MatchString(raw): + return MergeRefusalMergeQueue, "this branch only merges through GitHub's merge queue", 0 + case mergeRefusalReviewRE.MatchString(raw): + return MergeRefusalReview, "branch protection wants an approving review hive can't give", 0 + case mergeRefusalMethodRE.MatchString(raw): + return MergeRefusalMethod, "the repository has this merge method switched off", 0 + case status == 409 || mergeRefusalMovedRE.MatchString(raw): + return MergeRefusalHeadMoved, "the branch moved under the merge call; it needs a rebase", 0 + case status == 403 || strings.Contains(lower, "resource not accessible") || strings.Contains(lower, "forbidden"): + return MergeRefusalForbidden, "hive isn't allowed to merge here", 0 + case status == 405 || strings.Contains(lower, "not mergeable") || strings.Contains(lower, "blocked") || strings.Contains(lower, "protected branch") || strings.Contains(lower, "rule violations"): + return MergeRefusalProtection, "branch protection blocks it", 0 + } + return MergeRefusalOther, "GitHub refused the merge", 0 +} diff --git a/src/pkg/dashboard/stage_tracker_merge_refusal_test.go b/src/pkg/dashboard/stage_tracker_merge_refusal_test.go new file mode 100644 index 0000000000..bd57898c98 --- /dev/null +++ b/src/pkg/dashboard/stage_tracker_merge_refusal_test.go @@ -0,0 +1,33 @@ +package dashboard + +import "testing" + +// TestStageTrackerMergeRefusal: GitHub's merge refusals become plain words +// and a kind token; the raw text (hivecommons/docs#512's "PUT https://… +// 405 4 of 4 required status checks are expected. []") never is the chip. +func TestStageTrackerMergeRefusal(t *testing.T) { + for raw, want := range map[string]struct { + kind, text string + checks int + }{ + "PUT https://api.github.com/repos/hivecommons/docs/pulls/512/merge: 405 4 of 4 required status checks are expected. []": {MergeRefusalChecksPending, "4 required checks haven't finished", 4}, + "405 1 of 3 required status checks are expected.": {MergeRefusalChecksPending, "1 required check hasn't finished", 1}, + `405 Required status check "lint" is expected.`: {MergeRefusalChecksPending, "required check lint hasn't finished", 1}, + "PUT https://api.github.com/repos/o/r/pulls/1/merge: 405 Pull Request is not mergeable []": {MergeRefusalProtection, "branch protection blocks it", 0}, + "405 Base branch is protected; 2 rule violations found": {MergeRefusalProtection, "branch protection blocks it", 0}, + "405 At least 1 approving review is required by reviewers with write access.": {MergeRefusalReview, "branch protection wants an approving review hive can't give", 0}, + "405 Squash merges are not allowed on this repository.": {MergeRefusalMethod, "the repository has this merge method switched off", 0}, + "405 Changes must be made through the merge queue": {MergeRefusalMergeQueue, "this branch only merges through GitHub's merge queue", 0}, + "PUT https://api.github.com/repos/o/r/pulls/1/merge: 409 Head branch was modified. Review and try the merge again. []": {MergeRefusalHeadMoved, "the branch moved under the merge call; it needs a rebase", 0}, + "PUT https://api.github.com/repos/o/r/pulls/1/merge: 403 Resource not accessible by integration []": {MergeRefusalForbidden, "hive isn't allowed to merge here", 0}, + "context deadline exceeded": {MergeRefusalOther, "GitHub refused the merge", 0}, + } { + kind, text, checks := stageTrackerMergeRefusal(raw) + if kind != want.kind || text != want.text || checks != want.checks { + t.Errorf("%q → (%q, %q, %d), want (%q, %q, %d)", raw, kind, text, checks, want.kind, want.text, want.checks) + } + } + if kind, text, checks := stageTrackerMergeRefusal(" "); kind != "" || text != "" || checks != 0 { + t.Errorf("blank → (%q, %q, %d)", kind, text, checks) + } +} diff --git a/src/pkg/dashboard/stage_tracker_merging_hold_test.go b/src/pkg/dashboard/stage_tracker_merging_hold_test.go index 705db1f1b5..1f6dd5cd69 100644 --- a/src/pkg/dashboard/stage_tracker_merging_hold_test.go +++ b/src/pkg/dashboard/stage_tracker_merging_hold_test.go @@ -295,9 +295,9 @@ assert.strictEqual(info.detail, '', 'legacy 100 record: word alone'); info = stageTrackerMergeGateInfoFor(Object.assign(item({ state: 'merge-failed', merge_failed: 'merging PR o/r#1 (abc): 405 Pull Request is not mergeable\nmore', merge_failed_at: new Date(now - 9000).toISOString(), merge_path: 'relay' }), { stage: 90 }), now); assert.strictEqual(info.state, 'merge-failed'); assert.strictEqual(info.word, 'Merge failed'); -assert.strictEqual(info.detail, '405 Pull Request is not mergeable', 'first line, prefix stripped'); +assert.strictEqual(info.detail, 'branch protection', 'kind words, never the raw error'); assert.strictEqual(info.cue, 'waiting'); -assert.ok(info.tip.includes('hive-merge relay') && info.tip.includes('GitHub refused'), info.tip); +assert.ok(info.tip.includes('hive-merge relay') && info.tip.includes('GitHub refused — branch protection blocks it') && info.tip.includes('Details: merging PR o/r#1 (abc): 405 Pull Request is not mergeable'), info.tip); assert.strictEqual(stageTrackerMergeFailedShort(''), 'GitHub refused the merge'); assert.ok(stageTrackerMergeFailedShort('x'.repeat(80)).endsWith('…')); assert.strictEqual(stageTrackerMergeFailedShort('x'.repeat(80)).length, STAGE_TRACKER_MERGE_FAILED_SHORT_MAX); diff --git a/src/pkg/dashboard/stage_tracker_test.go b/src/pkg/dashboard/stage_tracker_test.go index ac0ecd8692..46a49e6130 100644 --- a/src/pkg/dashboard/stage_tracker_test.go +++ b/src/pkg/dashboard/stage_tracker_test.go @@ -115,32 +115,44 @@ func TestStageTrackerNeedsAuthorAndReturnedWords(t *testing.T) { } } caption, actor := stageTrackerCaption(stagelabels.NeedsAuthor, "check-failing:unit", "sam", "pr", false, stagelabels.Record{}, false, 0, "") - if caption != "Needs @sam — CI is red (check-failing:unit) — @sam must act" || actor != "sam" { + if caption != "Needs @sam — CI failed: unit — @sam must act" || actor != "sam" { t.Errorf("071 caption = %q actor = %q", caption, actor) } } func TestHumanizeStageReason(t *testing.T) { cases := map[string]string{ - "actionable": "", - "live agent claim": "", - "mirrors PR #12332": "mirrors PR #12332", - "label:needs-rebase": "needs a rebase", - "held": "held by a hold label", - "contributor-lane:no-verdict": "no review verdict yet", - "required-check-pending:build-and-test": "check build-and-test still running", - "required-check-failing:DCO": "check DCO failing", - "reviewer-verdict:changes_requested": "review swarm requested changes", - "pending: head pushed 59s ago (< min_head_age)": "head pushed 59s ago; waiting for the minimum head age", - "contributor-lane:soaking:12m": "soaking", - "excluded-label:do-not-merge": "label do-not-merge excludes it", - "some-new-token": "some new token", - "base-branch-red:docker (hive),docker (hub)": "waiting for the base branch's CI to recover (docker (hive), docker (hub)) — not this PR's fault", - "shared-ci-incident:13208": "deferred to shared-CI incident #13208 — not this PR's fault", - "fork-guard:Canary": "check Canary refuses fork PRs — a maintainer must push this branch to the repository", - "contributor-lane:workflow-path": "workflow path", - "contributor-lane:tests-removed": "tests removed", - "human-merge-path": "human-merge path", + "actionable": "", + "live agent claim": "", + "mirrors PR #12332": "mirrors PR #12332", + "label:needs-rebase": "needs a rebase", + "held": "held by a hold label", + "contributor-lane:no-verdict": "no review verdict yet", + "required-check-pending:build-and-test": "check build-and-test still running", + // Pending is not red (hivecommons/docs#512 read "CI is red (check-pending)"). + "check-pending": "CI running", + "status-pending": "CI running", + "check-success": "CI green", + "status-success": "CI green", + "check-failure": "CI failed", + "status-error": "CI failed", + "check-timed_out": "CI failed (timed out)", + "check-failing:lint": "CI failed: lint", + "status-failing:tests": "CI failed: tests", + "ci-red": "CI failed", + "check-runs": "CI checks could not be read", + "required-check-failing:DCO": "check DCO failing", + "reviewer-verdict:changes_requested": "review swarm requested changes", + "pending: head pushed 59s ago (< min_head_age)": "head pushed 59s ago; waiting for the minimum head age", + "contributor-lane:soaking:12m": "soaking", + "excluded-label:do-not-merge": "label do-not-merge excludes it", + "some-new-token": "some new token", + "base-branch-red:docker (hive),docker (hub)": "waiting for the base branch's CI to recover (docker (hive), docker (hub)) — not this PR's fault", + "shared-ci-incident:13208": "deferred to shared-CI incident #13208 — not this PR's fault", + "fork-guard:Canary": "check Canary refuses fork PRs — a maintainer must push this branch to the repository", + "contributor-lane:workflow-path": "workflow path", + "contributor-lane:tests-removed": "tests removed", + "human-merge-path": "human-merge path", "contributor-lane:workflow-path:human-approved@clubanderson": "workflow path — approved by @clubanderson", "reviewer-verdict:requires_human:human-approved@octocat": "review verdict requires human — approved by @octocat", } @@ -731,7 +743,7 @@ func TestStageTrackerAdoptedCaptionNamesTheWork(t *testing.T) { cases := map[string]string{ "conflicting": "Hive adopted this PR; hive is rebasing it onto the base branch — conflicting", "label:needs-rebase": "Hive adopted this PR; hive is rebasing it onto the base branch — needs a rebase", - "check-failing:coverage": "Hive adopted this PR; hive is fixing CI — CI is red (check-failing:coverage)", + "check-failing:coverage": "Hive adopted this PR; hive is fixing CI — CI failed: coverage", "required-check-failing:test": "Hive adopted this PR; hive is fixing CI — check test failing", "reviewer-verdict:changes_requested": "Hive adopted this PR; hive is addressing the review findings — review swarm requested changes", "": "Hive adopted this PR", diff --git a/src/pkg/dashboard/static-src/css/tracker.css b/src/pkg/dashboard/static-src/css/tracker.css index 5502a79944..0562cd4ed7 100644 --- a/src/pkg/dashboard/static-src/css/tracker.css +++ b/src/pkg/dashboard/static-src/css/tracker.css @@ -311,7 +311,10 @@ after the word ("next sweep in 42s", "7m left") is muted. */ .ham-gate-ico { display: inline-flex; align-items: center; margin-right: var(--sp-1); cursor: help; } .ham-gate-ico .ham-ico { width: 12px; height: 12px; } - .ham-gate-detail { font-weight: normal; opacity: 0.85; white-space: nowrap; font-variant-numeric: tabular-nums; } + /* The detail is a fixed short phrase; should a long one ever reach it + (hivecommons/docs#512 drew a raw GitHub URL across the column) it is + clipped with an ellipsis rather than overflowing the chip. */ + .ham-gate-detail { font-weight: normal; opacity: 0.85; white-space: nowrap; font-variant-numeric: tabular-nums; display: inline-block; vertical-align: bottom; max-width: 12em; overflow: hidden; text-overflow: ellipsis; } @keyframes ham-pulse { 0%, 100% { opacity: 0; } 50% { opacity: 0.3; } } /* ---- tracker-cues: the Activity Monitor's shared cue vocabulary ------ Owner request: a viewer must always read where an item stands, diff --git a/src/pkg/dashboard/static-src/js/tracker-motion.js b/src/pkg/dashboard/static-src/js/tracker-motion.js index eb64574edf..ea5bffb440 100644 --- a/src/pkg/dashboard/static-src/js/tracker-motion.js +++ b/src/pkg/dashboard/static-src/js/tracker-motion.js @@ -96,7 +96,9 @@ if (next.stage !== prev.stage) { if (next.stage >= STAGE_TRACKER_TERMINAL) return 'merged'; const sg = (stages || []).find(x => Number(x.number) === next.stage); - const name = next.label || (sg && (sg.label || sg.short)) || ('stage ' + next.stage); + // Plain words, never a stage slug ("fell back to stage/060-reviewed"). + const named = typeof stageTrackerStageName === 'function' ? stageTrackerStageName({ label: next.label, short: '' }) || stageTrackerStageName(sg) : ''; + const name = named || next.label || (sg && (sg.label || sg.short)) || ('stage ' + next.stage); const back = stageTrackerStageFell(prev, next, stages); const why = (back || next.stage < prev.stage) && next.caption ? ' — ' + next.caption : ''; return (back ? 'fell back to ' : 'moved to ') + name + why; @@ -222,7 +224,7 @@ // Pure: the strip column (0-based; STAGE_TRACKER_PATH.length = merged cap) // an item's stage lights, or -1 for an unknown stage. function stageTrackerColIndex(item, stages) { - const anchor = stageTrackerAnchor(item.stage, stages, item.via_pr ? 'pr' : item.kind); + const anchor = stageTrackerAnchor(item.stage, stages, item.via_pr ? 'pr' : item.kind, item); if (anchor >= STAGE_TRACKER_TERMINAL) return STAGE_TRACKER_CAP_COLUMN; return STAGE_TRACKER_PATH.indexOf(anchor); } diff --git a/src/pkg/dashboard/static-src/js/tracker-row.js b/src/pkg/dashboard/static-src/js/tracker-row.js index 13332357a7..dfa4b420e5 100644 --- a/src/pkg/dashboard/static-src/js/tracker-row.js +++ b/src/pkg/dashboard/static-src/js/tracker-row.js @@ -4,10 +4,16 @@ // light the segment they branch from (stageTrackerColumn in Go). // kind is 'issue' or 'pr': an issue parked on a person (045, or a // pre-045 085) is parked before any PR exists, so it lights Actionable - // rather than the merge gate. - function stageTrackerAnchor(stage, stages, kind) { + // rather than the merge gate. item (optional) is the row: once a merge + // call has been made on its head (merge_gate.state merging / + // merge-failed) the outcome is a Merge gate matter whatever numeric + // stage the lane fell back to — hivecommons/docs#512 drew "Merge + // failed" in CI / Review because the PR sat at 060. + function stageTrackerAnchor(stage, stages, kind, item) { const cur = Number(stage) || 0; if (cur >= STAGE_TRACKER_TERMINAL) return STAGE_TRACKER_TERMINAL; + const mg = item && item.merge_gate; + if (mg && (mg.state === 'merging' || mg.state === 'merge-failed') && cur > STAGE_TRACKER_PR_COLUMN) return STAGE_TRACKER_MERGE_COLUMN; if (cur === STAGE_TRACKER_ISSUE_NEEDS_DECISION || cur === STAGE_TRACKER_TRIAGE_NEEDED || cur === STAGE_TRACKER_POSSIBLY_EXISTS) return STAGE_TRACKER_ISSUE_DECISION_COLUMN; if (cur === STAGE_TRACKER_NEEDS_DECISION && kind === 'issue') return STAGE_TRACKER_ISSUE_DECISION_COLUMN; if (STAGE_TRACKER_PATH.indexOf(cur) >= 0) return cur; @@ -29,7 +35,7 @@ (stages || []).forEach(st => { byNum[st.number] = st; }); const cur = Number(item.stage) || 0; const curStage = byNum[cur] || {}; - const anchor = stageTrackerAnchor(cur, stages, item.via_pr ? 'pr' : item.kind); + const anchor = stageTrackerAnchor(cur, stages, item.via_pr ? 'pr' : item.kind, item); const terminal = anchor >= STAGE_TRACKER_TERMINAL; const sentinelLane = stageTrackerSentinelInLane(item); const detour = (!terminal && STAGE_TRACKER_PATH.indexOf(cur) < 0 && cur !== STAGE_TRACKER_TRIAGE_NEEDED && cur !== STAGE_TRACKER_POSSIBLY_EXISTS && cur !== 40 && cur !== 60 && cur !== STAGE_TRACKER_PRE_MERGE_SOAK && cur !== 100) @@ -75,7 +81,7 @@ const os = stageTrackerOpenSince(item); if (os.ms) { word += ' · since ' + stageTrackerShortAgo(nowMs - os.ms); openSince = Object.assign({ stale: !openDraft && nowMs - os.ms > STAGE_TRACKER_OPEN_STALE_DAYS * 86400000 }, os); } } - return { number: n, code: n ? String(n).padStart(3, '0') : '', short: word, label: tipStage.label || st.label || String(n), description: tipStage.description || st.description || '', state, terminal: false, detour: n === anchor ? detour : null, hold: openHold, blocked: openBlocked, draft: openDraft, isNew: openNew, openSince }; + return { number: n, code: n ? String(n).padStart(3, '0') : '', short: word, label: (typeof stageTrackerStageName === 'function' && (stageTrackerStageName(tipStage) || stageTrackerStageName(st))) || tipStage.label || st.label || String(n), description: tipStage.description || st.description || '', state, terminal: false, detour: n === anchor ? detour : null, hold: openHold, blocked: openBlocked, draft: openDraft, isNew: openNew, openSince }; }); segs.push({ number: STAGE_TRACKER_TERMINAL, code: '', short: 'Merged', label: 'Merged', description: 'Merged — the pipeline is complete', state: terminal ? 'active' : 'todo', terminal, cap: true, detour: null }); return segs; @@ -897,7 +903,7 @@ function stageTrackerLinkedSorted(item, stages) { const linked = Array.isArray(item.linked_prs) ? item.linked_prs.filter(lp => stageTrackerLinkedDrawnHere(lp, item)) : (item.linked_pr ? [{ number: item.linked_pr }] : []); const sinceOf = lp => Date.parse(lp.stage_since || '') || Infinity; - return linked.sort((x, y) => (stageTrackerAnchor(y.stage, stages, 'pr') - stageTrackerAnchor(x.stage, stages, 'pr')) || (stageTrackerAttentionTier(x) - stageTrackerAttentionTier(y)) || (sinceOf(x) - sinceOf(y)) || ((x.number || 0) - (y.number || 0))); + return linked.sort((x, y) => (stageTrackerAnchor(y.stage, stages, 'pr', y) - stageTrackerAnchor(x.stage, stages, 'pr', x)) || (stageTrackerAttentionTier(x) - stageTrackerAttentionTier(y)) || (sinceOf(x) - sinceOf(y)) || ((x.number || 0) - (y.number || 0))); } // Pure: a PR whose drawn_under issue is not a row of this page (filtered @@ -930,7 +936,7 @@ const linked = item.kind === 'issue' ? stageTrackerLinkedSorted(item, stages) : []; const lead = linked.length && linked[0].stage ? linked[0] : item; const kind = lead === item ? item.kind : 'pr'; - return { anchor: stageTrackerAnchor(lead.stage, stages, kind), since: Date.parse(lead.stage_since || '') || Infinity }; + return { anchor: stageTrackerAnchor(lead.stage, stages, kind, lead), since: Date.parse(lead.stage_since || '') || Infinity }; } /* ---- Repo chip and group-by-repo (pure; run under node by diff --git a/src/pkg/dashboard/static-src/js/tracker-words.js b/src/pkg/dashboard/static-src/js/tracker-words.js index d2c63f565c..d328b0f0ab 100644 --- a/src/pkg/dashboard/static-src/js/tracker-words.js +++ b/src/pkg/dashboard/static-src/js/tracker-words.js @@ -418,10 +418,11 @@ if (m < 60) return m + 'm'; return Math.floor(m / 60) + 'h' + (m % 60 ? String(m % 60).padStart(2, '0') + 'm' : ''); } - // Pure: the gate's reason token in plain words — "CI still running - // (build-and-test)", "CI is red (lint)"; '' for none. + // Pure: the gate's reason token in plain words — "CI running + // (build-and-test)", "CI failed: lint"; '' for none. Pending is never + // "red" (hivecommons/docs#512 read "CI is red (check-pending)"). const STAGE_TRACKER_GATE_REASON_WORDS = { - 'check-pending': 'CI still running', 'required-check-pending': 'CI still running', 'check-failing': 'CI is red', 'required-check-failing': 'CI is red', + 'check-pending': 'CI running', 'required-check-pending': 'CI running', 'check-failing': 'CI failed', 'required-check-failing': 'CI failed', 'optional-check-failing': 'an optional check is red', conflicting: 'branch has conflicts', 'needs-rebase': 'needs a rebase', 'dco-missing': 'DCO sign-off missing', }; // Pure: the 060 "Review passed" pill's detail from the lane's recorded @@ -446,7 +447,8 @@ const detail = i >= 0 ? raw.slice(i + 1).replace(/\(.*$/, '') : ''; const words = STAGE_TRACKER_GATE_REASON_WORDS[slug]; if (!words) return raw; - return words + (detail ? ' (' + detail + ')' : ''); + if (!detail) return words; + return /failed$/.test(words) ? words + ': ' + detail : words + ' (' + detail + ')'; } // Pure: "open PR #15090 covers it · at 060-reviewed" from an issue row's // lane reason ("open PR #15090 covers it (PR at 060-reviewed)"); '' for @@ -457,6 +459,20 @@ // (stage_tracker_vocabulary.go): every string the page renders names a // stage by its chevron's words, never by a code ("060 reviewed"). const STAGE_TRACKER_STAGE_PHRASE = { 10: 'actionable', 15: 'waiting for triage', 17: 'waiting for the author to confirm the gap (prior art found)', 20: 'claimed', 30: 'a PR in progress', 40: 'covered by a PR', 45: 'waiting for a human decision', 50: 'in CI / review', 60: 'review passed · waiting for merge admission', 70: 'being fixed by hive', 71: 'waiting for its author', 72: 'returned to the contributor', 74: 'adopted by hive', 80: 'at the merge gate', 85: 'waiting for a human decision', 90: 'ready for human merge', 95: 'soaking before merge', 100: 'in the merge queue' }; + // Pure: a stage's name in plain words for cues and tooltips — its short + // word when the stages table has one, else its label with the lane's + // "stage/060-" slug prefix dropped and the slug humanised ("Reviewed"). + // Minimal local fix for "fell back to stage/060-reviewed" + // (hivecommons/docs#512); the copy sweep retires stage slugs globally. + function stageTrackerStageName(st) { + if (!st) return ''; + if (st.short) return String(st.short); + const label = String(st.label || '').trim(); + const m = /^(?:stage\/)?\d{3}-(.+)$/.exec(label); + if (!m) return label; + const words = m[1].replace(/[-_]+/g, ' '); + return words.charAt(0).toUpperCase() + words.slice(1); + } // Pure: a stage code as the lane spells it ("060-reviewed", "stage/060-reviewed") → its phrase; the input when unknown. function stageTrackerStagePhrase(code) { const m = /^(?:stage\/)?(\d{3})(?:[- ][a-z-]+)?$/i.exec(String(code || '').trim()); @@ -599,6 +615,7 @@ // stagelabels RouteHuman), in the CI / Review column; the spinning cue // says the sweep is on it now. const preWhy = state === 'gate-pending' ? (stageTrackerReviewPassedDetail(mg.reason || laneReason) || 'waiting for merge admission') : ''; + if (state === 'merge-failed') return stageTrackerMergeFailedInfo(mg, nowMs, nextAt, lastSeen); if (mg.sweep_running) { return { state, word, detail: preWhy || 'merge sweep running', tip: (preWhy ? 'Review passed, not yet admitted to auto merge — ' + preWhy + '; ' : '') + "hive's merge sweep is running on this PR now.", cue: 'running', until: 0 }; } @@ -622,17 +639,56 @@ if (since > 0) return { state, word, detail: 'merge call in flight', tip: 'hive is merging it now' + (who ? ' (' + who + ')' : '') + ' — the merge call has been in flight' + sinceWords + '.', cue: 'merging', until: 0 }; return { state, word, detail: '', tip: 'Admitted and soaked; hive is merging it now (GitHub merge queue / merge window).' + lastSeen, cue: 'merging', until: 0 }; } - if (state === 'merge-failed') { - const why = String(mg.merge_failed || '').trim(); - const at = mg.merge_failed_at ? Date.parse(mg.merge_failed_at) : 0; - const who = STAGE_TRACKER_MERGE_PATH_WORDS[mg.merge_path] || ''; - return { state, word, detail: stageTrackerMergeFailedShort(why), tip: 'hive tried to merge this' + (who ? ' (' + who + ')' : '') + (at > 0 ? ' ' + stageTrackerAgoText(at, nowMs) : '') + ' and GitHub refused' + (why ? ': ' + why : '') + '. The lane re-evaluates it on its next pass' + (nextWords ? ' (' + nextWords + ')' : '') + '.' + lastSeen, cue: 'waiting', until: 0 }; - } const why = stageTrackerGateReasonText(mg.reason || laneReason); return { state, word, detail: preWhy, tip: 'Review passed, not yet admitted to auto merge' + (why ? ' — ' + why : '') + '.' + (nextWords ? ' hive re-checks the gate on its ' + nextWords.replace(/^next /, 'next ') + '.' : '') + sooner + lastSeen, cue: 'waiting', until: 0 }; } + // Refusal kind (merge_gate.merge_failed_kind, stageTrackerMergeRefusal in + // Go) → the chip's short detail. The chip never carries the raw error + // (hivecommons/docs#512 drew "PUT https://api.github.com/…" across the + // column); the plain sentence and the raw text ride the tooltip. + const STAGE_TRACKER_MERGE_REFUSAL_DETAIL = { protection: 'branch protection', review: 'review required', method: 'merge method off', 'merge-queue': 'merge queue only', 'head-moved': 'needs rebase', forbidden: 'not allowed', refused: 'GitHub refused' }; + // Pure: an older payload's raw refusal → its kind and sentence (the Go + // helper's mapping, abridged); 'refused' when nothing matches. + function stageTrackerMergeRefusalFromRaw(why) { + const m = /(\d+) of (\d+) required status checks? (?:are|is) expected/i.exec(why); + if (m) return { kind: 'checks-pending', text: m[1] + ' required check' + (m[1] === '1' ? " hasn't" : "s haven't") + ' finished', checks: Number(m[1]) }; + if (/required status check ["']([^"']+)["'] is expected/i.test(why)) return { kind: 'checks-pending', text: 'a required check hasn\'t finished', checks: 1 }; + if (/\b409\b|branch was modified/i.test(why)) return { kind: 'head-moved', text: 'the branch moved under the merge call; it needs a rebase', checks: 0 }; + if (/\b403\b|resource not accessible|forbidden/i.test(why)) return { kind: 'forbidden', text: "hive isn't allowed to merge here", checks: 0 }; + if (/\b405\b|not mergeable|blocked|protected branch/i.test(why)) return { kind: 'protection', text: 'branch protection blocks it', checks: 0 }; + return { kind: 'refused', text: 'GitHub refused the merge', checks: 0 }; + } + // Pure: the merge-failed pill. A refusal because required checks have + // not reported is not a failure — the sweep called too early — so the + // chip reads "Waiting for CI · 4 checks"; a sweep retrying now reads + // "Merge failed · retrying"; otherwise "Merge failed · ". + // The chip is a fixed short phrase (≤ 5 words); the tooltip carries the + // plain sentence and GitHub's raw text after "Details:". + function stageTrackerMergeFailedInfo(mg, nowMs, nextAt, lastSeen) { + const state = 'merge-failed'; + const why = String(mg.merge_failed || '').trim(); + const fallback = why && !mg.merge_failed_kind ? stageTrackerMergeRefusalFromRaw(why) : null; + const kind = mg.merge_failed_kind || (fallback && fallback.kind) || ''; + const text = mg.merge_failed_text || (fallback && fallback.text) || ''; + const checks = Number(mg.merge_failed_checks) || (fallback && fallback.checks) || 0; + const at = mg.merge_failed_at ? Date.parse(mg.merge_failed_at) : 0; + const who = STAGE_TRACKER_MERGE_PATH_WORDS[mg.merge_path] || ''; + const when = (who ? ' (' + who + ')' : '') + (at > 0 ? ' ' + stageTrackerAgoText(at, nowMs) : ''); + const nextWords = nextAt > nowMs ? 'next sweep in ' + stageTrackerShortLeft(nextAt - nowMs) : (nextAt > 0 ? 'sweep due now' : ''); + const details = why ? ' Details: ' + why : ''; + if (kind === 'checks-pending') { + const tip = 'hive tried to merge this' + when + ' before its required checks had reported — ' + (text || "required checks haven't finished") + '. It merges once they pass' + (mg.sweep_running ? "; hive's merge sweep is on it now" : (nextWords ? ' (' + nextWords + ')' : '')) + '.' + lastSeen + details; + return { state, word: 'Waiting for CI', detail: checks > 0 ? checks + ' check' + (checks === 1 ? '' : 's') : '', tip, cue: mg.sweep_running ? 'running' : 'waiting', until: 0 }; + } + const word = STAGE_TRACKER_MERGE_GATE_WORD[state]; + const sentence = 'hive tried to merge this' + when + ' and GitHub refused' + (text ? ' — ' + text : '') + '.'; + if (mg.sweep_running) { + return { state, word, detail: 'retrying', tip: sentence + " hive's merge sweep is retrying it now." + lastSeen + details, cue: 'running', until: 0 }; + } + return { state, word, detail: STAGE_TRACKER_MERGE_REFUSAL_DETAIL[kind] || 'GitHub refused', tip: sentence + ' The lane re-evaluates it on its next pass' + (nextWords ? ' (' + nextWords + ')' : '') + '.' + lastSeen + details, cue: 'waiting', until: 0 }; + } // Pure: a refusal's first line, cut to STAGE_TRACKER_MERGE_FAILED_SHORT_MAX - // for the pill detail; the full text rides the glyph tooltip. + // (tooltips and toasts; the pill detail comes from the refusal kind). function stageTrackerMergeFailedShort(why) { const line = String(why || '').split('\n')[0].replace(/^merging PR \S+ \([^)]*\): /, '').trim(); if (!line) return 'GitHub refused the merge'; diff --git a/src/pkg/dashboard/static/index.html b/src/pkg/dashboard/static/index.html index 9037adea45..624e73169d 100644 --- a/src/pkg/dashboard/static/index.html +++ b/src/pkg/dashboard/static/index.html @@ -1634,7 +1634,10 @@ after the word ("next sweep in 42s", "7m left") is muted. */ .ham-gate-ico { display: inline-flex; align-items: center; margin-right: var(--sp-1); cursor: help; } .ham-gate-ico .ham-ico { width: 12px; height: 12px; } - .ham-gate-detail { font-weight: normal; opacity: 0.85; white-space: nowrap; font-variant-numeric: tabular-nums; } + /* The detail is a fixed short phrase; should a long one ever reach it + (hivecommons/docs#512 drew a raw GitHub URL across the column) it is + clipped with an ellipsis rather than overflowing the chip. */ + .ham-gate-detail { font-weight: normal; opacity: 0.85; white-space: nowrap; font-variant-numeric: tabular-nums; display: inline-block; vertical-align: bottom; max-width: 12em; overflow: hidden; text-overflow: ellipsis; } @keyframes ham-pulse { 0%, 100% { opacity: 0; } 50% { opacity: 0.3; } } /* ---- tracker-cues: the Activity Monitor's shared cue vocabulary ------ Owner request: a viewer must always read where an item stands, @@ -14511,10 +14514,11 @@

Where to get help

if (m < 60) return m + 'm'; return Math.floor(m / 60) + 'h' + (m % 60 ? String(m % 60).padStart(2, '0') + 'm' : ''); } - // Pure: the gate's reason token in plain words — "CI still running - // (build-and-test)", "CI is red (lint)"; '' for none. + // Pure: the gate's reason token in plain words — "CI running + // (build-and-test)", "CI failed: lint"; '' for none. Pending is never + // "red" (hivecommons/docs#512 read "CI is red (check-pending)"). const STAGE_TRACKER_GATE_REASON_WORDS = { - 'check-pending': 'CI still running', 'required-check-pending': 'CI still running', 'check-failing': 'CI is red', 'required-check-failing': 'CI is red', + 'check-pending': 'CI running', 'required-check-pending': 'CI running', 'check-failing': 'CI failed', 'required-check-failing': 'CI failed', 'optional-check-failing': 'an optional check is red', conflicting: 'branch has conflicts', 'needs-rebase': 'needs a rebase', 'dco-missing': 'DCO sign-off missing', }; // Pure: the 060 "Review passed" pill's detail from the lane's recorded @@ -14539,7 +14543,8 @@

Where to get help

const detail = i >= 0 ? raw.slice(i + 1).replace(/\(.*$/, '') : ''; const words = STAGE_TRACKER_GATE_REASON_WORDS[slug]; if (!words) return raw; - return words + (detail ? ' (' + detail + ')' : ''); + if (!detail) return words; + return /failed$/.test(words) ? words + ': ' + detail : words + ' (' + detail + ')'; } // Pure: "open PR #15090 covers it · at 060-reviewed" from an issue row's // lane reason ("open PR #15090 covers it (PR at 060-reviewed)"); '' for @@ -14550,6 +14555,20 @@

Where to get help

// (stage_tracker_vocabulary.go): every string the page renders names a // stage by its chevron's words, never by a code ("060 reviewed"). const STAGE_TRACKER_STAGE_PHRASE = { 10: 'actionable', 15: 'waiting for triage', 17: 'waiting for the author to confirm the gap (prior art found)', 20: 'claimed', 30: 'a PR in progress', 40: 'covered by a PR', 45: 'waiting for a human decision', 50: 'in CI / review', 60: 'review passed · waiting for merge admission', 70: 'being fixed by hive', 71: 'waiting for its author', 72: 'returned to the contributor', 74: 'adopted by hive', 80: 'at the merge gate', 85: 'waiting for a human decision', 90: 'ready for human merge', 95: 'soaking before merge', 100: 'in the merge queue' }; + // Pure: a stage's name in plain words for cues and tooltips — its short + // word when the stages table has one, else its label with the lane's + // "stage/060-" slug prefix dropped and the slug humanised ("Reviewed"). + // Minimal local fix for "fell back to stage/060-reviewed" + // (hivecommons/docs#512); the copy sweep retires stage slugs globally. + function stageTrackerStageName(st) { + if (!st) return ''; + if (st.short) return String(st.short); + const label = String(st.label || '').trim(); + const m = /^(?:stage\/)?\d{3}-(.+)$/.exec(label); + if (!m) return label; + const words = m[1].replace(/[-_]+/g, ' '); + return words.charAt(0).toUpperCase() + words.slice(1); + } // Pure: a stage code as the lane spells it ("060-reviewed", "stage/060-reviewed") → its phrase; the input when unknown. function stageTrackerStagePhrase(code) { const m = /^(?:stage\/)?(\d{3})(?:[- ][a-z-]+)?$/i.exec(String(code || '').trim()); @@ -14692,6 +14711,7 @@

Where to get help

// stagelabels RouteHuman), in the CI / Review column; the spinning cue // says the sweep is on it now. const preWhy = state === 'gate-pending' ? (stageTrackerReviewPassedDetail(mg.reason || laneReason) || 'waiting for merge admission') : ''; + if (state === 'merge-failed') return stageTrackerMergeFailedInfo(mg, nowMs, nextAt, lastSeen); if (mg.sweep_running) { return { state, word, detail: preWhy || 'merge sweep running', tip: (preWhy ? 'Review passed, not yet admitted to auto merge — ' + preWhy + '; ' : '') + "hive's merge sweep is running on this PR now.", cue: 'running', until: 0 }; } @@ -14715,17 +14735,56 @@

Where to get help

if (since > 0) return { state, word, detail: 'merge call in flight', tip: 'hive is merging it now' + (who ? ' (' + who + ')' : '') + ' — the merge call has been in flight' + sinceWords + '.', cue: 'merging', until: 0 }; return { state, word, detail: '', tip: 'Admitted and soaked; hive is merging it now (GitHub merge queue / merge window).' + lastSeen, cue: 'merging', until: 0 }; } - if (state === 'merge-failed') { - const why = String(mg.merge_failed || '').trim(); - const at = mg.merge_failed_at ? Date.parse(mg.merge_failed_at) : 0; - const who = STAGE_TRACKER_MERGE_PATH_WORDS[mg.merge_path] || ''; - return { state, word, detail: stageTrackerMergeFailedShort(why), tip: 'hive tried to merge this' + (who ? ' (' + who + ')' : '') + (at > 0 ? ' ' + stageTrackerAgoText(at, nowMs) : '') + ' and GitHub refused' + (why ? ': ' + why : '') + '. The lane re-evaluates it on its next pass' + (nextWords ? ' (' + nextWords + ')' : '') + '.' + lastSeen, cue: 'waiting', until: 0 }; - } const why = stageTrackerGateReasonText(mg.reason || laneReason); return { state, word, detail: preWhy, tip: 'Review passed, not yet admitted to auto merge' + (why ? ' — ' + why : '') + '.' + (nextWords ? ' hive re-checks the gate on its ' + nextWords.replace(/^next /, 'next ') + '.' : '') + sooner + lastSeen, cue: 'waiting', until: 0 }; } + // Refusal kind (merge_gate.merge_failed_kind, stageTrackerMergeRefusal in + // Go) → the chip's short detail. The chip never carries the raw error + // (hivecommons/docs#512 drew "PUT https://api.github.com/…" across the + // column); the plain sentence and the raw text ride the tooltip. + const STAGE_TRACKER_MERGE_REFUSAL_DETAIL = { protection: 'branch protection', review: 'review required', method: 'merge method off', 'merge-queue': 'merge queue only', 'head-moved': 'needs rebase', forbidden: 'not allowed', refused: 'GitHub refused' }; + // Pure: an older payload's raw refusal → its kind and sentence (the Go + // helper's mapping, abridged); 'refused' when nothing matches. + function stageTrackerMergeRefusalFromRaw(why) { + const m = /(\d+) of (\d+) required status checks? (?:are|is) expected/i.exec(why); + if (m) return { kind: 'checks-pending', text: m[1] + ' required check' + (m[1] === '1' ? " hasn't" : "s haven't") + ' finished', checks: Number(m[1]) }; + if (/required status check ["']([^"']+)["'] is expected/i.test(why)) return { kind: 'checks-pending', text: 'a required check hasn\'t finished', checks: 1 }; + if (/\b409\b|branch was modified/i.test(why)) return { kind: 'head-moved', text: 'the branch moved under the merge call; it needs a rebase', checks: 0 }; + if (/\b403\b|resource not accessible|forbidden/i.test(why)) return { kind: 'forbidden', text: "hive isn't allowed to merge here", checks: 0 }; + if (/\b405\b|not mergeable|blocked|protected branch/i.test(why)) return { kind: 'protection', text: 'branch protection blocks it', checks: 0 }; + return { kind: 'refused', text: 'GitHub refused the merge', checks: 0 }; + } + // Pure: the merge-failed pill. A refusal because required checks have + // not reported is not a failure — the sweep called too early — so the + // chip reads "Waiting for CI · 4 checks"; a sweep retrying now reads + // "Merge failed · retrying"; otherwise "Merge failed · ". + // The chip is a fixed short phrase (≤ 5 words); the tooltip carries the + // plain sentence and GitHub's raw text after "Details:". + function stageTrackerMergeFailedInfo(mg, nowMs, nextAt, lastSeen) { + const state = 'merge-failed'; + const why = String(mg.merge_failed || '').trim(); + const fallback = why && !mg.merge_failed_kind ? stageTrackerMergeRefusalFromRaw(why) : null; + const kind = mg.merge_failed_kind || (fallback && fallback.kind) || ''; + const text = mg.merge_failed_text || (fallback && fallback.text) || ''; + const checks = Number(mg.merge_failed_checks) || (fallback && fallback.checks) || 0; + const at = mg.merge_failed_at ? Date.parse(mg.merge_failed_at) : 0; + const who = STAGE_TRACKER_MERGE_PATH_WORDS[mg.merge_path] || ''; + const when = (who ? ' (' + who + ')' : '') + (at > 0 ? ' ' + stageTrackerAgoText(at, nowMs) : ''); + const nextWords = nextAt > nowMs ? 'next sweep in ' + stageTrackerShortLeft(nextAt - nowMs) : (nextAt > 0 ? 'sweep due now' : ''); + const details = why ? ' Details: ' + why : ''; + if (kind === 'checks-pending') { + const tip = 'hive tried to merge this' + when + ' before its required checks had reported — ' + (text || "required checks haven't finished") + '. It merges once they pass' + (mg.sweep_running ? "; hive's merge sweep is on it now" : (nextWords ? ' (' + nextWords + ')' : '')) + '.' + lastSeen + details; + return { state, word: 'Waiting for CI', detail: checks > 0 ? checks + ' check' + (checks === 1 ? '' : 's') : '', tip, cue: mg.sweep_running ? 'running' : 'waiting', until: 0 }; + } + const word = STAGE_TRACKER_MERGE_GATE_WORD[state]; + const sentence = 'hive tried to merge this' + when + ' and GitHub refused' + (text ? ' — ' + text : '') + '.'; + if (mg.sweep_running) { + return { state, word, detail: 'retrying', tip: sentence + " hive's merge sweep is retrying it now." + lastSeen + details, cue: 'running', until: 0 }; + } + return { state, word, detail: STAGE_TRACKER_MERGE_REFUSAL_DETAIL[kind] || 'GitHub refused', tip: sentence + ' The lane re-evaluates it on its next pass' + (nextWords ? ' (' + nextWords + ')' : '') + '.' + lastSeen + details, cue: 'waiting', until: 0 }; + } // Pure: a refusal's first line, cut to STAGE_TRACKER_MERGE_FAILED_SHORT_MAX - // for the pill detail; the full text rides the glyph tooltip. + // (tooltips and toasts; the pill detail comes from the refusal kind). function stageTrackerMergeFailedShort(why) { const line = String(why || '').split('\n')[0].replace(/^merging PR \S+ \([^)]*\): /, '').trim(); if (!line) return 'GitHub refused the merge'; @@ -15200,10 +15259,16 @@

Where to get help

// light the segment they branch from (stageTrackerColumn in Go). // kind is 'issue' or 'pr': an issue parked on a person (045, or a // pre-045 085) is parked before any PR exists, so it lights Actionable - // rather than the merge gate. - function stageTrackerAnchor(stage, stages, kind) { + // rather than the merge gate. item (optional) is the row: once a merge + // call has been made on its head (merge_gate.state merging / + // merge-failed) the outcome is a Merge gate matter whatever numeric + // stage the lane fell back to — hivecommons/docs#512 drew "Merge + // failed" in CI / Review because the PR sat at 060. + function stageTrackerAnchor(stage, stages, kind, item) { const cur = Number(stage) || 0; if (cur >= STAGE_TRACKER_TERMINAL) return STAGE_TRACKER_TERMINAL; + const mg = item && item.merge_gate; + if (mg && (mg.state === 'merging' || mg.state === 'merge-failed') && cur > STAGE_TRACKER_PR_COLUMN) return STAGE_TRACKER_MERGE_COLUMN; if (cur === STAGE_TRACKER_ISSUE_NEEDS_DECISION || cur === STAGE_TRACKER_TRIAGE_NEEDED || cur === STAGE_TRACKER_POSSIBLY_EXISTS) return STAGE_TRACKER_ISSUE_DECISION_COLUMN; if (cur === STAGE_TRACKER_NEEDS_DECISION && kind === 'issue') return STAGE_TRACKER_ISSUE_DECISION_COLUMN; if (STAGE_TRACKER_PATH.indexOf(cur) >= 0) return cur; @@ -15225,7 +15290,7 @@

Where to get help

(stages || []).forEach(st => { byNum[st.number] = st; }); const cur = Number(item.stage) || 0; const curStage = byNum[cur] || {}; - const anchor = stageTrackerAnchor(cur, stages, item.via_pr ? 'pr' : item.kind); + const anchor = stageTrackerAnchor(cur, stages, item.via_pr ? 'pr' : item.kind, item); const terminal = anchor >= STAGE_TRACKER_TERMINAL; const sentinelLane = stageTrackerSentinelInLane(item); const detour = (!terminal && STAGE_TRACKER_PATH.indexOf(cur) < 0 && cur !== STAGE_TRACKER_TRIAGE_NEEDED && cur !== STAGE_TRACKER_POSSIBLY_EXISTS && cur !== 40 && cur !== 60 && cur !== STAGE_TRACKER_PRE_MERGE_SOAK && cur !== 100) @@ -15271,7 +15336,7 @@

Where to get help

const os = stageTrackerOpenSince(item); if (os.ms) { word += ' · since ' + stageTrackerShortAgo(nowMs - os.ms); openSince = Object.assign({ stale: !openDraft && nowMs - os.ms > STAGE_TRACKER_OPEN_STALE_DAYS * 86400000 }, os); } } - return { number: n, code: n ? String(n).padStart(3, '0') : '', short: word, label: tipStage.label || st.label || String(n), description: tipStage.description || st.description || '', state, terminal: false, detour: n === anchor ? detour : null, hold: openHold, blocked: openBlocked, draft: openDraft, isNew: openNew, openSince }; + return { number: n, code: n ? String(n).padStart(3, '0') : '', short: word, label: (typeof stageTrackerStageName === 'function' && (stageTrackerStageName(tipStage) || stageTrackerStageName(st))) || tipStage.label || st.label || String(n), description: tipStage.description || st.description || '', state, terminal: false, detour: n === anchor ? detour : null, hold: openHold, blocked: openBlocked, draft: openDraft, isNew: openNew, openSince }; }); segs.push({ number: STAGE_TRACKER_TERMINAL, code: '', short: 'Merged', label: 'Merged', description: 'Merged — the pipeline is complete', state: terminal ? 'active' : 'todo', terminal, cap: true, detour: null }); return segs; @@ -16093,7 +16158,7 @@

Where to get help

function stageTrackerLinkedSorted(item, stages) { const linked = Array.isArray(item.linked_prs) ? item.linked_prs.filter(lp => stageTrackerLinkedDrawnHere(lp, item)) : (item.linked_pr ? [{ number: item.linked_pr }] : []); const sinceOf = lp => Date.parse(lp.stage_since || '') || Infinity; - return linked.sort((x, y) => (stageTrackerAnchor(y.stage, stages, 'pr') - stageTrackerAnchor(x.stage, stages, 'pr')) || (stageTrackerAttentionTier(x) - stageTrackerAttentionTier(y)) || (sinceOf(x) - sinceOf(y)) || ((x.number || 0) - (y.number || 0))); + return linked.sort((x, y) => (stageTrackerAnchor(y.stage, stages, 'pr', y) - stageTrackerAnchor(x.stage, stages, 'pr', x)) || (stageTrackerAttentionTier(x) - stageTrackerAttentionTier(y)) || (sinceOf(x) - sinceOf(y)) || ((x.number || 0) - (y.number || 0))); } // Pure: a PR whose drawn_under issue is not a row of this page (filtered @@ -16126,7 +16191,7 @@

Where to get help

const linked = item.kind === 'issue' ? stageTrackerLinkedSorted(item, stages) : []; const lead = linked.length && linked[0].stage ? linked[0] : item; const kind = lead === item ? item.kind : 'pr'; - return { anchor: stageTrackerAnchor(lead.stage, stages, kind), since: Date.parse(lead.stage_since || '') || Infinity }; + return { anchor: stageTrackerAnchor(lead.stage, stages, kind, lead), since: Date.parse(lead.stage_since || '') || Infinity }; } /* ---- Repo chip and group-by-repo (pure; run under node by @@ -16444,7 +16509,9 @@

Where to get help

if (next.stage !== prev.stage) { if (next.stage >= STAGE_TRACKER_TERMINAL) return 'merged'; const sg = (stages || []).find(x => Number(x.number) === next.stage); - const name = next.label || (sg && (sg.label || sg.short)) || ('stage ' + next.stage); + // Plain words, never a stage slug ("fell back to stage/060-reviewed"). + const named = typeof stageTrackerStageName === 'function' ? stageTrackerStageName({ label: next.label, short: '' }) || stageTrackerStageName(sg) : ''; + const name = named || next.label || (sg && (sg.label || sg.short)) || ('stage ' + next.stage); const back = stageTrackerStageFell(prev, next, stages); const why = (back || next.stage < prev.stage) && next.caption ? ' — ' + next.caption : ''; return (back ? 'fell back to ' : 'moved to ') + name + why; @@ -16570,7 +16637,7 @@

Where to get help

// Pure: the strip column (0-based; STAGE_TRACKER_PATH.length = merged cap) // an item's stage lights, or -1 for an unknown stage. function stageTrackerColIndex(item, stages) { - const anchor = stageTrackerAnchor(item.stage, stages, item.via_pr ? 'pr' : item.kind); + const anchor = stageTrackerAnchor(item.stage, stages, item.via_pr ? 'pr' : item.kind, item); if (anchor >= STAGE_TRACKER_TERMINAL) return STAGE_TRACKER_CAP_COLUMN; return STAGE_TRACKER_PATH.indexOf(anchor); } diff --git a/src/pkg/github/automerge/automerge_contributor_lane.go b/src/pkg/github/automerge/automerge_contributor_lane.go index e4319e3755..13a2f5319f 100644 --- a/src/pkg/github/automerge/automerge_contributor_lane.go +++ b/src/pkg/github/automerge/automerge_contributor_lane.go @@ -1434,7 +1434,7 @@ func (c *Engine) trySweepContributorLanePR(ctx context.Context, displayRepo, own return effects.Result{Provenance: mergeResult.GetSHA()}, nil }) if err != nil { - if requiredChecksExpectedMergeError(err) { + if c.requiredChecksExpected(attempt, err) { return c.updateBranchAndSkip(ctx, displayRepo, owner, repo, number, headSHA, "required-checks-expected", c.isForkPR(eval.pr)) } if reason := c.workflowFenceMergeUnauthorized(ctx, displayRepo, owner, repo, eval, err); reason != "" { diff --git a/src/pkg/github/automerge/automerge_merge_refusal.go b/src/pkg/github/automerge/automerge_merge_refusal.go index d80a5e489e..194b39a215 100644 --- a/src/pkg/github/automerge/automerge_merge_refusal.go +++ b/src/pkg/github/automerge/automerge_merge_refusal.go @@ -94,6 +94,48 @@ func mergeRefusalReviewKey(a mergeAttempt) string { return "review|" + strings.ToLower(a.owner+"/"+a.repo) + "#" + strconv.Itoa(a.number) } +// mergeRefusalChecksKey remembers a "required status checks are expected" +// 405 per PR: the head's required checks have not reported yet. +func mergeRefusalChecksKey(a mergeAttempt) string { + return "checks|" + strings.ToLower(a.owner+"/"+a.repo) + "#" + strconv.Itoa(a.number) +} + +// autoMergeReasonChecksExpected is the skip reason while GitHub has told the +// sweep the head's required checks are still expected. +const autoMergeReasonChecksExpected = "check-pending" + +// requiredChecksExpected reports whether err is GitHub's 405 "N of M +// required status checks are expected" and, when it is, remembers the head +// so knownMergeRefusal skips the merge call on the following passes while +// GitHub still reports the PR blocked (hivecommons/docs#512: the sweep put +// /merge on every pass, each refusal lighting "Merge failed" on the tracker +// for a PR whose checks had simply not started). A check run completing +// flips mergeable_state off "blocked", which re-arms the call. +func (c *Engine) requiredChecksExpected(a mergeAttempt, err error) bool { + if !requiredChecksExpectedMergeError(err) { + return false + } + if c == nil { + return true + } + c.rememberMergeRefusal(mergeRefusalChecksKey(a), mergeRefusal{head: strings.TrimSpace(a.head), state: comparableMergeableState(a.state)}) + return true +} + +// checksExpectedKnown reports whether the head of a is remembered as +// waiting on required checks and GitHub still reports it blocked. +func (c *Engine) checksExpectedKnown(a mergeAttempt, now time.Time) bool { + r, ok := c.mergeRefusals[mergeRefusalChecksKey(a)] + if !ok { + return false + } + if now.Sub(r.at) >= mergeRefusalRecheck || !strings.EqualFold(r.head, strings.TrimSpace(a.head)) || comparableMergeableState(a.state) != "blocked" { + delete(c.mergeRefusals, mergeRefusalChecksKey(a)) + return false + } + return true +} + func mergeRefusalMethodKey(a mergeAttempt) string { return "method|" + strings.ToLower(a.owner+"/"+a.repo) + "|" + strings.ToLower(strings.TrimSpace(a.method)) } @@ -125,6 +167,9 @@ func (c *Engine) knownMergeRefusal(a mergeAttempt) string { now := c.clock() c.mergeRefusalsMu.Lock() defer c.mergeRefusalsMu.Unlock() + if c.checksExpectedKnown(a, now) { + return autoMergeReasonChecksExpected + } if key := mergeRefusalMethodKey(a); strings.TrimSpace(a.method) != "" { if r, ok := c.mergeRefusals[key]; ok { if now.Sub(r.at) < mergeRefusalRecheck { @@ -159,7 +204,7 @@ func (c *Engine) refusedMerge(a mergeAttempt, err error) string { return reason } var key string - r := mergeRefusal{at: c.clock()} + var r mergeRefusal switch reason { case autoMergeReasonMergeRefusedReview: key, r.head, r.state = mergeRefusalReviewKey(a), strings.TrimSpace(a.head), comparableMergeableState(a.state) @@ -169,6 +214,14 @@ func (c *Engine) refusedMerge(a mergeAttempt, err error) string { } key = mergeRefusalMethodKey(a) } + c.rememberMergeRefusal(key, r) + return reason +} + +// rememberMergeRefusal stores r under key, stamped now, pruning expired +// entries once the map is large. +func (c *Engine) rememberMergeRefusal(key string, r mergeRefusal) { + r.at = c.clock() c.mergeRefusalsMu.Lock() defer c.mergeRefusalsMu.Unlock() if c.mergeRefusals == nil { @@ -183,5 +236,4 @@ func (c *Engine) refusedMerge(a mergeAttempt, err error) string { } } c.mergeRefusals[key] = r - return reason } diff --git a/src/pkg/github/automerge/automerge_merge_refusal_test.go b/src/pkg/github/automerge/automerge_merge_refusal_test.go index c2f7524b7c..fe2c3bceb3 100644 --- a/src/pkg/github/automerge/automerge_merge_refusal_test.go +++ b/src/pkg/github/automerge/automerge_merge_refusal_test.go @@ -214,3 +214,44 @@ func TestContributorLanePermanentMergeRefusalOneMergeCall(t *testing.T) { }) } } + +// TestRequiredChecksExpectedRemembered: GitHub's 405 "N of M required status +// checks are expected" (hivecommons/docs#512, 2026-10-29) is remembered per +// head, and the next pass skips the merge call as check-pending while the +// PR is still blocked — a new head, an unblocked state or the recheck +// window re-arms it; other errors are not remembered. +func TestRequiredChecksExpectedRemembered(t *testing.T) { + expected := &gh.ErrorResponse{Response: &http.Response{StatusCode: http.StatusMethodNotAllowed}, Message: "4 of 4 required status checks are expected."} + base := mergeAttempt{owner: "hivecommons", repo: "docs", base: "main", number: 512, head: "sha512", state: "blocked", method: "squash"} + for _, tc := range []struct { + name string + err error + next func(mergeAttempt) mergeAttempt + advance time.Duration + want string + }{ + {name: "same head still blocked", err: expected, want: autoMergeReasonChecksExpected}, + {name: "new head re-arms", err: expected, next: func(a mergeAttempt) mergeAttempt { a.head = "sha513"; return a }}, + {name: "checks reported re-arms", err: expected, next: func(a mergeAttempt) mergeAttempt { a.state = "clean"; return a }}, + {name: "state not yet computed re-arms", err: expected, next: func(a mergeAttempt) mergeAttempt { a.state = "unknown"; return a }}, + {name: "recheck re-arms", err: expected, advance: mergeRefusalRecheck}, + {name: "per PR", err: expected, next: func(a mergeAttempt) mergeAttempt { a.number = 513; return a }}, + {name: "other 405 is not remembered", err: &gh.ErrorResponse{Response: &http.Response{StatusCode: http.StatusMethodNotAllowed}, Message: "Pull Request is not mergeable"}}, + } { + t.Run(tc.name, func(t *testing.T) { + clock := time.Date(2026, 10, 29, 15, 4, 0, 0, time.UTC) + c := &Engine{now: func() time.Time { return clock }} + if got := c.requiredChecksExpected(base, tc.err); got != requiredChecksExpectedMergeError(tc.err) { + t.Fatalf("requiredChecksExpected = %v", got) + } + clock = clock.Add(tc.advance) + next := base + if tc.next != nil { + next = tc.next(base) + } + if got := c.knownMergeRefusal(next); got != tc.want { + t.Fatalf("knownMergeRefusal = %q, want %q", got, tc.want) + } + }) + } +} diff --git a/src/pkg/github/automerge/automerge_sweep.go b/src/pkg/github/automerge/automerge_sweep.go index ccf3b813bd..97221e28b1 100644 --- a/src/pkg/github/automerge/automerge_sweep.go +++ b/src/pkg/github/automerge/automerge_sweep.go @@ -1948,7 +1948,7 @@ func (c *Engine) trySweepSelfAuthoredPR(ctx context.Context, displayRepo, owner, return effects.Result{Provenance: mergeResult.GetSHA()}, nil }) if err != nil { - if requiredChecksExpectedMergeError(err) { + if c.requiredChecksExpected(attempt, err) { if !branchUpdateAllowed { return AutoMergeSweepEvent{}, "check-pending", nil } @@ -2343,7 +2343,7 @@ func (c *Engine) trySweepTrustedAuthorPR(ctx context.Context, displayRepo, owner return effects.Result{Provenance: mergeResult.GetSHA()}, nil }) if err != nil { - if requiredChecksExpectedMergeError(err) { + if c.requiredChecksExpected(attempt, err) { return c.updateBranchAndSkip(ctx, displayRepo, owner, repo, number, headSHA, "required-checks-expected", c.isForkPR(pr)) } if refused := c.refusedMerge(attempt, err); refused != "" { From e4b72c814dff6cacd59885f7e07992a0d5ae7644 Mon Sep 17 00:00:00 2001 From: Andrew Anderson Date: Thu, 29 Oct 2026 11:40:16 -0400 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=90=9B=20tracker:=20lift=20stageTrack?= =?UTF-8?q?erAnchor=20by=20its=20new=20signature=20in=20the=20adopted-colu?= =?UTF-8?q?mn=20node=20suite?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Andrew Anderson --- src/pkg/dashboard/stage_tracker_adopted_column.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pkg/dashboard/stage_tracker_adopted_column.test.js b/src/pkg/dashboard/stage_tracker_adopted_column.test.js index a5fd48d7ef..1d57306acf 100644 --- a/src/pkg/dashboard/stage_tracker_adopted_column.test.js +++ b/src/pkg/dashboard/stage_tracker_adopted_column.test.js @@ -32,7 +32,7 @@ const src = [ pick(/const STAGE_TRACKER_TERMINAL = \d+;/, 'STAGE_TRACKER_TERMINAL'), pick(/const STAGE_TRACKER_ADOPTED_BY_HIVE = \d+;/, 'STAGE_TRACKER_ADOPTED_BY_HIVE'), pick(/function stageTrackerAdoptedWord\(item\) \{[\s\S]*?\n \}\n/, 'stageTrackerAdoptedWord'), - pick(/function stageTrackerAnchor\(stage, stages, kind\) \{[\s\S]*?\n \}\n/, 'stageTrackerAnchor'), + pick(/function stageTrackerAnchor\(stage, stages, kind, item\) \{[\s\S]*?\n \}\n/, 'stageTrackerAnchor'), ].join('\n'); const lifted = new Function(src + '; return { anchor: stageTrackerAnchor, adoptedWord: stageTrackerAdoptedWord, ADOPTED: STAGE_TRACKER_ADOPTED_BY_HIVE };')();