Skip to content

Commit cacb180

Browse files
Copilotstrawgate
andauthored
Add automated Claude workflow for test failure analysis (#200)
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: strawgate <6384545+strawgate@users.noreply.github.com> Co-authored-by: William Easton <williamseaston@gmail.com>
1 parent 02a21b3 commit cacb180

File tree

2 files changed

+165
-0
lines changed

2 files changed

+165
-0
lines changed
Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
name: Claude Test Failure Analysis
2+
3+
on:
4+
workflow_run:
5+
workflows: ["Run Tests"]
6+
types:
7+
- completed
8+
9+
concurrency:
10+
group: claude-test-failure-${{ github.event.workflow_run.head_branch }}
11+
cancel-in-progress: true
12+
13+
jobs:
14+
claude-analyze-failure:
15+
# Only run if the test workflow failed
16+
if: ${{ github.event.workflow_run.conclusion == 'failure' }}
17+
runs-on: ubuntu-latest
18+
permissions:
19+
contents: read
20+
pull-requests: write
21+
issues: write
22+
id-token: write
23+
actions: read # Required for Claude to read CI results
24+
steps:
25+
- name: Checkout repository
26+
uses: actions/checkout@v4
27+
with:
28+
fetch-depth: 1
29+
30+
- name: Set up Python 3.10
31+
uses: actions/setup-python@v5
32+
with:
33+
python-version: '3.10'
34+
35+
# Install UV package manager
36+
- name: Install UV
37+
uses: astral-sh/setup-uv@v7
38+
39+
- name: Set analysis prompt
40+
id: analysis-prompt
41+
run: |
42+
cat >> $GITHUB_OUTPUT << 'EOF'
43+
PROMPT<<PROMPT_END
44+
You're a test failure analysis assistant for Py-Key-Value, a Python framework for interacting with Key-Value stores.
45+
46+
# Your Task
47+
A GitHub Actions workflow has failed. Your job is to:
48+
1. Analyze the test failure(s) to understand what went wrong
49+
2. Identify the root cause of the failure(s)
50+
3. Suggest a clear, actionable solution to fix the failure(s)
51+
52+
# Getting Started
53+
1. Call the generate_agents_md tool to get a high-level summary of the project
54+
2. Get the pull request associated with this workflow run from the GitHub repository: ${{ github.repository }}
55+
- The workflow run ID is: ${{ github.event.workflow_run.id }}
56+
- The workflow run was triggered by: ${{ github.event.workflow_run.event }}
57+
- Use GitHub MCP tools to get PR details and workflow run information
58+
3. Use the GitHub MCP tools to fetch job logs and failure information:
59+
- Use get_workflow_run to get details about the failed workflow
60+
- Use list_workflow_jobs to see which jobs failed
61+
- Use get_job_logs with failed_only=true to get logs for failed jobs
62+
- Use summarize_run_log_failures to get an AI summary of what failed
63+
4. Analyze the failures to understand the root cause
64+
5. Search the codebase for relevant files, tests, and implementations
65+
66+
# Your Response
67+
Post a comment on the pull request with your analysis. Your comment should include:
68+
69+
## Test Failure Analysis
70+
71+
**Summary**: A brief 1-2 sentence summary of what failed.
72+
73+
**Root Cause**: A clear explanation of why the tests failed, based on your analysis of the logs and code.
74+
75+
**Suggested Solution**: Specific, actionable steps to fix the failure(s). Include:
76+
- Which files need to be modified
77+
- What changes are needed
78+
- Why these changes will fix the issue
79+
80+
<details>
81+
<summary>Detailed Analysis</summary>
82+
83+
Include here:
84+
- Relevant log excerpts showing the failure
85+
- Code snippets that are causing the issue
86+
- Any related issues or PRs that might be relevant
87+
</details>
88+
89+
<details>
90+
<summary>Related Files</summary>
91+
92+
List files that are relevant to the failure with brief explanations of their relevance.
93+
</details>
94+
95+
# Important Guidelines
96+
- Be concise and actionable - developers want to quickly understand and fix the issue
97+
- Focus on facts from the logs and code, not speculation
98+
- If you can't determine the root cause, say so clearly
99+
- Provide specific file names, line numbers, and code references when possible
100+
- You can run make commands (e.g., `make lint`, `make typecheck`, `make sync`) to build, test, or lint the code
101+
- You can also run git commands (e.g., `git status`, `git log`, `git diff`) to inspect the repository
102+
- You can use WebSearch and WebFetch to research errors, stack traces, or related issues
103+
- For bash commands, you are limited to make and git commands only
104+
105+
# CRITICAL: Loop Detection
106+
**IMPORTANT**: Before posting your analysis, check the PR comments to detect if there's a loop where:
107+
- CodeRabbit or another bot triggered this workflow
108+
- Your previous analysis triggered CodeRabbit or another bot
109+
- This created a repeating cycle of bot comments
110+
111+
If you detect such a loop (e.g., you see multiple similar bot comments or your own previous analysis comments):
112+
1. **DO NOT** post another analysis comment
113+
2. Instead, post a brief comment stating: "Loop detected: Multiple automated analysis comments found. Stopping to prevent further automated comments. Please review the existing analysis comments."
114+
3. Exit immediately without further action
115+
116+
# Problems Encountered
117+
If you encounter any problems during your analysis (e.g., unable to fetch logs, tools not working), document them clearly so the team knows what limitations you faced.
118+
PROMPT_END
119+
EOF
120+
121+
- name: Setup GitHub MCP Server
122+
run: |
123+
mkdir -p /tmp/mcp-config
124+
cat > /tmp/mcp-config/mcp-servers.json << 'EOF'
125+
{
126+
"mcpServers": {
127+
"repository-summary": {
128+
"type": "http",
129+
"url": "https://agents-md-generator.fastmcp.app/mcp"
130+
},
131+
"code-search": {
132+
"type": "http",
133+
"url": "https://public-code-search.fastmcp.app/mcp"
134+
},
135+
"github-research": {
136+
"type": "stdio",
137+
"command": "uvx",
138+
"args": [
139+
"github-research-mcp"
140+
],
141+
"env": {
142+
"DISABLE_SUMMARIES": "true", # Disable verbose summaries for faster analysis
143+
"GITHUB_PERSONAL_ACCESS_TOKEN": "${{ secrets.GITHUB_TOKEN }}"
144+
}
145+
}
146+
}
147+
}
148+
EOF
149+
150+
- name: Run Claude Code
151+
id: claude
152+
uses: anthropics/claude-code-action@v1
153+
with:
154+
claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
155+
156+
additional_permissions: |
157+
actions: read
158+
159+
prompt: ${{ steps.analysis-prompt.outputs.PROMPT }}
160+
track_progress: true
161+
claude_args: |
162+
--allowed-tools mcp__repository-summary,mcp__code-search,mcp__github-research,WebSearch,WebFetch,Bash(make:*,git:*)
163+
--mcp-config /tmp/mcp-config/mcp-servers.json

AGENTS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,8 @@ GitHub Actions workflows are in `.github/workflows/`:
224224
- `publish.yml` - Publish packages to PyPI
225225
- `claude-on-mention.yml` - Claude Code assistant (can make PRs)
226226
- `claude-on-open-label.yml` - Claude triage assistant (read-only analysis)
227+
- `claude-on-test-failure.yml` - Claude test failure analysis (automatically
228+
analyzes failed tests and suggests solutions)
227229

228230
## Version Management
229231

0 commit comments

Comments
 (0)