Skip to content

feat(quality-gates): probe WSL availability before CodeRabbit invocation — fixes #757 - #761

Merged
rafaelscosta merged 1 commit into
mainfrom
fix/wsl-availability-probe-757
May 18, 2026
Merged

feat(quality-gates): probe WSL availability before CodeRabbit invocation — fixes #757#761
rafaelscosta merged 1 commit into
mainfrom
fix/wsl-availability-probe-757

Conversation

@rafaelscosta

@rafaelscosta rafaelscosta commented May 18, 2026

Copy link
Copy Markdown
Collaborator

Summary

Add an explicit WSL availability probe in workflow-executor.js and layer2-pr-automation.js before constructing the wsl bash -c command 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 the installation_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 host
  • status !== 0 — wsl installed but no distribution available

In both failure modes, throw:

CodeRabbit CLI requires WSL on Windows hosts. Install WSL via `wsl --install` (https://learn.microsoft.com/windows/wsl/install), then install the CodeRabbit CLI inside the WSL distribution. See docs/guides/installation-troubleshooting.md Issue 10. To bypass this check, set coderabbit.installation_mode='native' in your config.

The graceful-degradation try/catch in runCodeRabbit already 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')) so jest.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.js extended from 12 to 16 cases:

  • Existing 12 WSL command-shape tests now mock spawnSync in beforeEach to return { status: 0 }, so they continue passing on macOS/Linux dev boxes where wsl is unavailable.
  • 4 new tests cover:
    • ENOENT probe failure surfaces actionable error
    • non-zero exit probe failure surfaces same actionable error
    • probe is NOT invoked when installation_mode='native' (bypass works)
    • probe is NOT invoked on macOS native invocation (no waste)

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/16
  • npx jest tests/core/workflow-executor.test.js → existing tests still green
  • npm run lint → clean
  • npm run typecheck → clean
  • Manual smoke on macOS dev: pre-push CodeRabbit gate still runs (mode auto-detects native, probe never fires)
  • Manual smoke (when available): Windows host without WSL — see the new error message instead of cmd.exe's generic one

Issue

Closes #757

🤖 Generated with Claude Code

Summary by CodeRabbit

Release Notes

  • Bug Fixes

    • Improved Windows/WSL compatibility detection for CodeRabbit integration with enhanced validation to prevent execution failures when WSL is unavailable.
    • Enhanced error messaging to guide users on WSL setup or platform configuration options.
  • Tests

    • Added cross-platform validation tests for WSL availability scenarios.

Review Change Stack

…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>
@vercel

vercel Bot commented May 18, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
aiox-core Ready Ready Preview, Comment May 18, 2026 11:43am

Request Review

@github-actions github-actions Bot added type: test Test coverage and quality area: core Core framework (.aios-core/core/) area: docs Documentation (docs/) labels May 18, 2026
@coderabbitai

coderabbitai Bot commented May 18, 2026

Copy link
Copy Markdown

Walkthrough

Windows hosts running CodeRabbit in WSL mode now receive a preflight WSL availability check that runs wsl -l synchronously before command construction. Both orchestration and PR automation modules implement the same probe logic; when WSL is unavailable or has no distribution, a detailed error with installation guidance is thrown. Unit tests cover the probe outcomes and verify the check is skipped in native mode. Manifest timestamps and hashes are updated.

Changes

WSL availability probe and child process refactoring

Layer / File(s) Summary
WSL probe in workflow-executor.js
.aiox-core/core/orchestration/workflow-executor.js
runCodeRabbitAnalysis refactors to use promisify(childProcess.exec) and adds a synchronous wsl -l probe when installation_mode is wsl on Windows; throws a detailed error with WSL setup instructions if the probe fails.
WSL probe and spawn refactoring in layer2-pr-automation.js
.aiox-core/core/quality-gates/layer2-pr-automation.js
Import style changed to childProcess namespace; runCodeRabbit adds an identical WSL availability probe with error handling; runCommand updated to use childProcess.spawn instead of destructured spawn.
Test coverage for WSL probe behavior
tests/unit/quality-gates/cross-platform-coderabbit.test.js
Imports child_process and sets up a default spawnSync mock in beforeEach to simulate WSL availability; afterEach restores the mock. New test suite validates error outcomes when wsl is missing (ENOENT) or unavailable (non-zero exit), and verifies the probe is skipped when installation_mode='native' on Windows or on macOS native mode.
Manifest updates
.aiox-core/install-manifest.yaml
Generated timestamp and content hashes/sizes refreshed for workflow-executor.js and layer2-pr-automation.js.

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
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

  • SynkraAI/aiox-core#752: Introduces cross-platform CodeRabbit CLI execution for Windows/WSL; this PR adds the WSL availability probe on top of that foundation.

Suggested labels

area: core, area: workflows, area: devops, type: test

Suggested reviewers

  • Pedrovaleriolopez
  • oalanicolas
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: adding a WSL availability probe before CodeRabbit invocation on Windows, with a direct reference to issue #757.
Linked Issues check ✅ Passed The PR fulfills all coding requirements from issue #757: WSL availability probe via spawnSync, error handling for ENOENT and non-zero exit codes, and actionable error messages.
Out of Scope Changes check ✅ Passed All changes are directly aligned with issue #757 objectives: WSL probe implementation, refactored child_process imports for testability, and comprehensive unit test coverage.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/wsl-availability-probe-757

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions

Copy link
Copy Markdown
Contributor

📊 Coverage Report

Coverage report not available

📈 Full coverage report available in Codecov


Generated by PR Automation (Story 6.1)

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 win

Add non-zero exit code handling to prevent silent quality gate bypass.

After the WSL probe passes, runCommand() resolves on every exit code (including failures), and runCodeRabbit() never checks result.exitCode. If the CodeRabbit binary is missing inside the WSL distribution or crashes, the method parses empty output, finds zero issues, and returns pass: 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 win

Add 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

📥 Commits

Reviewing files that changed from the base of the PR and between 1e1f64d and 4c6577c.

📒 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.yaml
  • tests/unit/quality-gates/cross-platform-coderabbit.test.js

@rafaelscosta
rafaelscosta merged commit 6216cda into main May 18, 2026
43 checks passed
@rafaelscosta
rafaelscosta deleted the fix/wsl-availability-probe-757 branch May 18, 2026 11:49
tuanmedeiros pushed a commit to tuanmedeiros/aios-core-synkraay that referenced this pull request Jun 2, 2026
…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: core Core framework (.aios-core/core/) area: docs Documentation (docs/) type: test Test coverage and quality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add WSL availability check on Windows before invoking CodeRabbit (Issue #731 follow-up)

1 participant