feat(quality-gates): probe WSL availability before CodeRabbit invocation — fixes #757 - #761
Conversation
…ion [#757] When running on Windows with WSL mode (default), the runtime now probes `spawnSync('wsl', ['-l'])` before constructing the wsl bash command. If the probe fails with ENOENT (binary missing) or non-zero exit (WSL feature present but no distribution installed), throw a clear error pointing to `wsl --install` documentation, the installation-troubleshooting guide, and the `installation_mode='native'` bypass. Replaces cmd.exe's generic "'wsl' is not recognized as an internal or external command" with framework-aware guidance. ~1ms latency per CodeRabbit invocation on Windows hosts. ## Changes - `.aiox-core/core/orchestration/workflow-executor.js`: switch to namespaced `childProcess` import (was destructured) so jest spies can intercept; add probe at the top of the wsl branch. - `.aiox-core/core/quality-gates/layer2-pr-automation.js`: same pattern. Both files now use `childProcess.spawnSync` directly. - `tests/unit/quality-gates/cross-platform-coderabbit.test.js`: mock `spawnSync` in beforeEach so the existing 12 WSL-mode tests continue to pass on macOS/Linux dev boxes; add 4 new tests covering: - ENOENT probe failure surfaces actionable error message - non-zero exit probe failure surfaces same actionable error message - probe is NOT invoked when installation_mode=native (bypass works) - probe is NOT invoked on macOS native invocation Suite: 16/16 pass (was 12/12). Total 77/77 across all touched files. Closes #757 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
WalkthroughWindows hosts running CodeRabbit in WSL mode now receive a preflight WSL availability check that runs ChangesWSL availability probe and child process refactoring
Sequence Diagram(s)sequenceDiagram
participant Host
participant runCodeRabbit as runCodeRabbit() / runCodeRabbitAnalysis()
participant probeWSL as spawnSync('wsl', ['-l'])
participant cmdExec as execute CodeRabbit command
participant ErrorHandler
Host->>runCodeRabbit: invoke with installation_mode='wsl' on Windows
runCodeRabbit->>probeWSL: probe WSL availability
alt WSL available (status 0)
probeWSL-->>runCodeRabbit: success
runCodeRabbit->>cmdExec: execute CodeRabbit via WSL
cmdExec-->>Host: analysis/command result
else WSL missing (ENOENT)
probeWSL-->>runCodeRabbit: ENOENT error
runCodeRabbit->>ErrorHandler: throw with installation guidance
ErrorHandler-->>Host: error: WSL not installed
else WSL no distribution (non-zero exit)
probeWSL-->>runCodeRabbit: non-zero exit code
runCodeRabbit->>ErrorHandler: throw with distribution setup guidance
ErrorHandler-->>Host: error: no WSL distribution
end
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Suggested labels
Suggested reviewers
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
📊 Coverage ReportCoverage report not available
Generated by PR Automation (Story 6.1) |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
.aiox-core/core/quality-gates/layer2-pr-automation.js (1)
120-149:⚠️ Potential issue | 🟠 Major | ⚡ Quick winAdd non-zero exit code handling to prevent silent quality gate bypass.
After the WSL probe passes,
runCommand()resolves on every exit code (including failures), andrunCodeRabbit()never checksresult.exitCode. If the CodeRabbit binary is missing inside the WSL distribution or crashes, the method parses empty output, finds zero issues, and returnspass: true, silently bypassing Layer 2.Fix required
const result = await this.runCommand(command, timeout); + if (result.exitCode !== 0) { + throw new Error( + result.stderr.trim() || + result.stdout.trim() || + `CodeRabbit exited with code ${result.exitCode}`, + ); + } // Parse CodeRabbit output for issues const issues = this.parseCodeRabbitOutput(result.stdout + result.stderr);Also add test coverage for this scenario (non-zero exitCode with empty output).
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In @.aiox-core/core/quality-gates/layer2-pr-automation.js around lines 120 - 149, After the WSL probe passes, add explicit handling of non-zero child exit codes returned by runCommand (the result from runCommand(...) stored in result) inside runCodeRabbit so a non-zero result.exitCode does not get treated as success; if result.exitCode !== 0 (or result.error is present) treat the invocation as a failure (throw or return pass: false with an informative message including result.exitCode and stdout/stderr), and ensure you still surface stdout/stderr for debugging rather than parsing empty output as “0 issues.” Update tests to cover the case where runCommand returns a non-zero exitCode with empty stdout/stderr to assert Layer 2 fails instead of passing.
🧹 Nitpick comments (1)
.aiox-core/core/orchestration/workflow-executor.js (1)
776-809: ⚡ Quick winAdd direct WSL-probe coverage for
runCodeRabbitAnalysis.The Layer 2 suite covers this behavior, but I don't see equivalent coverage for the orchestration path that now ships the same Windows/WSL branching. A small parity test here would reduce drift in this core module.
As per coding guidelines, "Verify test coverage exists for new/modified functions."
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In @.aiox-core/core/orchestration/workflow-executor.js around lines 776 - 809, The orchestration function runCodeRabbitAnalysis lacks tests for the Windows/WSL branching; add unit tests that exercise coderabbitConfig.installation_mode='wsl' and the default platform-detected branch so the WSL probe behavior is covered: mock/stub childProcess.spawnSync (and childProcess.exec/promisify if needed) to simulate both a missing WSL (spawnSync.error or non-zero status) and a present WSL (status 0) and assert that runCodeRabbitAnalysis throws the expected error message on failure and proceeds to build/execute the WSL command on success; target the runCodeRabbitAnalysis export and verify the command construction path that reads coderabbitConfig.cli_path and installation_mode.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In @.aiox-core/core/quality-gates/layer2-pr-automation.js:
- Around line 120-149: After the WSL probe passes, add explicit handling of
non-zero child exit codes returned by runCommand (the result from
runCommand(...) stored in result) inside runCodeRabbit so a non-zero
result.exitCode does not get treated as success; if result.exitCode !== 0 (or
result.error is present) treat the invocation as a failure (throw or return
pass: false with an informative message including result.exitCode and
stdout/stderr), and ensure you still surface stdout/stderr for debugging rather
than parsing empty output as “0 issues.” Update tests to cover the case where
runCommand returns a non-zero exitCode with empty stdout/stderr to assert Layer
2 fails instead of passing.
---
Nitpick comments:
In @.aiox-core/core/orchestration/workflow-executor.js:
- Around line 776-809: The orchestration function runCodeRabbitAnalysis lacks
tests for the Windows/WSL branching; add unit tests that exercise
coderabbitConfig.installation_mode='wsl' and the default platform-detected
branch so the WSL probe behavior is covered: mock/stub childProcess.spawnSync
(and childProcess.exec/promisify if needed) to simulate both a missing WSL
(spawnSync.error or non-zero status) and a present WSL (status 0) and assert
that runCodeRabbitAnalysis throws the expected error message on failure and
proceeds to build/execute the WSL command on success; target the
runCodeRabbitAnalysis export and verify the command construction path that reads
coderabbitConfig.cli_path and installation_mode.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 6a75af2b-68a7-424f-a24b-5c094bee40bd
📒 Files selected for processing (4)
.aiox-core/core/orchestration/workflow-executor.js.aiox-core/core/quality-gates/layer2-pr-automation.js.aiox-core/install-manifest.yamltests/unit/quality-gates/cross-platform-coderabbit.test.js
…ion [SynkraAI#757] (SynkraAI#761) When running on Windows with WSL mode (default), the runtime now probes `spawnSync('wsl', ['-l'])` before constructing the wsl bash command. If the probe fails with ENOENT (binary missing) or non-zero exit (WSL feature present but no distribution installed), throw a clear error pointing to `wsl --install` documentation, the installation-troubleshooting guide, and the `installation_mode='native'` bypass. Replaces cmd.exe's generic "'wsl' is not recognized as an internal or external command" with framework-aware guidance. ~1ms latency per CodeRabbit invocation on Windows hosts. ## Changes - `.aiox-core/core/orchestration/workflow-executor.js`: switch to namespaced `childProcess` import (was destructured) so jest spies can intercept; add probe at the top of the wsl branch. - `.aiox-core/core/quality-gates/layer2-pr-automation.js`: same pattern. Both files now use `childProcess.spawnSync` directly. - `tests/unit/quality-gates/cross-platform-coderabbit.test.js`: mock `spawnSync` in beforeEach so the existing 12 WSL-mode tests continue to pass on macOS/Linux dev boxes; add 4 new tests covering: - ENOENT probe failure surfaces actionable error message - non-zero exit probe failure surfaces same actionable error message - probe is NOT invoked when installation_mode=native (bypass works) - probe is NOT invoked on macOS native invocation Suite: 16/16 pass (was 12/12). Total 77/77 across all touched files. Closes SynkraAI#757 Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Summary
Add an explicit WSL availability probe in
workflow-executor.jsandlayer2-pr-automation.jsbefore constructing thewsl bash -ccommand on Windows hosts. Replaces cmd.exe's generic "'wsl' is not recognized" error with framework-aware guidance pointing to install docs, the troubleshooting guide, and theinstallation_mode='native'bypass.Closes the CodeRabbit suggestion declined in PR #752 (Issue #731) for follow-up.
Implementation
Both files probe
spawnSync('wsl', ['-l'], { encoding: 'utf8' })at the top of the wsl-mode branch. The probe fails when:error.code === 'ENOENT'— wsl binary not installed on the hoststatus !== 0— wsl installed but no distribution availableIn both failure modes, throw:
The graceful-degradation try/catch in
runCodeRabbitalready converts the throw into a soft failure ({ pass: false, error: <message> }), so the probe never crashes the quality-gate pipeline — it just turns an opaque CLI failure into an actionable one.Refactor for testability
Both files switched from destructured imports (
const { spawn, spawnSync } = require('child_process')) to namespaced imports (const childProcess = require('child_process')) sojest.spyOn(childProcess, 'spawnSync')can intercept calls in tests. No behavior change — every call site updated.Test coverage
tests/unit/quality-gates/cross-platform-coderabbit.test.jsextended from 12 to 16 cases:spawnSyncinbeforeEachto return{ status: 0 }, so they continue passing on macOS/Linux dev boxes where wsl is unavailable.installation_mode='native'(bypass works)Suite: 16/16 pass. Total 77/77 across all related test files. Lint clean. TypeScript clean.
Test plan
npx jest tests/unit/quality-gates/cross-platform-coderabbit.test.js→ 16/16npx jest tests/core/workflow-executor.test.js→ existing tests still greennpm run lint→ cleannpm run typecheck→ cleanIssue
Closes #757
🤖 Generated with Claude Code
Summary by CodeRabbit
Release Notes
Bug Fixes
Tests