From a41f8177ace4b9e84638018df91607900ba773a6 Mon Sep 17 00:00:00 2001 From: Danathar Date: Wed, 28 Oct 2026 14:08:44 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=92=20fix(contributor-lane):=20stop=20?= =?UTF-8?q?/hive=20approve=20promising=20a=20merge=20for=20a=20workflow=20?= =?UTF-8?q?head=20that=20removes=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The /hive approve reply keyed its "a trusted merger's Approve review lets the lane merge" caption on the workflow-path fence alone. Since #15027 the lane checks removed tests before the owner-approval release, so a head that edits workflows and removes tests stops at tests-removed, and that caption sent the owner to approve a head the lane will not merge. Such a head now gets the manual-merge reply. Raised by the hive review of #15027 (backlog #15034); the fix was pushed to #15027's branch seconds after it merged, so it lands here. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01BQYnPGFJx81c8JXR3o1sg1 Signed-off-by: Danathar --- .../fixed-approve-reply-tests-removed.md | 1 + .../github/automerge/pr_approve_command.go | 5 +++- .../automerge/pr_approve_command_test.go | 25 +++++++++++++------ 3 files changed, 23 insertions(+), 8 deletions(-) create mode 100644 changelog.d/fixed-approve-reply-tests-removed.md diff --git a/changelog.d/fixed-approve-reply-tests-removed.md b/changelog.d/fixed-approve-reply-tests-removed.md new file mode 100644 index 0000000000..4a134b6a8d --- /dev/null +++ b/changelog.d/fixed-approve-reply-tests-removed.md @@ -0,0 +1 @@ +- **`/hive approve` no longer promises a merge for a workflow-file head that also removes tests.** Its reply keyed the "a trusted merger's Approve review lets the lane merge" caption on the workflow-path fence alone; since the contributor lane checks removed tests before the owner-approval release ([#15027](https://github.com/hivecommons/hive/pull/15027)), such a head stops at `contributor-lane:tests-removed`, so the reply now gives the manual-merge wording instead ([#15034](https://github.com/hivecommons/hive/issues/15034)). diff --git a/src/pkg/github/automerge/pr_approve_command.go b/src/pkg/github/automerge/pr_approve_command.go index 46f3ade989..bf644ab2ee 100644 --- a/src/pkg/github/automerge/pr_approve_command.go +++ b/src/pkg/github/automerge/pr_approve_command.go @@ -85,7 +85,10 @@ func (c *Engine) PRApproveReply(ctx context.Context, displayRepo string, number if contributor { diffReason = contributorLaneDiffReason(files) } - if len(intent.HumanMergePathMatches(files, patterns)) == 0 && diffReason == contributorLaneReasonWorkflowPath && c.currentContributorLanePolicy().OwnerApprovalReleasesWorkflowFence { + // The owner-approval release lifts only the workflow-path fence; a head + // that also removes tests stops at tests-removed, so it gets the manual + // caption below rather than a promise the lane will merge it. + if len(intent.HumanMergePathMatches(files, patterns)) == 0 && diffReason == contributorLaneReasonWorkflowPath && contributorLaneTestsRemovedReason(files) == "" && c.currentContributorLanePolicy().OwnerApprovalReleasesWorkflowFence { return "`/hive approve` acknowledged, but this PR edits CI workflow / action files, which the contributor lane merges only on a hive owner's explicit approval: a trusted merger submits a GitHub **Approve** review for the current head (`" + stagelabels.ShortSHA(head) + "`) or approves it from the Hive dashboard, and the lane merges once CI and the other gates are clear. Approval on an earlier head does not carry over.", nil } if len(intent.HumanMergePathMatches(files, patterns)) > 0 || diffReason != "" { diff --git a/src/pkg/github/automerge/pr_approve_command_test.go b/src/pkg/github/automerge/pr_approve_command_test.go index 2f03bb59b5..44a8903f6b 100644 --- a/src/pkg/github/automerge/pr_approve_command_test.go +++ b/src/pkg/github/automerge/pr_approve_command_test.go @@ -15,8 +15,11 @@ import ( func TestPRApproveReply(t *testing.T) { for _, tc := range []struct { name, author, actor, verdict, file, body, want string - labels []string - bot, disabled, readError, trustedAuthor bool + // removedTest adds a deleted test file to the diff. + removedTest string + labels []string + bot, disabled, readError, trustedAuthor bool + releaseFence bool }{ {name: "says no needs-human blocks", author: testHiveAppBotLogin, actor: "owner", want: "No `needs-human` label blocks this PR."}, {name: "says needs-human still blocks", author: testHiveAppBotLogin, actor: "owner", labels: []string{"needs-human"}, want: "`needs-human` still blocks this PR"}, @@ -32,6 +35,8 @@ func TestPRApproveReply(t *testing.T) { {name: "bot", author: "contributor", actor: "owner", bot: true, want: "a bot cannot release"}, {name: "rejected contributor", author: "contributor", actor: "owner", verdict: "reject", want: "cannot override this contributor-lane verdict"}, {name: "manual workflow", author: "contributor", actor: "owner", file: ".github/workflows/ci.yml", want: "requires a person to merge manually"}, + {name: "owner approval releases workflow fence", author: "contributor", actor: "owner", file: ".github/workflows/ci.yml", releaseFence: true, want: "merges only on a hive owner's explicit approval"}, + {name: "workflow fence with removed test stays manual", author: "contributor", actor: "owner", file: ".github/workflows/ci.yml", removedTest: "src/pkg/widget/widget_test.go", releaseFence: true, want: "requires a person to merge manually"}, {name: "manual path", author: testHiveAppBotLogin, actor: "owner", file: "sensitive/config.yaml", want: "requires a person to merge manually"}, {name: "carried fence on App lane", author: testHiveAppBotLogin, actor: "owner", body: CarriedFenceMarker(contributorLaneReasonTestsRemoved, 9), want: "carries a diff fence from the contributor PR it supersedes"}, {name: "disabled lane", author: "contributor", actor: "owner", disabled: true, want: "must merge it manually"}, @@ -64,7 +69,11 @@ func TestPRApproveReply(t *testing.T) { if file == "" { file = "src/main.go" } - json.NewEncoder(w).Encode([]*gh.CommitFile{{Filename: gh.Ptr(file), Status: gh.Ptr("modified")}}) + files := []*gh.CommitFile{{Filename: gh.Ptr(file), Status: gh.Ptr("modified")}} + if tc.removedTest != "" { + files = append(files, &gh.CommitFile{Filename: gh.Ptr(tc.removedTest), Status: gh.Ptr("removed")}) + } + json.NewEncoder(w).Encode(files) default: t.Errorf("unexpected read: %s", r.URL.Path) w.WriteHeader(http.StatusNotFound) @@ -74,10 +83,12 @@ func TestPRApproveReply(t *testing.T) { client := hgithub.NewClient("token", "acme", []string{"widget"}, nil, api.URL) client.SetAppBotLogin(testHiveAppBotLogin) e := New(client, Options{ - MergerAuthorizer: func(login string) bool { return login == "owner" }, - TrustedAuthorPolicy: func() TrustedAuthorPolicy { return TrustedAuthorPolicy{Enabled: tc.trustedAuthor} }, - TrustedAuthorizer: func(string, string) TrustedAuthorDecision { return TrustedAuthorDecision{Allowed: tc.trustedAuthor} }, - ContributorLanePolicy: func() ContributorLanePolicy { return ContributorLanePolicy{Enabled: true} }, + MergerAuthorizer: func(login string) bool { return login == "owner" }, + TrustedAuthorPolicy: func() TrustedAuthorPolicy { return TrustedAuthorPolicy{Enabled: tc.trustedAuthor} }, + TrustedAuthorizer: func(string, string) TrustedAuthorDecision { return TrustedAuthorDecision{Allowed: tc.trustedAuthor} }, + ContributorLanePolicy: func() ContributorLanePolicy { + return ContributorLanePolicy{Enabled: true, OwnerApprovalReleasesWorkflowFence: tc.releaseFence} + }, ContributorLaneVerdict: func(string, int, string) ContributorLaneVerdict { return ContributorLaneVerdict{Configured: true, Verdict: verdict} },