Skip to content

fix: reject unknown subcommands on the host instead of forwarding them - #4

Open
kapil-agnihotri wants to merge 1 commit into
mainfrom
fix/reject-unknown-subcommands
Open

fix: reject unknown subcommands on the host instead of forwarding them#4
kapil-agnihotri wants to merge 1 commit into
mainfrom
fix/reject-unknown-subcommands

Conversation

@kapil-agnihotri

Copy link
Copy Markdown

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.

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>

Copilot AI 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.

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 calls loadConfig() 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. Point configPath at 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.

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.

2 participants