Repository navigation
fix: treat Claude quota refusals as non-fatal in PR review health report #2448
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
don-petry
wants to merge
12
commits into
main
Choose a base branch
from
dev-lead/issue-2446-20261103-1632
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
0548cd8
feat: implement issue #2446 — [Fleet Monitor] combsmith/.github-priva…
don-petry 7ae133a
fix(reviews): recognise 'reached your limit' refusals, trap temp-file…
don-petry 6fd8d09
docs: add function docstrings for complexity thresholds
don-petry 70fd673
fix(bot): narrow quota refusal detection to match Claude-specific pat…
don-petry 37b9939
fix: add docstrings to setup() and teardown() in pr_review_health.bats
don-petry 671b894
fix(bot): move docstrings before function definitions to meet coverag…
don-petry d2f1c9e
fix(bot): remove redundant cleanup and use overall variable in LLM pr…
don-petry e0a236a
fix(bot): revert feature-ideation.yml to synced template state
don-petry 08e31b9
fix(bot): use [[ instead of [ for conditional tests in llm_quota_refused
don-petry a8a0ba9
fix(bot): remove out-of-scope feature-ideation.yml changes — defer au…
don-petry 2a78ecd
Merge branch 'main' into dev-lead/issue-2446-20261103-1632
don-petry 9e70a51
Merge branch 'main' into dev-lead/issue-2446-20261103-1632
don-petry File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| #!/usr/bin/env bats | ||
| # Tests for scripts/pr_review_health.sh — how the Claude log-analysis call's | ||
| # failure is handled (#2446). `gh` and `claude` are stubbed on PATH, so no | ||
| # network I/O happens; the stubbed gh returns an empty run window. | ||
| # Run locally: bats tests/pr_review_health.bats | ||
|
|
||
| # Set up test environment: create stubs for gh and claude CLIs. | ||
| setup() { | ||
| SCRIPT="${BATS_TEST_DIRNAME}/../scripts/pr_review_health.sh" | ||
| WORK="$(mktemp -d)" | ||
| STUB_BIN="${WORK}/bin" | ||
| mkdir -p "$STUB_BIN" | ||
|
|
||
| # gh stub: every run list is empty, workflow discovery finds no ingress | ||
| # workflow, and the workflow-source read fails (the script tolerates it). | ||
| cat > "${STUB_BIN}/gh" <<'GH' | ||
| #!/usr/bin/env bash | ||
| case "$*" in | ||
| *"/contents/"*) exit 1 ;; | ||
| *"actions/workflows?per_page"*) exit 0 ;; | ||
| *"created="*) echo '[]' ;; | ||
| *) echo '{}' ;; | ||
| esac | ||
| GH | ||
| chmod +x "${STUB_BIN}/gh" | ||
|
|
||
| export PATH="${STUB_BIN}:${PATH}" | ||
| export GITHUB_ENV="${WORK}/github_env" | ||
| export GITHUB_STEP_SUMMARY="${WORK}/step_summary" | ||
| : > "$GITHUB_ENV" | ||
| : > "$GITHUB_STEP_SUMMARY" | ||
| cd "$WORK" || return 1 | ||
| } | ||
|
|
||
| # Clean up temporary test directories. | ||
| teardown() { | ||
| rm -rf "$WORK" | ||
| } | ||
|
|
||
| # make_claude <exit_code> <stdout_text> [stderr_text] | ||
| make_claude() { | ||
| { | ||
| printf '#!/usr/bin/env bash\ncat >/dev/null\n' | ||
| printf 'printf %%s\\\\n %q\n' "$2" | ||
| [ -n "${3:-}" ] && printf 'printf %%s\\\\n %q >&2\n' "$3" | ||
| printf 'exit %s\n' "$1" | ||
| } > "${STUB_BIN}/claude" | ||
| chmod +x "${STUB_BIN}/claude" | ||
| } | ||
|
|
||
| @test "quota refusal from Claude: warns, keeps the deterministic report, exits 0" { | ||
| make_claude 1 "You've hit your weekly limit · resets 4pm (UTC)" | ||
| run bash "$SCRIPT" | ||
| [ "$status" -eq 0 ] | ||
| [[ "$output" == *"::warning::"*"quota"* ]] | ||
| grep -q '## Convergence latency (deterministic)' pr_review_health_report.md | ||
| grep -q 'Log analysis skipped' pr_review_health_report.md | ||
| # The CLI's refusal line is not pasted into the report as if it were analysis. | ||
| run grep -c "hit your weekly limit" pr_review_health_report.md | ||
| [ "$output" = "0" ] | ||
| grep -q 'Log analysis skipped' "$GITHUB_STEP_SUMMARY" | ||
| } | ||
|
|
||
| @test "quota refusal reported on stderr is also recognised" { | ||
| make_claude 1 "" "API Error: 429 Too Many Requests" | ||
| run bash "$SCRIPT" | ||
| [ "$status" -eq 0 ] | ||
| grep -q 'Log analysis skipped' pr_review_health_report.md | ||
| run grep -c "429 Too Many Requests" pr_review_health_report.md | ||
| [ "$output" = "0" ] | ||
| } | ||
|
|
||
| @test "documented 'reached your weekly limit' wording is recognised" { | ||
| make_claude 1 "You've reached your weekly limit · resets 4pm (UTC)" | ||
| run bash "$SCRIPT" | ||
| [ "$status" -eq 0 ] | ||
| grep -q 'Log analysis skipped' pr_review_health_report.md | ||
| } | ||
|
|
||
| @test "'5-hour limit reached' wording is recognised" { | ||
| make_claude 1 "5-hour limit reached - resets 4pm" | ||
| run bash "$SCRIPT" | ||
| [ "$status" -eq 0 ] | ||
| grep -q 'Log analysis skipped' pr_review_health_report.md | ||
| } | ||
|
|
||
| @test "non-quota Claude failure still fails the step" { | ||
| make_claude 1 "Error: model not found" | ||
| run bash "$SCRIPT" | ||
| [ "$status" -eq 1 ] | ||
| [[ "$output" == *"::error::Claude invocation failed"* ]] | ||
| [[ "$output" == *"Error: model not found"* ]] | ||
| } | ||
|
|
||
| @test "successful Claude call appends the analysis to the report" { | ||
| make_claude 0 "### 1. Executive Summary" | ||
| run bash "$SCRIPT" | ||
| [ "$status" -eq 0 ] | ||
| grep -q '## Convergence latency (deterministic)' pr_review_health_report.md | ||
| grep -q '### 1. Executive Summary' pr_review_health_report.md | ||
| run grep -c 'Log analysis skipped' pr_review_health_report.md | ||
| [ "$output" = "0" ] | ||
| } | ||
|
|
||
| @test "a successful analysis that discusses rate limits is not treated as a refusal" { | ||
| make_claude 0 "| Engine rate limit (Claude or Copilot quota) | 0 | — |" | ||
| run bash "$SCRIPT" | ||
| [ "$status" -eq 0 ] | ||
| grep -q 'Engine rate limit' pr_review_health_report.md | ||
| [[ "$output" != *"::warning::"*"quota"* ]] | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.