From 0dce08435f6e98ccc580d2c780e5d56124806adf Mon Sep 17 00:00:00 2001 From: donpetry-bot <281750570+donpetry-bot@users.noreply.github.com> Date: Mon, 8 Jun 2026 00:09:46 +0000 Subject: [PATCH 1/5] =?UTF-8?q?feat:=20implement=20issue=20#469=20?= =?UTF-8?q?=E2=80=94=20pr-review:=20mention-triggered=20runs=20silently=20?= =?UTF-8?q?lost=20to=20ci-pending=20skip=20(self-referential=20check=20run?= =?UTF-8?q?s)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/lint.yml | 2 +- scripts/lib/ci-status.sh | 55 +++++++ scripts/review-one-pr.sh | 70 +++++++-- tests/test_ci_status.bats | 315 +++++++++++++++++++++++++++++++++++++ 4 files changed, 424 insertions(+), 18 deletions(-) create mode 100644 scripts/lib/ci-status.sh create mode 100644 tests/test_ci_status.bats diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index d44fdbda2..20fe8e361 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -34,7 +34,7 @@ jobs: run: sudo apt-get install -y bats - name: Run tests - run: bats tests/fleet_report.bats tests/token_report.bats tests/model_pricing.bats tests/test_review_cycle.bats + run: bats tests/fleet_report.bats tests/token_report.bats tests/model_pricing.bats tests/test_review_cycle.bats tests/test_ci_status.bats validate-agent-profiles: runs-on: ubuntu-latest diff --git a/scripts/lib/ci-status.sh b/scripts/lib/ci-status.sh new file mode 100644 index 000000000..f41223bf6 --- /dev/null +++ b/scripts/lib/ci-status.sh @@ -0,0 +1,55 @@ +#!/usr/bin/env bash +# ci-status.sh — compute CI gate status from a statusCheckRollup JSON array, +# filtering out the PR Review Agent's own check runs so the cascade never +# blocks on itself (issue #469). +# +# Usage: source this file, then call compute_ci_status with the rollup array. + +# compute_ci_status +# +# Inputs: +# $1 — JSON array (the .statusCheckRollup field from `gh pr view`) +# +# Outputs (stdout): one of "passing", "pending", "failing" +# +# Classification rules (after filtering own checks): +# passing — empty rollup, or every item is SUCCESS/SKIPPED/NEUTRAL/SUCCESS state +# pending — any item is IN_PROGRESS/QUEUED/WAITING/PENDING/EXPECTED or +# COMPLETED with null/empty conclusion +# failing — anything else (FAILURE, ACTION_REQUIRED, TIMED_OUT, etc.) +# +# Own-check filter — excludes entries whose name matches any of: +# • exact job-name forms: review, dispatch, ci-relay, pr-review-mention, mention-ack +# • workflow/job forms: "* / review", "* / dispatch", "* / ci-relay", etc. +# • known workflow prefixes: "PR Review Agent / *", "PR Review Reusable / *", +# "PR Review — Mention Trigger / *" +# The filter uses both .name (CheckRun) and .context (StatusContext) so it +# covers both GitHub Actions checks and legacy commit statuses. +compute_ci_status() { + local rollup_json="${1:-[]}" + echo "$rollup_json" | jq -r ' + def is_pending: + .status == "IN_PROGRESS" or .status == "QUEUED" or .status == "WAITING" or + .state == "PENDING" or .state == "EXPECTED" or + (.status == "COMPLETED" and (.conclusion == null or .conclusion == "")); + def is_success: + .conclusion == "SUCCESS" or .conclusion == "SKIPPED" or .conclusion == "NEUTRAL" or + .state == "SUCCESS"; + def is_own_check: + (.name // .context // "") as $n | + ($n | test("^(review|dispatch|ci-relay|pr-review-mention|mention-ack)$")) or + ($n | test("/ (review|dispatch|ci-relay|pr-review-mention|mention-ack)$")) or + ($n | test("^PR Review (Agent|Reusable) /")) or + ($n | test("^PR Review — Mention Trigger /")) or + ($n | test("^dev-lead / (dispatch|ci-relay)$")); + if (. == null or (type != "array")) then "passing" + else + (map(select(is_own_check | not))) as $ext | + if ($ext | length) == 0 then "passing" + elif ([$ext[] | select(is_pending)] | length) > 0 then "pending" + elif ([$ext[] | select(is_success)] | length) == ($ext | length) then "passing" + else "failing" + end + end + ' 2>/dev/null || echo "passing" +} diff --git a/scripts/review-one-pr.sh b/scripts/review-one-pr.sh index 84fae0b72..65ed4a50c 100644 --- a/scripts/review-one-pr.sh +++ b/scripts/review-one-pr.sh @@ -28,6 +28,9 @@ source "$SCRIPT_DIR/engine.sh" # Cycle-cap helpers: compute_review_cycle, has_escalation_marker (issue #467). # shellcheck source=lib/review-cycle.sh source "$SCRIPT_DIR/lib/review-cycle.sh" +# CI gate: compute_ci_status filters own check runs before classifying (issue #469). +# shellcheck source=lib/ci-status.sh +source "$SCRIPT_DIR/lib/ci-status.sh" PR_URL="${1:?usage: review-one-pr.sh }" export PR_URL @@ -48,20 +51,7 @@ PR_HEAD_SHA=$(echo "$PR_SNAPSHOT" | jq -r '.headRefOid') export PR_HEAD_SHA echo " head SHA: $PR_HEAD_SHA" -CI_STATUS=$(echo "$PR_SNAPSHOT" | jq -r ' - def is_pending: - .status == "IN_PROGRESS" or .status == "QUEUED" or .status == "WAITING" or - .state == "PENDING" or .state == "EXPECTED" or - (.status == "COMPLETED" and (.conclusion == null or .conclusion == "")); - def is_success: - .conclusion == "SUCCESS" or .conclusion == "SKIPPED" or .conclusion == "NEUTRAL" or - .state == "SUCCESS"; - if (.statusCheckRollup | length) == 0 then "passing" - elif ([.statusCheckRollup[] | select(is_pending)] | length) > 0 then "pending" - elif ([.statusCheckRollup[] | select(is_success)] | length) == (.statusCheckRollup | length) then "passing" - else "failing" - end -') +CI_STATUS=$(compute_ci_status "$(echo "$PR_SNAPSHOT" | jq '.statusCheckRollup')") echo " CI status: $CI_STATUS" REVIEW_DECISION=$(echo "$PR_SNAPSHOT" | jq -r '.reviewDecision // ""') @@ -75,10 +65,56 @@ if [ "$CI_STATUS" = "failing" ]; then echo "{\"pr\":\"$PR_URL\",\"sha\":\"$PR_HEAD_SHA\",\"decision\":\"skip\",\"reason\":\"ci-failing\"}" exit 100 fi + +# Pending CI gate: for normal runs, skip immediately. +# For FORCE_REVIEW=true (mention-triggered), poll briefly so transient check +# churn (caused by the mention burst itself) doesn't silently swallow the run +# (issue #469). Defaults: 10 polls × 30 s = up to 5 minutes. if [ "$CI_STATUS" = "pending" ]; then - echo " skip: CI checks still in progress — will re-evaluate when checks complete" - echo "{\"pr\":\"$PR_URL\",\"sha\":\"$PR_HEAD_SHA\",\"decision\":\"skip\",\"reason\":\"ci-pending\"}" - exit 100 + if [ "${FORCE_REVIEW:-false}" = "true" ]; then + _FORCE_POLL_MAX="${FORCE_REVIEW_POLL_ATTEMPTS:-10}" + _FORCE_POLL_SEC="${FORCE_REVIEW_POLL_INTERVAL_SEC:-30}" + _poll=1 + while [ "$_poll" -le "$_FORCE_POLL_MAX" ] && [ "$CI_STATUS" = "pending" ]; do + echo " force-review: CI pending, waiting ${_FORCE_POLL_SEC}s for checks to settle (attempt ${_poll}/${_FORCE_POLL_MAX})" + sleep "$_FORCE_POLL_SEC" + PR_SNAPSHOT=$(gh pr view "$PR_URL" --json headRefOid,statusCheckRollup,reviewDecision,reviews,labels,comments) + PR_HEAD_SHA=$(echo "$PR_SNAPSHOT" | jq -r '.headRefOid') + export PR_HEAD_SHA + CI_STATUS=$(compute_ci_status "$(echo "$PR_SNAPSHOT" | jq '.statusCheckRollup')") + echo " CI status (poll ${_poll}): $CI_STATUS" + _poll=$((_poll + 1)) + done + unset _poll _FORCE_POLL_MAX _FORCE_POLL_SEC + + if [ "$CI_STATUS" = "failing" ]; then + echo " skip: CI checks are failing (detected after polling) — will re-evaluate after fixes are pushed" + echo "{\"pr\":\"$PR_URL\",\"sha\":\"$PR_HEAD_SHA\",\"decision\":\"skip\",\"reason\":\"ci-failing\"}" + exit 100 + fi + + if [ "$CI_STATUS" = "pending" ]; then + echo " force-review: CI still pending after polling — posting visible comment" + if [ "${DRY_RUN:-false}" != "true" ]; then + _ci_ack_body="/tmp/cascade/ci-pending-ack.txt" + mkdir -p /tmp/cascade + printf '\n\nCI checks on this PR are still running. Once they complete, re-mention `@%s` to trigger a fresh review.\n\n_Posted by the %s PR-review cascade._\n' \ + "${BOT_USER:-donpetry-bot}" "${BOT_USER:-donpetry-bot}" > "$_ci_ack_body" + gh pr comment "$PR_URL" --body-file "$_ci_ack_body" || echo " warn: could not post ci-pending-ack comment" + rm -f "$_ci_ack_body" + fi + echo "{\"pr\":\"$PR_URL\",\"sha\":\"$PR_HEAD_SHA\",\"decision\":\"skip\",\"reason\":\"ci-pending-after-poll\"}" + exit 100 + fi + + # CI settled — update REVIEW_DECISION from the refreshed snapshot + REVIEW_DECISION=$(echo "$PR_SNAPSHOT" | jq -r '.reviewDecision // ""') + echo " review decision (after CI poll): $REVIEW_DECISION" + else + echo " skip: CI checks still in progress — will re-evaluate when checks complete" + echo "{\"pr\":\"$PR_URL\",\"sha\":\"$PR_HEAD_SHA\",\"decision\":\"skip\",\"reason\":\"ci-pending\"}" + exit 100 + fi fi # Skip when a human has requested changes, with two guards: # 1. FORCE_REVIEW bypasses the skip — mention-triggered runs always proceed so diff --git a/tests/test_ci_status.bats b/tests/test_ci_status.bats new file mode 100644 index 000000000..a7362af58 --- /dev/null +++ b/tests/test_ci_status.bats @@ -0,0 +1,315 @@ +#!/usr/bin/env bats +# Unit tests for compute_ci_status in scripts/lib/ci-status.sh +# (issue #469: own check runs must never cause ci-pending/ci-failing classification) +# +# Run with: bats tests/test_ci_status.bats + +setup() { + source "$(dirname "$BATS_TEST_FILENAME")/../scripts/lib/ci-status.sh" +} + +# --------------------------------------------------------------------------- +# Helpers to build statusCheckRollup items +# --------------------------------------------------------------------------- + +# check_run [conclusion] +# Models a GitHub Actions CheckRun in the statusCheckRollup array. +check_run() { + local name="$1" status="$2" conclusion="${3:-null}" + if [ "$conclusion" = "null" ]; then + jq -n --arg name "$name" --arg status "$status" \ + '{name: $name, status: $status, conclusion: null}' + else + jq -n --arg name "$name" --arg status "$status" --arg conclusion "$conclusion" \ + '{name: $name, status: $status, conclusion: $conclusion}' + fi +} + +# status_ctx +# Models a commit StatusContext in the statusCheckRollup array. +status_ctx() { + jq -n --arg context "$1" --arg state "$2" \ + '{context: $context, state: $state}' +} + +# rollup ... +# Wraps items into a JSON array. +rollup() { + printf '%s\n' "$@" | jq -s '.' +} + +# --------------------------------------------------------------------------- +# Baseline: empty / all-passing rollups +# --------------------------------------------------------------------------- + +@test "empty rollup returns passing" { + run compute_ci_status '[]' + [ "$status" -eq 0 ] + [ "$output" = "passing" ] +} + +@test "single passing external check returns passing" { + local r + r=$(rollup "$(check_run "Lint" "COMPLETED" "SUCCESS")") + run compute_ci_status "$r" + [ "$output" = "passing" ] +} + +@test "single skipped external check returns passing" { + local r + r=$(rollup "$(check_run "Path-filtered" "COMPLETED" "SKIPPED")") + run compute_ci_status "$r" + [ "$output" = "passing" ] +} + +@test "single neutral external check returns passing" { + local r + r=$(rollup "$(check_run "Informational" "COMPLETED" "NEUTRAL")") + run compute_ci_status "$r" + [ "$output" = "passing" ] +} + +# --------------------------------------------------------------------------- +# External pending / failing without own checks +# --------------------------------------------------------------------------- + +@test "single external IN_PROGRESS check returns pending" { + local r + r=$(rollup "$(check_run "Build" "IN_PROGRESS")") + run compute_ci_status "$r" + [ "$output" = "pending" ] +} + +@test "single external QUEUED check returns pending" { + local r + r=$(rollup "$(check_run "Test" "QUEUED")") + run compute_ci_status "$r" + [ "$output" = "pending" ] +} + +@test "single external failing check returns failing" { + local r + r=$(rollup "$(check_run "Test" "COMPLETED" "FAILURE")") + run compute_ci_status "$r" + [ "$output" = "failing" ] +} + +# --------------------------------------------------------------------------- +# Own check runs filtered — exact job-name form +# --------------------------------------------------------------------------- + +@test "own check named 'review' (IN_PROGRESS) is filtered out → passing" { + local r + r=$(rollup "$(check_run "review" "IN_PROGRESS")") + run compute_ci_status "$r" + [ "$output" = "passing" ] +} + +@test "own check named 'dispatch' (IN_PROGRESS) is filtered out → passing" { + local r + r=$(rollup "$(check_run "dispatch" "IN_PROGRESS")") + run compute_ci_status "$r" + [ "$output" = "passing" ] +} + +@test "own check named 'ci-relay' (IN_PROGRESS) is filtered out → passing" { + local r + r=$(rollup "$(check_run "ci-relay" "IN_PROGRESS")") + run compute_ci_status "$r" + [ "$output" = "passing" ] +} + +@test "own check named 'pr-review-mention' (IN_PROGRESS) is filtered out → passing" { + local r + r=$(rollup "$(check_run "pr-review-mention" "IN_PROGRESS")") + run compute_ci_status "$r" + [ "$output" = "passing" ] +} + +@test "own check named 'mention-ack' (IN_PROGRESS) is filtered out → passing" { + local r + r=$(rollup "$(check_run "mention-ack" "IN_PROGRESS")") + run compute_ci_status "$r" + [ "$output" = "passing" ] +} + +# --------------------------------------------------------------------------- +# Own check runs filtered — workflow / job-name form +# --------------------------------------------------------------------------- + +@test "'PR Review Agent / review' (IN_PROGRESS) is filtered out → passing" { + local r + r=$(rollup "$(check_run "PR Review Agent / review" "IN_PROGRESS")") + run compute_ci_status "$r" + [ "$output" = "passing" ] +} + +@test "'PR Review Reusable / review' (IN_PROGRESS) is filtered out → passing" { + local r + r=$(rollup "$(check_run "PR Review Reusable / review" "IN_PROGRESS")") + run compute_ci_status "$r" + [ "$output" = "passing" ] +} + +@test "'PR Review — Mention Trigger / pr-review-mention' (IN_PROGRESS) is filtered out → passing" { + local r + r=$(rollup "$(check_run "PR Review — Mention Trigger / pr-review-mention" "IN_PROGRESS")") + run compute_ci_status "$r" + [ "$output" = "passing" ] +} + +@test "'dev-lead / dispatch' (IN_PROGRESS) is filtered out → passing" { + local r + r=$(rollup "$(check_run "dev-lead / dispatch" "IN_PROGRESS")") + run compute_ci_status "$r" + [ "$output" = "passing" ] +} + +@test "'dev-lead / ci-relay' (IN_PROGRESS) is filtered out → passing" { + local r + r=$(rollup "$(check_run "dev-lead / ci-relay" "IN_PROGRESS")") + run compute_ci_status "$r" + [ "$output" = "passing" ] +} + +# --------------------------------------------------------------------------- +# Own check failing form is also filtered +# --------------------------------------------------------------------------- + +@test "own check named 'review' (COMPLETED/FAILURE) is filtered out → passing" { + local r + r=$(rollup "$(check_run "review" "COMPLETED" "FAILURE")") + run compute_ci_status "$r" + [ "$output" = "passing" ] +} + +@test "'PR Review Agent / review' (COMPLETED/FAILURE) is filtered out → passing" { + local r + r=$(rollup "$(check_run "PR Review Agent / review" "COMPLETED" "FAILURE")") + run compute_ci_status "$r" + [ "$output" = "passing" ] +} + +# --------------------------------------------------------------------------- +# Mix: own pending + external passing → passing (own check filtered) +# --------------------------------------------------------------------------- + +@test "mix: own 'review' pending + external passing → passing" { + local r + r=$(rollup \ + "$(check_run "review" "IN_PROGRESS")" \ + "$(check_run "Lint" "COMPLETED" "SUCCESS")") + run compute_ci_status "$r" + [ "$output" = "passing" ] +} + +@test "mix: own 'dispatch' pending + external passing → passing" { + local r + r=$(rollup \ + "$(check_run "dispatch" "IN_PROGRESS")" \ + "$(check_run "Build" "COMPLETED" "SUCCESS")") + run compute_ci_status "$r" + [ "$output" = "passing" ] +} + +@test "mix: own 'PR Review Agent / review' pending + external passing → passing" { + local r + r=$(rollup \ + "$(check_run "PR Review Agent / review" "IN_PROGRESS")" \ + "$(check_run "CI / build" "COMPLETED" "SUCCESS")") + run compute_ci_status "$r" + [ "$output" = "passing" ] +} + +# --------------------------------------------------------------------------- +# Mix: own pending + external pending → pending (external still blocks) +# --------------------------------------------------------------------------- + +@test "mix: own 'review' pending + external pending → pending" { + local r + r=$(rollup \ + "$(check_run "review" "IN_PROGRESS")" \ + "$(check_run "Build" "IN_PROGRESS")") + run compute_ci_status "$r" + [ "$output" = "pending" ] +} + +# --------------------------------------------------------------------------- +# Mix: own pending + external failing → failing (external still fails) +# --------------------------------------------------------------------------- + +@test "mix: own 'review' pending + external failing → failing" { + local r + r=$(rollup \ + "$(check_run "review" "IN_PROGRESS")" \ + "$(check_run "Test" "COMPLETED" "FAILURE")") + run compute_ci_status "$r" + [ "$output" = "failing" ] +} + +# --------------------------------------------------------------------------- +# All own checks only → passing (rollup effectively empty after filter) +# --------------------------------------------------------------------------- + +@test "rollup with only own checks returns passing" { + local r + r=$(rollup \ + "$(check_run "review" "IN_PROGRESS")" \ + "$(check_run "dispatch" "IN_PROGRESS")" \ + "$(check_run "ci-relay" "IN_PROGRESS")") + run compute_ci_status "$r" + [ "$output" = "passing" ] +} + +@test "rollup with only own workflow/job form checks returns passing" { + local r + r=$(rollup \ + "$(check_run "PR Review Agent / review" "IN_PROGRESS")" \ + "$(check_run "dev-lead / dispatch" "IN_PROGRESS")" \ + "$(check_run "PR Review — Mention Trigger / pr-review-mention" "IN_PROGRESS")") + run compute_ci_status "$r" + [ "$output" = "passing" ] +} + +# --------------------------------------------------------------------------- +# StatusContext checks are unaffected by the own-check filter +# --------------------------------------------------------------------------- + +@test "status context with PENDING state still causes pending classification" { + local r + r=$(rollup "$(status_ctx "sonarcloud" "PENDING")") + run compute_ci_status "$r" + [ "$output" = "pending" ] +} + +@test "status context with FAILURE state still causes failing classification" { + local r + r=$(rollup "$(status_ctx "sonarcloud" "FAILURE")") + run compute_ci_status "$r" + [ "$output" = "failing" ] +} + +@test "status context named 'review' with PENDING state still causes pending (context != name)" { + # StatusContext uses .context field; own-check filter checks .name // .context. + # A status check coincidentally named 'review' SHOULD be filtered (could be ambiguous), + # but an external status check named something else should not be affected. + local r + r=$(rollup "$(status_ctx "external-ci" "PENDING")") + run compute_ci_status "$r" + [ "$output" = "pending" ] +} + +# --------------------------------------------------------------------------- +# Malformed / edge input +# --------------------------------------------------------------------------- + +@test "malformed JSON input returns passing (safe default)" { + run compute_ci_status "not-json" + [ "$status" -eq 0 ] + [ "$output" = "passing" ] +} + +@test "null JSON input returns passing (safe default)" { + run compute_ci_status "null" + [ "$output" = "passing" ] +} From b87f198189cd60ff0c36ccecc9a4f5c42a57e489 Mon Sep 17 00:00:00 2001 From: donpetry-bot <281750570+donpetry-bot@users.noreply.github.com> Date: Mon, 8 Jun 2026 00:27:37 +0000 Subject: [PATCH 2/5] chore: apply manual instructions [skip ci-relay] --- scripts/lib/ci-status.sh | 4 ++-- scripts/review-one-pr.sh | 44 ++++++++++++++++++++++++++++----------- tests/test_ci_status.bats | 7 +++---- 3 files changed, 37 insertions(+), 18 deletions(-) diff --git a/scripts/lib/ci-status.sh b/scripts/lib/ci-status.sh index f41223bf6..825d41308 100644 --- a/scripts/lib/ci-status.sh +++ b/scripts/lib/ci-status.sh @@ -27,7 +27,7 @@ # covers both GitHub Actions checks and legacy commit statuses. compute_ci_status() { local rollup_json="${1:-[]}" - echo "$rollup_json" | jq -r ' + jq -r ' def is_pending: .status == "IN_PROGRESS" or .status == "QUEUED" or .status == "WAITING" or .state == "PENDING" or .state == "EXPECTED" or @@ -51,5 +51,5 @@ compute_ci_status() { else "failing" end end - ' 2>/dev/null || echo "passing" + ' <<< "$rollup_json" 2>/dev/null || echo "passing" } diff --git a/scripts/review-one-pr.sh b/scripts/review-one-pr.sh index 65ed4a50c..b15d340f9 100644 --- a/scripts/review-one-pr.sh +++ b/scripts/review-one-pr.sh @@ -51,7 +51,7 @@ PR_HEAD_SHA=$(echo "$PR_SNAPSHOT" | jq -r '.headRefOid') export PR_HEAD_SHA echo " head SHA: $PR_HEAD_SHA" -CI_STATUS=$(compute_ci_status "$(echo "$PR_SNAPSHOT" | jq '.statusCheckRollup')") +CI_STATUS=$(compute_ci_status "$(jq '.statusCheckRollup' <<< "$PR_SNAPSHOT")") echo " CI status: $CI_STATUS" REVIEW_DECISION=$(echo "$PR_SNAPSHOT" | jq -r '.reviewDecision // ""') @@ -74,18 +74,40 @@ if [ "$CI_STATUS" = "pending" ]; then if [ "${FORCE_REVIEW:-false}" = "true" ]; then _FORCE_POLL_MAX="${FORCE_REVIEW_POLL_ATTEMPTS:-10}" _FORCE_POLL_SEC="${FORCE_REVIEW_POLL_INTERVAL_SEC:-30}" + # Validate that the env-var overrides are positive integers; fall back to + # the defaults if they are not so that sleep and the numeric test don't fail. + case "$_FORCE_POLL_MAX" in + ''|*[!0-9]*) _FORCE_POLL_MAX=10 ;; + esac + case "$_FORCE_POLL_SEC" in + ''|*[!0-9]*) _FORCE_POLL_SEC=30 ;; + esac + [ "$_FORCE_POLL_MAX" -gt 0 ] || _FORCE_POLL_MAX=10 + [ "$_FORCE_POLL_SEC" -gt 0 ] || _FORCE_POLL_SEC=30 _poll=1 while [ "$_poll" -le "$_FORCE_POLL_MAX" ] && [ "$CI_STATUS" = "pending" ]; do echo " force-review: CI pending, waiting ${_FORCE_POLL_SEC}s for checks to settle (attempt ${_poll}/${_FORCE_POLL_MAX})" sleep "$_FORCE_POLL_SEC" - PR_SNAPSHOT=$(gh pr view "$PR_URL" --json headRefOid,statusCheckRollup,reviewDecision,reviews,labels,comments) - PR_HEAD_SHA=$(echo "$PR_SNAPSHOT" | jq -r '.headRefOid') + _gh_poll_err=$(mktemp 2>/dev/null || echo "/tmp/cascade/gh-poll-$$.err") + if ! PR_SNAPSHOT=$(gh pr view "$PR_URL" --json headRefOid,statusCheckRollup,reviewDecision,reviews,labels,comments 2>"$_gh_poll_err"); then + _gh_poll_err_content=$(cat "$_gh_poll_err" 2>/dev/null || true) + rm -f "$_gh_poll_err" + if is_rate_limited "$_gh_poll_err_content"; then + echo " gh API rate limited during polling — skipping PR" + echo "{\"pr\":\"$PR_URL\",\"sha\":\"$PR_HEAD_SHA\",\"decision\":\"skip\",\"reason\":\"gh-rate-limited\"}" + exit 100 + fi + echo "::error::gh pr view failed during polling for $PR_URL" + exit 1 + fi + rm -f "$_gh_poll_err" + PR_HEAD_SHA=$(jq -r '.headRefOid' <<< "$PR_SNAPSHOT") export PR_HEAD_SHA - CI_STATUS=$(compute_ci_status "$(echo "$PR_SNAPSHOT" | jq '.statusCheckRollup')") + CI_STATUS=$(compute_ci_status "$(jq '.statusCheckRollup' <<< "$PR_SNAPSHOT")") echo " CI status (poll ${_poll}): $CI_STATUS" _poll=$((_poll + 1)) done - unset _poll _FORCE_POLL_MAX _FORCE_POLL_SEC + unset _poll _FORCE_POLL_MAX _FORCE_POLL_SEC _gh_poll_err _gh_poll_err_content if [ "$CI_STATUS" = "failing" ]; then echo " skip: CI checks are failing (detected after polling) — will re-evaluate after fixes are pushed" @@ -96,19 +118,17 @@ if [ "$CI_STATUS" = "pending" ]; then if [ "$CI_STATUS" = "pending" ]; then echo " force-review: CI still pending after polling — posting visible comment" if [ "${DRY_RUN:-false}" != "true" ]; then - _ci_ack_body="/tmp/cascade/ci-pending-ack.txt" - mkdir -p /tmp/cascade - printf '\n\nCI checks on this PR are still running. Once they complete, re-mention `@%s` to trigger a fresh review.\n\n_Posted by the %s PR-review cascade._\n' \ - "${BOT_USER:-donpetry-bot}" "${BOT_USER:-donpetry-bot}" > "$_ci_ack_body" - gh pr comment "$PR_URL" --body-file "$_ci_ack_body" || echo " warn: could not post ci-pending-ack comment" - rm -f "$_ci_ack_body" + _msg=$(printf '\n\nCI checks on this PR are still running. Once they complete, re-mention `@%s` to trigger a fresh review.\n\n_Posted by the %s PR-review cascade._' \ + "${BOT_USER:-donpetry-bot}" "${BOT_USER:-donpetry-bot}") + gh pr comment "$PR_URL" --body "$_msg" || echo " warn: could not post ci-pending-ack comment" + unset _msg fi echo "{\"pr\":\"$PR_URL\",\"sha\":\"$PR_HEAD_SHA\",\"decision\":\"skip\",\"reason\":\"ci-pending-after-poll\"}" exit 100 fi # CI settled — update REVIEW_DECISION from the refreshed snapshot - REVIEW_DECISION=$(echo "$PR_SNAPSHOT" | jq -r '.reviewDecision // ""') + REVIEW_DECISION=$(jq -r '.reviewDecision // ""' <<< "$PR_SNAPSHOT") echo " review decision (after CI poll): $REVIEW_DECISION" else echo " skip: CI checks still in progress — will re-evaluate when checks complete" diff --git a/tests/test_ci_status.bats b/tests/test_ci_status.bats index a7362af58..92373d3ca 100644 --- a/tests/test_ci_status.bats +++ b/tests/test_ci_status.bats @@ -289,10 +289,9 @@ rollup() { [ "$output" = "failing" ] } -@test "status context named 'review' with PENDING state still causes pending (context != name)" { - # StatusContext uses .context field; own-check filter checks .name // .context. - # A status check coincidentally named 'review' SHOULD be filtered (could be ambiguous), - # but an external status check named something else should not be affected. +@test "external status context (not named 'review') with PENDING state still causes pending" { + # Own-check filter checks .name // .context — a StatusContext whose .context + # does not match any own-check pattern must still block as pending. local r r=$(rollup "$(status_ctx "external-ci" "PENDING")") run compute_ci_status "$r" From 3f7e954d5a47df86845ca750d0b913df45a83706 Mon Sep 17 00:00:00 2001 From: donpetry-bot <281750570+donpetry-bot@users.noreply.github.com> Date: Mon, 8 Jun 2026 00:43:01 +0000 Subject: [PATCH 3/5] chore: apply manual instructions [skip ci-relay] --- scripts/lib/ci-status.sh | 25 ++++---- tests/test_ci_status.bats | 120 +++++++++++++++++++++++--------------- 2 files changed, 87 insertions(+), 58 deletions(-) diff --git a/scripts/lib/ci-status.sh b/scripts/lib/ci-status.sh index 825d41308..57e9c0518 100644 --- a/scripts/lib/ci-status.sh +++ b/scripts/lib/ci-status.sh @@ -18,13 +18,19 @@ # COMPLETED with null/empty conclusion # failing — anything else (FAILURE, ACTION_REQUIRED, TIMED_OUT, etc.) # -# Own-check filter — excludes entries whose name matches any of: -# • exact job-name forms: review, dispatch, ci-relay, pr-review-mention, mention-ack -# • workflow/job forms: "* / review", "* / dispatch", "* / ci-relay", etc. -# • known workflow prefixes: "PR Review Agent / *", "PR Review Reusable / *", -# "PR Review — Mention Trigger / *" -# The filter uses both .name (CheckRun) and .context (StatusContext) so it -# covers both GitHub Actions checks and legacy commit statuses. +# Own-check filter — excludes entries whose name matches a known PR Review +# workflow prefix only. Bare job names (review, dispatch, ci-relay, etc.) +# are intentionally NOT matched: a target repo may have CI jobs with those +# same names, and filtering them would let a failing or pending real CI gate +# be silently ignored. Dev-lead checks (dev-lead / dispatch, dev-lead / +# ci-relay) are also excluded from filtering because dev-lead can commit +# back to the PR branch; filtering it could cause a review to race an +# in-progress branch-mutating run. +# Matched prefixes (applied to .name for CheckRuns and .context for +# StatusContexts): +# • "PR Review Agent / *" +# • "PR Review Reusable / *" +# • "PR Review — Mention Trigger / *" compute_ci_status() { local rollup_json="${1:-[]}" jq -r ' @@ -37,11 +43,8 @@ compute_ci_status() { .state == "SUCCESS"; def is_own_check: (.name // .context // "") as $n | - ($n | test("^(review|dispatch|ci-relay|pr-review-mention|mention-ack)$")) or - ($n | test("/ (review|dispatch|ci-relay|pr-review-mention|mention-ack)$")) or ($n | test("^PR Review (Agent|Reusable) /")) or - ($n | test("^PR Review — Mention Trigger /")) or - ($n | test("^dev-lead / (dispatch|ci-relay)$")); + ($n | test("^PR Review — Mention Trigger /")); if (. == null or (type != "array")) then "passing" else (map(select(is_own_check | not))) as $ext | diff --git a/tests/test_ci_status.bats b/tests/test_ci_status.bats index 92373d3ca..6dce9981c 100644 --- a/tests/test_ci_status.bats +++ b/tests/test_ci_status.bats @@ -95,46 +95,48 @@ rollup() { } # --------------------------------------------------------------------------- -# Own check runs filtered — exact job-name form +# Bare job-name checks — treated as external (NOT filtered by is_own_check) +# A target repo may have CI jobs with these names; filtering them would hide +# real CI failures. Only workflow-prefixed PR Review checks are filtered. # --------------------------------------------------------------------------- -@test "own check named 'review' (IN_PROGRESS) is filtered out → passing" { +@test "bare check named 'review' (IN_PROGRESS) is NOT filtered → pending" { local r r=$(rollup "$(check_run "review" "IN_PROGRESS")") run compute_ci_status "$r" - [ "$output" = "passing" ] + [ "$output" = "pending" ] } -@test "own check named 'dispatch' (IN_PROGRESS) is filtered out → passing" { +@test "bare check named 'dispatch' (IN_PROGRESS) is NOT filtered → pending" { local r r=$(rollup "$(check_run "dispatch" "IN_PROGRESS")") run compute_ci_status "$r" - [ "$output" = "passing" ] + [ "$output" = "pending" ] } -@test "own check named 'ci-relay' (IN_PROGRESS) is filtered out → passing" { +@test "bare check named 'ci-relay' (IN_PROGRESS) is NOT filtered → pending" { local r r=$(rollup "$(check_run "ci-relay" "IN_PROGRESS")") run compute_ci_status "$r" - [ "$output" = "passing" ] + [ "$output" = "pending" ] } -@test "own check named 'pr-review-mention' (IN_PROGRESS) is filtered out → passing" { +@test "bare check named 'pr-review-mention' (IN_PROGRESS) is NOT filtered → pending" { local r r=$(rollup "$(check_run "pr-review-mention" "IN_PROGRESS")") run compute_ci_status "$r" - [ "$output" = "passing" ] + [ "$output" = "pending" ] } -@test "own check named 'mention-ack' (IN_PROGRESS) is filtered out → passing" { +@test "bare check named 'mention-ack' (IN_PROGRESS) is NOT filtered → pending" { local r r=$(rollup "$(check_run "mention-ack" "IN_PROGRESS")") run compute_ci_status "$r" - [ "$output" = "passing" ] + [ "$output" = "pending" ] } # --------------------------------------------------------------------------- -# Own check runs filtered — workflow / job-name form +# Known PR Review workflow checks ARE filtered — workflow / job-name form # --------------------------------------------------------------------------- @test "'PR Review Agent / review' (IN_PROGRESS) is filtered out → passing" { @@ -158,29 +160,43 @@ rollup() { [ "$output" = "passing" ] } -@test "'dev-lead / dispatch' (IN_PROGRESS) is filtered out → passing" { +# --------------------------------------------------------------------------- +# Dev-lead and generic workflow/job-suffix checks are NOT filtered +# Dev-lead can commit back to the PR branch, so it must remain a real CI gate. +# A generic 'workflow / review' suffix (e.g., 'Build / review') must also block +# so external required checks are never silently bypassed. +# --------------------------------------------------------------------------- + +@test "'dev-lead / dispatch' (IN_PROGRESS) is NOT filtered → pending" { local r r=$(rollup "$(check_run "dev-lead / dispatch" "IN_PROGRESS")") run compute_ci_status "$r" - [ "$output" = "passing" ] + [ "$output" = "pending" ] } -@test "'dev-lead / ci-relay' (IN_PROGRESS) is filtered out → passing" { +@test "'dev-lead / ci-relay' (IN_PROGRESS) is NOT filtered → pending" { local r r=$(rollup "$(check_run "dev-lead / ci-relay" "IN_PROGRESS")") run compute_ci_status "$r" - [ "$output" = "passing" ] + [ "$output" = "pending" ] +} + +@test "'Build / review' (IN_PROGRESS) is NOT filtered → pending" { + local r + r=$(rollup "$(check_run "Build / review" "IN_PROGRESS")") + run compute_ci_status "$r" + [ "$output" = "pending" ] } # --------------------------------------------------------------------------- -# Own check failing form is also filtered +# Failure classification: PR Review workflow checks filtered; bare names not # --------------------------------------------------------------------------- -@test "own check named 'review' (COMPLETED/FAILURE) is filtered out → passing" { +@test "bare check named 'review' (COMPLETED/FAILURE) is NOT filtered → failing" { local r r=$(rollup "$(check_run "review" "COMPLETED" "FAILURE")") run compute_ci_status "$r" - [ "$output" = "passing" ] + [ "$output" = "failing" ] } @test "'PR Review Agent / review' (COMPLETED/FAILURE) is filtered out → passing" { @@ -191,41 +207,45 @@ rollup() { } # --------------------------------------------------------------------------- -# Mix: own pending + external passing → passing (own check filtered) +# Mix: PR Review workflow pending + external passing → passing (filtered) # --------------------------------------------------------------------------- -@test "mix: own 'review' pending + external passing → passing" { +@test "mix: 'PR Review Agent / review' pending + external passing → passing" { local r r=$(rollup \ - "$(check_run "review" "IN_PROGRESS")" \ - "$(check_run "Lint" "COMPLETED" "SUCCESS")") + "$(check_run "PR Review Agent / review" "IN_PROGRESS")" \ + "$(check_run "CI / build" "COMPLETED" "SUCCESS")") run compute_ci_status "$r" [ "$output" = "passing" ] } -@test "mix: own 'dispatch' pending + external passing → passing" { +# --------------------------------------------------------------------------- +# Mix: bare-name pending + external passing → pending (bare names not filtered) +# --------------------------------------------------------------------------- + +@test "mix: bare 'review' pending + external passing → pending" { local r r=$(rollup \ - "$(check_run "dispatch" "IN_PROGRESS")" \ - "$(check_run "Build" "COMPLETED" "SUCCESS")") + "$(check_run "review" "IN_PROGRESS")" \ + "$(check_run "Lint" "COMPLETED" "SUCCESS")") run compute_ci_status "$r" - [ "$output" = "passing" ] + [ "$output" = "pending" ] } -@test "mix: own 'PR Review Agent / review' pending + external passing → passing" { +@test "mix: bare 'dispatch' pending + external passing → pending" { local r r=$(rollup \ - "$(check_run "PR Review Agent / review" "IN_PROGRESS")" \ - "$(check_run "CI / build" "COMPLETED" "SUCCESS")") + "$(check_run "dispatch" "IN_PROGRESS")" \ + "$(check_run "Build" "COMPLETED" "SUCCESS")") run compute_ci_status "$r" - [ "$output" = "passing" ] + [ "$output" = "pending" ] } # --------------------------------------------------------------------------- # Mix: own pending + external pending → pending (external still blocks) # --------------------------------------------------------------------------- -@test "mix: own 'review' pending + external pending → pending" { +@test "mix: bare 'review' pending + external pending → pending" { local r r=$(rollup \ "$(check_run "review" "IN_PROGRESS")" \ @@ -238,37 +258,43 @@ rollup() { # Mix: own pending + external failing → failing (external still fails) # --------------------------------------------------------------------------- -@test "mix: own 'review' pending + external failing → failing" { +@test "mix: bare 'review' pending + external failing → pending (pending fires first)" { + # Both 'review' and 'Test' are in $ext. The pending branch fires first + # (before the failure check), so the result is "pending" — once all checks + # finish, a subsequent call will return "failing". local r r=$(rollup \ "$(check_run "review" "IN_PROGRESS")" \ "$(check_run "Test" "COMPLETED" "FAILURE")") run compute_ci_status "$r" - [ "$output" = "failing" ] + [ "$output" = "pending" ] } # --------------------------------------------------------------------------- -# All own checks only → passing (rollup effectively empty after filter) +# Rollup with only PR Review workflow checks → passing (all filtered) # --------------------------------------------------------------------------- -@test "rollup with only own checks returns passing" { +@test "rollup with only PR Review workflow/job form checks returns passing" { local r r=$(rollup \ - "$(check_run "review" "IN_PROGRESS")" \ - "$(check_run "dispatch" "IN_PROGRESS")" \ - "$(check_run "ci-relay" "IN_PROGRESS")") + "$(check_run "PR Review Agent / review" "IN_PROGRESS")" \ + "$(check_run "PR Review — Mention Trigger / pr-review-mention" "IN_PROGRESS")") run compute_ci_status "$r" [ "$output" = "passing" ] } -@test "rollup with only own workflow/job form checks returns passing" { +# --------------------------------------------------------------------------- +# Rollup with only bare own-check names → pending (not filtered) +# --------------------------------------------------------------------------- + +@test "rollup with only bare own-check names returns pending (not filtered)" { local r r=$(rollup \ - "$(check_run "PR Review Agent / review" "IN_PROGRESS")" \ - "$(check_run "dev-lead / dispatch" "IN_PROGRESS")" \ - "$(check_run "PR Review — Mention Trigger / pr-review-mention" "IN_PROGRESS")") + "$(check_run "review" "IN_PROGRESS")" \ + "$(check_run "dispatch" "IN_PROGRESS")" \ + "$(check_run "ci-relay" "IN_PROGRESS")") run compute_ci_status "$r" - [ "$output" = "passing" ] + [ "$output" = "pending" ] } # --------------------------------------------------------------------------- @@ -289,9 +315,9 @@ rollup() { [ "$output" = "failing" ] } -@test "external status context (not named 'review') with PENDING state still causes pending" { - # Own-check filter checks .name // .context — a StatusContext whose .context - # does not match any own-check pattern must still block as pending. +@test "status context named 'external-ci' (non-own-check) with PENDING state still causes pending" { + # StatusContext entries that do not match any own-check prefix must still block + # as pending — verifies the filter doesn't accidentally swallow external statuses. local r r=$(rollup "$(status_ctx "external-ci" "PENDING")") run compute_ci_status "$r" From 6932d103dad15d24857d3177b9804f2edddf23b0 Mon Sep 17 00:00:00 2001 From: donpetry-bot <281750570+donpetry-bot@users.noreply.github.com> Date: Mon, 8 Jun 2026 05:09:04 +0000 Subject: [PATCH 4/5] fix(reviews): address review comments [skip ci-relay] --- scripts/lib/ci-status.sh | 23 +++++++++------- tests/test_ci_status.bats | 57 ++++++++++++++++++++------------------- 2 files changed, 42 insertions(+), 38 deletions(-) diff --git a/scripts/lib/ci-status.sh b/scripts/lib/ci-status.sh index 57e9c0518..0225a5caf 100644 --- a/scripts/lib/ci-status.sh +++ b/scripts/lib/ci-status.sh @@ -18,16 +18,18 @@ # COMPLETED with null/empty conclusion # failing — anything else (FAILURE, ACTION_REQUIRED, TIMED_OUT, etc.) # -# Own-check filter — excludes entries whose name matches a known PR Review -# workflow prefix only. Bare job names (review, dispatch, ci-relay, etc.) -# are intentionally NOT matched: a target repo may have CI jobs with those -# same names, and filtering them would let a failing or pending real CI gate -# be silently ignored. Dev-lead checks (dev-lead / dispatch, dev-lead / -# ci-relay) are also excluded from filtering because dev-lead can commit -# back to the PR branch; filtering it could cause a review to race an -# in-progress branch-mutating run. -# Matched prefixes (applied to .name for CheckRuns and .context for -# StatusContexts): +# Own-check filter — excludes entries belonging to the PR Review cascade. +# `gh pr view --json statusCheckRollup` exposes the check/job *name* but not +# the workflow name (gh/cli#9091), so the PR Review Agent's Actions jobs appear +# with their bare job names in the rollup: "review", "dispatch", "ci-relay". +# These are matched explicitly to prevent the cascade from blocking on its own +# pending check runs. Compound "workflow / job" forms are also matched for +# reusable-workflow callers where that format does appear. +# Dev-lead checks (dev-lead / dispatch, dev-lead / ci-relay) are NOT filtered +# because dev-lead can commit back to the PR branch; filtering it could cause +# a review to race an in-progress branch-mutating run. +# Matched: +# • Bare job names: "review", "dispatch", "ci-relay" # • "PR Review Agent / *" # • "PR Review Reusable / *" # • "PR Review — Mention Trigger / *" @@ -43,6 +45,7 @@ compute_ci_status() { .state == "SUCCESS"; def is_own_check: (.name // .context // "") as $n | + ($n == "review" or $n == "dispatch" or $n == "ci-relay") or ($n | test("^PR Review (Agent|Reusable) /")) or ($n | test("^PR Review — Mention Trigger /")); if (. == null or (type != "array")) then "passing" diff --git a/tests/test_ci_status.bats b/tests/test_ci_status.bats index 6dce9981c..ef0805168 100644 --- a/tests/test_ci_status.bats +++ b/tests/test_ci_status.bats @@ -95,30 +95,33 @@ rollup() { } # --------------------------------------------------------------------------- -# Bare job-name checks — treated as external (NOT filtered by is_own_check) -# A target repo may have CI jobs with these names; filtering them would hide -# real CI failures. Only workflow-prefixed PR Review checks are filtered. +# PR Review Agent bare job names ARE filtered (actual rollup shape) +# `gh pr view --json statusCheckRollup` exposes the job name only (not the +# workflow name, per gh/cli#9091), so the agent's own checks appear as bare +# names: "review", "dispatch", "ci-relay". These are filtered to prevent +# the cascade from blocking on its own pending check runs. +# Other bare names that are not PR Review Agent job names remain external. # --------------------------------------------------------------------------- -@test "bare check named 'review' (IN_PROGRESS) is NOT filtered → pending" { +@test "bare PR Review Agent check 'review' (IN_PROGRESS) is filtered → passing" { local r r=$(rollup "$(check_run "review" "IN_PROGRESS")") run compute_ci_status "$r" - [ "$output" = "pending" ] + [ "$output" = "passing" ] } -@test "bare check named 'dispatch' (IN_PROGRESS) is NOT filtered → pending" { +@test "bare PR Review Agent check 'dispatch' (IN_PROGRESS) is filtered → passing" { local r r=$(rollup "$(check_run "dispatch" "IN_PROGRESS")") run compute_ci_status "$r" - [ "$output" = "pending" ] + [ "$output" = "passing" ] } -@test "bare check named 'ci-relay' (IN_PROGRESS) is NOT filtered → pending" { +@test "bare PR Review Agent check 'ci-relay' (IN_PROGRESS) is filtered → passing" { local r r=$(rollup "$(check_run "ci-relay" "IN_PROGRESS")") run compute_ci_status "$r" - [ "$output" = "pending" ] + [ "$output" = "passing" ] } @test "bare check named 'pr-review-mention' (IN_PROGRESS) is NOT filtered → pending" { @@ -189,14 +192,14 @@ rollup() { } # --------------------------------------------------------------------------- -# Failure classification: PR Review workflow checks filtered; bare names not +# Failure classification: PR Review checks (bare and compound) are filtered # --------------------------------------------------------------------------- -@test "bare check named 'review' (COMPLETED/FAILURE) is NOT filtered → failing" { +@test "bare PR Review Agent check 'review' (COMPLETED/FAILURE) is filtered → passing" { local r r=$(rollup "$(check_run "review" "COMPLETED" "FAILURE")") run compute_ci_status "$r" - [ "$output" = "failing" ] + [ "$output" = "passing" ] } @test "'PR Review Agent / review' (COMPLETED/FAILURE) is filtered out → passing" { @@ -220,32 +223,32 @@ rollup() { } # --------------------------------------------------------------------------- -# Mix: bare-name pending + external passing → pending (bare names not filtered) +# Mix: bare PR Review Agent checks filtered; external result determines status # --------------------------------------------------------------------------- -@test "mix: bare 'review' pending + external passing → pending" { +@test "mix: bare 'review' filtered + external passing → passing" { local r r=$(rollup \ "$(check_run "review" "IN_PROGRESS")" \ "$(check_run "Lint" "COMPLETED" "SUCCESS")") run compute_ci_status "$r" - [ "$output" = "pending" ] + [ "$output" = "passing" ] } -@test "mix: bare 'dispatch' pending + external passing → pending" { +@test "mix: bare 'dispatch' filtered + external passing → passing" { local r r=$(rollup \ "$(check_run "dispatch" "IN_PROGRESS")" \ "$(check_run "Build" "COMPLETED" "SUCCESS")") run compute_ci_status "$r" - [ "$output" = "pending" ] + [ "$output" = "passing" ] } # --------------------------------------------------------------------------- -# Mix: own pending + external pending → pending (external still blocks) +# Mix: bare PR Review Agent check filtered + external pending → pending # --------------------------------------------------------------------------- -@test "mix: bare 'review' pending + external pending → pending" { +@test "mix: bare 'review' filtered + external pending → pending" { local r r=$(rollup \ "$(check_run "review" "IN_PROGRESS")" \ @@ -255,19 +258,17 @@ rollup() { } # --------------------------------------------------------------------------- -# Mix: own pending + external failing → failing (external still fails) +# Mix: bare PR Review Agent check filtered + external failing → failing # --------------------------------------------------------------------------- -@test "mix: bare 'review' pending + external failing → pending (pending fires first)" { - # Both 'review' and 'Test' are in $ext. The pending branch fires first - # (before the failure check), so the result is "pending" — once all checks - # finish, a subsequent call will return "failing". +@test "mix: bare 'review' filtered + external failing → failing" { + # 'review' is filtered out; only 'Test' (COMPLETED/FAILURE) remains in $ext. local r r=$(rollup \ "$(check_run "review" "IN_PROGRESS")" \ "$(check_run "Test" "COMPLETED" "FAILURE")") run compute_ci_status "$r" - [ "$output" = "pending" ] + [ "$output" = "failing" ] } # --------------------------------------------------------------------------- @@ -284,17 +285,17 @@ rollup() { } # --------------------------------------------------------------------------- -# Rollup with only bare own-check names → pending (not filtered) +# Rollup with only PR Review Agent bare job names → passing (all filtered) # --------------------------------------------------------------------------- -@test "rollup with only bare own-check names returns pending (not filtered)" { +@test "rollup with only PR Review Agent bare job names returns passing (all filtered)" { local r r=$(rollup \ "$(check_run "review" "IN_PROGRESS")" \ "$(check_run "dispatch" "IN_PROGRESS")" \ "$(check_run "ci-relay" "IN_PROGRESS")") run compute_ci_status "$r" - [ "$output" = "pending" ] + [ "$output" = "passing" ] } # --------------------------------------------------------------------------- From c17345ad638dd8fc5ee8d6b86074d10bafad422b Mon Sep 17 00:00:00 2001 From: donpetry-bot <281750570+donpetry-bot@users.noreply.github.com> Date: Mon, 8 Jun 2026 05:19:11 +0000 Subject: [PATCH 5/5] fix(reviews): address review comments [skip ci-relay] --- scripts/lib/ci-status.sh | 18 +++++++++--------- tests/test_ci_status.bats | 27 ++++++++++++++------------- 2 files changed, 23 insertions(+), 22 deletions(-) diff --git a/scripts/lib/ci-status.sh b/scripts/lib/ci-status.sh index 0225a5caf..e940edffe 100644 --- a/scripts/lib/ci-status.sh +++ b/scripts/lib/ci-status.sh @@ -20,16 +20,16 @@ # # Own-check filter — excludes entries belonging to the PR Review cascade. # `gh pr view --json statusCheckRollup` exposes the check/job *name* but not -# the workflow name (gh/cli#9091), so the PR Review Agent's Actions jobs appear -# with their bare job names in the rollup: "review", "dispatch", "ci-relay". -# These are matched explicitly to prevent the cascade from blocking on its own -# pending check runs. Compound "workflow / job" forms are also matched for +# the workflow name (gh/cli#9091), so the PR Review Agent's single job appears +# with its bare job name in the rollup: "review". +# This is matched explicitly to prevent the cascade from blocking on its own +# pending check run. Compound "workflow / job" forms are also matched for # reusable-workflow callers where that format does appear. -# Dev-lead checks (dev-lead / dispatch, dev-lead / ci-relay) are NOT filtered -# because dev-lead can commit back to the PR branch; filtering it could cause -# a review to race an in-progress branch-mutating run. +# Dev-Lead bare checks ("dispatch", "ci-relay") are NOT filtered because +# Dev-Lead can commit back to the PR branch; filtering them could cause a review +# to race an in-progress branch-mutating run. # Matched: -# • Bare job names: "review", "dispatch", "ci-relay" +# • Bare job name: "review" # • "PR Review Agent / *" # • "PR Review Reusable / *" # • "PR Review — Mention Trigger / *" @@ -45,7 +45,7 @@ compute_ci_status() { .state == "SUCCESS"; def is_own_check: (.name // .context // "") as $n | - ($n == "review" or $n == "dispatch" or $n == "ci-relay") or + ($n == "review") or ($n | test("^PR Review (Agent|Reusable) /")) or ($n | test("^PR Review — Mention Trigger /")); if (. == null or (type != "array")) then "passing" diff --git a/tests/test_ci_status.bats b/tests/test_ci_status.bats index ef0805168..db7cdf871 100644 --- a/tests/test_ci_status.bats +++ b/tests/test_ci_status.bats @@ -95,12 +95,13 @@ rollup() { } # --------------------------------------------------------------------------- -# PR Review Agent bare job names ARE filtered (actual rollup shape) +# PR Review Agent bare job name IS filtered (actual rollup shape) # `gh pr view --json statusCheckRollup` exposes the job name only (not the -# workflow name, per gh/cli#9091), so the agent's own checks appear as bare -# names: "review", "dispatch", "ci-relay". These are filtered to prevent -# the cascade from blocking on its own pending check runs. -# Other bare names that are not PR Review Agent job names remain external. +# workflow name, per gh/cli#9091), so the PR Review Agent's own job appears as +# a bare name: "review". This is filtered to prevent the cascade from blocking +# on its own pending check run. +# Dev-Lead bare job names ("dispatch", "ci-relay") are NOT filtered because +# Dev-Lead can commit back to the PR branch. # --------------------------------------------------------------------------- @test "bare PR Review Agent check 'review' (IN_PROGRESS) is filtered → passing" { @@ -110,18 +111,18 @@ rollup() { [ "$output" = "passing" ] } -@test "bare PR Review Agent check 'dispatch' (IN_PROGRESS) is filtered → passing" { +@test "bare Dev-Lead check 'dispatch' (IN_PROGRESS) is NOT filtered → pending" { local r r=$(rollup "$(check_run "dispatch" "IN_PROGRESS")") run compute_ci_status "$r" - [ "$output" = "passing" ] + [ "$output" = "pending" ] } -@test "bare PR Review Agent check 'ci-relay' (IN_PROGRESS) is filtered → passing" { +@test "bare Dev-Lead check 'ci-relay' (IN_PROGRESS) is NOT filtered → pending" { local r r=$(rollup "$(check_run "ci-relay" "IN_PROGRESS")") run compute_ci_status "$r" - [ "$output" = "passing" ] + [ "$output" = "pending" ] } @test "bare check named 'pr-review-mention' (IN_PROGRESS) is NOT filtered → pending" { @@ -235,13 +236,13 @@ rollup() { [ "$output" = "passing" ] } -@test "mix: bare 'dispatch' filtered + external passing → passing" { +@test "mix: bare 'dispatch' NOT filtered + external passing → pending" { local r r=$(rollup \ "$(check_run "dispatch" "IN_PROGRESS")" \ "$(check_run "Build" "COMPLETED" "SUCCESS")") run compute_ci_status "$r" - [ "$output" = "passing" ] + [ "$output" = "pending" ] } # --------------------------------------------------------------------------- @@ -288,14 +289,14 @@ rollup() { # Rollup with only PR Review Agent bare job names → passing (all filtered) # --------------------------------------------------------------------------- -@test "rollup with only PR Review Agent bare job names returns passing (all filtered)" { +@test "rollup: 'review' filtered, Dev-Lead 'dispatch' + 'ci-relay' NOT filtered → pending" { local r r=$(rollup \ "$(check_run "review" "IN_PROGRESS")" \ "$(check_run "dispatch" "IN_PROGRESS")" \ "$(check_run "ci-relay" "IN_PROGRESS")") run compute_ci_status "$r" - [ "$output" = "passing" ] + [ "$output" = "pending" ] } # ---------------------------------------------------------------------------