Skip to content

boxcli: fix VS Code binary path resolution on macOS#2806

Open
joshgodsiff wants to merge 1 commit intojetify-com:mainfrom
joshgodsiff:fix/vscode-binary-path-macos
Open

boxcli: fix VS Code binary path resolution on macOS#2806
joshgodsiff wants to merge 1 commit intojetify-com:mainfrom
joshgodsiff:fix/vscode-binary-path-macos

Conversation

@joshgodsiff
Copy link

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.

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.

The WSL fix in 4ba6fce constructs the editor binary path as
$VSCODE_CWD/bin/code. On WSL, VSCODE_CWD points to the VS Code
installation directory, so this works. On macOS however, VSCODE_CWD
is set to the workspace directory, producing a bogus path like
/Users/user/my-project/bin/code which does not exist.

Add 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. Extract the logic into a standalone
resolveEditorBinary function with tests covering both cases.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant