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

103 lines
3.8 KiB
Plaintext

# devvm host and devvm code: the folder's VM launched as devvm does without
# its shell (checked, started, self-checked, set up, in devvm's ssh
# config), then its host name shown, or its folder opened in VS Code (a
# stub code) with the SSH agent devvm started with. The Include line is
# offered for the sandbox's own ~/.ssh/config only.
# No VM.
project web
! exec devvm host
stderr '^devvm: no_vm dir=\S*/web$'
! exec devvm code
stderr '^devvm: no_vm dir=\S*/web$'
! exec devvm host now
stderr '^devvm: args_none command=devvm host given=now$'
! exec devvm code .
stderr '^devvm: args_none command=devvm code given=\.$'
# A stopped VM: started and set up, no shell. Without a terminal, the
# Include line is shown, not added.
exec devvm --no-network-policy --no-git-protect
vm_name WEB web
exec limactl stop $WEB
stub_reset
exec devvm host
stdout '^==> starting vm=devvm-web-[0-9a-f]{14}$'
stdout '^ssh_include_needed line=Include /\S*/data/devvm/ssh_config$'
stderr '^devvm: ssh_include_yourself$'
stdout '^ssh_host_info dir=/\S*/web host=devvm-web$'
stub_calls
stdout '^limactl start --tty=false devvm-web-[0-9a-f]{14}$'
stdout 'tar -xf'
! stdout 'limactl shell --workdir /\S*/web devvm-web'
catg $DATA/ssh_config
stdout '^Host devvm-web devvm-web-[0-9a-f]{14}$'
! exists $HOME/.ssh
# With the line there: nothing asked. A size its state asks for waits for
# the running VM's next start, as on a launch.
exec sh -c 'mkdir -p "$HOME/.ssh" && echo "Include $DATA/ssh_config" > "$HOME/.ssh/config"'
# ssh by the folder's name reads devvm's ssh config in its data folder
# through that line: the real ssh resolves the name, connecting to nothing.
[exec:/usr/bin/ssh] exec /usr/bin/ssh -F $HOME/.ssh/config -G devvm-web
[exec:/usr/bin/ssh] stdout '^hostname 127\.0\.0\.1$'
[exec:/usr/bin/ssh] stdout '^userknownhostsfile \S*/data/devvm/known_hosts$'
[exec:/usr/bin/ssh] stdout '^hostkeyalias devvm-web-[0-9a-f]{14}$'
exec sh -c 'echo cpus=6 >> "$WEB_dir/state"'
stub_reset
exec devvm host
! stdout 'starting|ssh_include'
stderr '^devvm: size_next_start vm=devvm-web-[0-9a-f]{14}$'
stdout '^ssh_host_info dir=/\S*/web host=devvm-web$'
stub_calls
! stdout 'limactl (start|edit)'
# devvm code: the folder in VS Code over Remote-SSH, with the SSH agent
# devvm started with, though this VM's own connections carry none.
env SSH_AUTH_SOCK=$WORK/user-agent.sock
stub_reset
exec devvm code
stub_calls
stdout '^code --remote ssh-remote\+devvm-web /\S*/web$'
exec sh -c 'cat "$STUB_DIR/code-agent"'
stdout '^\S*/user-agent\.sock$'
env SSH_AUTH_SOCK=
# Two folders named web: the VM by its full name.
mkdir $WORK/other/web
cd $WORK/other/web
exec devvm --no-network-policy --no-git-protect
stub_reset
exec devvm code
stub_calls
stdout '^code --remote ssh-remote\+devvm-web-[0-9a-f]{14} /\S*/other/web$'
# No code command on PATH: said, with the host to connect to.
exec sh -c 'mkdir "$WORK/nocode" && for f in "$(dirname "$DEVVM_HOST_MISE")"/*; do [ "${f##*/}" = code ] || ln -s "$f" "$WORK/nocode/"; done'
env SAVED_PATH=$PATH
env PATH=$DEVVM_BIN:$WORK/nocode:/usr/bin:/bin:/usr/sbin:/sbin
stub_reset
! exec devvm code
stderr '^devvm: no_code_command host=devvm-web-[0-9a-f]{14}$'
stub_calls
! stdout '^code '
env PATH=$SAVED_PATH
# Network policy: a VM devvm started confined that still reaches the
# internet directly is stopped, as on a launch; no host name. (Its
# hostagent here: the test's runner, which runs on, in place of the
# stub's.)
project leak
exec devvm --network-policy --no-git-protect
vm_name LEAK leak
exec sh -c 'echo $PPID > "$LIMA_HOME/$LEAK/ha.pid"; echo "$PPID 1" > "$LEAK_dir/run/started"'
stub_reset
exec sh -c ': > "$STUB_DIR/net-direct"'
! exec devvm host
stderr '^devvm: net_direct_route vm=devvm-leak-[0-9a-f]{14}$'
! stdout ssh_host_info
stub_calls
stdout '^limactl stop devvm-leak-[0-9a-f]{14}$'
! stdout 'tar -xf'
rm $STUB_DIR/net-direct