mirror of
https://github.com/devvmhq/devvm.git
synced 2026-12-01 21:36:40 -10:00
Every file devvm keeps for a project VM is in one folder, vms/<hash>/, where <hash> is the 14-hex hash of the project folder's path that the VM's name ends with: its state, its own rules (policy), its backend's files (backend/: record.json, key, known_hosts, proxy, ports and the port forwarder's ports.*), what its runs leave (run/: proxy.*, sandbox.sb, started, lifeline.pid, secrets.*, links.*) and its logs (logs/: network.jsonl, proxy.log, links.log). Build VMs keep the same layout in run/builds/<name>/. The top-level run/ holds only what isn't one VM's or must be short: the hashed control sockets, links' link-<hash>.sock/.ctl, the QEMU wrapper and the ports lock. A folder's VM is found by its path's hash (state.ReadHash), with the name and backend its state records, so devvm --backend docker then devvm in the same folder opens the one VM, and a backend's name limit applies to new VMs only. The state records the VM's name and its ssh alias, chosen once at creation (sshconfig.ChooseAlias) and never recomputed. Links' targets match recorded names, aliases and folders (project.Targets). One teardown (vmFolders.teardown) replaces Lifecycle.forget, undoCreate's own list, Leftovers.Forget's, Proxy.Forget and space's leftoverFiles: it stops the proxy and link session, then the pieces outside the folder (clone remote or .git locks, other VMs' links and the group, host keys, the backend's leftovers), removes the folder, and writes the ssh config. Each backend's Delete and Forget remove the VM's backend/ folder (vmssh.Forwards.Forget). A new VM made where an earlier one's folder was left clears it first. devvm space counts an orphan's whole folder as leftover state and the other VMs' logs as network logs. Path builders move into paths: Dirs.VMDir, Dirs.VM and paths.VM's files (secrets' BindingsFile/PolicyFile, netpolicy's run, EventLog, ProxyLog, LinkList, VMPolicyFile, Lima's profileFile, startedFile, forwards.file, vmssh.Forwards.file, links' LinksLog/linksPID, Docker's vmFile and lifeline), ToolLockConfig, ToolLockChecked and ToolsCheckLog; the user's cache folder for Lima's and smolvm's caches is Dirs.UserCache, from HOME, not os.UserCacheDir. Dirs.VMState, LimaVMs, SmolvmVM and DockerVM go. vmname.HashOf and IsHash, project.Hash. The proxy takes the links' sockets' folder (-link-sockets, devvm's run folder) apart from the links' list, which is in the VM's run folder. Tests: a VM made and removed (rm, gc --orphans) leaves nothing under vms/, and with network policy has no file named for it outside its folder (TestTeardownLeavesNothing); a new VM over an old folder starts clean; lookup finds a VM made on another backend with a long folder name and makes no second one (TestLookupOtherBackend, and in docker.txtar); the alias stays put when a second VM shares the folder name (TestChooseAlias, ssh.txtar); every socket fits under a 35-character home with the longest VM name (TestSocketsFit); space counts an orphan's whole folder (TestLeftoverFolders); paths.VM's files; state by hash and name; the proxy refuses a socket in the list's own folder. Co-Authored-By: Claude Opus 5.5 <[email protected]>
162 lines
5.2 KiB
Plaintext
162 lines
5.2 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 KNOWN=$DATA/known_hosts
|
|
project web git
|
|
exec devvm --no-network-policy
|
|
vm_name WEB web
|
|
|
|
# Running: opened without a start, its host keys kept, set up again.
|
|
stub_reset
|
|
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 grep -c '^net=off$' $WEB_dir/state
|
|
stdout '^1$'
|
|
|
|
# A size its state asks for: a running VM's waits for its next start; a
|
|
# stopped one's is applied once.
|
|
exec sh -c 'printf "cpus=6\n" >> "$WEB_dir/state"'
|
|
stub_reset
|
|
exec devvm
|
|
stderr '^devvm: size_next_start vm=devvm-web-[0-9a-f]{14}$'
|
|
stub_calls
|
|
! stdout 'limactl edit'
|
|
|
|
# Stopped: started, its host keys read again.
|
|
exec limactl stop $WEB
|
|
stub_reset
|
|
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 .*portForwards'
|
|
stdout '^limactl start --tty=false devvm-web-[0-9a-f]{14}$'
|
|
stdout '^ssh -F none -M .* -l stub 127\.0\.0\.1 sh -s$'
|
|
stdout 'sh -c .*/etc/ssh/ssh_host_'
|
|
# (The stub's VM gets the size its edit asked for.)
|
|
exec sh -c 'echo "6 8589934592 107374182400" > "$STUB_DIR/size-$WEB"'
|
|
exec limactl stop $WEB
|
|
stub_reset
|
|
exec devvm
|
|
stub_calls
|
|
! stdout 'limactl edit'
|
|
|
|
# restart: stopped, then opened.
|
|
stub_reset
|
|
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 '^devvm: args_none command=devvm restart given=base$'
|
|
|
|
# --tools, --agents and --layers change nothing on a VM that exists: it
|
|
# opens as it is, warning that devvm tools changes its shared tools.
|
|
exec devvm --tools go --layers docker
|
|
stderr '^devvm: parts_flags_ignored vm=devvm-web-[0-9a-f]{14}$'
|
|
! stdout new_vm_gets
|
|
catg $WEB_dir/state
|
|
stdout '^image=base$'
|
|
! stdout '^tool_names=.'
|
|
# Without them, nothing is said.
|
|
exec devvm
|
|
! stderr parts_flags_ignored
|
|
|
|
# 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="$WEB_dir/state"; grep -v "^net=" "$f" > "$f.new" && mv "$f.new" "$f"'
|
|
exec limactl stop $WEB
|
|
stub_reset
|
|
! 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 (the rotated ones too), host keys and ssh config entry, and .git's
|
|
# locks taken off.
|
|
project api
|
|
exec devvm --no-network-policy
|
|
vm_name API api
|
|
cd $WORK/web
|
|
exec sh -c 'l="$WEB_dir/logs" && mkdir -p "$l" && touch "$l/network.jsonl" "$l/network.jsonl.1" "$l/proxy.log" "$l/proxy.log.1"'
|
|
stub_reset
|
|
exec devvm rm --force
|
|
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$'
|
|
! exists $WEB_dir
|
|
exists $API_dir/state
|
|
exec cat $KNOWN
|
|
! stdout devvm-web
|
|
stdout devvm-api
|
|
exec cat $DATA/ssh_config
|
|
! stdout devvm-web
|
|
stdout devvm-api
|
|
! exec devvm rm --force
|
|
stderr '^devvm: no_vm dir=/\S*/web$'
|
|
! exec devvm restart
|
|
stderr '^devvm: no_vm dir=/\S*/web$'
|
|
! exec devvm tools update
|
|
stderr '^devvm: no_vm dir=/\S*/web$'
|
|
! exec devvm tools
|
|
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 --force --no-export
|
|
stdout '^==> deleted vm=devvm-api-[0-9a-f]{14}$'
|
|
! exists $API_dir
|
|
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.
|
|
project site
|
|
exec devvm --no-network-policy
|
|
cd $WORK
|
|
rm site
|
|
mkdir site
|
|
cd site
|
|
stub_reset
|
|
! exec devvm
|
|
stderr '^devvm: vm_other_folder vm=devvm-site-[0-9a-f]{14} was=/\S*/site$'
|
|
! exec devvm rm --force --no-export
|
|
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)'
|
|
vm_name SITE site
|
|
exists $SITE_dir/state
|