Repository navigation
🐛 Withhold the contributor nudge for a head the hive adopts anyway #18874
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
762e3ef
🐛 Withhold the contributor nudge for a head the hive adopts anyway
clubanderson f6e3dd0
🐛 Drop the withhold config leaf; the withholding is always on in prod…
clubanderson 3272874
✅ Name the zero-policy subtest
clubanderson a49f069
✅ Cover the withheld-nudge store mark
clubanderson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| - A contributor PR the hive is going to adopt anyway (author relay offline or unregistered, adoption enabled and unblocked) no longer gets a "back in your court" nudge followed by an adoption note 16-39 minutes later: the nudge is recorded (the adoption clock still runs, the relay still gets its task) but its GitHub comment is withheld, so the author gets one notification, and it is posted if the adoption stops being certain; an online author keeps the nudge and the full grace, and the ladder's immediate-supersede rung fires only for an unreachable author, the same condition. (#18872). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| package delegatedecision | ||
|
|
||
| import "testing" | ||
|
|
||
| // hivecommons/hive#18872: the ladder and the contributor nudge agree on one | ||
| // outcome per head. Rung 5 fires exactly when the author is unreachable | ||
| // (the nudge is withheld under that condition) and never for a reachable | ||
| // author (who keeps the nudge and the real grace). | ||
| func TestLadderAndNudgeAgree(t *testing.T) { | ||
| base := Input{Repo: "hivecommons/hive", Kind: KindPR, Number: 18561, AuthorTooling: AuthorToolingClanker} | ||
| patterns := []struct { | ||
| name string | ||
| mut func(*Input) | ||
| }{ | ||
| {"conflicting", func(i *Input) { i.Conflicting = true; i.CIGreen = true }}, | ||
| {"check-failing", func(i *Input) { i.CIGreen = false }}, | ||
| {"dco-missing", func(i *Input) { i.CIGreen = true; i.DCOMissing = true }}, | ||
| {"adoption-stalled", func(i *Input) { i.CIGreen = true; i.AdoptionStalled = true }}, | ||
| } | ||
| for _, p := range patterns { | ||
| t.Run(p.name+"/unreachable", func(t *testing.T) { | ||
| in := with(base, p.mut) | ||
| if in.ContributorReachable() || !AdoptsImmediately(in) { | ||
| t.Fatalf("an unreachable author's head is superseded now (reachable=%v)", in.ContributorReachable()) | ||
| } | ||
| }) | ||
| for _, reach := range []struct { | ||
| name string | ||
| mut func(*Input) | ||
| }{ | ||
| {"online", func(i *Input) { i.ContributorOnline = true }}, | ||
| {"rework-picked-up", func(i *Input) { i.ReworkPickedUp = true }}, | ||
| } { | ||
| t.Run(p.name+"/"+reach.name, func(t *testing.T) { | ||
| in := with(with(base, p.mut), reach.mut) | ||
| if !in.ContributorReachable() || AdoptsImmediately(in) { | ||
| t.Fatalf("a reachable author gets a real chance, not rung 5") | ||
| } | ||
| }) | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
153 changes: 153 additions & 0 deletions
153
src/pkg/github/automerge/automerge_nudge_withhold_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,153 @@ | ||
| package automerge | ||
|
|
||
| import ( | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/hivecommons/hive/pkg/stagelabels" | ||
| ) | ||
|
|
||
| // hivecommons/hive#18872: a contributor got "this PR is back in your court" | ||
| // and 16-39 minutes later the hive adopted the same PR. The nudge and the | ||
| // adoption now agree on one outcome per head: a head the hive adopts anyway | ||
| // (author relay offline or unregistered) is nudged on the record only, so | ||
| // the adoption clock runs and the adoption note is the one notification; a | ||
| // head with a real chance (relay online) keeps its nudge and is not adopted | ||
| // before the grace. | ||
|
|
||
| // withholdPatterns are the four pairs observed on the hive's spoke: | ||
| // #18561 contributor-lane, #18628 fork-not-editable, #18514 check-failing, | ||
| // #18510 conflicting. | ||
| var withholdPatterns = []struct{ name, reason string }{ | ||
| {"contributor-lane", contributorLaneReasonChangesRequested}, | ||
| {"fork-not-editable", autoMergeReasonForkNotEditable}, | ||
| {"check-failing", "required-check-failing:changelog-fragment-guard"}, | ||
| {"conflicting", "conflicting"}, | ||
| } | ||
|
|
||
| var withholdLabels = []string{"stage/072-returned-to-contributor", "role/contributor", "author/clanker"} | ||
|
|
||
| func withholdPolicy() StageLabelPolicy { | ||
| p := adoptPolicy() | ||
| p.NudgeWithholdWhenAdopting = true | ||
| return p | ||
| } | ||
|
|
||
| func TestNudgeWithheldWhenHiveAdoptsAnyway(t *testing.T) { | ||
| for _, pat := range withholdPatterns { | ||
| for _, registered := range []bool{true, false} { | ||
| name := pat.name + "/unregistered" | ||
| if registered { | ||
| name = pat.name + "/offline" | ||
| } | ||
| t.Run(name, func(t *testing.T) { | ||
| h, done := newAdoptHarness(t, ContributorNudgeOutcome{Mode: "queued"}, withholdPolicy()) | ||
| defer done() | ||
| start := h.clock.at | ||
| h.sink.presence = &ContributorPresence{Registered: registered} | ||
| h.observe(adoptPR(7, "aaa"), pat.reason) | ||
| // Invariant 1: no nudge comment for a head that is adopted anyway. | ||
| if got := nudgeComments(h.api); len(got) != 0 { | ||
| t.Fatalf("nudge posted for a head the hive adopts anyway: %v", got) | ||
| } | ||
| // The nudge is recorded: the adoption clock is running on it. | ||
| rec, ok := h.e.stageStoreOrShared().Get(stageKey("acme", "widget", 7)) | ||
| if !ok || rec.NudgeHead != "aaa" || rec.NudgeCount == 0 || rec.NudgeWithheldHead != "aaa" { | ||
| t.Fatalf("withheld nudge not recorded: %+v", rec) | ||
| } | ||
| // The adoption follows on the AutoAdoption clock, with its note. | ||
| h.api.reset() | ||
| h.clock.at = start.Add(16 * time.Minute) | ||
| h.observe(adoptPR(7, "aaa", withholdLabels...), pat.reason) | ||
| if len(adoptionComments(h.api)) != 1 { | ||
| t.Fatalf("no adoption note at +16m: %v", h.api.comments) | ||
| } | ||
| if got := nudgeComments(h.api); len(got) != 0 { | ||
| t.Fatalf("a nudge was posted next to the adoption: %v", got) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| func TestNudgeKeptAndNoEarlyAdoptionWhenAuthorHasARealChance(t *testing.T) { | ||
| for _, pat := range withholdPatterns { | ||
| t.Run(pat.name, func(t *testing.T) { | ||
| h, done := newAdoptHarness(t, ContributorNudgeOutcome{Mode: "queued"}, withholdPolicy()) | ||
| defer done() | ||
| start := h.clock.at | ||
| h.sink.presence = &ContributorPresence{Registered: true, Online: true} | ||
| h.observe(adoptPR(7, "aaa"), pat.reason) | ||
| if len(nudgeComments(h.api)) != 1 { | ||
| t.Fatalf("an online author is nudged: %v", h.api.comments) | ||
| } | ||
| // Invariant 2: not adopted before the online grace. | ||
| for _, at := range []time.Duration{16 * time.Minute, 31 * time.Minute, time.Hour} { | ||
| h.api.reset() | ||
| h.clock.at = start.Add(at) | ||
| h.observe(adoptPR(7, "aaa", withholdLabels...), pat.reason) | ||
| if len(adoptionComments(h.api)) != 0 || len(h.adopt.pulls) != 0 { | ||
| t.Fatalf("adopted at +%v before the grace: %v", at, h.api.comments) | ||
| } | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestWithheldNudgeIsPostedWhenTheAuthorReappears(t *testing.T) { | ||
| h, done := newAdoptHarness(t, ContributorNudgeOutcome{Mode: "queued"}, withholdPolicy()) | ||
| defer done() | ||
| start := h.clock.at | ||
| h.sink.presence = &ContributorPresence{Registered: true} | ||
| h.observe(adoptPR(7, "aaa"), "conflicting") | ||
| if len(nudgeComments(h.api)) != 0 { | ||
| t.Fatalf("nudge should be withheld: %v", h.api.comments) | ||
| } | ||
| // The relay reconnects before the adoption is due: a real chance now. | ||
| h.sink.presence = &ContributorPresence{Registered: true, Online: true} | ||
| h.clock.at = start.Add(5 * time.Minute) | ||
| h.observe(adoptPR(7, "aaa", withholdLabels...), "conflicting") | ||
| if len(nudgeComments(h.api)) != 1 { | ||
| t.Fatalf("the withheld nudge is owed once the author is reachable: %v", h.api.comments) | ||
| } | ||
| rec, _ := h.e.stageStoreOrShared().Get(stageKey("acme", "widget", 7)) | ||
| if rec.NudgeWithheldHead != "" { | ||
| t.Fatalf("withheld mark not cleared: %+v", rec) | ||
| } | ||
| } | ||
|
|
||
| func TestNudgeNotWithheldWithoutCertainAdoption(t *testing.T) { | ||
| t.Run("policy flag off", func(t *testing.T) { | ||
| h, done := newAdoptHarness(t, ContributorNudgeOutcome{Mode: "queued"}, adoptPolicy()) | ||
| defer done() | ||
| h.sink.presence = &ContributorPresence{Registered: true} | ||
| h.observe(adoptPR(7, "aaa"), "conflicting") | ||
| if len(nudgeComments(h.api)) != 1 { | ||
| t.Fatalf("withholding is off by default in the engine: %v", h.api.comments) | ||
| } | ||
| }) | ||
| t.Run("no presence source", func(t *testing.T) { | ||
| fake := &fakeNudgeSink{outcome: ContributorNudgeOutcome{Mode: "comment"}} | ||
| h, done := newAdoptHarnessWith(t, fake, nudgeOnlySink{fake}, withholdPolicy()) | ||
| defer done() | ||
| h.observe(adoptPR(7, "aaa"), "conflicting") | ||
| if len(nudgeComments(h.api)) != 1 { | ||
| t.Fatalf("without presence the adoption is not certain: %v", h.api.comments) | ||
| } | ||
| }) | ||
| t.Run("adoption disabled", func(t *testing.T) { | ||
| p := withholdPolicy() | ||
| p.Adoption = false | ||
| rec := stagelabels.Record{} | ||
| if adoptionBound(rec, stageObservation{HeadSHA: "aaa"}, p, ContributorPresence{Registered: true}, true) { | ||
| t.Fatal("adoption off cannot be certain") | ||
| } | ||
| }) | ||
| t.Run("maintainer policy ask", func(t *testing.T) { | ||
| p := withholdPolicy() | ||
| p.AdoptionMaintainerPolicy = "ask" | ||
| if adoptionBound(stagelabels.Record{}, stageObservation{HeadSHA: "aaa"}, p, ContributorPresence{Registered: true}, true) { | ||
| t.Fatal("a held adoption cannot be certain") | ||
| } | ||
| }) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Open question: the doc comment says reachability includes an author who picked the rework up (as
delegatedecision.ContributorReachabledoes, ladder.go:255), but this function only checkspresence.Registered && presence.Online.AdoptsImmediatelyis called only from its own test, so nothing keeps the two in step. If a claimedfix-prtask keeps AutoAdoption from adopting, that author's nudge is withheld wrongly; if not, drop the wording.