Files
devvm/testdata/script/tools.txtar
T
w3cjandClaude Opus 5.5 d8a7d4de7f refactor(state): a folder per VM, keyed by its project folder's hash
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]>
2026-11-03 08:16:39 -07:00

129 lines
6.0 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 SHARE=$XDG_DATA_HOME/devvm/tools
project web
cp $WORK/package.json package.json
# An agent chosen in a node project goes with node: the VM's image is
# base, and its shared tools are a list in its state.
exec devvm --no-network-policy --no-git-protect --agents claude
stdout '^==> new_vm_gets layers=none tools=node claude vm=devvm-web-[0-9a-f]{14}$'
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=base 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\}\]'
vm_name WEB web
catg $WEB_dir/state
stdout '^image=base$'
stdout '^tool_names=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 record: its hash, what it's built for,
# the backend that built it and when; nothing left of the build.
exec sh -c 'cd "$SHARE" && for f in *.erofs; do grep -qxF " \"sha256\": \"$({ sha256sum 2>/dev/null || shasum -a 256; } < "$f" | cut -c1-64)\"," "$f.json" || echo "bad $f"; grep -qxF " \"libc\": \"gnu\"," "$f.json" && grep -qxF " \"format\": \"\"," "$f.json" && grep -qxF " \"backend\": \"lima\"," "$f.json" || echo "bad target $f"; grep -qE "^ \"built\": \"[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9:]{8}Z\"$" "$f.json" || echo "bad time $f"; done; ls | wc -l'
! stdout bad
stdout '^ *8$'
! 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.
catg $DATA/logs/runs/*.log
stdout '^# \[4/5\] building_tools_in vm=devvm-tools-build$'
stdout '^# \[5/5\] deleting vm=devvm-tools-build$'
# Without a terminal, devvm tools lists the VM's tools; add and rm change
# its list and its tool files, built ones not built again.
stub_reset
exec devvm tools
stdout '^TOOL +VERSION +NEWER +BUILT$'
stdout '^claude +2\.1\.295 '
exec devvm tools rm claude
stdout '^==> vm_tools_now tools=node vm=devvm-web-[0-9a-f]{14}$'
catg $WEB_dir/state
stdout '^tool_names=node$'
! stdout 'claude-'
exec devvm tools add claude
! stdout 'building_tools|resolving_tools'
stdout '^==> vm_tools_now tools=node claude vm=devvm-web-[0-9a-f]{14}$'
catg $WEB_dir/state
stdout '^tool_names=node claude$'
stdout '^tools=.*claude-2\.1\.295-[0-9a-f]{12}\.erofs'
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
project api
exec devvm --no-network-policy --no-git-protect --tools go
stdout '^==> checking_tools$'
stdout '^==> building_tools tools=go 1\.27\.2$'
# Not again today.
project cli
exec devvm --no-network-policy --no-git-protect --tools go --agents claude
! stdout 'checking_tools|building_tools'
# The shared tools aren't images: build and rebuild refuse them.
! exec devvm rebuild node
stderr '^devvm: tool_not_layer tool=node$'
# 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
project py
! exec devvm --no-network-policy --no-git-protect --tools 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.json as a symlink can't make devvm write through it.
exec sh -c 'echo victim > "$STUB_DIR/tools-symlink"'
! exec devvm --no-network-policy --no-git-protect --tools 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 --no-network-policy --no-git-protect --tools 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.json" ] && echo link; done; true'
! stdout link
-- package.json --
{}