From cd327acfddeccd8afc218976b43bb875e8f76525 Mon Sep 17 00:00:00 2001 From: don-petry <{}+don-petry@users.noreply.github.com> Date: Sun, 13 Sep 2026 14:18:50 +0000 Subject: [PATCH 1/3] =?UTF-8?q?feat:=20implement=20issue=20#1813=20?= =?UTF-8?q?=E2=80=94=20pr-review=20can't=20approve=20ANY=20open=20PR:=20ma?= =?UTF-8?q?intainer-comment=20gate=20needs=20pushedDate=20(always=20null)?= =?UTF-8?q?=20and=20treats=20codeant/qodo/auto-rebase=20comments=20as=20ma?= =?UTF-8?q?intainer=20findings=20=E2=80=94=2018/18=20PRs=20stranded?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/lint.yml | 2 + prompts/dev-lead/fix-reviews.md | 42 ++++ scripts/dev-lead-fix-reviews.sh | 218 +++++++++++++++++ scripts/lib/comment-disposition-verify.sh | 181 +++++++++++++++ scripts/lib/consumer-manifest.json | 1 + scripts/lib/maintainer-comment-gate.sh | 219 +++++++----------- scripts/review-one-pr.sh | 30 +-- .../unit/test_comment_disposition_verify.bats | 180 ++++++++++++++ .../unit/test_maintainer_comment_gate.bats | 162 ++++++------- 9 files changed, 803 insertions(+), 232 deletions(-) create mode 100755 scripts/lib/comment-disposition-verify.sh create mode 100644 tests/dev-lead/unit/test_comment_disposition_verify.bats diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 281772deb..d5237d53a 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -177,6 +177,8 @@ jobs: tests/test_sc2_self_review_channel.bats \ tests/pr_review_canary.bats \ tests/dev-lead/unit/test_maintainer_review_thread_gate.bats \ + tests/dev-lead/unit/test_maintainer_comment_gate.bats \ + tests/dev-lead/unit/test_comment_disposition_verify.bats \ tests/dev-lead/unit/test_conflict_integrity.bats \ tests/dev-lead/unit/test_addressed_claim_verify.bats \ tests/dev-lead/unit/test_fewshot_assemble.bats \ diff --git a/prompts/dev-lead/fix-reviews.md b/prompts/dev-lead/fix-reviews.md index 71404913c..04d98b081 100644 --- a/prompts/dev-lead/fix-reviews.md +++ b/prompts/dev-lead/fix-reviews.md @@ -99,6 +99,48 @@ Your reply and its marker are the *only* lever you have on resolution — which Never stamp the addressed-marker on a thread you did not fix, and never on a marker-less human thread — even when you fixed it, and even when it is `isOutdated: true`. Reply and leave it for the maintainer. Resolution — signalling the issue is handled and giving the reviewer a clean slate — is the harness's job, not yours. +### Phase 1b — Disposition PR Issue Comments (#1813) + +Review threads are only half the surface. A finding posted as a PR **issue comment** — what `gh pr comment` and the GitHub main comment box produce, and what bots like `codeant-ai`, `qodo-code-review`, and the `auto-rebase-conflict` notice use — creates **no** review thread, so it is invisible to Phase 1 above. The pr-review gate now **withholds approval** while any such comment lacks a **verified disposition**, so you must disposition every one or the PR cannot merge. + +**Enumerate the PR's issue comments** (not review threads): + +```bash +gh api graphql -f query='query($owner:String!,$repo:String!,$pr:Int!){ + repository(owner:$owner,name:$repo){ pullRequest(number:$pr){ + comments(first:100){ nodes{ id author{login __typename} body isMinimized minimizedReason } } } } }' \ + -F owner="${REPO%%/*}" -F repo="${REPO##*/}" -F pr="${PR_NUMBER}" +``` + +**Skip** (do not disposition, never reply to): + +- any comment already `isMinimized: true` with `minimizedReason` = `RESOLVED` — it is done; +- **our own** automation comments — those authored by our bot account or carrying one of our markers (``, ``, `` including your own `` replies, ``). **Never answer your own disposition reply** — doing so would loop forever (#860 / #1813 AC7). + +For **every other** comment (bot or human alike — a bot conflict report or trial-ended notice is still a finding), research it, then post **exactly one** reply comment that states specifically what you found/did (never just "done"), ending with **one** disposition marker. Post the reply with `gh pr comment ${PR_NUMBER} --body "…"`; pass the `id` node id from the query above verbatim: + +``` + +``` + +**Choose the disposition and satisfy its evidence rule** (the harness verifies each before it minimizes the original comment — an unverifiable disposition leaves the comment open and the PR blocked): + +| Disposition | Use when | Required evidence (harness-verified) | +|---|---|---| +| `fixed` | you changed code to address the finding | `sha=` the **full 40-char** commit (`git rev-parse HEAD`) your fix rides on; the harness checks it is on the PR head with a non-empty diff | +| `out-of-scope` | the finding is real but belongs elsewhere | `ref=#` a tracking issue that **exists**; open one first if needed | +| `invalid` | the finding is wrong / a false positive | a reply body with concrete reasoning (non-empty beyond the marker) | +| `answered` | the comment asked a question you answer in the reply | a reply body that actually answers it | +| `informational` | a notice with no action needed (e.g. a trial-ended notice) | a reply body noting the acknowledgement; route any follow-up to **one** tracking issue per repo (see below) | + +**Emit exactly one marker per reply.** A reply with zero or more-than-one marker, an unknown disposition word, a `fixed` without a 40-hex `sha`, or an `out-of-scope` without `ref` is **unverifiable** — the harness leaves the comment open. Cite the real SHA / real issue. + +**AC5 — human maintainer comments.** A comment whose `author.__typename` is `"User"` (a person, using an account like a human maintainer) is auto-resolved by the harness **only** on a verified `fixed`. For any other disposition you still post your reply, but the comment stays open for the human to resolve — you can never dismiss a person's finding by arguing it away. Bot comments (`__typename` = `"Bot"`) resolve on any verified disposition. + +**AC6 — one tracking issue per repo.** When you defer findings (`out-of-scope`) or route `informational` follow-ups, funnel them into a **single** tracking issue per repository rather than opening one per comment; reference that issue's number in `ref=`. + +**Never minimize a comment yourself** (no `minimizeComment` mutation). As with review threads, resolution is the harness's job: it verifies your disposition reply and minimizes the original comment RESOLVED. Your reply + its marker are your only lever. + ### Phase 2 — Test Verification After addressing all threads, run the test suite to ensure no regressions were introduced: diff --git a/scripts/dev-lead-fix-reviews.sh b/scripts/dev-lead-fix-reviews.sh index 6206139ad..8b01b6653 100755 --- a/scripts/dev-lead-fix-reviews.sh +++ b/scripts/dev-lead-fix-reviews.sh @@ -14,6 +14,16 @@ source "$(dirname "$0")/lib/conflict-integrity.sh" source "$(dirname "$0")/lib/review-change-evidence.sh" source "$(dirname "$0")/lib/resolution-integrity.sh" source "$(dirname "$0")/lib/addressed-claim-verify.sh" +# PR issue-comment disposition verifier (#1813): the issue-comment sibling of +# addressed-claim-verify.sh. Turns a dev-lead comment-disposition reply into a +# machine-checkable claim the harness verifies before minimizing the original +# comment RESOLVED. +source "$(dirname "$0")/lib/comment-disposition-verify.sh" +# The issue-comment gate — sourced for its agent-marker regex +# ($_MAINTAINER_GATE_AGENT_MARKERS), so resolve_dispositioned_comments excludes +# our own disposition/ack/note replies with the SAME discriminator the gate uses +# (single source of truth; #1813 loop safety AC7). +source "$(dirname "$0")/lib/maintainer-comment-gate.sh" # Structured PR-body backfill (#1805): heal an existing PR whose body is still # missing 3+ required description sections, once, marker-keyed. source "$(dirname "$0")/lib/dev-lead-pr-body.sh" @@ -839,6 +849,199 @@ resolve_addressed_bot_threads() { echo "::notice::resolve_addressed_bot_threads: resolved ${resolved_count} addressed bot thread(s) on PR #${PR_NUMBER}" } +# resolve_dispositioned_comments: the issue-comment sibling of +# resolve_addressed_bot_threads (#1813). A PR *issue comment* (from `gh pr comment` +# or the GitHub main comment box) creates no review thread, so it is invisible to +# the thread-resolution path above. The maintainer-comment gate withholds +# pr-review's approval while ANY non-agent issue comment lacks a VERIFIED +# DISPOSITION, surfaced server-side as the comment being minimized RESOLVED. This +# net supplies that signal: for each undispositioned non-agent comment it locates +# dev-lead's single disposition reply, VERIFIES the disposition against ground +# truth (the pushed diff for `fixed`, the tracking issue for `out-of-scope`, a +# non-empty evidence reply for invalid/answered/informational), and — when +# cdv_authorize permits — minimizes the ORIGINAL comment RESOLVED (never the +# model; the harness alone resolves, #1813 AC4). +# +# Authorship (#1813 AC5): is_human is the server's own classification +# (author.__typename == "User"). A human maintainer's comment is auto-resolved +# ONLY on a verified `fixed` (an agent can never dismiss a person's finding by +# arguing it away); a bot's comment resolves on any verified disposition. +# +# Loop safety (#860 / AC7): candidate enumeration excludes our own account and any +# comment carrying an agent marker (which includes the `dev-lead:comment-disposition` +# reply itself), so our replies are never themselves treated as findings. The pass +# is idempotent — an already-minimized comment is filtered out — and every decision +# is delegated to the pure cdv_*/acv_* verifiers so it fails closed on any ambiguity. +resolve_dispositioned_comments() { + local intent="$1" + if [ "${DEV_LEAD_DRY_RUN:-false}" = "true" ]; then + echo "[dry-run] would resolve dispositioned PR issue comments on PR #${PR_NUMBER}" + return 0 + fi + if [ -z "${PR_NUMBER:-}" ]; then + echo "::notice::resolve_dispositioned_comments: PR_NUMBER not set for intent=${intent} — skipping" + return 0 + fi + + local bot_user="${BOT_USER:-donpetry-bot}" + + # Fetch ALL PR issue comments (author login + __typename, body, minimize state, + # createdAt, and the node id used both to match a disposition reply's `id=` and + # as minimizeComment's subjectId). The full set is needed twice: to find + # candidates AND to locate their disposition replies (a flat comment list, not a + # thread). Paginated 100/page. + local pages_file cursor="" has_next_page="true" page_response page_nodes + local cursor_args=() + local comments_query='query($owner:String!,$repo:String!,$pr:Int!,$cursor:String){ + repository(owner:$owner,name:$repo){ + pullRequest(number:$pr){ + comments(first:100,after:$cursor){ + pageInfo{hasNextPage endCursor} + nodes{ id author{login __typename} body isMinimized minimizedReason createdAt } + } + } + } + }' + pages_file=$(mktemp) + while [ "$has_next_page" = "true" ]; do + page_response=$(gh api graphql -f query="$comments_query" \ + -F owner="${REPO%%/*}" -F repo="${REPO##*/}" -F pr="$PR_NUMBER" \ + "${cursor_args[@]}" 2>/dev/null || echo "{}") + page_nodes=$(printf '%s' "$page_response" | jq -c \ + '.data?.repository?.pullRequest?.comments?.nodes // []' 2>/dev/null || echo "[]") + printf '%s\n' "$page_nodes" >> "$pages_file" + has_next_page=$(printf '%s' "$page_response" | jq -r \ + '.data?.repository?.pullRequest?.comments?.pageInfo?.hasNextPage // false' \ + 2>/dev/null || echo "false") + cursor=$(printf '%s' "$page_response" | jq -r \ + '.data?.repository?.pullRequest?.comments?.pageInfo?.endCursor // ""' \ + 2>/dev/null || echo "") + [ -z "$cursor" ] && has_next_page="false" + cursor_args=("-f" "cursor=${cursor}") + done + local all_comments + all_comments=$(jq -s 'add // []' "$pages_file" 2>/dev/null || echo "[]") + rm -f "$pages_file" + + # Candidate ids: non-agent comments not already minimized RESOLVED. Same filter + # as the gate (login != our account, body not agent-marked, not resolved-minimized) + # so what the harness resolves is exactly what the gate blocks on. + local candidate_ids + candidate_ids=$(printf '%s' "$all_comments" | jq -r \ + --arg botuser "$bot_user" \ + --arg markers "$_MAINTAINER_GATE_AGENT_MARKERS" ' + def bot_stripped: ($botuser | if endswith("[bot]") then .[0:-5] else . end); + .[] | objects + | (.author?.login // "" | tostring) as $l + | select($l != $botuser and $l != bot_stripped) + | select(((.body // "") | test($markers)) | not) + | select( + ((.isMinimized // false) == true) + and (((.minimizedReason // "") | ascii_downcase) == "resolved") + | not + ) + | .id + ' 2>/dev/null || true) + + if [ -z "$(printf '%s' "$candidate_ids" | sed '/^[[:space:]]*$/d')" ]; then + echo "::notice::no undispositioned PR issue comments on PR #${PR_NUMBER}" + return 0 + fi + + local resolved_count=0 + local cid is_human cur_minimized reply_body disp_json disposition sha ref verified + while IFS= read -r cid; do + [ -z "$cid" ] && continue + + # Re-read the ORIGINAL comment's CURRENT minimize state so a comment minimized + # since enumeration is not double-processed; a fetch that can't confirm state + # fails closed (skip). + cur_minimized=$(gh api graphql -f query='query($id:ID!){node(id:$id){... on IssueComment{isMinimized minimizedReason}}}' \ + -f id="$cid" 2>/dev/null \ + | jq -r 'if .data.node.isMinimized == null then "unknown" + elif .data.node.isMinimized then "true" else "false" end' 2>/dev/null || echo "unknown") + if [ "$cur_minimized" != "false" ]; then + echo "::notice::skipping comment ${cid} — already minimized or state unknown at re-check (${cur_minimized})" + continue + fi + + is_human=$(printf '%s' "$all_comments" | jq -r --arg id "$cid" \ + 'first(.[] | select(.id == $id)) | if (.author?.__typename // "") == "User" then "true" else "false" end' 2>/dev/null || echo "false") + + # Locate OUR disposition reply for this comment id: the comment whose parseable + # disposition marker cites id=. GitHub returns comments in chronological + # order, so the last match in the stream is the latest reply (AC7 expects exactly + # one). cdv_parse_disposition rejects malformed/ambiguous markers, so an + # unverifiable reply never matches. Bodies are base64-framed to survive newlines. + reply_body="" + local c_body_b64 c_body parsed pid + while IFS= read -r c_body_b64; do + [ -z "$c_body_b64" ] && continue + c_body=$(printf '%s' "$c_body_b64" | base64 -d 2>/dev/null || true) + parsed=$(cdv_parse_disposition "$c_body" 2>/dev/null) || continue + pid=$(printf '%s' "$parsed" | jq -r '.id // ""' 2>/dev/null || echo "") + [ "$pid" = "$cid" ] || continue + reply_body="$c_body" + disp_json="$parsed" + done < <(printf '%s' "$all_comments" | jq -r '.[] | (.body // "") | @base64' 2>/dev/null) + + if [ -z "$reply_body" ]; then + echo "::notice::skipping comment ${cid} — no verified dev-lead disposition reply found; leaving open (#1813)" + continue + fi + + disposition=$(printf '%s' "$disp_json" | jq -r '.disposition // ""' 2>/dev/null || echo "") + sha=$(printf '%s' "$disp_json" | jq -r '.sha // ""' 2>/dev/null || echo "") + ref=$(printf '%s' "$disp_json" | jq -r '.ref // ""' 2>/dev/null || echo "") + + # Verify the disposition against ground truth. Fail closed: unknown → false. + verified="false" + case "$disposition" in + fixed) + # The cited sha must be on the PR head with a non-empty diff. + local facts on_head own_files cumulative_files + facts=$(acv_gather_commit_facts "$sha") + on_head=$(printf '%s' "$facts" | jq -r '.on_head // false' 2>/dev/null || echo "false") + own_files=$(printf '%s' "$facts" | jq -r '(.own_files // []) | length' 2>/dev/null || echo "0") + cumulative_files=$(printf '%s' "$facts" | jq -r '(.cumulative_files // []) | length' 2>/dev/null || echo "0") + if [ "$on_head" = "true" ] && { [ "${own_files:-0}" -gt 0 ] || [ "${cumulative_files:-0}" -gt 0 ]; }; then + verified="true" + fi + ;; + out-of-scope) + # The referenced tracking issue must exist. + local ref_num="${ref#\#}" + if [ -n "$ref_num" ] && gh issue view "$ref_num" --repo "$REPO" --json number >/dev/null 2>&1; then + verified="true" + fi + ;; + invalid|answered|informational) + # The disposition reply must carry non-empty evidence beyond the marker itself. + local evidence + evidence=$(printf '%s' "$reply_body" | jq -Rsr 'gsub("";"";"s") | gsub("\\s";"";"g")' 2>/dev/null || echo "") + [ -n "$evidence" ] && verified="true" + ;; + *) + verified="false" + ;; + esac + + if ! cdv_authorize "$disposition" "$is_human" "$verified"; then + echo "::notice::skipping comment ${cid} — disposition '${disposition}' not authorized to resolve (is_human=${is_human} verified=${verified}); leaving open (#1813)" + continue + fi + + if gh api graphql -f query='mutation($id:ID!){minimizeComment(input:{subjectId:$id,classifier:RESOLVED}){minimizedComment{isMinimized}}}' \ + -f id="$cid" >/dev/null 2>&1; then + resolved_count=$((resolved_count + 1)) + echo "::notice::minimized comment ${cid} RESOLVED (disposition=${disposition} is_human=${is_human})" + else + echo "::warning::failed to minimize comment ${cid} RESOLVED" + fi + done <<< "$candidate_ids" + echo "::notice::resolve_dispositioned_comments: minimized ${resolved_count} dispositioned comment(s) on PR #${PR_NUMBER}" +} + # has_hard_blockers: returns 0 (true) if CI_STATUS_JSON or ALL_REVIEWS_JSON contain # hard Tier-1 blockers (failing CI checks or CHANGES_REQUESTED reviews). # Unlike has_tier1_blockers, does NOT check for unresolved bot threads — used to @@ -1625,6 +1828,13 @@ case "$INTENT_TYPE" in post_no_changes "fix-reviews" fi fi + # Minimize PR issue comments dev-lead has dispositioned + verified (#1813). + # Deliberately OUTSIDE the review-thread resolution gate: each disposition is + # verified on its own terms (a `fixed` sha must be on head; out-of-scope needs + # a tracking issue; invalid/answered/informational need a non-empty evidence + # reply), so an answered/invalid disposition requires no head advance. Runs on + # every successful pass, including a net-zero one where the model only replied. + resolve_dispositioned_comments "fix-reviews" if [ "$cp_rc" -ne 3 ]; then # Resolution gate (#1617): auto-resolve threads only when this pass advanced # the PR head. A no-commit pass resolves zero threads (#1609/#1024). @@ -1675,6 +1885,11 @@ case "$INTENT_TYPE" in post_no_changes "fix-bot-comment" fi fi + # Minimize PR issue comments dev-lead has dispositioned + verified (#1813). + # Outside the review-thread resolution gate for the same reason as fix-reviews: + # each disposition is independently verified, so a non-`fixed` disposition + # needs no head advance. Runs on every successful pass, net-zero included. + resolve_dispositioned_comments "fix-bot-comment" if [ "$cp_rc" -ne 3 ]; then # Resolution gate (#1617): auto-resolve threads only when this pass advanced # the PR head. A no-commit pass resolves zero threads (#1609/#1024). @@ -1754,6 +1969,9 @@ case "$INTENT_TYPE" in post_reviews_terminal "review-changes" "no-changes" "No changes were needed for this PR." fi fi + # Minimize PR issue comments dev-lead has dispositioned + verified (#1813) — + # independently verified, so outside the head-movement resolution gate. + resolve_dispositioned_comments "review-changes" # Resolution gate (#1617): auto-resolve threads only when this pass advanced # the PR head. A no-commit pass resolves zero threads (#1609/#1024). if resolution_gate_open "$cp_rc"; then diff --git a/scripts/lib/comment-disposition-verify.sh b/scripts/lib/comment-disposition-verify.sh new file mode 100755 index 000000000..391ac7c00 --- /dev/null +++ b/scripts/lib/comment-disposition-verify.sh @@ -0,0 +1,181 @@ +#!/usr/bin/env bash +# comment-disposition-verify.sh — the pure verifier for the dev-lead PR +# issue-comment DISPOSITION marker (#1813). +# +# WHY THIS EXISTS +# maintainer-comment-gate.sh (#1290) judged an issue comment "addressed" by +# comparing timestamps: a push after the comment cleared it. That is a proxy — +# it says nothing about whether the comment's finding was read, checked, and +# acted on, and it depended on pushedDate (now always null), so the gate failed +# closed on every open PR (#1813). The redesign makes "addressed" mean a +# VERIFIED DISPOSITION: dev-lead researches each comment and posts exactly one +# evidence-backed reply carrying +# +# +# +# and the harness verifies that disposition and then minimizes the ORIGINAL +# comment with classifier RESOLVED (GraphQL minimizeComment). The pr-review gate +# then treats a RESOLVED-minimized comment as addressed. This library is the +# issue-comment sibling of addressed-claim-verify.sh (the review-thread path). +# +# PURITY / TESTABILITY +# Every cdv_* function here is PURE: no gh/git/network. Verification of a claim +# against the pushed diff (the `fixed` case) reuses acv_gather_commit_facts from +# addressed-claim-verify.sh in the caller; this library only decides, from the +# parsed disposition and a caller-supplied `verified` boolean, whether the +# harness may resolve the comment. Sourced under `set -euo pipefail`, so the +# helpers only `return`, never `exit`, and fail closed on every ambiguity. + +set -euo pipefail + +# The literal marker delimiters — one definition shared by the emitter (prompt) +# and this parser. +readonly _CDV_MARKER_PREFIX='' + +# The five sanctioned dispositions (issue #1813 Design). Any other word is +# unverifiable → parse fails closed rather than guessing. +readonly _CDV_VALID_DISPOSITIONS='fixed invalid out-of-scope answered informational' + +# The post-disposition BOT-reply classification (AC7 loop safety) reuses the +# review-thread verifier's acknowledgement/finding discriminators so there is a +# single source of truth. Source it only if the caller has not already (the main +# script sources both, so this never double-sources or re-declares readonly vars). +if ! declare -F acv_bot_comment_is_acknowledgement >/dev/null 2>&1; then + # shellcheck source=addressed-claim-verify.sh + source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/addressed-claim-verify.sh" +fi + +# cdv_parse_disposition +# Extract and validate the single disposition marker from a reply body. On +# success echoes canonical compact JSON {id,disposition,sha,ref} and returns 0 +# (sha/ref are "" when absent). On any failure echoes a reason token and +# returns 1: no-disposition | multiple-dispositions | bad-id | bad-disposition +# | bad-sha | missing-ref. Pure — no gh/git/network. +cdv_parse_disposition() { + local body="${1:-}" + if [[ -z "$body" ]]; then + echo "no-disposition" + return 1 + fi + + # Count markers. Zero → nothing to verify; more than one → malformed (never + # silently pick one). `|| true` neutralises grep's no-match exit under pipefail. + local count + count=$( { grep -oF "$_CDV_MARKER_PREFIX" <<<"$body" || true; } | wc -l | tr -d '[:space:]') + if [[ "$count" == "0" ]]; then + echo "no-disposition" + return 1 + fi + if [[ "$count" != "1" ]]; then + echo "multiple-dispositions" + return 1 + fi + + # Extract the attribute string between the literal prefix and the trailing ` -->`. + local rest attrs + rest="${body#*"$_CDV_MARKER_PREFIX"}" + attrs="${rest%%"$_CDV_MARKER_SUFFIX"*}" + + # Pull each key=value token. Keys are matched anchored so `id=` cannot capture + # a substring of another key. A value runs to the next whitespace. + local id disposition sha ref + id=$(_cdv_attr "$attrs" id) + disposition=$(_cdv_attr "$attrs" disposition) + sha=$(_cdv_attr "$attrs" sha) + ref=$(_cdv_attr "$attrs" ref) + + if [[ -z "$id" ]]; then + echo "bad-id" + return 1 + fi + if [[ -z "$disposition" ]] || ! _cdv_is_valid_disposition "$disposition"; then + echo "bad-disposition" + return 1 + fi + # `fixed` must cite a full 40-hex sha (abbreviated SHAs are rejected, matching + # the addressed-claim contract). + if [[ "$disposition" == "fixed" ]]; then + if [[ ! "$sha" =~ ^[0-9a-f]{40}$ ]]; then + echo "bad-sha" + return 1 + fi + fi + # `out-of-scope` must cite the tracking reference it defers to. + if [[ "$disposition" == "out-of-scope" && -z "$ref" ]]; then + echo "missing-ref" + return 1 + fi + + jq -c -n \ + --arg id "$id" \ + --arg disposition "$disposition" \ + --arg sha "$sha" \ + --arg ref "$ref" \ + '{id:$id, disposition:$disposition, sha:$sha, ref:$ref}' 2>/dev/null || { + echo "bad-id" + return 1 + } +} + +# _cdv_attr +# Echo the value of `=` in a space-delimited attribute string, or +# empty when the key is absent. Value runs to the next whitespace. +_cdv_attr() { + local attrs="${1:-}" key="${2:-}" + [[ -z "$key" ]] && return 0 + # Prepend a space so a leading key matches the same ` =` pattern. + local padded=" $attrs" + if [[ "$padded" =~ [[:space:]]${key}=([^[:space:]]+) ]]; then + printf '%s' "${BASH_REMATCH[1]}" + fi +} + +# _cdv_is_valid_disposition +# 0 when is one of the five sanctioned dispositions, 1 otherwise. +_cdv_is_valid_disposition() { + local w="${1:-}" d + for d in $_CDV_VALID_DISPOSITIONS; do + [[ "$w" == "$d" ]] && return 0 + done + return 1 +} + +# cdv_authorize +# Decide whether the harness may resolve (minimize RESOLVED) the ORIGINAL +# comment. and are the strings "true"/"false". +# - is the disposition-specific verification the CALLER computed: +# fixed → the cited sha is on the PR head and its diff is non-empty +# out-of-scope → the referenced issue exists +# invalid/answered/informational → a reply with non-empty evidence exists +# - A human maintainer's comment is auto-resolved ONLY on a verified `fixed` +# (AC5); any other disposition leaves it open for the human to resolve, so +# an agent can never dismiss a person's finding by arguing with it. +# - A bot comment is resolved on any verified disposition (AC4). +# Returns 0 = the harness may minimize; 1 = leave the comment open. Pure. +cdv_authorize() { + local disposition="${1:-}" is_human="${2:-}" verified="${3:-}" + [[ "$verified" == "true" ]] || return 1 + if [[ "$is_human" == "true" ]]; then + [[ "$disposition" == "fixed" ]] && return 0 + return 1 + fi + return 0 +} + +# cdv_reply_needs_response +# Loop safety (#860 / AC7): a bot that replies AFTER our disposition is answered +# again ONLY if it raises a genuinely NEW finding — boilerplate/acknowledgements +# never start a reply chain. Reuses acv_bot_comment_is_acknowledgement (the same +# discriminator the review-thread path uses): +# new finding (rc1) → 0 (respond) +# acknowledgement (rc0) / ambiguous(2) → 1 (do NOT respond) +# Pure — no gh/git/network. +cdv_reply_needs_response() { + local body="${1:-}" + local ack_rc=0 + acv_bot_comment_is_acknowledgement "$body" || ack_rc=$? + [[ "$ack_rc" -eq 1 ]] && return 0 + return 1 +} diff --git a/scripts/lib/consumer-manifest.json b/scripts/lib/consumer-manifest.json index 2e8fcbe40..982c0588c 100644 --- a/scripts/lib/consumer-manifest.json +++ b/scripts/lib/consumer-manifest.json @@ -149,6 +149,7 @@ "prompts/dev-lead/review-changes.md", "scripts/lib/auto-merge.sh", "scripts/lib/git-identity.sh", + "scripts/lib/maintainer-comment-gate.sh", "scripts/lib/maintainer-review-thread-gate.sh", "scripts/lib/pr-worktree.sh" ], diff --git a/scripts/lib/maintainer-comment-gate.sh b/scripts/lib/maintainer-comment-gate.sh index 31d647734..a7b9f3bfe 100755 --- a/scripts/lib/maintainer-comment-gate.sh +++ b/scripts/lib/maintainer-comment-gate.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -# Maintainer issue-comment gate (issue #1290) +# Maintainer issue-comment gate (issues #1290, #1813) # # A maintainer finding posted as a PR *issue comment* — what `gh pr comment` and # the GitHub main comment box produce — creates NO review thread. So unlike an @@ -10,69 +10,64 @@ # words, posted two ways, have opposite force; the easy path (`gh pr comment`) is # the silent one. # -# This gate closes the "does not block" half at the pr-review approval boundary: -# it withholds pr-review's automated approval while the LATEST maintainer issue -# comment postdates the last push. It is deliberately modeled on the advisory-bot -# gate (`advisory-review-gate.sh`, #457/#458), which likewise defers approval -# until a signal is incorporated. +# This gate closes the "does not block" half at the pr-review approval boundary. # -# It FAILS CLOSED (the #1290 acceptance criterion): an inability to confirm that -# a maintainer comment was addressed must block, never read as "no findings" — -# that is precisely the bug that shipped the regression this issue tracks. +# #1813 REDESIGN — "addressed" means a VERIFIED DISPOSITION, not a timestamp. +# The original gate (#1290) judged a comment addressed by comparing timestamps: +# a push at/after the comment cleared it. That was wrong twice over: +# • it depended on the head-push timestamp, which GitHub now always returns +# as null, so the gate failed closed on every open PR (the #1813 outage); and +# • a push is only a proxy — it says nothing about whether a comment's finding +# was read, checked, and acted on. +# The redesign removes the push-timestamp model entirely. dev-lead +# researches each undispositioned comment and posts exactly one evidence-backed +# reply carrying ``; +# the harness verifies that disposition and then minimizes the ORIGINAL comment +# with classifier RESOLVED (GraphQL minimizeComment). This gate treats a +# RESOLVED-minimized comment as addressed and withholds approval while ANY +# non-agent issue comment lacks that signal. # -# check_maintainer_comments [bot_user] -# — output of `gh pr view --json comments,reviews,...` -# — committer.date of the PR head commit (push time) -# [bot_user] — the agent's own login (default donpetry-bot) +# Scope: EVERY PR issue comment, from human maintainers and bots alike +# (codeant-ai, qodo-code-review, auto-rebase-conflict, and so on). No author is +# exempt for being a bot — a conflict report is a finding, a trial-ended notice +# has an operational consequence. The ONLY exclusion is our own automation's +# disposition/ack/note replies (so the agent never has to answer itself): our +# bot login, or a body carrying one of our automation markers (which includes +# the `` reply itself). +# +# It FAILS CLOSED: an inability to evaluate the snapshot must block, and is +# reported DISTINCTLY (return 2 → a distinct verdict reason) so an undeterminable +# gate state can never recur disguised as a legitimate hold (#1813 AC8). +# +# check_maintainer_comments [bot_user] +# — output of `gh pr view --json comments,...`; each comment +# must carry {author.login, body, isMinimized, minimizedReason}. +# [bot_user] — the agent's own login (default donpetry-bot) # Returns: -# 0 = no unaddressed maintainer comment (none exist, OR the latest one is at/ -# older than the last push → a fix was pushed after it) -# 1 = the latest maintainer issue comment postdates the last push (unaddressed) -# OR a maintainer comment exists but the push time is undeterminable -# (fail closed) → withhold approval +# 0 = every non-agent issue comment is minimized RESOLVED (or none exist) +# 1 = at least one non-agent issue comment lacks a verified disposition → block # 2 = the snapshot could not be evaluated (malformed) → fail closed → block # # The check is pure: it makes no `gh`/network calls and reuses the snapshot the # caller already fetched, so it adds no API round-trip and is trivially testable. -# maintainer_gate_head_committer_date() is the thin `gh` helper the caller uses -# to obtain (mirrors the advisory gate's cherry-pick-safe -# committer.date fetch). +# maintainer_gate_head_committer_date() is a thin `gh` helper retained for the +# sibling review-thread gate's push-time needs; it uses committer.date and reads +# NO push-timestamp field (#1813 AC1 / matching advisory-review-gate.sh, #577). set -euo pipefail -# Comment authors that are never maintainers: advisory/review bots (already gated -# by advisory-review-gate.sh) and generic automation accounts. The agent's own -# login is excluded separately via the bot_user argument. Fail-closed principle: -# anything NOT on this list and NOT carrying one of our automation markers is -# treated as a human maintainer, so an unknown author blocks rather than slips. -# shellcheck disable=SC2034 -declare -ar MAINTAINER_GATE_EXCLUDED_BOTS=( - gemini-code-assist - copilot-pull-request-reviewer - sonarqubecloud - chatgpt-codex-connector - coderabbitai - github-actions - "github-actions[bot]" - dependabot - "dependabot[bot]" -) - -# JSON array form of the excluded-bot list, built lazily on first use so jq -# execution (and potential failures) happen inside check_maintainer_comments, -# where errors are caught and the gate can fail closed properly. -_MAINTAINER_GATE_EXCLUDED_BOTS_JSON="" - # Regex (case-sensitive) matching the HTML markers our own automation stamps into # comment bodies — pr-review reviews/acks (``, # ``), the pr-review re-review claim marker -# (``, issue #1589), dev-lead notes -# (``), and the dependency-advisory pass -# (``). A comment carrying any of these is one of -# ours, never a maintainer finding. This marker-based exclusion is essential -# because these workflows post as the human owner (`don-petry`) — the same account -# a human maintainer would use — so login alone cannot separate the agent's -# comments from a person's. +# (``, issue #1589), dev-lead notes AND dev-lead +# comment-dispositions (`` / ``), +# and the dependency-advisory pass (``). A comment +# carrying any of these is one of ours, never a finding we must disposition. +# This marker-based exclusion is essential because these workflows post as the +# human owner (`don-petry`) — the same account a human maintainer would use — so +# login alone cannot separate the agent's comments from a person's. It is also +# the loop-safety guard (#860 / #1813 AC7): our own disposition reply carries the +# `dev-lead` marker, so it is never itself counted as a comment needing a response. readonly _MAINTAINER_GATE_AGENT_MARKERS='' log_info() { @@ -83,109 +78,70 @@ log_warn() { echo "[maintainer-gate] WARNING: $*" >&2 } -# _mcg_to_epoch -# Echo the UTC epoch seconds for an ISO-8601 timestamp, or return non-zero when -# it is empty/unparseable. Supports both GNU date (-d) and BSD date (-jf). -_mcg_to_epoch() { - local iso="${1:-}" e - [[ -z "$iso" ]] && return 1 - e=$(date -u -d "$iso" +%s 2>/dev/null) \ - || e=$(date -u -jf "%Y-%m-%dT%H:%M:%SZ" "$iso" +%s 2>/dev/null) \ - || return 1 - printf '%s' "$e" -} - # maintainer_gate_head_committer_date -# Echo the server-recorded push timestamp for the PR's head commit via a single -# GraphQL query. Prefers pushedDate (a server-recorded field GitHub writes on -# receipt of the push — not settable by the committer) over committer.date so -# a future-dated no-op commit cannot make an old finding appear addressed. Fails -# closed (empty string) when pushedDate is unavailable; the caller treats empty -# as fail-closed (finding unresolved). Echoes empty on any API failure. +# Echo the committer.date of the PR's head commit via a single GraphQL query. +# Uses committer.date (not the deprecated, now-null push timestamp) so a cherry-pick +# or rebase reflects when it was applied rather than the original author date — +# the same cherry-pick-safe semantics advisory-review-gate.sh uses (#577). This +# gate no longer decides "addressed" from push time; the helper is retained only +# for the sibling review-thread gate, which sources this file for it. Echoes +# empty on any API failure. maintainer_gate_head_committer_date() { local pr_url="${1:-}" [[ -z "$pr_url" ]] && return 0 # shellcheck disable=SC2016 # $url is a GraphQL variable placeholder, not shell - local _gql='query($url:URI!){resource(url:$url){...on PullRequest{commits(last:1){nodes{commit{pushedDate committer{date}}}}}}}' - local _raw - _raw=$(gh api graphql -f query="$_gql" -f url="$pr_url" 2>/dev/null) || return 0 - # Use pushedDate (server-recorded) if available; fail closed if not. - local _pushed - _pushed=$(printf '%s' "$_raw" | jq -r '.data?.resource?.commits?.nodes[0]?.commit?.pushedDate // empty' 2>/dev/null) || true - if [[ -n "$_pushed" ]]; then - printf '%s' "$_pushed" - return 0 - fi - # pushedDate unavailable — return empty so the caller fails closed. - return 0 + local _gql='query($url:URI!){resource(url:$url){...on PullRequest{commits(last:1){nodes{commit{committer{date}}}}}}}' + gh api graphql -f query="$_gql" -f url="$pr_url" \ + --jq '.data.resource.commits.nodes[0].commit.committer.date // empty' 2>/dev/null || true } -# check_maintainer_comments [bot_user] +# check_maintainer_comments [bot_user] check_maintainer_comments() { local json="${1:-}" - local head_date="${2:-}" - local bot_user="${3:-donpetry-bot}" - - # Build excluded-bots JSON lazily on first use. This keeps jq execution inside - # the function so errors are caught properly and the gate can fail closed. - if [[ -z "$_MAINTAINER_GATE_EXCLUDED_BOTS_JSON" ]]; then - _MAINTAINER_GATE_EXCLUDED_BOTS_JSON=$(printf '%s\n' "${MAINTAINER_GATE_EXCLUDED_BOTS[@]}" | jq -R . | jq -sc .) \ - || { - log_warn "could not build excluded-bots list — failing closed (blocking approval)" - return 2 - } - fi - - # Latest maintainer (human, non-agent, non-bot) issue-comment timestamp. A jq - # failure here (malformed snapshot, or a JSON value that can't be indexed with + local bot_user="${2:-donpetry-bot}" + + # Count non-agent issue comments that are NOT yet resolved. A comment is + # "cleared" when it is authored by our own account, carries one of our + # automation markers (our disposition/ack/note replies), OR has been minimized + # with classifier RESOLVED (the harness's verified-disposition signal). Anything + # else — a bot or human comment without a verified disposition — blocks. + # A jq failure (malformed snapshot, or a value that can't be indexed with # .comments) exits non-zero → return 2 so undeterminable input fails closed # rather than silently reading as "no findings". - local latest - latest=$(printf '%s' "$json" | jq -r \ + local blockers + blockers=$(printf '%s' "$json" | jq -r \ --arg markers "$_MAINTAINER_GATE_AGENT_MARKERS" \ - --arg botuser "$bot_user" \ - --argjson bots "$_MAINTAINER_GATE_EXCLUDED_BOTS_JSON" ' + --arg botuser "$bot_user" ' + def bot_stripped: ($botuser | if endswith("[bot]") then .[0:-5] else . end); [ (.comments // [])[] | objects | (.author?.login // "" | tostring) as $l - | select($l != $botuser and ($bots | index($l)) == null) + | select($l != $botuser and $l != bot_stripped) | select(((.body // "") | test($markers)) | not) - | .createdAt? ] - | map(select(. != null)) - | sort - | last // "" + | select( + ((.isMinimized // false) == true) + and (((.minimizedReason // "") | ascii_downcase) == "resolved") + | not + ) + ] + | length ' 2>/dev/null) || { log_warn "could not parse PR snapshot — failing closed (blocking approval)" return 2 } - if [[ -z "$latest" ]]; then - log_info "no unaddressed maintainer issue comments" - return 0 - fi - - # A maintainer issue comment exists. It is addressed only if a push landed at or - # after it. When the push time is undeterminable we cannot confirm that, so we - # fail closed and block (issue #1290). - if [[ -z "$head_date" ]]; then - log_warn "maintainer issue comment present but head-commit push time is unknown — failing closed (blocking approval)" - return 1 - fi - - local latest_epoch head_epoch - latest_epoch=$(_mcg_to_epoch "$latest") || latest_epoch="" - head_epoch=$(_mcg_to_epoch "$head_date") || head_epoch="" - if [[ -z "$latest_epoch" || -z "$head_epoch" ]]; then - log_warn "could not compare comment/push timestamps — failing closed (blocking approval)" - return 1 + # Empty output (jq produced nothing at all) is undeterminable → fail closed. + if [[ -z "$blockers" ]]; then + log_warn "PR snapshot produced no verdict — failing closed (blocking approval)" + return 2 fi - if [[ "$latest_epoch" -gt "$head_epoch" ]]; then - log_warn "latest maintainer issue comment ($latest) postdates the last push ($head_date) — unaddressed, withholding approval (#1290)" - return 1 + if [[ "$blockers" -eq 0 ]]; then + log_info "no undispositioned PR issue comments" + return 0 fi - log_info "latest maintainer issue comment ($latest) predates the last push ($head_date) — treated as addressed" - return 0 + log_warn "$blockers PR issue comment(s) lack a verified disposition (not minimized RESOLVED) — withholding approval (#1813)" + return 1 } # Run standalone against a PR URL (only if executed, not sourced). @@ -199,7 +155,6 @@ if [[ "${BASH_SOURCE[0]}" = "${0}" ]]; then echo "[maintainer-gate] ERROR: gh pr view failed for $_pr_url" >&2 exit 2 } - _hd=$(maintainer_gate_head_committer_date "$_pr_url") - check_maintainer_comments "$_snap" "$_hd" "${BOT_USER:-donpetry-bot}" + check_maintainer_comments "$_snap" "${BOT_USER:-donpetry-bot}" exit $? fi diff --git a/scripts/review-one-pr.sh b/scripts/review-one-pr.sh index 9fed96430..8229b5d00 100755 --- a/scripts/review-one-pr.sh +++ b/scripts/review-one-pr.sh @@ -379,41 +379,43 @@ fi fi } -# Maintainer issue-comment gate (issue #1290). A maintainer finding posted as a -# PR *issue comment* (`gh pr comment` / the GitHub main comment box) creates no -# review thread, so it neither trips `required_review_thread_resolution` nor is -# read by dev-lead's fix-reviews prompt — pr-review approves and the PR -# auto-merges with the defect. Withhold approval while the latest maintainer -# issue comment postdates the last push. It FAILS CLOSED: an undeterminable -# snapshot/push-time blocks rather than reading as "no findings". +# Maintainer issue-comment gate (issues #1290, #1813). A maintainer finding +# posted as a PR *issue comment* (`gh pr comment` / the GitHub main comment box) +# creates no review thread, so it neither trips `required_review_thread_resolution` +# nor is read by dev-lead's fix-reviews prompt — pr-review approves and the PR +# auto-merges with the defect. #1813 redesign: "addressed" is no longer a +# timestamp proxy (pushedDate is always null and a push says nothing about +# whether the finding was answered). Withhold approval while ANY non-agent PR +# issue comment lacks a VERIFIED DISPOSITION — surfaced server-side as the +# comment being minimized RESOLVED after dev-lead's disposition reply is +# verified. It FAILS CLOSED: an undeterminable snapshot blocks distinctly. # • FORCE_REVIEW bypasses (a human @mention IS the human-in-the-loop, and the # same comment that triggers a re-review would otherwise deadlock the gate). -# • rc=1 → skip (exit 100); a later reply/push re-triggers pr-review. +# • rc=1 → skip (exit 100); a later disposition+minimize re-triggers pr-review. # • rc=2 → fail the PR (exit 1) so a scheduled run retries, never approve blind. if [ "${FORCE_REVIEW:-false}" != "true" ]; then ( # Subshell isolation so the gate's helpers/vars don't leak into the caller. # shellcheck source=lib/maintainer-comment-gate.sh source "$SCRIPT_DIR/lib/maintainer-comment-gate.sh" - _mc_head_date=$(maintainer_gate_head_committer_date "$PR_URL") - check_maintainer_comments "$PR_SNAPSHOT" "$_mc_head_date" "${BOT_USER:-donpetry-bot}" + check_maintainer_comments "$PR_SNAPSHOT" "${BOT_USER:-donpetry-bot}" ) || { mc_gate_rc=$? if [ "$mc_gate_rc" -eq 1 ]; then - echo " skip: unaddressed maintainer issue comment postdates last push — withholding approval (#1290)" + echo " skip: a PR issue comment lacks a verified disposition — withholding approval (#1813)" # Dismiss any existing pr-review-agent APPROVED review so the PR remains blocked # until the maintainer comment is addressed (best-effort). if [ "${DRY_RUN:-false}" != "true" ]; then _agent_approval=$(echo "$PR_SNAPSHOT" | jq -r --arg bot "${BOT_USER:-donpetry-bot}" --arg sha "$PR_HEAD_SHA" 'first((.reviews // [])[] | select(.author?.login == $bot and .state == "APPROVED" and .commit?.oid == $sha) | .id) // empty' 2>/dev/null || true) if [ -n "$_agent_approval" ]; then - gh api graphql -f query='mutation($id:ID!,$msg:String!){dismissPullRequestReview(input:{pullRequestReviewId:$id,message:$msg}){clientMutationId}}' -f id="$_agent_approval" -f msg="Dismissing approval due to unaddressed maintainer issue comment (#1290)" 2>/dev/null || echo " warn: could not dismiss prior approval" + gh api graphql -f query='mutation($id:ID!,$msg:String!){dismissPullRequestReview(input:{pullRequestReviewId:$id,message:$msg}){clientMutationId}}' -f id="$_agent_approval" -f msg="Dismissing approval due to a PR issue comment lacking a verified disposition (#1813)" 2>/dev/null || echo " warn: could not dismiss prior approval" fi fi - emit_verdict skip unaddressed-maintainer-comment "the maintainer comment is addressed by a new push, or an @mention (FORCE_REVIEW) overrides the gate" + emit_verdict skip undispositioned-pr-comment "dev-lead posts a verified disposition reply and the harness minimizes the comment RESOLVED, or an @mention (FORCE_REVIEW) overrides the gate" exit 100 elif [ "$mc_gate_rc" -eq 2 ]; then echo " error: maintainer-comment gate could not evaluate the PR snapshot — failing closed to avoid uninformed approval" - emit_verdict error maintainer-comment-gate-error "the gate can determine head push-time and comment authorship; the next scheduled pr-review sweep retries this PR" + emit_verdict error maintainer-comment-gate-error "the gate can parse the PR snapshot and each comment's disposition state; the next scheduled pr-review sweep retries this PR" exit 1 else exit "$mc_gate_rc" diff --git a/tests/dev-lead/unit/test_comment_disposition_verify.bats b/tests/dev-lead/unit/test_comment_disposition_verify.bats new file mode 100644 index 000000000..1f69df027 --- /dev/null +++ b/tests/dev-lead/unit/test_comment_disposition_verify.bats @@ -0,0 +1,180 @@ +#!/usr/bin/env bats +# Tests for comment-disposition-verify.sh (issue #1813) +# +# The pure verifier that turns a dev-lead comment-disposition reply into a +# machine-checkable claim, and decides whether the harness may resolve (minimize +# as RESOLVED) the original PR issue comment. Mirrors addressed-claim-verify.sh +# (review-thread path) for the issue-comment path. +# +# cdv_parse_disposition +# 0 + canonical JSON {id,disposition,sha,ref} (valid single marker) +# 1 + reason token (no-disposition | multiple-dispositions | bad-id | +# bad-disposition | bad-sha | missing-ref) +# cdv_authorize +# 0 = the harness may minimize the comment RESOLVED; 1 = leave it open +# cdv_reply_needs_response +# 0 = the bot's reply-to-our-disposition raises a NEW finding (answer it) +# 1 = boilerplate / acknowledgement / ambiguous (do NOT answer — loop safety) + +setup() { + export SCRIPT_DIR="$(cd "$(dirname "${BATS_TEST_FILENAME%/*}")" && pwd)/../../scripts" + LIB="$SCRIPT_DIR/lib/comment-disposition-verify.sh" +} + +teardown() { + unset SCRIPT_DIR +} + +_parse() { + run bash -c "source '$LIB'; cdv_parse_disposition \"\$1\"" _ "$1" +} + +_authorize() { + run bash -c "source '$LIB'; cdv_authorize \"\$1\" \"\$2\" \"\$3\"" _ "$1" "$2" "$3" +} + +_needs_response() { + run bash -c "source '$LIB'; cdv_reply_needs_response \"\$1\"" _ "$1" +} + +# ──────────────────────────────────────────────────────────────────── +# STRUCTURAL +# ──────────────────────────────────────────────────────────────────── + +@test "verifier: has correct shebang" { + head -1 "$LIB" | grep -q "^#!/usr/bin/env bash" +} + +@test "verifier: uses set -euo pipefail" { + grep -q "^set -euo pipefail" "$LIB" +} + +@test "verifier: shellcheck passes" { + command -v shellcheck >/dev/null 2>&1 || skip "shellcheck not installed" + shellcheck --shell=bash --severity=warning "$LIB" +} + +# ──────────────────────────────────────────────────────────────────── +# cdv_parse_disposition +# ──────────────────────────────────────────────────────────────────── + +@test "parse: valid answered disposition → JSON" { + _parse 'Answered below. +' + [ "$status" -eq 0 ] + echo "$output" | jq -e '.id == "IC_123" and .disposition == "answered"' +} + +@test "parse: valid fixed disposition with sha → JSON" { + _parse 'Fixed. +' + [ "$status" -eq 0 ] + echo "$output" | jq -e '.disposition == "fixed" and (.sha | length) == 40' +} + +@test "parse: valid out-of-scope disposition with ref → JSON" { + _parse 'Tracked elsewhere. +' + [ "$status" -eq 0 ] + echo "$output" | jq -e '.disposition == "out-of-scope" and .ref == "#42"' +} + +@test "parse: no marker → no-disposition rc1" { + _parse 'Just a plain reply with no marker.' + [ "$status" -eq 1 ] + [ "$output" = "no-disposition" ] +} + +@test "parse: two markers → multiple-dispositions rc1" { + _parse ' +' + [ "$status" -eq 1 ] + [ "$output" = "multiple-dispositions" ] +} + +@test "parse: unknown disposition word → bad-disposition rc1" { + _parse '' + [ "$status" -eq 1 ] + [ "$output" = "bad-disposition" ] +} + +@test "parse: fixed without sha → bad-sha rc1" { + _parse '' + [ "$status" -eq 1 ] + [ "$output" = "bad-sha" ] +} + +@test "parse: fixed with abbreviated sha → bad-sha rc1" { + _parse '' + [ "$status" -eq 1 ] + [ "$output" = "bad-sha" ] +} + +@test "parse: out-of-scope without ref → missing-ref rc1" { + _parse '' + [ "$status" -eq 1 ] + [ "$output" = "missing-ref" ] +} + +@test "parse: missing id → bad-id rc1" { + _parse '' + [ "$status" -eq 1 ] + [ "$output" = "bad-id" ] +} + +# ──────────────────────────────────────────────────────────────────── +# cdv_authorize (AC4 / AC5) +# ──────────────────────────────────────────────────────────────────── + +@test "authorize: bot comment + any verified disposition → 0 (resolve)" { + _authorize answered false true + [ "$status" -eq 0 ] +} + +@test "authorize: bot comment + unverified disposition → 1 (leave open)" { + _authorize answered false false + [ "$status" -eq 1 ] +} + +# AC9(c): a fixed disposition whose sha is not on head is unverified → blocks. +@test "AC9c: fixed disposition, sha not on head (verified=false) → 1 (block)" { + _authorize fixed false false + [ "$status" -eq 1 ] +} + +# AC5: a human maintainer comment auto-resolves ONLY on a verified fixed. +@test "AC5: human comment + verified fixed → 0 (resolve)" { + _authorize fixed true true + [ "$status" -eq 0 ] +} + +# AC9(d): a human comment with a non-fixed disposition stays open for the human. +@test "AC9d: human comment + verified invalid → 1 (leave open for human)" { + _authorize invalid true true + [ "$status" -eq 1 ] +} + +@test "AC9d: human comment + verified answered → 1 (leave open for human)" { + _authorize answered true true + [ "$status" -eq 1 ] +} + +# ──────────────────────────────────────────────────────────────────── +# cdv_reply_needs_response (AC7 / AC9f — loop safety) +# ──────────────────────────────────────────────────────────────────── + +# AC9(f): a bot's boilerplate/acknowledgement reply does not trigger another reply. +@test "AC9f: bot boilerplate ack reply → 1 (do not respond)" { + _needs_response '✅ Customized review instruction saved!' + [ "$status" -eq 1 ] +} + +@test "AC9f: bot reply with a genuinely new finding → 0 (respond)" { + _needs_response 'Potential issue: this introduces a SQL injection vulnerability.' + [ "$status" -eq 0 ] +} + +@test "AC9f: ambiguous bot reply → 1 (do not respond — no chain)" { + _needs_response 'Thanks for the update.' + [ "$status" -eq 1 ] +} diff --git a/tests/dev-lead/unit/test_maintainer_comment_gate.bats b/tests/dev-lead/unit/test_maintainer_comment_gate.bats index c7c7c1391..91326ceb5 100644 --- a/tests/dev-lead/unit/test_maintainer_comment_gate.bats +++ b/tests/dev-lead/unit/test_maintainer_comment_gate.bats @@ -1,16 +1,21 @@ #!/usr/bin/env bats -# Tests for maintainer-comment-gate.sh (issue #1290) +# Tests for maintainer-comment-gate.sh (issues #1290, #1813) # -# A maintainer finding posted as a PR *issue comment* (gh pr comment / the -# GitHub main comment box) creates no review thread, so it neither blocks merge -# nor reaches dev-lead. This gate withholds pr-review's automated approval while -# the latest maintainer issue comment postdates the last push, and FAILS CLOSED: -# an inability to confirm the comment was addressed must block, never read as -# "no findings". +# #1813 redesign: "addressed" is no longer a timestamp proxy against the head +# push (pushedDate is always null, and a push says nothing about whether a +# comment's finding was researched, answered, and resolved). Instead, a PR issue +# comment is "addressed" only once it carries a VERIFIED DISPOSITION — surfaced +# server-side as the comment being minimized with classifier RESOLVED (the +# harness minimizes it after verifying dev-lead's disposition reply). The gate +# withholds pr-review's approval while ANY non-agent issue comment lacks that +# signal — bots and humans alike, with the ONLY exclusion being our own account +# and our own agent-marked disposition/ack/note replies. It FAILS CLOSED: an +# undeterminable snapshot blocks and is reported distinctly (never disguised as +# the legitimate hold). # -# check_maintainer_comments [bot_user] -# 0 = no unaddressed maintainer comment (none, or latest is at/older than head push) -# 1 = latest maintainer comment postdates the last push (unaddressed) → block +# check_maintainer_comments [bot_user] +# 0 = every non-agent issue comment is minimized RESOLVED (or none exist) +# 1 = at least one non-agent issue comment lacks a verified disposition → block # 2 = snapshot could not be evaluated (malformed) → fail closed → block setup() { @@ -23,8 +28,8 @@ teardown() { } _run_check() { - # _run_check [bot_user] - run bash -c "source '$GATE'; check_maintainer_comments \"\$1\" \"\$2\" \"\$3\"" _ "$1" "$2" "${3:-donpetry-bot}" + # _run_check [bot_user] + run bash -c "source '$GATE'; check_maintainer_comments \"\$1\" \"\$2\"" _ "$1" "${2:-donpetry-bot}" } # ──────────────────────────────────────────────────────────────────── @@ -56,112 +61,100 @@ _run_check() { shellcheck --shell=bash --severity=warning "$GATE" } +# AC1 — no pushedDate dependency anywhere in the gate. +@test "AC1: gate reads no pushedDate field" { + ! grep -q "pushedDate" "$GATE" +} + +# AC1 — the head-time helper (still used by the review-thread gate) uses committer.date. +@test "AC1: head-time helper uses committer.date, not pushedDate" { + grep -q "committer" "$GATE" + ! grep -q "pushedDate" "$GATE" +} + # ──────────────────────────────────────────────────────────────────── # RUNTIME BEHAVIOR TESTS # ──────────────────────────────────────────────────────────────────── @test "Runtime: no comments → 0 (nothing to block on)" { - _run_check '{"comments":[],"reviews":[]}' '2026-06-07T10:00:00Z' + _run_check '{"comments":[],"reviews":[]}' [ "$status" -eq 0 ] } -@test "Runtime: maintainer comment postdates last push → 1 (block)" { - local json='{"comments":[{"author":{"login":"a-maintainer"},"body":"This fails open — an API error emits no labels and returns success.","createdAt":"2026-06-07T12:00:00Z"}],"reviews":[]}' - _run_check "$json" '2026-06-07T10:00:00Z' - [ "$status" -eq 1 ] -} - -@test "Runtime: push landed after the maintainer comment → 0 (addressed)" { - local json='{"comments":[{"author":{"login":"a-maintainer"},"body":"Please fix the fail-open.","createdAt":"2026-06-07T10:00:00Z"}],"reviews":[]}' - _run_check "$json" '2026-06-07T12:00:00Z' +@test "Runtime: null comments field is treated as no findings → 0" { + _run_check '{"reviews":[]}' [ "$status" -eq 0 ] } -@test "Runtime: empty head date with a maintainer comment → 1 (fail closed)" { - local json='{"comments":[{"author":{"login":"a-maintainer"},"body":"Blocking finding.","createdAt":"2026-06-07T12:00:00Z"}],"reviews":[]}' - _run_check "$json" '' +# AC9(b): an undispositioned codeant-ai comment blocks. +@test "AC9b: undispositioned codeant-ai comment → 1 (block)" { + local json='{"comments":[{"author":{"login":"codeant-ai"},"body":"## CodeAnt AI — Review Status","createdAt":"2026-09-13T04:23:06Z","isMinimized":false,"minimizedReason":""}]}' + _run_check "$json" [ "$status" -eq 1 ] } -@test "Runtime: empty head date and NO maintainer comment → 0 (nothing to block)" { - _run_check '{"comments":[],"reviews":[]}' '' - [ "$status" -eq 0 ] -} - -@test "Runtime: malformed snapshot → 2 (fail closed)" { - _run_check 'not json at all {' '2026-06-07T10:00:00Z' - [ "$status" -eq 2 ] -} - -@test "Runtime: our own pr-review agent-marked comment is ignored → 0" { - local json='{"comments":[{"author":{"login":"donpetry-bot"},"body":" Review posted.","createdAt":"2026-06-07T12:00:00Z"}],"reviews":[]}' - _run_check "$json" '2026-06-07T10:00:00Z' - [ "$status" -eq 0 ] +# AC9(b): an undispositioned qodo-code-review comment blocks. +@test "AC9b: undispositioned qodo-code-review comment → 1 (block)" { + local json='{"comments":[{"author":{"login":"qodo-code-review"},"body":" Qodo reviews are paused because your trial has ended.","createdAt":"2026-09-13T04:23:06Z","isMinimized":false,"minimizedReason":""}]}' + _run_check "$json" + [ "$status" -eq 1 ] } -@test "Runtime: dev-lead-marked comment is ignored → 0" { - local json='{"comments":[{"author":{"login":"don-petry"},"body":" Rebased onto main.","createdAt":"2026-06-07T12:00:00Z"}],"reviews":[]}' - _run_check "$json" '2026-06-07T10:00:00Z' - [ "$status" -eq 0 ] +# AC9(b): an undispositioned auto-rebase-conflict comment (authored by don-petry, +# NOT one of our agent markers) blocks — a conflict report is a finding. +@test "AC9b: undispositioned auto-rebase-conflict comment → 1 (block)" { + local json='{"comments":[{"author":{"login":"don-petry"},"body":" Auto-rebase failed — merge conflict.","createdAt":"2026-09-13T04:28:56Z","isMinimized":false,"minimizedReason":""}]}' + _run_check "$json" + [ "$status" -eq 1 ] } -@test "Runtime: persona-marked advisory comment is ignored → 0" { - local json='{"comments":[{"author":{"login":"donpetry-bot"},"body":" Advisory guidance.","createdAt":"2026-06-07T12:00:00Z"}],"reviews":[]}' - _run_check "$json" '2026-06-07T10:00:00Z' +# AC9(a): pushedDate is irrelevant; every comment minimized RESOLVED → passes. +@test "AC9a: all non-agent comments minimized RESOLVED → 0 (clear)" { + local json='{"comments":[{"author":{"login":"codeant-ai"},"body":"Review Status","createdAt":"2026-09-13T04:23:06Z","isMinimized":true,"minimizedReason":"resolved"},{"author":{"login":"qodo-code-review"},"body":"Trial ended.","createdAt":"2026-09-13T04:23:06Z","isMinimized":true,"minimizedReason":"resolved"}]}' + _run_check "$json" [ "$status" -eq 0 ] } -@test "Runtime: dependency-advisory comment (posted as don-petry) is ignored → 0" { - # dependency-advisory.yml posts as the human owner don-petry with a marker; it - # must not be mistaken for a maintainer finding and self-block auto-merge. - local json='{"comments":[{"author":{"login":"don-petry"},"body":"\n## Dependency Advisory\nNo issues.","createdAt":"2026-06-07T12:00:00Z"}],"reviews":[]}' - _run_check "$json" '2026-06-07T10:00:00Z' - [ "$status" -eq 0 ] +@test "Runtime: mix of resolved + one unresolved non-agent comment → 1 (block)" { + local json='{"comments":[{"author":{"login":"codeant-ai"},"body":"Status","createdAt":"2026-09-13T04:23:06Z","isMinimized":true,"minimizedReason":"resolved"},{"author":{"login":"a-maintainer"},"body":"Please fix this.","createdAt":"2026-09-13T05:00:00Z","isMinimized":false,"minimizedReason":""}]}' + _run_check "$json" + [ "$status" -eq 1 ] } -@test "Runtime: dev-lead rate-limit-ack (posted as don-petry) is ignored → 0" { - # The rate-limit ack in dev-lead-fix-reviews.sh is authored by don-petry; its - # marker must exclude it from the gate. - local json='{"comments":[{"author":{"login":"don-petry"},"body":"\n> [!NOTE]\n> I received your request but all AI engines are currently rate-limited.","createdAt":"2026-06-07T12:00:00Z"}],"reviews":[]}' - _run_check "$json" '2026-06-07T10:00:00Z' - [ "$status" -eq 0 ] +@test "Runtime: comment minimized for a NON-resolved reason (outdated) still blocks → 1" { + local json='{"comments":[{"author":{"login":"codeant-ai"},"body":"Status","createdAt":"2026-09-13T04:23:06Z","isMinimized":true,"minimizedReason":"outdated"}]}' + _run_check "$json" + [ "$status" -eq 1 ] } -@test "Runtime: advisory bot issue comment is ignored → 0 (handled by advisory gate)" { - local json='{"comments":[{"author":{"login":"gemini-code-assist"},"body":"Some advisory note.","createdAt":"2026-06-07T12:00:00Z"}],"reviews":[]}' - _run_check "$json" '2026-06-07T10:00:00Z' +# AC9(e): our own disposition/ack reply never blocks the gate (loop safety). +@test "AC9e: our dev-lead comment-disposition reply is ignored → 0" { + local json='{"comments":[{"author":{"login":"don-petry"},"body":"Researched and answered.\n","createdAt":"2026-09-13T06:00:00Z","isMinimized":false,"minimizedReason":""}]}' + _run_check "$json" [ "$status" -eq 0 ] } -@test "Runtime: coderabbitai issue comment is ignored → 0" { - local json='{"comments":[{"author":{"login":"coderabbitai"},"body":"Actionable comment.","createdAt":"2026-06-07T12:00:00Z"}],"reviews":[]}' - _run_check "$json" '2026-06-07T10:00:00Z' +@test "Runtime: our own pr-review agent-marked comment is ignored → 0" { + local json='{"comments":[{"author":{"login":"donpetry-bot"},"body":" Review posted.","createdAt":"2026-09-13T06:00:00Z","isMinimized":false,"minimizedReason":""}]}' + _run_check "$json" [ "$status" -eq 0 ] } @test "Runtime: bot_user's own plain comment is ignored → 0" { - local json='{"comments":[{"author":{"login":"donpetry-bot"},"body":"CI is still running.","createdAt":"2026-06-07T12:00:00Z"}],"reviews":[]}' - _run_check "$json" '2026-06-07T10:00:00Z' 'donpetry-bot' + local json='{"comments":[{"author":{"login":"donpetry-bot"},"body":"CI is still running.","createdAt":"2026-09-13T06:00:00Z","isMinimized":false,"minimizedReason":""}]}' + _run_check "$json" 'donpetry-bot' [ "$status" -eq 0 ] } -@test "Runtime: old addressed finding + newer bot comment → 0" { - # Maintainer finding predates the last push (addressed); a later advisory bot - # comment must not re-arm the gate. - local json='{"comments":[{"author":{"login":"a-maintainer"},"body":"Old finding.","createdAt":"2026-06-07T08:00:00Z"},{"author":{"login":"sonarqubecloud"},"body":"Quality gate passed.","createdAt":"2026-06-07T13:00:00Z"}],"reviews":[]}' - _run_check "$json" '2026-06-07T10:00:00Z' +@test "Runtime: dependency-advisory comment (posted as don-petry, marked) is ignored → 0" { + local json='{"comments":[{"author":{"login":"don-petry"},"body":"\n## Dependency Advisory\nNo issues.","createdAt":"2026-09-13T06:00:00Z","isMinimized":false,"minimizedReason":""}]}' + _run_check "$json" [ "$status" -eq 0 ] } -@test "Runtime: two maintainer comments, latest postdates push → 1 (block)" { - local json='{"comments":[{"author":{"login":"a-maintainer"},"body":"First note.","createdAt":"2026-06-07T08:00:00Z"},{"author":{"login":"another-maintainer"},"body":"Second finding after the fix push.","createdAt":"2026-06-07T12:00:00Z"}],"reviews":[]}' - _run_check "$json" '2026-06-07T10:00:00Z' - [ "$status" -eq 1 ] -} - -@test "Runtime: null comments field is treated as no findings → 0" { - _run_check '{"reviews":[]}' '2026-06-07T10:00:00Z' - [ "$status" -eq 0 ] +@test "Runtime: malformed snapshot → 2 (fail closed)" { + _run_check 'not json at all {' + [ "$status" -eq 2 ] } # ──────────────────────────────────────────────────────────────────── @@ -173,16 +166,13 @@ _run_check() { grep -q "check_maintainer_comments" "$SCRIPT_DIR/review-one-pr.sh" } -@test "Wiring: review-one-pr.sh skips on rc=1 with unaddressed-maintainer-comment reason" { - grep -q "unaddressed-maintainer-comment" "$SCRIPT_DIR/review-one-pr.sh" -} - -@test "Wiring: review-one-pr.sh fails closed on rc=2" { +@test "AC8: undispositioned hold and undeterminable error use distinct reasons" { + # The legitimate hold reason must NOT be reused for the undeterminable/error state. + grep -q "undispositioned-pr-comment" "$SCRIPT_DIR/review-one-pr.sh" grep -q "maintainer-comment-gate-error" "$SCRIPT_DIR/review-one-pr.sh" } @test "Wiring: FORCE_REVIEW bypasses the maintainer-comment gate" { - # The gate block must be guarded by a FORCE_REVIEW check like the other gates. grep -B8 "check_maintainer_comments" "$SCRIPT_DIR/review-one-pr.sh" | grep -q "FORCE_REVIEW" } From df2e9059d71da86704d16f19ea536adc498e7b57 Mon Sep 17 00:00:00 2001 From: don-petry <36422719+don-petry@users.noreply.github.com> Date: Sun, 13 Sep 2026 16:19:56 +0000 Subject: [PATCH 2/3] chore: dev-lead update (review-changes) [skip ci-relay] --- scripts/dev-lead-fix-reviews.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/dev-lead-fix-reviews.sh b/scripts/dev-lead-fix-reviews.sh index 8b01b6653..e2f74a1f3 100755 --- a/scripts/dev-lead-fix-reviews.sh +++ b/scripts/dev-lead-fix-reviews.sh @@ -902,11 +902,11 @@ resolve_dispositioned_comments() { } } }' - pages_file=$(mktemp) + pages_file=$(mktemp) || { echo "::error::failed to create temporary file" >&2; exit 1; } while [ "$has_next_page" = "true" ]; do page_response=$(gh api graphql -f query="$comments_query" \ -F owner="${REPO%%/*}" -F repo="${REPO##*/}" -F pr="$PR_NUMBER" \ - "${cursor_args[@]}" 2>/dev/null || echo "{}") + "${cursor_args[@]}" 2>/dev/null) page_nodes=$(printf '%s' "$page_response" | jq -c \ '.data?.repository?.pullRequest?.comments?.nodes // []' 2>/dev/null || echo "[]") printf '%s\n' "$page_nodes" >> "$pages_file" @@ -950,7 +950,7 @@ resolve_dispositioned_comments() { local resolved_count=0 local cid is_human cur_minimized reply_body disp_json disposition sha ref verified - while IFS= read -r cid; do + while IFS= read -r cid || [ -n "$cid" ]; do [ -z "$cid" ] && continue # Re-read the ORIGINAL comment's CURRENT minimize state so a comment minimized @@ -975,7 +975,7 @@ resolve_dispositioned_comments() { # unverifiable reply never matches. Bodies are base64-framed to survive newlines. reply_body="" local c_body_b64 c_body parsed pid - while IFS= read -r c_body_b64; do + while IFS= read -r c_body_b64 || [ -n "$c_body_b64" ]; do [ -z "$c_body_b64" ] && continue c_body=$(printf '%s' "$c_body_b64" | base64 -d 2>/dev/null || true) parsed=$(cdv_parse_disposition "$c_body" 2>/dev/null) || continue From 0557885185b1b6769573f24a1bc19a82bdd5b5ca Mon Sep 17 00:00:00 2001 From: don-petry <36422719+don-petry@users.noreply.github.com> Date: Sun, 13 Sep 2026 16:39:57 +0000 Subject: [PATCH 3/3] fix(reviews): address review comments [skip ci-relay] --- prompts/dev-lead/fix-reviews.md | 19 ++++-- scripts/dev-lead-fix-reviews.sh | 62 ++++++++++++++----- scripts/lib/comment-disposition-verify.sh | 6 ++ .../unit/test_maintainer_comment_gate.bats | 2 +- 4 files changed, 68 insertions(+), 21 deletions(-) diff --git a/prompts/dev-lead/fix-reviews.md b/prompts/dev-lead/fix-reviews.md index 04d98b081..86b425279 100644 --- a/prompts/dev-lead/fix-reviews.md +++ b/prompts/dev-lead/fix-reviews.md @@ -106,10 +106,21 @@ Review threads are only half the surface. A finding posted as a PR **issue comme **Enumerate the PR's issue comments** (not review threads): ```bash -gh api graphql -f query='query($owner:String!,$repo:String!,$pr:Int!){ - repository(owner:$owner,name:$repo){ pullRequest(number:$pr){ - comments(first:100){ nodes{ id author{login __typename} body isMinimized minimizedReason } } } } }' \ - -F owner="${REPO%%/*}" -F repo="${REPO##*/}" -F pr="${PR_NUMBER}" +# Paginate through EVERY issue comment — a PR with more than 100 comments would +# otherwise strand every finding past the first page (the maintainer gate stays +# blocked on them). Loop on pageInfo.hasNextPage / endCursor until exhausted. +cursor=null +while :; do + page=$(gh api graphql -f query='query($owner:String!,$repo:String!,$pr:Int!,$cursor:String){ + repository(owner:$owner,name:$repo){ pullRequest(number:$pr){ + comments(first:100, after:$cursor){ + nodes{ id author{login __typename} body isMinimized minimizedReason } + pageInfo{ hasNextPage endCursor } } } } }' \ + -F owner="${REPO%%/*}" -F repo="${REPO##*/}" -F pr="${PR_NUMBER}" -F cursor="${cursor}") + echo "$page" | jq -c '.data.repository.pullRequest.comments.nodes[]' # process this page + [ "$(echo "$page" | jq -r '.data.repository.pullRequest.comments.pageInfo.hasNextPage')" = "true" ] || break + cursor=$(echo "$page" | jq -r '.data.repository.pullRequest.comments.pageInfo.endCursor') +done ``` **Skip** (do not disposition, never reply to): diff --git a/scripts/dev-lead-fix-reviews.sh b/scripts/dev-lead-fix-reviews.sh index e2f74a1f3..bb16cb86f 100755 --- a/scripts/dev-lead-fix-reviews.sh +++ b/scripts/dev-lead-fix-reviews.sh @@ -968,25 +968,40 @@ resolve_dispositioned_comments() { is_human=$(printf '%s' "$all_comments" | jq -r --arg id "$cid" \ 'first(.[] | select(.id == $id)) | if (.author?.__typename // "") == "User" then "true" else "false" end' 2>/dev/null || echo "false") - # Locate OUR disposition reply for this comment id: the comment whose parseable - # disposition marker cites id=. GitHub returns comments in chronological - # order, so the last match in the stream is the latest reply (AC7 expects exactly - # one). cdv_parse_disposition rejects malformed/ambiguous markers, so an - # unverifiable reply never matches. Bodies are base64-framed to survive newlines. + # Locate OUR disposition reply for this comment id: a comment AUTHORED BY OUR + # BOT ACCOUNT (BOT_USER, or its GraphQL-stripped login) whose parseable + # disposition marker cites id=. Restricting to our account is an + # authorization gate (CWE-863): without it, an EXTERNAL commenter could post a + # marker citing a candidate id plus a real PR SHA and trick the harness into + # minimizing the original comment as RESOLVED. cdv_parse_disposition rejects + # malformed/ambiguous markers, so an unverifiable reply never matches. Require + # EXACTLY ONE authorized disposition (AC7) — zero or many fail closed. Bodies + # are base64-framed to survive newlines. reply_body="" - local c_body_b64 c_body parsed pid + local c_body_b64 c_body parsed pid auth_count=0 while IFS= read -r c_body_b64 || [ -n "$c_body_b64" ]; do [ -z "$c_body_b64" ] && continue c_body=$(printf '%s' "$c_body_b64" | base64 -d 2>/dev/null || true) parsed=$(cdv_parse_disposition "$c_body" 2>/dev/null) || continue pid=$(printf '%s' "$parsed" | jq -r '.id // ""' 2>/dev/null || echo "") [ "$pid" = "$cid" ] || continue + auth_count=$((auth_count + 1)) reply_body="$c_body" disp_json="$parsed" - done < <(printf '%s' "$all_comments" | jq -r '.[] | (.body // "") | @base64' 2>/dev/null) + done < <(printf '%s' "$all_comments" | jq -r \ + --arg botuser "$bot_user" ' + def bot_stripped: ($botuser | if endswith("[bot]") then .[0:-5] else . end); + .[] | objects + | (.author?.login // "" | tostring) as $l + | select($l == $botuser or $l == bot_stripped) + | (.body // "") | @base64' 2>/dev/null) if [ -z "$reply_body" ]; then - echo "::notice::skipping comment ${cid} — no verified dev-lead disposition reply found; leaving open (#1813)" + echo "::notice::skipping comment ${cid} — no authorized dev-lead disposition reply from ${bot_user} found; leaving open (#1813)" + continue + fi + if [ "$auth_count" -ne 1 ]; then + echo "::notice::skipping comment ${cid} — expected exactly one authorized disposition reply, found ${auth_count}; leaving open (#1813)" continue fi @@ -998,14 +1013,29 @@ resolve_dispositioned_comments() { verified="false" case "$disposition" in fixed) - # The cited sha must be on the PR head with a non-empty diff. - local facts on_head own_files cumulative_files - facts=$(acv_gather_commit_facts "$sha") - on_head=$(printf '%s' "$facts" | jq -r '.on_head // false' 2>/dev/null || echo "false") - own_files=$(printf '%s' "$facts" | jq -r '(.own_files // []) | length' 2>/dev/null || echo "0") - cumulative_files=$(printf '%s' "$facts" | jq -r '(.cumulative_files // []) | length' 2>/dev/null || echo "0") - if [ "$on_head" = "true" ] && { [ "${own_files:-0}" -gt 0 ] || [ "${cumulative_files:-0}" -gt 0 ]; }; then - verified="true" + # Bind the `fixed` evidence to THIS pass's commit — not merely any ancestor + # already on the PR head. Without this, a prior pass's commit (or any + # existing ancestor) satisfies the on-head + non-empty-diff check even when + # the current pass produced no fix. Require: this pass advanced the head + # (RESOLUTION_BASE_SHA → current HEAD via ri_may_resolve), the cited sha was + # produced by this pass (reachable from HEAD but NOT from the pre-pass base), + # and its diff is non-empty. Fail closed when the pre-pass base or HEAD is + # unknowable, or the sha predates this pass. + local facts on_head own_files cumulative_files pass_base pass_head + pass_base="${RESOLUTION_BASE_SHA:-}" + pass_head="$(git rev-parse HEAD 2>/dev/null || true)" + if ri_may_resolve "$pass_base" "$pass_head" \ + && git merge-base --is-ancestor "$sha" "$pass_head" 2>/dev/null \ + && ! git merge-base --is-ancestor "$sha" "$pass_base" 2>/dev/null; then + facts=$(acv_gather_commit_facts "$sha") + on_head=$(printf '%s' "$facts" | jq -r '.on_head // false' 2>/dev/null || echo "false") + own_files=$(printf '%s' "$facts" | jq -r '(.own_files // []) | length' 2>/dev/null || echo "0") + cumulative_files=$(printf '%s' "$facts" | jq -r '(.cumulative_files // []) | length' 2>/dev/null || echo "0") + if [ "$on_head" = "true" ] && { [ "${own_files:-0}" -gt 0 ] || [ "${cumulative_files:-0}" -gt 0 ]; }; then + verified="true" + fi + else + echo "::notice::skipping comment ${cid} — cited sha ${sha} was not produced by this pass (base=${pass_base:-} head=${pass_head:-}); leaving open (#1813)" fi ;; out-of-scope) diff --git a/scripts/lib/comment-disposition-verify.sh b/scripts/lib/comment-disposition-verify.sh index 391ac7c00..32df6c2dc 100755 --- a/scripts/lib/comment-disposition-verify.sh +++ b/scripts/lib/comment-disposition-verify.sh @@ -76,6 +76,12 @@ cdv_parse_disposition() { # Extract the attribute string between the literal prefix and the trailing ` -->`. local rest attrs rest="${body#*"$_CDV_MARKER_PREFIX"}" + # An unclosed marker (no trailing ` -->`) is malformed — reject it rather than + # letting `attrs` absorb the entire remaining body and parse valid-looking keys. + if [[ "$rest" != *"$_CDV_MARKER_SUFFIX"* ]]; then + echo "bad-disposition" + return 1 + fi attrs="${rest%%"$_CDV_MARKER_SUFFIX"*}" # Pull each key=value token. Keys are matched anchored so `id=` cannot capture diff --git a/tests/dev-lead/unit/test_maintainer_comment_gate.bats b/tests/dev-lead/unit/test_maintainer_comment_gate.bats index 91326ceb5..be8aeeb97 100644 --- a/tests/dev-lead/unit/test_maintainer_comment_gate.bats +++ b/tests/dev-lead/unit/test_maintainer_comment_gate.bats @@ -68,7 +68,7 @@ _run_check() { # AC1 — the head-time helper (still used by the review-thread gate) uses committer.date. @test "AC1: head-time helper uses committer.date, not pushedDate" { - grep -q "committer" "$GATE" + grep -q 'commit{committer{date}}' "$GATE" ! grep -q "pushedDate" "$GATE" }