Files
w3cjandClaude Opus 5.5 e4b44b5994 fix(lima): limactl shell never starts a stopped VM past devvm's checks
In a terminal, limactl shell of a stopped VM asks whether to start it, yes by default (Lima 2.3.0, reproduced under a pty), and that start is Lima's own: no proxy or sandbox-exec profile (no QEMU wrapper on Linux), no pins, and no folderChanged, so the project folder's mount, by path on Linux's 9p, follows a link put at the path or makes a folder that's gone again. devvm opens a shell (Shell) and runs an agent's login (Exec) on the terminal after bringUp, so a guest that powered itself off between the two got that question. This is the start path the self-check's restart was suspected of: that restart goes through startOnce, but limactl shell didn't.

The limactl builder, which every limactl command of devvm's goes through, now gives limactl shell --start=false, which Lima has had since 2.0.0-rc.0 (devvm's oldest is 2.2): a stopped VM's shell or command fails at once ("instance is stopped"), without asking, and devvm's next launch starts it with every check. devvm limactl, which passes its arguments on as given, is unchanged.

TestShellNeverStarts checks Exec's, Shell's and the builder's limactl shell, and fails without the change; the lima package's and the CLI scripts' expected limactl shell calls name the flag, their negative patterns too, so none turns vacuous. Docs: How it works' Lima page's A stopped VM's shell; the changelog's Security hardening gets the line, its summary widened to cover both of its lines, and the release page its section.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-25 07:43:53 -07:00

139 lines
5.2 KiB
Plaintext

# devvm host, devvm code and devvm cursor: the folder's VM launched as
# devvm does without its shell (checked, started, self-checked, set up, in
# devvm's ssh config), then its host name shown, or its folder opened in
# VS Code or Cursor (a stub code or cursor) with the SSH agent devvm
# started with. The Include line is offered for the sandbox's own
# ~/.ssh/config only.
# No VM.
project web
! exec devvm host
stderr '^devvm: no_vm dir=\S*/web$'
! exec devvm code
stderr '^devvm: no_vm dir=\S*/web$'
! exec devvm cursor
stderr '^devvm: no_vm dir=\S*/web$'
! stderr cursor_agent_in_vm
# A stopped VM: started and set up, no shell. Without a terminal, the
# Include line is shown, not added.
exec devvm --network open --no-git-protect
vm_name WEB web
exec limactl stop $WEB
stub_reset
exec devvm host
stdout '^==> starting what=devvm-web-[0-9a-f]{14}$'
stdout '^ssh_include_needed line=Include /\S*/data/devvm/ssh_config$'
stderr '^devvm: ssh_include_yourself$'
stdout '^ssh_host_info dir=/\S*/web host=devvm-web$'
stub_calls
stdout '^limactl start --tty=false devvm-web-[0-9a-f]{14}$'
stdout 'tar -xf'
! stdout 'limactl shell --start=false --workdir /\S*/web devvm-web'
catg $DATA/ssh_config
stdout '^Host devvm-web devvm-web-[0-9a-f]{14}$'
! exists $HOME/.ssh
# With the line there: nothing asked. A size its state asks for waits for
# the running VM's next start, as on a launch.
exec sh -c 'mkdir -p "$HOME/.ssh" && echo "Include $DATA/ssh_config" > "$HOME/.ssh/config"'
# ssh by the folder's name reads devvm's ssh config in its data folder
# through that line: the real ssh resolves the name, connecting to nothing.
[exec:/usr/bin/ssh] exec /usr/bin/ssh -F $HOME/.ssh/config -G devvm-web
[exec:/usr/bin/ssh] stdout '^hostname 127\.0\.0\.1$'
[exec:/usr/bin/ssh] stdout '^userknownhostsfile \S*/data/devvm/vms/[0-9a-f]{14}/run/known_hosts$'
[exec:/usr/bin/ssh] stdout '^hostkeyalias devvm-web-[0-9a-f]{14}$'
json_set $WEB_dir/vm.json size.cpus=6
stub_reset
exec devvm host
! stdout 'starting|ssh_include'
stderr '^devvm: next_start_size vm=devvm-web-[0-9a-f]{14}\ndevvm: next_start count=1 vm=devvm-web-[0-9a-f]{14}$'
stdout '^ssh_host_info dir=/\S*/web host=devvm-web$'
stub_calls
! stdout 'limactl (start|edit)'
# devvm code: the folder in VS Code over Remote-SSH, with the SSH agent
# devvm started with, though this VM's own connections carry none.
env SSH_AUTH_SOCK=$WORK/user-agent.sock
stub_reset
exec devvm code
stub_calls
stdout '^code --remote ssh-remote\+devvm-web /\S*/web$'
exec sh -c 'cat "$STUB_DIR/code-agent"'
stdout '^\S*/user-agent\.sock$'
# devvm cursor: the same in the Cursor editor, with its cursor command,
# first warning that Cursor's Agent will run in the VM while Cursor's
# user settings on this machine don't route it through the app here.
stub_reset
exec devvm cursor
stderr '^devvm: cursor_agent_in_vm file=.*/Cursor/User/settings\.json$'
stub_calls
stdout '^cursor --remote ssh-remote\+devvm-web /\S*/web$'
! stdout '^code '
exec sh -c 'cat "$STUB_DIR/cursor-agent"'
stdout '^\S*/user-agent\.sock$'
env SSH_AUTH_SOCK=
# With the route set there, no warning, and the file stays as it was.
[darwin] env CURSOR_USER=$HOME/Library/Application' Support'/Cursor/User
[!darwin] env CURSOR_USER=$XDG_CONFIG_HOME/Cursor/User
mkdir $CURSOR_USER
cp $WORK/cursor-settings.json $CURSOR_USER/settings.json
exec devvm cursor
! stderr cursor_agent_in_vm
cmp $CURSOR_USER/settings.json $WORK/cursor-settings.json
# Two folders named web: the VM by its full name.
mkdir $WORK/other/web
cd $WORK/other/web
exec devvm --network open --no-git-protect
stub_reset
exec devvm code
stub_calls
stdout '^code --remote ssh-remote\+devvm-web-[0-9a-f]{14} /\S*/other/web$'
stub_reset
exec devvm cursor
stub_calls
stdout '^cursor --remote ssh-remote\+devvm-web-[0-9a-f]{14} /\S*/other/web$'
# No code or cursor command on PATH: said, with the host to connect to,
# and no warning about Cursor's Agent, without Cursor's settings too.
rm $CURSOR_USER/settings.json
exec sh -c 'mkdir "$WORK/nocode" && for f in "$(dirname "$DEVVM_HOST_MISE")"/*; do case "${f##*/}" in code|cursor) ;; *) ln -s "$f" "$WORK/nocode/";; esac; done'
env SAVED_PATH=$PATH
env PATH=$DEVVM_BIN:$WORK/nocode:/usr/bin:/bin:/usr/sbin:/sbin
stub_reset
! exec devvm code
stderr '^devvm: no_code_command host=devvm-web-[0-9a-f]{14}$'
! exec devvm cursor
stderr '^devvm: no_cursor_command host=devvm-web-[0-9a-f]{14}$'
! stderr cursor_agent_in_vm
stub_calls
! stdout '^(code|cursor) '
env PATH=$SAVED_PATH
# Network policy: a VM devvm started confined that still reaches the
# internet directly is stopped, as on a launch; no host name. (Its
# hostagent here: the test's runner, which runs on, in place of the
# stub's.)
project leak
exec devvm --network allowlist --no-git-protect
vm_name LEAK leak
exec sh -c 'echo $PPID > "$LIMA_HOME/$LEAK/ha.pid"; echo "$PPID 1" > "$LEAK_dir/run/started"'
stub_reset
exec sh -c ': > "$STUB_DIR/net-direct"'
! exec devvm host
stderr '^devvm: net_direct_route vm=devvm-leak-[0-9a-f]{14}$'
! stdout ssh_host_info
stub_calls
stdout '^limactl stop devvm-leak-[0-9a-f]{14}$'
! stdout 'tar -xf'
rm $STUB_DIR/net-direct
-- cursor-settings.json --
// Cursor's user settings, with comments and a trailing comma.
{
"editor.fontSize": 14,
"cursorAgentHost.remoteInferenceRoute": "always",
}