Files
devvm/testdata/script/mount_cache.txtar
T
w3cjandClaude Opus 5.5 b6954e1e11 refactor(vmname): a VM's name is a vmname.VM, parsed where it's read
vmname.VM is the name of every machine devvm runs on a backend: a
project VM, an image's machine (devvm-img-<key>), a build VM and a
remake's aside. Fields, parameters, results and map keys that held a VM's
name as a string now hold a VM, from the backend interface down to the
CLI's --json structs, whose output is byte for byte the same.

Boundary parsers, the only places a string becomes a VM:
- vmname.Parse: a project VM's name (state's vm.json name, export file
  names, devvm _links's argument, the forwarder's -vm, project.Nth)
- vmname.ParseListed: one path element, for what a backend lists
- VM.UnmarshalText: JSON (Lima's list, proxy config and events, links'
  targets in state, link lists); empty stays no VM
- vmname.Image(key), VM.Aside(), and typed constants for Lima's build VMs
- msg.M.VM: the VM a message's function took, read back

vmname's functions on names became methods (Hash, Slug, Short, Aside,
AsideHash, ImageKey, IsProject); Lima's image prefix moved to vmname;
vmname.Join joins VM lists. Messages' vm and vm_name fields are typed
by the generator. Seven messages whose field took something else became
what= (backend_lacks, backend_unreviewed, backend_unreviewed_used,
starting, deleting, configuring, running_script) and rm_vm_failed's
name=: the text is unchanged, the names-mode scripts follow.
Review.RequireFor names an image or the tools being built.

Typed sites per package (added lines with vmname.VM, non-test): msg 347
(generated), vm 124, lima 48, backendtest 32, vmssh 31, netpolicy 22,
backend 16, gitprotect 14, proxy 11, cli 11, project 10, state 8,
ports 6, paths 3, sshagent 2, sshconfig 2, tools 2.

The structure test's owners rule now fails on a field, parameter or
result named for a VM (vm, vms, otherVM, vmName) typed string, []string
or map[string]…, and on converting anything but a literal to vmname.VM
outside the files it lists; internal/stubtest is free. depguard holds
internal/vmname to the standard library, and the proxy may import it.

ParseListed and UnmarshalText refuse a name starting with -, which would read as a flag in limactl's argv, and vmname.Image refuses a key that's empty, holds a / or NUL, or makes a project VM's name, so Lima's ImageSize and DeleteImage no longer check it themselves. The check also fails on a *string VM name and an alias of vmname.VM, and says what it doesn't see.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-15 19:36:28 -07:00

213 lines
9.5 KiB
Plaintext

# devvm mount-cache [none]: how a VM caches its project folder's mount,
# which on a Linux host QEMU's 9p does. A new VM gets none, the one mode
# devvm sets; a VM whose mode nobody chose keeps Lima's mmap untouched,
# warned of at each launch, until devvm mount-cache none switches it from
# its next start, which makes it in one edit and mounts the folder again.
# On macOS the backend has no such choice.
cp $WORK/features-none.json $DATA/settings.json
# No VM yet; a mode that isn't none, and a value with --json, are refused
# before devvm looks for one.
project web
! exec devvm mount-cache
stderr '^devvm: no_vm_mount_cache dir=\S*/web$'
! exec devvm mount-cache mmap
stderr '^devvm: mount_cache_invalid value="mmap"$'
stderr '^usage_help command=devvm mount-cache$'
! stderr no_vm_mount_cache
! exec devvm mount-cache loose
stderr '^devvm: mount_cache_invalid value="loose"$'
! exec devvm mount-cache none none
stderr '^devvm: args_too_many '
! exec devvm mount-cache --json none
stderr '^devvm: json_shows_only command=devvm mount-cache$'
! exec devvm mount-cache -g
stderr '^devvm: flag_unknown '
# A new VM gets none: on Linux it's in its state, and its project folder
# is mounted with it as it's made.
stub_reset
exec devvm --network open --no-git-protect
! stderr mount_cache_unchosen
vm_name WEB web
vm_state $WEB_dir/vm.json
[linux] stdout '^mount\.cache=none$'
[darwin] ! stdout '^mount\.'
stub_calls
[linux] stdout '^limactl clone --tty=false \S+ devvm-web-[0-9a-f]{14} --mount-none --set \.mounts = \[\{"location":"\S*/web","writable":true,"9p":\{"cache":"none"\}\},'
[darwin] stdout '^limactl clone --tty=false \S+ devvm-web-[0-9a-f]{14} --mount-none --set \.mounts = \[\{"location":"\S*/web","writable":true\},'
# macOS: the VM's mode is refused, to show or to change.
[darwin] ! exec devvm mount-cache
[darwin] stderr '^devvm: backend_lacks backend=lima feature=mount-cache what=devvm-web-[0-9a-f]{14}$'
[darwin] ! exec devvm mount-cache none
[darwin] stderr '^devvm: backend_lacks backend=lima feature=mount-cache what=devvm-web-[0-9a-f]{14}$'
[darwin] stop 'the rest is a Linux host''s'
# Running: its mode, chosen, as it has it.
exec devvm mount-cache
stdout '\Anone\n\z'
! stderr .
exec devvm mount-cache --json
stdout '\A{\n "version": 1,\n "mode": "none",\n "chosen": true\n}\n\z'
exec devvm mount-cache none
stdout '^==> vm_mount_cache mode=none vm=devvm-web-[0-9a-f]{14}$'
# A VM whose mode nobody chose, as one made before devvm chose it: none
# in its state, and Lima's mmap on its mount. Its start leaves the mount
# as it is, and each launch warns.
exec limactl stop $WEB
json_set $WEB_dir/vm.json mount:={}
exec sh -c 'limactl edit "$1" --set ".mounts = [{\"location\":\"$(pwd -P)\",\"writable\":true},{\"location\":\"$DATA/tools\",\"mountPoint\":\"/mnt/devvm-tools\",\"writable\":false}]"' sh $WEB
stub_reset
exec devvm
stderr '^devvm: mount_cache_unchosen mode=mmap vm=devvm-web-[0-9a-f]{14}$'
stub_calls
! stdout 'limactl edit'
exec devvm
stderr '^devvm: mount_cache_unchosen '
exec devvm mount-cache --json
stdout '"mode": "mmap",\n "chosen": false'
stderr '^devvm: mount_cache_unchosen '
# Running, devvm mount-cache none waits for its next start.
stub_reset
exec devvm mount-cache none
stderr '^devvm: next_start count=1 vm=devvm-web-[0-9a-f]{14}$'
stub_calls
! stdout 'limactl (edit|stop)'
vm_state $WEB_dir/vm.json
stdout '^mount\.cache=none$'
exec devvm mount-cache
stdout '\Ammap\n\z'
stderr '^mount_cache_pending mode=none vm=devvm-web-[0-9a-f]{14}$'
exec devvm mount-cache --json
stdout '"pending": "none"'
exec devvm
stderr '^devvm: next_start_mount_cache vm=devvm-web-[0-9a-f]{14}$'
! stderr mount_cache_unchosen
# Stopped: the next start sets it in its one edit, then mounts the folder
# again and checks it; the start after that edits nothing.
exec limactl stop $WEB
stub_reset
exec devvm
stub_calls
stdout '^limactl edit --tty=false devvm-web-[0-9a-f]{14} --set \.mounts = \[\{"location":"\S*/web","writable":true,"9p":\{"cache":"none"\}\},'
! stdout '(?s)limactl edit --tty=false devvm-web.*limactl edit --tty=false devvm-web'
stdout '^limactl start --tty=false devvm-web-[0-9a-f]{14}\n(.*\n)*limactl shell --workdir / devvm-web-[0-9a-f]{14} sudo sh -c umount ''\S*/web'' \|\| exit 3; mount '
stdout '^limactl shell --workdir / devvm-web-[0-9a-f]{14} sh -c if mountpoint -q ''\S*/web''; then P=''\S*/web'' awk .* /proc/self/mountinfo; '
exec devvm mount-cache
stdout '\Anone\n\z'
! stderr .
exec limactl stop $WEB
stub_reset
exec devvm
stub_calls
! stdout 'limactl edit'
# A folder that isn't mounted after the remount gets one restart, whose
# boot mounts it. One that isn't mounted after the restart either fails
# the launch before its shell opens, naming devvm restart.
exec limactl stop $WEB
json_set $WEB_dir/vm.json mount:={}
exec sh -c 'limactl edit "$1" --set ".mounts = [{\"location\":\"$(pwd -P)\",\"writable\":true},{\"location\":\"$DATA/tools\",\"mountPoint\":\"/mnt/devvm-tools\",\"writable\":false}]"' sh $WEB
exec devvm mount-cache none
stdout '^==> mount_cache_pending mode=none vm=devvm-web-[0-9a-f]{14}$'
exec sh -c ': > "$STUB_DIR/mount-unmounted"'
stub_reset
! exec devvm
stderr '^devvm: mount_cache_unmounted vm=devvm-web-[0-9a-f]{14}$'
stub_calls
! stdout '^limactl shell --workdir \S*/web devvm-web'
stdout '(?s)sudo sh -c umount .*\nlimactl stop devvm-web-[0-9a-f]{14}\n(.*\n)*limactl start --tty=false devvm-web-[0-9a-f]{14}\n(.*\n)*limactl stop devvm-web-[0-9a-f]{14}\n'
! stdout '(?s)sudo sh -c umount .*sudo sh -c umount '
! stdout '(?s)(limactl start --tty=false devvm-web.*){3}'
rm $STUB_DIR/mount-unmounted
# The remount fails, as an Alpine guest's can, and leaves the folder
# unmounted: the restart's boot mounts it with none, and the launch goes
# on into its shell, with the restart in the run log. The restart is a
# whole start again, on the allowlist tier a proxy of its own, which
# warns of a policy line that isn't a rule once, not at each start.
exec limactl stop $WEB
json_set $WEB_dir/vm.json mount:={}
exec sh -c 'limactl edit "$1" --set ".mounts = [{\"location\":\"$(pwd -P)\",\"writable\":true},{\"location\":\"$DATA/tools\",\"mountPoint\":\"/mnt/devvm-tools\",\"writable\":false}]"' sh $WEB
exec devvm mount-cache none
exec devvm network allowlist
exec sh -c 'echo "example.com:x" >> "$CFG/policy"'
exec sh -c ': > "$STUB_DIR/remount-fails"'
stub_reset
exec devvm
! stderr 'mount_cache_'
stderr -count=1 '^devvm: policy_not_rule file=\S*/policy line=\d+ rule=example\.com:x$'
exec sh -c 'grep -v "example.com:x" "$CFG/policy" > "$WORK/p"; cat "$WORK/p" > "$CFG/policy"'
stub_calls
stdout '(?s)sudo sh -c umount .*\nlimactl stop devvm-web-[0-9a-f]{14}\n(.*\n)*limactl start --tty=false devvm-web-[0-9a-f]{14}\n(.*\n)*limactl shell --workdir \S*/web devvm-web-[0-9a-f]{14}\n'
! stdout '(?s)sudo sh -c umount .*sudo sh -c umount '
exec sh -c 'cat "$DATA"/logs/runs/*.log'
stdout 'devvm: devvm-web-[0-9a-f]{14}''s project folder after its remount: it isn''t mounted; restarting the VM$'
exec devvm mount-cache
stdout '\Anone\n\z'
rm $STUB_DIR/remount-fails
exec devvm stop
exec devvm network open
# A launch into a running VM whose folder isn't mounted is refused before
# its shell.
exec devvm
exec sh -c ': > "$STUB_DIR/mount-unmounted"'
stub_reset
! exec devvm
stderr '^devvm: project_unmounted vm=devvm-web-[0-9a-f]{14}$'
stub_calls
! stdout '^limactl shell --workdir \S*/web devvm-web'
rm $STUB_DIR/mount-unmounted
# A stored mmap, as a build of devvm before none alone wrote, is none
# chosen: the VM works, warns, and devvm mount-cache none switches it.
exec limactl stop $WEB
json_set $WEB_dir/vm.json mount.cache=mmap
exec sh -c 'limactl edit "$1" --set ".mounts = [{\"location\":\"$(pwd -P)\",\"writable\":true},{\"location\":\"$DATA/tools\",\"mountPoint\":\"/mnt/devvm-tools\",\"writable\":false}]"' sh $WEB
exec devvm mount-cache
stdout '\Ammap\n\z'
stderr '^devvm: mount_cache_unchosen mode=mmap '
exec devvm mount-cache none
stdout '^==> mount_cache_pending mode=none '
# A state with a mode devvm doesn't know is refused as the VM is found,
# naming its state file.
json_set $WEB_dir/vm.json mount.cache=loose
! exec devvm mount-cache
stderr '\S*/vm\.json: mount\.cache: mount_cache_invalid value="loose"'
# A VM an earlier devvm left strict, with no cache mode chosen, on a host
# that pins (DEVVM_PINS), as on is refused where it can't (git_pins.txtar):
# after devvm mount-cache none, one start converts strict to on and
# switches the cache in its one edit, then mounts the folder again.
env DEVVM_PINS=on
project app git
exec devvm --network open
vm_name APP app
exec devvm stop
json_set $APP_dir/vm.json mount:={} git.mode=strict
exec sh -c 'limactl edit "$1" --set ".mounts = [{\"location\":\"$(pwd -P)\",\"writable\":true},{\"location\":\"$DATA/tools\",\"mountPoint\":\"/mnt/devvm-tools\",\"writable\":false}]"' sh $APP
exec git config --file .git/config diff.ignoreSubmodules all
exec devvm mount-cache none
stdout '^==> mount_cache_pending mode=none vm=devvm-app-[0-9a-f]{14}$'
stub_reset
exec devvm
stderr '^devvm: git_strict_converted vm=devvm-app-[0-9a-f]{14}$'
! stderr 'mount_cache_unchosen|mount_cache_unchecked|mount_cache_unmounted'
stub_calls
stdout '^limactl edit --tty=false devvm-app-[0-9a-f]{14} --set \.mounts = \[\{"location":"\S*/app","writable":true,"9p":\{"cache":"none"\}\},'
! stdout '(?s)limactl edit --tty=false devvm-app.*limactl edit --tty=false devvm-app'
stdout '^limactl start --tty=false devvm-app-[0-9a-f]{14}\n(.*\n)*limactl shell --workdir / devvm-app-[0-9a-f]{14} sudo sh -c umount ''\S*/app'' \|\| exit 3; mount '
vm_state $APP_dir/vm.json
stdout '^git\.mode=on$'
stdout '^mount\.cache=none$'
-- features-none.json --
{"features": []}