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

184 lines
6.8 KiB
Plaintext

# devvm size: a folder's VM's CPUs, memory and disk, changed from its next
# start, with a restart offered for a running one; with -g, the size new
# VMs get (config.toml's, else settings.json's) and where each came from.
# No VM yet.
project web
! exec devvm size
stderr '^devvm: no_vm_size dir=\S*/web$'
# A bad size is refused before devvm looks for the VM.
! exec devvm size --cpus many
stderr '^devvm: cpus_not_number flag=--cpus value="many"$'
stderr '^usage_help command=devvm size$'
! stderr no_vm_size
! exec devvm size --memory
stderr '^devvm: flag_needs_value flag=--memory form=--memory GiB$'
# -g: the size new VMs get, unset (the image's) until it's set; each change
# keeps what it leaves unset. No VM is looked at.
stub_reset
exec devvm size -g
cmp stdout $WORK/unset
exec devvm size -g --cpus 2 --memory 3G
stdout '^==> size_defaults size=cpus=2 memory=3GiB$'
exec devvm size -g --memory=2.5GiB
stdout '^==> size_defaults size=cpus=2 memory=2\.5GiB$'
exec devvm size -g
cmp stdout $WORK/set
# --json: what's unset left out; it only shows.
exec devvm size -g --json
stdout '\A{\n "version": 1,\n "cpus": 2,\n "memory_gib": 2\.5,\n "sources": {\n "cpus": "settings.json",\n "disk": "built-in",\n "memory": "settings.json"\n }\n}\n\z'
! exec devvm size -g --json --cpus 4
stderr '^devvm: json_shows_only command=devvm size$'
grep '^ "size": {\n "cpus": "2",\n "memory": "2\.5"\n },?$' $DATA/settings.json
! exec devvm size -g --cpus 9999
stderr '^devvm: too_many_cpus have=8 want=9999$'
! exec devvm size -g --memory 16M
stderr '^devvm: size_not_gib flag=--memory value="16M"$'
! stub_calls
# config.toml's memory wins, and -g shows where it came from; -g refuses
# to change it, naming the file and the key, and changes what it leaves.
cp $WORK/memory.toml $CFG/config.toml
exec devvm size -g
stdout '\Acpus=2 # devvm: settings\.json\nmemory=6 # \S*/config/devvm/config\.toml\ndisk= # devvm: default\n\z'
exec devvm size -g --json
stdout '"memory": "config.toml"'
! exec devvm size -g --memory 4
stderr '^devvm: set_in_config file=\S*/config/devvm/config\.toml key=size\.memory$'
! exec devvm size -g --cpus 1 --memory 4
stderr '^devvm: set_in_config '
grep '"cpus": "2"' $DATA/settings.json
exec devvm size -g --cpus 1
stdout '^==> size_defaults size=cpus=1 memory=6GiB$'
# A hand-edited config.toml with a bad value is refused, to show or
# change, naming its line.
cp $WORK/bad-size.toml $CFG/config.toml
! exec devvm size -g
stderr '^devvm: size_failed reason=\S*/config/devvm/config\.toml:3: size_not_gib flag=memory value="1\$\(touch x\)"$'
! exec devvm size -g --cpus 2
stderr '^devvm: size_failed reason=\S*/config/devvm/config\.toml:3: '
rm $CFG/config.toml
cp $WORK/features-none.json $DATA/settings.json
# A new VM. Running: devvm size shows what it has, and a change waits for
# its next start. It has 2 CPUs, which any host running the tests has.
exec devvm --network open --no-git-protect
vm_name WEB web
exec stub size $WEB 2 8589934592 107374182400
exec devvm size
stdout '\Acpus=2 memory=8GiB disk=100GiB\n\z'
! stderr .
exec devvm size --json
stdout '\A{\n "version": 1,\n "cpus": 2,\n "memory_gib": 8,\n "disk_gib": 100\n}\n\z'
! stderr .
stub_reset
exec devvm size --cpus 1 --memory 3
stderr '^devvm: next_start count=1 vm=devvm-web-[0-9a-f]{14}$'
! stdout vm_size
stub_calls
! stdout 'limactl edit'
vm_state $WEB_dir/vm.json
stdout '^size.cpus=1$'
stdout '^size.memory=3$'
exec devvm size
stdout '\Acpus=2 memory=8GiB disk=100GiB\n\z'
stderr '^size_pending_running size=cpus=1 memory=3GiB vm=devvm-web-[0-9a-f]{14}$'
exec devvm size --json
stdout '^ "disk_gib": 100,\n "pending": {\n "cpus": 1,\n "memory_gib": 3\n }\n}\n\z'
stderr '^size_pending_running '
# Back to what it has: nothing waits.
exec devvm size --cpus 2 --memory 8
stdout '^==> vm_size size=cpus=2 memory=8GiB disk=100GiB vm=devvm-web-[0-9a-f]{14}$'
! stderr .
# A smaller disk is refused, running or not, and so is more than this
# machine has.
! exec devvm size --disk 50
stderr '^devvm: disk_shrink have=100 vm=devvm-web-[0-9a-f]{14} want=50$'
! exec devvm size --cpus 9999
stderr '^devvm: too_many_cpus have=8 want=9999$'
! exec devvm size --cpus 1.5
stderr '^devvm: cpus_not_number flag=--cpus value="1\.5"$'
# Stopped: saved, and changed at its next start, only what differs, in
# that start's one edit.
exec limactl stop $WEB
stub_reset
exec devvm size --cpus 1 --memory 8 --disk 120GiB
stdout '^==> size_pending size=cpus=1 disk=120GiB vm=devvm-web-[0-9a-f]{14}$'
exec devvm size
stderr '^size_pending size=cpus=1 disk=120GiB vm=devvm-web-[0-9a-f]{14}$'
stub_calls
! stdout 'limactl edit'
stub_reset
exec devvm
stub_calls
stdout '^limactl edit --tty=false devvm-web-[0-9a-f]{14} --cpus 1 --disk 120( |$)'
! stdout '(?s)limactl edit --tty=false devvm-web.*limactl edit --tty=false devvm-web'
exec devvm size
stdout '\Acpus=1 memory=8GiB disk=120GiB\n\z'
! stderr .
! exec devvm size --disk 100
stderr '^devvm: disk_shrink have=120 vm=devvm-web-[0-9a-f]{14} want=100$'
# --cpus on devvm is ignored, with a warning naming devvm size.
exec devvm --cpus 3
stderr '^devvm: new_vm_flags_ignored_run command=devvm size flags=--cpus vm=devvm-web-[0-9a-f]{14}$'
# Opening it while a new size waits: without a terminal, the warnings
# alone, and it keeps running.
exec devvm size --cpus 2
stderr '^devvm: next_start count=1 vm=devvm-web-[0-9a-f]{14}$'
stub_reset
exec devvm
stderr '^devvm: next_start_size vm=devvm-web-[0-9a-f]{14}\ndevvm: next_start count=1 vm=devvm-web-[0-9a-f]{14}$'
! stderr 'restart_now'
stub_calls
! stdout 'limactl (stop|edit)'
# In a terminal, one question after the line naming what waits, no by
# default: no keeps the warning and the VM running.
stub_reset
ttyin -stdin $WORK/no.txt
exec devvm
stderr '^next_start_size vm=devvm-web-[0-9a-f]{14}$'
stderr '^restart_now count=1 vm=devvm-web-[0-9a-f]{14} \[y/N\] '
stderr 'devvm: next_start count=1 vm=devvm-web-[0-9a-f]{14}$'
stub_calls
! stdout 'limactl (stop|edit)'
# Yes stops it and starts it with its new size, then sets it up (which
# fails here, so the run ends before its shell).
stub_reset
exec sh -c ': > "$STUB_DIR/sync-fails-with"'
ttyin -stdin $WORK/yes.txt
! exec devvm
stderr '^restart_now count=1 vm=devvm-web-[0-9a-f]{14} \[y/N\] '
! stderr 'next_start '
stdout '^==> starting what=devvm-web-[0-9a-f]{14}$'
stub_calls
stdout '^limactl stop devvm-web-[0-9a-f]{14}\n(.*\n)*limactl edit --tty=false devvm-web-[0-9a-f]{14} --cpus 2( |$)'
rm $STUB_DIR/sync-fails-with
exec devvm size
stdout '\Acpus=2 memory=8GiB disk=120GiB\n\z'
-- unset --
cpus= # devvm: default
memory= # devvm: default
disk= # devvm: default
-- set --
cpus=2 # devvm: settings.json
memory=2.5 # devvm: settings.json
disk= # devvm: default
-- no.txt --
n
-- yes.txt --
y
-- features-none.json --
{"features": []}
-- memory.toml --
[size]
memory = "6GiB"
-- bad-size.toml --
# new VMs' size
[size]
memory = "1$(touch x)"