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

284 lines
12 KiB
Plaintext

# devvm 0.1.0's state (testdata/v0.1.0/GOOS, which 0.1.0 itself made:
# see its README), read and used by this devvm: four VMs (app: node,
# Claude Code and Codex, allowlist, ports, .git protected on macOS, the
# github secret, a link to db and a group; db: publishes 5432; web:
# --clone and Claude Code; scratch: no network, .git protection off),
# 0.1.0's defaults, its agent store and logins. Nothing is migrated: the
# layout version stays, the read-only commands change no file, each
# --json has all that 0.1.0's had, and a launch starts the VM as it is,
# with only the notes an upgrade brings. Then today's commands work on
# app as 0.1.0 left it: a repo nested in its folder, .git pins on a Linux
# host that has them, a secret of your own, and devvm rm.
[!darwin] [!linux] skip 'a fixture for macOS and Linux only'
env GIT_AUTHOR_NAME=t GIT_AUTHOR_EMAIL=t@t GIT_COMMITTER_NAME=t GIT_COMMITTER_EMAIL=t@t
# The projects' folders, as the user has them, then 0.1.0's state for
# them.
mkdir $HOME/src/db $HOME/src/app $HOME/src/web $HOME/src/scratch
cd $HOME/src/app
exec git init -q -b main
exec git commit -q --allow-empty -m one
cd $HOME/src/web
exec git init -q -b main
exec git commit -q --allow-empty -m one
cd $HOME/src/scratch
exec git init -q
fixture v0.1.0
vm_name APP app
vm_name DB db
vm_name WEB web
vm_name SCRATCH scratch
exec sh -c 'mkdir "$WORK/before" && cp -R "$DATA" "$WORK/before/data" && cp -R "$CFG" "$WORK/before/config"'
# Every VM is listed as 0.1.0 listed it, without a warning.
exec devvm ls
[darwin] stdout '^devvm-app-[0-9a-f]{14} +Stopped +base +node,claude,codex +on +allowlist +1 '
[linux] stdout '^devvm-app-[0-9a-f]{14} +Stopped +base +node,claude,codex +off +allowlist +1 '
stdout '^devvm-db-[0-9a-f]{14} +Stopped +base +- +off +allowlist +- '
stdout '^devvm-scratch-[0-9a-f]{14} +Stopped +base +claude +off +none +- '
stdout '^devvm-web-[0-9a-f]{14} +Stopped +base +go,claude +clone +open +- '
! stderr .
exec devvm ls --json
cp stdout $WORK/ls.json
json_superset $WORK/fixture/json/ls.json $WORK/ls.json
! stderr .
# The global settings and the store, read as 0.1.0 saved them.
exec devvm secret --json
cp stdout $WORK/secret.json
json_superset $WORK/fixture/json/secret.json $WORK/secret.json
exec devvm network -g --json
cp stdout $WORK/network-g.json
json_superset $WORK/fixture/json/network-g.json $WORK/network-g.json
exec devvm ports -g --json
cp stdout $WORK/ports-g.json
json_superset $WORK/fixture/json/ports-g.json $WORK/ports-g.json
exec devvm retention --json
cp stdout $WORK/retention.json
json_superset $WORK/fixture/json/retention.json $WORK/retention.json
# The images and tools: newer catalogs and keys, so their shape only.
exec devvm images --json
cp stdout $WORK/images.json
json_superset -shape $WORK/fixture/json/images.json $WORK/images.json
# Each VM's own settings, as 0.1.0 showed them.
cd $HOME/src/web
exec devvm clone --json
cp stdout $WORK/clone.json
json_superset $WORK/fixture/json/clone.json $WORK/clone.json
cd $HOME/src/app
exec devvm git-protect
[darwin] stdout '\Aon\n\z'
[linux] stdout '\Aoff\n\z'
exec devvm git-protect --json
cp stdout $WORK/git-protect.json
json_superset $WORK/fixture/json/git-protect.json $WORK/git-protect.json
exec devvm network
stdout '\Aallowlist\n'
exec devvm network --json
cp stdout $WORK/network.json
json_superset $WORK/fixture/json/network.json $WORK/network.json
exec devvm ports --json
cp stdout $WORK/ports.json
json_superset $WORK/fixture/json/ports.json $WORK/ports.json
exec devvm link --json
cp stdout $WORK/link.json
json_superset $WORK/fixture/json/link.json $WORK/link.json
exec devvm group --json
cp stdout $WORK/group.json
json_superset $WORK/fixture/json/group.json $WORK/group.json
exec devvm size --json
cp stdout $WORK/size.json
json_superset $WORK/fixture/json/size.json $WORK/size.json
exec devvm tools --json
cp stdout $WORK/tools.json
json_superset -shape $WORK/fixture/json/tools.json $WORK/tools.json
exec devvm ssh-agent --json
cp stdout $WORK/ssh-agent.json
json_superset $WORK/fixture/json/ssh-agent.json $WORK/ssh-agent.json
cd $HOME/src/scratch
exec devvm git-protect
stdout '\Aoff\n\z'
exec devvm network
stdout '\Anone\n'
# 0.1.0 chose no cache mode for the project folder: on Linux it keeps
# Lima's mmap, with the warning each launch gives; macOS has no such
# choice.
cd $HOME/src/app
[linux] exec devvm mount-cache --json
[linux] stdout '\A{\n "version": 1,\n "mode": "mmap",\n "chosen": false\n}\n\z'
[linux] stderr '^devvm: mount_cache_unchosen mode=mmap vm=devvm-app-[0-9a-f]{14}$'
[darwin] ! exec devvm mount-cache
[darwin] stderr '^devvm: backend_lacks backend=lima feature=mount-cache what=devvm-app-[0-9a-f]{14}$'
# devvm doctor reads every VM's state and each of its sections as a
# launch does, and can use all of 0.1.0's.
exec devvm doctor
! stderr 'vm_state_broken|vm_state_unreadable|corrupt'
# None of that wrote a file: the layout version is 0.1.0's, and every
# state is as 0.1.0 left it.
exec diff -r -x logs $WORK/before/data $DATA
exec diff -r $WORK/before/config $CFG
grep '\A1\n\z' $DATA/version
grep '\A1\n\z' $CFG/version
# A launch: app starts as it is, its Lima config unchanged (an edit
# would give it new host keys), its .git locked again on macOS. What an upgrade
# says: base and the tools are newer than the VM's, Codex's login has a
# field devvm doesn't know, which the VM doesn't get, while Claude Code's
# account has only fields it knows, and the link's target is stopped.
cd $HOME/src/app
cp $APP_dir/vm.json $WORK/app-before.json
cp $APP_dir/run/secrets.json $WORK/app-secrets.json
stub_reset
exec devvm
stdout '^==> starting what=devvm-app-[0-9a-f]{14}$'
stderr '^devvm: vm_outdated changed=base$'
stderr '^devvm: newer_tools tools='
stderr '^devvm: login_fields_withheld agent=Codex file=auth\.json keys=extra_field$'
! stderr 'login_fields_withheld agent=Claude'
stderr '^devvm: link_target_stopped target=devvm-db-[0-9a-f]{14} vm=devvm-app-[0-9a-f]{14}$'
! stderr 'unreadable|corrupt|layout_|moved|replaced|refused|failed'
# The github secret 0.1.0 saved is found, and the bindings file it wrote
# is written again byte for byte: the placeholder the VM has is the same.
! stderr no_github_token
cmp $APP_dir/run/secrets.json $WORK/app-secrets.json
# On Linux, where the tests' host can't pin (DEVVM_PINS), .git is
# unprotected, as it was, and the watch 0.1.0 didn't have takes its first
# scan, which reports nothing. 0.1.0 recorded off on Linux, the one mode
# it could set there, so app is warned of, never refused for the pins it
# lacks.
[linux] stderr '^devvm: git_unprotected vm=devvm-app-[0-9a-f]{14}$'
[linux] ! stderr backend_lacks
! stderr 'git_changed|git_watch_blind'
# Its project folder keeps the cache mode it has, Lima's mmap on Linux,
# with a warning until a mode is chosen: no edit.
[linux] stderr '^devvm: mount_cache_unchosen mode=mmap vm=devvm-app-[0-9a-f]{14}$'
[darwin] ! stderr mount_cache_unchosen
stub_calls
stdout '^limactl start --tty=false devvm-app-[0-9a-f]{14}$'
# Its ssh port, which 0.1.0 chose from the whole range, moves onto the
# ports browsers refuse (here the sandbox's own, DEVVM_SSH_PORTS), in one
# edit of that alone.
stdout '^limactl edit --tty=false devvm-app-[0-9a-f]{14} --set \.ssh\.localPort=[0-9]+$'
! stdout '(?s)limactl edit .*limactl edit'
! stdout 'limactl (create|clone|delete)'
[darwin] stdout '^chflags -R -P uchg \S*/home/src/app/\.git/config$'
stdout '^limactl shell --start=false --workdir \S*/home/src/app devvm-app-[0-9a-f]{14}$'
# The launch kept every field 0.1.0 wrote, but the start it records and
# its ssh port, now one of the sandbox's list.
json_superset -changes .agent.made.started -changes .ports.host.ssh $WORK/app-before.json $APP_dir/vm.json
exec sh -c 'p=$(sed -n "s/.*\"ssh\": \([0-9]*\).*/\1/p" "$APP_dir/vm.json") && case ",$DEVVM_SSH_PORTS," in *",$p,"*) ;; *) exit 1 ;; esac'
vm_state $APP_dir/vm.json
stdout '^agent\.made\.started=off_[0-9a-f]{32}$'
[linux] stdout '^git\.mode=off$'
[darwin] stdout '^git\.mode=on$'
[linux] stdout '^git\.watched\.scanned=true$'
[darwin] ! stdout '^git\.watched'
grep '\A1\n\z' $DATA/version
# scratch and web start too, with the same notes, their Lima configs
# unchanged but their ssh ports, and nothing said of nested repos or the
# github secret, which neither has.
cd $HOME/src/scratch
stub_reset
exec devvm
stdout '^==> starting what=devvm-scratch-[0-9a-f]{14}$'
stderr '^devvm: vm_outdated changed=base$'
! stderr 'unreadable|corrupt|layout_|moved|replaced|refused|failed'
! stderr 'git_nested|no_github_token'
[linux] stderr '^devvm: mount_cache_unchosen mode=mmap vm=devvm-scratch-[0-9a-f]{14}$'
stub_calls
stdout '^limactl edit --tty=false devvm-scratch-[0-9a-f]{14} --set \.ssh\.localPort=[0-9]+$'
! stdout '(?s)limactl edit .*limactl edit'
! stdout 'limactl (create|clone|delete)'
# web is a --clone VM: it mounts no project folder to cache.
cd $HOME/src/web
stub_reset
exec devvm
stdout '^==> starting what=devvm-web-[0-9a-f]{14}$'
stderr '^devvm: vm_outdated changed=base$'
! stderr 'unreadable|corrupt|layout_|moved|replaced|refused|failed'
! stderr 'git_nested|no_github_token'
! stderr mount_cache_unchosen
stub_calls
stdout '^limactl edit --tty=false devvm-web-[0-9a-f]{14} --set \.ssh\.localPort=[0-9]+$'
! stdout '(?s)limactl edit .*limactl edit'
! stdout 'limactl (create|clone|delete)'
# devvm agent save reads web's Claude Code settings, which are 0.1.0's
# store's.
exec devvm agent save --no-input
stdout '^==> agent_save_nothing vm=devvm-web-[0-9a-f]{14}$'
! stderr .
grep '\A1\n\z' $DATA/version
# A repo nested in app's folder, which 0.1.0's protection, its own repo's
# alone, doesn't cover. On macOS, the stop's check says once that devvm
# git-protect on covers it, which then locks it. On Linux, where app's
# .git is unprotected and watched, the stop names the repo that appeared
# while the VM ran, and the watch covers it from then on, so the next
# launch names only app's own .git.
cd $HOME/src/app
exec git init -q lib
exec devvm stop
[darwin] stderr '^devvm: git_nested_protectable repos=lib vm=devvm-app-[0-9a-f]{14}$'
[linux] stderr '^devvm: git_nested_appeared repo=lib vm=devvm-app-[0-9a-f]{14}$'
[darwin] exec devvm stop
[darwin] ! stderr git_nested
[darwin] stub_reset
[darwin] exec devvm git-protect on
[darwin] stdout '^==> git_locked vm=devvm-app-[0-9a-f]{14}$'
[darwin] stub_calls
[darwin] stdout '^chflags -R -P uchg \S*/home/src/app/lib/\.git/config$'
[linux] exec devvm
[linux] stderr '^devvm: git_unprotected vm=devvm-app-[0-9a-f]{14}$'
[linux] ! stderr git_nested
[linux] exec devvm stop
[linux] ! stderr git_nested
vm_state $APP_dir/vm.json
stdout '^git\.made\.nested=true$'
stdout '^git\.made\.repos\.lib\.git_id=[0-9]+:[0-9]+'
# On a Linux host that pins (DEVVM_PINS), app, which 0.1.0 left
# unprotected, is told it can be locked now; devvm git-protect on turns it
# on, and the next start pins .git, nested repos too.
[linux] env DEVVM_PINS=on
[linux] exec devvm
[linux] stderr '^devvm: git_protect_available vm=devvm-app-[0-9a-f]{14}$'
[linux] exec devvm stop
[linux] exec devvm git-protect on
[linux] exec devvm
[linux] ! stderr 'git_protect_available|git_unprotected|git_nested_unprotected'
[linux] grep '"root":"\S*/home/src/app",' $APP_dir/run/git-pins.json
[linux] grep '\{"path":"\.git/config","read_only":true\}' $APP_dir/run/git-pins.json
[linux] grep '\{"path":"lib/\.git/config","read_only":true\}' $APP_dir/run/git-pins.json
[linux] exec devvm stop
# A secret of your own, used in app next to 0.1.0's github secret: its
# state lists both, and its bindings file keeps github's placeholder.
stdin $WORK/stripe.token
exec devvm secret set stripe --host api.stripe.com --env STRIPE_API_KEY --stdin
exec devvm secret use stripe
vm_state $APP_dir/vm.json
stdout '^secrets\.names=github stripe$'
stdout '^secrets\.yours\.0\.name=stripe$'
grep '^\{"version":1,' $APP_dir/run/secrets.json
grep '"name":"stripe","kind":"secret"' $APP_dir/run/secrets.json
exec sh -c 'grep -o "{\"name\":\"github\"[^}]*}" "$WORK/app-secrets.json" >"$WORK/github.binding" && test -s "$WORK/github.binding" && grep -qF -f "$WORK/github.binding" "$APP_dir/run/secrets.json"'
# devvm rm unlocks every .git it locked, nested ones too, keeps none for
# another VM, and deletes the VM.
stub_reset
exec devvm rm --force --no-export
! stderr git_kept_
stub_calls
[darwin] stdout '^chflags -R -P nouchg \S*/home/src/app/\.git/config$'
[darwin] stdout '^chflags -R -P nouchg \S*/home/src/app/lib/\.git/config$'
stdout '^limactl delete -f devvm-app-[0-9a-f]{14}$'
-- stripe.token --
sk_test_fixturefakev010