diff --git a/.github/workflows/pr-review-mention-reusable.yml b/.github/workflows/pr-review-mention-reusable.yml index fa783ca19..4ad53010e 100644 --- a/.github/workflows/pr-review-mention-reusable.yml +++ b/.github/workflows/pr-review-mention-reusable.yml @@ -40,12 +40,22 @@ jobs: # For comment events we also gate at the job level on author_association so # that the job (and its secrets) never start for external/untrusted actors. # - # Recursion guard: the ack comment this job posts itself contains - # '@donpetry-bot' and is posted via a PAT (so it DOES re-trigger workflows, - # unlike GITHUB_TOKEN), which without this guard self-loops until GitHub's - # 2500-comment cap. Skip any comment carrying our own ack marker. We match on - # the marker (not the bot actor) because donpetry-bot is also a human account - # whose own @-mention review requests must still fire. + # Recursion guard (#538): when triggered by a human the ack comment + # addresses them as '@' — but ack comments posted by the bot itself + # use a plain login (no leading '@'), so they carry no mention webhook. The + # comment is also posted via a PAT (so it DOES re-trigger workflows, unlike + # GITHUB_TOKEN), which without this guard self-loops until GitHub's + # 2500-comment cap (.github-private#860: 1,481 identical acks over ~4.5h). + # A comment the agent posts about its own work must never re-trigger the + # agent, so we exclude on TWO independent axes, belt-and-suspenders: + # 1. the bot actor — any comment authored by donpetry-bot is skipped, and + # 2. the marker — any comment carrying an '"* ]] +} + +# ── the #538 self-mention kill ─────────────────────────────────────────────── + +@test "ack: never emits a literal @donpetry-bot when the bot is the actor (comment path)" { + EVENT_NAME="issue_comment" COMMENT_USER="donpetry-bot" run_ack + [[ "$(body)" != *"@donpetry-bot"* ]] + # still addresses the bot, just without the mention-firing '@' + [[ "$(body)" == *"donpetry-bot"* ]] +} + +@test "ack: never emits a literal @donpetry-bot when the bot self-assigns as reviewer (pull_request path)" { + EVENT_NAME="pull_request" SENDER_LOGIN="donpetry-bot" run_ack + [[ "$(body)" != *"@donpetry-bot"* ]] +} + +@test "ack: a human reviewer-assigner is still @-mentioned (pull_request path)" { + EVENT_NAME="pull_request" SENDER_LOGIN="bob" run_ack + [[ "$(body)" == *"@bob"* ]] +} diff --git a/test/workflows/pr-review-mention/guard.bats b/test/workflows/pr-review-mention/guard.bats new file mode 100644 index 000000000..abad4da4e --- /dev/null +++ b/test/workflows/pr-review-mention/guard.bats @@ -0,0 +1,57 @@ +#!/usr/bin/env bats +# Tests for the handle-mention job-level `if:` guard in +# .github/workflows/pr-review-mention-reusable.yml. +# +# Pins issue #538: the mention listener must never re-trigger itself. The +# acknowledgement comment the cascade posts @-mentions donpetry-bot and carries +# an `` marker; without an exclusion that ack is an +# `issue_comment: created` event the guard reads as a fresh review request, so +# the cascade self-loops (.github-private#860: 1,481 identical acks over ~4.5h). +# +# The guard MUST stay a job-level `if:` (not a runtime step): it gates whether +# the job — and its secrets — start at all, so a bot/agent comment must be +# rejected before the job spins up. These tests therefore assert on the guard +# expression itself rather than a shell reimplementation. + +load 'helpers/setup' + +# ── recursion kill: bot-authored + agent-marker comments must be excluded ───── + +@test "guard: excludes comments authored by donpetry-bot itself" { + guard="$(tt_job_if)" + [[ "$guard" == *"github.event.comment.user.login != 'donpetry-bot'"* ]] +} + +@test "guard: excludes any comment carrying an