Fix VS Code "Reopen in Devbox shell environment" in WSL by apgrucza · Pull Request #2729 · jetify-com/devbox

@joshgodsiff @claude

## Summary

The WSL fix in #2729 (4ba6fce) broke "Reopen in Devbox shell
environment" on macOS.

That commit constructs the VS Code binary path as
`$VSCODE_CWD/bin/code`. On WSL, `VSCODE_CWD` points to the VS Code
installation directory (e.g., `/mnt/c/.../Microsoft VS Code`), so this
works correctly. On macOS however, `VSCODE_CWD` is set to the workspace
directory, producing a path like `/Users/user/my-project/bin/code` —
which doesn't exist:

e.g. The debug logs on my machine gives:

```
fork/exec /Users/josh/src/my-project/bin/code: no such file or directory
```

This PR adds an os.Stat check so the constructed path is only used when
the binary actually exists there, falling back to the bare command name
(resolved via `PATH`) otherwise. The resolution logic is extracted into
a `resolveEditorBinary` function with unit tests covering:

- `VSCODE_CWD` unset → uses bare name
- `VSCODE_CWD` points to a VS Code installation (WSL) → uses full path
- `VSCODE_CWD` points to a workspace directory (macOS) → falls back to
bare name

## How was it tested?

- Unit tests for `resolveEditorBinary` covering all three scenarios
- `go test -race -cover ./internal/boxcli/` passes
- `golangci-lint run ./internal/boxcli/` passes

## Community Contribution License

All community contributions in this pull request are licensed to the
project
maintainers under the terms of the
[Apache 2 License](https://www.apache.org/licenses/LICENSE-2.0).

By creating this pull request, I represent that I have the right to
license the
contributions to the project maintainers under the Apache 2 License as
stated in
the
[Community Contribution
License](https://github.com/jetify-com/opensource/blob/main/CONTRIBUTING.md#community-contribution-license).

Co-authored-by: Josh Godsiff <josh.godsiff@corro.co>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>