fix: reject unknown subcommands on the host instead of forwarding them - #4
Open
kapil-agnihotri wants to merge 1 commit into
Open
fix: reject unknown subcommands on the host instead of forwarding them#4kapil-agnihotri wants to merge 1 commit into
kapil-agnihotri wants to merge 1 commit into
Conversation
The root command needs arbitrary args so `code-vm -- <cmd>` can forward a command to the guest, but cobra.ArbitraryArgs also handed any word it did not recognize as a subcommand straight into the VM. A typo, or a binary older than the subcommand being invoked, then surfaced as the guest shell's `exec: profile: not found` and exit 127 — after the VM had already been booted and entered — naming neither the real problem nor the host. Validate args instead: ArgsLenAtDash reports how many args preceded `--` (-1 when absent), so 0 is exactly the passthrough form. A bare invocation and `code-vm -- <cmd>` are unchanged; anything else fails on the host before the config is loaded, before Status, before boot. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR rejects unknown root-level arguments on the host while preserving explicit -- passthrough to the guest VM.
Changes:
- Added host-side argument validation.
- Added unit and integration coverage.
- Documented guest passthrough syntax.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Summary |
|---|---|
test-vm-sandbox.sh |
Adds an integration regression check. |
README.md |
Documents command forwarding behavior. |
internal/cli/root.go |
Rejects unknown commands before VM setup. |
internal/cli/root_test.go |
Tests rejection and explicit passthrough. |
Suppressed comments (1)
internal/cli/root_test.go:90
- Could this test use a missing or invalid config instead of
setupShellFixture? That helper callsloadConfig()itself and leaves a valid config in place, so the test only proves that no fake Lima calls occur; a regression that loads the config before rejecting the unknown word would still pass. PointconfigPathat a nonexistent config (and restore it) so this test also locks in the documented ordering before config loading.
setupShellFixture(t)
r := installFakeClient(t, "")
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The root command needs arbitrary args so
code-vm -- <cmd>can forward a command to the guest, but cobra.ArbitraryArgs also handed any word it did not recognize as a subcommand straight into the VM. A typo, or a binary older than the subcommand being invoked, then surfaced as the guest shell'sexec: profile: not foundand exit 127 — after the VM had already been booted and entered — naming neither the real problem nor the host.Validate args instead: ArgsLenAtDash reports how many args preceded
--(-1 when absent), so 0 is exactly the passthrough form. A bare invocation andcode-vm -- <cmd>are unchanged; anything else fails on the host before the config is loaded, before Status, before boot.