Repository navigation
Return a test summary from run_tests #18
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -79,18 +79,34 @@ export function ReviewLead() { | |
| description: 'Run the demo-pr test suite and return its output', | ||
| input: v.object({}), | ||
| async run({ log }) { | ||
| let output: string; | ||
| const reportPath = '/tmp/vitest.json'; | ||
| let exitCode = 0; | ||
| try { | ||
| const { stdout, stderr } = await execFileAsync('npm', ['test'], { | ||
| cwd: 'fixtures/demo-pr', | ||
| maxBuffer: 64 * 1024 * 1024, | ||
| }); | ||
| output = `${stdout}\n${stderr}`; | ||
| await execFileAsync( | ||
| 'npx', | ||
| ['vitest', 'run', '--reporter=json', `--outputFile=${reportPath}`], | ||
| { cwd: 'fixtures/demo-pr', maxBuffer: 64 * 1024 * 1024 }, | ||
| ); | ||
| } catch (error) { | ||
| const failure = error as { code?: number; stdout?: string; stderr?: string }; | ||
| const failure = error as { code?: number }; | ||
| exitCode = typeof failure.code === 'number' ? failure.code : 1; | ||
| output = `Tests failed (exit ${exitCode})\n${failure.stdout ?? ''}\n${failure.stderr ?? ''}`; | ||
| } | ||
| let output: string; | ||
| try { | ||
| const report = JSON.parse(await readFile(reportPath, 'utf8')); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Stale test report can be reusedLow Severity
Reviewed by Cursor Bugbot for commit 9e04910. Configure here. |
||
| const failures = report.testResults.flatMap( | ||
| (file: { name: string; assertionResults: { status: string; fullName: string }[] }) => | ||
| file.assertionResults | ||
| .filter((test) => test.status === 'failed') | ||
| .map((test) => `${path.basename(file.name)}: ${test.fullName}`), | ||
| ); | ||
| output = JSON.stringify({ | ||
| passed: report.numPassedTests, | ||
| failed: report.numFailedTests, | ||
| failures, | ||
| }); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suite failures look like successMedium Severity The summary keeps only Additional Locations (1)Reviewed by Cursor Bugbot for commit 9e04910. Configure here. |
||
| } catch { | ||
| output = `Tests failed to run (exit ${exitCode})`; | ||
| } | ||
| log.info('tests finished', { exitCode, bytes: output.length }); | ||
| return output; | ||
|
|
||


There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: The code uses a hardcoded file path
/tmp/vitest.jsonfor test reports. This can cause race conditions or stale data reads if multiple reviews run concurrently on the same machine.Severity: LOW
Suggested Fix
Use a unique filename for the temporary report file to avoid conflicts. This can be achieved by appending a unique identifier, such as a process ID (
process.pid) or a timestamp, to the filename. For example,/tmp/vitest-${process.pid}.json. Ensure the temporary file is cleaned up after use.Prompt for AI Agent
Did we get this right? 👍 / 👎 to inform future reviews.