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

81 lines
3.0 KiB
Plaintext

# Base image features: devvm's own, chosen the first time anything is
# built (without a terminal, every one), saved in settings.json unless
# config.toml chooses them, and run in base after base.sh, in the order
# chosen. A script in ~/.config/devvm/features isn't a feature: your own
# extras are layers.
env CHOSEN=$DATA/settings.json
rm $CHOSEN
mkdir $XDG_CONFIG_HOME/devvm/features
cp mine.sh $XDG_CONFIG_HOME/devvm/features/mine.sh
mkdir $XDG_CONFIG_HOME/devvm/layers
cp foo.sh $XDG_CONFIG_HOME/devvm/layers/foo.sh
exec devvm build base
! stderr .
! stdout features_help
stdout '^==> base_features features=cli-tools fzf omb$'
grep '^ "features": \[\n "cli-tools",\n "fzf",\n "omb"\n \]$' $CHOSEN
cmp $STUB_DIR/scripts ran-all
catg $DATA/logs/runs/*.log
stdout '^# \[4/10\] running_script script=apt\.sh what=devvm-img-'
stdout '^# \[5/10\] running_script script=base\.sh what=devvm-img-'
stdout '^# \[6/10\] running_script script=cli-tools\.sh what=devvm-img-'
stdout '^# \[9/10\] running_script script=apt\.sh what=devvm-img-'
stdout '^# \[10/10\] stopping vm=devvm-img-'
# Chosen once: the next build keeps the choice, and base. The script in
# ~/.config/devvm/features is in no image's key.
exec sh -c 'echo "# edited" >> "$XDG_CONFIG_HOME/devvm/features/mine.sh"'
exec devvm build base
! stdout 'base_features|building_image'
# A chosen feature without a script is skipped, with a warning, mine
# among them; the steps count only what runs. A layer runs only its own
# script. config.toml's features win over settings.json's.
cp some.toml $CFG/config.toml
exec sh -c ': > "$STUB_DIR/scripts"'
exec devvm build foo
stderr '^devvm: unknown_feature feature=nope$'
stderr '^devvm: unknown_feature feature=mine$'
! stdout base_features
cmp $STUB_DIR/scripts ran-some
exec sh -c 'cat "$XDG_DATA_HOME"/devvm/logs/runs/*.log'
stdout '^# \[5/9\] running_script script=base\.sh what=devvm-img-'
stdout '^# \[6/9\] running_script script=fzf\.sh what=devvm-img-'
stdout '^# \[7/9\] running_script script=omb\.sh what=devvm-img-'
stdout '^# \[9/9\] stopping vm=devvm-img-'
stdout '^# \[5/6\] running_script script=foo\.sh what=devvm-img-'
! stdout '\[10/9\]|\[7/6\]'
# None chosen: base runs only base.sh.
cp none.toml $CFG/config.toml
exec sh -c ': > "$STUB_DIR/scripts"'
exec devvm build base
! stderr .
cmp $STUB_DIR/scripts ran-none
grep '"omb"' $CHOSEN
-- some.toml --
features = ["fzf", "omb", "nope", "mine"]
-- none.toml --
features = []
-- mine.sh --
#!/bin/bash
# my tools
-- foo.sh --
#!/bin/bash
echo foo
-- ran-all --
# Essentials, and mise for the shared tools (shared-tools/).
# CLI tools: bat, fd, eza, zoxide (z), btop, tree, tldr
# fzf: fuzzy Ctrl-R history and Ctrl-T file search
# oh-my-bash: themed prompt, completions, aliases
-- ran-some --
# Essentials, and mise for the shared tools (shared-tools/).
# fzf: fuzzy Ctrl-R history and Ctrl-T file search
# oh-my-bash: themed prompt, completions, aliases
echo foo
-- ran-none --
# Essentials, and mise for the shared tools (shared-tools/).