diff --git a/docs/pr-review-agent/maintainer-comment-gate.md b/docs/pr-review-agent/maintainer-comment-gate.md index 2d5052a75..58ef33628 100644 --- a/docs/pr-review-agent/maintainer-comment-gate.md +++ b/docs/pr-review-agent/maintainer-comment-gate.md @@ -116,6 +116,10 @@ minimized with classifier `RESOLVED`. In practice: `::warning::… fixed-unverified:`. The harness then re-answers with the branch commit whose diff removes the token, when one exists. Otherwise the next pass re-answers the disposition, which is not settled. + When the push guard rebased the cited commit during the pass, that sha never + reaches the branch. The harness first edits the reply so its marker cites the + rebased successor that landed (#2156), then judges that commit by the same + rules. - **A maintainer clears it without dev-lead (#1910/#1918).** When dev-lead is suppressed, rate-limited, cancelled, or never dispatched, a maintainer can run [`scripts/maintainer-resolve-comment.sh`](../../scripts/maintainer-resolve-comment.sh) diff --git a/prompts/dev-lead/fix-bot-comment.md b/prompts/dev-lead/fix-bot-comment.md index 40f1e68e6..3f7a49d2a 100644 --- a/prompts/dev-lead/fix-bot-comment.md +++ b/prompts/dev-lead/fix-bot-comment.md @@ -55,6 +55,7 @@ Analyze the bot's findings and address each actionable issue: 2. Locate the referenced files and line numbers using Read/Grep/Glob tools 3. Apply targeted fixes using Edit/Write tools 4. **Reply to each fixed thread with the specific change** — the harness resolves the addressed bot threads afterward (see below); do not resolve them yourself +5. **Disposition the bot's issue comment when the finding came from one** — a review thread and a PR issue comment are answered differently; see [Fixing a finding posted as a PR issue comment](#fixing-a-finding-posted-as-a-pr-issue-comment-2261) ### Replying to threads from this bot @@ -109,6 +110,27 @@ The claim payload is schema `v1` — one comment per reply, with a full 40-char **Do not resolve the thread yourself.** You must not call the `resolveReviewThread` (or `unresolveReviewThread`) GraphQL mutation under any circumstance — resolution is done **only** by the harness (`dev-lead-fix-reviews.sh`), whose deterministic guards are the authoritative merge gate. The harness resolves every bot thread you addressed with an our-account addressed-marker reply, plus any thread from this bot marked `isOutdated: true`. Your reply and its marker are your only lever on resolution. +### Fixing a finding posted as a PR issue comment (#2261) + +Every registered reviewer bot (`scripts/lib/reviewer-sources.tsv`), not only CodeRabbit, can post a finding as a PR **issue comment** instead of a review thread: CodeAnt's `## CodeAnt Nitpicks`, a Qodo or CodeRabbit summary, a SonarCloud quality-gate comment. The comment that triggered this pass is one, and `${COMMENT_NODE_ID}` is its node id. An issue comment has **no** review thread, so nothing in *Replying to threads from this bot* applies to it. + +**The addressed-marker and the claim are for review threads only. They do not disposition an issue comment.** The maintainer-comment gate clears an issue comment only on a verified `dev-lead:comment-disposition` reply. A "Fixed in …" PR comment that ends with `` and a claim leaves the bot's comment undispositioned, the retries run out, and the PR can never be approved (PR #2205). Never put the addressed-marker or a claim in a PR comment. + +When you fix a finding from an issue comment, **commit the fix locally first**, then post **exactly one** reply on the PR. Name the file(s) you changed and how the change addresses the finding, and end the reply with **exactly one** marker: `disposition=fixed` with the full 40-char sha of that commit. + +```bash +# First run the target and already-dispositioned check under "Non-actionable bot +# notices" below: it guards every disposition, not only `informational`. +node_id='${COMMENT_NODE_ID}' +[ -n "$node_id" ] || { echo "no triggering comment node id — not dispositioning" >&2; exit 1; } +sha=$(git rev-parse HEAD) # read AFTER committing the fix +gh pr comment "${PR_NUMBER}" --repo "${REPO}" --body "Fixed in scripts/foo.sh: replaced the unpinned curl|bash install with a SHA-verified binary download. + +" +``` + +One comment gets one reply and one marker, however many findings it lists. Say how each finding was handled, and use `fixed` if you changed code for any of them. If you changed no code, end the same single reply with `answered`, `invalid` or `out-of-scope ref=#` and the reason. `informational` is only for a notice that carries no finding (see below). The harness verifies the sha against the pushed head and minimizes the bot's comment RESOLVED; do not call `minimizeComment` yourself. *Cite the commit that fixed it* below is the rule the sha must pass, and `scripts/lib/comment-disposition-verify.sh` is the normative parser. If the same bot also opened review threads, answer those in their threads with the addressed-marker and claim, and still post the one disposition reply for the comment. + ## Deferring a valid finding that is out of scope (#2045) When a thread from this bot is a real finding that does not belong in this PR, do not leave a bare skip note: that thread can never be resolved and blocks merge. Defer it to the repo's **single** `dev-lead: deferred review findings` tracking issue (never one issue per finding): @@ -230,6 +252,7 @@ Some bot comments are pure **operational notices**, not code findings: a rate-li - Do not suppress bot rules without a documented reason - Do not modify the bot's configuration files - For every thread you fix, post a reply naming the specific change, ending with the addressed-marker — never reply-less +- For a finding you fix from a PR issue comment, post exactly one reply on the PR ending with exactly one `` marker. The addressed-marker and the claim are for review threads only: they never disposition an issue comment, so never put them in a PR comment (#2261) - **Never resolve a thread yourself**: do not call the `resolveReviewThread` (or `unresolveReviewThread`) mutation. Resolution is the harness's job — it resolves the addressed and outdated threads from `${ACTOR}`; your only lever is the addressed-marker on your reply - Stay within the scope of the pull request's changed files where possible - Commit your fixes locally so your claims can cite them, but **never push**. The CI workflow pushes after you finish, verifies the push landed, and retracts any claim that did not land (#2013) @@ -242,6 +265,7 @@ After applying fixes, output a summary: Bot: ${ACTOR} Issues addressed: N - : [replied + addressed-marker] +- : [issue comment: disposition=fixed sha=] - : outdated — replied (harness resolves) Files changed: Skipped (informational): diff --git a/scripts/dev-lead-fix-reviews.sh b/scripts/dev-lead-fix-reviews.sh index a6292d6aa..2309c4458 100755 --- a/scripts/dev-lead-fix-reviews.sh +++ b/scripts/dev-lead-fix-reviews.sh @@ -141,6 +141,10 @@ github_knows_commit() { # - earlier: a commit missing from a still-shallow checkout, one GitHub knows # (pushed, then rewritten), or one GitHub cannot be asked about is # left as is. +# A reply that also carries the review-thread addressed-marker or claim (#2261) +# is handled here in the same edit, so it has one writer: a re-point moves a +# claim citing the same commit along with the disposition, and a retraction +# removes the addressed-marker and the claim with it. # Best-effort: returns 1 on a listing/PATCH failure; the caller folds it in. sweep_fixed_dispositions() { local ref="${1:-}" window="${2:-pass}" @@ -196,6 +200,10 @@ sweep_fixed_dispositions() { fi if [ -n "$rebased" ] && git merge-base --is-ancestor "$rebased" "$ref" 2>/dev/null \ && new_body=$(cl_rewrite_disposition_sha "$body" "$rebased"); then + # #2261: a claim in the same reply citing the same commit moves with it. + if [ "$(acv_parse_claim "$body" 2>/dev/null | jq -r '.sha // ""' 2>/dev/null)" = "$sha" ]; then + new_body=$(cl_rewrite_claim_sha "$new_body" "$rebased") || new_body=$(cl_rewrite_disposition_sha "$body" "$rebased") + fi if gh api -X PATCH "repos/${REPO}/issues/comments/${id}" -f body="$new_body" >/dev/null 2>&1; then remapped=$((remapped + 1)) echo "::notice::\`fixed\` reply ${id} on PR #${PR_NUMBER}: ${sha} was rebased onto a foreign commit and landed as ${rebased} — disposition updated, not retracted (#2156)" @@ -203,7 +211,9 @@ sweep_fixed_dispositions() { fi echo "::warning::could not update \`fixed\` reply ${id} on PR #${PR_NUMBER} to the rebased commit ${rebased} — retracting it instead (#2156)" fi - new_body=$(cl_retract_disposition_body "$body" "$reason") + # #2261: the addressed-marker and claim go too, or the quoted original would + # keep a claim citing the unlanded commit. Without either, the body is unchanged. + new_body=$(cl_retract_disposition_body "$(cl_strip_claim_markers "$body" || printf '%s' "$body")" "$reason") if gh api -X PATCH "repos/${REPO}/issues/comments/${id}" -f body="$new_body" >/dev/null 2>&1; then retracted=$((retracted + 1)) echo "::warning::retracted \`fixed\` disposition reply ${id} on PR #${PR_NUMBER} (${reason}; cited ${sha:-}, remote head ${ref:-}) (#2156)" @@ -3490,6 +3500,10 @@ save_pending_replies() { # cl_retract_body, which strips both markers so it can never resolve a thread. # This pass's `fixed` disposition replies on issue comments are swept against the # same reference head (sweep_fixed_dispositions, #2156). +# Claim replies are swept on both surfaces (#2261): review-thread replies, and the +# PR issue comments the model posts when it answers a bot's issue comment the +# same way. A PR comment that also carries a `fixed` disposition is left to +# sweep_fixed_dispositions alone, so one reply is never rewritten by two sweeps. # # The reference head is the remote head. When there is no upstream (rc 1) on an # `ok` outcome, the local HEAD is what was pushed; in every other case — including @@ -3534,10 +3548,44 @@ retract_unlanded_claims() { echo "::warning::retract_unlanded_claims: could not parse the review comments on PR #${PR_NUMBER} — this pass's claim replies were NOT verified (#2013)" return 1 } - local rebased remapped=0 - while IFS=$'\t' read -r id sha; do + + # #2261: the model can also post its addressed/claim reply as a PR ISSUE comment + # (PR #2205: "Fixed in …" answering a bot's issue comment). That reply is not in + # the review-comment listing above, so its claim was never checked and kept + # citing a commit that was never pushed. Sweep the same selection (our account, + # since the pass start, carrying the marker or a claim) over the issue comments. + # A reply that also carries a `fixed` disposition is left out: it belongs to + # sweep_fixed_dispositions above, which handles its claim in the same edit. + # An unreadable listing is reported as a failure: those replies were NOT + # verified. The thread replies above are still swept. + local issue_raw="" issue_comments="" issue_rows="" + if ! issue_raw=$(gh api --paginate "repos/${REPO}/issues/${PR_NUMBER}/comments?per_page=100" 2>/dev/null) \ + || ! issue_comments=$(jq -s 'add // []' <<<"$issue_raw" 2>/dev/null) \ + || ! issue_comments=$(cl_without_fixed_dispositions "$issue_comments") \ + || ! issue_rows=$(cl_select_pass_claims "$issue_comments" "$bot_user" "$PASS_START_ISO"); then + echo "::warning::retract_unlanded_claims: could not list the issue comments on PR #${PR_NUMBER} — claim replies this pass posted as PR comments were NOT verified (#2261)" + issue_comments="" + issue_rows="" + failed=1 + fi + # One row per reply: `\t\t`. is the REST collection + # the reply lives in (pulls = review-thread reply, issues = PR issue comment), + # which is also the path segment its PATCH uses. + rows=$( + [ -z "$rows" ] || awk '{ print "pulls\t" $0 }' <<<"$rows" + [ -z "$issue_rows" ] || awk '{ print "issues\t" $0 }' <<<"$issue_rows" + ) + + local rebased remapped=0 surface listing what + while IFS=$'\t' read -r surface id sha; do [ -z "$id" ] && continue - body=$(printf '%s' "$comments" | jq -r --arg id "$id" 'first(.[] | select((.id | tostring) == $id)) | .body // ""' 2>/dev/null || echo "") + listing="$comments" + what="claim reply" + if [ "$surface" = "issues" ]; then + listing="$issue_comments" + what="PR-comment claim reply" + fi + body=$(printf '%s' "$listing" | jq -r --arg id "$id" 'first(.[] | select((.id | tostring) == $id)) | .body // ""' 2>/dev/null || echo "") if [ -z "$sha" ]; then reason="unverifiable" else @@ -3563,21 +3611,24 @@ retract_unlanded_claims() { new_body=$(cl_rewrite_claim_sha "$body" "$rebased") || new_body="" if acv_claim_in_pass "$base" "$on_ref" "$in_base" >/dev/null \ && [ -n "$new_body" ]; then - if gh api -X PATCH "repos/${REPO}/pulls/comments/${id}" -f body="$new_body" >/dev/null 2>&1; then + if gh api -X PATCH "repos/${REPO}/${surface}/comments/${id}" -f body="$new_body" >/dev/null 2>&1; then remapped=$((remapped + 1)) - echo "::notice::claim reply ${id} on PR #${PR_NUMBER}: ${sha} was rebased onto a foreign commit and landed as ${rebased} — claim updated, not retracted (#2032)" + echo "::notice::${what} ${id} on PR #${PR_NUMBER}: ${sha} was rebased onto a foreign commit and landed as ${rebased} — claim updated, not retracted (#2032)" continue fi - echo "::warning::could not update claim reply ${id} on PR #${PR_NUMBER} to the rebased commit ${rebased} — retracting it instead (#2032)" + echo "::warning::could not update ${what} ${id} on PR #${PR_NUMBER} to the rebased commit ${rebased} — retracting it instead (#2032)" fi fi fi + # cl_retract_body removes only the addressed-marker and the claim. A + # non-`fixed` `dev-lead:comment-disposition` marker in the same reply is + # kept: the disposition resolver verifies that one on its own (#2261). new_body=$(cl_retract_body "$body" "$reason") - if gh api -X PATCH "repos/${REPO}/pulls/comments/${id}" -f body="$new_body" >/dev/null 2>&1; then + if gh api -X PATCH "repos/${REPO}/${surface}/comments/${id}" -f body="$new_body" >/dev/null 2>&1; then retracted=$((retracted + 1)) - echo "::warning::retracted claim reply ${id} on PR #${PR_NUMBER} (${reason}; cited ${sha:-}, remote head ${ref:-}) (#2013)" + echo "::warning::retracted ${what} ${id} on PR #${PR_NUMBER} (${reason}; cited ${sha:-}, remote head ${ref:-}) (#2013)" else - echo "::error::could not retract claim reply ${id} on PR #${PR_NUMBER} (${reason}) — a false 'Fixed' reply may remain (#2013)" + echo "::error::could not retract ${what} ${id} on PR #${PR_NUMBER} (${reason}) — a false 'Fixed' reply may remain (#2013)" failed=1 fi done <<< "$rows" diff --git a/scripts/lib/claim-landing.sh b/scripts/lib/claim-landing.sh index 67c8c831a..af416e55c 100644 --- a/scripts/lib/claim-landing.sh +++ b/scripts/lib/claim-landing.sh @@ -96,7 +96,8 @@ cl_push_landed_verdict() { # cl_select_pass_claims # is the REST `pulls/{pr}/comments` array ({id, user.login, body, -# created_at}). Emits one `\t` row per comment that (a) our account +# created_at}), or the `issues/{pr}/comments` array, which has the same fields +# (#2261). Emits one `\t` row per comment that (a) our account # authored (bot_user or its [bot]-suffixed / stripped form), (b) was created at or # after (the pass start), and (c) still carries the addressed-marker or # a claim comment. is the parsed claim SHA, or empty when the claim is @@ -322,6 +323,20 @@ cl_escape_dashes() { printf '%s' "${t//--/-\\u002d}" } +# cl_strip_claim_markers +# without its addressed-marker and claim comment, and without trailing +# whitespace. The claim comment ends at its FIRST `-->` (as acv_parse_claim reads +# it), so a different marker later on the same line, such as a +# comment-disposition, is kept, and a claim whose JSON spans lines is removed +# whole (#2261). Returns 1 when the body cannot be processed. Pure. +cl_strip_claim_markers() { + jq -Rsr --arg marker "$_DEV_LEAD_ADDRESSED_MARKER" ' + gsub($marker; "") + | gsub(""; "") + | sub("\\s+$"; "") + ' <<<"${1:-}" 2>/dev/null +} + # cl_retract_body # The retracted form of a claim reply. Removes the addressed-marker and the claim # comment (so neither the thread gate nor another bot can treat it as a fix), @@ -349,11 +364,7 @@ cl_retract_body() { fi local stripped - stripped=$(jq -Rsr --arg marker "$_DEV_LEAD_ADDRESSED_MARKER" ' - gsub($marker; "") - | gsub(""; "") - | sub("\\s+$"; "") - ' <<<"$body" 2>/dev/null) || stripped="" + stripped=$(cl_strip_claim_markers "$body") || stripped="" local quoted quoted=$(printf '%s\n' "$stripped" | sed 's/^/> /') @@ -567,6 +578,24 @@ cl_select_fixed_dispositions() { done <<<"$rows" } +# cl_without_fixed_dispositions +# (the REST `issues/{pr}/comments` array) without the comments +# that carry a `disposition=fixed` marker, by the same test +# cl_select_fixed_dispositions selects them with. Those replies belong to the +# `fixed`-disposition sweep, which also handles a claim they carry; the claim +# sweep reads the rest, so no reply is rewritten by both (#2261). A payload +# that is JSON but not an array is echoed unchanged: the claim selector reads it +# as "no replies", as it does for the review-comment listing. Returns 1 only +# when the payload is not JSON. Pure. +cl_without_fixed_dispositions() { + jq -c ' + if type == "array" then + map(select(((objects | .body // "") + | test("" "$PATCHES/issue-401" + ! grep -q "dev-lead:addressed" "$PATCHES/issue-401" || false + ! grep -q "" "$PATCHES/issue-402" + # No claim on the PR cites a commit that is not on the branch. + ! grep -q "$cited" "$PATCHES/issue-402" || false + run acv_parse_claim "$(cat "$PATCHES/issue-402")" + [ "$status" -eq 0 ] + [ "$(jq -r .sha <<<"$output")" = "$rebased" ] +} + +@test "#2261 AC3: only OUR issue comments from THIS pass are swept; a landed claim is left alone" { + # A fix this pass committed and pushed: its claim is true. + echo fixed > f; git add f; git commit -q -m "fix(bot): address bot feedback" + git push -q origin main + local landed; landed=$(git rev-parse HEAD) + _serve_pr_comments \ + "$(_pr_comment 411 "2026-10-09T03:01:00Z" "$(_claim "$GHOST_2261")")" \ + "$(_pr_comment 412 "2026-10-09T03:01:00Z" "$(_claim "$GHOST_2261")" "mallory")" \ + "$(_pr_comment 413 "2026-10-09T02:59:59Z" "$(_claim "$GHOST_2261")")" \ + "$(_pr_comment 414 "2026-10-09T03:02:00Z" "$(_claim "$landed")")" \ + "$(_pr_comment 415 "2026-10-09T03:02:00Z" "Looked into it; nothing to change.")" + + run retract_unlanded_claims fix-bot-comment ok + [ "$status" -eq 0 ] + # Ours, this pass, never landed: retracted. + [ -f "$PATCHES/issue-411" ] + # Another author's comment, ours from before the pass start, a claim that + # landed, and a comment with no marker or claim: all untouched. + [ ! -f "$PATCHES/issue-412" ] + [ ! -f "$PATCHES/issue-413" ] + [ ! -f "$PATCHES/issue-414" ] + [ ! -f "$PATCHES/issue-415" ] + [ "$(find "$PATCHES" -type f | wc -l | tr -d '[:space:]')" -eq 1 ] +} + +@test "#2261 AC3: a claim on the second page of the issue-comment listing is still swept" { + # `gh api --paginate` prints one JSON array per page. + { + jq -c -n --argjson c "$(_pr_comment 421 "2026-10-09T03:01:00Z" "No change needed here.")" '[$c]' + jq -c -n --argjson c "$(_pr_comment 422 "2026-10-09T03:01:30Z" "$(_claim "$GHOST_2261")")" '[$c]' + } > "$ISSUE_COMMENTS" + + run retract_unlanded_claims fix-bot-comment ok + [ "$status" -eq 0 ] + [ -f "$PATCHES/issue-422" ] + grep -q "reason=not-on-ref" "$PATCHES/issue-422" + [ ! -f "$PATCHES/issue-421" ] +} + +@test "#2261 AC3: retracting a claim keeps a non-fixed disposition marker in the same reply, even on the claim's line" { + local disp="" + _serve_pr_comments \ + "$(_pr_comment 431 "2026-10-09T03:01:00Z" "$(_claim "$GHOST_2261") +${disp}")" \ + "$(_pr_comment 432 "2026-10-09T03:01:00Z" "$(_claim "$GHOST_2261") ${disp}")" + + run retract_unlanded_claims fix-bot-comment ok + [ "$status" -eq 0 ] + local id + for id in 431 432; do + [ -f "$PATCHES/issue-${id}" ] + grep -q "" "$PATCHES/issue-${id}" + ! grep -q "dev-lead:addressed" "$PATCHES/issue-${id}" || false + ! grep -q "` on the claim's line: the claim ends at the first. + _serve "$(_reply 441 "2026-10-09T03:01:00Z" "$(_claim "$GHOST_2261") ")" + + run retract_unlanded_claims fix-reviews ok + [ -f "$PATCHES/441" ] + grep -q "" "$PATCHES/441" + ! grep -q "" "$PATCHES/441" +} + +@test "#2261: a reply with a claim AND a fixed disposition is re-pointed once, both markers together" { + echo fixed > f; git add f; git commit -q -m "fix(bot): address bot feedback" + local cited; cited=$(git rev-parse HEAD) + _serve_pr_comments "$(_pr_comment 451 "2026-10-09T03:01:00Z" "$(_claim "$cited") +")" + _foreign_push merged-main.txt "from main" + push_no_clobber + local rebased; rebased=$(git rev-parse HEAD) + [ "$rebased" != "$cited" ] + + run retract_unlanded_claims fix-bot-comment ok + [ "$status" -eq 0 ] + # The fixed-disposition sweep owns the reply; the claim sweep leaves it alone. + [[ "$output" == *"\`fixed\` reply 451"*"disposition updated, not retracted"* ]] + [[ "$output" != *"PR-comment claim reply 451"* ]] + [ -f "$PATCHES/issue-451" ] + ! grep -q "$cited" "$PATCHES/issue-451" || false + ! grep -q "Retracted" "$PATCHES/issue-451" || false + run cdv_parse_disposition "$(cat "$PATCHES/issue-451")" + [ "$status" -eq 0 ] + [ "$(jq -r '[.disposition, .sha] | join(" ")' <<<"$output")" = "fixed $rebased" ] + run acv_parse_claim "$(cat "$PATCHES/issue-451")" + [ "$status" -eq 0 ] + [ "$(jq -r .sha <<<"$output")" = "$rebased" ] +} + +@test "#2261: a reply with a claim AND a fixed disposition whose commit never landed is retracted once, with neither marker left" { + _serve_pr_comments "$(_pr_comment 461 "2026-10-09T03:01:00Z" "$(_claim "$GHOST_2261") +")" + + run retract_unlanded_claims fix-bot-comment ok + [ "$status" -eq 0 ] + [[ "$output" == *"retracted \`fixed\` disposition reply 461"* ]] + [[ "$output" != *"PR-comment claim reply 461"* ]] + [ -f "$PATCHES/issue-461" ] + grep -q "" "$PATCHES/issue-461" + ! grep -q "dev-lead:comment-disposition" "$PATCHES/issue-461" || false + ! grep -q "dev-lead:addressed" "$PATCHES/issue-461" || false + ! grep -q "") +$(_pr_comment 483 "$PASS_AT" "x ")")") + [ "$(jq -c '[.[].id]' <<<"$kept")" = "[481,483]" ] + # JSON that is not a list passes through for the claim selector to read as + # "no replies"; only a payload that is not JSON fails. + run cl_without_fixed_dispositions '{}' + [ "$status" -eq 0 ] + [ "$output" = "{}" ] + run cl_without_fixed_dispositions 'not json' + [ "$status" -ne 0 ] +} + +@test "#2261: an issue-comment listing that is JSON but not a list does not fail the sweep" { + # A full-script gh stub (and any proxy) may answer the listing with an object. + # main's `fixed`-disposition sweep reads that as "no replies"; the claim sweep + # must too, or a pushed pass is reported as failed. + printf '{}' > "$ISSUE_COMMENTS" + _serve "$(_reply 495 "2026-10-09T03:01:00Z" "$(_claim "$GHOST_2261")")" + + run retract_unlanded_claims fix-reviews ok + [ "$status" -eq 0 ] + [[ "$output" != *"NOT verified"* ]] + [ -f "$PATCHES/495" ] +} + +@test "#2261: a claim whose JSON spans lines is removed whole, so the retracted reply is not selected again" { + # acv_parse_claim reads through the first ` -->` across lines; the retraction + # must remove the same span. + local body + body=$(printf 'Fixed in f.\n\n\n ' "$GHOST_2261") + run acv_parse_claim "$body" + [ "$status" -eq 0 ] + _serve "$(_reply 491 "2026-10-09T03:01:00Z" "$body")" + + run retract_unlanded_claims fix-reviews ok + [ -f "$PATCHES/491" ] + ! grep -q "" "$PATCHES/491" + # Idempotent: the next sweep finds nothing to select in the retracted reply. + run cl_select_pass_claims "$(jq -c -n --arg b "$(cat "$PATCHES/491")" \ + '[{id: 491, user: {login: "donpetry-bot"}, created_at: "2026-10-09T03:01:00Z", body: $b}]')" "donpetry-bot" "$PASS_AT" + [ "$status" -eq 0 ] + [ -z "$output" ] +} diff --git a/tests/dev-lead/unit/test_fix_reviews.bats b/tests/dev-lead/unit/test_fix_reviews.bats index c6f625371..eed9072ca 100644 --- a/tests/dev-lead/unit/test_fix_reviews.bats +++ b/tests/dev-lead/unit/test_fix_reviews.bats @@ -7257,6 +7257,90 @@ _stale_nodes() { done } +# ── #2261: a finding fixed in a bot ISSUE comment is dispositioned, not "addressed" ── +# PR #2205: fix-bot-comment fixed a CodeAnt finding posted as a PR issue comment and +# answered it like a review thread, with the addressed-marker and a claim. The +# maintainer-comment gate reads neither, so the comment was never dispositioned and +# the retries ran out. The prompt described a `fixed` disposition only for CodeRabbit +# summaries; it now describes one for every bot's issue comment. + +# _fbc_issue_comment_section — the prompt's "Fixing a finding posted as a PR issue +# comment" section, rendered as build_and_run renders it (envsubst over the +# variables the template declares) for the triggering comment IC_FIND. +_fbc_issue_comment_section() { + local p="$SCRIPT_DIR/prompts/dev-lead/fix-bot-comment.md" vars + vars=$(head -1 "$p" | sed 's///' \ + | tr ',' '\n' | awk '{gsub(/^ +| +$/, ""); if (length) printf "${%s}", $0}') + COMMENT_NODE_ID=IC_FIND PR_NUMBER=54 REPO=petry-projects/.github-private envsubst "$vars" < "$p" \ + | awk '/^### Fixing a finding posted as a PR issue comment \(#2261\)$/{f=1; next} f && /^##+ /{exit} f' +} + +@test "#2261 AC1: fix-bot-comment prompt — the addressed-marker and claim are for review threads only; an issue comment gets one fixed disposition" { + local p="$SCRIPT_DIR/prompts/dev-lead/fix-bot-comment.md" sec + # The Task steps name the issue-comment answer, not only the thread reply. + grep -qE '^5\. \*\*Disposition the bot.s issue comment when the finding came from one\*\*' "$p" + sec=$(_fbc_issue_comment_section) + [ -n "$sec" ] + [[ "$sec" == *'**The addressed-marker and the claim are for review threads only. They do not disposition an issue comment.**'* ]] + [[ "$sec" == *'Never put the addressed-marker or a claim in a PR comment.'* ]] + # Every registered reviewer bot, not only CodeRabbit. + [[ "$sec" == *'Every registered reviewer bot (`scripts/lib/reviewer-sources.tsv`), not only CodeRabbit'* ]] + # Exactly one reply, exactly one marker: fixed, with the commit's full sha. + [[ "$sec" == *'post **exactly one** reply on the PR'* ]] + [[ "$sec" == *'**exactly one** marker: `disposition=fixed` with the full 40-char sha of that commit'* ]] + [ "$(grep -c 'gh pr comment' <<<"$sec")" -eq 1 ] + [ "$(grep -c '' <<<"$sec")" -eq 1 ] # named once, as what NOT to post + # The Constraints list repeats the rule. + grep -qE '^- For a finding you fix from a PR issue comment, post exactly one reply .*.*review threads only.*#2261' "$p" +} + +@test "#2261 AC1: the prompt's issue-comment example, executed, posts one reply the disposition parser accepts as fixed for the triggering comment" { + local snip="$BATS_TEST_TMPDIR/fixed-snippet.sh" repo="$BATS_TEST_TMPDIR/fixrepo" + local posted="$BATS_TEST_TMPDIR/posted" fix_sha + _fbc_issue_comment_section | awk '/^```bash$/{f=1; next} f && /^```$/{exit} f' > "$snip" + [ -s "$snip" ] + + # The pass's local fix commit, which the reply must cite. + mkdir -p "$repo" "$posted" + git -C "$repo" init -q + echo fixed > "$repo/f" + git -C "$repo" add f + git -C "$repo" -c user.email=t@test -c user.name=T commit -q -m "fix(bot): address bot feedback" + fix_sha=$(git -C "$repo" rev-parse HEAD) + + # A gh that records each `gh pr comment` body as $posted/, and refuses any + # other call (a thread reply would be one). + cat > "$STUB_BIN_DIR/gh" < "$posted/\$((n + 1))" + ;; + *) echo "unexpected gh call: \$*" >&2; exit 1 ;; +esac +GHEOF + chmod +x "$STUB_BIN_DIR/gh" + + run bash -c "cd '$repo' && bash '$snip'" + [ "$status" -eq 0 ] + # Exactly one reply was posted. + [ "$(find "$posted" -type f | wc -l | tr -d '[:space:]')" -eq 1 ] + # It carries no thread marker… + if grep -q 'dev-lead:addressed' "$posted/1"; then false; fi + if grep -q 'dev-lead:claim' "$posted/1"; then false; fi + # …and the normative parser reads exactly one disposition: fixed, for the + # triggering comment, citing the pass's commit. + run bash -c "source '$SCRIPT_DIR/scripts/lib/comment-disposition-verify.sh'; cdv_parse_disposition \"\$(cat '$posted/1')\"" + [ "$status" -eq 0 ] + [ "$(jq -r .id <<<"$output")" = "IC_FIND" ] + [ "$(jq -r .disposition <<<"$output")" = "fixed" ] + [ "$(jq -r .sha <<<"$output")" = "$fix_sha" ] +} + # ── #2161 AC3: the deferred resolver's no-change branch is reachable ───────────── # It used to run after the deferral parse and the post-marker gate, so a thread with # no deferral never reached it. It now runs first, and the deferred resolver runs on