Skip to content

fix(sandbox): Make WSL backend tests deterministic - #948

Merged
kevincodex1 merged 1 commit into
Twigpine:mainfrom
euxaristia:fix/isolate-wsl-backend-test
Aug 25, 2026
Merged

kevincodex1 merged 1 commit into
Twigpine:mainfrom
euxaristia:fix/isolate-wsl-backend-test

Conversation

@euxaristia

@euxaristia euxaristia commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Make Linux backend selection tests deterministic on WSL hosts by allowing WSL detection to be injected. Production still defaults to detecting the real host environment.

Changes

  • Add DetectWSL to BackendOptions and SandboxManagerOptions.
  • Use the production detectWSL() implementation when no detector is supplied.
  • Pin the non-WSL missing-helper fallback and add explicit WSL2 fallback coverage.

Test plan

  • go test ./internal/sandbox -run TestSelectBackendChoosesPlatformAdapterWithFallback/linux_helper_missing_falls_back_explicitly -count=1
  • go test ./...
  • go vet ./...

Fixes #947

Summary by CodeRabbit

  • Bug Fixes

    • Improved Linux sandbox detection when the standard helper is unavailable.
    • WSL2 environments are now clearly identified as an unavailable fallback with diagnostic information.
  • Tests

    • Added coverage verifying WSL2 fallback behavior for Linux systems lacking the sandbox helper.

Co-Authored-By: cairn-code <cairn-code@users.noreply.github.com>
@coderabbitai

coderabbitai Bot commented Aug 24, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: ddf9d000-8d9d-4830-970f-03cac2e42535

📥 Commits

Reviewing files that changed from the base of the PR and between ad34dc8 and be76466.

📒 Files selected for processing (3)
  • internal/sandbox/adapters.go
  • internal/sandbox/adapters_test.go
  • internal/sandbox/manager.go

Included review availability: Your plan provides up to 4 included reviews per hour; 3 remain after this review.


Walkthrough

Backend selection now accepts injectable WSL detection and preserves real detection by default. Tests cover Linux helper-missing fallback behavior for both non-WSL and WSL2 environments.

Changes

Sandbox backend WSL detection

Layer / File(s) Summary
Propagate injectable WSL detection
internal/sandbox/adapters.go, internal/sandbox/manager.go
BackendOptions and SandboxManagerOptions accept a DetectWSL callback. Backend selection forwards the callback and defaults to detectWSL when it is unset.
Cover non-WSL and WSL2 fallback paths
internal/sandbox/adapters_test.go
Tests inject non-WSL detection for the existing missing-helper case and verify the unavailable WSL2 fallback and diagnostic.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to be764

This localized change makes WSL backend selection tests deterministic while preserving production host detection defaults; no actionable merge-blocking risk remains after normal checks and review.

Suggested reviewers: anandh8x, vasanthdev2004, gnanam1990

🚥 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 describes the main change: making WSL backend tests deterministic.
Linked Issues check ✅ Passed The changes inject WSL detection, preserve production defaults, and add non-WSL and WSL2 fallback coverage required by issue #947.
Out of Scope Changes check ✅ Passed All changes support deterministic WSL backend selection tests and the linked issue objectives; no unrelated code changes are shown.
Docstring Coverage ✅ Passed Docstring check was indeterminate for this PR — some files could not be analyzed in time. Not blocking.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@Vasanthdev2004 Vasanthdev2004 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Approving. Right fix, and it is complete, which I checked rather than assumed.

The interesting question with a change like this is not whether the one named test is now pinned, but whether any other test still reaches the real host detector. Eyeballing the call sites is not proof, so I made detectWSL panic and ran the whole package on both heads:

main:    --- FAIL: TestSelectBackendChoosesPlatformAdapterWithFallback/linux_helper_missing_falls_back_explicitly
         panic: PRODUCTION detectWSL REACHED FROM A TEST

this PR: ok  github.com/Gitlawb/zero/internal/sandbox

Exactly one subtest was host-dependent, and after this nothing in the package touches the production detector. The other linux cases all supply a lookup that finds the helper, so they return before the WSL branch and never needed injecting.

Production behaviour is unchanged: selectPlatformBackend falls back to detectWSL when the field is nil, and both entry points forward it. gofmt clean, go vet clean for linux, darwin and windows, go build ./... clean.

Adding DetectWSL to the exported options structs is a test seam in a public API, but LookupExecutable is already exactly that in the same two structs, so it fits rather than sets a precedent.

The added WSL2 case is a real gain on its own: the positive branch had no coverage at all before, so nobody would have noticed if the fallback stopped reporting WSL2.

@kevincodex1
kevincodex1 merged commit e59bf78 into Twigpine:main Aug 25, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test(sandbox): Isolate WSL detection in backend selection tests

3 participants