Elffuss BraidHub

kikocis/continue public

cai: workflow to auto-fix tests (disabled for now)
Changeset4e08584b8e1b1bf68fb8c6cd2bc1aadeecff2e4b9b63834f73dd06be4b421ad1
AuthorNate <sestinj@gmail.com> · 2025-08-31 16:40 -07:00
CommitterNate <sestinj@gmail.com> · 2025-08-31 16:40 -07:00
Parentse9ecc1af12bb

Browse the files at this changeset

2 files changed

added .github/workflows/auto-fix-failed-tests.yml +170 −0
@@ -0,0 +1,170 @@
1+name: Auto Fix Failed Tests
2+
3+on:
4+ workflow_run:
5+ workflows: ["PR Checks", "CLI PR Checks"]
6+ types:
7+ - completed
8+
9+permissions:
10+ contents: write
11+ pull-requests: write
12+ issues: write
13+ actions: read
14+
15+jobs:
16+ fix-failed-tests:
17+ # Only run if the workflow failed
18+ # DISABLED: Remove 'false && ' on the next line to enable auto-fixing
19+ if: false && github.event.workflow_run.conclusion == 'failure'
20+ runs-on: ubuntu-latest
21+
22+ steps:
23+ - name: Get workflow run details
24+ id: workflow-details
25+ uses: actions/github-script@v7
26+ with:
27+ script: |
28+ const workflowRun = context.payload.workflow_run;
29+ const { data: jobs } = await github.rest.actions.listJobsForWorkflowRun({
30+ owner: context.repo.owner,
31+ repo: context.repo.repo,
32+ run_id: workflowRun.id
33+ });
34+
35+ // Find all failed jobs since we're only monitoring specific test workflows
36+ const failedJobs = jobs.jobs.filter(job => job.conclusion === 'failure');
37+
38+ if (failedJobs.length === 0) {
39+ core.info('No failed jobs found');
40+ return null;
41+ }
42+
43+ core.setOutput('has_failed_tests', 'true');
44+ core.setOutput('workflow_name', workflowRun.name);
45+ core.setOutput('workflow_run_id', workflowRun.id);
46+ core.setOutput('head_branch', workflowRun.head_branch);
47+ core.setOutput('head_sha', workflowRun.head_sha);
48+ core.setOutput('failed_jobs', JSON.stringify(failedJobs.map(j => j.name)));
49+
50+ return failedJobs;
51+
52+ - name: Get job logs for failed tests
53+ if: steps.workflow-details.outputs.has_failed_tests == 'true'
54+ id: get-logs
55+ uses: actions/github-script@v7
56+ with:
57+ script: |
58+ const workflowRunId = ${{ github.event.workflow_run.id }};
59+ const { data: jobs } = await github.rest.actions.listJobsForWorkflowRun({
60+ owner: context.repo.owner,
61+ repo: context.repo.repo,
62+ run_id: workflowRunId
63+ });
64+
65+ let errorLogs = '';
66+
67+ for (const job of jobs.jobs) {
68+ if (job.conclusion === 'failure') {
69+ try {
70+ const { data: logData } = await github.rest.actions.downloadJobLogsForWorkflowRun({
71+ owner: context.repo.owner,
72+ repo: context.repo.repo,
73+ job_id: job.id
74+ });
75+
76+ errorLogs += `\n\n=== Job: ${job.name} ===\n`;
77+ errorLogs += logData;
78+ } catch (error) {
79+ core.warning(`Could not fetch logs for job ${job.name}: ${error.message}`);
80+ }
81+ }
82+ }
83+
84+ // Store logs in environment file for next step
85+ const fs = require('fs');
86+ fs.writeFileSync('/tmp/test_failure_logs.txt', errorLogs);
87+
88+ core.setOutput('has_logs', errorLogs.length > 0 ? 'true' : 'false');
89+
90+ - name: Checkout repository
91+ if: steps.workflow-details.outputs.has_failed_tests == 'true'
92+ uses: actions/checkout@v4
93+ with:
94+ token: ${{ secrets.GITHUB_TOKEN }}
95+ fetch-depth: 0
96+ ref: ${{ steps.workflow-details.outputs.head_sha }}
97+
98+ - name: Setup Node.js
99+ if: steps.workflow-details.outputs.has_failed_tests == 'true'
100+ uses: actions/setup-node@v4
101+ with:
102+ node-version: "20"
103+
104+ - name: Install Continue CLI globally
105+ if: steps.workflow-details.outputs.has_failed_tests == 'true'
106+ run: npm i -g @continuedev/cli
107+
108+ - name: Start remote session to fix failed tests
109+ if: steps.workflow-details.outputs.has_failed_tests == 'true'
110+ id: remote-session
111+ env:
112+ CONTINUE_API_KEY: ${{ secrets.CONTINUE_API_KEY }}
113+ run: |
114+ # Create a detailed prompt for fixing the failed tests
115+ cat > /tmp/fix_tests_prompt.txt << 'PROMPT_EOF'
116+ 🔧 **Auto Test Fix Request**
117+
118+ The following tests failed in workflow "${{ steps.workflow-details.outputs.workflow_name }}" (Run ID: ${{ steps.workflow-details.outputs.workflow_run_id }}):
119+
120+ **Failed Jobs:** ${{ steps.workflow-details.outputs.failed_jobs }}
121+ **Branch:** ${{ steps.workflow-details.outputs.head_branch }}
122+ **Commit:** ${{ steps.workflow-details.outputs.head_sha }}
123+
124+ **Your Task:**
125+ 1. Analyze the test failure logs and error messages
126+ 2. Identify the root cause of the test failures
127+ 3. Fix the failing tests by updating the test code or the underlying implementation
128+ 4. Ensure all tests pass after your changes
129+ 5. Commit your fixes with a descriptive message
130+
131+ **Test Failure Context:**
132+ Please examine the repository structure, run the failing tests locally to understand the errors, and implement appropriate fixes.
133+
134+ Focus on:
135+ - Understanding what the tests are trying to validate
136+ - Identifying why they're failing (code changes, environment issues, test logic errors)
137+ - Making minimal, targeted fixes that address the root cause
138+ - Ensuring the fixes don't break other functionality
139+
140+ Please start by examining the failing tests and their error messages, then proceed with the necessary fixes.
141+ PROMPT_EOF
142+
143+ echo "Starting Continue CLI remote session for test fixes..."
144+ echo "Prompt content:"
145+ cat /tmp/fix_tests_prompt.txt
146+
147+ # Start remote session and capture JSON output
148+ SESSION_OUTPUT=$(cat /tmp/fix_tests_prompt.txt | cn remote -s --branch ${{ steps.workflow-details.outputs.head_branch }})
149+ echo "Raw session output: $SESSION_OUTPUT"
150+
151+ # Extract URL from JSON output
152+ SESSION_URL=$(echo "$SESSION_OUTPUT" | jq -r '.url // empty')
153+
154+ if [ -z "$SESSION_URL" ] || [ "$SESSION_URL" = "null" ]; then
155+ echo "Failed to extract session URL from output: $SESSION_OUTPUT"
156+ exit 1
157+ fi
158+
159+ echo "session_url=$SESSION_URL" >> $GITHUB_OUTPUT
160+ echo "✅ Started remote session: $SESSION_URL"
161+
162+ - name: Log session details
163+ if: steps.workflow-details.outputs.has_failed_tests == 'true'
164+ run: |
165+ echo "✅ Successfully started auto-fix session for failed tests"
166+ echo "Workflow: ${{ steps.workflow-details.outputs.workflow_name }}"
167+ echo "Run ID: ${{ steps.workflow-details.outputs.workflow_run_id }}"
168+ echo "Branch: ${{ steps.workflow-details.outputs.head_branch }}"
169+ echo "Session URL: ${{ steps.remote-session.outputs.session_url }}"
170+ echo "Failed jobs: ${{ steps.workflow-details.outputs.failed_jobs }}"
deleted extensions/cli/.github/workflows/respond-to-cubic-dev-ai.yml +0 −215
@@ -1,215 +0,0 @@
1-name: Respond to @continuedev Comments
2-
3-on:
4- issue_comment:
5- types: [created]
6- pull_request_review_comment:
7- types: [created]
8-
9-permissions:
10- contents: write
11- pull-requests: write
12- issues: write
13-
14-jobs:
15- respond-to-comment:
16- # Only run on pull request comments
17- if: github.event_name == 'issue_comment' && github.event.issue.pull_request
18- runs-on: ubuntu-latest
19-
20- steps:
21- - name: Check if comment contains @continuedev
22- id: check-mention
23- run: |
24- if echo "${{ github.event.comment.body }}" | grep -q "@continuedev"; then
25- echo "contains_mention=true" >> $GITHUB_OUTPUT
26- else
27- echo "contains_mention=false" >> $GITHUB_OUTPUT
28- fi
29-
30- - name: Checkout PR branch
31- if: steps.check-mention.outputs.contains_mention == 'true'
32- uses: actions/checkout@v4
33- with:
34- token: ${{ secrets.GITHUB_TOKEN }}
35- fetch-depth: 0
36-
37- - name: Get PR information
38- if: steps.check-mention.outputs.contains_mention == 'true'
39- id: pr-info
40- uses: actions/github-script@v7
41- with:
42- script: |
43- const { data: pr } = await github.rest.pulls.get({
44- owner: context.repo.owner,
45- repo: context.repo.repo,
46- pull_number: context.issue.number
47- });
48-
49- core.setOutput('head_ref', pr.head.ref);
50- core.setOutput('head_sha', pr.head.sha);
51- return pr;
52-
53- - name: Checkout PR branch
54- if: steps.check-mention.outputs.contains_mention == 'true'
55- run: |
56- git checkout ${{ steps.pr-info.outputs.head_ref }}
57-
58- - name: Setup Node.js
59- if: steps.check-mention.outputs.contains_mention == 'true'
60- uses: actions/setup-node@v4
61- with:
62- node-version: "20"
63-
64- - name: Install Continue CLI globally
65- if: steps.check-mention.outputs.contains_mention == 'true'
66- run: npm i -g @continuedev/cli
67-
68- - name: Start remote session
69- if: steps.check-mention.outputs.contains_mention == 'true'
70- id: remote-session
71- env:
72- CONTINUE_API_KEY: ${{ secrets.CONTINUE_API_KEY }}
73- run: |
74- # Create the prompt for remote session
75- PROMPT="Please help with the following request from @${{ github.event.comment.user.login }} on PR #${{ github.event.issue.number }}:
76-
77- ${{ github.event.comment.body }}
78-
79- Please analyze the current PR, understand the request, implement the necessary changes, and commit them to this branch."
80-
81- # Start remote session and capture JSON output
82- SESSION_OUTPUT=$(echo "$PROMPT" | cn remote -s --branch ${{ steps.pr-info.outputs.head_ref }})
83- echo "Raw session output: $SESSION_OUTPUT"
84-
85- # Extract URL from JSON output
86- SESSION_URL=$(echo "$SESSION_OUTPUT" | jq -r '.url // empty')
87-
88- if [ -z "$SESSION_URL" ] || [ "$SESSION_URL" = "null" ]; then
89- echo "Failed to extract session URL from output: $SESSION_OUTPUT"
90- exit 1
91- fi
92-
93- echo "session_url=$SESSION_URL" >> $GITHUB_OUTPUT
94- echo "✅ Started remote session: $SESSION_URL"
95-
96- - name: Comment with session URL
97- if: steps.check-mention.outputs.contains_mention == 'true' && steps.remote-session.outputs.session_url
98- uses: actions/github-script@v7
99- with:
100- script: |
101- const commentBody = `I've started [a remote session](${{ steps.remote-session.outputs.session_url }}) to help with your request:
102- > ${{ github.event.comment.body }}`;
103-
104- await github.rest.issues.createComment({
105- owner: context.repo.owner,
106- repo: context.repo.repo,
107- issue_number: context.issue.number,
108- body: commentBody
109- });
110-
111- - name: Log session details
112- if: steps.check-mention.outputs.contains_mention == 'true'
113- run: |
114- echo "✅ Successfully started remote session for comment from ${{ github.event.comment.user.login }} on PR #${{ github.event.issue.number }}"
115- echo "Session URL: ${{ steps.remote-session.outputs.session_url }}"
116- echo "Original comment: ${{ github.event.comment.body }}"
117-
118- respond-to-review-comment:
119- # Only run on pull request review comments
120- if: github.event_name == 'pull_request_review_comment'
121- runs-on: ubuntu-latest
122-
123- steps:
124- - name: Check if comment contains @continuedev
125- id: check-mention
126- run: |
127- if echo "${{ github.event.comment.body }}" | grep -q "@continuedev"; then
128- echo "contains_mention=true" >> $GITHUB_OUTPUT
129- else
130- echo "contains_mention=false" >> $GITHUB_OUTPUT
131- fi
132-
133- - name: Checkout PR branch
134- if: steps.check-mention.outputs.contains_mention == 'true'
135- uses: actions/checkout@v4
136- with:
137- token: ${{ secrets.GITHUB_TOKEN }}
138- fetch-depth: 0
139- ref: ${{ github.event.pull_request.head.ref }}
140-
141- - name: Setup Node.js
142- if: steps.check-mention.outputs.contains_mention == 'true'
143- uses: actions/setup-node@v4
144- with:
145- node-version: "20"
146-
147- - name: Install Continue CLI globally
148- if: steps.check-mention.outputs.contains_mention == 'true'
149- run: npm i -g @continuedev/cli
150-
151- - name: Start remote session
152- if: steps.check-mention.outputs.contains_mention == 'true'
153- id: remote-session
154- env:
155- CONTINUE_API_KEY: ${{ secrets.CONTINUE_API_KEY }}
156- run: |
157- # Create a temporary file for the prompt to handle special characters and newlines properly
158- cat > /tmp/prompt.txt << 'PROMPT_EOF'
159- Please help with the following code review comment from @${{ github.event.comment.user.login }} on PR #${{ github.event.pull_request.number }}:
160-
161- **File:** ${{ github.event.comment.path }}
162- **Line:** ${{ github.event.comment.line || github.event.comment.original_line || 'N/A' }}
163- **Comment:** ${{ github.event.comment.body }}
164-
165- Please analyze the specific file and line mentioned, understand the review feedback, implement the necessary changes, and commit them to this branch.
166- PROMPT_EOF
167-
168- # Debug output
169- echo "PROMPT content:"
170- cat /tmp/prompt.txt
171-
172- # Start remote session and capture JSON output
173- echo "Starting cn with prompt..."
174- SESSION_OUTPUT=$(cat /tmp/prompt.txt | cn remote -s --branch ${{ github.event.pull_request.head.ref }})
175- echo "Raw session output: $SESSION_OUTPUT"
176-
177- # Extract URL from JSON output
178- SESSION_URL=$(echo "$SESSION_OUTPUT" | jq -r '.url // empty')
179-
180- if [ -z "$SESSION_URL" ] || [ "$SESSION_URL" = "null" ]; then
181- echo "Failed to extract session URL from output: $SESSION_OUTPUT"
182- exit 1
183- fi
184-
185- echo "session_url=$SESSION_URL" >> $GITHUB_OUTPUT
186- echo "✅ Started remote session: $SESSION_URL"
187-
188- - name: Comment with session URL
189- if: steps.check-mention.outputs.contains_mention == 'true' && steps.remote-session.outputs.session_url
190- uses: actions/github-script@v7
191- with:
192- script: |
193- const commentBody = `I've started [a remote session](${{ steps.remote-session.outputs.session_url }}) to help with your request:
194- > ${{ github.event.comment.body }}`;
195-
196- const commentParams = {
197- owner: context.repo.owner,
198- repo: context.repo.repo,
199- pull_number: ${{ github.event.pull_request.number }},
200- body: commentBody,
201- commit_id: '${{ github.event.pull_request.head.sha }}',
202- path: '${{ github.event.comment.path }}',
203- in_reply_to: ${{ github.event.comment.id }}
204- };
205-
206- await github.rest.pulls.createReviewComment(commentParams);
207-
208- - name: Log session details
209- if: steps.check-mention.outputs.contains_mention == 'true'
210- run: |
211- echo "✅ Successfully started remote session for review comment from ${{ github.event.comment.user.login }} on PR #${{ github.event.pull_request.number }}"
212- echo "Session URL: ${{ steps.remote-session.outputs.session_url }}"
213- echo "File: ${{ github.event.comment.path }}"
214- echo "Line: ${{ github.event.comment.line }}"
215- echo "Original comment: ${{ github.event.comment.body }}"