diff --git a/changelog.d/fixed-tracker-linked-pr-progress.md b/changelog.d/fixed-tracker-linked-pr-progress.md new file mode 100644 index 0000000000..22efeeda72 --- /dev/null +++ b/changelog.d/fixed-tracker-linked-pr-progress.md @@ -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. diff --git a/src/pkg/dashboard/stage_tracker.go b/src/pkg/dashboard/stage_tracker.go index 9a3b44f7f6..42fba07781 100644 --- a/src/pkg/dashboard/stage_tracker.go +++ b/src/pkg/dashboard/stage_tracker.go @@ -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 { @@ -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`) diff --git a/src/pkg/dashboard/stage_tracker_actor.go b/src/pkg/dashboard/stage_tracker_actor.go index a29f7de73c..ae35d51ddb 100644 --- a/src/pkg/dashboard/stage_tracker_actor.go +++ b/src/pkg/dashboard/stage_tracker_actor.go @@ -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 { @@ -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 } diff --git a/src/pkg/dashboard/stage_tracker_linked_progress_test.go b/src/pkg/dashboard/stage_tracker_linked_progress_test.go new file mode 100644 index 0000000000..06e36fc78a --- /dev/null +++ b/src/pkg/dashboard/stage_tracker_linked_progress_test.go @@ -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); +`) +} diff --git a/src/pkg/dashboard/stage_tracker_new.go b/src/pkg/dashboard/stage_tracker_new.go index 193ad5146c..3a734dbabf 100644 --- a/src/pkg/dashboard/stage_tracker_new.go +++ b/src/pkg/dashboard/stage_tracker_new.go @@ -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 { diff --git a/src/pkg/dashboard/stage_tracker_new_test.go b/src/pkg/dashboard/stage_tracker_new_test.go index 5350f8f4fe..21a3f36738 100644 --- a/src/pkg/dashboard/stage_tracker_new_test.go +++ b/src/pkg/dashboard/stage_tracker_new_test.go @@ -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}}, diff --git a/src/pkg/dashboard/stage_tracker_test.go b/src/pkg/dashboard/stage_tracker_test.go index 488d0139b3..b9ead3e7f0 100644 --- a/src/pkg/dashboard/stage_tracker_test.go +++ b/src/pkg/dashboard/stage_tracker_test.go @@ -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 @@ -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) }