Files
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

147 lines
5.8 KiB
Plaintext

# devvm clone [on|off]: bare, it shows whether the folder's VM has its own
# clone of the repo. On makes a VM that mounts the folder again with its
# own clone instead, after asking, keeping its settings: nothing of the
# folder mounted, the repo's branches copied in as it starts, a git remote
# for it, and .git's locks taken off. Off checks the clone as devvm rm
# does, fetching the work this repo lacks first, then makes it again
# mounting the folder: .git locked as a new VM's, and the remote removed.
# (The stubs keep the VM's files in $STUB_DIR/vmfs.)
env GIT_AUTHOR_NAME=t GIT_AUTHOR_EMAIL=t@t GIT_COMMITTER_NAME=t GIT_COMMITTER_EMAIL=t@t
mkdir $WORK/web
cd $WORK/web
# Usage errors, before anything runs.
! exec devvm clone maybe
stderr '^devvm: arg_not_choice choices=on, off command=devvm clone given=maybe$'
! exec devvm clone on off
stderr '^devvm: args_too_many '
! exec devvm clone --json on
stderr '^devvm: json_shows_only command=devvm clone$'
! exec devvm clone --json --force
stderr '^devvm: json_shows_only command=devvm clone$'
# No VM.
! exec devvm clone
stderr '^devvm: no_vm dir=/\S*/web$'
! exec devvm clone on --force
stderr '^devvm: no_vm dir=/\S*/web$'
# A VM that mounts the folder, which is a repo with two branches.
exec git init -q -b main
exec git commit -q --allow-empty -m one
exec git branch other
exec devvm --network open
vm_name WEB web
exec devvm clone
stdout '\Aoff\n\z'
exec devvm clone --json
stdout '\A{\n "version": 1,\n "clone": "off"\n}\n\z'
! exec devvm --clone
stderr '^devvm: clone_needs_new_vm vm=devvm-web-[0-9a-f]{14}$'
# Without a terminal, on refuses unless --force; in one, it says what
# changes and asks, and no keeps the VM.
stub_reset
! exec devvm clone on
stderr '^devvm: no_input answer=--force$'
ttyin -stdin $WORK/no.txt
exec devvm clone on
stdout '^==> clone_switch_on vm=devvm-web-[0-9a-f]{14}$'
stderr '^remake_confirm image=base vm=devvm-web-[0-9a-f]{14} \[y/N\] '
stdout '==> kept vm=devvm-web-[0-9a-f]{14}$'
stub_calls
! stdout 'limactl (stop|rename|clone)'
# --force: made again with nothing of the folder mounted, its branches
# copied into its clone as it starts, the remote added, and on macOS
# .git's locks taken off.
stub_reset
exec devvm clone on --force
stdout '==> remade image=base vm=devvm-web-[0-9a-f]{14}$'
stdout '^==> clone_ready branch=main remote=devvm$'
stub_calls
stdout 'limactl rename --tty=false devvm-web-[0-9a-f]{14} devvm-[0-9a-f]{14}-old\n'
stdout '^limactl clone --tty=false devvm-img-[0-9a-f]{12} devvm-web-[0-9a-f]{14} --mount-none --set \.mounts = \[\{"location":"[^"]*/data/devvm/tools","mountPoint":"/mnt/devvm-tools","writable":false\}\] '
! stdout 'git-receive-pack'
stdout 'limactl delete -f devvm-[0-9a-f]{14}-old\n'
[darwin] stdout 'limactl delete -f devvm-[0-9a-f]{14}-old\n(.*\n)*chflags -R -P nouchg /\S*/web/\.git/config\n'
exec sh -c 'cat "$STUB_DIR/vmfs$(pwd -P)/.git/devvm-seeded"'
stdout '^done$'
vm_state $WEB_dir/vm.json
stdout '^clone.on=true$'
stdout '^clone.made.remote=devvm$'
stdout '^clone.made.seeded=true$'
stdout '^git.mode=clone$'
! stdout '^remake'
exec git remote get-url devvm
stdout '^devvm-web-[0-9a-f]{14}:/\S*/web$'
exec sh -c 'git -C "$STUB_DIR/vmfs$(pwd -P)" branch --format="%(refname:short)"'
stdout '\Amain\nother\n\z'
exec devvm clone
stdout '\Aon\n\z'
# On a Linux host, a --clone VM mounts no project folder, so it has no
# cache mode to warn of, even with none chosen; the mode it shows is the
# one the folder devvm clone off mounts gets: none.
[linux] json_set $WEB_dir/vm.json mount:={}
[linux] exec devvm
[linux] ! stderr mount_cache_unchosen
[linux] exec devvm mount-cache
[linux] stdout '\Anone\n\z'
[linux] stderr '^mount_cache_clone mode=none vm=devvm-web-[0-9a-f]{14}$'
[linux] exec devvm mount-cache --json
[linux] stdout '"chosen": false'
# Again: said, and nothing made.
stub_reset
exec devvm clone on --force
stdout '^==> setting_already command=devvm clone on vm=devvm-web-[0-9a-f]{14}$'
stub_calls
! stdout 'limactl (stop|rename|clone)'
# Off: the VM's own commit isn't fetched, so without a terminal it
# refuses, --force or not, and keeps the VM as it is.
exec sh -c 'git -C "$STUB_DIR/vmfs$(pwd -P)" commit -q --allow-empty -m from-vm'
stub_reset
! exec devvm clone off --force
stdout '^unfetched_commits refs="main"$'
stderr '^devvm: no_terminal_fetch command=devvm clone off$'
stub_calls
! stdout 'limactl (rename|clone)'
# In a terminal, the work is fetched into saved/devvm/*, then the VM is
# made again mounting the folder: the remote removed, then .git locked,
# before it starts.
stub_reset
ttyin -stdin $WORK/yes.txt
exec devvm clone off --force
stdout '^==> clone_switch_off vm=devvm-web-[0-9a-f]{14}$'
stderr 'fetch_before_delete prefix=saved/devvm'
stdout '==> saved_branches branches="saved/devvm/main"$'
stdout '==> removed_remote remote=devvm\n(.*\n)*==> starting what=devvm-web-[0-9a-f]{14}\n'
stdout '==> remade image=base vm=devvm-web-[0-9a-f]{14}$'
! stderr mount_cache_unchosen
stub_calls
stdout '^limactl clone --tty=false devvm-img-[0-9a-f]{12} devvm-web-[0-9a-f]{14} --mount-none --set \.mounts = \[.*"location":"/\S*/web","writable":true'
# The folder it mounts is new, so on Linux it's cached with none, which
# its state records, and nothing warned of it.
[linux] stdout '^limactl clone --tty=false devvm-img-[0-9a-f]{12} devvm-web-[0-9a-f]{14} --mount-none --set \.mounts = \[.*"location":"/\S*/web","writable":true,"9p":\{"cache":"none"\}\}'
[darwin] stdout '^chflags -R -P uchg /\S*/web/\.git/config\n(.*\n)*limactl start --tty=false devvm-web-[0-9a-f]{14}\n'
exec git log --format=%s -1 saved/devvm/main
stdout '^from-vm$'
! exec git remote get-url devvm
vm_state $WEB_dir/vm.json
! stdout '^clone\.(on=true|made)'
[darwin] stdout '^git.mode=on$'
[linux] stdout '^git.mode=off$'
[linux] stdout '^mount.cache=none$'
! stdout '^remake'
exec devvm clone
stdout '\Aoff\n\z'
exec devvm rm --force --no-export
-- no.txt --
n
-- yes.txt --
y