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]>
50 lines
1.5 KiB
Plaintext
50 lines
1.5 KiB
Plaintext
# devvm stop: stops the folder's VM and its proxy, then checks .git as a
|
|
# launch that finds it stopped does (locking it again on macOS), and drops
|
|
# the VM from devvm's ssh config.
|
|
|
|
# No VM.
|
|
project web
|
|
! exec devvm stop
|
|
stderr '^devvm: no_vm dir=\S*/web$'
|
|
! exec devvm stop now
|
|
stderr '^devvm: args_none command=devvm stop given=now$'
|
|
|
|
# A running VM with network policy: it stops, then its proxy. (Its
|
|
# hostagent here: the test's runner, which runs on, so the proxy runs until
|
|
# stopped; the stub's would be gone after devvm.)
|
|
exec git init -q
|
|
exec sh -c 'echo $PPID > "$STUB_DIR/hostagent"'
|
|
exec devvm --network-policy
|
|
catg $DATA/ssh_config
|
|
stdout '^Host devvm-web devvm-web-[0-9a-f]{14}$'
|
|
exec sh -c 'cat "$VMS"/*/run/proxy.pid > "$WORK/pid" && kill -0 "$(cat "$WORK/pid")"'
|
|
stub_reset
|
|
exec devvm stop
|
|
stdout '^==> stopped vm=devvm-web-[0-9a-f]{14}$'
|
|
stub_calls
|
|
stdout '^limactl stop devvm-web-[0-9a-f]{14}$'
|
|
[darwin] stdout '^limactl stop devvm-web-[0-9a-f]{14}\n(.*\n)*chflags -R -P uchg /\S*/web/\.git/hooks$'
|
|
! stdout 'limactl (start|edit)'
|
|
! exec sh -c 'kill -0 "$(cat "$WORK/pid")"'
|
|
catg $DATA/ssh_config
|
|
! stdout devvm-web
|
|
|
|
# Already stopped: said; .git is checked all the same.
|
|
stub_reset
|
|
exec devvm stop
|
|
stdout '^==> already_stopped vm=devvm-web-[0-9a-f]{14}$'
|
|
! stdout '==> stopped'
|
|
stub_calls
|
|
! stdout 'limactl stop'
|
|
|
|
# A VM made for an earlier folder at this path isn't stopped.
|
|
cd $WORK
|
|
rm web
|
|
mkdir web
|
|
cd web
|
|
stub_reset
|
|
! exec devvm stop
|
|
stderr '^devvm: vm_other_folder vm=devvm-web-[0-9a-f]{14} was=/\S*/web$'
|
|
stub_calls
|
|
! stdout 'limactl stop'
|