mirror of
https://github.com/devvmhq/devvm.git
synced 2026-12-01 21:36:40 -10:00
A VM deleted outside devvm (limactl delete, smolvm machine delete, docker rm) left its state, logs, run files, backend files, ssh config entry and host keys, and gc kept its tools. --orphans finds each VM whose state names a backend that answers (Check and List, 30 s each) and that, asked by Inspect, doesn't have it (vm.Leftovers.Find), lists them with their project folders, asks in a terminal, and deletes what devvm keeps for each as devvm rm does after its delete (Lifecycle's tail, now forget), after asking the backend once more. Backends delete their own leftovers through backend.Forgetter: Lima its port records, sandbox profile and start record; smolvm its record, proxy file, ssh key and forwarder files; Docker its relay, networks, ssh keys, labelled volumes and commit image. Each refuses a VM it has. Never an orphan, each said with a note: a VM whose backend can't be asked or isn't this devvm's (gc_orphans_unknown); one made where this run's backend doesn't look (gc_orphan_elsewhere) - new VMs record backend_at, a hash of backend.LocationOf: Lima's home (DEVVM_LIMA_HOME), smolvm's HOME on macOS, Docker's engine ID and name - and a VM without the record counts only when its backend looks in its default place; one whose state changed in the last hour, as a VM being made has its state before its backend has it (gc_orphan_recent). When a backend a VM uses can't list its images, gc stops before deleting anything, as before. devvm space: the leftover row says gc --orphans; VMs with devvm's label that this devvm has no state for (another devvm's, a sandbox's) are named with their label's data folder (space_stray, backend.StrayFinder), and never deleted. Messages: gc_orphans, gc_orphan, forgot_orphan, gc_orphans_unknown, gc_orphan_elsewhere, gc_orphan_recent, space_stray. Docs: the What devvm keeps page (leftovers, VMs devvm has no state for, how to delete one), using/images.md's Cleaning up, the CLI reference. Review (a backend down, slow or answering garbage; a VM moved between Lima homes; smolvm under another HOME; Docker Desktop vs a Linux engine; a VM being made): down, slow (timeout) or unreadable answers make a backend unknown, never its VMs orphans; moved homes and engines are caught by backend_at; a VM being made is recent; Forget re-asks the backend and each Forgetter refuses a VM it has. Tests: gc_orphans.txtar (a live Lima VM and its files kept, a deleted one forgotten with its logs, run and port files, a Docker one's volume deleted, a smolvm one, another Lima home, no record under a non-default home, a recent state, an unknown backend; no backend delete runs; gc stops when smolvm can't list); tools.txtar (backend_at recorded). Co-Authored-By: Claude Opus 5.5 <[email protected]>
117 lines
5.1 KiB
Plaintext
117 lines
5.1 KiB
Plaintext
# The shared tools: their versions resolved on first use (the stub mise
|
|
# resolves the fixture lock), built in a throwaway VM from base, moved into
|
|
# the share with their hashes, listed in a VM's state and sent to it.
|
|
env DEVVM_MESSAGES=names
|
|
env DATA=$XDG_DATA_HOME/devvm
|
|
env SHARE=$XDG_DATA_HOME/devvm/tools
|
|
mkdir $WORK/web
|
|
cd $WORK/web
|
|
cp $WORK/package.json package.json
|
|
|
|
# An agent named in a node project goes on top of node.
|
|
exec devvm --no-network-policy --no-git-protect claude
|
|
stdout '^==> detected found=node$'
|
|
stdout '^==> resolving_tools$'
|
|
stdout '^==> building_tools tools=node 24\.21\.0, pnpm 12\.10\.1, bun 1\.4\.2, claude 2\.1\.295$'
|
|
stdout '^==> creating_from image=node\+claude vm=devvm-web-[0-9a-f]{14}$'
|
|
cmp $DATA/mise.lock $MISE_STUB_LOCK
|
|
exists $DATA/mise.lock.toml
|
|
exists $DATA/mise.lock.checked
|
|
stub_calls
|
|
stdout '^mise lock --platform linux-(arm64|x64),linux-(arm64|x64)-musl$'
|
|
# The build VM is a clone of base whose only mount is a folder of its own,
|
|
# never the share; it gets the tools and versions, and goes.
|
|
stdout '^limactl clone --tty=false --mount-none --set \.mounts = \[\{"location":"\S*/data/devvm/tools-build\.[0-9]+","mountPoint":"/mnt/devvm-tools","writable":true\}\] devvm-img-[0-9a-f]{12} devvm-tools-build$'
|
|
! stdout '"location":"\S*/data/devvm/tools","mountPoint":"/mnt/devvm-tools","writable":true'
|
|
stdout '^limactl shell --workdir / devvm-tools-build bash -s -- node 24\.21\.0 node-24\.21\.0-[0-9a-f]{12}\.erofs pnpm \S+ pnpm-\S+\.erofs bun 1\.4\.2 bun-1\.4\.2-[0-9a-f]{12}\.erofs claude 2\.1\.295 claude-2\.1\.295-[0-9a-f]{12}\.erofs$'
|
|
stdout '^limactl delete -f devvm-tools-build$'
|
|
# The VM is made from base's image, with the share read-only.
|
|
stdout '^limactl clone --tty=false devvm-img-[0-9a-f]{12} devvm-web-[0-9a-f]{14} --mount-none --set \.mounts = \[.*\{"location":"\S*/data/devvm/tools","mountPoint":"/mnt/devvm-tools","writable":false\}\]'
|
|
exec sh -c 'cat "$DATA"/vms/devvm-web-*'
|
|
stdout '^image=node\+claude$'
|
|
stdout '^libc=gnu$'
|
|
stdout '^backend_at=[0-9a-f]{16}$'
|
|
stdout '^tools=node-24\.21\.0-[0-9a-f]{12}\.erofs pnpm-\S+ bun-1\.4\.2-[0-9a-f]{12}\.erofs claude-2\.1\.295-[0-9a-f]{12}\.erofs$'
|
|
# Each image in the share with its hash and what it's built for; nothing
|
|
# left of the build.
|
|
exec sh -c 'cd "$SHARE" && for f in *.erofs; do [ "$(cat "$f.sha256")" = "$(shasum -a 256 < "$f" 2>/dev/null | cut -c1-64 || sha256sum < "$f" | cut -c1-64)" ] || echo "bad $f"; grep -qx libc=gnu "$f.target" || echo "bad target $f"; done; ls | wc -l'
|
|
! stdout bad
|
|
stdout '^ *12$'
|
|
! exists $SHARE/.lock
|
|
exec sh -c 'ls -d "$DATA"/tools-build.* 2>/dev/null || true'
|
|
! stdout .
|
|
# What the VM was sent: assets/guest/'s sync.sh and tools.sh, and its tool list.
|
|
exec tar -xOf $STUB_DIR/sync.tar tools
|
|
stdout '^node-24\.21\.0-[0-9a-f]{12}\.erofs node 24\.21\.0$'
|
|
stdout '^claude-2\.1\.295-[0-9a-f]{12}\.erofs claude 2\.1\.295$'
|
|
stdout -count=4 '\.erofs '
|
|
exec tar -tf $STUB_DIR/sync.tar
|
|
stdout '^sync\.sh$'
|
|
stdout '^tools\.sh$'
|
|
# The build's steps are numbered: clone, configure, start, build.sh, delete.
|
|
exec sh -c 'cat "$DATA"/logs/runs/*.log'
|
|
stdout '^# \[4/5\] building_tools_in vm=devvm-tools-build$'
|
|
stdout '^# \[5/5\] deleting vm=devvm-tools-build$'
|
|
|
|
# Built: nothing to build, nothing to resolve.
|
|
exec sh -c ': > "$STUB_LOG"'
|
|
exec devvm build node+claude
|
|
! stdout 'building_tools|resolving_tools'
|
|
stub_calls
|
|
! stdout 'devvm-tools-build|mise'
|
|
|
|
# The daily check: a new VM with tools checks first when it's due.
|
|
exec touch -t 202001010000 $DATA/mise.lock.checked
|
|
mkdir $WORK/api
|
|
cd $WORK/api
|
|
exec devvm --no-network-policy --no-git-protect go
|
|
stdout '^==> checking_tools$'
|
|
stdout '^==> building_tools tools=go 1\.27\.2$'
|
|
# Not again today.
|
|
mkdir $WORK/cli
|
|
cd $WORK/cli
|
|
exec devvm --no-network-policy --no-git-protect go+claude
|
|
! stdout 'checking_tools|building_tools'
|
|
|
|
# The shared tools aren't images: rebuild refuses them.
|
|
! exec devvm rebuild node+claude
|
|
stderr '^devvm: tools_not_images tools=node claude$'
|
|
|
|
# The daily check's job, run by hand: a failure leaves the lock.
|
|
env MISE_STUB_FAIL=1
|
|
! exec devvm _refresh-tools
|
|
stderr 'failed to fetch versions: offline'
|
|
stderr '^devvm: tools_resolve_failed$'
|
|
cmp $DATA/mise.lock $MISE_STUB_LOCK
|
|
env MISE_STUB_FAIL=
|
|
exec devvm _refresh-tools
|
|
exec devvm --help
|
|
! stdout _refresh-tools
|
|
|
|
# Offline with no lock yet: what's needed, and mise's error from the log.
|
|
rm $DATA/mise.lock
|
|
env MISE_STUB_FAIL=1
|
|
! exec devvm build python
|
|
stdout '^==> resolving_tools$'
|
|
stderr 'failed to fetch versions: offline'
|
|
stderr '^devvm: tools_need_resolve$'
|
|
! exists $DATA/mise.lock
|
|
env MISE_STUB_FAIL=
|
|
|
|
# A build that leaves a symlink instead of an image is refused; one that
|
|
# plants FILE.sha256 as a symlink can't make devvm write through it.
|
|
exec sh -c 'echo victim > "$STUB_DIR/tools-symlink"'
|
|
! exec devvm build python
|
|
stderr '^devvm: tool_bad_output file=python-\S+\.erofs$'
|
|
exec sh -c 'ls "$SHARE"'
|
|
! stdout python
|
|
exec sh -c 'rm "$STUB_DIR/tools-symlink" && echo victim > "$STUB_DIR/tools-hash-symlink"'
|
|
exec devvm build python
|
|
exec cat $STUB_DIR/tools-hash-symlink
|
|
stdout '^victim$'
|
|
exec sh -c 'cd "$SHARE" && for f in python-*.erofs uv-*.erofs; do [ -L "$f.sha256" ] && echo link; done; true'
|
|
! stdout link
|
|
|
|
-- package.json --
|
|
{}
|