From 33bb88a1e6e1b0330f282f00980937b9f9139888 Mon Sep 17 00:00:00 2001 From: Andrew Anderson Date: Thu, 29 Oct 2026 23:34:18 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Adopt=20now=20overrides=20an=20e?= =?UTF-8?q?arlier=20Approve;=20approve=20no=20longer=20deadlocks=20an=20un?= =?UTF-8?q?mergeable=20head?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A maintainer's Approve on a contributor PR whose fork the App cannot update (behind the base, fork-not-editable) locked the PR into 'merge as-is' while the merge itself failed every cycle, and Adopt now left the row saying 'not adopted … the hive merges it as-is' with the action still offered until the sweep landed minutes later. - adoptionRefusedByAdmission stands down only when the head is mergeable as-is; otherwise the hive adopts and carries the approval to its copy (decision approval on the copy head + body note). - NoteAdoptionForced clears the adoption blocker; the tracker renders the acted state (adoption.queued_by, takeover.forced_by, adopt_now=false, no decision popover) and the SPA hides Adopt now and shows 'adopting… (queued)'. - Adopt now answers adoption-queued when the copy has not opened within the wait instead of claiming the running pass will open it. - Tests (Go + node), operator-reference docs, changelog fragment. Signed-off-by: Andrew Anderson --- changelog.d/fixed-adopt-overrides-approve.md | 1 + src/docs/operator-reference.md | 41 ++++++++- .../api_repo_item_decision_reroute.go | 12 ++- .../dashboard/api_repo_item_takeover_test.go | 49 +++++++++- .../stage_tracker_adopt_queued.test.js | 72 +++++++++++++++ src/pkg/dashboard/stage_tracker_adoption.go | 24 ++++- src/pkg/dashboard/stage_tracker_decision.go | 3 + .../dashboard/stage_tracker_presence.test.js | 2 + src/pkg/dashboard/stage_tracker_takeover.go | 16 +++- .../dashboard/static-src/js/tracker-words.js | 26 ++++-- src/pkg/dashboard/static/index.html | 26 ++++-- .../automerge/automerge_contributor_adopt.go | 18 +++- .../automerge/automerge_operator_admission.go | 58 +++++++++++- .../automerge_operator_admission_test.go | 92 +++++++++++++++++++ src/pkg/stagelabels/store.go | 6 +- 15 files changed, 419 insertions(+), 27 deletions(-) create mode 100644 changelog.d/fixed-adopt-overrides-approve.md create mode 100644 src/pkg/dashboard/stage_tracker_adopt_queued.test.js diff --git a/changelog.d/fixed-adopt-overrides-approve.md b/changelog.d/fixed-adopt-overrides-approve.md new file mode 100644 index 0000000000..a258ee0bb1 --- /dev/null +++ b/changelog.d/fixed-adopt-overrides-approve.md @@ -0,0 +1 @@ +- Approve no longer deadlocks a contributor PR the hive cannot merge as-is: when the approved head is on a fork the App cannot update and sits behind the base (`fork-not-editable`), conflicts, or lacks a sign-off, the admission no longer records `not adopted: a maintainer approved this head; the hive merges it as-is` — the hive adopts and carries the approval to its copy. Adopt now always wins over an earlier Approve: recording it clears the admission blocker at once, the row immediately reads *adopting… (queued)* with the Adopt now action gone from the menu and popover, and the decision response says `adoption-queued` instead of promising the running pass when the copy has not opened yet. diff --git a/src/docs/operator-reference.md b/src/docs/operator-reference.md index c0f9c92a27..23a5e1d0c8 100644 --- a/src/docs/operator-reference.md +++ b/src/docs/operator-reference.md @@ -503,6 +503,40 @@ the engine derives it from the recorded approval and writes it back. An explicit **Adopt** / **Re-author** from the dashboard is the person choosing re-authoring and is not refused. +**Approve means "approved to proceed", not "merge this exact head whatever +happens".** The merge-as-is hold applies only while the head *is* mergeable +as-is. When the lane cannot land the approved head unchanged — the fork is +not editable by the App and sits behind the base (`fork-not-editable`), +it conflicts (`conflicting` / `not-mergeable` / `needs-rebase`), or a +commit lacks `Signed-off-by` (`dco-missing`) — the admission does not +block adoption: the hive adopts (re-authors the commits on a hive-owned +branch) and **carries the approval to its copy** (a decision approval +recorded on the copy's head; the copy's body says *Approval carried over: +@you approved #N at head …*). Logged as `a person admitted this head but +the hive cannot merge it as-is; adopting and carrying the approval`. Before +this, an approved fork PR that fell behind `v5` deadlocked: every cycle +refused adoption (*not adopted: a maintainer approved this head; the hive +merges it as-is*) while the merge itself failed on `fork-not-editable`. + +**Adopt now always wins over an earlier Approve.** Recording the forced +adoption clears the `operator-admission` blocker at once, and the adoption +engine bypasses admission, presence, grace and `maintainer_policy` on its +next pass. The response is honest about timing: `status: adopted-now` with +the copy's number when the nudged pass opened it within the handler's wait, +else `status: adoption-queued` (*Adopting… (queued): the hive opens its copy +on its next stage pass*). Either way the row is in its acted state the +moment you click — `adoption.queued_by` / `takeover.forced_by` on the +payload, chip *adopting… (queued)*, caption *Adopting… (queued by @you …)*, +no *not adopted* blocker, **Adopt now** gone from the ⋯ menu and the +popover, no decision popover asking again — until the sweep lands and the +row reads *Adopted → #N*. + +| You | Head mergeable as-is | Head not mergeable as-is (fork not editable + behind, conflicting, DCO missing) | +|---|---|---| +| **Approve** | admitted; hive merges it unchanged after checks and soak; no adoption | hive adopts (supersede), approval carried to the copy | +| **Adopt** / **Re-author** | hive adopts on the next pass (grace and policy still apply to a plain Adopt) | same | +| **Adopt now** (`force: true`) | hive adopts on the next pass regardless of an earlier Approve, presence, grace, policy; row acted at once | same | + | Decision | What it does | Audit / ledger | |---|---|---| | `re-author` — *Re-author as hive PR* | Offered as its own lead action on a 090 PR whose head cannot merge as-is — the stage record's commit check counted commits without a `Signed-off-by` (`dco_unsigned` / `dco_total` on the row). The popover and both Approve confirms say so **before** acting (*2 of 3 commits have no Signed-off-by, so a required DCO check refuses the merge*); approving never re-authors by itself. Re-author posts its own note and the `adoption/supersede` request label; the hive re-homes the commits on a hive-owned, signed-off branch and opens a superseding PR. Disabled with the reason on a person's PR (the hive does not re-author a human's PR — ask them to `git commit -s --amend`). | `repo_item_decision_adopt` with `decision=re-author`; `last_operator_action.action: re-author`; toast *adopted*. | @@ -791,8 +825,11 @@ Dashboard: Settings → Labels → "When the PR author maintains the repository". Whatever the policy and the clocks say, the row's ⋯ menu on a 072 / 071 clanker PR offers the operator **Adopt now — hive takes it over** (decision API `adopt` + `force: true`: supersede adoption on the next nudged -sweep, bypassing presence, grace and `maintainer_policy`; `hold` still -stops it; marker `hive:adopted reason=operator-forced by=@login`) and +sweep, bypassing presence, grace, `maintainer_policy` and an earlier +Approve's admission; `hold` still stops it; marker `hive:adopted +reason=operator-forced by=@login`; the row shows *adopting… (queued)* and +drops the action until the copy opens — see *Adopt now always wins over an +earlier Approve* above) and **Reroute to another clanker** (decision API `reroute` + `to: |any`: the follow-up work goes to an online contributor clanker's fix queue as a `fix-pr` interrupt — the same mechanism as the 072 nudge — with a diff --git a/src/pkg/dashboard/api_repo_item_decision_reroute.go b/src/pkg/dashboard/api_repo_item_decision_reroute.go index 4f54a0675c..8ad7bf7523 100644 --- a/src/pkg/dashboard/api_repo_item_decision_reroute.go +++ b/src/pkg/dashboard/api_repo_item_decision_reroute.go @@ -156,6 +156,12 @@ func (s *Server) nudgeSweepAndAwaitAdoption(ctx context.Context, store *stagelab return rec.AdoptedBy } +// repoItemDecisionStatusAdoptionQueued is Adopt now's status when the sweep +// has not opened the copy within the handler's wait: queued, not done. The +// earlier "adoption-forced" wording claimed the pass now running would open +// it, which the tracker then contradicted for minutes. +const repoItemDecisionStatusAdoptionQueued = "adoption-queued" + func repoItemAdoptNowResponse(repoFull string, number, superseding int) repoItemDecisionResponse { out := repoItemDecisionResponse{OK: true, Repo: repoFull, Number: number, Decision: repoItemDecisionAdopt, Label: delegatedecision.LabelAdoptSupersede, Result: &RowActionResult{Target: rowActionTarget(repoFull, "pr", number), Action: rowActionAdopted}} @@ -165,9 +171,9 @@ func repoItemAdoptNowResponse(repoFull string, number, superseding int) repoItem out.Result.Next = fmt.Sprintf("The hive rebases and fixes CI on #%d; the author's commits and sign-off are preserved.", superseding) return out } - 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 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." + out.Status = repoItemDecisionStatusAdoptionQueued + out.Result.Outcome = "Adopting… (queued): the hive opens its copy on its next stage pass; any earlier approval of this head no longer holds it." + out.Result.Next = "The row reads \"Adopting… (queued)\" until the pass lands, then \"Adopted → #N\". The contributor PR closes as superseded (an agent's PR in the adopting pass, a person's when the hive's copy merges); the author's commits and sign-off are preserved." return out } diff --git a/src/pkg/dashboard/api_repo_item_takeover_test.go b/src/pkg/dashboard/api_repo_item_takeover_test.go index 9aa8d18715..2c5f97692c 100644 --- a/src/pkg/dashboard/api_repo_item_takeover_test.go +++ b/src/pkg/dashboard/api_repo_item_takeover_test.go @@ -105,9 +105,12 @@ func TestRepoItemAdoptNowWithoutSweepIsQueuedForm(t *testing.T) { w := postRepoItemDecision(t, srv, 8, "writer", `{"decision":"adopt","force":true,"type":"pr"}`) out := decodeDecision(t, w.Body.String()) - if w.Code != http.StatusOK || out.Status != "adoption-forced" || !strings.HasPrefix(out.Result.Outcome, "Adoption forced:") { + if w.Code != http.StatusOK || out.Status != repoItemDecisionStatusAdoptionQueued || !strings.HasPrefix(out.Result.Outcome, "Adopting… (queued)") || out.Result.Action != rowActionAdopted { t.Fatalf("code=%d out=%+v", w.Code, out) } + if strings.Contains(out.Result.Outcome, "pass now running") { + t.Fatalf("queued adoption promised the running pass: %q", out.Result.Outcome) + } rec, _ := store.Get(stagelabels.Key("testorg/testrepo", 8)) if rec.AdoptForcedBy != "writer" || !recForced(rec) { t.Fatalf("forced mark missing: %+v", rec) @@ -323,6 +326,50 @@ func TestStageTrackerTakeoverOffersAdoptNowAndReroute(t *testing.T) { } } +// Approve, then Adopt now (hive#15312): the moment Adopt now is recorded +// the row is in its acted state — "Adopting… (queued by @x)", no "not +// adopted: a maintainer approved this head", no Adopt now action, no +// decision popover asking the person to take it over again. +func TestStageTrackerTakeoverQueuedAfterAdoptNow(t *testing.T) { + now := time.Date(2026, 10, 28, 16, 0, 0, 0, time.UTC) + s, store, status := adoptionFixture(t, now, config.AdoptionMaintainerPolicyNever, offlinePresence(now.Add(-26*time.Hour))) + s.rerouteCandidates = func(string) []RerouteCandidate { return []RerouteCandidate{{Login: "bee2", Capable: true}} } + key := stagelabels.Key("hivecommons/hive", 14524) + store.NoteAdmission(key, "feed", stagelabels.OperatorApprovalAdmission("andan02"), now.Add(-10*time.Minute)) + store.NoteAdoptionBlocked(key, "feed", stagelabels.AdoptBlockedOperatorAdmission, now.Add(-9*time.Minute)) + it := trackerItem(t, s.buildStageTracker(status, store, now), "pr", 14524) + if it.Adoption == nil || it.Adoption.BlockedBy != stagelabels.AdoptBlockedOperatorAdmission || !strings.Contains(it.Adoption.Text, "a maintainer approved this head") || it.Takeover == nil || !it.Takeover.AdoptNow { + t.Fatalf("precondition (approved, blocked, Adopt now offered): adoption=%+v takeover=%+v", it.Adoption, it.Takeover) + } + + store.NoteAdoptionForced(key, "andan02", now.Add(-time.Minute)) + it = trackerItem(t, s.buildStageTracker(status, store, now), "pr", 14524) + a, tk := it.Adoption, it.Takeover + if a == nil || a.QueuedBy != "andan02" || a.BlockedBy != "" || a.Action != "" || !strings.HasPrefix(a.Text, "Adopting… (queued by @andan02") { + t.Fatalf("adoption after Adopt now = %+v", a) + } + if tk == nil || tk.AdoptNow || tk.AdoptNowReason != takeoverAdoptNowQueued || tk.ForcedBy != "andan02" || !tk.Reroute { + t.Fatalf("takeover after Adopt now = %+v", tk) + } + if it.DecisionNeeded != nil { + t.Fatalf("queued adoption still asks a person: %+v", it.DecisionNeeded) + } + if strings.Contains(it.Caption, "not adopted") { + t.Fatalf("caption still says not adopted: %q", it.Caption) + } + for _, o := range takeoverDecisionOptions(tk, false) { + if o.Action == decisionActionAdoptNow { + t.Fatalf("Adopt now still offered in the popover: %+v", o) + } + } + raw, _ := json.Marshal(it) + for _, want := range []string{`"queued_by":"andan02"`, `"forced_by":"andan02"`, `"adopt_now":false`} { + if !strings.Contains(string(raw), want) { + t.Errorf("payload lacks %s: %s", want, raw) + } + } +} + func TestStageTrackerTakeoverDisabledReasons(t *testing.T) { now := time.Date(2026, 10, 28, 16, 0, 0, 0, time.UTC) s, store, status := adoptionFixture(t, now, config.AdoptionMaintainerPolicyNever, offlinePresence(now.Add(-26*time.Hour))) diff --git a/src/pkg/dashboard/stage_tracker_adopt_queued.test.js b/src/pkg/dashboard/stage_tracker_adopt_queued.test.js new file mode 100644 index 0000000000..0eae9cdc3d --- /dev/null +++ b/src/pkg/dashboard/stage_tracker_adopt_queued.test.js @@ -0,0 +1,72 @@ +// Adopt now's acted state on the Activity Monitor row (hive#15312: the +// maintainer pressed Adopt now on PRs they had approved earlier and the rows +// kept reading "not adopted: a maintainer approved this head" and offering +// Adopt now again until the sweep landed minutes later). Once the payload +// carries `adoption.queued_by` / `takeover.forced_by` the chip reads +// "adopting… (queued)" and the ⋯ menu no longer offers Adopt now. The +// helpers are lifted out of index.html so this runs against the shipped +// source. +const test = require('node:test'); +const assert = require('node:assert'); +const fs = require('node:fs'); +const path = require('node:path'); + +const html = fs.readFileSync(path.join(__dirname, 'static', 'index.html'), 'utf8'); + +function pick(re, what) { + const m = html.match(re); + assert.ok(m, what + ' not found in index.html'); + return m[0]; +} + +const src = [ + pick(/const STAGE_TRACKER_ACTION_LABELS = \{[\s\S]*?\n \};\n/, 'STAGE_TRACKER_ACTION_LABELS'), + pick(/const STAGE_TRACKER_WHY_WRITE = [^\n]*\n/, 'STAGE_TRACKER_WHY_WRITE'), + pick(/function stageTrackerAdoptOffered\(item\) \{[\s\S]*?\n \}\n/, 'stageTrackerAdoptOffered'), + pick(/const STAGE_TRACKER_ADOPTION_QUEUED_CHIP = [^\n]*\n/, 'STAGE_TRACKER_ADOPTION_QUEUED_CHIP'), + pick(/function stageTrackerAdoptionQueued\(item\) \{[\s\S]*?\n \}\n/, 'stageTrackerAdoptionQueued'), + pick(/function stageTrackerAdoptionChipText\(item\) \{[\s\S]*?\n \}\n/, 'stageTrackerAdoptionChipText'), + pick(/const STAGE_TRACKER_ADOPT_NOW_CONSEQUENCE = [^\n]*\n/, 'STAGE_TRACKER_ADOPT_NOW_CONSEQUENCE'), + pick(/const STAGE_TRACKER_REROUTE_ANY = [^\n]*\n/, 'STAGE_TRACKER_REROUTE_ANY'), + pick(/const STAGE_TRACKER_REROUTE_PREFIX = [^\n]*\n/, 'STAGE_TRACKER_REROUTE_PREFIX'), + pick(/function stageTrackerTakeoverOf\(item\) \{[\s\S]*?\n \}\n/, 'stageTrackerTakeoverOf'), + pick(/function stageTrackerClankerLabel\(c, nowMs\) \{[\s\S]*?\n \}\n/, 'stageTrackerClankerLabel'), + pick(/function stageTrackerRerouteOptions\(tk, enabled, why, nowMs\) \{[\s\S]*?\n \}\n/, 'stageTrackerRerouteOptions'), + pick(/function stageTrackerTakeoverActions\(item, ctx, nowMs\) \{[\s\S]*?\n \}\n/, 'stageTrackerTakeoverActions'), +].join('\n'); +const api = new Function(src + '; return { chipText: stageTrackerAdoptionChipText, queued: stageTrackerAdoptionQueued, actions: stageTrackerTakeoverActions };')(); + +const ctx = { user: 'clubanderson', canHold: true }; +function row(over) { + return Object.assign({ + repo: 'hivecommons/hive', number: 15312, kind: 'pr', stage: 72, + adoption: { author: 'odttlnt', due: true, blocked_by: 'operator-admission', nudges: 3, author_online: false, text: 'waiting on @odttlnt (offline 18m) — not adopted: a maintainer approved this head; the hive merges it as-is' }, + takeover: { author: 'odttlnt', author_online: false, adopt_now: true, reroute: false, reroute_reason: 'no other clanker is online' }, + }, over || {}); +} + +test('before Adopt now: the approved-head blocker shows and Adopt now is offered', () => { + const it = row(); + assert.equal(api.queued(it), false); + assert.equal(api.chipText(it), 'not adopted'); + const adopt = api.actions(it, ctx).find(a => a.id === 'decide:adopt-now'); + assert.ok(adopt && adopt.enabled, 'Adopt now offered'); +}); + +test('after Adopt now: acted state — "adopting… (queued)", no Adopt now action, Reroute still listed', () => { + const it = row({ + adoption: { author: 'odttlnt', due: true, queued_by: 'clubanderson', nudges: 3, author_online: false, text: 'Adopting… (queued by @clubanderson; the hive opens its copy on the next stage pass)' }, + takeover: { author: 'odttlnt', author_online: false, adopt_now: false, adopt_now_reason: 'adoption already queued', forced_by: 'clubanderson', forced_at: '2026-10-30T03:16:58Z', reroute: false, reroute_reason: 'no other clanker is online' }, + }); + assert.equal(api.queued(it), true); + assert.equal(api.chipText(it), 'adopting… (queued)'); + const acts = api.actions(it, ctx); + assert.ok(!acts.some(a => a.id === 'decide:adopt-now'), 'Adopt now must not be offered again: ' + JSON.stringify(acts)); + assert.ok(acts.some(a => a.id === 'decide:reroute'), 'Reroute stays listed'); +}); + +test('forced_by alone (older payload without adoption.queued_by) is enough for the acted state', () => { + const it = row({ takeover: { author: 'odttlnt', adopt_now: true, forced_by: 'clubanderson', reroute: false } }); + assert.equal(api.chipText(it), 'adopting… (queued)'); + assert.ok(!api.actions(it, ctx).some(a => a.id === 'decide:adopt-now')); +}); diff --git a/src/pkg/dashboard/stage_tracker_adoption.go b/src/pkg/dashboard/stage_tracker_adoption.go index 874524fe8a..09c8e55c72 100644 --- a/src/pkg/dashboard/stage_tracker_adoption.go +++ b/src/pkg/dashboard/stage_tracker_adoption.go @@ -52,6 +52,10 @@ type StageTrackerAdoption struct { // Action is the row action that lifts the hold ("decide:adopt"), "" // when nothing is the owner's to decide. Action string `json:"action,omitempty"` + // QueuedBy is the operator whose Adopt now is waiting for the sweep: + // the row is in its acted state ("Adopting… (queued by @x)") and no + // blocker or adopt action is shown. + QueuedBy string `json:"queued_by,omitempty"` // Text is the plain-words pill/tooltip: "waiting on @hanthor // (maintainer, offline 26h) — adopt?". Text string `json:"text"` @@ -116,6 +120,20 @@ func stageTrackerAdoption(it StageTrackerItem, rec stagelabels.Record, hasRec bo out.Text = stageTrackerAdoptionText(it.Author, *out, now) return out } + if rec.AdoptedHead != "" && (it.Head == "" || rec.Adopted(it.Head) || rec.AdoptedInPlace()) { + return nil + } + if by, ok := rec.AdoptionForced(); ok { + // An operator pressed Adopt now and the sweep has not landed yet: + // the row reads as acted on, whatever held adoption before. + out := &StageTrackerAdoption{Author: it.Author, Policy: policy, Due: true, QueuedBy: by, Nudges: rec.NudgeCount} + if !rec.AdoptForcedAt.IsZero() { + since := rec.AdoptForcedAt + out.Since = &since + } + out.Text = stageTrackerAdoptionText(it.Author, *out, now) + return out + } if rec.NudgeCount == 0 || rec.NudgeStart().IsZero() { return nil } @@ -124,9 +142,6 @@ func stageTrackerAdoption(it StageTrackerItem, rec stagelabels.Record, hasRec bo // next sweep; nothing to say about adoption yet. return nil } - if rec.AdoptedHead != "" && (it.Head == "" || rec.Adopted(it.Head) || rec.AdoptedInPlace()) { - return nil - } since := rec.NudgeStart() out := &StageTrackerAdoption{Author: it.Author, Since: &since, Nudges: rec.NudgeCount, Policy: policy} if presence != nil && it.Author != "" { @@ -166,6 +181,9 @@ func stageTrackerAdoptionText(author string, a StageTrackerAdoption, now time.Ti if a.BlockedBy == stagelabels.AdoptBlockedAuthorPerson { return who + " pushed this PR themselves — not adopted: the hive asks them, not adopts" } + if a.QueuedBy != "" { + return "Adopting… (queued by @" + a.QueuedBy + "; the hive opens its copy on the next stage pass)" + } var facts []string if a.AuthorMaintainer { facts = append(facts, "maintainer") diff --git a/src/pkg/dashboard/stage_tracker_decision.go b/src/pkg/dashboard/stage_tracker_decision.go index 910f3dad30..ed19a9299d 100644 --- a/src/pkg/dashboard/stage_tracker_decision.go +++ b/src/pkg/dashboard/stage_tracker_decision.go @@ -226,6 +226,9 @@ func stageTrackerDecisionNeededWith(it StageTrackerItem, verdict *review.Aggrega return decisionForUnauthorized(it, held) case it.Kind == "pr" && it.Adoption != nil && it.Adoption.Action == decisionActionAdopt: return decisionForAdoption(it, held, now) + case it.Kind == "pr" && it.Adoption != nil && it.Adoption.QueuedBy != "": + // Adopt now already pressed: nothing is asked until the sweep lands. + return nil case it.Kind == "pr" && it.Takeover != nil && it.Takeover.GraceElapsed && it.Adoption != nil && it.Adoption.BlockedBy != stagelabels.AdoptBlockedAuthorMaintainer: // The nudge grace ran out and the engine has not adopted (ask is // the case above; never stays the policy's word): the wait is a diff --git a/src/pkg/dashboard/stage_tracker_presence.test.js b/src/pkg/dashboard/stage_tracker_presence.test.js index 75f56ab359..25f98f9ddd 100644 --- a/src/pkg/dashboard/stage_tracker_presence.test.js +++ b/src/pkg/dashboard/stage_tracker_presence.test.js @@ -23,6 +23,8 @@ const src = [ pick(/function agentNowAgo\(ms\) \{[\s\S]*?\n \}\n/, 'agentNowAgo'), pick(/function stageTrackerAdoptionTip\(item\) \{[\s\S]*?\n \}\n/, 'stageTrackerAdoptionTip'), pick(/function stageTrackerAdoptOffered\(item\) \{[\s\S]*?\n \}\n/, 'stageTrackerAdoptOffered'), + pick(/const STAGE_TRACKER_ADOPTION_QUEUED_CHIP = [^\n]*\n/, 'STAGE_TRACKER_ADOPTION_QUEUED_CHIP'), + pick(/function stageTrackerAdoptionQueued\(item\) \{[\s\S]*?\n \}\n/, 'stageTrackerAdoptionQueued'), pick(/function stageTrackerAdoptionChipText\(item\) \{[\s\S]*?\n \}\n/, 'stageTrackerAdoptionChipText'), pick(/function stageTrackerAdoptionChipHtml\(item\) \{[\s\S]*?\n \}\n/, 'stageTrackerAdoptionChipHtml'), pick(/const STAGE_TRACKER_ICONS = \{[\s\S]*?\n \};\n/, 'STAGE_TRACKER_ICONS'), diff --git a/src/pkg/dashboard/stage_tracker_takeover.go b/src/pkg/dashboard/stage_tracker_takeover.go index e9db9ac12b..79d2c6cf28 100644 --- a/src/pkg/dashboard/stage_tracker_takeover.go +++ b/src/pkg/dashboard/stage_tracker_takeover.go @@ -69,6 +69,10 @@ const takeoverAdoptNowDisabledHold = "release the hold first" // takeoverAdoptNowDisabledOff is the reason when adoption is off on this hive. const takeoverAdoptNowDisabledOff = "adoption is disabled (governor.labels.stage.adoption.enabled)" +// takeoverAdoptNowQueued is the reason once Adopt now was pressed and the +// sweep has not landed yet: the action is spent, not offered again. +const takeoverAdoptNowQueued = "adoption already queued" + // stageTrackerRerouteCandidates returns the lookup for the online clankers a // reroute may target, excluding the PR's author. Tests inject // rerouteCandidates. @@ -102,7 +106,11 @@ func stageTrackerTakeover(it StageTrackerItem, rec stagelabels.Record, hasRec bo } } held := slices.Contains(it.Modifiers, modHold) + _, forcedPending := rec.AdoptionForced() + forcedPending = forcedPending && hasRec switch { + case forcedPending: + out.AdoptNowReason = takeoverAdoptNowQueued case !adoptionEnabled: out.AdoptNowReason = takeoverAdoptNowDisabledOff case held: @@ -210,10 +218,12 @@ func takeoverDecisionOptions(t *StageTrackerTakeover, held bool) []StageTrackerD if held && rerouteWhy == "" { rerouteWhy = "Release the hold first" } - return []StageTrackerDecisionOption{ - decisionOption(decisionActionAdoptNow, "Adopt now — hive takes it over", t.AdoptNow && !held, adoptWhy), - decisionOption(decisionActionReroute, "Reroute to another clanker", t.Reroute && !held, rerouteWhy), + out := []StageTrackerDecisionOption{} + if t.ForcedBy == "" { + // Spent once pressed: the row says "Adopting… (queued)" instead. + out = append(out, decisionOption(decisionActionAdoptNow, "Adopt now — hive takes it over", t.AdoptNow && !held, adoptWhy)) } + return append(out, decisionOption(decisionActionReroute, "Reroute to another clanker", t.Reroute && !held, rerouteWhy)) } // stageTrackerTakeoverCaption appends the reroute pill text to the caption. diff --git a/src/pkg/dashboard/static-src/js/tracker-words.js b/src/pkg/dashboard/static-src/js/tracker-words.js index a6506f99d8..2b05de813c 100644 --- a/src/pkg/dashboard/static-src/js/tracker-words.js +++ b/src/pkg/dashboard/static-src/js/tracker-words.js @@ -1302,10 +1302,22 @@ const a = item && item.kind === 'pr' ? item.adoption : null; return !!(a && a.due && a.action === 'decide:adopt'); } - // The chip text: "adopt?" when the owner is asked, else "waiting on @x". + // Whether an Adopt now is queued on the row (`adoption.queued_by` / + // `takeover.forced_by`): the operator already acted; the sweep has not + // opened the copy yet. The row reads as acted on and offers no Adopt. + const STAGE_TRACKER_ADOPTION_QUEUED_CHIP = 'adopting… (queued)'; + function stageTrackerAdoptionQueued(item) { + const a = item && item.kind === 'pr' ? item.adoption : null; + const tk = item && item.kind === 'pr' ? item.takeover : null; + return !!((a && a.queued_by) || (tk && tk.forced_by)); + } + // The chip text: "adopt?" when the owner is asked, "adopting… (queued)" + // once Adopt now was pressed, else "waiting on @x". function stageTrackerAdoptionChipText(item) { const a = item && item.adoption; if (!a) return ''; + // Guarded: the test harnesses load helpers by name. + if (typeof stageTrackerAdoptionQueued === 'function' && stageTrackerAdoptionQueued(item)) return STAGE_TRACKER_ADOPTION_QUEUED_CHIP; if (stageTrackerAdoptOffered(item)) return 'adopt?'; if (a.blocked_by) return 'not adopted'; // Guarded: the test harnesses load helpers by name. @@ -1550,14 +1562,16 @@ ctx = ctx || {}; const write = ctx.canHold !== false && !!ctx.user; const whyWrite = write ? '' : STAGE_TRACKER_WHY_WRITE; - const adoptOk = write && !!tk.adopt_now; + const adoptOk = write && !!tk.adopt_now && !tk.forced_by; const adoptWhy = adoptOk ? '' : (whyWrite || tk.adopt_now_reason || 'Not available on this row'); const rerouteOk = write && !!tk.reroute; const rerouteWhy = rerouteOk ? '' : (whyWrite || tk.reroute_reason || 'Not available on this row'); - return [ - { id: 'decide:adopt-now', label: STAGE_TRACKER_ACTION_LABELS['decide:adopt-now'] + '…', note: STAGE_TRACKER_ADOPT_NOW_CONSEQUENCE, enabled: adoptOk, why: adoptWhy, danger: true }, - { id: 'decide:reroute', label: STAGE_TRACKER_ACTION_LABELS['decide:reroute'], note: tk.rerouted && tk.rerouted.to ? 'rerouted → @' + tk.rerouted.to + ' already; pick again to move it' : (rerouteOk ? 'hands the reviewer\'s requested changes to another online clanker' : ''), enabled: rerouteOk, why: rerouteWhy, submenu: stageTrackerRerouteOptions(tk, rerouteOk, rerouteWhy, nowMs) }, - ]; + const out = []; + // Adopt now is spent once pressed: the row shows "adopting… (queued)" + // instead of offering the same action again (hivecommons/hive#15038). + if (!tk.forced_by) out.push({ id: 'decide:adopt-now', label: STAGE_TRACKER_ACTION_LABELS['decide:adopt-now'] + '…', note: STAGE_TRACKER_ADOPT_NOW_CONSEQUENCE, enabled: adoptOk, why: adoptWhy, danger: true }); + out.push({ id: 'decide:reroute', label: STAGE_TRACKER_ACTION_LABELS['decide:reroute'], note: tk.rerouted && tk.rerouted.to ? 'rerouted → @' + tk.rerouted.to + ' already; pick again to move it' : (rerouteOk ? 'hands the reviewer\'s requested changes to another online clanker' : ''), enabled: rerouteOk, why: rerouteWhy, submenu: stageTrackerRerouteOptions(tk, rerouteOk, rerouteWhy, nowMs) }); + return out; } // Pure: the "rerouted → @x" pill with the target's presence dot; '' when // the row is not rerouted. diff --git a/src/pkg/dashboard/static/index.html b/src/pkg/dashboard/static/index.html index fcf464087f..c57ec0dfea 100644 --- a/src/pkg/dashboard/static/index.html +++ b/src/pkg/dashboard/static/index.html @@ -15724,10 +15724,22 @@

Where to get help

const a = item && item.kind === 'pr' ? item.adoption : null; return !!(a && a.due && a.action === 'decide:adopt'); } - // The chip text: "adopt?" when the owner is asked, else "waiting on @x". + // Whether an Adopt now is queued on the row (`adoption.queued_by` / + // `takeover.forced_by`): the operator already acted; the sweep has not + // opened the copy yet. The row reads as acted on and offers no Adopt. + const STAGE_TRACKER_ADOPTION_QUEUED_CHIP = 'adopting… (queued)'; + function stageTrackerAdoptionQueued(item) { + const a = item && item.kind === 'pr' ? item.adoption : null; + const tk = item && item.kind === 'pr' ? item.takeover : null; + return !!((a && a.queued_by) || (tk && tk.forced_by)); + } + // The chip text: "adopt?" when the owner is asked, "adopting… (queued)" + // once Adopt now was pressed, else "waiting on @x". function stageTrackerAdoptionChipText(item) { const a = item && item.adoption; if (!a) return ''; + // Guarded: the test harnesses load helpers by name. + if (typeof stageTrackerAdoptionQueued === 'function' && stageTrackerAdoptionQueued(item)) return STAGE_TRACKER_ADOPTION_QUEUED_CHIP; if (stageTrackerAdoptOffered(item)) return 'adopt?'; if (a.blocked_by) return 'not adopted'; // Guarded: the test harnesses load helpers by name. @@ -15972,14 +15984,16 @@

Where to get help

ctx = ctx || {}; const write = ctx.canHold !== false && !!ctx.user; const whyWrite = write ? '' : STAGE_TRACKER_WHY_WRITE; - const adoptOk = write && !!tk.adopt_now; + const adoptOk = write && !!tk.adopt_now && !tk.forced_by; const adoptWhy = adoptOk ? '' : (whyWrite || tk.adopt_now_reason || 'Not available on this row'); const rerouteOk = write && !!tk.reroute; const rerouteWhy = rerouteOk ? '' : (whyWrite || tk.reroute_reason || 'Not available on this row'); - return [ - { id: 'decide:adopt-now', label: STAGE_TRACKER_ACTION_LABELS['decide:adopt-now'] + '…', note: STAGE_TRACKER_ADOPT_NOW_CONSEQUENCE, enabled: adoptOk, why: adoptWhy, danger: true }, - { id: 'decide:reroute', label: STAGE_TRACKER_ACTION_LABELS['decide:reroute'], note: tk.rerouted && tk.rerouted.to ? 'rerouted → @' + tk.rerouted.to + ' already; pick again to move it' : (rerouteOk ? 'hands the reviewer\'s requested changes to another online clanker' : ''), enabled: rerouteOk, why: rerouteWhy, submenu: stageTrackerRerouteOptions(tk, rerouteOk, rerouteWhy, nowMs) }, - ]; + const out = []; + // Adopt now is spent once pressed: the row shows "adopting… (queued)" + // instead of offering the same action again (hivecommons/hive#15038). + if (!tk.forced_by) out.push({ id: 'decide:adopt-now', label: STAGE_TRACKER_ACTION_LABELS['decide:adopt-now'] + '…', note: STAGE_TRACKER_ADOPT_NOW_CONSEQUENCE, enabled: adoptOk, why: adoptWhy, danger: true }); + out.push({ id: 'decide:reroute', label: STAGE_TRACKER_ACTION_LABELS['decide:reroute'], note: tk.rerouted && tk.rerouted.to ? 'rerouted → @' + tk.rerouted.to + ' already; pick again to move it' : (rerouteOk ? 'hands the reviewer\'s requested changes to another online clanker' : ''), enabled: rerouteOk, why: rerouteWhy, submenu: stageTrackerRerouteOptions(tk, rerouteOk, rerouteWhy, nowMs) }); + return out; } // Pure: the "rerouted → @x" pill with the target's presence dot; '' when // the row is not rerouted. diff --git a/src/pkg/github/automerge/automerge_contributor_adopt.go b/src/pkg/github/automerge/automerge_contributor_adopt.go index 18a22cb0a5..601597c1d7 100644 --- a/src/pkg/github/automerge/automerge_contributor_adopt.go +++ b/src/pkg/github/automerge/automerge_contributor_adopt.go @@ -860,6 +860,9 @@ func (c *Engine) supersedeAdoptedPR(ctx context.Context, store *stagelabels.Stor } owner, repo, number := obs.Owner, obs.Repo, obs.Number rec.AdoptReason = reason + // A person's approval of this head travels to the copy + // (hivecommons/hive#15136 follow-up): adopting is not un-approving. + admittedBy := c.operatorAdmission(owner, repo, number, obs.HeadSHA) if stored, ok := store.Get(key); ok && stored.AdoptDiffFence != "" { // A second takeover (dco-rehome, signoff-rehome, in-place-stalled) // carries the fence the first adoption recorded. @@ -971,7 +974,7 @@ func (c *Engine) supersedeAdoptedPR(ctx context.Context, store *stagelabels.Stor Title: gh.Ptr(nonEmpty(strings.TrimSpace(obs.Title), fmt.Sprintf("Adopt #%d", number))), Head: gh.Ptr(branch), Base: gh.Ptr(obs.BaseRef), - Body: gh.Ptr(AdoptionPRBody(obs, rec, dcoRehome, resignedTip) + adoptionCopyConflictNote(obs, fixerResolves)), + Body: gh.Ptr(AdoptionPRBody(obs, rec, dcoRehome, resignedTip) + adoptionCopyConflictNote(obs, fixerResolves) + adoptionCarriedApprovalNote(obs, admittedBy)), }) if apiErr != nil { return effects.Result{}, effects.NotApplied(apiErr) @@ -1007,6 +1010,9 @@ func (c *Engine) supersedeAdoptedPR(ctx context.Context, store *stagelabels.Stor superseding := created.GetNumber() store.MarkAdopted(key, obs.HeadSHA, superseding, now) store.NoteAdoptReason(key, reason) + if admittedBy != "" { + c.carryAdmissionToCopy(obs, admittedBy, superseding, nonEmpty(created.GetHead().GetSHA(), nonEmpty(resignedTip, obs.HeadSHA)), now) + } c.info("stage labels: contributor PR adopted", "repo", obs.Display, "pr", number, "head", obs.HeadSHA, "superseded_by", superseding, "branch", branch, "fence", rec.AdoptDiffFence, "forced_by", forcedBy, "fixer_resolves_conflicts", fixerResolves) if fixerResolves { c.requestAdoptionCopyRebase(ctx, store, key, obs, branch, superseding, created.GetHead().GetSHA()) @@ -1126,6 +1132,16 @@ func adoptionCopyConflictNote(obs stageObservation, conflicting bool) string { return fmt.Sprintf("\n\n**Conflicts with `%s`:** the contributor head could not be replayed onto the base, so this copy opened as it is and the hive's fixer is resolving the conflicts on this branch (rebase-resolve episode, two attempts). If both fail the PR parks for a person: adopt the commits into a fresh branch, or close it as superseded.\n", obs.BaseRef) } +// adoptionCarriedApprovalNote is the paragraph appended to the copy's body +// when a person had approved the original head: the approval stands for +// the content the copy carries unchanged. +func adoptionCarriedApprovalNote(obs stageObservation, login string) string { + if login == "" { + return "" + } + return fmt.Sprintf("\n\n**Approval carried over:** @%s approved #%d at head `%s`. The hive could not merge that head as-is (%s), so it re-authors it here; the approval travels with the content.\n", login, obs.Number, shortSHA(obs.HeadSHA), nonEmpty(headNotMergeableAsIs(obs), nonEmpty(obs.Reason, obs.LaneReason))) +} + // requestAdoptionCopyRebase opens the fixer's rebase-resolve episode on the // hive's conflicting copy (hivecommons/hive#15307) and records on the // original that its copy is in the fixer's hands. The copy is the hive's diff --git a/src/pkg/github/automerge/automerge_operator_admission.go b/src/pkg/github/automerge/automerge_operator_admission.go index 3fd36d2b94..64d639bf48 100644 --- a/src/pkg/github/automerge/automerge_operator_admission.go +++ b/src/pkg/github/automerge/automerge_operator_admission.go @@ -1,9 +1,12 @@ package automerge import ( + "fmt" "strings" "time" + "github.com/hivecommons/hive/pkg/review" + "github.com/hivecommons/hive/pkg/stageengine/prstage" "github.com/hivecommons/hive/pkg/stagelabels" ) @@ -58,7 +61,11 @@ func (m contributorClaimMatch) admittedByOperator() bool { // about to be adopted carries a person's admission (hivecommons/hive#15136): // the PR is theirs to merge as-is, so the hive records why it stood down // and does not take it over. An explicit Adopt request from the dashboard -// is the same person choosing re-authoring, so it is not refused. +// is the same person choosing re-authoring, so it is not refused. Nor is a +// head the lane cannot merge as-is (fork not editable and behind the base, +// conflicting, DCO missing): approval there means "approved to proceed", +// so the hive adopts and carries the approval to its copy rather than +// deadlocking between "merge as-is" and "cannot merge". func (c *Engine) adoptionRefusedByAdmission(store *stagelabels.Store, key string, obs stageObservation, requested bool, now time.Time) bool { if requested { return false @@ -67,7 +74,56 @@ func (c *Engine) adoptionRefusedByAdmission(store *stagelabels.Store, key string if login == "" { return false } + if reason := headNotMergeableAsIs(obs); reason != "" { + c.info("stage labels: a person admitted this head but the hive cannot merge it as-is; adopting and carrying the approval", "repo", obs.Display, "pr", obs.Number, "author", obs.Author, "head", obs.HeadSHA, "admitted_by", stagelabels.OperatorApprovalAdmission(login), "reason", reason) + return false + } store.NoteAdoptionBlocked(key, obs.HeadSHA, stagelabels.AdoptBlockedOperatorAdmission, now) c.info("stage labels: adoption due but a person admitted this head; not adopting", "repo", obs.Display, "pr", obs.Number, "author", obs.Author, "head", obs.HeadSHA, "admitted_by", stagelabels.OperatorApprovalAdmission(login)) return true } + +// headNotMergeableAsIsReasons are the lane reasons under which no approval +// makes the head land unchanged: the hive must re-author it on a branch it +// owns. +var headNotMergeableAsIsReasons = map[string]bool{ + autoMergeReasonForkNotEditable: true, "conflicting": true, "not-mergeable": true, + "label:needs-rebase": true, stagelabels.LaneReasonDCOMissing: true, +} + +// headNotMergeableAsIs names why the lane cannot merge obs's head unchanged, +// or "" when an admission alone would let it land. +func headNotMergeableAsIs(obs stageObservation) string { + for _, r := range []string{obs.Reason, obs.LaneReason} { + if headNotMergeableAsIsReasons[r] { + return r + } + } + if hasLabelFold(obs.Labels, "needs-rebase") { + return "label:needs-rebase" + } + if obs.Detail.DCO == stagelabels.DCONo { + return stagelabels.LaneReasonDCOMissing + } + return "" +} + +// carryAdmissionToCopy moves a person's approval of the adopted head onto the +// hive's copy: the approval stands for the content, and the copy carries +// that content unchanged. Recorded as a decision approval on the copy's head +// so the lanes read the carried-over requires_human question as answered. +func (c *Engine) carryAdmissionToCopy(obs stageObservation, login string, superseding int, copyHead string, now time.Time) { + if c == nil || c.humanChangeRequests == nil || login == "" || superseding <= 0 || strings.TrimSpace(copyHead) == "" { + return + } + req := review.HumanChangeRequest{ + Repo: obs.Owner + "/" + obs.Repo, Number: superseding, HeadSHA: strings.TrimSpace(copyHead), + Source: review.HumanChangeRequestSourceDecision, SourceID: int64(obs.Number), Actor: login, + Body: fmt.Sprintf("approve (carried from #%d head %s)", obs.Number, shortSHA(obs.HeadSHA)), Kind: review.HumanChangeRequestKindApprove, RecordedAt: now, + } + if err := c.humanChangeRequests.Record(req); err != nil { + c.warn("stage labels: carrying the approval to the hive's copy failed", "repo", obs.Display, "pr", obs.Number, "superseded_by", superseding, "by", login, "error", err) + return + } + c.info("stage labels: approval carried to the hive's copy", "repo", obs.Display, "pr", obs.Number, "superseded_by", superseding, "head", copyHead, "by", login) +} diff --git a/src/pkg/github/automerge/automerge_operator_admission_test.go b/src/pkg/github/automerge/automerge_operator_admission_test.go index a3414f1be1..4e5aee4d03 100644 --- a/src/pkg/github/automerge/automerge_operator_admission_test.go +++ b/src/pkg/github/automerge/automerge_operator_admission_test.go @@ -1,6 +1,7 @@ package automerge import ( + "strings" "testing" "time" @@ -105,3 +106,94 @@ func TestOperatorAdmissionAbsent(t *testing.T) { t.Fatalf("empty head admitted: %q", got) } } + +// An approval on a head the lane cannot merge as-is (the fork is not +// editable and sits behind the base) must not lock the PR into "merge +// as-is": that deadlocked hive#15312 and friends between "a maintainer +// approved this head; the hive merges it as-is" and "fork-not-editable". +// Approval means approved to proceed — the hive adopts, and the approval +// travels to its copy. +func TestOperatorAdmissionDoesNotBlockUnmergeableHead(t *testing.T) { + h, done := newAdoptHarness(t, ContributorNudgeOutcome{Mode: "comment"}, adoptPolicy()) + defer done() + h.e.humanChangeRequests = review.NewHumanChangeRequests("") + h.observe(adoptPR(7, "aaa"), autoMergeReasonForkNotEditable) + key := stageKey("acme", "widget", 7) + store := h.e.stageStoreOrShared() + if !store.NoteAdmission(key, "aaa", stagelabels.OperatorApprovalAdmission("octo"), h.clock.now()) { + t.Fatalf("NoteAdmission refused a known key") + } + labels := []string{"stage/072-returned-to-contributor", "role/contributor", "author/clanker"} + h.api.reset() + h.clock.advance(5 * time.Hour) + h.observe(adoptPR(7, "aaa", labels...), autoMergeReasonForkNotEditable) + rec, _ := store.Get(key) + if rec.AdoptedHead != "aaa" || rec.AdoptedBy == 0 || len(h.adopt.pulls) != 1 { + t.Fatalf("approved fork-not-editable head not adopted: pulls=%d rec=%+v", len(h.adopt.pulls), rec) + } + if got := rec.AdoptionBlocked("aaa"); got != "" { + t.Fatalf("adoption blocked %q on a head the lane cannot merge as-is", got) + } + if body, _ := h.adopt.pulls[0]["body"].(string); !strings.Contains(body, "**Approval carried over:** @octo approved #7") { + t.Fatalf("copy body lacks the carried approval:\n%s", body) + } + req, ok := h.e.humanChangeRequests.For("acme/widget", rec.AdoptedBy, "aaa") + if !ok || !req.IsApproval() || req.Actor != "octo" { + t.Fatalf("approval not carried to copy #%d: %+v ok=%v", rec.AdoptedBy, req, ok) + } +} + +// A mergeable admitted head still stands down (the person merges it as-is); +// the lane reasons that make a head unmergeable as-is are named. +func TestHeadNotMergeableAsIs(t *testing.T) { + for _, tc := range []struct { + name string + obs stageObservation + want string + }{ + {name: "check failing only", obs: stageObservation{Reason: "check-failing:unit"}, want: ""}, + {name: "fork not editable", obs: stageObservation{Reason: autoMergeReasonForkNotEditable}, want: autoMergeReasonForkNotEditable}, + {name: "lane reason conflicting", obs: stageObservation{Reason: "decision-requested", LaneReason: "conflicting"}, want: "conflicting"}, + {name: "needs-rebase label", obs: stageObservation{Labels: []string{"needs-rebase"}}, want: "label:needs-rebase"}, + {name: "dco missing", obs: stageObservation{Detail: stageDetail{DCO: stagelabels.DCONo}}, want: stagelabels.LaneReasonDCOMissing}, + } { + t.Run(tc.name, func(t *testing.T) { + if got := headNotMergeableAsIs(tc.obs); got != tc.want { + t.Fatalf("headNotMergeableAsIs = %q, want %q", got, tc.want) + } + }) + } +} + +// Approve, then Adopt now: the forced adoption wins. The recorded +// "operator-admission" blocker clears the moment Adopt now is recorded (the +// row stops saying "not adopted") and the next pass supersedes the PR. +func TestForcedAdoptionOverridesAdmission(t *testing.T) { + h, done := newAdoptHarness(t, ContributorNudgeOutcome{Mode: "comment"}, adoptPolicy()) + defer done() + h.observe(adoptPR(7, "aaa"), "check-failing:unit") + key := stageKey("acme", "widget", 7) + store := h.e.stageStoreOrShared() + store.NoteAdmission(key, "aaa", stagelabels.OperatorApprovalAdmission("octo"), h.clock.now()) + labels := []string{"stage/072-returned-to-contributor", "role/contributor", "author/clanker"} + h.api.reset() + h.clock.advance(5 * time.Hour) + h.observe(adoptPR(7, "aaa", labels...), "check-failing:unit") + if rec, _ := store.Get(key); rec.AdoptionBlocked("aaa") != stagelabels.AdoptBlockedOperatorAdmission || rec.AdoptedHead != "" { + t.Fatalf("precondition: mergeable admitted head should be blocked, got %+v", rec) + } + store.NoteAdoptionForced(key, "octo", h.clock.now()) + if rec, _ := store.Get(key); rec.AdoptionBlocked("aaa") != "" { + t.Fatalf("Adopt now left the admission blocker standing: %+v", rec) + } + h.api.reset() + h.clock.advance(time.Minute) + h.observe(adoptPR(7, "aaa", labels...), "check-failing:unit") + rec, _ := store.Get(key) + if rec.AdoptedHead != "aaa" || rec.AdoptedBy == 0 || rec.AdoptReason != AdoptReasonOperatorForced { + t.Fatalf("forced adoption did not run over the admission: %+v", rec) + } + if _, pending := rec.AdoptionForced(); pending { + t.Fatalf("forced adoption still pending after it ran: %+v", rec) + } +} diff --git a/src/pkg/stagelabels/store.go b/src/pkg/stagelabels/store.go index 1150e2c080..312ee7598c 100644 --- a/src/pkg/stagelabels/store.go +++ b/src/pkg/stagelabels/store.go @@ -1380,7 +1380,10 @@ func (r Record) Admission(head string) string { } // NoteAdoptionForced records an operator's "Adopt now" by login at now. The -// pending reroute (if any) is dropped: a forced adoption supersedes it. +// pending reroute (if any) is dropped: a forced adoption supersedes it. So +// is a recorded adoption blocker (a person's admission, maintainer policy): +// the forced adoption outranks it, and the tracker must stop saying "not +// adopted" the moment the operator asked. func (s *Store) NoteAdoptionForced(key, login string, now time.Time) { s.mu.Lock() defer s.mu.Unlock() @@ -1390,6 +1393,7 @@ func (s *Store) NoteAdoptionForced(key, login string, now time.Time) { } r.AdoptForcedBy, r.AdoptForcedAt = login, now r.RerouteTo, r.RerouteBy, r.RerouteAt, r.RerouteReason, r.RerouteHead = "", "", time.Time{}, "", "" + r.AdoptBlockedHead, r.AdoptBlockedBy, r.AdoptBlockedAt = "", "", time.Time{} s.items[key] = r s.dirty = true }