diff --git a/changelog.d/fixed-automerge-ok-to-test-eligibility-probe.md b/changelog.d/fixed-automerge-ok-to-test-eligibility-probe.md new file mode 100644 index 0000000000..7c8c60dd09 --- /dev/null +++ b/changelog.d/fixed-automerge-ok-to-test-eligibility-probe.md @@ -0,0 +1 @@ +- Hardened the automerge workflow-approval path against the read-only integration eligibility probe: the probe could reach the `/ok-to-test` post, where the mutation boundary refused the comment and the caller logged a WARN on every tick. The probe now skips the post and leaves it to the live sweep; live behaviour is unchanged. diff --git a/src/pkg/github/automerge/automerge_held_runs.go b/src/pkg/github/automerge/automerge_held_runs.go index 0a27335a11..3f871225f5 100644 --- a/src/pkg/github/automerge/automerge_held_runs.go +++ b/src/pkg/github/automerge/automerge_held_runs.go @@ -210,6 +210,12 @@ func (c *Engine) workflowApprovalAttention(ctx context.Context, displayRepo, own if c.workflowApprovalUntrustedKnown(owner, repo, number) { return workflowApprovalUntrustedPrefix + contextName } + if integrationEligibilityProbe(ctx) { + // The read-only eligibility probe cannot comment: its mutation + // boundary would refuse the post and WARN every tick. Skipping + // leaves the post to the live sweep. + return workflowApprovalRequiredPrefix + contextName + } firstSeen, first := c.markWorkflowApprovalCommandSeen(owner, repo, number, headSHA) state, scanned := c.workflowApprovalCommentState(ctx, displayRepo, owner, repo, number, headSHA, first) if scanned && (state.rejected || state.prowManaged) && !c.okToTestWorkflowInstalled(ctx, displayRepo, owner, repo) { diff --git a/src/pkg/github/automerge/automerge_held_runs_test.go b/src/pkg/github/automerge/automerge_held_runs_test.go index 85df75faf3..2cf239b1ff 100644 --- a/src/pkg/github/automerge/automerge_held_runs_test.go +++ b/src/pkg/github/automerge/automerge_held_runs_test.go @@ -717,3 +717,30 @@ func TestWorkflowApprovalUntrustedReasonParksAtNeedsDecision(t *testing.T) { t.Fatalf("decisionCause(%q) = %q, want Prow, the command and the workflow path named", reason, cause) } } + +func TestWorkflowApprovalAttentionSkipsCommandInReadOnlyEligibilityProbe(t *testing.T) { + var comments []string + pr := missingRequiredPR(func(p *selfAuthoredPR) { + p.workflowRuns = []map[string]any{heldRun(1, "acme/widget")} + p.commentBodies = &comments + }) + var merged []int + api := newSelfAuthoredAutoMergeAPI(t, []selfAuthoredPR{pr}, &merged) + defer api.Close() + c := newAutoMergeSweepClient(api.URL) + + probeCtx := context.WithValue(context.Background(), integrationEligibilityContextKey{}, &integrationEligibilityCapture{}) + want := workflowApprovalRequiredPrefix + "ci/build" + if got := c.workflowApprovalAttention(probeCtx, "widget", "acme", "widget", 23, "sha23", "ci/build", 1); got != want { + t.Fatalf("probe reason = %q, want %q", got, want) + } + if len(comments) != 0 { + t.Fatalf("probe posted comments %q, want none", comments) + } + if got := c.workflowApprovalAttention(context.Background(), "widget", "acme", "widget", 23, "sha23", "ci/build", 1); got != want { + t.Fatalf("live reason = %q, want %q", got, want) + } + if len(comments) != 1 || comments[0] != workflowApprovalCommandBody("sha23") { + t.Fatalf("live comments = %q, want one command after the probe", comments) + } +}