fix: drop /root/repo fallback in vm exec for unbound VMs
vm exec defaulted execGuestPath to /root/repo whenever the VM had no recorded workspace, so running it against a plain VM (one that never had vm workspace prepare / vm run ./repo) blew up with 'cd: /root/repo: No such file or directory' — surfaced via the login shell's mise activate hook because bash -lc sources profile.d before the explicit cd. Now auto-cd only fires when --guest-path is passed or the VM actually has a workspace recorded; otherwise the command runs from root's home. Mise wrapping unchanged — without a .mise.toml it's a no-op. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
9400bab6fd
commit
b0a9d64f4a
3 changed files with 81 additions and 18 deletions
35
internal/cli/vm_exec_test.go
Normal file
35
internal/cli/vm_exec_test.go
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
package cli
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestBuildVMExecScriptWithGuestPath(t *testing.T) {
|
||||
got := buildVMExecScript("/root/repo", []string{"make", "test"})
|
||||
want := "cd '/root/repo' && if command -v mise >/dev/null 2>&1; then mise exec -- 'make' 'test'; else 'make' 'test'; fi"
|
||||
if got != want {
|
||||
t.Fatalf("buildVMExecScript with path:\n got: %q\n want: %q", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildVMExecScriptWithoutGuestPath(t *testing.T) {
|
||||
got := buildVMExecScript("", []string{"whoami"})
|
||||
want := "if command -v mise >/dev/null 2>&1; then mise exec -- 'whoami'; else 'whoami'; fi"
|
||||
if got != want {
|
||||
t.Fatalf("buildVMExecScript without path:\n got: %q\n want: %q", got, want)
|
||||
}
|
||||
if strings.Contains(got, "cd ") {
|
||||
t.Fatalf("expected no cd when guestPath is empty, got: %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildVMExecScriptShellQuotesPathWithSpaces(t *testing.T) {
|
||||
got := buildVMExecScript("/tmp/with space", []string{"echo", "a b"})
|
||||
if !strings.Contains(got, "cd '/tmp/with space'") {
|
||||
t.Fatalf("expected guest path to be shell-quoted, got: %q", got)
|
||||
}
|
||||
if !strings.Contains(got, "mise exec -- 'echo' 'a b'") {
|
||||
t.Fatalf("expected command args to be shell-quoted, got: %q", got)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue