From a7575c39d56dc30c81036c50853a982346fd3c14 Mon Sep 17 00:00:00 2001 From: donpetry-bot <281750570+donpetry-bot@users.noreply.github.com> Date: Thu, 21 May 2026 10:18:24 +0000 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20implement=20issue=20#338=20?= =?UTF-8?q?=E2=80=94=20[Fleet=20Monitor]=20petry-projects/.github-private?= =?UTF-8?q?=20=E2=80=94=20dev-lead.yml?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/dev-lead.yml | 36 +++++++-- scripts/dev-lead-fix-issue.sh | 10 ++- tests/dev-lead/unit/test_fix_issue.bats | 99 +++++++++++++++++++++++++ 3 files changed, 137 insertions(+), 8 deletions(-) diff --git a/.github/workflows/dev-lead.yml b/.github/workflows/dev-lead.yml index 546c2b289..85a7a9bd7 100644 --- a/.github/workflows/dev-lead.yml +++ b/.github/workflows/dev-lead.yml @@ -169,7 +169,11 @@ jobs: CHECKS_JSON: ${{ env.INTENT_CHECKS }} REPO: ${{ github.repository }} REVIEW_ENGINE: ${{ env.DEV_LEAD_ENGINE }} - run: bash scripts/dev-lead-fix-ci.sh + run: | + rc=0 + bash scripts/dev-lead-fix-ci.sh || rc=$? + # exit 2 = rate-limited; script already posted a marker — not a workflow failure + [ "$rc" -eq 2 ] && exit 0 || exit "$rc" # ── fix-reviews ─────────────────────────────────────────────────────── - name: Run fix-reviews @@ -179,7 +183,10 @@ jobs: HEAD_SHA: ${{ env.INTENT_HEAD_SHA }} REPO: ${{ github.repository }} REVIEW_ENGINE: ${{ env.DEV_LEAD_ENGINE }} - run: bash scripts/dev-lead-fix-reviews.sh + run: | + rc=0 + bash scripts/dev-lead-fix-reviews.sh || rc=$? + [ "$rc" -eq 2 ] && exit 0 || exit "$rc" # ── fix-bot-comment ─────────────────────────────────────────────────── - name: Run fix-bot-comment @@ -191,7 +198,10 @@ jobs: COMMENT_BODY: ${{ env.INTENT_COMMENT_BODY }} REPO: ${{ github.repository }} REVIEW_ENGINE: ${{ env.DEV_LEAD_ENGINE }} - run: bash scripts/dev-lead-fix-reviews.sh + run: | + rc=0 + bash scripts/dev-lead-fix-reviews.sh || rc=$? + [ "$rc" -eq 2 ] && exit 0 || exit "$rc" # ── human ───────────────────────────────────────────────────────────── - name: Run human @@ -203,7 +213,10 @@ jobs: USER_INSTRUCTION: ${{ env.INTENT_COMMENT_BODY }} REPO: ${{ github.repository }} REVIEW_ENGINE: ${{ env.DEV_LEAD_ENGINE }} - run: bash scripts/dev-lead-fix-reviews.sh + run: | + rc=0 + bash scripts/dev-lead-fix-reviews.sh || rc=$? + [ "$rc" -eq 2 ] && exit 0 || exit "$rc" # ── human-pr ────────────────────────────────────────────────────────── - name: Run human-pr @@ -213,7 +226,10 @@ jobs: HEAD_SHA: ${{ env.INTENT_HEAD_SHA }} REPO: ${{ github.repository }} REVIEW_ENGINE: ${{ env.DEV_LEAD_ENGINE }} - run: bash scripts/dev-lead-fix-reviews.sh + run: | + rc=0 + bash scripts/dev-lead-fix-reviews.sh || rc=$? + [ "$rc" -eq 2 ] && exit 0 || exit "$rc" # ── issue ───────────────────────────────────────────────────────────── - name: Run issue @@ -222,7 +238,10 @@ jobs: ISSUE_NUMBER: ${{ env.INTENT_ISSUE_NUMBER }} REPO: ${{ github.repository }} REVIEW_ENGINE: ${{ env.DEV_LEAD_ENGINE }} - run: bash scripts/dev-lead-fix-issue.sh + run: | + rc=0 + bash scripts/dev-lead-fix-issue.sh || rc=$? + [ "$rc" -eq 2 ] && exit 0 || exit "$rc" # ── rebase ──────────────────────────────────────────────────────────── - name: Run rebase @@ -231,7 +250,10 @@ jobs: PR_NUMBER: ${{ env.INTENT_PR_NUMBER }} REPO: ${{ github.repository }} REVIEW_ENGINE: ${{ env.DEV_LEAD_ENGINE }} - run: bash scripts/dev-lead-fix-reviews.sh + run: | + rc=0 + bash scripts/dev-lead-fix-reviews.sh || rc=$? + [ "$rc" -eq 2 ] && exit 0 || exit "$rc" # ── enable-auto-merge ───────────────────────────────────────────────── # Triggered when a trusted bot approves a PR. Skips engine install and diff --git a/scripts/dev-lead-fix-issue.sh b/scripts/dev-lead-fix-issue.sh index c925a373f..fb42b9287 100755 --- a/scripts/dev-lead-fix-issue.sh +++ b/scripts/dev-lead-fix-issue.sh @@ -70,7 +70,15 @@ main() { local pre_engine_sha pre_engine_sha=$(git rev-parse HEAD) - if ! run_writer_with_fallback "$prompt_file"; then + local engine_rc=0 + run_writer_with_fallback "$prompt_file" || engine_rc=$? + if [ "$engine_rc" -eq 2 ]; then + echo "::warning::All engines rate-limited — cannot implement issue #${ISSUE_NUMBER}; re-apply the label to retry" + gh issue comment "$ISSUE_NUMBER" --repo "$REPO" \ + --body "All engines are currently rate-limited. Please re-apply the \`dev-lead\` label when the rate limit clears to retry." 2>/dev/null || true + rm -f "$prompt_file" + exit 2 + elif [ "$engine_rc" -ne 0 ]; then echo "::error::Engine failed to implement issue #${ISSUE_NUMBER}" rm -f "$prompt_file" exit 1 diff --git a/tests/dev-lead/unit/test_fix_issue.bats b/tests/dev-lead/unit/test_fix_issue.bats index 5181d32c2..e88727cb3 100644 --- a/tests/dev-lead/unit/test_fix_issue.bats +++ b/tests/dev-lead/unit/test_fix_issue.bats @@ -144,3 +144,102 @@ GHEOF # Dry-run message contains reference to the issue [[ "$output" == *"issue #${ISSUE_NUMBER}"* ]] } + +# ── rate-limit handling tests ───────────────────────────────────────────────── + +@test "fix-issue: rate-limited: all engines rate-limited → exits 2, not 1" { + # Override engine stubs to emit a rate-limit message and exit 1 + for engine in claude gemini; do + cat > "$STUB_BIN_DIR/$engine" <<'STUB' +#!/usr/bin/env bash +echo "You've hit your limit · resets 11:20pm (UTC)" +exit 1 +STUB + chmod +x "$STUB_BIN_DIR/$engine" + done + export COPILOT_GITHUB_TOKEN="stub-token" + + # Stub git to avoid real branch creation in the workspace + cat > "$STUB_BIN_DIR/git" <<'GITEOF' +#!/usr/bin/env bash +case "$*" in + "config"*) exit 0 ;; + "checkout"*) exit 0 ;; + "rev-parse HEAD") echo "abc123deadbeef" ;; + *) exit 0 ;; +esac +GITEOF + chmod +x "$STUB_BIN_DIR/git" + + # gh stub: no existing PRs, issue API, comment posts ok, copilot rate-limited + cat > "$STUB_BIN_DIR/gh" <<'GHEOF' +#!/usr/bin/env bash +case "$*" in + *"pulls?state=open"*) echo "[]" ;; + *"api"*"repos/"*"issues/"*) echo '{"title":"Test Issue","body":"Test body"}' ;; + *"api"*"users/"*) echo '{"id":12345}' ;; + *"issue comment"*) exit 0 ;; + *"copilot"*) echo "rate limit exceeded"; exit 1 ;; + *) echo "{}" ;; +esac +GHEOF + chmod +x "$STUB_BIN_DIR/gh" + + export DEV_LEAD_DRY_RUN="false" + + run bash "$FIX_ISSUE_SCRIPT" + + # Must exit 2 (rate-limited), not 1 (engine error) + [ "$status" -eq 2 ] + [[ "$output" == *"rate-limited"* ]] || [[ "$output" == *"rate limited"* ]] + [[ "$output" != *"Engine failed"* ]] +} + +@test "fix-issue: rate-limited: posts comment on issue before exiting" { + for engine in claude gemini; do + cat > "$STUB_BIN_DIR/$engine" <<'STUB' +#!/usr/bin/env bash +echo "rate limit exceeded" +exit 1 +STUB + chmod +x "$STUB_BIN_DIR/$engine" + done + export COPILOT_GITHUB_TOKEN="stub-token" + + local comment_posted_sentinel + comment_posted_sentinel="$(mktemp)" + rm "$comment_posted_sentinel" # deleted; presence after run = was posted + + cat > "$STUB_BIN_DIR/git" <<'GITEOF' +#!/usr/bin/env bash +case "$*" in + "config"*) exit 0 ;; + "checkout"*) exit 0 ;; + "rev-parse HEAD") echo "abc123deadbeef" ;; + *) exit 0 ;; +esac +GITEOF + chmod +x "$STUB_BIN_DIR/git" + + cat > "$STUB_BIN_DIR/gh" </dev/null || true +} From b44e01964bf5c0e97c02ce93442f1aae8eee30bb Mon Sep 17 00:00:00 2001 From: donpetry-bot Date: Thu, 21 May 2026 10:26:39 +0000 Subject: [PATCH 2/2] fix(reviews): address review comments [skip ci-relay] --- scripts/dev-lead-fix-issue.sh | 9 +++++++-- tests/dev-lead/unit/test_fix_issue.bats | 4 ++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/scripts/dev-lead-fix-issue.sh b/scripts/dev-lead-fix-issue.sh index fb42b9287..a84b102f2 100755 --- a/scripts/dev-lead-fix-issue.sh +++ b/scripts/dev-lead-fix-issue.sh @@ -74,8 +74,13 @@ main() { run_writer_with_fallback "$prompt_file" || engine_rc=$? if [ "$engine_rc" -eq 2 ]; then echo "::warning::All engines rate-limited — cannot implement issue #${ISSUE_NUMBER}; re-apply the label to retry" - gh issue comment "$ISSUE_NUMBER" --repo "$REPO" \ - --body "All engines are currently rate-limited. Please re-apply the \`dev-lead\` label when the rate limit clears to retry." 2>/dev/null || true + local reset_msg="" + if [ -f /tmp/dev-lead-rate-limit-reset ]; then + local reset_time + reset_time=$(cat /tmp/dev-lead-rate-limit-reset) + [ -n "$reset_time" ] && reset_msg=" The limit is expected to reset at ${reset_time}." + fi + gh issue comment "$ISSUE_NUMBER" --repo "$REPO" --body "All engines are currently rate-limited.${reset_msg} Please re-apply the \`dev-lead\` label when the rate limit clears to retry." 2>/dev/null || true rm -f "$prompt_file" exit 2 elif [ "$engine_rc" -ne 0 ]; then diff --git a/tests/dev-lead/unit/test_fix_issue.bats b/tests/dev-lead/unit/test_fix_issue.bats index e88727cb3..7160f72b3 100644 --- a/tests/dev-lead/unit/test_fix_issue.bats +++ b/tests/dev-lead/unit/test_fix_issue.bats @@ -175,7 +175,7 @@ GITEOF cat > "$STUB_BIN_DIR/gh" <<'GHEOF' #!/usr/bin/env bash case "$*" in - *"pulls?state=open"*) echo "[]" ;; + *"pulls?state=open"*) echo "0" ;; *"api"*"repos/"*"issues/"*) echo '{"title":"Test Issue","body":"Test body"}' ;; *"api"*"users/"*) echo '{"id":12345}' ;; *"issue comment"*) exit 0 ;; @@ -224,7 +224,7 @@ GITEOF cat > "$STUB_BIN_DIR/gh" <