diff --git a/changelog.d/fixed-adoption-superseded-close-and-note.md b/changelog.d/fixed-adoption-superseded-close-and-note.md new file mode 100644 index 0000000000..1d96bf7649 --- /dev/null +++ b/changelog.d/fixed-adoption-superseded-close-and-note.md @@ -0,0 +1 @@ +- A PR superseded by a hive adoption now closes promptly and reads as one muted line in the Activity Monitor (hivecommons/hive#15511 listed hive's #15574 *Merge queued* and, under it, the still-open original #15526 whose greyed note "· Adopted → #15574 · superseded (hive re-authored with sign-off)" wrapped to two lines; the close-first close had been refused by the write-back gate with `needs-opt-in-label`). New `governor.labels.stage.adoption.close_superseded: on_adopt|on_merge` (default `on_adopt`): a clanker- or hive-authored original closes in the adopting pass by policy — the gate admits the close as `superseded-agent-pr` without the `contributor_adopt` opt-in label once the copy carries its commits and sign-off; a human-authored original still needs the label, else it closes when the copy merges. The tracker marks the original `superseded_by: M` (cleared when the copy dies, omitted for in-place adoptions) and the copy's `adopted_from.state` / `lineage.from_state`; the muted sub-row's note is now "superseded · hive adopted → #M" ("superseded · closed · hive adopted → #M" once closed) on one line — the title ellipsizes first, the hover carries "re-authored with the same commits and sign-off" and whether it closes when #M merges or is already closed — and the line stays only while #M is open and listed. diff --git a/src/cmd/hive/merge_eligibility.go b/src/cmd/hive/merge_eligibility.go index 73b2ad6941..ea4e33ede1 100644 --- a/src/cmd/hive/merge_eligibility.go +++ b/src/cmd/hive/merge_eligibility.go @@ -125,6 +125,7 @@ func stageLabelPolicyFunc(cfg *config.Config) func() automerge.StageLabelPolicy AdoptionAutoMerge: stage.Adoption.AutoMergeEnabled(), AdoptionMaintainerPolicy: stage.Adoption.EffectiveMaintainerPolicy(), AdoptSupersedeCloseFirst: stage.Adoption.Supersede.CloseFirstEnabled(), + AdoptCloseSuperseded: stage.Adoption.EffectiveCloseSuperseded(), HiveID: cfg.HiveID, AuthorKindLabels: cfg.Governor.Labels.Author.Names(), RelayKnown: contributorRelayKnown, diff --git a/src/docs/dashboard-sections.md b/src/docs/dashboard-sections.md index 3f07bed9ed..f0cc5fe321 100644 --- a/src/docs/dashboard-sections.md +++ b/src/docs/dashboard-sections.md @@ -977,6 +977,8 @@ An adopted pull request names the hive's superseding copy in its detour word (`a If two copies are closed within an hour the hive stops (`adopted_by_state: "closed-twice"`, park reason `adoption-child-closed-twice`): the row reads "Adopted → #N (closed twice) · needs a person" and the popover question asks you to reopen the last copy, give direction, or close the PR. With close-first supersession (the default, hivecommons/hive#15135) the original is closed in the adopting pass and has **no row** while its copy is open — the copy is the one active PR for the issue, and the original's record is superseded (no chevron, no *Needs human decision*). +A superseded original keeps a muted, chevron-less sub-row under the issue while its superseder is open and listed (hivecommons/hive#15511 showed hive's #15574 *Merge queued* and, beneath it, the still-open #15526 as a greyed line whose note "· Adopted → #15574 · superseded (hive re-authored with sign-off)" wrapped to two lines). The note now reads **"superseded · hive adopted → #M"**, or **"superseded · closed · hive adopted → #M"** once the original is closed, and never wraps — the PR title ellipsizes first; the hover carries the long form ("Hive re-authored this PR as #M with the same commits and sign-off. This PR closes as superseded when #M merges." / "…This PR is closed as superseded."). The tracker sets `superseded_by: M` on the original (omitted for an in-place adoption, cleared when the copy is closed / closed-twice / copy-failed so the original counts again) and `adopted_from.state` / `lineage.from_state` on the copy (`"open"` or `"closed"`). A closed original is listed in this muted form only while #M is open and listed; it leaves the tracker once #M merges or closes. Agent-authored originals close in the adopting pass by policy (`governor.labels.stage.adoption.close_superseded`, default `on_adopt`); a person's PR closes then only with the write-back opt-in label, else when the copy merges — see [hive-merge.md](hive-merge.md). + A copy that then fails (closed unmerged, or red at two heads) reopens the original: `adopted_by_state: "copy-failed"` renders "Adopted → #N (copy failed) · reopened, needs a person" at 085 with the caption "The hive's copy #N failed; this PR was reopened and needs a person". #### Presence indicator on the waiting-on pill diff --git a/src/docs/hive-merge.md b/src/docs/hive-merge.md index 54ca0ead4c..9c75c5dd5f 100644 --- a/src/docs/hive-merge.md +++ b/src/docs/hive-merge.md @@ -775,10 +775,27 @@ then), so the issue list and the PR list read the same ([#12436](https://github.com/hivecommons/hive/issues/12436)). An adoption pair is one logical PR everywhere a person might otherwise be -asked to pick between PRs (hivecommons/hive#15495). When the write-back gate -keeps the contributor's original open after supersession (`needs-opt-in-label`, -a fork the hive cannot edit), it sits at 072 "superseded by #N" and the -issue's caption, open-PR count, parked-PR check and "Let hive decide — all N +asked to pick between PRs (hivecommons/hive#15495). A clanker- or +hive-authored original closes in the adopting pass by policy +(`governor.labels.stage.adoption.close_superseded: on_adopt`, the default; +`on_merge` keeps it open until the copy merges): the write-back gate admits +the close as `superseded-agent-pr` without the repo opt-in label the +`contributor_adopt` kind otherwise wants, because the copy carries the same +commits and sign-off (hivecommons/hive#15526 sat open beside hive's #15574 +as "Adopted → #15574 · superseded" with the gate saying +`needs-opt-in-label`). A human-authored original still needs that opt-in +label to close in the adopting pass; without it the gate keeps it open after +supersession (`needs-opt-in-label`, or a fork the hive cannot edit) and it +sits at 072 "superseded by #N" until the copy merges. Either way the +superseded original draws in the Activity Monitor as one muted, +chevron-less line under the issue (greyed title, no stage strip) whose +trailing note reads "superseded · hive adopted → #M" — or "superseded · +closed · hive adopted → #M" once it is closed — on a single line (the title +ellipsizes first); the hover carries the long form ("Hive re-authored this +PR as #M with the same commits and sign-off. This PR closes as superseded +when #M merges." / "…is closed as superseded."). The tracker marks it +`superseded_by: M`; the line stays only while #M is open and listed and +drops once #M merges or closes. The issue's caption, open-PR count, parked-PR check and "Let hive decide — all N PRs" fan-out all see only the hive's copy: the original's review verdict never gates the issue, and the copy's body carries every `Fixes #N` / `Refs #N` line of the original (an annotated `Refs #N — partial` travels as the bare diff --git a/src/docs/labels-and-control-signals.md b/src/docs/labels-and-control-signals.md index ec0c9da4fa..360176392a 100644 --- a/src/docs/labels-and-control-signals.md +++ b/src/docs/labels-and-control-signals.md @@ -2045,7 +2045,13 @@ When a contributor-agent PR goes red the hive does not just relabel it (a human- table in [operator-reference.md](operator-reference.md#what-hive-writes-to-github-and-when)): refused, nothing is written and the original stays open on the - keep-open path below until the copy merges. `close_first: false` restores the keep-open behaviour + keep-open path below until the copy merges. A clanker- or + hive-authored original does not need the label: the gate admits its + close as `superseded-agent-pr` by policy + (`governor.labels.stage.adoption.close_superseded`, `on_adopt` by + default, `on_merge` to keep it open until the copy merges), because + the copy carries the same commits and sign-off + (hivecommons/hive#15526). `close_first: false` restores the keep-open behaviour below: the note has no `close_first` field, the original moves to `stage/074-adopted-by-hive` (its linked issue mirrors the stage) and closes only when the copy merges. The hub drops the PR from the diff --git a/src/docs/operator-reference.md b/src/docs/operator-reference.md index 0dec23abf4..e0fa5d0fcd 100644 --- a/src/docs/operator-reference.md +++ b/src/docs/operator-reference.md @@ -861,7 +861,13 @@ label, close and reopen are unsolicited writes on a contributor's PR, so each first asks the write-back gate as kind `contributor_adopt` (L6 + opt-in label by default; see [the write-back table](#what-hive-writes-to-github-and-when)): refused, the original is not closed and stays open on the keep-open path -until the copy merges, and a due reopen waits for the next poll (a pause +until the copy merges, and a due reopen waits for the next poll. A clanker- +or hive-authored original is exempt from the opt-in label: with +`governor.labels.stage.adoption.close_superseded: on_adopt` (the default; +`on_merge` keeps it open until the copy merges) the gate admits its close +as `superseded-agent-pr` once the copy carries its commits and sign-off, so +an agent's PR never lingers open beside hive's copy +(hivecommons/hive#15526) (a pause lifting lands it; a policy change after the close is warned in the log and leaves the PR closed until a person reopens it). `close_first: false` keeps the earlier behaviour: the original moves to 074 and closes @@ -1073,7 +1079,7 @@ that level, the power the write-back exists to govern? | PR↔issue linker (`pr_issue_link.go`, `pr_contributor_link.go`, `linked_prs.go`) | PR watcher | "covered by PR" label on the issue, link comments | issues referenced by any PR | `covered_by_pr_label` → L5 + label | | Verdict / decision labels (`pr_decision_operator.go`, `human_decision_label.go`, `legacy_decision_labels.go`, `contribute_verdict_settle.go`) | review verdicts, dashboard decisions | `hive:verdict-*`, decision labels | reviewed PRs | `verdict_label` → L3 + label; dashboard-triggered decisions are solicited | | Contributor adopt / nudge / bot takeover (`automerge/automerge_contributor_*.go`, `automerge_bot_takeover.go`) | auto-merge sweep | adopt comment, update-branch push, workflow approval, nudge comments | contributor PRs in the contributor lane | `contributor_adopt` → L6 + label | -| Adoption close-first (`automerge/automerge_adoption_close_first.go`) | auto-merge sweep, when a supersede adoption opens the hive's copy; close-first poll | close-first note, `hive/superseded` label and close on the original; reopen, copy-failed note and label removal when the copy fails | the contributor's original PR | `contributor_adopt` → L6 + label; refused: the original stays open until the copy merges, and a due reopen waits for the next poll | +| Adoption close-first (`automerge/automerge_adoption_close_first.go`) | auto-merge sweep, when a supersede adoption opens the hive's copy; close-first poll | close-first note, `hive/superseded` label and close on the original; reopen, copy-failed note and label removal when the copy fails | the contributor's original PR | `contributor_adopt` → L6 + label (an agent-authored original closes without the label, `adoption.close_superseded: on_adopt`); refused: the original stays open until the copy merges, and a due reopen waits for the next poll | | Claims (`prclaims.go`, `claimed_by_label.go`, `cmd/hive/claimswire.go`, `claimescalation.go`) | claim ledger changes | `claimed-by:*` labels, claim/escalation comments | claimed issues | `claim_comment` → L4 + label (hive-claimed issues are own items) | | Issue close / task-list / decomposed parents (`issue_close.go`, `task_list_sweep.go`, `decomposed_parents.go`, `close_on_merge.go`, `tracking_issue.go`) | merges, sweeps | close, body edits (checkbox ticks), `Refs` rewrites | issues linked from hive PRs | `issue_close`, `parent_issue_edit` → L5 + label; hive-filed issues are own items | | Gate comments (`pkg/scheduler/clarity_gate.go`, `prior_art_gate.go`, `triage.go`, `issue_blocked.go`, `issue_recheck_soak.go`) | scheduler intake | clarity/prior-art/triage questions, `blocked` labels | issues admitted by the issue filter | `gate_comment` → L5 + label; items carrying the intake label are opted in | diff --git a/src/pkg/config/adoption_close_first_test.go b/src/pkg/config/adoption_close_first_test.go index 89fb4802dc..9db2245bb2 100644 --- a/src/pkg/config/adoption_close_first_test.go +++ b/src/pkg/config/adoption_close_first_test.go @@ -27,3 +27,27 @@ func TestStageAdoptionSupersedeCloseFirst(t *testing.T) { } } } + +// governor.labels.stage.adoption.close_superseded (hivecommons/hive#15586): +// on_adopt by default; on_merge keeps an agent-authored original open until +// the copy merges; unknown or oddly-cased values read as the default. +func TestStageAdoptionCloseSuperseded(t *testing.T) { + if got := (StageAdoptionConfig{}).EffectiveCloseSuperseded(); got != AdoptionCloseSupersededOnAdopt { + t.Fatalf("close_superseded default = %q, want %q", got, AdoptionCloseSupersededOnAdopt) + } + for in, want := range map[string]string{ + "{}\n": AdoptionCloseSupersededOnAdopt, + "close_superseded: on_adopt\n": AdoptionCloseSupersededOnAdopt, + "close_superseded: ' On_Merge '\n": AdoptionCloseSupersededOnMerge, + "close_superseded: on_merge\n": AdoptionCloseSupersededOnMerge, + "close_superseded: whenever\n": AdoptionCloseSupersededOnAdopt, + } { + var cfg StageAdoptionConfig + if err := yaml.NewDecoder(strings.NewReader(in)).Decode(&cfg); err != nil { + t.Fatalf("%q: %v", in, err) + } + if got := cfg.EffectiveCloseSuperseded(); got != want { + t.Errorf("%q: EffectiveCloseSuperseded = %q, want %q", in, got, want) + } + } +} diff --git a/src/pkg/config/config.go b/src/pkg/config/config.go index 3a19be1bf2..026fe86b08 100644 --- a/src/pkg/config/config.go +++ b/src/pkg/config/config.go @@ -2928,11 +2928,46 @@ type StageAdoptionConfig struct { // AdoptionMaintainerPolicyNever is the pre-#14524 rule: the hive never // takes a maintainer's PR over and releases any adoption of one. MaintainerPolicy string `yaml:"maintainer_policy,omitempty"` + // CloseSuperseded says when a supersede adoption closes a clanker- or + // hive-authored original once the hive's copy carries its commits + // (hivecommons/hive#15526 sat open as "Adopted → #15574 · superseded" + // because the write-back gate wanted a repo opt-in label the + // contributor_adopt kind requires on items the hive did not author): + // AdoptionCloseSupersededOnAdopt (default) closes it in the adopting + // pass by policy — an agent's PR the hive re-authored is one logical PR, + // so no opt-in label is asked for; AdoptionCloseSupersededOnMerge keeps + // it open until the copy merges. Human-authored originals are not + // governed here: they close in the adopting pass only when they carry + // a writeback opt-in label (writeback.kinds.contributor_adopt), else + // when the copy merges. + CloseSuperseded string `yaml:"close_superseded,omitempty"` // Supersede tunes supersede-mode adoption (the hive-authored copy from // hive/adopt-). Supersede StageAdoptionSupersedeConfig `yaml:"supersede,omitempty"` } +// Values for governor.labels.stage.adoption.close_superseded. +const ( + AdoptionCloseSupersededOnAdopt = "on_adopt" + AdoptionCloseSupersededOnMerge = "on_merge" + DefaultAdoptionCloseSuperseded = AdoptionCloseSupersededOnAdopt +) + +// AdoptionCloseSupersededValues lists the accepted close_superseded values. +var AdoptionCloseSupersededValues = []string{AdoptionCloseSupersededOnAdopt, AdoptionCloseSupersededOnMerge} + +// EffectiveCloseSuperseded normalises CloseSuperseded; empty or unknown +// reads as the default (on_adopt). +func (c StageAdoptionConfig) EffectiveCloseSuperseded() string { + v := strings.ToLower(strings.TrimSpace(c.CloseSuperseded)) + for _, p := range AdoptionCloseSupersededValues { + if v == p { + return p + } + } + return DefaultAdoptionCloseSuperseded +} + // StageAdoptionSupersedeConfig is governor.labels.stage.adoption.supersede. type StageAdoptionSupersedeConfig struct { // CloseFirst closes the original PR as soon as the hive's copy is open diff --git a/src/pkg/config/testdata/agent_runtime_golden.json b/src/pkg/config/testdata/agent_runtime_golden.json index 1dfc005a14..b464060d78 100644 --- a/src/pkg/config/testdata/agent_runtime_golden.json +++ b/src/pkg/config/testdata/agent_runtime_golden.json @@ -207,6 +207,7 @@ "StrictAttribution": null, "AutoMerge": null, "MaintainerPolicy": "", + "CloseSuperseded": "", "Supersede": { "CloseFirst": null } diff --git a/src/pkg/dashboard/api_repo_item_decision_reroute.go b/src/pkg/dashboard/api_repo_item_decision_reroute.go index 41e63c33c8..4f54a0675c 100644 --- a/src/pkg/dashboard/api_repo_item_decision_reroute.go +++ b/src/pkg/dashboard/api_repo_item_decision_reroute.go @@ -167,7 +167,7 @@ func repoItemAdoptNowResponse(repoFull string, number, superseding int) repoItem } out.Status = "adoption-forced" out.Result.Outcome = "Adoption forced: hive opens its copy on the pass now running." - out.Result.Next = "The contributor PR closes when the hive's copy merges; the author's commits and sign-off are preserved. The row updates when the pass lands." + out.Result.Next = "The contributor PR closes as superseded (an agent's PR in the adopting pass, a person's when the hive's copy merges) and leaves the list; the author's commits and sign-off are preserved. The row updates when the pass lands." return out } diff --git a/src/pkg/dashboard/stage_tracker.go b/src/pkg/dashboard/stage_tracker.go index 1697897eab..97898e930e 100644 --- a/src/pkg/dashboard/stage_tracker.go +++ b/src/pkg/dashboard/stage_tracker.go @@ -460,6 +460,14 @@ type StageTrackerItem struct { // "copy-failed" — a close-first copy failed and the original was // reopened for a person (hivecommons/hive#15135). AdoptedByState string `json:"adopted_by_state,omitempty"` + // SupersededBy is, on an adopted original still open while the hive's + // copy is live (AdoptedBy with no failed / closed state), that copy: + // the SPA folds such a row into the copy's "adopted from" chip instead + // of listing it — a superseded PR is closed and not listed, never a + // second row for one logical PR (hivecommons/hive#15526 under #15511 + // read as two PRs). 0 when the copy is gone and the original is live + // work again. + SupersededBy int `json:"superseded_by,omitempty"` // Supersedes names the closed original this PR replaced (the hive's // close-first supersession, hivecommons/hive#15135). The original is // closed, unmerged, and never a tracker row; this is the only trace of @@ -641,9 +649,11 @@ type StageTrackerLinkedPR struct { Lineage *StageTrackerLineage `json:"lineage,omitempty"` // State is "closed" for an adopted original the hive (or a person) // closed once its copy existed (hivecommons/hive#15126): the sub-row - // is one dimmed line "#N · closed · superseded by #M" with no - // chevron track. SupersededBy is the copy; Title is cached from the - // copy (same commits, same title), never fetched live. + // is one muted line "#N <title> superseded · closed · hive adopted → + // #M" with no chevron track, listed only while the copy is listed open + // (hivecommons/hive#15511). SupersededBy is the copy (set on an open + // original too, once the copy exists); Title is cached from the copy + // (same commits, same title), never fetched live. State string `json:"state,omitempty"` SupersededBy int `json:"superseded_by,omitempty"` // Hold mirrors the nested PR's own row field (hivecommons/hive#15020). @@ -1938,6 +1948,21 @@ func stageTrackerAdoptedByState(rec stagelabels.Record) string { return "" } +// stageTrackerSupersededBy is the live copy that supersedes an adopted +// original, 0 when the adoption was in place or the copy is closed, failed +// or being replaced (then the original is live work again). A copy still +// resolving conflicts is live: the pair stays one logical PR. +func stageTrackerSupersededBy(rec stagelabels.Record) int { + if rec.AdoptedBy <= 0 || rec.AdoptMode == stagelabels.AdoptModeInPlace { + return 0 + } + switch stageTrackerAdoptedByState(rec) { + case "", stageTrackerAdoptedResolving: + return rec.AdoptedBy + } + return 0 +} + // stageTrackerAdoptionLoopCaption is the 085 caption for the loop guard. func stageTrackerAdoptionLoopCaption(rec stagelabels.Record) string { return "The hive's copies of this PR (last #" + strconv.Itoa(rec.AdoptedBy) + ") were closed without merging twice within an hour; the hive stopped opening copies and a person must decide" @@ -2083,6 +2108,7 @@ func (s *Server) buildStageTracker(status *StatusPayload, store *stagelabels.Sto } it.AdoptedBy = rec.AdoptedBy it.AdoptedByState = stageTrackerAdoptedByState(rec) + it.SupersededBy = stageTrackerSupersededBy(rec) it.SoakRemainingSeconds = int64(stageTrackerSoakRemaining(rec, now) / time.Second) it.AdmittedBy = rec.Admission(it.Head) if total, unsigned, ok := rec.DCOFor(it.Head); ok { @@ -3155,7 +3181,7 @@ func stageTrackerResolveLinkedPRs(items []StageTrackerItem, open func(repo strin } seen[lp.Number] = true pr := prs[it.Repo+"#"+strconv.Itoa(lp.Number)] - if pr == nil && (open == nil || !open(it.Repo, lp.Number)) { + if pr == nil && (open == nil || !open(it.Repo, lp.Number)) && !stageTrackerClosedOriginalListed(it, lp, prs) { return } if pr != nil { @@ -3180,6 +3206,9 @@ func stageTrackerResolveLinkedPRs(items []StageTrackerItem, open func(repo strin lp.LastOperatorAction, lp.OperatorActionCount = pr.LastOperatorAction, pr.OperatorActionCount lp.Decided, lp.AdoptedFrom = pr.Decided, pr.AdoptedFrom lp.AdoptedBy, lp.AdoptedByState = pr.AdoptedBy, pr.AdoptedByState + if lp.SupersededBy == 0 { + lp.SupersededBy = pr.SupersededBy + } lp.Hold = pr.Hold if len(pr.Modifiers) > 0 { lp.Modifiers = append([]string(nil), pr.Modifiers...) @@ -3285,6 +3314,15 @@ func stageTrackerLinkedPRProgress(it *StageTrackerItem) { it.Actor = "its PR" } +// stageTrackerClosedOriginalListed keeps a closed adopted original in its +// issue's list while the hive copy that superseded it is itself listed +// open there: it draws as one muted "superseded · closed · hive adopted → +// #M" line (hivecommons/hive#15511). Once the copy merges or closes the +// original leaves with it. +func stageTrackerClosedOriginalListed(issue *StageTrackerItem, lp StageTrackerLinkedPR, prs map[string]*StageTrackerItem) bool { + return lp.State == "closed" && lp.SupersededBy > 0 && prs[issue.Repo+"#"+strconv.Itoa(lp.SupersededBy)] != nil +} + // stageTrackerLinkedPRSupersededByListed reports whether lp is the // original of an adoption pair whose hive copy is itself listed open under // the same issue (or a closed original the copy replaced): the pair is one diff --git a/src/pkg/dashboard/stage_tracker_adoption_close_first_test.go b/src/pkg/dashboard/stage_tracker_adoption_close_first_test.go index 207125f35c..71dad03c45 100644 --- a/src/pkg/dashboard/stage_tracker_adoption_close_first_test.go +++ b/src/pkg/dashboard/stage_tracker_adoption_close_first_test.go @@ -66,8 +66,10 @@ func TestStageTrackerCloseFirstCopyFailedSaysWhy(t *testing.T) { // A closed original (#15184, closed first when its copy #15247 opened) // must not ride under its issue as a bare sub-row with an empty ladder: // the claims index still names it "open" for a while, and the status -// enumeration's bucket reason still names it. The live copy keeps the -// trace as `supersedes` metadata only (hivecommons/hive#15135 follow-up). +// enumeration's bucket reason still names it. It rides as the muted +// "superseded · closed · hive adopted → #15247" line while the copy is +// open (hivecommons/hive#15511), and the live copy keeps the trace as +// `supersedes` metadata (hivecommons/hive#15135 follow-up). func TestStageTrackerClosedSupersededPRNotASubRow(t *testing.T) { now := time.Date(2026, 10, 29, 2, 30, 0, 0, time.UTC) s := newTestServer() @@ -100,8 +102,11 @@ func TestStageTrackerClosedSupersededPRNotASubRow(t *testing.T) { } } issue := trackerItem(t, resp, "issue", 15183) - if len(issue.LinkedPRs) != 1 || issue.LinkedPRs[0].Number != 15247 { - t.Fatalf("issue 15183 linked_prs = %+v (want only the live copy #15247)", issue.LinkedPRs) + if len(issue.LinkedPRs) != 2 || issue.LinkedPRs[0].Number != 15247 || issue.LinkedPRs[1].Number != 15184 { + t.Fatalf("issue 15183 linked_prs = %+v (want the live copy #15247 and the muted closed original)", issue.LinkedPRs) + } + if c := issue.LinkedPRs[1]; c.State != "closed" || c.SupersededBy != 15247 || c.Caption != "superseded · closed · hive adopted → #15247" || c.Title == "" || c.Stage != 0 { + t.Fatalf("closed original must be the muted line, never a bare numbered row: %+v", c) } lp := issue.LinkedPRs[0] if lp.Stage != 70 || lp.Title == "" { diff --git a/src/pkg/dashboard/stage_tracker_attention_order_test.go b/src/pkg/dashboard/stage_tracker_attention_order_test.go index 05d45d4fd6..5738eae1dc 100644 --- a/src/pkg/dashboard/stage_tracker_attention_order_test.go +++ b/src/pkg/dashboard/stage_tracker_attention_order_test.go @@ -115,6 +115,9 @@ func TestStageTrackerAttentionOrderJS(t *testing.T) { "var _stageTrackerFilter = stageTrackerDefaultFilter();", jsFunc(t, html, "stageTrackerAnchor"), jsFunc(t, html, "stageTrackerLinkedDrawnHere"), + jsFunc(t, html, "stageTrackerLinkedSuperseder"), + jsFunc(t, html, "stageTrackerLinkedSupersededGone"), + jsFunc(t, html, "stageTrackerLinkedSupersededTip"), jsFunc(t, html, "stageTrackerLinkedSorted"), jsFunc(t, html, "stageTrackerSortKey"), jsFunc(t, html, "stageTrackerRegressionHandled"), diff --git a/src/pkg/dashboard/stage_tracker_decided.go b/src/pkg/dashboard/stage_tracker_decided.go index fcb7ce50d9..32b7d1b0ba 100644 --- a/src/pkg/dashboard/stage_tracker_decided.go +++ b/src/pkg/dashboard/stage_tracker_decided.go @@ -91,7 +91,12 @@ type StageTrackerAdoptedFrom struct { DecidedAt *time.Time `json:"decided_at,omitempty"` DecidedAction string `json:"decided_action,omitempty"` Verdict string `json:"verdict,omitempty"` - Text string `json:"text"` + // State is the original's state: "open" (still open; closes when the + // copy merges) or "closed" (closed as superseded). The chip's hover + // says which, since the original is not listed as a row of its own + // (hivecommons/hive#15526). + State string `json:"state,omitempty"` + Text string `json:"text"` } const ( @@ -163,7 +168,7 @@ func stageTrackerDecided(it StageTrackerItem, sweep automerge.SweepState, now ti switch { case it.AdoptedBy > 0 && verdict == string(delegatedecision.VerdictAdoptSupersede): d.Effect, d.SupersededBy = decidedEffectLanded, it.AdoptedBy - d.Text = "Adopted → #" + strconv.Itoa(it.AdoptedBy) + " · superseded (hive re-authored with sign-off)" + d.Text = stageTrackerSupersededNote(it.AdoptedBy, false) case moved || a.State == operatorActionStateAddressed: d.Effect = decidedEffectLanded case !a.At.IsZero() && now.Sub(a.At) >= timeout: @@ -306,8 +311,10 @@ func (s *Server) applyDecidedProjection(items []StageTrackerItem, now time.Time) pr := prs[it.Repo+"#"+strconv.Itoa(it.LinkedPR)] if pr == nil { s.stageTrackerClosedOriginal(it, prs, store) + stageTrackerListClosedOriginals(it, prs) continue } + stageTrackerListClosedOriginals(it, prs) if copy := prs[it.Repo+"#"+strconv.Itoa(pr.AdoptedBy)]; pr.AdoptedBy > 0 && copy != nil { stageTrackerFollowAdoption(it, pr, copy) continue @@ -354,7 +361,7 @@ func stageTrackerFollowAdoption(issue, orig, copy *StageTrackerItem) { // stageTrackerAdoptedFrom builds the copy's adopted_from from the original // PR and its recorded decision. func stageTrackerAdoptedFrom(orig *StageTrackerItem, now time.Time) *StageTrackerAdoptedFrom { - af := &StageTrackerAdoptedFrom{Number: orig.Number, URL: orig.URL, Author: orig.Author} + af := &StageTrackerAdoptedFrom{Number: orig.Number, URL: orig.URL, Author: orig.Author, State: lineageFromStateOpen} text := "↳ adopted from #" + strconv.Itoa(orig.Number) if a := orig.LastOperatorAction; a != nil && stageTrackerDecidedVerdict(a) != "" { t := a.At @@ -391,18 +398,64 @@ func (s *Server) stageTrackerClosedOriginal(issue *StageTrackerItem, prs map[str return } orig := StageTrackerLinkedPR{Number: issue.LinkedPR, State: "closed", SupersededBy: copy.Number, Title: copy.Title, - Caption: "closed · superseded by #" + strconv.Itoa(copy.Number)} + Caption: stageTrackerSupersededNote(copy.Number, true)} if a := s.stageTrackerLatestDecision(issue.Repo, issue.LinkedPR); a != nil { orig.LastOperatorAction = a copy.AdoptedFrom = stageTrackerAdoptedFrom(&StageTrackerItem{Number: issue.LinkedPR, LastOperatorAction: a}, time.Time{}) } else if copy.AdoptedFrom == nil { copy.AdoptedFrom = &StageTrackerAdoptedFrom{Number: issue.LinkedPR, Text: "↳ adopted from #" + strconv.Itoa(issue.LinkedPR)} } + copy.AdoptedFrom.State = lineageFromStateClosed stageTrackerFollowAdoption(issue, &StageTrackerItem{Number: issue.LinkedPR}, copy) issue.LinkedPRs = slices.DeleteFunc(issue.LinkedPRs, func(lp StageTrackerLinkedPR) bool { return lp.Number == orig.Number }) issue.LinkedPRs = append(issue.LinkedPRs, orig) } +// stageTrackerSupersededNote is the muted sub-row's trailing note for an +// adopted original (owner, hivecommons/hive#15511: one short line, +// "superseded · hive adopted → #15574"; "superseded · closed · hive adopted +// → #15574" once the close landed — the "re-authored with sign-off" part +// lives in the hover). +func stageTrackerSupersededNote(copy int, closed bool) string { + if closed { + return "superseded · closed · hive adopted → #" + strconv.Itoa(copy) + } + return "superseded · hive adopted → #" + strconv.Itoa(copy) +} + +// stageTrackerListClosedOriginals lists, under an issue, the closed +// original of every hive copy the issue carries (the copy's lineage names +// it: from_number, from_state closed), as a muted "superseded · closed · +// hive adopted → #M" line. Closed PRs are not in the open-PR projection, so +// without this the original vanished the moment the close-first close +// landed; the owner wants it visible in that muted form while its +// superseder is open (hivecommons/hive#15511). A copy that merged or closed +// is not listed, so its original goes with it. +func stageTrackerListClosedOriginals(issue *StageTrackerItem, prs map[string]*StageTrackerItem) { + for _, lp := range slices.Clone(issue.LinkedPRs) { + copy := prs[issue.Repo+"#"+strconv.Itoa(lp.Number)] + if copy == nil || copy.Lineage == nil || copy.Lineage.Kind != lineageAdopted || copy.Lineage.FromState != lineageFromStateClosed || copy.Lineage.FromNumber <= 0 { + continue + } + n := copy.Lineage.FromNumber + if n == issue.LinkedPR || prs[issue.Repo+"#"+strconv.Itoa(n)] != nil { + continue + } + closed := StageTrackerLinkedPR{Number: n, URL: copy.Lineage.FromURL, State: "closed", SupersededBy: copy.Number, + Title: copy.Title, Author: copy.Lineage.FromAuthor, AuthorKind: copy.Lineage.FromAuthorKind, Caption: stageTrackerSupersededNote(copy.Number, true)} + // The claims index may still list the original as open for a while + // after the close: that bare entry becomes the muted line. + if k := slices.IndexFunc(issue.LinkedPRs, func(x StageTrackerLinkedPR) bool { return x.Number == n }); k >= 0 { + if issue.LinkedPRs[k].URL != "" { + closed.URL = issue.LinkedPRs[k].URL + } + issue.LinkedPRs[k] = closed + continue + } + issue.LinkedPRs = append(issue.LinkedPRs, closed) + } +} + // stageTrackerLatestDecision reads the ledger for the newest decision // recorded on repo#number, or nil. func (s *Server) stageTrackerLatestDecision(repo string, number int) *StageTrackerOperatorAction { diff --git a/src/pkg/dashboard/stage_tracker_decided_test.go b/src/pkg/dashboard/stage_tracker_decided_test.go index 3bcbfe1047..f7c2471d9c 100644 --- a/src/pkg/dashboard/stage_tracker_decided_test.go +++ b/src/pkg/dashboard/stage_tracker_decided_test.go @@ -80,7 +80,7 @@ func TestStageTrackerDecidedProjection(t *testing.T) { if o.Decided == nil || o.Decided.Effect != decidedEffectLanded || o.Decided.SupersededBy != 15123 || o.Stage != stagelabels.AdoptedByHive.Number() { t.Fatalf("original: %+v", o.Decided) } - if !strings.HasPrefix(o.Decided.Text, "Adopted → #15123 · superseded") { + if o.Decided.Text != "superseded · hive adopted → #15123" { t.Fatalf("original text %q", o.Decided.Text) } if c.AdoptedFrom == nil || c.AdoptedFrom.Number != 15029 || c.AdoptedFrom.DecidedBy != "clubanderson" || c.AdoptedFrom.Text != "↳ adopted from #15029 · you let hive decide 17:51 UTC" { @@ -113,7 +113,7 @@ func TestStageTrackerDecidedProjection(t *testing.T) { t.Fatalf("linked_prs = %+v", is.LinkedPRs) } orig := is.LinkedPRs[0] - if orig.Number != 15029 || orig.State != "closed" || orig.SupersededBy != 15123 || orig.Title != "fix: decided state" || orig.Caption != "closed · superseded by #15123" { + if orig.Number != 15029 || orig.State != "closed" || orig.SupersededBy != 15123 || orig.Title != "fix: decided state" || orig.Caption != "superseded · closed · hive adopted → #15123" { t.Fatalf("closed original = %+v", orig) } if c.AdoptedFrom == nil || c.AdoptedFrom.Number != 15029 { diff --git a/src/pkg/dashboard/stage_tracker_decided_ui_test.go b/src/pkg/dashboard/stage_tracker_decided_ui_test.go index 90e4df91c9..e13bde72ad 100644 --- a/src/pkg/dashboard/stage_tracker_decided_ui_test.go +++ b/src/pkg/dashboard/stage_tracker_decided_ui_test.go @@ -34,6 +34,8 @@ func stageTrackerDecidedUIJS(t *testing.T, html string) string { jsFunc(t, html, "stageTrackerDecidedActing"), jsFunc(t, html, "stageTrackerDecidedLead"), jsFunc(t, html, "stageTrackerLinkedSupersededText"), + jsFunc(t, html, "stageTrackerLinkedSupersededTip"), + jsFunc(t, html, "stageTrackerSupersededOriginalClause"), jsFunc(t, html, "stageTrackerAdoptedFromChipHtml"), // Pending entries as stageTrackerRowDeciding reads them. "var _stageTrackerPending = [];", @@ -165,59 +167,103 @@ for (const a of ['adopted', 'directed', 'closed', 'merged', 'queued-for-merge', } // ── 3. landed: the adoption pair ──────────────────────────────────────── -// The original is dimmed "Adopted → #15123 · superseded (hive re-authored -// with sign-off)" with no chevron track, no row tools and no needs-human -// styling; the copy carries the single active chevron and the chip -// "↳ adopted from #15029 · you let hive decide 11:57 UTC"; the issue row's -// pill follows the copy. +// The superseded original stays listed under the issue as one muted, +// chevron-less sub-row (owner likes the look, hivecommons/hive#15511) whose +// trailing note is short and never wraps: "superseded · hive adopted → +// #15123" — the "re-authored with sign-off" part moved into the hover. The +// copy carries the single active chevron and its "↳ adopted from #15029 · +// you let hive decide 11:57 UTC" chip; the issue row's pill follows the copy. { const landed = Object.assign({}, decidedPending, { effect: 'landed', superseded_by: 15123, next_at: undefined }); - const orig = original({ stage: 74, modifiers: [], manual_merge: false, human_merge_reason_text: '', adopted_by: 15123, adopted_by_state: 'open', decided: landed, last_operator_action: Object.assign({}, acted, { state: 'addressed' }), operator_action_count: 1 }); - const copy = { number: 15123, title: 'fix: tracker pill', url: 'u123', stage: 50, author: 'hivecommons-hive[bot]', author_kind: 'hive', modifiers: [], adopted_from: { number: 15029, url: 'u29', author: 'Karibhou', decided_by: 'clubanderson', decided_at: at, decided_action: 'let-hive-decide', verdict: 'adopt-supersede', text: '↳ adopted from #15029 · you let hive decide 11:57 UTC' } }; + const orig = original({ stage: 74, modifiers: [], manual_merge: false, human_merge_reason_text: '', adopted_by: 15123, adopted_by_state: 'open', superseded_by: 15123, decided: landed, last_operator_action: Object.assign({}, acted, { state: 'addressed' }), operator_action_count: 1 }); + const copy = { number: 15123, title: 'fix: tracker pill', url: 'u123', stage: 50, author: 'hivecommons-hive[bot]', author_kind: 'hive', modifiers: [], adopted_from: { number: 15029, url: 'u29', author: 'Karibhou', state: 'open', decided_by: 'clubanderson', decided_at: at, decided_action: 'let-hive-decide', verdict: 'adopt-supersede', text: '↳ adopted from #15029 · you let hive decide 11:57 UTC' } }; const issue = issueOf([orig, copy], { stage: 50 }); const row = stageTrackerRowHtml(issue, stages, ctx); - assert.strictEqual(subs(row).length, 1, 'one full sub-row: the copy; the original is a dimmed line'); - const dim = (/<div class="ham-sub ham-sub-superseded"[\s\S]*?<\/div>\s*<\/div>/.exec(row) || [''])[0]; - assert.ok(dim, 'the original renders as a superseded line: ' + row); + // subs() counts full sub-rows only; the muted line is a "ham-sub ham-sub-superseded". + const parts = (r) => r.split('<div class="ham-sub').slice(1); + const part = (r, n) => parts(r).find(s => s.includes('pr#' + n + '"')) || ''; + assert.deepStrictEqual(parts(row).map(s => (/pr#(\d+)"/.exec(s) || [])[1]), ['15029', '15123'], 'two sub-rows, the original muted: ' + row); + assert.strictEqual(subs(row).length, 1, 'one full sub-row: the copy'); + const dim = part(row, 15029); + assert.ok(dim.startsWith(' ham-sub-superseded"'), 'the original is the muted line: ' + dim); assert.ok(dim.includes('data-ham-superseded-by="15123"')); - assert.ok(text(dim).includes('#15029') && text(dim).includes('Adopted → #15123 · superseded (hive re-authored with sign-off)'), text(dim)); - assert.ok(!dim.includes('aria-label="Pipeline progress"') && !dim.includes('ham-seg active'), 'no chevron track on the superseded original'); - assert.ok(!dim.includes('ham-row-tools') && !dim.includes('needs-human') && !dim.includes('Ready for human merge'), 'no action chevron, no needs-human styling'); - const sub = subHtml(row, 15123); - assert.ok(sub.includes('aria-current="step"'), 'the copy carries the active chevron'); - assert.ok(sub.includes('class="ham-badge ham-adopted-from"') && /↳ adopted from #15029 · you let hive decide 11:57( AM)? UTC/.test(text(sub)), 'the adopted-from chip: ' + text(sub)); - assert.ok(!text(sub).includes('untrusted author'), 'the copy is hive-authored'); - // With several PRs the issue strip ends at Claimed, unlit: the copy's - // chevron is the row's single active one; the original has none. + const note = (/<span class="ham-superseded-note"[^>]*>([^<]*)<\/span>/.exec(dim) || [])[1] || ''; + assert.strictEqual(note, 'superseded · hive adopted → #15123', 'the note is short, one line, no parenthetical: ' + note); + assert.ok(!note.includes('re-authored') && !note.includes('(') && !text(dim).includes('(hive re-authored'), 'no parenthetical in the row: ' + text(dim)); + const noteTip = (/<span class="ham-superseded-note" title="([^"]*)"/.exec(dim) || [])[1] || ''; + assert.strictEqual(noteTip, 'Hive re-authored this PR as #15123 with the same commits and sign-off. This PR closes as superseded when #15123 merges.', noteTip); + assert.ok(!dim.includes('aria-label="Pipeline progress"') && !dim.includes('aria-current="step"'), 'no chevron track on the muted line'); + assert.ok(!dim.includes('ham-kebab') && !dim.includes('ham-sel'), 'no row tools on the muted line'); + assert.ok(text(dim).includes('#15029') && text(dim).includes('fix: tracker pill'), 'greyed title stays: ' + text(dim)); + const cp = part(row, 15123); + assert.ok(cp.includes('aria-current="step"'), 'the copy carries the active chevron'); + assert.ok(cp.includes('class="ham-badge ham-adopted-from"') && /↳ adopted from #15029 · you let hive decide 11:57( AM)? UTC/.test(text(cp)), 'the adopted-from chip on the copy: ' + text(cp)); + const chipTip = (/class="ham-badge ham-adopted-from"[^>]*title="([^"]*)"/.exec(cp) || [])[1] || ''; + assert.ok(chipTip.includes('#15029 is superseded and still open; it closes when this merges.'), 'the chip tooltip names the superseded state: ' + chipTip); + assert.ok(!text(cp).includes('untrusted author'), 'the copy is hive-authored'); assert.strictEqual((row.match(/aria-current="step"/g) || []).length, 1, 'exactly one active chevron: the copy'); - assert.ok(pill(sub).includes('CI / Review'), 'the active pill follows the copy: ' + pill(sub)); + assert.ok(pill(row).includes('CI / Review'), 'the active pill follows the copy: ' + pill(row)); assert.ok(!/Approving/.test(row)); + // The same muted line without superseded_by (an older payload): adopted_by + // with a live copy in the list is enough. + const legacy = stageTrackerRowHtml(issueOf([original({ stage: 74, modifiers: [], manual_merge: false, human_merge_reason_text: '', adopted_by: 15123, adopted_by_state: 'open' }), copy], { stage: 50 }), stages, ctx); + assert.ok(part(legacy, 15029).startsWith(' ham-sub-superseded"') && text(part(legacy, 15029)).includes('superseded · hive adopted → #15123'), 'legacy payload: ' + text(legacy)); + // A copy that was closed (recovering): the original is a live PR again + // — a full sub-row with a chevron, no muted line. + const recovering = issueOf([original({ stage: 85, modifiers: [], adopted_by: 15123, adopted_by_state: 'closed', superseded_by: 0 }), Object.assign({}, copy, { state: 'closed' })], { stage: 85 }); + assert.strictEqual(stageTrackerLinkedSuperseder(recovering.linked_prs[0], recovering), 0, 'a closed copy never supersedes its original'); + const rrow = stageTrackerRowHtml(recovering, stages, ctx); + assert.ok(!rrow.includes('ham-sub-superseded') && rrow.includes('aria-label="Pipeline progress"'), 'recovering: the original is a live row: ' + rrow); } // ── 4. closed original ────────────────────────────────────────────────── -// A closed-superseded original (closed PRs drop out of the open-PR -// projection; only the back-link remains) is one dimmed line with the -// cached title: "#15029 fix: tracker pill · closed · superseded by #15123". +// Once the close-first close landed the original is still listed, in the +// same muted form, while its superseder is open: the note becomes +// "superseded · closed · hive adopted → #15123". With the copy gone from +// the list (merged, closed) the closed original goes with it. { - const closed = { number: 15029, title: 'fix: tracker pill', url: 'u29', stage: 74, state: 'closed', superseded_by: 15123, adopted_by: 15123, adopted_by_state: 'open', caption: 'closed · superseded by #15123', modifiers: [] }; - const copy = { number: 15123, title: 'fix: tracker pill', url: 'u123', stage: 50, author: 'hivecommons-hive[bot]', author_kind: 'hive', modifiers: [], adopted_from: { number: 15029, url: 'u29', author: 'Karibhou', text: '↳ adopted from #15029' } }; + const closed = { number: 15029, title: 'fix: tracker pill', url: 'u29', stage: 74, state: 'closed', superseded_by: 15123, adopted_by: 15123, adopted_by_state: 'open', caption: 'superseded · closed · hive adopted → #15123', modifiers: [] }; + const copy = { number: 15123, title: 'fix: tracker pill', url: 'u123', stage: 50, author: 'hivecommons-hive[bot]', author_kind: 'hive', modifiers: [], adopted_from: { number: 15029, url: 'u29', author: 'Karibhou', state: 'closed', text: '↳ adopted from #15029' } }; const row = stageTrackerRowHtml(issueOf([closed, copy], { stage: 50 }), stages, ctx); - const dim = (/<div class="ham-sub ham-sub-superseded"[\s\S]*?<\/div>\s*<\/div>/.exec(row) || [''])[0]; - assert.ok(dim, 'the closed original renders as a line, not a bare number: ' + row); - assert.ok(text(dim).includes('#15029 fix: tracker pill') || (text(dim).includes('#15029') && text(dim).includes('fix: tracker pill')), 'cached title, no live fetch: ' + text(dim)); - assert.ok(text(dim).includes('closed · superseded by #15123'), text(dim)); + const parts = (r) => r.split('<div class="ham-sub').slice(1); + const part = (r, n) => parts(r).find(s => s.includes('pr#' + n + '"')) || ''; + const dim = part(row, 15029); + assert.ok(dim.startsWith(' ham-sub-superseded"'), 'the closed original renders as a muted line: ' + row); + assert.strictEqual(subs(row).length, 1, 'one full sub-row: the copy'); + const note = (/<span class="ham-superseded-note"[^>]*>([^<]*)<\/span>/.exec(dim) || [])[1] || ''; + assert.strictEqual(note, 'superseded · closed · hive adopted → #15123', note); + assert.ok(text(dim).includes('#15029') && text(dim).includes('fix: tracker pill'), 'cached title, no live fetch: ' + text(dim)); assert.ok(!dim.includes('aria-label="Pipeline progress"'), 'no hollow chevrons'); + const noteTip = (/<span class="ham-superseded-note" title="([^"]*)"/.exec(dim) || [])[1] || ''; + assert.ok(noteTip.includes('This PR is closed as superseded.'), noteTip); + const chipTip = (/class="ham-badge ham-adopted-from"[^>]*title="([^"]*)"/.exec(part(row, 15123)) || [])[1] || ''; + assert.ok(chipTip.includes('#15029 is closed as superseded.'), 'the chip tooltip says closed: ' + chipTip); assert.ok(!stageTrackerLinkedPROpen(stageTrackerLinkedPRItem(issueOf([closed]), closed)), 'a closed PR is not an open linked PR'); - assert.strictEqual(subs(row).length, 1, 'only the copy is a full sub-row'); // The issue row never shows a blank numbered sub-row. for (const s of row.split('<div class="ham-sub').slice(1)) assert.ok(text(s).replace(/^#\d+\s*$/, '') !== '', 'never a blank numbered row: ' + text(s)); + // Copy not listed (merged / closed): the closed original is not drawn. + assert.ok(stageTrackerLinkedSupersededGone(closed, issueOf([closed])), 'no superseder listed: gone'); + assert.ok(stageTrackerLinkedSupersededGone(closed, issueOf([closed, Object.assign({}, copy, { state: 'closed' })])), 'closed superseder: gone'); + assert.deepStrictEqual(stageTrackerLinkedSorted(issueOf([closed, copy], { stage: 50 }), stages).map(lp => lp.number), [15029, 15123]); + assert.deepStrictEqual(stageTrackerLinkedSorted(issueOf([closed], { stage: 74 }), stages).map(lp => lp.number), []); + const alone = stageTrackerRowHtml(issueOf([closed], { stage: 74 }), stages, ctx); + assert.ok(!alone.includes('<span class="ham-pr-num">#15029</span>'), 'the orphaned closed original is not drawn: ' + text(alone)); } // ── 5. superseded text is pure and conservative ───────────────────────── -assert.strictEqual(stageTrackerLinkedSupersededText({ state: 'closed', superseded_by: 9 }, null), 'closed · superseded by #9'); -assert.strictEqual(stageTrackerLinkedSupersededText({ adopted_by: 9, adopted_by_state: 'open' }, { linked_prs: [{ number: 9 }] }), 'Adopted → #9 · superseded (hive re-authored with sign-off)'); -assert.strictEqual(stageTrackerLinkedSupersededText({ adopted_by: 9, adopted_by_state: 'open' }, { linked_prs: [{ number: 8 }] }), '', 'the copy must be in the list before the original dims'); +assert.strictEqual(stageTrackerLinkedSupersededText({ state: 'closed', superseded_by: 9 }, { linked_prs: [{ number: 9 }] }), 'superseded · closed · hive adopted → #9'); +assert.strictEqual(stageTrackerLinkedSupersededText({ state: 'closed', superseded_by: 9 }, null), '', 'a closed original without its copy listed says nothing'); +assert.strictEqual(stageTrackerLinkedSupersededText({ adopted_by: 9, adopted_by_state: 'open' }, { linked_prs: [{ number: 9 }] }), 'superseded · hive adopted → #9'); +assert.strictEqual(stageTrackerLinkedSupersededText({ superseded_by: 9 }, { linked_prs: [{ number: 9 }] }), 'superseded · hive adopted → #9'); +assert.strictEqual(stageTrackerLinkedSupersededText({ adopted_by: 9, adopted_by_state: 'open' }, { linked_prs: [{ number: 8 }] }), ''); assert.strictEqual(stageTrackerLinkedSupersededText({ adopted_by: 9, adopted_by_state: 'closed' }, { linked_prs: [{ number: 9 }] }), '', 'a closed copy keeps the original live (recovering)'); +assert.strictEqual(stageTrackerLinkedSupersededText({ adopted_by: 9, adopted_by_state: 'open' }, { linked_prs: [{ number: 9, state: 'closed' }] }), '', 'a copy listed closed does not supersede'); assert.strictEqual(stageTrackerLinkedSupersededText({}, null), ''); +assert.strictEqual(stageTrackerLinkedSupersededTip({ superseded_by: 9 }), 'Hive re-authored this PR as #9 with the same commits and sign-off. This PR closes as superseded when #9 merges.'); +assert.strictEqual(stageTrackerLinkedSupersededTip({ adopted_by: 9, state: 'closed' }), 'Hive re-authored this PR as #9 with the same commits and sign-off. This PR is closed as superseded.'); +assert.strictEqual(stageTrackerSupersededOriginalClause(9, 'open'), ' #9 is superseded and still open; it closes when this merges.'); +assert.strictEqual(stageTrackerSupersededOriginalClause(9, 'closed'), ' #9 is closed as superseded.'); +assert.strictEqual(stageTrackerSupersededOriginalClause(9, ''), ''); +assert.strictEqual(stageTrackerSupersededOriginalClause(0, 'open'), ''); `) } diff --git a/src/pkg/dashboard/stage_tracker_lineage.go b/src/pkg/dashboard/stage_tracker_lineage.go index b78a939aec..f52cae4910 100644 --- a/src/pkg/dashboard/stage_tracker_lineage.go +++ b/src/pkg/dashboard/stage_tracker_lineage.go @@ -28,6 +28,12 @@ const ( lineageRebasedByHive = "rebased-by-hive" ) +// Lineage from_state values. +const ( + lineageFromStateOpen = "open" + lineageFromStateClosed = "closed" +) + // Lineage reason slugs the SPA words its hover from. const ( lineageReasonCIRedOffline = "ci-red-contributor-offline" @@ -47,6 +53,12 @@ type StageTrackerLineage struct { FromURL string `json:"from_url,omitempty"` FromAuthor string `json:"from_author,omitempty"` FromAuthorKind string `json:"from_author_kind,omitempty"` + // FromState is the original's state on the hive's copy: "closed" once + // the hive closed it as superseded, "open" while it is still open + // (it closes when the copy merges), "" when unknown. The copy's chip + // is the only place the superseded original is drawn + // (hivecommons/hive#15526), so its hover says which. + FromState string `json:"from_state,omitempty"` // ToNumber / ToURL name the hive's copy on the original. ToNumber int `json:"to_number,omitempty"` ToURL string `json:"to_url,omitempty"` @@ -132,8 +144,12 @@ func stageTrackerLineageIndex(store *stagelabels.Store, baseURL string) map[stri } } reason := stageTrackerLineageReason(rec.AdoptReason) + fromState := "" + if rec.Superseded() && !rec.SupersededOpen { + fromState = lineageFromStateClosed + } out[copyKey] = StageTrackerLineage{Kind: kind, FromNumber: number, FromURL: overviewItemURL("", repo, number, "pr", baseURL), - FromAuthor: rec.Author, FromAuthorKind: stageTrackerLineageAuthorKind(rec.AdoptReason), At: at, Reason: reason} + FromAuthor: rec.Author, FromAuthorKind: stageTrackerLineageAuthorKind(rec.AdoptReason), FromState: fromState, At: at, Reason: reason} out[key] = StageTrackerLineage{Kind: lineageSuperseded, ToNumber: by, ToURL: overviewItemURL("", repo, by, "pr", baseURL), At: at, Reason: reason} } return out @@ -163,8 +179,9 @@ func stageTrackerLineageFor(idx map[string]StageTrackerLineage, repo string, num } // stageTrackerLineageFillAuthors completes from_author / from_author_kind -// on each copy whose original is itself a row (close_first off): the -// row's own author fields beat the record's guess. +// on each copy whose original is itself a row (close_first off, or the +// write-back gate kept it open): the row's own author fields beat the +// record's guess, and from_state reads open. func stageTrackerLineageFillAuthors(items []StageTrackerItem) { prs := map[string]*StageTrackerItem{} for i := range items { @@ -187,5 +204,6 @@ func stageTrackerLineageFillAuthors(items []StageTrackerItem) { if orig.AuthorKind != "" { l.FromAuthorKind = orig.AuthorKind } + l.FromState = lineageFromStateOpen } } diff --git a/src/pkg/dashboard/stage_tracker_lineage_test.go b/src/pkg/dashboard/stage_tracker_lineage_test.go index b8d6287ea6..84441f2f6e 100644 --- a/src/pkg/dashboard/stage_tracker_lineage_test.go +++ b/src/pkg/dashboard/stage_tracker_lineage_test.go @@ -95,6 +95,7 @@ func TestStageTrackerLineageChipJS(t *testing.T) { jsFunc(t, html, "stageTrackerAgoText"), jsConstBlock(t, html, "STAGE_TRACKER_LINEAGE_REASON_TIP"), jsFunc(t, html, "stageTrackerLineageText"), + jsFunc(t, html, "stageTrackerSupersededOriginalClause"), jsFunc(t, html, "stageTrackerLineageTip"), jsFunc(t, html, "stageTrackerLineageChipHtml"), jsFunc(t, html, "stageTrackerLineageClause"), diff --git a/src/pkg/dashboard/stage_tracker_motion_test.go b/src/pkg/dashboard/stage_tracker_motion_test.go index 764fe59c71..de848662f0 100644 --- a/src/pkg/dashboard/stage_tracker_motion_test.go +++ b/src/pkg/dashboard/stage_tracker_motion_test.go @@ -271,6 +271,9 @@ func TestStageTrackerMotionDetector(t *testing.T) { jsFunc(t, html, "stageTrackerItemKey"), jsFunc(t, html, "stageTrackerPRKey"), jsFunc(t, html, "stageTrackerLinkedDrawnHere"), + jsFunc(t, html, "stageTrackerLinkedSuperseder"), + jsFunc(t, html, "stageTrackerLinkedSupersededGone"), + jsFunc(t, html, "stageTrackerLinkedSupersededTip"), jsFunc(t, html, "stageTrackerLinkedSorted"), jsConstLine(t, html, "STAGE_TRACKER_ATTENTION_STAGES"), jsConstLine(t, html, "STAGE_TRACKER_HUMAN_MODS"), @@ -456,6 +459,9 @@ func TestStageTrackerMotionRowStamp(t *testing.T) { jsFunc(t, html, "stageTrackerLinkedTip"), jsConstLine(t, html, "STAGE_TRACKER_LINKED_GLYPH"), jsFunc(t, html, "stageTrackerLinkedDrawnHere"), + jsFunc(t, html, "stageTrackerLinkedSuperseder"), + jsFunc(t, html, "stageTrackerLinkedSupersededGone"), + jsFunc(t, html, "stageTrackerLinkedSupersededTip"), jsFunc(t, html, "stageTrackerLinkedSorted"), jsFunc(t, html, "stageTrackerNeedsAttention"), stageTrackerTierJS(t, html), @@ -582,6 +588,9 @@ func TestStageTrackerMotionPreviewSample(t *testing.T) { jsFunc(t, html, "stageTrackerLinkedTip"), jsConstLine(t, html, "STAGE_TRACKER_LINKED_GLYPH"), jsFunc(t, html, "stageTrackerLinkedDrawnHere"), + jsFunc(t, html, "stageTrackerLinkedSuperseder"), + jsFunc(t, html, "stageTrackerLinkedSupersededGone"), + jsFunc(t, html, "stageTrackerLinkedSupersededTip"), jsFunc(t, html, "stageTrackerLinkedSorted"), jsFunc(t, html, "stageTrackerNeedsAttention"), stageTrackerTierJS(t, html), diff --git a/src/pkg/dashboard/stage_tracker_repo_grouping_test.go b/src/pkg/dashboard/stage_tracker_repo_grouping_test.go index 7061e1360f..9e5fe1a2be 100644 --- a/src/pkg/dashboard/stage_tracker_repo_grouping_test.go +++ b/src/pkg/dashboard/stage_tracker_repo_grouping_test.go @@ -169,6 +169,9 @@ func stageTrackerRepoGroupingHarness(t *testing.T, html string) string { jsFunc(t, html, "stageTrackerLinkedTip"), jsConstLine(t, html, "STAGE_TRACKER_LINKED_GLYPH"), jsFunc(t, html, "stageTrackerLinkedDrawnHere"), + jsFunc(t, html, "stageTrackerLinkedSuperseder"), + jsFunc(t, html, "stageTrackerLinkedSupersededGone"), + jsFunc(t, html, "stageTrackerLinkedSupersededTip"), jsFunc(t, html, "stageTrackerLinkedSorted"), stageTrackerTierJS(t, html), jsFunc(t, html, "stageTrackerSortKey"), diff --git a/src/pkg/dashboard/stage_tracker_superseded_row_test.go b/src/pkg/dashboard/stage_tracker_superseded_row_test.go new file mode 100644 index 0000000000..ea4f3e6960 --- /dev/null +++ b/src/pkg/dashboard/stage_tracker_superseded_row_test.go @@ -0,0 +1,258 @@ +package dashboard + +import ( + "encoding/json" + "strings" + "testing" + "time" + + "github.com/hivecommons/hive/pkg/config" + "github.com/hivecommons/hive/pkg/github" + "github.com/hivecommons/hive/pkg/stagelabels" +) + +// A PR superseded by a hive adoption stays listed under its issue as one +// muted, chevron-less sub-row while its superseder is open (owner, +// hivecommons/hive#15511: hive's #15574 and, beneath it, the original +// #15526 greyed). The server marks the original with `superseded_by`, the +// copy's lineage / adopted_from carry the original's state ("open" while +// it waits, "closed" once close-first ran), a closed original is listed +// under the issue only while the copy is, and the note reads "superseded · +// hive adopted → #N" / "superseded · closed · hive adopted → #N". +func supersededRowFixture(t *testing.T, now time.Time) (*Server, *stagelabels.Store, *StatusPayload, string) { + t.Helper() + s := newTestServer() + store := stagelabels.NewStore("", func() time.Time { return now }) + s.stageStore = store + s.deps = &Dependencies{Config: &config.Config{}} + orig := stagelabels.Key("hivecommons/hive", 15526) + store.Observe(orig, stagelabels.AdoptedByHive, "contributor-lane:adopted") + store.MarkAdopted(orig, "ab12cd3", 15574, now.Add(-15*time.Minute)) + store.Observe(stagelabels.Key("hivecommons/hive", 15574), stagelabels.AwaitingMergeAdmission, "merge-lane:queued") + + status := minimalPayload() + status.HiveID = "hive" + status.Repos = []FrontendRepo{{ + Name: "hive", Full: "hivecommons/hive", + ActionableIssues: []any{github.Issue{Number: 15511, Title: "Tracker lists a superseded PR", Author: "clubanderson", Labels: []string{"stage/040-covered-by-pr"}, + LinkedPRs: []github.IssueLinkedPR{ + {Number: 15526, State: "open", URL: "https://github.com/hivecommons/hive/pull/15526", Closing: true}, + {Number: 15574, State: "open", URL: "https://github.com/hivecommons/hive/pull/15574", Closing: true}, + }}}, + OpenPrs: []any{ + FrontendPR{PullRequest: github.PullRequest{Number: 15526, Title: "fix: tracker", Author: "odttlnt", HeadSHA: "ab12cd3", Labels: []string{"author/clanker", "role/contributor", "stage/074-adopted-by-hive"}, + LinkedIssues: []github.PRLinkedIssue{{Number: 15511, State: "open"}}}}, + FrontendPR{PullRequest: github.PullRequest{Number: 15574, Title: "fix: tracker", Author: "hivecommons-hive[bot]", AppAuthored: true, HeadSHA: "ef45ab6", Labels: []string{"stage/080-merge-gate"}, + LinkedIssues: []github.PRLinkedIssue{{Number: 15511, State: "open"}}}}, + }, + }} + s.UpdateStatus(status) + return s, store, status, orig +} + +func TestStageTrackerSupersededOriginalCarriesSupersededBy(t *testing.T) { + now := time.Date(2026, 10, 29, 23, 49, 0, 0, time.UTC) + s, store, status, _ := supersededRowFixture(t, now) + resp := s.buildStageTracker(status, store, now) + + orig := trackerItem(t, resp, "pr", 15526) + if orig.SupersededBy != 15574 || orig.AdoptedBy != 15574 || orig.AdoptedByState != "" { + t.Fatalf("original superseded_by=%d adopted_by=%d state=%q", orig.SupersededBy, orig.AdoptedBy, orig.AdoptedByState) + } + if orig.NestedUnder != 15511 { + t.Fatalf("original nested_under=%d", orig.NestedUnder) + } + copyPR := trackerItem(t, resp, "pr", 15574) + if copyPR.SupersededBy != 0 { + t.Fatalf("copy must never carry superseded_by: %d", copyPR.SupersededBy) + } + if copyPR.AdoptedFrom == nil || copyPR.AdoptedFrom.Number != 15526 || copyPR.AdoptedFrom.State != "open" { + t.Fatalf("copy adopted_from = %+v", copyPR.AdoptedFrom) + } + if copyPR.Lineage == nil || copyPR.Lineage.FromNumber != 15526 || copyPR.Lineage.FromState != "open" { + t.Fatalf("copy lineage = %+v", copyPR.Lineage) + } + issue := trackerItem(t, resp, "issue", 15511) + var mirrored bool + for _, lp := range issue.LinkedPRs { + if lp.Number == 15526 { + mirrored = lp.SupersededBy == 15574 + } + } + if !mirrored { + t.Fatalf("issue linked_prs do not mirror superseded_by: %+v", issue.LinkedPRs) + } + raw, err := json.Marshal(orig) + if err != nil { + t.Fatal(err) + } + if !strings.Contains(string(raw), `"superseded_by":15574`) { + t.Fatalf("payload lacks superseded_by: %s", raw) + } +} + +func TestStageTrackerSupersededByClearsWhenCopyDies(t *testing.T) { + now := time.Date(2026, 10, 29, 23, 49, 0, 0, time.UTC) + s, store, status, orig := supersededRowFixture(t, now) + store.NoteAdoptionOrphaned(orig, 15574, now) + it := trackerItem(t, s.buildStageTracker(status, store, now), "pr", 15526) + if it.SupersededBy != 0 || it.AdoptedByState != "closed" { + t.Fatalf("orphaned original must not fold: superseded_by=%d state=%q", it.SupersededBy, it.AdoptedByState) + } +} + +func TestStageTrackerSupersededByOmittedForInPlaceAdoption(t *testing.T) { + now := time.Date(2026, 10, 29, 23, 49, 0, 0, time.UTC) + s, store, status, key := orphanTrackerFixture(t, now, stagelabels.AdoptedByHive, "contributor-lane:adopted", []string{"stage/074-adopted-by-hive"}) + store.MarkAdoptedInPlace(key, "bc3a6ea", "contributor-lane:adopted-in-place", now) + it := trackerItem(t, s.buildStageTracker(status, store, now), "pr", 14947) + if it.SupersededBy != 0 { + t.Fatalf("in-place adoption has no superseder: %d", it.SupersededBy) + } +} + +func TestStageTrackerSupersededClosedOriginalListedWhileCopyOpen(t *testing.T) { + now := time.Date(2026, 10, 29, 23, 49, 0, 0, time.UTC) + s, store, status, orig := supersededRowFixture(t, now) + store.MarkSupersededClosedFirst(orig, 15574, false, now.Add(-10*time.Minute)) + // The close landed: GitHub's open-PR list no longer carries #15526. + status.Repos[0].OpenPrs = status.Repos[0].OpenPrs[1:] + s.UpdateStatus(status) + resp := s.buildStageTracker(status, store, now) + for _, it := range resp.Items { + if it.Kind == "pr" && it.Number == 15526 { + t.Fatalf("closed original rendered as a row of its own: %+v", it) + } + } + copyPR := trackerItem(t, resp, "pr", 15574) + if copyPR.Lineage == nil || copyPR.Lineage.FromNumber != 15526 || copyPR.Lineage.FromState != "closed" { + t.Fatalf("copy lineage = %+v", copyPR.Lineage) + } + if copyPR.Supersedes == nil || copyPR.Supersedes.Number != 15526 || copyPR.Supersedes.Open { + t.Fatalf("copy supersedes = %+v", copyPR.Supersedes) + } + issue := trackerItem(t, resp, "issue", 15511) + var closed *StageTrackerLinkedPR + for i := range issue.LinkedPRs { + if issue.LinkedPRs[i].Number == 15526 { + closed = &issue.LinkedPRs[i] + } + } + if closed == nil { + t.Fatalf("the closed original must stay listed under the issue while #15574 is open: %+v", issue.LinkedPRs) + } + if closed.State != "closed" || closed.SupersededBy != 15574 || closed.Caption != "superseded · closed · hive adopted → #15574" || closed.Title != "fix: tracker" || closed.AuthorKind != "clanker" { + t.Fatalf("closed original = %+v", *closed) + } +} + +func TestStageTrackerSupersededClosedOriginalLeavesWithCopy(t *testing.T) { + now := time.Date(2026, 10, 29, 23, 49, 0, 0, time.UTC) + s, store, status, orig := supersededRowFixture(t, now) + store.MarkSupersededClosedFirst(orig, 15574, false, now.Add(-10*time.Minute)) + // Both gone from GitHub's open list: the copy merged. + status.Repos[0].OpenPrs = nil + s.UpdateStatus(status) + resp := s.buildStageTracker(status, store, now) + for _, it := range resp.Items { + if it.Kind == "pr" && (it.Number == 15526 || it.Number == 15574) { + t.Fatalf("closed pair rendered: %+v", it) + } + if it.Kind == "issue" && it.Number == 15511 { + for _, lp := range it.LinkedPRs { + if lp.Number == 15526 { + t.Fatalf("closed original listed without its open superseder: %+v", it.LinkedPRs) + } + } + } + } +} + +func TestStageTrackerSupersededNoteCSSNeverWraps(t *testing.T) { + html := indexHTML(t) + rule := ".ham-superseded-note {" + i := strings.Index(html, rule) + if i < 0 { + t.Fatal("index.html lacks the .ham-superseded-note rule") + } + body := html[i : i+strings.Index(html[i:], "}")] + for _, want := range []string{"white-space: nowrap", "flex: 0 0 auto"} { + if !strings.Contains(body, want) { + t.Errorf("the superseded note must not wrap nor shrink (the title ellipsizes first): %q lacks %q", body, want) + } + } +} + +// Ratchet (SPA): a superseded original whose superseder is listed open is +// exactly one muted, chevron-less sub-row with the short note, never a +// full row of its own; a closed original leaves with its superseder. +func TestStageTrackerSupersededRowRatchetJS(t *testing.T) { + html := indexHTML(t) + runStageTrackerRowActionsScript(t, stageTrackerRowsPreludeJS(t, html)+"\n"+jsFunc(t, html, "stageTrackerLinkedSupersededText")+"\n"+jsFunc(t, html, "stageTrackerLinkedSupersededTip")+"\n"+stageTrackerRowsFixtureJS+` +const since = new Date(now - 3600000).toISOString(); +const pr = (n, extra) => Object.assign({ repo: 'hivecommons/hive', number: n, kind: 'pr', title: 'dashboard: split stage_tracker.go into 4 files, a very long title that must ellipsize before the note does', url: 'https://x/' + n, stage: 74, stage_since: since, caption: 'Adopted', author: 'odttlnt', author_kind: 'clanker', modifiers: [] }, extra || {}); +const issue = (n, prs, extra) => Object.assign({ repo: 'hivecommons/hive', number: n, kind: 'issue', title: 'Issue ' + n, url: 'https://x/i' + n, stage: 40, stage_since: since, linked_prs: prs }, extra || {}); +const copy = (n, from, extra) => pr(n, Object.assign({ author: 'hivecommons-hive[bot]', author_kind: 'hive', stage: 80, caption: 'Merge queued', adopted_from: { number: from, url: 'https://x/' + from, author: 'odttlnt', state: 'open', text: '↳ adopted from #' + from } }, extra || {})); +const noteOf = (sub) => (/<span class="ham-superseded-note"[^>]*>([^<]*)<\/span>/.exec(sub) || [])[1] || ''; +const subsOf = (row) => row.split('<div class="ham-sub').slice(1); + +// Nested: the issue lists both; the original is the muted line. +{ + const orig = pr(15526, { adopted_by: 15574, adopted_by_state: '', superseded_by: 15574, nested_under: 15511 }); + const cp = copy(15574, 15526, { nested_under: 15511 }); + const items = [issue(15511, [orig, cp]), orig, cp]; + const rows = stageTrackerVisible(items, { kind: 'all', repo: '' }); + assert.deepStrictEqual(rows.map(r => r.kind + '#' + r.number), ['issue#15511'], 'the nested pair draws under the issue only'); + assert.deepStrictEqual(stageTrackerLinkedSorted(rows[0]).map(lp => lp.number), [15574, 15526], 'the copy first, the muted original after it'); + const row = stageTrackerRowHtml(rows[0], stages, ctx); + const subs = subsOf(row); + assert.strictEqual(subs.length, 2, 'two sub-rows: ' + row); + const dim = subs.find(s => s.includes('ham-sub-superseded')) || ''; + assert.ok(dim && dim.includes('pr#15526"'), 'the original is the muted sub-row: ' + row); + assert.strictEqual(noteOf(dim), 'superseded · hive adopted → #15574'); + assert.ok(!dim.includes('aria-label="Pipeline progress"'), 'no chevron track'); + assert.ok(dim.includes('ham-pr-title'), 'the title is in its own ellipsizing span, the note is a non-shrinking sibling'); + assert.ok(/<span class="ham-superseded-note" title="Hive re-authored this PR as #15574 with the same commits and sign-off\. This PR closes as superseded when #15574 merges\."/.test(dim), 'hover carries the long form: ' + dim); + assert.strictEqual((row.match(/aria-label="Pipeline progress"/g) || []).length, 2, 'the issue strip and the copy strip only'); +} +// Closed original, copy open: the same muted line with "closed" in the note. +{ + const closed = pr(15526, { state: 'closed', superseded_by: 15574, caption: 'superseded · closed · hive adopted → #15574' }); + const cp = copy(15574, 15526, { adopted_from: { number: 15526, url: 'https://x/15526', author: 'odttlnt', state: 'closed', text: '↳ adopted from #15526' } }); + const row = stageTrackerRowHtml(issue(15511, [closed, cp]), stages, ctx); + const dim = subsOf(row).find(s => s.includes('ham-sub-superseded')) || ''; + assert.strictEqual(noteOf(dim), 'superseded · closed · hive adopted → #15574', row); + assert.ok(dim.includes('This PR is closed as superseded.')); + // Copy gone (merged / closed): the closed original is not drawn. + assert.deepStrictEqual(stageTrackerLinkedSorted(issue(15511, [closed])).map(lp => lp.number), []); + assert.deepStrictEqual(stageTrackerLinkedSorted(issue(15511, [closed, copy(15574, 15526, { state: 'closed' })])).map(lp => lp.number), []); +} +// Ratchet over a mixed fixture: every drawn PR whose superseded_by names a +// drawn open PR under the same issue is the muted line, never a full row. +{ + const orig = pr(15526, { adopted_by: 15574, superseded_by: 15574, nested_under: 15511 }); + const cp = copy(15574, 15526, { nested_under: 15511 }); + const loose = pr(15561, { adopted_by: 15567, superseded_by: 15567, nested_under: 15560 }); + const looseCopy = copy(15567, 15561, { nested_under: 15560 }); + const items = [issue(15511, [orig, cp]), issue(15560, [loose, looseCopy]), orig, cp, loose, looseCopy, pr(15600, { stage: 70, caption: 'Fixing' })]; + for (const f of [{ kind: 'all', repo: '' }, { kind: 'pr', repo: '' }]) { + const rows = stageTrackerVisible(items, f); + for (const r of rows) { + if (r.kind !== 'issue') continue; + const html = stageTrackerRowHtml(r, stages, ctx); + const listed = new Set(stageTrackerLinkedSorted(r).filter(lp => String(lp.state || '') !== 'closed').map(lp => lp.number)); + for (const sub of subsOf(html)) { + const n = Number((/pr#(\d+)"/.exec(sub) || [])[1]); + const lp = r.linked_prs.find(x => x.number === n); + if (lp && Number(lp.superseded_by) > 0 && listed.has(Number(lp.superseded_by))) { + assert.ok(sub.includes('ham-sub-superseded') && !sub.includes('aria-label="Pipeline progress"'), 'ratchet: superseded #' + n + ' must be the muted line, not a full row: ' + sub); + assert.ok(/^superseded · (closed · )?hive adopted → #\d+$/.test(noteOf(sub)), 'ratchet: note shape: ' + noteOf(sub)); + } + } + } + const top = rows.filter(r => r.kind === 'pr').map(r => r.number); + if (f.kind === 'all') assert.ok(!top.includes(15526) && !top.includes(15561), 'nested superseded originals never float to the top level: ' + top.join(',')); + } +} +`) +} diff --git a/src/pkg/dashboard/stage_tracker_ui_test.go b/src/pkg/dashboard/stage_tracker_ui_test.go index 337cb3f876..5088befc1c 100644 --- a/src/pkg/dashboard/stage_tracker_ui_test.go +++ b/src/pkg/dashboard/stage_tracker_ui_test.go @@ -181,6 +181,7 @@ func stageTrackerRowsPreludeJS(t *testing.T, html string) string { jsFunc(t, html, "stageTrackerAgoText"), jsConstBlock(t, html, "STAGE_TRACKER_LINEAGE_REASON_TIP"), jsFunc(t, html, "stageTrackerLineageText"), + jsFunc(t, html, "stageTrackerSupersededOriginalClause"), jsFunc(t, html, "stageTrackerLineageTip"), jsFunc(t, html, "stageTrackerLineageChipHtml"), jsFunc(t, html, "stageTrackerLinkedPRItem"), @@ -191,6 +192,9 @@ func stageTrackerRowsPreludeJS(t *testing.T, html string) string { jsFunc(t, html, "stageTrackerLinkedTip"), jsConstLine(t, html, "STAGE_TRACKER_LINKED_GLYPH"), jsFunc(t, html, "stageTrackerLinkedDrawnHere"), + jsFunc(t, html, "stageTrackerLinkedSuperseder"), + jsFunc(t, html, "stageTrackerLinkedSupersededGone"), + jsFunc(t, html, "stageTrackerLinkedSupersededTip"), jsFunc(t, html, "stageTrackerLinkedSorted"), stageTrackerTierJS(t, html), jsFunc(t, html, "stageTrackerSortKey"), @@ -940,6 +944,9 @@ func TestStageTrackerFilterSortPage(t *testing.T) { "var _stageTrackerFilter = stageTrackerDefaultFilter();", jsFunc(t, html, "stageTrackerAnchor"), jsFunc(t, html, "stageTrackerLinkedDrawnHere"), + jsFunc(t, html, "stageTrackerLinkedSuperseder"), + jsFunc(t, html, "stageTrackerLinkedSupersededGone"), + jsFunc(t, html, "stageTrackerLinkedSupersededTip"), jsFunc(t, html, "stageTrackerLinkedSorted"), stageTrackerTierJS(t, html), jsFunc(t, html, "stageTrackerSortKey"), diff --git a/src/pkg/dashboard/static-src/css/tracker.css b/src/pkg/dashboard/static-src/css/tracker.css index 5c4b9a485a..9cc72f9535 100644 --- a/src/pkg/dashboard/static-src/css/tracker.css +++ b/src/pkg/dashboard/static-src/css/tracker.css @@ -387,7 +387,7 @@ .cue-acting > .ham-strip-row .ham-seg.active { background-image: repeating-linear-gradient(-45deg, transparent 0 6px, color-mix(in srgb, var(--surface-0) 28%, transparent) 6px 12px); background-size: 34px 100%; animation: cue-acting-stripes 1.1s linear infinite; } .ham-sub-superseded { opacity: .55; } .ham-sub-superseded .ham-row-head { min-height: 0; } - .ham-superseded-note { color: var(--muted); font-size: var(--fs-xs); } + .ham-superseded-note { color: var(--muted); font-size: var(--fs-xs); flex: 0 0 auto; white-space: nowrap; } .ham-adopted-from { color: var(--muted); text-decoration: none; } /* The Let hive decide preview. One decision, readable in three seconds (operator feedback on the dialog, issue 15397): subject line, diff --git a/src/pkg/dashboard/static-src/js/config-governor.js b/src/pkg/dashboard/static-src/js/config-governor.js index 649cf750bb..1d469f99d6 100644 --- a/src/pkg/dashboard/static-src/js/config-governor.js +++ b/src/pkg/dashboard/static-src/js/config-governor.js @@ -799,7 +799,7 @@ <div class="config-field"> <label for="cfg-stage-grace-offline">Offline contributor grace ${yamlHint('governor.labels.stage.contributor_grace_offline')}</label> <input type="text" id="cfg-stage-grace-offline" value="${esc(stageGraceOffline)}" placeholder="1h" data-change-action="markDirty" data-arg0="labels" data-arg1="stage_grace_offline" data-arg-types="s,s,w"> - <div class="config-help">Go duration after the comment-only nudge before an offline or external author's red PR is adopted. With live hub presence the hive instead waits ${yamlHint('governor.labels.stage.adoption.after_offline')} (default 30m) after a registered relay's last heartbeat, or ${yamlHint('governor.labels.stage.adoption.after_unregistered')} (default 2h) for an author with no profile here, and adopts in place on the PR's own branch when GitHub permits ${yamlHint('governor.labels.stage.adoption.in_place')} (default on) rather than opening a superseding PR. An in-place adoption keeps a changed head only when GitHub links the commit to the App bot ${yamlHint('governor.labels.stage.adoption.strict_attribution')} (default on); otherwise the hive hands the PR back to the contributor. Once the hive owns the head, the contributor lane merges it under the hive's own authority when the hive-authored gates pass (CI green on the adopted head, reviewer verdict, DCO, diff fences, soak), without requiring the original author's trust tier ${yamlHint('governor.labels.stage.adoption.auto_merge')} (default on). When the hive supersedes instead, it closes the original in the same pass that opens its copy — one note naming the copy, <code>hive/superseded</code> — and reopens it if the copy is closed unmerged or red at two heads ${yamlHint('governor.labels.stage.adoption.supersede.close_first')} (default on; off keeps the original open at stage 074 until the copy merges). A copy that conflicts with the base is handed to the fixer's rebase-resolve episode (two attempts, then stage 085 <code>rebase-failed-twice</code>); an adoption attempt that opened nothing is retried once the author's clanker has stayed offline for ${yamlHint('governor.labels.stage.adoption.offline_grace')} (default 30m).</div> + <div class="config-help">Go duration after the comment-only nudge before an offline or external author's red PR is adopted. With live hub presence the hive instead waits ${yamlHint('governor.labels.stage.adoption.after_offline')} (default 30m) after a registered relay's last heartbeat, or ${yamlHint('governor.labels.stage.adoption.after_unregistered')} (default 2h) for an author with no profile here, and adopts in place on the PR's own branch when GitHub permits ${yamlHint('governor.labels.stage.adoption.in_place')} (default on) rather than opening a superseding PR. An in-place adoption keeps a changed head only when GitHub links the commit to the App bot ${yamlHint('governor.labels.stage.adoption.strict_attribution')} (default on); otherwise the hive hands the PR back to the contributor. Once the hive owns the head, the contributor lane merges it under the hive's own authority when the hive-authored gates pass (CI green on the adopted head, reviewer verdict, DCO, diff fences, soak), without requiring the original author's trust tier ${yamlHint('governor.labels.stage.adoption.auto_merge')} (default on). When the hive supersedes instead, it closes the original in the same pass that opens its copy — one note naming the copy, <code>hive/superseded</code> — and reopens it if the copy is closed unmerged or red at two heads ${yamlHint('governor.labels.stage.adoption.supersede.close_first')} (default on; off keeps the original open at stage 074 until the copy merges). A clanker- or hive-authored original closes in that pass by policy even without the repo's write-back opt-in label, since the copy carries its commits and sign-off ${yamlHint('governor.labels.stage.adoption.close_superseded')} (default <code>on_adopt</code>; <code>on_merge</code> waits for the copy to merge; a person's PR always waits unless the label is present). A copy that conflicts with the base is handed to the fixer's rebase-resolve episode (two attempts, then stage 085 <code>rebase-failed-twice</code>); an adoption attempt that opened nothing is retried once the author's clanker has stayed offline for ${yamlHint('governor.labels.stage.adoption.offline_grace')} (default 30m).</div> </div> ${renderReporterTrustBlock()} <h4>Writing guide</h4> diff --git a/src/pkg/dashboard/static-src/js/config-state.js b/src/pkg/dashboard/static-src/js/config-state.js index c431add812..67a9688a85 100644 --- a/src/pkg/dashboard/static-src/js/config-state.js +++ b/src/pkg/dashboard/static-src/js/config-state.js @@ -81,7 +81,7 @@ { tab: 'Labels', section: 'Labels', label: 'Stage dwell overrides', key: 'governor.labels.stage.dwell', text: 'stage dwell stalled threshold governor.labels.stage.dwell' }, { tab: 'Labels', section: 'Labels', label: 'Adoption of a maintainer\'s PR', key: 'governor.labels.stage.adoption.maintainer_policy', text: 'adoption maintainer policy adopt ask never maintainer own pr clanker disconnected offline adopt action governor.labels.stage.adoption.maintainer_policy' }, { tab: 'Labels', section: 'Labels', label: 'Contributor nudge', key: 'governor.labels.stage.contributor_nudge.enabled', text: 'contributor nudge returned-to-contributor red ci fix-pr relay interrupt renudge presence window governor.labels.stage.contributor_nudge.enabled governor.labels.stage.contributor_nudge.renudge_interval governor.labels.stage.presence_window' }, - { tab: 'Labels', section: 'Labels', label: 'Adopt red contributor PRs', key: 'governor.labels.stage.adoption.enabled', text: 'adoption adopted-by-hive stage 074 red contributor pr grace online offline supersede takeover in place after offline unregistered heartbeat governor.labels.stage.adoption.enabled governor.labels.stage.contributor_grace_online governor.labels.stage.contributor_grace_offline governor.labels.stage.adoption.after_offline governor.labels.stage.adoption.after_unregistered governor.labels.stage.adoption.in_place governor.labels.stage.adoption.strict_attribution strict attribution governor.labels.stage.adoption.auto_merge auto merge adopted head hive authority governor.labels.stage.adoption.supersede.close_first close first superseded reopen copy failed governor.labels.stage.adoption.offline_grace offline grace rebase failed twice fixer resolving conflicts' }, + { tab: 'Labels', section: 'Labels', label: 'Adopt red contributor PRs', key: 'governor.labels.stage.adoption.enabled', text: 'adoption adopted-by-hive stage 074 red contributor pr grace online offline supersede takeover in place after offline unregistered heartbeat governor.labels.stage.adoption.enabled governor.labels.stage.contributor_grace_online governor.labels.stage.contributor_grace_offline governor.labels.stage.adoption.after_offline governor.labels.stage.adoption.after_unregistered governor.labels.stage.adoption.in_place governor.labels.stage.adoption.strict_attribution strict attribution governor.labels.stage.adoption.auto_merge auto merge adopted head hive authority governor.labels.stage.adoption.supersede.close_first close first superseded reopen copy failed governor.labels.stage.adoption.close_superseded close superseded on adopt on merge clanker authored opt-in label governor.labels.stage.adoption.offline_grace offline grace rebase failed twice fixer resolving conflicts' }, { tab: 'Hub', section: 'Contributor Relay', label: 'Fix budget', key: 'contribute.max_parallel_fixes', text: 'fix budget parallel fixes focus window red pr fix-pr preempt spawn contribute.max_parallel_fixes contribute.min_focus_window' }, { tab: 'Logging', section: 'Logging', label: 'Governor logging', key: 'governor.logging.max_size_mb', text: 'governor logging directory level compression max size age backups governor.logging.compress governor.logging.dir governor.logging.level governor.logging.max_age_days governor.logging.max_backups governor.logging.max_size_mb' }, { tab: 'Advisory', section: 'Advisory', label: 'Advisory digest', key: 'governor.advisory.max_findings', text: 'advisory digest max findings show all staleness pr autoclose target linear issue retry backoff' }, diff --git a/src/pkg/dashboard/static-src/js/tracker-row.js b/src/pkg/dashboard/static-src/js/tracker-row.js index 7181299d91..4180efd127 100644 --- a/src/pkg/dashboard/static-src/js/tracker-row.js +++ b/src/pkg/dashboard/static-src/js/tracker-row.js @@ -991,7 +991,16 @@ if (l.kind === 'superseded') return 'Hive took this PR over as #' + Number(l.to_number) + '; this original is closed when that merges.'; const who = l.from_author ? '@' + l.from_author : 'the contributor'; const tip = STAGE_TRACKER_LINEAGE_REASON_TIP[l.reason] || STAGE_TRACKER_LINEAGE_REASON_TIP['ci-red-contributor-offline']; - return tip.split('@AUTHOR').join(who); + return tip.split('@AUTHOR').join(who) + stageTrackerSupersededOriginalClause(Number(l.from_number), l.from_state); + } + // Pure: the hover clause that says what became of the superseded + // original the chip stands in for — closed, or still open and closing + // when the copy merges; '' when the server does not say. + function stageTrackerSupersededOriginalClause(number, state) { + if (!(number > 0)) return ''; + if (state === 'closed') return ' #' + number + ' is closed as superseded.'; + if (state === 'open') return ' #' + number + ' is superseded and still open; it closes when this merges.'; + return ''; } function stageTrackerLineageChipHtml(item, nowMs) { const text = stageTrackerLineageText(item, nowMs); @@ -1022,7 +1031,7 @@ const what = af.decided_action === 'let-hive-decide' ? 'you let hive decide' : 'you approved'; text += ' · ' + what + ' ' + agentNowClockTime(Date.parse(af.decided_at), typeof nowMs === 'number' ? nowMs : Date.now()); } - const tip = 'Hive re-authored #' + af.number + (af.author ? ' (by @' + af.author + ')' : '') + ' as this PR with the same commits and sign-off' + (af.decided_by ? '; the decision on #' + af.number + ' was ' + (af.decided_action || 'yours') + ' by @' + af.decided_by : '') + '. #' + af.number + ' is closed as superseded when this merges.'; + const tip = 'Hive re-authored #' + af.number + (af.author ? ' (by @' + af.author + ')' : '') + ' as this PR with the same commits and sign-off' + (af.decided_by ? '; the decision on #' + af.number + ' was ' + (af.decided_action || 'yours') + ' by @' + af.decided_by : '') + '.' + (stageTrackerSupersededOriginalClause(Number(af.number), af.state) || ' #' + af.number + ' is closed as superseded when this merges.'); return `<a class="ham-badge ham-adopted-from" href="${esc(af.url || '#')}" target="_blank" rel="noopener" title="${esc(tip)}">${esc(text)}</a>`; } // The row's inline lead action (tracker-actions.js @@ -1043,7 +1052,7 @@ function stageTrackerSubRowHtml(lp, issue, stages, nowMs, ctx) { const pr = stageTrackerLinkedPRItem(issue, lp); const superseded = typeof stageTrackerLinkedSupersededText === 'function' ? stageTrackerLinkedSupersededText(lp, issue) : ''; - let ref = stageTrackerPRRef(pr.number, pr.url, pr.author_kind, pr.author, pr.title, (pr.title ? pr.title + ' · ' : '') + (superseded || stageTrackerTooltip(pr, nowMs)) + ' · ' + stageTrackerLinkedTip(issue, pr.number, ctx)); + let ref = stageTrackerPRRef(pr.number, pr.url, pr.author_kind, pr.author, pr.title, (pr.title ? pr.title + ' · ' : '') + (superseded ? superseded + ' · ' + stageTrackerLinkedSupersededTip(lp) : stageTrackerTooltip(pr, nowMs)) + ' · ' + stageTrackerLinkedTip(issue, pr.number, ctx)); // One line (hivecommons/hive: "consolidate from 3 lines of text to // 1"): connector, repo chip, author icon + #N + title, the lineage / // adopted-from chip, then the base pill — all siblings of the flex-row @@ -1054,11 +1063,13 @@ ref = stageTrackerPRPillsHtml(ref, lineage || null, lp.base_ref); ref = STAGE_TRACKER_LINKED_GLYPH + ref; if (superseded) { - // The adopted original: one dimmed line, no chevron track, no row - // tools, no needs-human styling — the copy carries the chevron. + // The adopted original: one muted line, no chevron track, no row + // tools, no needs-human styling — the copy carries the chevron. The + // trailing note never wraps; the title ellipsizes first (owner, + // hivecommons/hive#15511: "superseded · hive adopted → #15574"). return `<div class="ham-sub ham-sub-superseded" data-ham-kind="pr" data-ham-stage="${pr.stage}" data-ham-sub-key="${esc(stageTrackerItemKey(pr))}" data-ham-superseded-by="${Number(lp.superseded_by || lp.adopted_by) || 0}"> <div class="ham-row-head"> - ${stageTrackerHeadColsHtml([ref + ` <span class="ham-superseded-note">· ${esc(superseded)}</span>`], '', stageTrackerActedBadgeHtml(pr, nowMs))} + ${stageTrackerHeadColsHtml([ref + ` <span class="ham-superseded-note" title="${esc(stageTrackerLinkedSupersededTip(lp))}">${esc(superseded)}</span>`], '', stageTrackerActedBadgeHtml(pr, nowMs))} </div> </div>`; } @@ -1093,7 +1104,7 @@ return stageTrackerLinkedElsewhere(item).map(lp => `<a class="ham-badge ham-linked-elsewhere" href="${esc(lp.url || '#')}" target="_blank" rel="noopener" title="${esc('PR #' + (Number(lp.number) || 0) + ' covers this issue too; its row is drawn under #' + Number(lp.drawn_under))}">↳ #${Number(lp.number) || 0} · under #${Number(lp.drawn_under)}</a>`).join(' '); } 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 linked = Array.isArray(item.linked_prs) ? item.linked_prs.filter(lp => stageTrackerLinkedDrawnHere(lp, item) && !stageTrackerLinkedSupersededGone(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', y) - stageTrackerAnchor(x.stage, stages, 'pr', x)) || (stageTrackerAttentionTier(x) - stageTrackerAttentionTier(y)) || (sinceOf(x) - sinceOf(y)) || ((x.number || 0) - (y.number || 0))); } @@ -1274,7 +1285,7 @@ // One covering PR: a single entry whose strip the PR's stage drives. const lp = linked[0]; const who = (lp.author_kind || 'hive') + (lp.author ? ' · @' + lp.author : ''); - prRefs = [STAGE_TRACKER_LINKED_GLYPH + stageTrackerPRPillsHtml(stageTrackerPRRef(lp.number, lp.url, lp.author_kind || '', lp.author, lp.title, (lp.title ? lp.title + '\n' : '') + 'Author: ' + who + ' · ' + stageTrackerLinkedTip(item, lp.number, ctx)), lp.lineage && typeof stageTrackerLineageChipHtml === 'function' ? (stageTrackerLineageChipHtml(lp, nowMs) || null) : null, lp.base_ref)]; + prRefs = [STAGE_TRACKER_LINKED_GLYPH + stageTrackerPRPillsHtml(stageTrackerPRRef(lp.number, lp.url, lp.author_kind || '', lp.author, lp.title, (lp.title ? lp.title + '\n' : '') + 'Author: ' + who + ' · ' + stageTrackerLinkedTip(item, lp.number, ctx)), (lp.lineage && typeof stageTrackerLineageChipHtml === 'function' ? stageTrackerLineageChipHtml(lp, nowMs) : '') || (typeof stageTrackerAdoptedFromChipHtml === 'function' ? stageTrackerAdoptedFromChipHtml(lp, nowMs) : '') || null, lp.base_ref)]; shown = Object.assign({}, item, { via_pr: true, stage: lp.stage || 40, stage_since: lp.stage_since || item.stage_since, modifiers: lp.modifiers || item.modifiers, deferred_modifiers: lp.deferred_modifiers || item.deferred_modifiers || [], caption: lp.caption || item.caption, reason: lp.reason || item.reason, human_approver: lp.human_approver || '', manual_merge: !!lp.manual_merge, human_merge_reason: lp.human_merge_reason || '', human_merge_reason_text: lp.human_merge_reason_text || '', sentinel_alert: !!lp.sentinel_alert, sentinel_reason: lp.sentinel_reason || '', head: lp.head || '', decision_needed: lp.decision_needed || null, hold: lp.hold || null, adoption: lp.adoption || null, stage_actor: lp.stage_actor || item.stage_actor || null, claimant: lp.claimant || null, presence: lp.presence || null, rework: lp.rework || null, merge_gate: lp.merge_gate || null, merge_train: lp.merge_train || null, decided: lp.decided || item.decided || null }); } else if (linked.length) { diff --git a/src/pkg/dashboard/static-src/js/tracker-words.js b/src/pkg/dashboard/static-src/js/tracker-words.js index e938b1d0e7..397f88a6c5 100644 --- a/src/pkg/dashboard/static-src/js/tracker-words.js +++ b/src/pkg/dashboard/static-src/js/tracker-words.js @@ -843,18 +843,39 @@ const lead = who + ' · ' + chose + ', ' + agentNowClockTime(atMs, nowMs); return lead + (d.title ? '\n' + d.title : ''); } + // Pure: the PR a nested original was superseded by — `superseded_by` + // from the server, or `adopted_by` while the copy is live — when that + // copy is itself listed under the issue; else 0. + function stageTrackerLinkedSuperseder(lp, issue) { + if (!lp) return 0; + const live = lp.adopted_by_state !== 'closed' && lp.adopted_by_state !== 'closed-twice' && lp.adopted_by_state !== 'copy-failed'; + const by = Number(lp.superseded_by) || (live ? Number(lp.adopted_by) || 0 : 0); + if (!(by > 0) || by === Number(lp.number)) return 0; + const linked = Array.isArray(issue && issue.linked_prs) ? issue.linked_prs : []; + return linked.some(x => x && Number(x.number) === by && String(x.state || '') !== 'closed') ? by : 0; + } // Pure: an adopted original listed under its issue — closed, or still - // open with the hive's copy already in the list — draws as one dimmed - // line without a chevron track (hivecommons/hive#15126). + // open — with the hive's copy in the list draws as one muted line + // without a chevron track (hivecommons/hive#15126, #15511): the note + // reads "superseded · hive adopted → #N", "superseded · closed · hive + // adopted → #N" once the close landed. '' when the copy is not listed. function stageTrackerLinkedSupersededText(lp, issue) { - if (!lp) return ''; - const by = Number(lp.superseded_by || lp.adopted_by) || 0; - if (String(lp.state || '') === 'closed') return 'closed · superseded by #' + by; - if (by > 0 && lp.adopted_by_state !== 'closed' && lp.adopted_by_state !== 'closed-twice') { - const linked = Array.isArray(issue && issue.linked_prs) ? issue.linked_prs : []; - if (linked.some(x => Number(x.number) === by)) return 'Adopted → #' + by + ' · superseded (hive re-authored with sign-off)'; - } - return ''; + const by = stageTrackerLinkedSuperseder(lp, issue); + if (!by) return ''; + return 'superseded · ' + (String(lp.state || '') === 'closed' ? 'closed · ' : '') + 'hive adopted → #' + by; + } + // Pure: the hover behind that note — what hive did and what becomes of + // this PR. + function stageTrackerLinkedSupersededTip(lp) { + const by = Number(lp && (lp.superseded_by || lp.adopted_by)) || 0; + if (!by) return ''; + return 'Hive re-authored this PR as #' + by + ' with the same commits and sign-off. ' + (String(lp.state || '') === 'closed' ? 'This PR is closed as superseded.' : 'This PR closes as superseded when #' + by + ' merges.'); + } + // Pure: a closed original whose superseder is no longer listed open + // under the issue (merged, closed, filtered) has nothing left to say + // and is not drawn. + function stageTrackerLinkedSupersededGone(lp, issue) { + return !!lp && String(lp.state || '') === 'closed' && !stageTrackerLinkedSuperseder(lp, issue); } function stageTrackerCoveringPR(item) { if (!item || item.kind === 'pr') return null; diff --git a/src/pkg/dashboard/static/index.html b/src/pkg/dashboard/static/index.html index 9809108f1c..d84aad917f 100644 --- a/src/pkg/dashboard/static/index.html +++ b/src/pkg/dashboard/static/index.html @@ -1712,7 +1712,7 @@ .cue-acting > .ham-strip-row .ham-seg.active { background-image: repeating-linear-gradient(-45deg, transparent 0 6px, color-mix(in srgb, var(--surface-0) 28%, transparent) 6px 12px); background-size: 34px 100%; animation: cue-acting-stripes 1.1s linear infinite; } .ham-sub-superseded { opacity: .55; } .ham-sub-superseded .ham-row-head { min-height: 0; } - .ham-superseded-note { color: var(--muted); font-size: var(--fs-xs); } + .ham-superseded-note { color: var(--muted); font-size: var(--fs-xs); flex: 0 0 auto; white-space: nowrap; } .ham-adopted-from { color: var(--muted); text-decoration: none; } /* The Let hive decide preview. One decision, readable in three seconds (operator feedback on the dialog, issue 15397): subject line, @@ -15157,18 +15157,39 @@ <h3 class="faq-group-title">Where to get help</h3> const lead = who + ' · ' + chose + ', ' + agentNowClockTime(atMs, nowMs); return lead + (d.title ? '\n' + d.title : ''); } + // Pure: the PR a nested original was superseded by — `superseded_by` + // from the server, or `adopted_by` while the copy is live — when that + // copy is itself listed under the issue; else 0. + function stageTrackerLinkedSuperseder(lp, issue) { + if (!lp) return 0; + const live = lp.adopted_by_state !== 'closed' && lp.adopted_by_state !== 'closed-twice' && lp.adopted_by_state !== 'copy-failed'; + const by = Number(lp.superseded_by) || (live ? Number(lp.adopted_by) || 0 : 0); + if (!(by > 0) || by === Number(lp.number)) return 0; + const linked = Array.isArray(issue && issue.linked_prs) ? issue.linked_prs : []; + return linked.some(x => x && Number(x.number) === by && String(x.state || '') !== 'closed') ? by : 0; + } // Pure: an adopted original listed under its issue — closed, or still - // open with the hive's copy already in the list — draws as one dimmed - // line without a chevron track (hivecommons/hive#15126). + // open — with the hive's copy in the list draws as one muted line + // without a chevron track (hivecommons/hive#15126, #15511): the note + // reads "superseded · hive adopted → #N", "superseded · closed · hive + // adopted → #N" once the close landed. '' when the copy is not listed. function stageTrackerLinkedSupersededText(lp, issue) { - if (!lp) return ''; - const by = Number(lp.superseded_by || lp.adopted_by) || 0; - if (String(lp.state || '') === 'closed') return 'closed · superseded by #' + by; - if (by > 0 && lp.adopted_by_state !== 'closed' && lp.adopted_by_state !== 'closed-twice') { - const linked = Array.isArray(issue && issue.linked_prs) ? issue.linked_prs : []; - if (linked.some(x => Number(x.number) === by)) return 'Adopted → #' + by + ' · superseded (hive re-authored with sign-off)'; - } - return ''; + const by = stageTrackerLinkedSuperseder(lp, issue); + if (!by) return ''; + return 'superseded · ' + (String(lp.state || '') === 'closed' ? 'closed · ' : '') + 'hive adopted → #' + by; + } + // Pure: the hover behind that note — what hive did and what becomes of + // this PR. + function stageTrackerLinkedSupersededTip(lp) { + const by = Number(lp && (lp.superseded_by || lp.adopted_by)) || 0; + if (!by) return ''; + return 'Hive re-authored this PR as #' + by + ' with the same commits and sign-off. ' + (String(lp.state || '') === 'closed' ? 'This PR is closed as superseded.' : 'This PR closes as superseded when #' + by + ' merges.'); + } + // Pure: a closed original whose superseder is no longer listed open + // under the issue (merged, closed, filtered) has nothing left to say + // and is not drawn. + function stageTrackerLinkedSupersededGone(lp, issue) { + return !!lp && String(lp.state || '') === 'closed' && !stageTrackerLinkedSuperseder(lp, issue); } function stageTrackerCoveringPR(item) { if (!item || item.kind === 'pr') return null; @@ -16888,7 +16909,16 @@ <h3 class="faq-group-title">Where to get help</h3> if (l.kind === 'superseded') return 'Hive took this PR over as #' + Number(l.to_number) + '; this original is closed when that merges.'; const who = l.from_author ? '@' + l.from_author : 'the contributor'; const tip = STAGE_TRACKER_LINEAGE_REASON_TIP[l.reason] || STAGE_TRACKER_LINEAGE_REASON_TIP['ci-red-contributor-offline']; - return tip.split('@AUTHOR').join(who); + return tip.split('@AUTHOR').join(who) + stageTrackerSupersededOriginalClause(Number(l.from_number), l.from_state); + } + // Pure: the hover clause that says what became of the superseded + // original the chip stands in for — closed, or still open and closing + // when the copy merges; '' when the server does not say. + function stageTrackerSupersededOriginalClause(number, state) { + if (!(number > 0)) return ''; + if (state === 'closed') return ' #' + number + ' is closed as superseded.'; + if (state === 'open') return ' #' + number + ' is superseded and still open; it closes when this merges.'; + return ''; } function stageTrackerLineageChipHtml(item, nowMs) { const text = stageTrackerLineageText(item, nowMs); @@ -16919,7 +16949,7 @@ <h3 class="faq-group-title">Where to get help</h3> const what = af.decided_action === 'let-hive-decide' ? 'you let hive decide' : 'you approved'; text += ' · ' + what + ' ' + agentNowClockTime(Date.parse(af.decided_at), typeof nowMs === 'number' ? nowMs : Date.now()); } - const tip = 'Hive re-authored #' + af.number + (af.author ? ' (by @' + af.author + ')' : '') + ' as this PR with the same commits and sign-off' + (af.decided_by ? '; the decision on #' + af.number + ' was ' + (af.decided_action || 'yours') + ' by @' + af.decided_by : '') + '. #' + af.number + ' is closed as superseded when this merges.'; + const tip = 'Hive re-authored #' + af.number + (af.author ? ' (by @' + af.author + ')' : '') + ' as this PR with the same commits and sign-off' + (af.decided_by ? '; the decision on #' + af.number + ' was ' + (af.decided_action || 'yours') + ' by @' + af.decided_by : '') + '.' + (stageTrackerSupersededOriginalClause(Number(af.number), af.state) || ' #' + af.number + ' is closed as superseded when this merges.'); return `<a class="ham-badge ham-adopted-from" href="${esc(af.url || '#')}" target="_blank" rel="noopener" title="${esc(tip)}">${esc(text)}</a>`; } // The row's inline lead action (tracker-actions.js @@ -16940,7 +16970,7 @@ <h3 class="faq-group-title">Where to get help</h3> function stageTrackerSubRowHtml(lp, issue, stages, nowMs, ctx) { const pr = stageTrackerLinkedPRItem(issue, lp); const superseded = typeof stageTrackerLinkedSupersededText === 'function' ? stageTrackerLinkedSupersededText(lp, issue) : ''; - let ref = stageTrackerPRRef(pr.number, pr.url, pr.author_kind, pr.author, pr.title, (pr.title ? pr.title + ' · ' : '') + (superseded || stageTrackerTooltip(pr, nowMs)) + ' · ' + stageTrackerLinkedTip(issue, pr.number, ctx)); + let ref = stageTrackerPRRef(pr.number, pr.url, pr.author_kind, pr.author, pr.title, (pr.title ? pr.title + ' · ' : '') + (superseded ? superseded + ' · ' + stageTrackerLinkedSupersededTip(lp) : stageTrackerTooltip(pr, nowMs)) + ' · ' + stageTrackerLinkedTip(issue, pr.number, ctx)); // One line (hivecommons/hive: "consolidate from 3 lines of text to // 1"): connector, repo chip, author icon + #N + title, the lineage / // adopted-from chip, then the base pill — all siblings of the flex-row @@ -16951,11 +16981,13 @@ <h3 class="faq-group-title">Where to get help</h3> ref = stageTrackerPRPillsHtml(ref, lineage || null, lp.base_ref); ref = STAGE_TRACKER_LINKED_GLYPH + ref; if (superseded) { - // The adopted original: one dimmed line, no chevron track, no row - // tools, no needs-human styling — the copy carries the chevron. + // The adopted original: one muted line, no chevron track, no row + // tools, no needs-human styling — the copy carries the chevron. The + // trailing note never wraps; the title ellipsizes first (owner, + // hivecommons/hive#15511: "superseded · hive adopted → #15574"). return `<div class="ham-sub ham-sub-superseded" data-ham-kind="pr" data-ham-stage="${pr.stage}" data-ham-sub-key="${esc(stageTrackerItemKey(pr))}" data-ham-superseded-by="${Number(lp.superseded_by || lp.adopted_by) || 0}"> <div class="ham-row-head"> - ${stageTrackerHeadColsHtml([ref + ` <span class="ham-superseded-note">· ${esc(superseded)}</span>`], '', stageTrackerActedBadgeHtml(pr, nowMs))} + ${stageTrackerHeadColsHtml([ref + ` <span class="ham-superseded-note" title="${esc(stageTrackerLinkedSupersededTip(lp))}">${esc(superseded)}</span>`], '', stageTrackerActedBadgeHtml(pr, nowMs))} </div> </div>`; } @@ -16990,7 +17022,7 @@ <h3 class="faq-group-title">Where to get help</h3> return stageTrackerLinkedElsewhere(item).map(lp => `<a class="ham-badge ham-linked-elsewhere" href="${esc(lp.url || '#')}" target="_blank" rel="noopener" title="${esc('PR #' + (Number(lp.number) || 0) + ' covers this issue too; its row is drawn under #' + Number(lp.drawn_under))}">↳ #${Number(lp.number) || 0} · under #${Number(lp.drawn_under)}</a>`).join(' '); } 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 linked = Array.isArray(item.linked_prs) ? item.linked_prs.filter(lp => stageTrackerLinkedDrawnHere(lp, item) && !stageTrackerLinkedSupersededGone(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', y) - stageTrackerAnchor(x.stage, stages, 'pr', x)) || (stageTrackerAttentionTier(x) - stageTrackerAttentionTier(y)) || (sinceOf(x) - sinceOf(y)) || ((x.number || 0) - (y.number || 0))); } @@ -17171,7 +17203,7 @@ <h3 class="faq-group-title">Where to get help</h3> // One covering PR: a single entry whose strip the PR's stage drives. const lp = linked[0]; const who = (lp.author_kind || 'hive') + (lp.author ? ' · @' + lp.author : ''); - prRefs = [STAGE_TRACKER_LINKED_GLYPH + stageTrackerPRPillsHtml(stageTrackerPRRef(lp.number, lp.url, lp.author_kind || '', lp.author, lp.title, (lp.title ? lp.title + '\n' : '') + 'Author: ' + who + ' · ' + stageTrackerLinkedTip(item, lp.number, ctx)), lp.lineage && typeof stageTrackerLineageChipHtml === 'function' ? (stageTrackerLineageChipHtml(lp, nowMs) || null) : null, lp.base_ref)]; + prRefs = [STAGE_TRACKER_LINKED_GLYPH + stageTrackerPRPillsHtml(stageTrackerPRRef(lp.number, lp.url, lp.author_kind || '', lp.author, lp.title, (lp.title ? lp.title + '\n' : '') + 'Author: ' + who + ' · ' + stageTrackerLinkedTip(item, lp.number, ctx)), (lp.lineage && typeof stageTrackerLineageChipHtml === 'function' ? stageTrackerLineageChipHtml(lp, nowMs) : '') || (typeof stageTrackerAdoptedFromChipHtml === 'function' ? stageTrackerAdoptedFromChipHtml(lp, nowMs) : '') || null, lp.base_ref)]; shown = Object.assign({}, item, { via_pr: true, stage: lp.stage || 40, stage_since: lp.stage_since || item.stage_since, modifiers: lp.modifiers || item.modifiers, deferred_modifiers: lp.deferred_modifiers || item.deferred_modifiers || [], caption: lp.caption || item.caption, reason: lp.reason || item.reason, human_approver: lp.human_approver || '', manual_merge: !!lp.manual_merge, human_merge_reason: lp.human_merge_reason || '', human_merge_reason_text: lp.human_merge_reason_text || '', sentinel_alert: !!lp.sentinel_alert, sentinel_reason: lp.sentinel_reason || '', head: lp.head || '', decision_needed: lp.decision_needed || null, hold: lp.hold || null, adoption: lp.adoption || null, stage_actor: lp.stage_actor || item.stage_actor || null, claimant: lp.claimant || null, presence: lp.presence || null, rework: lp.rework || null, merge_gate: lp.merge_gate || null, merge_train: lp.merge_train || null, decided: lp.decided || item.decided || null }); } else if (linked.length) { @@ -46546,7 +46578,7 @@ <h3 style="color:var(--amber);text-align:center">Configure LiteLLM</h3> { tab: 'Labels', section: 'Labels', label: 'Stage dwell overrides', key: 'governor.labels.stage.dwell', text: 'stage dwell stalled threshold governor.labels.stage.dwell' }, { tab: 'Labels', section: 'Labels', label: 'Adoption of a maintainer\'s PR', key: 'governor.labels.stage.adoption.maintainer_policy', text: 'adoption maintainer policy adopt ask never maintainer own pr clanker disconnected offline adopt action governor.labels.stage.adoption.maintainer_policy' }, { tab: 'Labels', section: 'Labels', label: 'Contributor nudge', key: 'governor.labels.stage.contributor_nudge.enabled', text: 'contributor nudge returned-to-contributor red ci fix-pr relay interrupt renudge presence window governor.labels.stage.contributor_nudge.enabled governor.labels.stage.contributor_nudge.renudge_interval governor.labels.stage.presence_window' }, - { tab: 'Labels', section: 'Labels', label: 'Adopt red contributor PRs', key: 'governor.labels.stage.adoption.enabled', text: 'adoption adopted-by-hive stage 074 red contributor pr grace online offline supersede takeover in place after offline unregistered heartbeat governor.labels.stage.adoption.enabled governor.labels.stage.contributor_grace_online governor.labels.stage.contributor_grace_offline governor.labels.stage.adoption.after_offline governor.labels.stage.adoption.after_unregistered governor.labels.stage.adoption.in_place governor.labels.stage.adoption.strict_attribution strict attribution governor.labels.stage.adoption.auto_merge auto merge adopted head hive authority governor.labels.stage.adoption.supersede.close_first close first superseded reopen copy failed governor.labels.stage.adoption.offline_grace offline grace rebase failed twice fixer resolving conflicts' }, + { tab: 'Labels', section: 'Labels', label: 'Adopt red contributor PRs', key: 'governor.labels.stage.adoption.enabled', text: 'adoption adopted-by-hive stage 074 red contributor pr grace online offline supersede takeover in place after offline unregistered heartbeat governor.labels.stage.adoption.enabled governor.labels.stage.contributor_grace_online governor.labels.stage.contributor_grace_offline governor.labels.stage.adoption.after_offline governor.labels.stage.adoption.after_unregistered governor.labels.stage.adoption.in_place governor.labels.stage.adoption.strict_attribution strict attribution governor.labels.stage.adoption.auto_merge auto merge adopted head hive authority governor.labels.stage.adoption.supersede.close_first close first superseded reopen copy failed governor.labels.stage.adoption.close_superseded close superseded on adopt on merge clanker authored opt-in label governor.labels.stage.adoption.offline_grace offline grace rebase failed twice fixer resolving conflicts' }, { tab: 'Hub', section: 'Contributor Relay', label: 'Fix budget', key: 'contribute.max_parallel_fixes', text: 'fix budget parallel fixes focus window red pr fix-pr preempt spawn contribute.max_parallel_fixes contribute.min_focus_window' }, { tab: 'Logging', section: 'Logging', label: 'Governor logging', key: 'governor.logging.max_size_mb', text: 'governor logging directory level compression max size age backups governor.logging.compress governor.logging.dir governor.logging.level governor.logging.max_age_days governor.logging.max_backups governor.logging.max_size_mb' }, { tab: 'Advisory', section: 'Advisory', label: 'Advisory digest', key: 'governor.advisory.max_findings', text: 'advisory digest max findings show all staleness pr autoclose target linear issue retry backoff' }, @@ -53424,7 +53456,7 @@ <h4 class="mt-6 mb-3">Stage labels</h4> <div class="config-field"> <label for="cfg-stage-grace-offline">Offline contributor grace ${yamlHint('governor.labels.stage.contributor_grace_offline')}</label> <input type="text" id="cfg-stage-grace-offline" value="${esc(stageGraceOffline)}" placeholder="1h" data-change-action="markDirty" data-arg0="labels" data-arg1="stage_grace_offline" data-arg-types="s,s,w"> - <div class="config-help">Go duration after the comment-only nudge before an offline or external author's red PR is adopted. With live hub presence the hive instead waits ${yamlHint('governor.labels.stage.adoption.after_offline')} (default 30m) after a registered relay's last heartbeat, or ${yamlHint('governor.labels.stage.adoption.after_unregistered')} (default 2h) for an author with no profile here, and adopts in place on the PR's own branch when GitHub permits ${yamlHint('governor.labels.stage.adoption.in_place')} (default on) rather than opening a superseding PR. An in-place adoption keeps a changed head only when GitHub links the commit to the App bot ${yamlHint('governor.labels.stage.adoption.strict_attribution')} (default on); otherwise the hive hands the PR back to the contributor. Once the hive owns the head, the contributor lane merges it under the hive's own authority when the hive-authored gates pass (CI green on the adopted head, reviewer verdict, DCO, diff fences, soak), without requiring the original author's trust tier ${yamlHint('governor.labels.stage.adoption.auto_merge')} (default on). When the hive supersedes instead, it closes the original in the same pass that opens its copy — one note naming the copy, <code>hive/superseded</code> — and reopens it if the copy is closed unmerged or red at two heads ${yamlHint('governor.labels.stage.adoption.supersede.close_first')} (default on; off keeps the original open at stage 074 until the copy merges). A copy that conflicts with the base is handed to the fixer's rebase-resolve episode (two attempts, then stage 085 <code>rebase-failed-twice</code>); an adoption attempt that opened nothing is retried once the author's clanker has stayed offline for ${yamlHint('governor.labels.stage.adoption.offline_grace')} (default 30m).</div> + <div class="config-help">Go duration after the comment-only nudge before an offline or external author's red PR is adopted. With live hub presence the hive instead waits ${yamlHint('governor.labels.stage.adoption.after_offline')} (default 30m) after a registered relay's last heartbeat, or ${yamlHint('governor.labels.stage.adoption.after_unregistered')} (default 2h) for an author with no profile here, and adopts in place on the PR's own branch when GitHub permits ${yamlHint('governor.labels.stage.adoption.in_place')} (default on) rather than opening a superseding PR. An in-place adoption keeps a changed head only when GitHub links the commit to the App bot ${yamlHint('governor.labels.stage.adoption.strict_attribution')} (default on); otherwise the hive hands the PR back to the contributor. Once the hive owns the head, the contributor lane merges it under the hive's own authority when the hive-authored gates pass (CI green on the adopted head, reviewer verdict, DCO, diff fences, soak), without requiring the original author's trust tier ${yamlHint('governor.labels.stage.adoption.auto_merge')} (default on). When the hive supersedes instead, it closes the original in the same pass that opens its copy — one note naming the copy, <code>hive/superseded</code> — and reopens it if the copy is closed unmerged or red at two heads ${yamlHint('governor.labels.stage.adoption.supersede.close_first')} (default on; off keeps the original open at stage 074 until the copy merges). A clanker- or hive-authored original closes in that pass by policy even without the repo's write-back opt-in label, since the copy carries its commits and sign-off ${yamlHint('governor.labels.stage.adoption.close_superseded')} (default <code>on_adopt</code>; <code>on_merge</code> waits for the copy to merge; a person's PR always waits unless the label is present). A copy that conflicts with the base is handed to the fixer's rebase-resolve episode (two attempts, then stage 085 <code>rebase-failed-twice</code>); an adoption attempt that opened nothing is retried once the author's clanker has stayed offline for ${yamlHint('governor.labels.stage.adoption.offline_grace')} (default 30m).</div> </div> ${renderReporterTrustBlock()} <h4>Writing guide</h4> diff --git a/src/pkg/github/automerge/automerge_adoption_close_first.go b/src/pkg/github/automerge/automerge_adoption_close_first.go index 0f711eea45..d3efdeaba8 100644 --- a/src/pkg/github/automerge/automerge_adoption_close_first.go +++ b/src/pkg/github/automerge/automerge_adoption_close_first.go @@ -10,6 +10,8 @@ import ( "time" gh "github.com/google/go-github/v72/github" + "github.com/hivecommons/hive/pkg/authorkind" + "github.com/hivecommons/hive/pkg/config" hgithub "github.com/hivecommons/hive/pkg/github" "github.com/hivecommons/hive/pkg/stagelabels" "github.com/hivecommons/hive/pkg/writeback" @@ -41,6 +43,16 @@ import ( // the original open on the keep-open path; a refused reopen leaves the // record due its next poll, so the reopen lands once the gate allows it // (e.g. when an operator lifts a repo pause). +// +// An agent-authored original (a contributor's clanker or another hive, +// hivecommons/hive#15526) is the exception: under +// governor.labels.stage.adoption.close_superseded: on_adopt (default) the +// gate item names the copy that carries its commits and the gate allows the +// close by policy (writeback.ReasonSupersededAgentPR) — no repo opt-in +// label is asked for, because the pair is one logical PR of the hive's own. +// on_merge skips close-first for those and lets settleSuperseder close them +// when the copy merges. A human's original is never closed on adopt without +// the opt-in label. // AdoptionCopyFailedMarker opens the note posted when the hive reopens (or, // past the reopen guard, declines to reopen) a close-first original. @@ -112,6 +124,25 @@ func AdoptionCopyFailedHeldComment(copy int, head, why string, redHeads int, reo AdoptionCopyFailedMarker, copy, head, why, copy, adoptionCopyFailedWhy(why, redHeads), ago) } +// closeFirstGateItem is the write-back gate's view of an original about to +// be closed in favour of its copy `superseding`. An agent-authored +// original (author/clanker, author/hive) under close_superseded on_adopt +// (the default) names the copy so the gate allows the close by policy +// (writeback.ReasonSupersededAgentPR); under on_merge it reports onMerge +// and the caller leaves the original to settleSuperseder. A person's +// original is the plain gated item whatever the policy says. +func closeFirstGateItem(obs stageObservation, policy StageLabelPolicy, superseding int) (item writeback.Item, onMerge bool) { + item = writebackItemForObservation(obs) + if obs.AuthorKind != authorkind.Clanker && obs.AuthorKind != authorkind.Hive { + return item, false + } + if policy.AdoptCloseSuperseded == config.AdoptionCloseSupersededOnMerge { + return item, true + } + item.AgentAuthored, item.SupersededBy = true, superseding + return item, false +} + // closeSupersededOriginalFirst closes the original right after its copy // opened. The comment goes first so GitHub shows why before the close; // the record is marked as soon as the note is out so nothing re-posts it. @@ -123,7 +154,12 @@ func (c *Engine) closeSupersededOriginalFirst(ctx context.Context, store *stagel owner, repo, number := obs.Owner, obs.Repo, obs.Number logArgs := []any{"repo", obs.Display, "pr", number, "head", obs.HeadSHA, "superseded_by", superseding, "reason", reason} body := AdoptionCloseFirstComment(obs, policy.HiveID, superseding, reason) + adoptionFenceNote(fence) - if d := c.writebackAllowed(obs.Display, writebackItemForObservation(obs), writeback.KindContributorAdopt, body); !d.Allowed { + item, onMerge := closeFirstGateItem(obs, policy, superseding) + if onMerge { + c.info("stage labels: agent-authored original left open until the copy merges (close_superseded: on_merge)", logArgs...) + return 0, nil + } + if d := c.writebackAllowed(obs.Display, item, writeback.KindContributorAdopt, body); !d.Allowed { c.info("stage labels: close-first adoption suppressed by the write-back gate; original left open on the keep-open path", append(logArgs, "writeback_reason", d.Reason, "writeback_detail", d.Detail)...) return 0, nil } diff --git a/src/pkg/github/automerge/automerge_adoption_close_first_test.go b/src/pkg/github/automerge/automerge_adoption_close_first_test.go index 723a5f44db..310d708e56 100644 --- a/src/pkg/github/automerge/automerge_adoption_close_first_test.go +++ b/src/pkg/github/automerge/automerge_adoption_close_first_test.go @@ -9,6 +9,8 @@ import ( "testing" "time" + "github.com/hivecommons/hive/pkg/authorkind" + "github.com/hivecommons/hive/pkg/config" "github.com/hivecommons/hive/pkg/delegatedecision" hgithub "github.com/hivecommons/hive/pkg/github" "github.com/hivecommons/hive/pkg/stagelabels" @@ -341,6 +343,9 @@ func TestAdoptionCloseFirstReopenPingPongGuard(t *testing.T) { type closeFirstGateState struct { adoptOff bool paused bool + // requireLabel keeps the contributor_adopt kind's default opt-in label + // requirement (the live hive's needs-opt-in-label refusal on #15526). + requireLabel bool } // installWritebackGate puts a write-back gate on the harness's client at @@ -355,12 +360,12 @@ func (h *closeFirstHarness) installWritebackGate(st *closeFirstGateState) *write return writeback.RepoPauseInfo{By: "ops", Reason: "freeze"}, st.paused }, Config: func() writeback.Config { - one, no, yes, ownOnly := 1, false, true, st.adoptOff + one, no, yes, ownOnly, adoptLabel := 1, false, true, st.adoptOff, st.requireLabel return writeback.Config{ Unsolicited: writeback.UnsolicitedConfig{Backfill: &yes}, Kinds: map[string]writeback.KindPolicyOverride{ string(writeback.KindStageLabel): {MinLevel: &one, RequireLabel: &no}, - string(writeback.KindContributorAdopt): {MinLevel: &one, RequireLabel: &no, OwnOnly: &ownOnly}, + string(writeback.KindContributorAdopt): {MinLevel: &one, RequireLabel: &adoptLabel, OwnOnly: &ownOnly}, }, } }, @@ -436,6 +441,93 @@ func TestAdoptionCloseFirstWritebackGate(t *testing.T) { }) } +// hivecommons/hive#15526: with the contributor_adopt kind requiring a repo +// opt-in label (the default), an agent-authored original the hive has +// re-authored closes on adopt by policy (close_superseded: on_adopt, +// writeback.ReasonSupersededAgentPR); on_merge leaves it to the merge-time +// close. A person's original still needs the label (TestCloseFirstGateItem +// and the gate's own decision table). +func TestAdoptionCloseFirstSupersededAgentPolicy(t *testing.T) { + run := func(t *testing.T, policy StageLabelPolicy) (*closeFirstHarness, *writeback.Gate, func()) { + t.Helper() + h, done := newCloseFirstHarness(t, policy) + gate := h.installWritebackGate(&closeFirstGateState{requireLabel: true}) + h.adoptCloseFirst() + return h, gate, done + } + t.Run("clanker original closes on adopt without the label", func(t *testing.T) { + h, gate, done := run(t, closeFirstPolicy()) + defer done() + if len(h.adopt.pulls) != 1 { + t.Fatalf("copy not opened: pulls=%d", len(h.adopt.pulls)) + } + if len(h.adopt.prEdits) != 1 || h.adopt.prEdits[0] != "7:closed" { + t.Fatalf("original not closed: %v", h.adopt.prEdits) + } + if c := adoptionComments(h.api); len(c) != 1 || !strings.Contains(c[0], "close_first=true") || !strings.Contains(c[0], "same commits and sign-off") { + t.Fatalf("comments: %v", h.api.comments) + } + if rec := h.record(); !rec.SupersededClosedFirst || rec.SupersededBy != 90 || rec.SupersededOpen { + t.Fatalf("record = %+v", rec) + } + if s := suppressedFor(gate, 7, writeback.KindContributorAdopt); len(s) != 0 { + t.Fatalf("suppressed = %+v", s) + } + }) + t.Run("on_merge leaves a clanker original open until the copy merges", func(t *testing.T) { + p := closeFirstPolicy() + p.AdoptCloseSuperseded = config.AdoptionCloseSupersededOnMerge + h, gate, done := run(t, p) + defer done() + if len(h.adopt.pulls) != 1 || len(h.adopt.prEdits) != 0 { + t.Fatalf("pulls=%d edits=%v", len(h.adopt.pulls), h.adopt.prEdits) + } + if c := adoptionComments(h.api); len(c) != 0 { + t.Fatalf("close-first note posted under on_merge: %v", c) + } + rec := h.record() + if rec.SupersededClosedFirst || rec.AdoptedBy != 90 { + t.Fatalf("record = %+v", rec) + } + // Not a gate refusal: nothing was asked of the gate. + if s := suppressedFor(gate, 7, writeback.KindContributorAdopt); len(s) != 0 { + t.Fatalf("suppressed = %+v", s) + } + }) +} + +// closeFirstGateItem: only an agent-authored original names the copy for the +// gate; a person's never does, whatever close_superseded says. +func TestCloseFirstGateItem(t *testing.T) { + obs := func(kind authorkind.Kind) stageObservation { + return stageObservation{Number: 7, Author: "odttlnt", AuthorKind: kind, Labels: []string{"stage/072-returned-to-contributor"}} + } + onAdopt, onMerge := closeFirstPolicy(), closeFirstPolicy() + onMerge.AdoptCloseSuperseded = config.AdoptionCloseSupersededOnMerge + for _, tc := range []struct { + name string + kind authorkind.Kind + policy StageLabelPolicy + agent bool + by int + onMerge bool + }{ + {"clanker default", authorkind.Clanker, onAdopt, true, 90, false}, + {"hive default", authorkind.Hive, onAdopt, true, 90, false}, + {"clanker on_merge", authorkind.Clanker, onMerge, false, 0, true}, + {"human default", authorkind.Human, onAdopt, false, 0, false}, + {"human on_merge", authorkind.Human, onMerge, false, 0, false}, + {"unknown default", authorkind.Unknown, onAdopt, false, 0, false}, + } { + t.Run(tc.name, func(t *testing.T) { + item, onMerge := closeFirstGateItem(obs(tc.kind), tc.policy, 90) + if item.AgentAuthored != tc.agent || item.SupersededBy != tc.by || onMerge != tc.onMerge || item.Number != 7 || item.Author != "odttlnt" || !item.IsPR { + t.Fatalf("item=%+v onMerge=%v", item, onMerge) + } + }) + } +} + // A paused repo gets no reopen while paused; the record stays due its poll // and the reopen lands once the pause lifts. func TestAdoptionCloseFirstReopenWaitsForWritebackGate(t *testing.T) { diff --git a/src/pkg/github/automerge/automerge_stage_labels.go b/src/pkg/github/automerge/automerge_stage_labels.go index f9cedf20a6..73acfa5582 100644 --- a/src/pkg/github/automerge/automerge_stage_labels.go +++ b/src/pkg/github/automerge/automerge_stage_labels.go @@ -106,6 +106,14 @@ type StageLabelPolicy struct { // hivecommons/hive#15135). Off, the original stays open at 074 until // the copy merges. AdoptSupersedeCloseFirst bool + // AdoptCloseSuperseded is governor.labels.stage.adoption.close_superseded + // (config.AdoptionCloseSuperseded*): when an agent-authored original + // (author/clanker, author/hive) closes once the hive's copy exists. + // "" or on_adopt closes it in the adopting pass by policy, without the + // write-back opt-in label the contributor_adopt kind otherwise needs; + // on_merge leaves it open until the copy merges. Human-authored + // originals always take the gated path. + AdoptCloseSuperseded string // DCORequired resolves the per-repo `governor.labels.stage.dco.required` // override for "owner/repo"; ok false means "detect" (a DCO context in // the branch's required checks or on the head). nil = always detect. diff --git a/src/pkg/writeback/gate.go b/src/pkg/writeback/gate.go index 1a74b8bd34..9349fd9cf4 100644 --- a/src/pkg/writeback/gate.go +++ b/src/pkg/writeback/gate.go @@ -27,6 +27,16 @@ type Item struct { // an attributed relay PR, or an issue the hive filed. Own items are // never gated (except per-repo mode off). HiveAuthored bool + // AgentAuthored is true when the author is an agent rather than a + // person: a contributor's clanker (author/clanker) or another hive. + // With SupersededBy it lets the adoption kind close the item by + // policy (ReasonSupersededAgentPR). + AgentAuthored bool + // SupersededBy is the hive's own pull request that carries this item's + // commits (the supersede adoption's copy), 0 when none. Set only by a + // caller whose policy closes superseded originals on adopt + // (governor.labels.stage.adoption.close_superseded: on_adopt). + SupersededBy int // Labels is the item's current label set. Labels []string // CreatedAt is the item's creation time; the backfill guard compares it @@ -65,6 +75,13 @@ const ( // quiet on the repo, and the advisory digest edit that kept landing on // a paused torch-spyre showed that "unsolicited only" was not enough. ReasonRepoPaused = "repo-paused" + // ReasonSupersededAgentPR allows the adoption kind on an agent-authored + // PR the hive has re-authored as its own copy (hivecommons/hive#15526 + // stayed open at "superseded" for want of an opt-in label): the pair + // is one logical PR and the copy carries the author's commits and + // sign-off, so the close is the hive's own housekeeping, not an + // unsolicited write on a person's work. + ReasonSupersededAgentPR = "superseded-agent-pr" ) // RepoPauseInfo is the provenance of an operator pause, as config records @@ -425,6 +442,13 @@ func (g *Gate) decideLocked(repo string, item Item, kind Kind) Decision { if p.OwnOnly { return Decision{Reason: ReasonOwnOnly, Detail: fmt.Sprintf("%s only ever writes on hive-authored items; #%d is by %s", kind, item.Number, item.Author)} } + // An agent's PR the hive re-authored as its own copy: the close is + // housekeeping on one logical PR of the hive's, so neither the level + // nor the opt-in label applies (an operator's own_only / repo mode / + // pause above still do). + if kind == KindContributorAdopt && item.AgentAuthored && item.SupersededBy > 0 { + return Decision{Allowed: true, Reason: ReasonSupersededAgentPR, Detail: fmt.Sprintf("#%d is agent-authored and the hive's copy #%d carries its commits; close_superseded is on_adopt", item.Number, item.SupersededBy)} + } level := 0 if g.deps.LevelFor != nil { level = g.deps.LevelFor(repo) diff --git a/src/pkg/writeback/writeback_test.go b/src/pkg/writeback/writeback_test.go index 328f78ffa5..66c71aa97b 100644 --- a/src/pkg/writeback/writeback_test.go +++ b/src/pkg/writeback/writeback_test.go @@ -18,6 +18,12 @@ var ( humanPR = Item{Number: 10, IsPR: true, Author: "maintainer", CreatedAt: t0.Add(time.Hour)} optedPR = Item{Number: 11, IsPR: true, Author: "maintainer", Labels: []string{"Hive-Review"}, CreatedAt: t0.Add(time.Hour)} ownPR = Item{Number: 12, IsPR: true, Author: "hive[bot]", HiveAuthored: true, CreatedAt: t0.Add(time.Hour)} + // clankerSuperseded is a contributor's clanker PR the hive re-authored + // as its copy #90 (hivecommons/hive#15526); humanSuperseded the same + // for a person's PR. + clankerSuperseded = Item{Number: 13, IsPR: true, Author: "odttlnt", AgentAuthored: true, SupersededBy: 90, CreatedAt: t0.Add(time.Hour)} + humanSuperseded = Item{Number: 14, IsPR: true, Author: "maintainer", SupersededBy: 90, CreatedAt: t0.Add(time.Hour)} + clankerAdopting = Item{Number: 15, IsPR: true, Author: "odttlnt", AgentAuthored: true, CreatedAt: t0.Add(time.Hour)} ) func newGate(t *testing.T, cfg Config, level int) (*Gate, *bytes.Buffer) { @@ -169,6 +175,16 @@ func TestDecisionTable(t *testing.T) { {"no-label kind by level", Config{Kinds: map[string]KindPolicyOverride{"claim_comment": {RequireLabel: boolp(false)}}}, 4, humanPR, KindClaimComment, true, ReasonLevel}, {"no-label kind below", Config{Kinds: map[string]KindPolicyOverride{"claim_comment": {RequireLabel: boolp(false)}}}, 3, humanPR, KindClaimComment, false, ReasonBelowLevel}, {"unknown kind fails closed", Config{}, 6, optedPR, Kind("mystery"), false, ReasonOwnOnly}, + // Adoption close of a superseded original (hivecommons/hive#15526): + // agent-authored with the hive's copy on record closes by policy, + // no opt-in label needed; a person's PR, or an agent PR before its + // copy exists, still needs the label; other kinds are unchanged. + {"adopt close superseded clanker L6", Config{}, 6, clankerSuperseded, KindContributorAdopt, true, ReasonSupersededAgentPR}, + {"adopt close superseded clanker L1", Config{}, 1, clankerSuperseded, KindContributorAdopt, true, ReasonSupersededAgentPR}, + {"adopt close superseded human L6", Config{}, 6, humanSuperseded, KindContributorAdopt, false, ReasonNeedsLabel}, + {"adopt clanker no copy yet L6", Config{}, 6, clankerAdopting, KindContributorAdopt, false, ReasonNeedsLabel}, + {"sentinel on superseded clanker", Config{}, 5, clankerSuperseded, KindSentinel, false, ReasonNeedsLabel}, + {"adopt close superseded repo off", Config{PerRepo: map[string]RepoOverride{"org/repo": {Mode: RepoModeOff}}}, 6, clankerSuperseded, KindContributorAdopt, false, ReasonRepoOff}, } for _, tc := range cases { t.Run(tc.name, func(t *testing.T) { @@ -340,6 +356,7 @@ func TestRepoPausedRefusesEveryKind(t *testing.T) { {"issue file", "org/repo", Item{}, KindIssueFile}, {"stage label opted", "org/repo", optedPR, KindStageLabel}, {"case-insensitive repo", "org/repo", ownPR, KindClaimComment}, + {"superseded agent PR close", "org/repo", clankerSuperseded, KindContributorAdopt}, } for _, tc := range cases { t.Run(tc.name, func(t *testing.T) {