From fe4045a970b15c58fef9cfefe79968823798bda2 Mon Sep 17 00:00:00 2001 From: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> Date: Thu, 29 Oct 2026 08:36:06 -0400 Subject: [PATCH 1/3] =?UTF-8?q?=F0=9F=8C=B1=20chore(stageengine):=20share?= =?UTF-8?q?=20decision-cause=20prose=20between=20automerge=20and=20goldens?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The goldens test re-declared decisionCauseFor's prose string-for-string, so rewording had to be applied twice or the goldens drifted. The prose now lives once in pkg/stageengine/prstage, which both packages already import. Rendered bytes are unchanged; goldens untouched. Closes #15384 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> --- .../changed-decision-cause-prose-shared.md | 1 + .../automerge_decision_cause_test.go | 31 ++++++++++++ .../github/automerge/automerge_stage_human.go | 23 ++++----- src/pkg/stageengine/prstage/causes.go | 47 +++++++++++++++++++ src/pkg/stageengine/stage_goldens_test.go | 23 +++++---- 5 files changed, 102 insertions(+), 23 deletions(-) create mode 100644 changelog.d/changed-decision-cause-prose-shared.md create mode 100644 src/pkg/github/automerge/automerge_decision_cause_test.go create mode 100644 src/pkg/stageengine/prstage/causes.go diff --git a/changelog.d/changed-decision-cause-prose-shared.md b/changelog.d/changed-decision-cause-prose-shared.md new file mode 100644 index 0000000000..35abcb4d0c --- /dev/null +++ b/changelog.d/changed-decision-cause-prose-shared.md @@ -0,0 +1 @@ +Decision-cause prose shared between the automerge sweep and the stage goldens test through `pkg/stageengine/prstage` (#15384) diff --git a/src/pkg/github/automerge/automerge_decision_cause_test.go b/src/pkg/github/automerge/automerge_decision_cause_test.go new file mode 100644 index 0000000000..a570d77b30 --- /dev/null +++ b/src/pkg/github/automerge/automerge_decision_cause_test.go @@ -0,0 +1,31 @@ +package automerge + +import ( + "testing" + + "github.com/hivecommons/hive/pkg/stageengine/prstage" +) + +// The stage goldens render the same prose from prstage; a reworded cause here +// that skips prstage would drift from them (hivecommons/hive#15384). +func TestDecisionCauseUsesSharedProse(t *testing.T) { + for _, tc := range []struct{ reason, want string }{ + {contributorLaneReasonTestsRemoved, prstage.CauseTestsRemoved}, + {contributorLaneReasonReporterTrustHold, prstage.CauseReporterTrustHold}, + {autoMergeReasonHumanMergePath, prstage.CauseHumanMergePath}, + {autoMergeReasonIntentUnauthorized, prstage.CauseIntentUnauthorized}, + {"approval-desk-withheld", prstage.CauseApprovalDeskWithheld}, + {contributorLaneReasonWorkflowPath, prstage.CauseWorkflowPathManual}, + {workflowApprovalUntrustedPrefix, prstage.CauseWorkflowApprovalUntrusted()}, + {workflowApprovalWorkflowMissingPrefix, prstage.CauseWorkflowApprovalWorkflowMissing()}, + {workflowApprovalRequiredPrefix, prstage.CauseWorkflowApprovalRequired()}, + {"something-new", prstage.CauseLaneReported("something-new")}, + } { + if got := decisionCause(tc.reason); got != tc.want { + t.Errorf("decisionCause(%q) = %q, want %q", tc.reason, got, tc.want) + } + } + if got := decisionCauseFor(contributorLaneReasonWorkflowPath, false); got != prstage.CauseWorkflowPathAwaitingApproval { + t.Errorf("decisionCauseFor(workflow-path, false) = %q, want the awaiting-approval cause", got) + } +} diff --git a/src/pkg/github/automerge/automerge_stage_human.go b/src/pkg/github/automerge/automerge_stage_human.go index 6e21fc07ac..7ada2a9c71 100644 --- a/src/pkg/github/automerge/automerge_stage_human.go +++ b/src/pkg/github/automerge/automerge_stage_human.go @@ -19,6 +19,7 @@ import ( hgithub "github.com/hivecommons/hive/pkg/github" "github.com/hivecommons/hive/pkg/oktotest" "github.com/hivecommons/hive/pkg/stageengine" + "github.com/hivecommons/hive/pkg/stageengine/prstage" "github.com/hivecommons/hive/pkg/stagelabels" ) @@ -364,9 +365,9 @@ func decisionCause(reason string) string { // owner's explicit approval (hivecommons/hive#14664). func workflowPathCause(workflowManual bool) string { if workflowManual { - return "the PR edits CI workflow / action files, which the lane never merges unattended" + return prstage.CauseWorkflowPathManual } - return "the PR edits CI workflow / action files: awaiting owner approval — a hive owner / trusted merger's GitHub **Approve** review on the current head (or a dashboard `/hive decision approve`) releases the fence and the hive merges it; approval on an earlier head does not count, so re-approve after a push" + return prstage.CauseWorkflowPathAwaitingApproval } // decisionCauseFor is decisionCause with the workflow-path fence's standing @@ -379,7 +380,7 @@ func decisionCauseFor(reason string, workflowManual bool) string { case reason == contributorLaneReasonWorkflowPath: return workflowPathCause(workflowManual) case reason == contributorLaneReasonTestsRemoved: - return "the PR removes tests, which the lane never merges unattended" + return prstage.CauseTestsRemoved case strings.HasPrefix(reason, stageReasonForkGuard): // RouteHuman names the fork-guard checks from the evidence. return "" @@ -387,21 +388,21 @@ func decisionCauseFor(reason string, workflowManual bool) string { // RouteHuman renders the verdict itself from the evidence. return "" case reason == contributorLaneReasonReporterTrustHold: - return "the reporter-trust hold is in place" + return prstage.CauseReporterTrustHold case reason == autoMergeReasonHumanMergePath, reason == autoMergeReasonHumanMergePathEvidence: - return "the PR touches a human-merge path (auto_merge.human_merge_paths)" + return prstage.CauseHumanMergePath case reason == autoMergeReasonIntentUnauthorized, reason == autoMergeReasonIntentEvidence: - return "the merge intent could not be authorized" + return prstage.CauseIntentUnauthorized case strings.HasPrefix(reason, workflowApprovalUntrustedPrefix): - return "GitHub Actions is holding the workflow runs for approval and Hive cannot start them: `" + workflowApprovalCommand + "` on this repository belongs to Prow, which does not trust the Hive App. A maintainer must comment `" + workflowApprovalCommand + "` (and `/lgtm` + `/approve` for tide), or install `" + oktotest.WorkflowPath + "` (`hivectl ok-to-test-template`) so the repository GITHUB_TOKEN approves trusted same-repo bot runs on Hive's command." + return prstage.CauseWorkflowApprovalUntrusted() case strings.HasPrefix(reason, workflowApprovalWorkflowMissingPrefix): - return "GitHub Actions is still waiting after Hive posted `" + workflowApprovalCommand + "`. Install the self-contained `" + oktotest.WorkflowPath + "` below (or render it with `hivectl ok-to-test-template`) so the repository GITHUB_TOKEN can approve trusted same-repo bot runs, or manually approve the runs from the PR checks banner." + return prstage.CauseWorkflowApprovalWorkflowMissing() case strings.HasPrefix(reason, unauthorizedReasonPrefix): return "the hive's GitHub App is not permitted to " + strings.ReplaceAll(strings.TrimPrefix(reason, unauthorizedReasonPrefix), "-", " ") + " (GitHub answered 403 Resource not accessible by integration); the `" + unauthorizedLabel + "` note above names the permission and the step a maintainer must take" case strings.HasPrefix(reason, workflowApprovalRequiredPrefix): - return "GitHub Actions is waiting for workflow approval. Hive posted `" + workflowApprovalCommand + "`; install `" + oktotest.WorkflowPath + "` (`hivectl ok-to-test-template`) if the runs do not start, or manually approve them from the PR checks banner." + return prstage.CauseWorkflowApprovalRequired() case reason == "approval-desk-withheld": - return "the approval desk withheld this merge" + return prstage.CauseApprovalDeskWithheld case reason == autoMergeReasonMergeRefusedReview: return "GitHub refused the merge: branch protection requires an approving review from someone with write access, and the Hive App cannot give it. A GitHub **Approve** review on this head (or an App bypass in the branch rules) lets the hive merge it; the hive retries once GitHub reports the PR unblocked, or within 30 minutes" case reason == autoMergeReasonMergeRefusedMethod: @@ -409,7 +410,7 @@ func decisionCauseFor(reason string, workflowManual bool) string { case reason == "": return "" } - return "the lane reported `" + reason + "`" + return prstage.CauseLaneReported(reason) } // postHumanEntry writes the 085 / 090 entry comment once per stage visit, diff --git a/src/pkg/stageengine/prstage/causes.go b/src/pkg/stageengine/prstage/causes.go new file mode 100644 index 0000000000..4356bf6706 --- /dev/null +++ b/src/pkg/stageengine/prstage/causes.go @@ -0,0 +1,47 @@ +package prstage + +import "github.com/hivecommons/hive/pkg/oktotest" + +// WorkflowApprovalCommand is the comment the hive posts to have the +// repository's ok-to-test workflow approve held workflow runs. +const WorkflowApprovalCommand = "/ok-to-test" + +// Decision causes: the prose the 085 comment gives for a non-trust +// human-only lane reason. The automerge sweep renders them and the stage +// goldens expect them, so the wording lives here once (hivecommons/hive#15384). +const ( + CauseTestsRemoved = "the PR removes tests, which the lane never merges unattended" + CauseReporterTrustHold = "the reporter-trust hold is in place" + CauseHumanMergePath = "the PR touches a human-merge path (auto_merge.human_merge_paths)" + CauseIntentUnauthorized = "the merge intent could not be authorized" + CauseApprovalDeskWithheld = "the approval desk withheld this merge" + // CauseWorkflowPathManual is the workflow-path fence read as a rule a + // person merges around. + CauseWorkflowPathManual = "the PR edits CI workflow / action files, which the lane never merges unattended" + // CauseWorkflowPathAwaitingApproval is the same fence awaiting the + // owner's explicit approval (hivecommons/hive#14664). + CauseWorkflowPathAwaitingApproval = "the PR edits CI workflow / action files: awaiting owner approval — a hive owner / trusted merger's GitHub **Approve** review on the current head (or a dashboard `/hive decision approve`) releases the fence and the hive merges it; approval on an earlier head does not count, so re-approve after a push" +) + +// CauseWorkflowApprovalUntrusted is the cause when the repository's +// ok-to-test command belongs to Prow, which does not trust the Hive App. +func CauseWorkflowApprovalUntrusted() string { + return "GitHub Actions is holding the workflow runs for approval and Hive cannot start them: `" + WorkflowApprovalCommand + "` on this repository belongs to Prow, which does not trust the Hive App. A maintainer must comment `" + WorkflowApprovalCommand + "` (and `/lgtm` + `/approve` for tide), or install `" + oktotest.WorkflowPath + "` (`hivectl ok-to-test-template`) so the repository GITHUB_TOKEN approves trusted same-repo bot runs on Hive's command." +} + +// CauseWorkflowApprovalWorkflowMissing is the cause when runs stay held after +// the hive posted the command and the repository has no ok-to-test workflow. +func CauseWorkflowApprovalWorkflowMissing() string { + return "GitHub Actions is still waiting after Hive posted `" + WorkflowApprovalCommand + "`. Install the self-contained `" + oktotest.WorkflowPath + "` below (or render it with `hivectl ok-to-test-template`) so the repository GITHUB_TOKEN can approve trusted same-repo bot runs, or manually approve the runs from the PR checks banner." +} + +// CauseWorkflowApprovalRequired is the cause when runs are held and the hive +// has just posted the command. +func CauseWorkflowApprovalRequired() string { + return "GitHub Actions is waiting for workflow approval. Hive posted `" + WorkflowApprovalCommand + "`; install `" + oktotest.WorkflowPath + "` (`hivectl ok-to-test-template`) if the runs do not start, or manually approve them from the PR checks banner." +} + +// CauseLaneReported is the fallback cause naming an unrecognised lane reason. +func CauseLaneReported(reason string) string { + return "the lane reported `" + reason + "`" +} diff --git a/src/pkg/stageengine/stage_goldens_test.go b/src/pkg/stageengine/stage_goldens_test.go index 10d9c0c91a..94e564db9a 100644 --- a/src/pkg/stageengine/stage_goldens_test.go +++ b/src/pkg/stageengine/stage_goldens_test.go @@ -34,7 +34,7 @@ import ( "time" "github.com/hivecommons/hive/pkg/authorkind" - "github.com/hivecommons/hive/pkg/oktotest" + "github.com/hivecommons/hive/pkg/stageengine/prstage" "github.com/hivecommons/hive/pkg/stagelabels" ) @@ -1080,30 +1080,30 @@ func decisionCause(reason string) string { strings.HasPrefix(reason, "excluded-label:"), reason == "sentinel", reason == contributorLaneReasonSentinelBlocked: return "" case reason == contributorLaneReasonWorkflowPath: - return "the PR edits CI workflow / action files, which the lane never merges unattended" + return prstage.CauseWorkflowPathManual case reason == contributorLaneReasonTestsRemoved: - return "the PR removes tests, which the lane never merges unattended" + return prstage.CauseTestsRemoved case reason == contributorLaneReasonNoReviewer, reason == StageReasonVerdictRequiresHuman, reason == StageReasonDecisionRequested: // RouteHuman renders the verdict itself from the evidence. return "" case reason == contributorLaneReasonReporterTrustHold: - return "the reporter-trust hold is in place" + return prstage.CauseReporterTrustHold case reason == autoMergeReasonHumanMergePath, reason == autoMergeReasonHumanMergePathEvidence: - return "the PR touches a human-merge path (auto_merge.human_merge_paths)" + return prstage.CauseHumanMergePath case reason == autoMergeReasonIntentUnauthorized, reason == autoMergeReasonIntentEvidence: - return "the merge intent could not be authorized" + return prstage.CauseIntentUnauthorized case strings.HasPrefix(reason, workflowApprovalUntrustedPrefix): - return "GitHub Actions is holding the workflow runs for approval and Hive cannot start them: `" + workflowApprovalCommand + "` on this repository belongs to Prow, which does not trust the Hive App. A maintainer must comment `" + workflowApprovalCommand + "` (and `/lgtm` + `/approve` for tide), or install `" + oktotest.WorkflowPath + "` (`hivectl ok-to-test-template`) so the repository GITHUB_TOKEN approves trusted same-repo bot runs on Hive's command." + return prstage.CauseWorkflowApprovalUntrusted() case strings.HasPrefix(reason, workflowApprovalWorkflowMissingPrefix): - return "GitHub Actions is still waiting after Hive posted `" + workflowApprovalCommand + "`. Install the self-contained `" + oktotest.WorkflowPath + "` below (or render it with `hivectl ok-to-test-template`) so the repository GITHUB_TOKEN can approve trusted same-repo bot runs, or manually approve the runs from the PR checks banner." + return prstage.CauseWorkflowApprovalWorkflowMissing() case strings.HasPrefix(reason, workflowApprovalRequiredPrefix): - return "GitHub Actions is waiting for workflow approval. Hive posted `" + workflowApprovalCommand + "`; install `" + oktotest.WorkflowPath + "` (`hivectl ok-to-test-template`) if the runs do not start, or manually approve them from the PR checks banner." + return prstage.CauseWorkflowApprovalRequired() case reason == "approval-desk-withheld": - return "the approval desk withheld this merge" + return prstage.CauseApprovalDeskWithheld case reason == "": return "" } - return "the lane reported `" + reason + "`" + return prstage.CauseLaneReported(reason) } var humanConflictReasons = map[string]bool{"conflicting": true, "not-mergeable": true, "label:needs-rebase": true} @@ -1131,4 +1131,3 @@ func dcoState(total, unsigned int) stagelabels.DCOState { const contributorLaneReasonRegistryTrusted = "contributor-lane:" + "registry-trusted" const workflowApprovalUntrustedPrefix = "workflow-approval-required:untrusted-commenter:" const workflowApprovalWorkflowMissingPrefix = "workflow-approval-required:missing-workflow:" -const workflowApprovalCommand = "/ok-to-test" From 4091817bae2a1edf4968eb6103a18b633b1a8a22 Mon Sep 17 00:00:00 2001 From: "hivecommons-hive[bot]" <280983584+hivecommons-hive[bot]@users.noreply.github.com> Date: Thu, 29 Oct 2026 12:36:39 +0000 Subject: [PATCH 2/3] changelog: fragment for #15385 Generated by changelog-fragment-guard from the PR title (#5675). Edit the wording freely, or replace this file with the no-changelog label if the change is not user-visible. Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Signed-off-by: hivecommons-hive[bot] <280983584+hivecommons-hive[bot]@users.noreply.github.com> --- changelog.d/changed-15385.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/changed-15385.md diff --git a/changelog.d/changed-15385.md b/changelog.d/changed-15385.md new file mode 100644 index 0000000000..132d13b221 --- /dev/null +++ b/changelog.d/changed-15385.md @@ -0,0 +1 @@ +- chore(stageengine): share decision-cause prose between automerge and goldens test (#15385) From 5a490c73e47b54721931792e027f1f60dc51d12b Mon Sep 17 00:00:00 2001 From: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> Date: Thu, 29 Oct 2026 08:38:52 -0400 Subject: [PATCH 3/3] changelog: drop malformed duplicate fragment, keep the bulleted one Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> --- changelog.d/changed-15385.md | 2 +- changelog.d/changed-decision-cause-prose-shared.md | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) delete mode 100644 changelog.d/changed-decision-cause-prose-shared.md diff --git a/changelog.d/changed-15385.md b/changelog.d/changed-15385.md index 132d13b221..8949df19a5 100644 --- a/changelog.d/changed-15385.md +++ b/changelog.d/changed-15385.md @@ -1 +1 @@ -- chore(stageengine): share decision-cause prose between automerge and goldens test (#15385) +- chore(stageengine): share decision-cause prose between automerge and goldens test (#15384, #15385) diff --git a/changelog.d/changed-decision-cause-prose-shared.md b/changelog.d/changed-decision-cause-prose-shared.md deleted file mode 100644 index 35abcb4d0c..0000000000 --- a/changelog.d/changed-decision-cause-prose-shared.md +++ /dev/null @@ -1 +0,0 @@ -Decision-cause prose shared between the automerge sweep and the stage goldens test through `pkg/stageengine/prstage` (#15384)