diff --git a/scripts/dev-lead-fix-reviews.sh b/scripts/dev-lead-fix-reviews.sh index 749951a9b..16eae41ea 100755 --- a/scripts/dev-lead-fix-reviews.sh +++ b/scripts/dev-lead-fix-reviews.sh @@ -635,11 +635,10 @@ resolve_addressed_bot_threads() { fi # Our own account: the addressed-marker reply must have been posted by us before - # it can authorize resolution. GraphQL author.login omits the "[bot]" suffix, so - # match both the raw BOT_USER and its [bot]-stripped form (same pattern as - # resolve_actor_outdated_threads). + # it can authorize resolution. The acv_* thread helpers below derive the + # [bot]-stripped form internally (GraphQL author.login omits the "[bot]" suffix), + # so they match both the raw BOT_USER and its stripped form. local bot_user="${BOT_USER:-donpetry-bot}" - local bot_user_stripped="${bot_user%\[bot\]}" # The enumeration pass ONLY collects candidate thread ids (unresolved, # bot-originated). It deliberately does NOT capture the last reply's body or @@ -705,7 +704,7 @@ resolve_addressed_bot_threads() { }' local resolved_count=0 - local id node_json cur_resolved reply_author reply_body + local id node_json cur_resolved comments_json marker_idx marker_body while IFS= read -r id; do [ -z "$id" ] && continue # Re-read the thread's CURRENT state immediately before resolving so a reply @@ -721,25 +720,36 @@ resolve_addressed_bot_threads() { echo "::notice::skipping thread ${id} — already resolved or state unknown at re-check (${cur_resolved})" continue fi - # The latest reply is the last node of the full-thread fetch. - reply_author=$(printf '%s' "$node_json" | jq -r '.data.node.comments.nodes[-1]?.author?.login // ""' 2>/dev/null || echo "") - reply_body=$(printf '%s' "$node_json" | jq -r '.data.node.comments.nodes[-1]?.body // ""' 2>/dev/null || echo "") - # The addressed-marker only authorizes resolution when OUR account posted it. - # A marker-bearing reply from any other human or bot is not our confirmation. - if [ "$reply_author" != "$bot_user" ] && [ "$reply_author" != "$bot_user_stripped" ]; then - echo "::notice::skipping thread ${id} — latest reply author '${reply_author}' is not our account; a marker from another account does not authorize resolution" + # ── #1735: full-thread scan, not comments(last:1) ───────────────────────── + # Our addressed-marker reply need NOT be the thread's LATEST comment. Find the + # latest comment OUR account posted carrying the marker; a bot acknowledgement + # (or our own later note) landing after it must not lock the thread unresolvable + # forever (the regression #1691 exposed). A marker from any other account still + # does not authorize resolution (acv_latest_marker_index checks the author). + comments_json=$(printf '%s' "$node_json" | jq -c '.data.node.comments.nodes // []' 2>/dev/null || echo "[]") + if ! marker_idx=$(acv_latest_marker_index "$comments_json" "$bot_user"); then + echo "::notice::skipping thread ${id} — no addressed-marker reply from our account in the thread; leaving unresolved (#1735)" + continue + fi + marker_body=$(printf '%s' "$comments_json" | jq -r --argjson i "$marker_idx" '.[$i]?.body // ""' 2>/dev/null || echo "") + + # Nothing UNADDRESSED may have landed since our marker (#1735 AC2/AC3/AC4): a bot + # acknowledgement is fine, but a bot NEW finding or ANY human comment (regardless + # of content, preserving #1415) blocks, and an undeterminable post-marker comment + # fails closed. This composes with the #1692 claim gate below (AC5) — both must pass. + local post_reason post_rc + post_reason=$(acv_post_marker_clear "$comments_json" "$marker_idx" "$bot_user") && post_rc=0 || post_rc=$? + if [ "${post_rc:-0}" -ne 0 ]; then + echo "::notice::skipping thread ${id} — an unaddressed comment landed after our marker (${post_reason}); leaving unresolved (#1735)" continue fi - # And the reply must actually carry the addressed-marker — a skip note or any - # other reply leaves the thread open. - review_reply_is_addressed_marker "$reply_body" || continue # ── #1692: the marker is now a VERIFIABLE CLAIM, not an assertion ────────── # A marker with no claim payload (pre-migration replies) is unverifiable — do # NOT resolve (the safe direction; may leave some existing threads open until # re-run). A malformed/contract-violating claim is likewise unverifiable. local claim_json parse_reason - if ! claim_json=$(acv_parse_claim "$reply_body"); then + if ! claim_json=$(acv_parse_claim "$marker_body"); then parse_reason="$claim_json" echo "::notice::skipping thread ${id} — addressed-marker claim not verifiable (${parse_reason:-unparseable}); leaving unresolved (#1692)" continue @@ -785,11 +795,11 @@ resolve_addressed_bot_threads() { fi fi - # AC4: honour a standing maintainer disposition. Scan ALL comments; if a - # marker-less human maintainer asserted a required disposition, resolve only if - # the verified commit postdates it. Unparseable disposition -> fail closed. - local comments_json disposition disp_rc - comments_json=$(printf '%s' "$node_json" | jq -c '.data.node.comments.nodes // []' 2>/dev/null || echo "[]") + # AC4: honour a standing maintainer disposition. Scan ALL comments (reusing the + # comments_json captured above); if a marker-less human maintainer asserted a + # required disposition, resolve only if the verified commit postdates it. + # Unparseable disposition -> fail closed. + local disposition disp_rc disposition=$(acv_latest_maintainer_disposition "$comments_json" "$bot_user") && disp_rc=0 || disp_rc=$? if [ "${disp_rc:-0}" -eq 2 ]; then echo "::notice::skipping thread ${id} — a maintainer disposition could not be parsed; leaving unresolved (fail closed) (#1692 AC4)" diff --git a/scripts/lib/addressed-claim-verify.sh b/scripts/lib/addressed-claim-verify.sh index 23319b1f6..756ffdec6 100644 --- a/scripts/lib/addressed-claim-verify.sh +++ b/scripts/lib/addressed-claim-verify.sh @@ -63,6 +63,25 @@ readonly _ACV_CLAIM_SUFFIX=' -->' # merge" shape) rather than any human chatter, so a neutral "thanks" never blocks. readonly _ACV_DISPOSITION_RE_UPPER='(REQUIRED|MUST BE (FIXED|ADDRESSED|RESOLVED|CHANGED)|CHANGES REQUIRED|BLOCKING|REQUEST(ING|ED)? CHANGES)' +# Post-marker BOT-comment classification (#1735 AC2/AC4). A review bot that replies +# AFTER our addressed-marker either ACKNOWLEDGES (accepts our refutation / records a +# custom rule — the codeant-ai "✅ Customized review instruction saved!" shape) or +# raises a NEW finding. An acknowledgement must not keep the thread open; a new +# finding must. Both regexes are matched case-insensitively (against the upper-cased +# body). They are deliberately NARROW and the finding signal is checked FIRST, so a +# comment that is neither a clear ack nor a clear finding — or that mixes ack phrasing +# with a new point — resolves toward "undeterminable" / "finding" (fail closed): a +# stuck thread is a nuisance, a wrongly-resolved one clears a merge gate. +readonly _ACV_BOT_ACK_RE_UPPER='(CUSTOMIZED REVIEW INSTRUCTION SAVED|REVIEW INSTRUCTION SAVED|INSTRUCTION (SAVED|RECORDED)|ACKNOWLEDG|WILL NOT (FLAG|REPORT|RAISE)|NO (FURTHER|MORE) (ACTION|CONCERNS?)|MARKING (THIS )?(AS )?RESOLVED|DISMISS(ED|ING)?)' +readonly _ACV_BOT_FINDING_RE_UPPER='(POTENTIAL ISSUE|REFACTOR SUGGESTION|SUGGESTION:|NEW (ISSUE|FINDING|PROBLEM|CONCERN)|SECURITY|VULNERABILIT|BUG|MUST (FIX|BE FIXED)|SHOULD (FIX|BE FIXED)|NITPICK|CRITICAL|BLOCKER|CHANGES REQUIRED)' +# A NEGATED acknowledgement ("cannot acknowledge this", "won't acknowledge", "unable to +# acknowledge") is not an ack — the bare ACKNOWLEDG alternative above would otherwise +# clear a thread the bot explicitly refused to accept. Detected before the ack match so +# such comments fall through to "undeterminable" (fail closed → thread stays open). The +# negator may be separated from ACKNOWLEDG by up to three words (e.g. "unable to fully +# acknowledge") so it survives light hedging. +readonly _ACV_BOT_ACK_NEGATION_RE_UPPER='(CANNOT|CAN.?T|COULD ?NOT|COULDN.?T|WILL NOT|WON.?T|DO(ES)? NOT|DON.?T|DOESN.?T|DID ?NOT|DIDN.?T|UNABLE|NOT ABLE|NEVER|NOT)[[:space:]]+([A-Z]+[[:space:]]+){0,3}ACKNOWLEDG' + # acv_parse_claim # Extract and validate the single claim payload from a reply body. On success, # echoes the canonical compact JSON and returns 0. On any failure, echoes a reason @@ -124,6 +143,133 @@ acv_parse_claim() { return 0 } +# acv_latest_marker_index +# Full-thread scan for OUR addressed-marker reply (#1735 AC1). is a +# JSON array of {author:{login,__typename}, body, createdAt} in thread order. Echoes +# the 0-based index of the LATEST comment authored by our account (bot_user or its +# [bot]-stripped form) that carries the dev-lead addressed-marker, and returns 0. +# Returns 1 (echoing nothing) when no such reply exists — the unchanged no-marker +# case. The marker need NOT be the thread's last comment: a bot acknowledgement (or +# our own later note) landing after it no longer hides the marker (the pre-#1735 +# comments(last:1) hole). Pure — no gh/git/network. +acv_latest_marker_index() { + local comments_json="${1:-}" bot_user="${2:-}" + local bot_user_stripped="${bot_user%\[bot\]}" + + # Single jq pass (no per-comment subprocess loop): select our-account comments whose + # body carries the addressed-marker and echo the LAST such index. The marker regex is + # the SAME _DEV_LEAD_ADDRESSED_MARKER constant review_reply_is_addressed_marker uses, + # so the pattern still has a single source of truth. Only OUR account's marker + # authorizes resolution (a foreign marker does not). + local idx + idx=$(jq -r \ + --arg bot_user "$bot_user" \ + --arg bot_user_stripped "$bot_user_stripped" \ + --arg pattern "$_DEV_LEAD_ADDRESSED_MARKER" \ + 'if type == "array" then + to_entries + | map(select( + (.value.author.login == $bot_user or .value.author.login == $bot_user_stripped) and + ((.value.body // "") | test($pattern)) + )) + | last | .key // "" + else + "" + end' <<<"$comments_json" 2>/dev/null) || return 1 + + if [[ -n "$idx" ]]; then + echo "$idx" + return 0 + fi + return 1 +} + +# acv_bot_comment_is_acknowledgement +# Classify a post-marker BOT comment (#1735 AC2/AC4). Returns: +# 0 = acknowledgement / no new finding (does not block resolution) +# 1 = a new finding (blocks — thread stays open) +# 2 = undeterminable (fail closed — thread stays open, AC4) +# The finding signal is checked FIRST so a comment that both acknowledges and raises +# a new point fails toward blocking. Pure — no gh/git/network. +acv_bot_comment_is_acknowledgement() { + local body="${1:-}" + [[ -z "$body" ]] && return 2 + local up="${body^^}" + if [[ "$up" =~ $_ACV_BOT_FINDING_RE_UPPER ]]; then + return 1 + fi + # A negated acknowledgement is not an ack — fail closed rather than clearing. + if [[ "$up" =~ $_ACV_BOT_ACK_NEGATION_RE_UPPER ]]; then + return 2 + fi + if [[ "$up" =~ $_ACV_BOT_ACK_RE_UPPER ]]; then + return 0 + fi + return 2 +} + +# acv_post_marker_clear +# Assert nothing UNADDRESSED has landed since our marker reply (#1735 AC2/AC3/AC4). +# Scans every comment AFTER and classifies it, reusing the SAME +# discriminators the rest of the gate uses (no second classifier, #1735 AC3): +# - our own account (login == bot_user / stripped) -> ours, ignored; +# - an agent-marker-bearing comment (review_thread_is_agent_authored) -> ours; +# - a bot comment (author __typename Bot, or login endswith [bot]) -> classified +# by acv_bot_comment_is_acknowledgement: ack clears, finding blocks (rc1), +# undeterminable fails closed (rc2); +# - any other marker-less User comment ALWAYS blocks (rc1), regardless of content +# — this preserves the #1415 maintainer guard exactly; +# - any other undeterminable author type -> fail closed (rc2). +# Echoes a short reason token ("clear" | "bot-finding" | "bot-ambiguous" | "human" | +# "unknown-author" | "unparseable"). Returns 0 only when clear. Pure. +acv_post_marker_clear() { + local comments_json="${1:-}" marker_index="${2:-0}" bot_user="${3:-}" + local bot_user_stripped="${bot_user%\[bot\]}" + + # Single jq pass extracts the three fields of every post-marker comment as one TSV + # row (login, typename, base64(body)). Body is base64-encoded so embedded tabs and + # newlines survive the row split; the loop then decodes it and runs the SAME shared + # discriminators (review_thread_is_agent_authored, acv_bot_comment_is_acknowledgement) + # — no jq is spawned inside the loop and no second classifier is introduced (#1735 AC3). + local rows + rows=$(jq -r --argjson mi "$marker_index" ' + if type == "array" then + to_entries[] + | select(.key > $mi) + | [ (.value.author.login // ""), (.value.author.__typename // ""), ((.value.body // "") | @base64) ] + | @tsv + else empty end + ' <<<"$comments_json" 2>/dev/null) || { echo "unparseable"; return 2; } + [[ -z "$rows" ]] && { echo "clear"; return 0; } + + local login typename body_b64 body ack_rc + while IFS=$'\t' read -r login typename body_b64; do + body=$(base64 --decode <<<"$body_b64" 2>/dev/null || printf '') + # Our own account is never an unaddressed comment. + [[ "$login" == "$bot_user" || "$login" == "$bot_user_stripped" ]] && continue + # An agent-marker-bearing comment is ours by the shared discriminator. + review_thread_is_agent_authored "$body" && continue + if [[ "$typename" == "Bot" || "$login" == *"[bot]" ]]; then + acv_bot_comment_is_acknowledgement "$body" && ack_rc=0 || ack_rc=$? + if [[ "$ack_rc" -eq 0 ]]; then + continue + elif [[ "$ack_rc" -eq 1 ]]; then + echo "bot-finding"; return 1 + else + echo "bot-ambiguous"; return 2 + fi + fi + if [[ "$typename" == "User" ]]; then + echo "human"; return 1 + fi + # Undeterminable author type -> fail closed. + echo "unknown-author"; return 2 + done <<<"$rows" + + echo "clear" + return 0 +} + # acv_verify_intersection # The file-level hard gate (AC2/AC3). is the claim's `files` array; # the two diff lists are newline-separated repo-relative paths (own = the named diff --git a/tests/dev-lead/unit/test_addressed_claim_verify.bats b/tests/dev-lead/unit/test_addressed_claim_verify.bats index 2a680101a..403b6de08 100644 --- a/tests/dev-lead/unit/test_addressed_claim_verify.bats +++ b/tests/dev-lead/unit/test_addressed_claim_verify.bats @@ -183,6 +183,182 @@ setup() { [[ "$output" == "2026-09-05T00:00:00Z" ]] } +# --------------------------------------------------------------------------- +# acv_latest_marker_index — find our addressed-marker reply anywhere in the thread (#1735 AC1) +# --------------------------------------------------------------------------- + +@test "acv_latest_marker_index: our marker reply as the only comment -> index 0" { + local comments='[{"author":{"login":"donpetry-bot","__typename":"User"},"body":"Applied. ","createdAt":"2026-09-01T10:00:00Z"}]' + run acv_latest_marker_index "$comments" "donpetry-bot" + [[ "$status" -eq 0 ]] + [[ "$output" == "0" ]] +} + +@test "acv_latest_marker_index: marker reply after a bot finding -> its index (not comments(last:1))" { + local comments='[ + {"author":{"login":"codeant-ai[bot]","__typename":"Bot"},"body":"Potential issue here.","createdAt":"2026-09-01T09:00:00Z"}, + {"author":{"login":"donpetry-bot","__typename":"User"},"body":"Refuted. ","createdAt":"2026-09-01T10:00:00Z"} + ]' + run acv_latest_marker_index "$comments" "donpetry-bot" + [[ "$status" -eq 0 ]] + [[ "$output" == "1" ]] +} + +@test "acv_latest_marker_index: marker NOT the latest comment (bot ack follows) -> still found" { + local comments='[ + {"author":{"login":"donpetry-bot","__typename":"User"},"body":"Refuted. ","createdAt":"2026-09-01T10:00:00Z"}, + {"author":{"login":"codeant-ai[bot]","__typename":"Bot"},"body":"Customized review instruction saved!","createdAt":"2026-09-01T11:00:00Z"} + ]' + run acv_latest_marker_index "$comments" "donpetry-bot" + [[ "$status" -eq 0 ]] + [[ "$output" == "0" ]] +} + +@test "acv_latest_marker_index: multiple of our markers -> latest index wins" { + local comments='[ + {"author":{"login":"donpetry-bot","__typename":"User"},"body":"First. ","createdAt":"2026-09-01T10:00:00Z"}, + {"author":{"login":"codeant-ai[bot]","__typename":"Bot"},"body":"still an issue","createdAt":"2026-09-01T11:00:00Z"}, + {"author":{"login":"donpetry-bot","__typename":"User"},"body":"Second. ","createdAt":"2026-09-01T12:00:00Z"} + ]' + run acv_latest_marker_index "$comments" "donpetry-bot" + [[ "$status" -eq 0 ]] + [[ "$output" == "2" ]] +} + +@test "acv_latest_marker_index: no marker anywhere -> rc1 (unchanged no-marker behavior)" { + local comments='[{"author":{"login":"donpetry-bot","__typename":"User"},"body":"Looked into it, no change.","createdAt":"2026-09-01T10:00:00Z"}]' + run acv_latest_marker_index "$comments" "donpetry-bot" + [[ "$status" -eq 1 ]] +} + +@test "acv_latest_marker_index: marker from another account -> rc1 (not ours)" { + local comments='[{"author":{"login":"someone-else","__typename":"User"},"body":"Applied. ","createdAt":"2026-09-01T10:00:00Z"}]' + run acv_latest_marker_index "$comments" "donpetry-bot" + [[ "$status" -eq 1 ]] +} + +@test "acv_latest_marker_index: empty array -> rc1" { + run acv_latest_marker_index '[]' "donpetry-bot" + [[ "$status" -eq 1 ]] +} + +# --------------------------------------------------------------------------- +# acv_bot_comment_is_acknowledgement — ack / finding / undeterminable (#1735 AC2/AC4) +# --------------------------------------------------------------------------- + +@test "acv_bot_comment_is_acknowledgement: codeant 'Customized review instruction saved' -> rc0 (ack)" { + run acv_bot_comment_is_acknowledgement "✅ Customized review instruction saved!" + [[ "$status" -eq 0 ]] +} + +@test "acv_bot_comment_is_acknowledgement: 'Acknowledged, will not flag this again' -> rc0 (ack)" { + run acv_bot_comment_is_acknowledgement "Acknowledged. We will not flag this pattern again." + [[ "$status" -eq 0 ]] +} + +@test "acv_bot_comment_is_acknowledgement: a new finding -> rc1 (blocks)" { + run acv_bot_comment_is_acknowledgement "Potential issue: this introduces a race condition on shutdown." + [[ "$status" -eq 1 ]] +} + +@test "acv_bot_comment_is_acknowledgement: ack phrasing mixed with a new finding -> rc1 (finding wins, fail toward blocking)" { + run acv_bot_comment_is_acknowledgement "Instruction saved, but there is a new issue: unhandled null." + [[ "$status" -eq 1 ]] +} + +@test "acv_bot_comment_is_acknowledgement: undeterminable chatter -> rc2 (fail closed)" { + run acv_bot_comment_is_acknowledgement "Interesting perspective on the tradeoffs here." + [[ "$status" -eq 2 ]] +} + +@test "acv_bot_comment_is_acknowledgement: empty body -> rc2 (fail closed)" { + run acv_bot_comment_is_acknowledgement "" + [[ "$status" -eq 2 ]] +} + +@test "acv_bot_comment_is_acknowledgement: negated 'cannot acknowledge this' -> rc2 (not an ack, fail closed)" { + run acv_bot_comment_is_acknowledgement "I cannot acknowledge this refutation as valid." + [[ "$status" -eq 2 ]] +} + +@test "acv_bot_comment_is_acknowledgement: negated 'unable to fully acknowledge' -> rc2 (not an ack, fail closed)" { + run acv_bot_comment_is_acknowledgement "We are unable to fully acknowledge the change." + [[ "$status" -eq 2 ]] +} + +# --------------------------------------------------------------------------- +# acv_post_marker_clear — nothing unaddressed since our marker (#1735 AC2/AC3/AC4) +# --------------------------------------------------------------------------- + +@test "acv_post_marker_clear: nothing after the marker -> clear rc0" { + local comments='[{"author":{"login":"donpetry-bot","__typename":"User"},"body":"Refuted. ","createdAt":"2026-09-01T10:00:00Z"}]' + run acv_post_marker_clear "$comments" 0 "donpetry-bot" + [[ "$status" -eq 0 ]] + [[ "$output" == "clear" ]] +} + +@test "acv_post_marker_clear: bot acknowledgement after our marker -> clear rc0 (AC2)" { + local comments='[ + {"author":{"login":"donpetry-bot","__typename":"User"},"body":"Refuted. ","createdAt":"2026-09-01T10:00:00Z"}, + {"author":{"login":"codeant-ai[bot]","__typename":"Bot"},"body":"✅ Customized review instruction saved!","createdAt":"2026-09-01T11:00:00Z"} + ]' + run acv_post_marker_clear "$comments" 0 "donpetry-bot" + [[ "$status" -eq 0 ]] + [[ "$output" == "clear" ]] +} + +@test "acv_post_marker_clear: bot NEW finding after our marker -> blocks rc1 (AC2)" { + local comments='[ + {"author":{"login":"donpetry-bot","__typename":"User"},"body":"Refuted. ","createdAt":"2026-09-01T10:00:00Z"}, + {"author":{"login":"codeant-ai[bot]","__typename":"Bot"},"body":"Potential issue: new race condition on shutdown.","createdAt":"2026-09-01T11:00:00Z"} + ]' + run acv_post_marker_clear "$comments" 0 "donpetry-bot" + [[ "$status" -eq 1 ]] + [[ "$output" == "bot-finding" ]] +} + +@test "acv_post_marker_clear: human comment after our marker ALWAYS blocks regardless of content -> rc1 (AC3, preserves #1415)" { + local comments='[ + {"author":{"login":"donpetry-bot","__typename":"User"},"body":"Refuted. ","createdAt":"2026-09-01T10:00:00Z"}, + {"author":{"login":"a-maintainer","__typename":"User"},"body":"Looks fine to me, thanks.","createdAt":"2026-09-01T11:00:00Z"} + ]' + run acv_post_marker_clear "$comments" 0 "donpetry-bot" + [[ "$status" -eq 1 ]] + [[ "$output" == "human" ]] +} + +@test "acv_post_marker_clear: undeterminable bot comment after our marker -> fail closed rc2 (AC4)" { + local comments='[ + {"author":{"login":"donpetry-bot","__typename":"User"},"body":"Refuted. ","createdAt":"2026-09-01T10:00:00Z"}, + {"author":{"login":"codeant-ai[bot]","__typename":"Bot"},"body":"Interesting.","createdAt":"2026-09-01T11:00:00Z"} + ]' + run acv_post_marker_clear "$comments" 0 "donpetry-bot" + [[ "$status" -eq 2 ]] + [[ "$output" == "bot-ambiguous" ]] +} + +@test "acv_post_marker_clear: our own later note after the marker is ours -> clear rc0" { + local comments='[ + {"author":{"login":"donpetry-bot","__typename":"User"},"body":"Refuted. ","createdAt":"2026-09-01T10:00:00Z"}, + {"author":{"login":"donpetry-bot","__typename":"User"},"body":"Rebased onto latest main.","createdAt":"2026-09-01T11:00:00Z"} + ]' + run acv_post_marker_clear "$comments" 0 "donpetry-bot" + [[ "$status" -eq 0 ]] + [[ "$output" == "clear" ]] +} + +@test "acv_post_marker_clear: a post-marker comment carrying our marker is ours by the shared discriminator -> clear rc0" { + # A User comment that carries one of our automation markers is agent-authored per + # review_thread_is_agent_authored, so it is never treated as a human finding (#1735 AC3). + local comments='[ + {"author":{"login":"donpetry-bot","__typename":"User"},"body":"Refuted. ","createdAt":"2026-09-01T10:00:00Z"}, + {"author":{"login":"don-petry","__typename":"User"},"body":"Follow-up note. ","createdAt":"2026-09-01T11:00:00Z"} + ]' + run acv_post_marker_clear "$comments" 0 "donpetry-bot" + [[ "$status" -eq 0 ]] + [[ "$output" == "clear" ]] +} + # --------------------------------------------------------------------------- # acv_gather_commit_facts — the impure gatherer, against a real git repo # --------------------------------------------------------------------------- diff --git a/tests/dev-lead/unit/test_fix_reviews.bats b/tests/dev-lead/unit/test_fix_reviews.bats index 95e053774..2fe1437b0 100644 --- a/tests/dev-lead/unit/test_fix_reviews.bats +++ b/tests/dev-lead/unit/test_fix_reviews.bats @@ -1307,6 +1307,125 @@ STUB [ "$status" -eq 1 ] } +# ── #1735: full-thread scan — a bot ack after our marker must not lock the thread ── +# After #1691 (harness-only resolution) a thread we refuted (our addressed-marker +# reply) and a review bot then ACCEPTED ("✅ Customized review instruction saved!") +# became permanently unresolvable: the bot ack is the LATEST reply, so the old +# comments(last:1) gate saw a non-us author and skipped the thread forever. These +# cases assert the full-thread scan: our marker need not be the latest comment, a +# bot ack clears, a bot new-finding / any human / an ambiguous comment keeps it open. + +# Shared gh stub body for the #1735 harness cases: bot-originated candidate thread, +# claim verifies from the cumulative range (base_sha is a root commit, so +# base_sha..HEAD == the engine's new fix.txt). The node's comment set is injected +# per-case via $POST_MARKER_NODE. +_1735_run_case() { + local tmpdir="$BATS_TEST_TMPDIR/workdir" + mkdir -p "$tmpdir" + local mutations_file="$BATS_TEST_TMPDIR/mutations" + : > "$mutations_file" + local base_sha + rm -f /tmp/dev-lead-session-output.txt + + git -C "$tmpdir" init -q + echo "initial" > "$tmpdir/file.txt" + git -C "$tmpdir" add . + git -C "$tmpdir" -c user.email="t@test" -c user.name="T" commit -q -m "init" + git -C "$tmpdir" update-ref refs/remotes/origin/main "$(git -C "$tmpdir" rev-parse HEAD)" + base_sha="$(git -C "$tmpdir" rev-parse HEAD)" + + local marker_reply + marker_reply="Refuted — the pattern is intentional. \n" + + cat > "$STUB_BIN_DIR/gh" << GHEOF +#!/usr/bin/env bash +ARGS="\$*" +case "\$ARGS" in + *"resolveReviewThread"*) + echo "\$*" >> "$mutations_file" + echo '{"data":{"resolveReviewThread":{"thread":{"isResolved":true}}}}' + ;; + *"PullRequestReviewThread"*) + echo '{"data":{"node":{"isResolved":false,"path":"fix.txt","comments":{"nodes":[{"author":{"login":"donpetry-bot","__typename":"User"},"body":"${marker_reply}","createdAt":"2026-09-01T10:00:00Z"},${POST_MARKER_NODE}]}}}}' + ;; + *"reviewThreads"*) + echo '{"data":{"repository":{"pullRequest":{"reviewThreads":{"pageInfo":{"hasNextPage":false,"endCursor":""},"nodes":[{"id":"PRRT_1735","isResolved":false,"isOutdated":false,"origin":{"nodes":[{"author":{"login":"codeant-ai[bot]","__typename":"Bot"}}]}}]}}}}}' + ;; + *"check-runs"*) echo '{"check_runs":[]}' ;; + *"statuses"*) echo '[]' ;; + *"pulls/"*"reviews"*) echo '[]' ;; + *"pulls/"*) echo '{"head":{"sha":"${base_sha}"},"auto_merge":null}' ;; + *"pr checkout"*) exit 0 ;; + *"pr comment"*) exit 0 ;; + *"pr merge"*) exit 0 ;; + *) echo "{}" ;; +esac +GHEOF + chmod +x "$STUB_BIN_DIR/gh" + + cat > "$STUB_BIN_DIR/claude" << 'STUB' +#!/usr/bin/env bash +echo "Addressed feedback." +printf 'fixed\n' > fix.txt +STUB + chmod +x "$STUB_BIN_DIR/claude" + + cat > "$STUB_BIN_DIR/git" << 'GITEOF' +#!/usr/bin/env bash +if [ "$1" = "push" ]; then exit 0; fi +exec /usr/bin/git "$@" +GITEOF + chmod +x "$STUB_BIN_DIR/git" + + run bash -c " + cd '$tmpdir' + export INTENT_TYPE=fix-reviews DEV_LEAD_DRY_RUN=false + export PR_NUMBER=54 HEAD_SHA=$base_sha REPO='petry-projects/.github-private' + export REVIEW_ENGINE=claude BASE_REF=main PROMPTS_DIR='$SCRIPT_DIR/prompts/dev-lead' + export ACTOR='codeant-ai[bot]' + export BOT_USER='donpetry-bot' + export PATH='$STUB_BIN_DIR:$PATH' + bash '$FIX_REVIEWS_SCRIPT' + " 2>&1 + + # Expose the harness exit status so each case can assert the run completed instead of + # crashing before it ever reached the resolve step — otherwise a "stays open" grep + # (expecting no mutation) would pass even when the harness died early writing nothing. + _HARNESS_STATUS="$status" + _MUTATIONS_FILE="$mutations_file" +} + +@test "resolve_addressed_bot_threads (#1735): marker then a bot acknowledgement -> resolves" { + export POST_MARKER_NODE='{"author":{"login":"codeant-ai[bot]","__typename":"Bot"},"body":"✅ Customized review instruction saved!","createdAt":"2026-09-01T11:00:00Z"}' + _1735_run_case + [ "$_HARNESS_STATUS" -eq 0 ] + grep -q "PRRT_1735" "$_MUTATIONS_FILE" +} + +@test "resolve_addressed_bot_threads (#1735): marker then a bot NEW finding -> stays open" { + export POST_MARKER_NODE='{"author":{"login":"codeant-ai[bot]","__typename":"Bot"},"body":"Potential issue: this still leaks a file descriptor.","createdAt":"2026-09-01T11:00:00Z"}' + _1735_run_case + [ "$_HARNESS_STATUS" -eq 0 ] + run grep -q "PRRT_1735" "$_MUTATIONS_FILE" + [ "$status" -eq 1 ] +} + +@test "resolve_addressed_bot_threads (#1735): marker then a human comment -> stays open (AC3)" { + export POST_MARKER_NODE='{"author":{"login":"a-maintainer","__typename":"User"},"body":"Looks fine to me, thanks.","createdAt":"2026-09-01T11:00:00Z"}' + _1735_run_case + [ "$_HARNESS_STATUS" -eq 0 ] + run grep -q "PRRT_1735" "$_MUTATIONS_FILE" + [ "$status" -eq 1 ] +} + +@test "resolve_addressed_bot_threads (#1735): marker then an ambiguous bot comment -> stays open (AC4)" { + export POST_MARKER_NODE='{"author":{"login":"codeant-ai[bot]","__typename":"Bot"},"body":"Interesting.","createdAt":"2026-09-01T11:00:00Z"}' + _1735_run_case + [ "$_HARNESS_STATUS" -eq 0 ] + run grep -q "PRRT_1735" "$_MUTATIONS_FILE" + [ "$status" -eq 1 ] +} + # ── Harness-only resolution (#1691, epic #1621) ────────────────────────────── # Story 1 removes the model's resolveReviewThread path from the prompts, leaving # the harness as the ONLY resolver. This asserts the guarantee at the harness