Skip to content

Commit 6b89cb0

Browse files
committed
fix: clauder fixer job not being able to write. Improved comment creation and title for new fixer PR
1 parent 60c150f commit 6b89cb0

1 file changed

Lines changed: 42 additions & 18 deletions

File tree

.github/workflows/claude-fixer.yml

Lines changed: 42 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -63,34 +63,35 @@ jobs:
6363
REPO="${GITHUB_REPOSITORY}"
6464
RUN_ID="${{ github.event.workflow_run.id }}"
6565
66-
gh api "repos/${REPO}/actions/runs/${RUN_ID}/jobs" --paginate > all_jobs.json
67-
FAILED_JOB_IDS=$(jq -r '.jobs[] | select(.conclusion == "failure") | .id' all_jobs.json)
66+
# Write all temp files to /tmp so the working tree stays clean for Claude's changes
67+
gh api "repos/${REPO}/actions/runs/${RUN_ID}/jobs" --paginate > /tmp/all_jobs.json
68+
FAILED_JOB_IDS=$(jq -r '.jobs[] | select(.conclusion == "failure") | .id' /tmp/all_jobs.json)
6869
69-
: > failed_logs.txt
70+
: > /tmp/failed_logs.txt
7071
FAILED_TEST_FILES=""
7172
7273
for job_id in $FAILED_JOB_IDS; do
73-
JOB_NAME=$(jq -r ".jobs[] | select(.id == $job_id) | .name" all_jobs.json)
74-
echo "=== Failed Shard: ${JOB_NAME} ===" >> failed_logs.txt
74+
JOB_NAME=$(jq -r ".jobs[] | select(.id == $job_id) | .name" /tmp/all_jobs.json)
75+
echo "=== Failed Shard: ${JOB_NAME} ===" >> /tmp/failed_logs.txt
7576
76-
gh api "repos/${REPO}/actions/jobs/${job_id}/logs" > raw_log.txt 2>/dev/null || {
77-
echo "[Could not fetch logs for job ${job_id}]" >> failed_logs.txt
77+
gh api "repos/${REPO}/actions/jobs/${job_id}/logs" > /tmp/raw_log.txt 2>/dev/null || {
78+
echo "[Could not fetch logs for job ${job_id}]" >> /tmp/failed_logs.txt
7879
continue
7980
}
8081
8182
# "Failed Tests" is always the last section in vitest output —
8283
# take from its line to EOF so we capture all failures without a hard limit.
83-
START_LINE=$(grep -n "Failed Tests" raw_log.txt | tail -1 | cut -d: -f1)
84+
START_LINE=$(grep -n "Failed Tests" /tmp/raw_log.txt | tail -1 | cut -d: -f1)
8485
if [ -n "$START_LINE" ]; then
8586
CONTEXT_START=$((START_LINE > 5 ? START_LINE - 5 : 1))
86-
tail -n +"$CONTEXT_START" raw_log.txt >> failed_logs.txt
87+
tail -n +"$CONTEXT_START" /tmp/raw_log.txt >> /tmp/failed_logs.txt
8788
else
88-
echo "[No 'Failed Tests' section found — showing last 100 lines]" >> failed_logs.txt
89-
tail -100 raw_log.txt >> failed_logs.txt
89+
echo "[No 'Failed Tests' section found — showing last 100 lines]" >> /tmp/failed_logs.txt
90+
tail -100 /tmp/raw_log.txt >> /tmp/failed_logs.txt
9091
fi
91-
echo "" >> failed_logs.txt
92+
echo "" >> /tmp/failed_logs.txt
9293
93-
NEW_FILES=$(grep " FAIL test/" raw_log.txt | grep -o "test/[^[:space:]>]*\.test\.ts" | sort -u | tr '\n' ' ')
94+
NEW_FILES=$(grep " FAIL test/" /tmp/raw_log.txt | grep -o "test/[^[:space:]>]*\.test\.ts" | sort -u | tr '\n' ' ')
9495
FAILED_TEST_FILES="${FAILED_TEST_FILES}${NEW_FILES}"
9596
done
9697
@@ -101,16 +102,17 @@ jobs:
101102
uses: anthropics/claude-code-action@v1
102103
with:
103104
claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
105+
claude_args: "--allowedTools Bash,Read,Edit,Write --max-turns 100"
104106
prompt: |
105107
The "${{ github.event.workflow_run.name }}" workflow failed on branch "${{ github.event.workflow_run.head_branch }}".
106108
107109
Failing test files: ${{ steps.fetch-logs.outputs.failed_test_files }}
108110
109-
Filtered failure logs from all failed shards are in `failed_logs.txt` in the working directory. Read it first.
111+
Filtered failure logs from all failed shards are in `/tmp/failed_logs.txt`. Read it first.
110112
111113
Follow these steps carefully:
112114
113-
1. **Diagnose the root cause**: Read `failed_logs.txt` thoroughly. Before writing a single line of code, understand WHY the tests are failing — not just the symptom. Read the relevant source files to understand the existing architecture and patterns.
115+
1. **Diagnose the root cause**: Read `/tmp/failed_logs.txt` thoroughly. Before writing a single line of code, understand WHY the tests are failing — not just the symptom. Read the relevant source files to understand the existing architecture and patterns.
114116
115117
2. **Implement an architecturally sound fix**: The fix must address the underlying root cause, match existing code patterns in this codebase, and introduce no workarounds or hacks. Do not mask symptoms.
116118
@@ -142,15 +144,37 @@ jobs:
142144

143145
- name: Open pull request
144146
if: steps.auto-commit.outputs.changes_detected == 'true'
147+
id: create-pr
145148
env:
146149
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
147150
run: |
148-
gh pr create \
149-
--title "fix: auto-fix test failures from ${{ github.event.workflow_run.name }}" \
151+
PR_URL=$(gh pr create \
152+
--title "fix: auto-fix ${{ github.event.workflow_run.name }} failures on ${{ github.event.workflow_run.head_branch }}" \
150153
--body "Failures detected in \`${{ github.event.workflow_run.name }}\` on branch \`${{ github.event.workflow_run.head_branch }}\`.
151154
152155
This PR was automatically generated by the Claude Test Fixer workflow.
153156
154157
> ⚠️ AI-generated fix. Please review carefully before merging." \
155158
--base ${{ github.event.workflow_run.head_branch }} \
156-
--head ${{ steps.branch.outputs.name }}
159+
--head ${{ steps.branch.outputs.name }})
160+
echo "pr-url=$PR_URL" >> $GITHUB_OUTPUT
161+
162+
- name: Add failure logs as PR comment
163+
if: steps.auto-commit.outputs.changes_detected == 'true'
164+
env:
165+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
166+
run: |
167+
{
168+
echo '## Test Failure Logs'
169+
echo ''
170+
echo '<details>'
171+
echo '<summary>Click to expand failure logs from the failed CI run</summary>'
172+
echo ''
173+
echo '```'
174+
head -c 60000 /tmp/failed_logs.txt
175+
echo '```'
176+
echo ''
177+
echo '</details>'
178+
} > /tmp/pr-comment.md
179+
180+
gh pr comment "${{ steps.create-pr.outputs.pr-url }}" --body-file /tmp/pr-comment.md

0 commit comments

Comments
 (0)