Files
devvm/testdata/script/existing.txtar
T
w3cjandClaude Opus 5.5 f2aa210bf7 feat(up): existing VMs, restart, remove, update, adopt and rm
devvm opens a VM that exists instead of refusing it: unfinished VMs
(no state or no network choice) are refused before anything; --backend,
--network-policy, --no-git-protect, --cpus/--memory/--disk and --ports
are ignored with a warning each; an IMAGE naming what the VM lacks adds
it in place after asking (tools built and listed, a layer's script run
in the VM, new agents' folders mounted with a stop first); outdated
images and newer tools are warned about, the daily tools check runs,
agent folder mounts follow the host's, .git is checked per run, set-id
files are named on Linux, a stopped VM gets the size and ports its state
asks for (a running one is told they apply at its next start); then it
is started if stopped (a running VM with network policy keeps its
proxy), the self-check runs (a failure stops the VM), and it is set up
and its shell opened.

Commands: restart (stop, then open), update (newest shared tools, built
from base, then open), remove TOOLS (out of the image and tool list,
then open), adopt (a VM made for an earlier folder at this path, after
asking; .git protection restarts as appeared), rm [-f] (exports the
agents' history first unless -f, a failed export keeps the VM; a VM of
an earlier folder only after asking, without export; deletes the VM,
state, proxy, rules, run files, logs, .git locks, host keys and ssh
config entry, also when the delete failed but left no VM).

Inventory:
- vm: find/findExisting/existing, sameFolder, open, run, setUp,
  warnIgnored, checkSetID, applySize, applyPorts, addLayers,
  wantedImage, runScript, buildTools; Restart, Remove, Update, Adopt,
  Rm, export, delete; start refuses vm_unfinished and stops a leftover
  proxy for VMs without network policy
- gitprotect: Protector.Check (replaced, appeared, new submodules in
  the tree and .git/modules, unlocked hooks, commondir, delegations on
  change; locks only while stopped; unset protection set up as new),
  Locked field; platform.Immutable
- tools.Update takes a build func; build.Builder.LayerScript exported
- cli: restart, remove, update, adopt, rm; withEnv; root Long
- messages: vm_other_folder (reworded), vm_other_folder_rm/_adopt,
  delete_other_folder_vm, adopt_vm, vm_adopted, vm_already_here, no_vm,
  vm_unfinished, backend/net/git_protect/ports_flag_ignored,
  size_flags_ignored, size_next_start, ports_next_start, add_in_place,
  restart_for_mounts, no_terminal_confirm, keeping, adding,
  add_layer_failed, vm_is_now, exported, export_failed, deleted,
  rm_failed, adopt_failed, git_replaced, git_appeared,
  git_embedded_new, git_hooks_unlocked; net_unenforced_stop says devvm
  starts it again confined; vm_exists removed
- tests: testscript existing.txtar, existing_agents.txtar; Go tests for
  Check (five per-run reports, replaced/appeared, off/unset), open with
  network policy, addLayers, Rm, Adopt, remove/update/restart; limactl
  stub: delete-fails, Exec-fed scripts
- converted bats: delete (vm_unfinished, rm cleans up after a failed
  delete, rm deletes only this VM), project (folder made again, update
  twice, remove twice, five .git per-run reports), ports (applied once,
  restart warning), size (restart warning), cli (rm forgets host keys)
- e2e: project (stop and relaunch, running relaunch, restart with host
  keys, swapped .git, new submodule locked, rm unlocks; agent folder
  added/removed on restart, rm exports history without logins), tools
  (update, remove), network (relaunch confined, unenforced relaunch
  stops it, rm -f)
- docs: commands.md (existing VM, adding, deleting, a folder made
  again), coding-agents.md (mounts on launch, history), git-protection
  (on each launch), images, network, security; CLI reference

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-24 12:07:16 -06:00

168 lines
5.6 KiB
Plaintext

# A VM that exists: devvm opens it as it is, starting it if it's stopped,
# and sets it up again; flags for new VMs are ignored with a warning, and
# what its state asks of a stopped VM's size and ports is applied.
# restart stops it first.
env DEVVM_MESSAGES=names
env VMS=$XDG_DATA_HOME/devvm/vms
env KNOWN=$XDG_CONFIG_HOME/devvm/known_hosts
mkdir $WORK/web
cd $WORK/web
exec git init -q
exec devvm --no-network-policy base
# Running: opened without a start, its host keys kept, set up again.
exec sh -c ': > "$STUB_LOG"'
exec devvm
! stdout 'starting|creating'
! stderr .
stub_calls
! stdout 'limactl (start|stop|clone|create|edit|delete)'
stdout '^limactl shell --workdir / devvm-web-[0-9a-f]{14} sh -c .*tar -xf - '
stdout '^limactl shell --workdir /\S*/web devvm-web-[0-9a-f]{14}\n\z'
exec grep -c '^devvm-web-' $KNOWN
stdout '^1$'
# Flags for new VMs: ignored, with a warning each; --backend names the
# backend it stays on.
exec devvm --network-policy --cpus 2 --ports none --backend lima
stderr '^devvm: net_flag_ignored$'
stderr '^devvm: size_flags_ignored$'
stderr '^devvm: ports_flag_ignored$'
! stderr backend_flag_ignored
exec devvm --no-git-protect
stderr '^devvm: git_protect_flag_ignored$'
exec sh -c 'grep -c "^net=off$" "$VMS"/devvm-web-*'
stdout '^1$'
# A size or ports its state asks for: a running VM's wait for its next
# start; a stopped one's are applied once.
exec sh -c 'f=$(ls "$VMS"/devvm-web-*); printf "cpus=6\nports=5173\n" >> "$f"'
exec sh -c ': > "$STUB_LOG"'
exec devvm
stderr '^devvm: size_next_start vm=devvm-web-[0-9a-f]{14}$'
stderr '^devvm: ports_next_start vm=devvm-web-[0-9a-f]{14}$'
stub_calls
! stdout 'limactl edit'
# Stopped: started, its host keys read again.
exec sh -c 'limactl stop "$(basename "$VMS"/devvm-web-*)"'
exec sh -c ': > "$STUB_LOG"'
exec devvm
stdout '^==> starting vm=devvm-web-[0-9a-f]{14}$'
! stderr 'next_start'
stub_calls
stdout '^limactl edit --tty=false devvm-web-[0-9a-f]{14} --cpus 6$'
stdout '^limactl edit --tty=false devvm-web-[0-9a-f]{14} --set \.portForwards = \[\{"guestPortRange":\[5173,5173\],"proto":"any"\}'
stdout '^limactl start --tty=false devvm-web-[0-9a-f]{14}$'
stdout 'sh -c .*/etc/ssh/ssh_host_'
exec sh -c 'cat "$VMS"/devvm-web-*'
stdout '^ports_set=5173$'
# (The stub's VM gets the size its edit asked for.)
exec sh -c 'echo "6 8589934592 107374182400" > "$STUB_DIR/size-$(basename "$VMS"/devvm-web-*)"'
exec sh -c 'limactl stop "$(basename "$VMS"/devvm-web-*)"'
exec sh -c ': > "$STUB_LOG"'
exec devvm
stub_calls
! stdout 'limactl edit'
# restart: stopped, then opened.
exec sh -c ': > "$STUB_LOG"'
exec devvm restart
stdout '^==> starting vm=devvm-web-[0-9a-f]{14}$'
stub_calls
stdout '^limactl stop devvm-web-[0-9a-f]{14}\n(.*\n)*limactl start --tty=false devvm-web-[0-9a-f]{14}\n'
stdout '^limactl shell --workdir /\S*/web devvm-web-[0-9a-f]{14}\n\z'
! exec devvm restart base
stderr usage_error
# An image naming what it lacks adds it in place, after asking: without
# a terminal, nothing changes.
! exec devvm go
stderr '^devvm: no_terminal_confirm vm=devvm-web-[0-9a-f]{14} want=go$'
exec sh -c 'cat "$VMS"/devvm-web-*'
stdout '^image=base$'
# Naming what it has adds nothing.
exec devvm base
! stderr no_terminal_confirm
# A VM without a network choice didn't finish being made: never started
# (it would start without network policy); rm deletes it.
exec sh -c 'f=$(ls "$VMS"/devvm-web-*); grep -v "^net=" "$f" > "$f.new" && mv "$f.new" "$f"'
exec sh -c 'limactl stop "$(basename "$VMS"/devvm-web-*)"'
exec sh -c ': > "$STUB_LOG"'
! exec devvm
stderr '^devvm: vm_unfinished vm=devvm-web-[0-9a-f]{14}$'
! exec devvm restart
stderr '^devvm: vm_unfinished vm=devvm-web-[0-9a-f]{14}$'
stub_calls
! stdout 'limactl (start|stop)'
# rm: base has no agents, so nothing is exported; only this VM is
# deleted, with its state, logs, host keys and ssh config entry, and .git's
# locks taken off.
mkdir $WORK/api
cd $WORK/api
exec devvm --no-network-policy base
cd $WORK/web
exec sh -c 'touch "$XDG_DATA_HOME/devvm/logs/$(basename "$VMS"/devvm-web-*).jsonl"'
exec sh -c ': > "$STUB_LOG"'
exec devvm rm
stdout '^==> deleted vm=devvm-web-[0-9a-f]{14}$'
! stdout exported
stub_calls
stdout '^limactl delete -f devvm-web-[0-9a-f]{14}$'
! stdout 'delete -f devvm-api'
! stdout 'limactl (start|shell)'
[darwin] stdout '^chflags -R -P nouchg /\S*/web/\.git/config$'
exec sh -c 'ls "$VMS"'
! stdout devvm-web
stdout devvm-api
exec sh -c 'ls "$XDG_DATA_HOME/devvm/logs"'
! stdout devvm-web
exec cat $KNOWN
! stdout devvm-web
stdout devvm-api
exec cat $XDG_CONFIG_HOME/devvm/ssh_config
! stdout devvm-web
stdout devvm-api
! exec devvm rm
stderr '^devvm: no_vm dir=/\S*/web$'
! exec devvm restart
stderr '^devvm: no_vm dir=/\S*/web$'
! exec devvm update
stderr '^devvm: no_vm dir=/\S*/web$'
! exec devvm adopt
stderr '^devvm: no_vm dir=/\S*/web$'
# A delete that fails but leaves no VM cleans up like one that worked.
cd $WORK/api
exec sh -c ': > "$STUB_DIR/delete-fails"'
exec devvm rm -f
stdout '^==> deleted vm=devvm-api-[0-9a-f]{14}$'
exec sh -c 'ls "$VMS"'
! stdout devvm-api
rm $STUB_DIR/delete-fails
# A folder made again at the same path: rm and adopt ask first, so
# without a terminal neither deletes nor takes the VM over.
mkdir $WORK/site
cd $WORK/site
exec devvm --no-network-policy base
cd $WORK
rm site
mkdir site
cd site
exec sh -c ': > "$STUB_LOG"'
! exec devvm
stderr '^devvm: vm_other_folder vm=devvm-site-[0-9a-f]{14} was=/\S*/site$'
! exec devvm rm -f
stderr '^devvm: vm_other_folder_rm vm=devvm-site-[0-9a-f]{14} was=/\S*/site$'
! exec devvm adopt
stderr '^devvm: vm_other_folder_adopt vm=devvm-site-[0-9a-f]{14} was=/\S*/site$'
! exec devvm restart
stderr '^devvm: vm_other_folder '
stub_calls
! stdout 'limactl (delete|stop|start)'
exec sh -c 'ls "$VMS"'
stdout devvm-site