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>
35 lines
1.2 KiB
Go
35 lines
1.2 KiB
Go
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)
|
|
}
|
|
}
|