Files
devvm/testdata/script/script_cmds.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

62 lines
1.5 KiB
Plaintext

# The scripts' own commands, which every other script uses.
# The sandbox shows messages by name and names devvm's folders.
exec sh -c 'test "$DEVVM_MESSAGES" = names && test "$DATA" = "$XDG_DATA_HOME/devvm" && test "$VMS" = "$DATA/vms" && test "$RUN" = "$DATA/run" && test "$CFG" = "$XDG_CONFIG_HOME/devvm"'
# stub_reset forgets the stubs' calls, and empties stdout as an exec does.
exec gpgv x
stub_calls
stdout '^gpgv x$'
stub_reset
! stdout .
! stub_calls
exec gpgv y
stub_calls
cmp stdout calls
# catg cats the one file a glob matches; a glob matching none or two
# fails it.
mkdir $VMS/0123456789abcd
cp state $VMS/0123456789abcd/state
catg $VMS/*/state
cmp stdout state
! catg $VMS/*/policy
cp state $VMS/0123456789abcd/policy
! catg $VMS/0123456789abcd/*
catg $VMS/*/state
cmp stdout state
# vm_name sets a variable to the one VM whose state records a name made
# for a folder, and VAR_dir to its folder; a folder without state, another
# folder's VM, no VM or two fail it.
mkdir $VMS/0123456789abce
cp policy $VMS/0123456789abce/state
vm_name WEB web
exec echo $WEB $WEB_dir
stdout '^devvm-web-0123456789abcd .*/vms/0123456789abcd$'
! vm_name API api
mkdir $VMS/fedcba98765432
cp other $VMS/fedcba98765432/state
! vm_name WEB web
# project makes a folder in $WORK and goes to it; with git, a repo.
project app
exec pwd
stdout '/app$'
! exists .git
project repo git
exec pwd
stdout '/repo$'
exists .git
-- calls --
gpgv y
-- state --
name=devvm-web-0123456789abcd
image=base
-- policy --
example.com
-- other --
name=devvm-web-fedcba98765432
image=base