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-tracker-linked-pr-progress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Activity Monitor issue messages now follow covering PR progress instead of stale New/scanner captions, including links discovered from the PR side.
30 changes: 30 additions & 0 deletions src/pkg/dashboard/stage_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -2806,7 +2806,9 @@ func stageTrackerResolveLinkedPRs(items []StageTrackerItem) {
out = nil
}
it.LinkedPRs = out
stageTrackerLinkedPRProgress(it)
}

// NestedUnder is final only once every issue has been read; name it on
// each listing so the SPA draws the PR's strip under one parent only.
for i := range items {
Expand All @@ -2827,6 +2829,34 @@ func stageTrackerResolveLinkedPRs(items []StageTrackerItem) {
}
}

// Link evidence arrives after the issue's stage/new narration, including
// reverse closing references from PRs. Do not narrate a completed intake
// step as work the scanner still needs to do.
func stageTrackerLinkedPRProgress(it *StageTrackerItem) {
if it.Kind != "issue" || len(it.LinkedPRs) == 0 || (it.Stage > trackerNumberCoveredByPR && !it.Mirrored) ||
it.Hold != nil || len(it.BlockedOn) > 0 || it.BlockedOnPR != nil {
return
}
it.New = nil
if it.StageSlug == StageTrackerNewSlug {
it.StageSlug = ""
}
progress := make([]string, 0, len(it.LinkedPRs))
for _, pr := range it.LinkedPRs {
text := fmt.Sprintf("PR #%d", pr.Number)
if pr.Caption != "" {
text += " — " + pr.Caption
}
progress = append(progress, text)
}
prefix := "Covered by "
if stageengine.ReasonIsPartialCover(it.Reason) {
prefix = "Partially covered by "
}
it.Caption = prefix + strings.Join(progress, "; ")
it.Actor = "its PR"
}

// stageTrackerClosedIssueAnchor returns the closed issue a standalone PR
// row re-anchors around, or nil. A PR nested under a listed issue, a PR
// with an open closing link, and a PR whose links are all soft (`Refs #N`)
Expand Down
8 changes: 4 additions & 4 deletions src/pkg/dashboard/stage_tracker_actor.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,9 +316,9 @@ func stageTrackerBotFixingCaption(it StageTrackerItem) string {
}

// stageTrackerResolveActors runs after stageTrackerResolveLinkedPRs: an
// issue riding its covering PR (030 / 040 / mirrored) takes that PR's
// actor, and each nested sub-row carries its PR's actor so the SPA draws
// the same icon on both.
// issue riding its covering PR (including stale intake narration replaced
// after link resolution) takes that PR's actor, and each nested sub-row
// carries its PR's actor so the SPA draws the same icon on both.
func stageTrackerResolveActors(items []StageTrackerItem) {
prs := map[string]*StageTrackerItem{}
for i := range items {
Expand All @@ -340,7 +340,7 @@ func stageTrackerResolveActors(items []StageTrackerItem) {
if it.StageActor == nil || slices.Contains(it.Modifiers, modHold) {
continue
}
rides := it.Mirrored || it.Stage == trackerNumberPRInProgress || it.Stage == trackerNumberCoveredByPR
rides := it.Mirrored || it.Stage == trackerNumberPRInProgress || it.Stage == trackerNumberCoveredByPR || it.Actor == "its PR"
if !rides || len(it.LinkedPRs) == 0 {
continue
}
Expand Down
131 changes: 131 additions & 0 deletions src/pkg/dashboard/stage_tracker_linked_progress_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
package dashboard

import (
"encoding/json"
"strings"
"testing"
"time"

"github.com/hivecommons/hive/pkg/github"
"github.com/hivecommons/hive/pkg/stagelabels"
)

func TestStageTrackerLinkedPRProgressPayload(t *testing.T) {
now := time.Date(2026, 10, 29, 1, 45, 0, 0, time.UTC)
for _, reverse := range []bool{false, true} {
for _, stage := range []stagelabels.Stage{stagelabels.None, stagelabels.Actionable, stagelabels.Claimed, stagelabels.PRInProgress} {
t.Run(stage.Slug()+"/"+map[bool]string{false: "issue-link", true: "pr-link"}[reverse], func(t *testing.T) {
s, store := stageTrackerFixture(t, now)
issue := github.Issue{Number: 15218, Title: "Soak countdown", Author: "pat", CreatedAt: now.Add(-time.Hour)}
if stage != stagelabels.None {
store.Observe(stagelabels.Key("acme/console", issue.Number), stage, "actionable")
}
pr := github.PullRequest{Number: 15223, Author: "pat", Labels: []string{stagelabels.ReviewPending.Label()}}
if reverse {
pr.LinkedIssues = []github.PRLinkedIssue{{Number: issue.Number}}
} else {
issue.LinkedPRs = []github.IssueLinkedPR{{Number: pr.Number, State: "open"}}
}
repo := &s.status.Repos[0]
repo.ActionableIssues = append(repo.ActionableIssues, issue,
github.Issue{Number: 15219, Title: "Still new", CreatedAt: now})
repo.OpenPrs = append(repo.OpenPrs, FrontendPR{PullRequest: pr})
for _, prStage := range []stagelabels.Stage{stagelabels.ReviewPending, stagelabels.NeedsAuthor} {
pr.Labels = []string{prStage.Label()}
repo.OpenPrs[len(repo.OpenPrs)-1] = FrontendPR{PullRequest: pr}
resp := s.buildStageTracker(s.status, store, now)
got := trackerItem(t, resp, "issue", issue.Number)
cover := trackerItem(t, resp, "pr", pr.Number)
if got.New != nil || got.StageSlug == StageTrackerNewSlug || got.Caption != "Covered by PR #15223 — "+cover.Caption {
t.Fatalf("issue retained stale intake narration: %+v", got)
}
if got.Stage != stage.Number() {
t.Fatalf("narration must not mutate the issue's recorded stage: %d", got.Stage)
}
if got.StageActor == nil || cover.StageActor == nil || *got.StageActor != *cover.StageActor {
t.Fatalf("issue actor %+v, want covering PR actor %+v", got.StageActor, cover.StageActor)
}
if fresh := trackerItem(t, resp, "issue", 15219); fresh.New == nil || !strings.Contains(fresh.Caption, "then the scanner") {
t.Fatalf("no-PR intake behavior changed: %+v", fresh)
}
}
})
}
}
}

func TestStageTrackerLinkedPRProgressBoundaries(t *testing.T) {
prs := []StageTrackerLinkedPR{{Number: 15223, Caption: "Needs @pat to fix CI"}, {Number: 15224}}
for name, it := range map[string]StageTrackerItem{
"no PR": {Kind: "issue"},
"PR row": {Kind: "pr", LinkedPRs: prs},
"held": {Kind: "issue", LinkedPRs: prs, Hold: &StageTrackerHold{}},
"blocked": {Kind: "issue", LinkedPRs: prs, BlockedOn: []string{"#1"}},
"blocked on PR": {Kind: "issue", LinkedPRs: prs, BlockedOnPR: &StageTrackerBlockedOnPR{}},
"decision": {Kind: "issue", Stage: trackerNumberIssueDecision, LinkedPRs: prs},
} {
t.Run(name, func(t *testing.T) {
it.Caption = "Keep the issue's own state"
stageTrackerLinkedPRProgress(&it)
if it.Caption != "Keep the issue's own state" {
t.Fatalf("overrode an independent state: %+v", it)
}
})
}
for _, mirrored := range []bool{false, true} {
it := StageTrackerItem{Kind: "issue", Stage: trackerNumberCoveredByPR, Mirrored: mirrored,
LinkedPRs: prs, Reason: "open PR addresses part of it (references it without a closing keyword)"}
if mirrored {
it.Stage = trackerNumberReviewed
}
stageTrackerLinkedPRProgress(&it)
if it.Caption != "Partially covered by PR #15223 — Needs @pat to fix CI; PR #15224" {
t.Fatalf("partial/multiple/metadata-free coverage: %+v", it)
}
}
}

func TestStageTrackerLinkedPRProgressRowsAndEvents(t *testing.T) {
items := []StageTrackerItem{
{Repo: "acme/console", Number: 15218, Kind: "issue", StageSlug: StageTrackerNewSlug, New: &StageTrackerNew{},
Caption: "New · waiting for the stage-label pass, then the scanner"},
{Repo: "acme/console", Number: 15223, Kind: "pr", Stage: trackerNumberNeedsAuthor, Caption: "Needs @pat to fix CI",
LinkedIssues: []StageTrackerLinkedIssue{{Number: 15218}}},
}
stageTrackerResolveLinkedPRs(items)
before, err := json.Marshal(items)
if err != nil {
t.Fatal(err)
}
items[1].Caption = "Needs @pat to rebase"
stageTrackerResolveLinkedPRs(items)
after, err := json.Marshal(items)
if err != nil {
t.Fatal(err)
}
html := indexHTML(t)
runStageTrackerRowActionsScript(t, stageTrackerRowsPreludeJS(t, html)+stageTrackerRowsFixtureJS+
jsFunc(t, html, "stageTrackerNewState")+"\n"+jsFunc(t, html, "stageTrackerNewLines")+"\n"+
"const before = "+string(before)+";\nconst after = "+string(after)+`;
const issue = before[0], key = stageTrackerItemKey(issue);
assert.strictEqual(stageTrackerNewState(issue), null);
assert.deepStrictEqual(stageTrackerNewLines(issue, now), []);
assert.ok(stageTrackerTooltip(issue, now).includes('Covered by PR #15223 — Needs @pat to fix CI'));
for (const row of [
issue,
Object.assign({}, issue, {linked_prs: issue.linked_prs.concat([{number: 15224, stage: 50, caption: 'Review pending'}])}),
Object.assign({}, issue, {linked_prs: issue.linked_prs.map(lp => Object.assign({}, lp, {drawn_under: 1}))})
]) {
const rendered = stageTrackerRowHtml(row, stages, {nowMs: now});
assert.ok(!rendered.includes('then the scanner'), rendered);
assert.ok(!rendered.includes('ham-open-new'), rendered);
}
const prev = stageTrackerStateMap(before), next = stageTrackerStateMap(after);
assert.ok(prev[key].caption.includes('Needs @pat to fix CI'));
assert.deepStrictEqual(stageTrackerEventsNext({}, null, prev, stages, now), {});
const events = stageTrackerEventsNext({}, prev, next, stages, now + 1000);
const line = stageTrackerEventHtml(key, {events, nowMs: now + 1000});
assert.ok(line.includes('Hive') && line.includes('Covered by PR #15223 — Needs @pat to rebase'), line);
assert.ok(!line.includes('scanner') && !line.includes('stage-label pass'), line);
`)
}
2 changes: 1 addition & 1 deletion src/pkg/dashboard/stage_tracker_new.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ type StageTrackerNew struct {
// bucket that means "not placed yet" rather than "placed outside the
// actionable set" (filtered, hive_advisory, claimed, …).
func stageTrackerIsNew(it StageTrackerItem, hasRec bool) bool {
if it.Stage != 0 || hasRec || it.Hold != nil || len(it.BlockedOn) > 0 || it.BlockedOnPR != nil {
if it.Stage != 0 || hasRec || it.Hold != nil || len(it.BlockedOn) > 0 || it.BlockedOnPR != nil || it.LinkedPR > 0 || len(it.LinkedPRs) > 0 {
return false
}
for _, m := range it.Modifiers {
Expand Down
2 changes: 2 additions & 0 deletions src/pkg/dashboard/stage_tracker_new_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ func TestStageTrackerNewState(t *testing.T) {

notNew := map[string]StageTrackerItem{
"stage": {Kind: "issue", Stage: 10},
"linked": {Kind: "issue", LinkedPR: 15223},
"links": {Kind: "issue", LinkedPRs: []StageTrackerLinkedPR{{Number: 15223}}},
"hold": {Kind: "issue", Stage: 0, Hold: &StageTrackerHold{By: "pat"}, Modifiers: []string{modHold}},
"blocked": {Kind: "issue", Stage: 0, BlockedOn: []string{"#1"}, Modifiers: []string{modBlocked}},
"draft": {Kind: "pr", Stage: 0, Modifiers: []string{modDraft}},
Expand Down
5 changes: 3 additions & 2 deletions src/pkg/dashboard/stage_tracker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ func TestStageTrackerEndpoint(t *testing.T) {
if issue7.Stage != 95 || !issue7.Mirrored || issue7.LinkedPR != 102 || issue7.Lane != laneIssue || issue7.AuthorKind != authorKindHuman {
t.Fatalf("issue7 = %+v", issue7)
}
if issue7.Caption != "Covered by PR #102 — soaking on the PR side" {
if issue7.Caption != "Covered by PR #102 — "+pr102.Caption {
t.Fatalf("issue7 caption = %q", issue7.Caption)
}
// The covering PR is resolved onto the issue with what its sub-row
Expand All @@ -533,7 +533,8 @@ func TestStageTrackerEndpoint(t *testing.T) {
t.Fatalf("nested_under: pr102=%d pr101=%d", pr102.NestedUnder, pr101.NestedUnder)
}
issue8 := trackerItem(t, resp, "issue", 8)
if issue8.Stage != 10 || issue8.Mirrored || issue8.Actor != "scanner" || issue8.AuthorKind != authorKindHive {
if issue8.Stage != 10 || issue8.Mirrored || issue8.Actor != "its PR" || issue8.AuthorKind != authorKindHive ||
issue8.Caption != "Covered by PR #103 — "+pr103.Caption {
t.Fatalf("issue8 = %+v", issue8)
}

Expand Down
Loading