From e51fd4b68c4e386560d6094504cdbc1fa71b8b96 Mon Sep 17 00:00:00 2001 From: Danathar Date: Tue, 10 Nov 2026 07:38:15 -0500 Subject: [PATCH] fix(adoption): name the branch update a person must run when a fork's base changed workflows A fork PR the hive cannot finish because its base changed .github/workflows/ parked at 085 (adoption-stalled:fork-rehome-refused) with a general "bring it into the repository yourself or close it" ask. GitHub refuses any App push to a fork that carries a workflow change, whatever the App is granted on the base repository, so the one action is a person's branch update. The note now reads the fork's maintainer_can_modify and the base-side workflow change when it is posted and names that action (Update branch / gh pr update-branch, or a local merge on a conflict), or the author's step when maintainer edits are off. Refs projectbluefin/common#1611, projectbluefin/utah-packages#812 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01BQYnPGFJx81c8JXR3o1sg1 Signed-off-by: Danathar --- changelog.d/fixed-fork-workflow-sync-park.md | 1 + src/docs/hive-merge.md | 7 +- .../stage-labels.md | 9 +- .../automerge/automerge_contributor_adopt.go | 131 +++++++++++-- .../automerge_fork_update_block_test.go | 183 ++++++++++++++++++ 5 files changed, 318 insertions(+), 13 deletions(-) create mode 100644 changelog.d/fixed-fork-workflow-sync-park.md create mode 100644 src/pkg/github/automerge/automerge_fork_update_block_test.go diff --git a/changelog.d/fixed-fork-workflow-sync-park.md b/changelog.d/fixed-fork-workflow-sync-park.md new file mode 100644 index 0000000000..1c0eb85ea7 --- /dev/null +++ b/changelog.d/fixed-fork-workflow-sync-park.md @@ -0,0 +1 @@ +- A fork PR the hive cannot finish because its base changed `.github/workflows/` now parks at `085` with the one action that unblocks it (a person runs **Update branch** or `gh pr update-branch`, or merges the base in locally on a conflict), instead of asking a maintainer to bring the change into the repository or close it; a fork without maintainer edits names the author's step (projectbluefin/common#1611). diff --git a/src/docs/hive-merge.md b/src/docs/hive-merge.md index 4767856175..980b99cef1 100644 --- a/src/docs/hive-merge.md +++ b/src/docs/hive-merge.md @@ -1359,7 +1359,12 @@ code would run as trusted. So a fork PR the hive cannot push to is not adopted at all: it stays at `072` with its author's nudge and queued `fix-pr` task, and only after the `072` dwell (24h) since the nudge on that head does it park at `085` as `adoption-stalled:fork-rehome-refused` with a maintainer -ask. In-place adoption on the fork's own branch (when the contributor allows +ask. The ask names the cause when the hive can read it: a base-side change +under `.github/workflows/` (GitHub refuses any App push to a fork that +carries one, whatever the App is granted, so a person runs **Update branch** +or `gh pr update-branch`, or merges the base in locally on a conflict), or a +fork that allows no maintainer edits (the author turns them on or pushes). +In-place adoption on the fork's own branch (when the contributor allows maintainer edits) is unchanged; if such an adoption later needs a re-home, the hive records the refusal and the next pass parks it at `085` with the same ask. When adoption is in-place on the contributor PR's own diff --git a/src/docs/labels-and-control-signals/stage-labels.md b/src/docs/labels-and-control-signals/stage-labels.md index 8a503cc56a..b4e674670d 100644 --- a/src/docs/labels-and-control-signals/stage-labels.md +++ b/src/docs/labels-and-control-signals/stage-labels.md @@ -944,7 +944,14 @@ When a contributor-agent PR goes red the hive does not just relabel it (a human- queued `fix-pr` task, and after the `072` dwell (24h) since the nudge on that head it parks at `085` as `adoption-stalled:fork-rehome-refused` with one note asking a maintainer to review it and bring it in or close - it (once per head and reason, retried on later sweeps until GitHub + it. When the hive can read why it could not update the fork, the note + names the one action instead: if the base changed a file under + `.github/workflows/` since the branch was cut (GitHub refuses any App + push to a fork that carries a workflow change, whatever the App is + granted on the base repository), a person brings the branch up to date + with **Update branch** or `gh pr update-branch` (or merges the base in + locally when it conflicts); if the fork allows no maintainer edits, the + author turns them on or pushes the fix (the note posts once per head and reason, retried on later sweeps until GitHub accepts it; an errored lane's weak 080 does not lift it). A new head from the author re-arms the normal path. An explicit owner-delegated adoption request is still recorded and parks at once. - `reason=dco-rehome` (always `mode=supersede`) — not a fresh adoption diff --git a/src/pkg/github/automerge/automerge_contributor_adopt.go b/src/pkg/github/automerge/automerge_contributor_adopt.go index e7a682419c..130e49063f 100644 --- a/src/pkg/github/automerge/automerge_contributor_adopt.go +++ b/src/pkg/github/automerge/automerge_contributor_adopt.go @@ -529,6 +529,13 @@ func adoptionBodyCause(reason string, wait adoptionWait) string { // person: it names the lane reason the hive was stuck on, so nobody reads // "waiting on a maintainer" into a PR the hive still owes a fix. func AdoptionStalledComment(obs stageObservation, rec stagelabels.Record, reason string, sat time.Duration) string { + return adoptionStalledComment(obs, rec, reason, sat, forkUpdateBlock{}) +} + +// adoptionStalledComment is AdoptionStalledComment with what the hive read +// about why it cannot update a fork's branch (forkUpdateBlockFor), which +// the fork-rehome-refused blocker names. +func adoptionStalledComment(obs stageObservation, rec stagelabels.Record, reason string, sat time.Duration, block forkUpdateBlock) string { var b strings.Builder fmt.Fprintf(&b, "%s head=%s reason=%s -->\n", AdoptionStalledMarker, obs.HeadSHA, reason) if reason == stagelabels.LaneReasonAdoptionStalledPrefix+stagelabels.LaneReasonRebaseFailedTwice { @@ -539,7 +546,7 @@ func AdoptionStalledComment(obs stageObservation, rec stagelabels.Record, reason } fmt.Fprintf(&b, "The hive adopted this PR (`%s`) but its head `%s` has not moved for %s and the hive has nothing it can push: `%s`.\n\n", stagelabels.AdoptedByHive.Label(), shortSHA(obs.HeadSHA), formatSat(sat), reason) b.WriteString("**Blocker:** ") - b.WriteString(adoptionBlockerText(obs, rec)) + b.WriteString(adoptionBlockerTextFor(obs, rec, block)) b.WriteString("\n\nMoving to `") b.WriteString(stagelabels.NeedsDecision.Label()) b.WriteString("` so a person sees it. This is not a merge-approval wait: the lane has not admitted this head.") @@ -651,6 +658,12 @@ func (c *Engine) headManualMergeRule(ctx context.Context, key string, obs stageO // adoptionBlockerText spells out what the lane reason stands for. func adoptionBlockerText(obs stageObservation, rec stagelabels.Record) string { + return adoptionBlockerTextFor(obs, rec, forkUpdateBlock{}) +} + +// adoptionBlockerTextFor is adoptionBlockerText with the fork update +// blocker the fork-rehome-refused ask names. +func adoptionBlockerTextFor(obs stageObservation, rec stagelabels.Record, block forkUpdateBlock) string { switch { case adoptedHeadSignoffUnfixable(obs, rec): author := nonEmpty(obs.Author, "the contributor") @@ -684,7 +697,7 @@ func adoptionBlockerText(obs stageObservation, rec stagelabels.Record) string { } return msg + "." case rec.ForkRehomeRefused(obs.HeadSHA): - return forkRehomeBlockerText(obs) + return forkRehomeBlockerTextFor(obs, block) case rec.AdoptionAttemptedNothingOpened(obs.HeadSHA): return fmt.Sprintf("the hive tried to re-home this PR onto `%s%d` (`%s`) and could not open the superseding PR.", adoptBranchPrefix, obs.Number, rec.AdoptReason) } @@ -697,9 +710,80 @@ func adoptionBlockerText(obs stageObservation, rec stagelabels.Record) string { return fmt.Sprintf("lane reason `%s` on this head and nothing changed.", nonEmpty(obs.LaneReason, obs.Reason)) } +// forkUpdateBlock is what the hive read about why it cannot bring a fork +// PR's branch up to date itself, so the fork-rehome-refused note can name +// the one action that unblocks it instead of a general "bring it in or +// close it" (projectbluefin/common#1611, utah-packages#812). The zero value +// means nothing specific was read, and the note keeps the general ask. +type forkUpdateBlock struct { + // NoMaintainerEdits: GET pulls/n reports maintainer_can_modify false. + NoMaintainerEdits bool + // WorkflowFile is a file under .github/workflows/ that the base changed + // since the PR's merge-base, or "". Updating the fork's branch would + // carry it into the fork, which GitHub refuses from the App whatever + // the App is granted on the base repository (projectbluefin/utah#1001). + WorkflowFile string +} + +// forkUpdateBlockFor reads forkUpdateBlock for a fork PR. It runs only when +// a fork-rehome-refused note is about to be posted (once per head), and a +// failed read leaves its part unset. +func (c *Engine) forkUpdateBlockFor(ctx context.Context, obs stageObservation) forkUpdateBlock { + var block forkUpdateBlock + if strings.TrimSpace(obs.HeadRepo) == "" || !adoptionFromFork(obs) { + return block + } + if pr, _, err := c.gh.PullRequests.Get(ctx, obs.Owner, obs.Repo, obs.Number); err == nil && pr.MaintainerCanModify != nil { + block.NoMaintainerEdits = !pr.GetMaintainerCanModify() + } + if file, err := c.baseSyncWorkflowFile(ctx, obs); err == nil { + block.WorkflowFile = file + } + return block +} + // forkRehomeBlockerText is the maintainer ask for a fork PR the hive cannot // finish on the fork's own branch and will not move into this repository. func forkRehomeBlockerText(obs stageObservation) string { + return forkRehomeBlockerTextFor(obs, forkUpdateBlock{}) +} + +// forkRehomeBlockerTextFor is forkRehomeBlockerText naming the block the +// hive read: a base-side workflow change the App cannot carry into the fork +// (the one action is a person's branch update), or a fork that allows no +// maintainer edits (the author's). With neither, the general ask stands. +func forkRehomeBlockerTextFor(obs stageObservation, block forkUpdateBlock) string { + fork := nonEmpty(obs.HeadRepo, "unknown") + base := nonEmpty(obs.BaseRef, "the base branch") + author := "the author" + if a := strings.TrimSpace(obs.Author); a != "" { + author = "@" + a + } + conflict := " If GitHub reports a conflict, merge `" + base + "` into the branch locally, resolve it and push." + if supersedeHeadConflicts(obs) { + conflict = " This PR also conflicts with `" + base + "`, so **Update branch** cannot do it alone: merge `" + base + "` into the branch locally, resolve the conflicts and push." + } + update := fmt.Sprintf("**Update branch** on this PR, or `gh pr update-branch %d -R %s/%s`", obs.Number, obs.Owner, obs.Repo) + switch { + case block.WorkflowFile != "": + var b strings.Builder + fmt.Fprintf(&b, "this PR comes from a fork (`%s`), and `%s` has changed `%s` since this branch was cut. "+ + "Bringing the branch up to date (a merge or a rebase) carries that workflow change into the fork, and GitHub refuses such a push from the Hive App whatever the App is granted on this repository: the App is not installed on the fork. "+ + "The change is inherited from `%s`, not part of this PR's own diff. "+ + "Moving the commits to `%s%d` in this repository instead would run code no maintainer has reviewed with the repository's trusted CI, so the hive did not. ", + fork, base, block.WorkflowFile, base, adoptBranchPrefix, obs.Number) + if block.NoMaintainerEdits { + fmt.Fprintf(&b, "**Ask (maintainer):** the fork does not allow edits by maintainers, so ask %s to bring the branch up to date with `%s` (%s), or to turn on \"Allow edits by maintainers\" so you can.", author, base, update) + } else { + fmt.Fprintf(&b, "**Ask (maintainer):** bring the branch up to date with `%s` yourself (%s), or ask %s to.", base, update, author) + } + b.WriteString(conflict) + b.WriteString(" The update is a merge, so the contributor's commits and sign-off stay, and the new head goes through CI, `/test` and review as usual.") + return b.String() + case block.NoMaintainerEdits: + return fmt.Sprintf("this PR comes from a fork (`%s`) that does not allow edits by maintainers, so the hive cannot push to its branch. Moving its commits to `%s%d` in this repository would run code no maintainer has reviewed with the repository's trusted CI (secrets, write tokens, no fork guards), so the hive did not. "+ + "**Ask (maintainer):** ask %s to turn on \"Allow edits by maintainers\" (the hive can then finish it on the fork) or to push the fix themselves; if it should not wait, review the change and bring it into the repository yourself, otherwise close it.", fork, adoptBranchPrefix, obs.Number, author) + } return fmt.Sprintf("this PR comes from a fork (`%s`) and the hive cannot finish it on the fork's own branch. Moving its commits to `%s%d` in this repository would run code no maintainer has reviewed with the repository's trusted CI (secrets, write tokens, no fork guards), so the hive did not. "+ "**Ask (maintainer):** review the change; if it should land, bring it into the repository yourself or follow the repository's process for fork pull requests, otherwise close it.", nonEmpty(obs.HeadRepo, "unknown"), adoptBranchPrefix, obs.Number) } @@ -708,11 +792,17 @@ func forkRehomeBlockerText(obs stageObservation) string { // to adopt (adoptContributorPR) when it is handed to a person after waiting // on its author for the 072 dwell. func ForkNotAdoptedComment(obs stageObservation, reason string, sat time.Duration) string { + return forkNotAdoptedComment(obs, reason, sat, forkUpdateBlock{}) +} + +// forkNotAdoptedComment is ForkNotAdoptedComment naming the fork update +// block the hive read (forkUpdateBlockFor). +func forkNotAdoptedComment(obs stageObservation, reason string, sat time.Duration, block forkUpdateBlock) string { var b strings.Builder fmt.Fprintf(&b, "%s head=%s reason=%s -->\n", AdoptionStalledMarker, obs.HeadSHA, reason) fmt.Fprintf(&b, "Head `%s` has waited on its author at `%s` for %s since the nudge (lane reason `%s`). The hive did not adopt it: it cannot push to this fork's branch, and it does not move a fork's commits into this repository.\n\n", shortSHA(obs.HeadSHA), stagelabels.ReturnedToContributor.Label(), formatSat(sat), nonEmpty(obs.LaneReason, obs.Reason)) b.WriteString("**Blocker:** ") - b.WriteString(forkRehomeBlockerText(obs)) + b.WriteString(forkRehomeBlockerTextFor(obs, block)) b.WriteString("\n\nMoving to `") b.WriteString(stagelabels.NeedsDecision.Label()) b.WriteString("` so a person sees it. A new head from the author returns it to the normal path.") @@ -1994,24 +2084,39 @@ func (c *Engine) pushAccessLost(ctx context.Context, obs stageObservation) bool // dead end (#12865). A compare failure counts as touching: a superseding PR // is always deliverable. func (c *Engine) baseSyncTouchesWorkflows(ctx context.Context, obs stageObservation) bool { + file, err := c.baseSyncWorkflowFile(ctx, obs) + if err != nil { + c.warn("stage labels: adoption could not compare head to base for workflow changes; superseding", "repo", obs.Display, "pr", obs.Number, "error", err) + return true + } + if file != "" { + c.info("stage labels: base-sync touches .github/workflows/ which the App cannot push; superseding", "repo", obs.Display, "pr", obs.Number, "file", file) + return true + } + return false +} + +// baseSyncWorkflowFile returns the first file under .github/workflows/ that +// the base changed since the PR's merge-base (compare head...base lists +// only the base side), or "" when there is none or the PR's head or base is +// unknown. +func (c *Engine) baseSyncWorkflowFile(ctx context.Context, obs stageObservation) (string, error) { if obs.HeadSHA == "" || obs.BaseRef == "" { - return false + return "", nil } opts := &gh.ListOptions{PerPage: 300} for { cmp, resp, err := c.gh.Repositories.CompareCommits(ctx, obs.Owner, obs.Repo, obs.HeadSHA, obs.BaseRef, opts) if err != nil { - c.warn("stage labels: adoption could not compare head to base for workflow changes; superseding", "repo", obs.Display, "pr", obs.Number, "error", err) - return true + return "", err } for _, f := range cmp.Files { if strings.HasPrefix(f.GetFilename(), ".github/workflows/") { - c.info("stage labels: base-sync touches .github/workflows/ which the App cannot push; superseding", "repo", obs.Display, "pr", obs.Number, "file", f.GetFilename()) - return true + return f.GetFilename(), nil } } if resp == nil || resp.NextPage == 0 { - return false + return "", nil } opts.Page = resp.NextPage } @@ -2557,7 +2662,11 @@ func (c *Engine) escapeStalledAdoption(ctx context.Context, store *stagelabels.S // Only this blocker's text carries the merge-commit ask. obs = c.withMergeAskFacts(ctx, key, obs) } - body := AdoptionStalledComment(obs, rec, reason, now.Sub(rec.AdoptedHeadSince())) + block := forkUpdateBlock{} + if rec.ForkRehomeRefused(obs.HeadSHA) { + block = c.forkUpdateBlockFor(ctx, obs) + } + body := adoptionStalledComment(obs, rec, reason, now.Sub(rec.AdoptedHeadSince()), block) n, err := c.postAdoptionEscalationNote(ctx, store, key, obs, reason, body, "stage labels: adoption escalation note failed") comments += n if err != nil && firstErr == nil { @@ -2592,6 +2701,6 @@ func (c *Engine) escalateUnadoptableFork(ctx context.Context, store *stagelabels return esc, 0, nil } c.info("stage labels: fork PR the hive cannot adopt waited past the 072 dwell; escalating to needs-decision", "repo", obs.Display, "pr", obs.Number, "head", obs.HeadSHA, "head_repo", obs.HeadRepo, "nudged_at", start, "lane_reason", nonEmpty(obs.LaneReason, obs.Reason)) - n, err := c.postAdoptionEscalationNote(ctx, store, key, obs, reason, ForkNotAdoptedComment(obs, reason, now.Sub(start)), "stage labels: fork escalation note failed") + n, err := c.postAdoptionEscalationNote(ctx, store, key, obs, reason, forkNotAdoptedComment(obs, reason, now.Sub(start), c.forkUpdateBlockFor(ctx, obs)), "stage labels: fork escalation note failed") return esc, n, err } diff --git a/src/pkg/github/automerge/automerge_fork_update_block_test.go b/src/pkg/github/automerge/automerge_fork_update_block_test.go new file mode 100644 index 0000000000..673a6739a8 --- /dev/null +++ b/src/pkg/github/automerge/automerge_fork_update_block_test.go @@ -0,0 +1,183 @@ +package automerge + +import ( + "strings" + "testing" + "time" + + "github.com/hivecommons/hive/pkg/stagelabels" +) + +// projectbluefin/utah-packages#812 and projectbluefin/common#1611: a fork PR +// the hive could not update because main had changed .github/workflows/ +// parked at 085 with "bring it into the repository yourself ... otherwise +// close it". GitHub refuses any App push to a fork that carries workflow +// files (the App is not installed on the fork), so no grant fixes it; the +// one action is a person's branch update, and the note must say so. + +const forkUpdateWorkflowFile = ".github/workflows/bump-upstream-enqueue.yml" + +func forkUpdateObs(reason string, labels ...string) stageObservation { + return stageObservation{ + Owner: "acme", Repo: "widget", Number: 7, HeadSHA: "aaa", HeadRepo: "mallory/widget", + BaseRef: "main", Author: "mallory", Reason: reason, LaneReason: reason, Labels: labels, + } +} + +func TestForkRehomeBlockerTextNamesTheUpdate(t *testing.T) { + for _, tc := range []struct { + name string + obs stageObservation + block forkUpdateBlock + want []string + notWant []string + }{ + { + name: "base workflow change, maintainer edits on", + obs: forkUpdateObs("check-failing:unit"), + block: forkUpdateBlock{WorkflowFile: forkUpdateWorkflowFile}, + want: []string{ + "comes from a fork (`mallory/widget`), and `main` has changed `" + forkUpdateWorkflowFile + "` since this branch was cut", + "not installed on the fork", + "inherited from `main`, not part of this PR's own diff", + "trusted CI", + "**Ask (maintainer):** bring the branch up to date with `main` yourself (**Update branch** on this PR, or `gh pr update-branch 7 -R acme/widget`), or ask @mallory to.", + "If GitHub reports a conflict, merge `main` into the branch locally", + "contributor's commits and sign-off stay", + }, + notWant: []string{"follow the repository's process", "otherwise close it", "Workflows: write", "lacks"}, + }, + { + name: "base workflow change on a conflicting fork without maintainer edits", + obs: forkUpdateObs("conflicting"), + block: forkUpdateBlock{WorkflowFile: forkUpdateWorkflowFile, NoMaintainerEdits: true}, + want: []string{ + "the fork does not allow edits by maintainers, so ask @mallory to bring the branch up to date with `main`", + "turn on \"Allow edits by maintainers\" so you can", + "also conflicts with `main`, so **Update branch** cannot do it alone", + }, + notWant: []string{"yourself (", "If GitHub reports a conflict", "otherwise close it"}, + }, + { + name: "no maintainer edits, no workflow change", + obs: forkUpdateObs("check-failing:unit"), + block: forkUpdateBlock{NoMaintainerEdits: true}, + want: []string{"comes from a fork (`mallory/widget`) that does not allow edits by maintainers", "trusted CI", "**Ask (maintainer):** ask @mallory to turn on \"Allow edits by maintainers\""}, + notWant: []string{"gh pr update-branch", ".github/workflows"}, + }, + { + name: "nothing read keeps the general ask", + obs: forkUpdateObs("check-failing:unit"), + block: forkUpdateBlock{}, + want: []string{"the hive cannot finish it on the fork's own branch", "**Ask (maintainer):** review the change", "otherwise close it"}, + }, + } { + t.Run(tc.name, func(t *testing.T) { + got := forkRehomeBlockerTextFor(tc.obs, tc.block) + for _, s := range tc.want { + if !strings.Contains(got, s) { + t.Errorf("missing %q:\n%s", s, got) + } + } + for _, s := range tc.notWant { + if strings.Contains(got, s) { + t.Errorf("unexpected %q:\n%s", s, got) + } + } + }) + } + if got, want := forkRehomeBlockerText(forkUpdateObs("x")), forkRehomeBlockerTextFor(forkUpdateObs("x"), forkUpdateBlock{}); got != want { + t.Fatalf("forkRehomeBlockerText changed its general ask:\n%s\nwant\n%s", got, want) + } +} + +// A fork PR the hive declined to adopt because the base changed a workflow +// file parks after the 072 dwell with the update as the one action, not the +// general "bring it in or close it" ask. +func TestForkNotAdoptedForBaseWorkflowChangeNamesUpdateBranch(t *testing.T) { + p := adoptPolicy() + p.AdoptInPlace = true + h, done := newAdoptHarness(t, ContributorNudgeOutcome{Mode: "comment"}, p) + defer done() + h.sink.presence = &ContributorPresence{Registered: true, Online: false} + h.adopt.allowMaintainerEdits(7, true) + h.adopt.compareFiles = []string{"README.md", forkUpdateWorkflowFile} + key := stageKey("acme", "widget", 7) + returned := []string{"stage/072-returned-to-contributor", "role/contributor", "author/clanker"} + + h.observe(forkPR(7, "aaa"), "check-failing:unit") + h.clock.advance(30 * time.Minute) + h.observe(forkPR(7, "aaa", returned...), "check-failing:unit") + if rec, _ := h.e.stageStoreOrShared().Get(key); !rec.ForkRehomeRefused("aaa") || rec.AdoptedHead != "" { + t.Fatalf("a fork whose update carries a workflow change must not be adopted: %+v", rec) + } + + h.clock.advance(24 * time.Hour) + h.observe(forkPR(7, "aaa", returned...), "check-failing:unit") + want := stagelabels.LaneReasonAdoptionStalledPrefix + adoptStallForkRehomeRefused + if rec, _ := h.e.stageStoreOrShared().Get(key); rec.Stage != stagelabels.NeedsDecision || rec.Reason != want { + t.Fatalf("record %+v, want 085 on %s", rec, want) + } + notes := stalledComments(h.api) + if len(notes) != 1 { + t.Fatalf("escalation note: %v", h.api.comments) + } + for _, s := range []string{ + "reason=" + want, + "`v5` has changed `" + forkUpdateWorkflowFile + "` since this branch was cut", + "not installed on the fork", + "bring the branch up to date with `v5` yourself (**Update branch** on this PR, or `gh pr update-branch 7 -R acme/widget`), or ask @mallory to.", + } { + if !strings.Contains(notes[0], s) { + t.Fatalf("note missing %q:\n%s", s, notes[0]) + } + } + if strings.Contains(notes[0], "follow the repository's process") { + t.Fatalf("note kept the general ask:\n%s", notes[0]) + } + if len(adoptionComments(h.api)) != 0 || len(h.adopt.pulls) != 0 || len(h.adopt.refs) != 0 { + t.Fatalf("fork PR adopted or re-homed: comments=%v pulls=%v refs=%v", h.api.comments, h.adopt.pulls, h.adopt.refs) + } +} + +// utah-packages#812's own path: a fork adopted in place while it could be +// pushed, then main changed a workflow file and the branch needed a rebase. +// The re-home is refused (fork code never moves into the base repository) +// and the 085 note names the conflict and the person's update. +func TestAdoptedForkConflictAfterBaseWorkflowChangeNamesUpdate(t *testing.T) { + p := adoptPolicy() + p.AdoptInPlace = true + h, done := newAdoptHarness(t, ContributorNudgeOutcome{Mode: "comment"}, p) + defer done() + key := adoptInPlaceAt(h, "aaa", "label:needs-rebase") + h.adopt.compareFiles = []string{forkUpdateWorkflowFile} + labels := append(append([]string{}, adoptedLabels...), "needs-rebase") + h.clock.advance(time.Minute) + h.observe(forkPR(7, "aaa", labels...), "label:needs-rebase") + h.clock.advance(adoptedDwell) + h.observe(forkPR(7, "aaa", labels...), "label:needs-rebase") + if rec, _ := h.e.stageStoreOrShared().Get(key); !rec.ForkRehomeRefused("aaa") || len(h.adopt.pulls) != 0 || len(h.adopt.refs) != 0 { + t.Fatalf("fork re-home must be refused: rec=%+v pulls=%v refs=%v", rec, h.adopt.pulls, h.adopt.refs) + } + h.api.reset() + h.clock.advance(time.Minute) + h.observe(forkPR(7, "aaa", labels...), "label:needs-rebase") + want := stagelabels.LaneReasonAdoptionStalledPrefix + adoptStallForkRehomeRefused + if rec, _ := h.e.stageStoreOrShared().Get(key); rec.Stage != stagelabels.NeedsDecision || rec.Reason != want { + t.Fatalf("record %+v, want 085 on %s", rec, want) + } + notes := stalledComments(h.api) + if len(notes) != 1 { + t.Fatalf("stall note: %v", h.api.comments) + } + for _, s := range []string{ + "`v5` has changed `" + forkUpdateWorkflowFile + "`", + "also conflicts with `v5`, so **Update branch** cannot do it alone: merge `v5` into the branch locally, resolve the conflicts and push.", + "`gh pr update-branch 7 -R acme/widget`", + "trusted CI", + } { + if !strings.Contains(notes[0], s) { + t.Fatalf("note missing %q:\n%s", s, notes[0]) + } + } +}