Files
devvm/testdata/script/existing.txtar
T
w3cjandClaude Opus 5.5 16b4ad8771 feat(cli): --no-input, a flag or command for every question, and --force only skips a confirmation
A global --no-input (persistent on the root, with --help and -v): no
question is asked or read. The ui's prompts (Ask, Confirm, Answer,
Secret, Pick/PickOne in a terminal) show the question, then fail with
no_input naming what answers it (msg.AnswerFor, by the question's ID),
or no_input_terminal for a question only a terminal answers. ui.Flags
and SetFlags carry -v and --no-input.

Answers: --network-policy/--no-network-policy, --here, devvm size -g,
devvm setup --features/--backend, devvm network -g, devvm ssh-agent add,
devvm restart, --ssh-config (new, on devvm, host and code: the Include
line without asking; sshconfig.Config.AddInclude, vm.Env.AddInclude),
--stdin, and --force.

--force (-f) only skips a confirmation, and destructive commands need it
without a terminal (force_needed, a failure, not a usage error): rm (new
rm_confirm), gc (it went ahead without a terminal), gc --caches (now
allowed without a terminal with --force), images rm (images_rm_confirm),
secret rm (secret_rm_confirm), adopt (adopt_vm), rebuild when images
are built on the one rebuilt (build.Env.Force). rm --no-export skips the
export; rm's parent-folder, earlier-folder and --clone confirmations are
terminal-only and --force never answers them (vm.RmOptions). gc --tools
--force splits: --recent (only with --tools, gc_recent_needs_tools)
drops the hour's hold and keeps the refusal while a VM is being made
(gc_recent_making); gc_tools_recent names devvm gc --tools --recent.
gc_caches_need_terminal goes.

Tests: TestNoInput, TestAnswers, TestConfirmed, TestRmConfirms, TestAdopt
(--force), TestRebuild (force_needed, then Force); secret, rebuild,
images, gc*, clone, subfolder, existing scripts. e2e: rm/gc/images
rm/secret rm/rebuild with --force (and --no-export where rm -f skipped
the export), and the clone section's rm with its checks. Docs:
commands.md (Questions devvm asks, rm, flags), first-vm, clone, images
(cleaning up, --recent), space, coding-agents, internals overview and
images; CLI reference.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-01 03:51:27 -08:00

168 lines
5.7 KiB
Plaintext

# A VM that exists: devvm opens it as it is, starting it if it's stopped,
# and sets it up again; flags for new VMs are ignored with a warning, and
# what its state asks of a stopped VM's size and ports is applied.
# restart stops it first.
env DEVVM_MESSAGES=names
env VMS=$XDG_DATA_HOME/devvm/vms
env KNOWN=$XDG_CONFIG_HOME/devvm/known_hosts
mkdir $WORK/web
cd $WORK/web
exec git init -q
exec devvm --no-network-policy base
# Running: opened without a start, its host keys kept, set up again.
exec sh -c ': > "$STUB_LOG"'
exec devvm
! stdout 'starting|creating'
! stderr .
stub_calls
! stdout 'limactl (start|stop|clone|create|edit|delete)'
stdout '^limactl shell --workdir / devvm-web-[0-9a-f]{14} sh -c .*tar -xf - '
stdout '^limactl shell --workdir /\S*/web devvm-web-[0-9a-f]{14}\n\z'
exec grep -c '^devvm-web-' $KNOWN
stdout '^1$'
# Flags for new VMs: ignored, with a warning each; --backend names the
# backend it stays on.
exec devvm --network-policy --cpus 2 --ports none --backend lima
stderr '^devvm: net_flag_ignored$'
stderr '^devvm: size_flags_ignored$'
stderr '^devvm: ports_flag_ignored$'
! stderr backend_flag_ignored
exec devvm --no-git-protect
stderr '^devvm: git_protect_flag_ignored$'
exec sh -c 'grep -c "^net=off$" "$VMS"/devvm-web-*'
stdout '^1$'
# A size its state asks for: a running VM's waits for its next start; a
# stopped one's is applied once.
exec sh -c 'f=$(ls "$VMS"/devvm-web-*); printf "cpus=6\n" >> "$f"'
exec sh -c ': > "$STUB_LOG"'
exec devvm
stderr '^devvm: size_next_start vm=devvm-web-[0-9a-f]{14}$'
stub_calls
! stdout 'limactl edit'
# Stopped: started, its host keys read again.
exec sh -c 'limactl stop "$(basename "$VMS"/devvm-web-*)"'
exec sh -c ': > "$STUB_LOG"'
exec devvm
stdout '^==> starting vm=devvm-web-[0-9a-f]{14}$'
! stderr 'next_start'
stub_calls
stdout '^limactl edit --tty=false devvm-web-[0-9a-f]{14} --cpus 6$'
! stdout 'limactl edit .*portForwards'
stdout '^limactl start --tty=false devvm-web-[0-9a-f]{14}$'
stdout '^ssh -F none -M .* -l stub 127\.0\.0\.1 sh -s$'
stdout 'sh -c .*/etc/ssh/ssh_host_'
# (The stub's VM gets the size its edit asked for.)
exec sh -c 'echo "6 8589934592 107374182400" > "$STUB_DIR/size-$(basename "$VMS"/devvm-web-*)"'
exec sh -c 'limactl stop "$(basename "$VMS"/devvm-web-*)"'
exec sh -c ': > "$STUB_LOG"'
exec devvm
stub_calls
! stdout 'limactl edit'
# restart: stopped, then opened.
exec sh -c ': > "$STUB_LOG"'
exec devvm restart
stdout '^==> starting vm=devvm-web-[0-9a-f]{14}$'
stub_calls
stdout '^limactl stop devvm-web-[0-9a-f]{14}\n(.*\n)*limactl start --tty=false devvm-web-[0-9a-f]{14}\n'
stdout '^limactl shell --workdir /\S*/web devvm-web-[0-9a-f]{14}\n\z'
! exec devvm restart base
stderr '^devvm: args_none command=devvm restart given=base$'
# An image naming what it lacks is refused, naming the command that adds
# its shared tools, and nothing changes.
! exec devvm go
stderr '^devvm: vm_lacks_tools tools=go vm=devvm-web-[0-9a-f]{14}$'
exec sh -c 'cat "$VMS"/devvm-web-*'
stdout '^image=base$'
# Naming what it has opens it.
exec devvm base
! stderr vm_lacks
# A VM without a network choice didn't finish being made: never started
# (it would start without network policy); rm deletes it.
exec sh -c 'f=$(ls "$VMS"/devvm-web-*); grep -v "^net=" "$f" > "$f.new" && mv "$f.new" "$f"'
exec sh -c 'limactl stop "$(basename "$VMS"/devvm-web-*)"'
exec sh -c ': > "$STUB_LOG"'
! exec devvm
stderr '^devvm: vm_unfinished vm=devvm-web-[0-9a-f]{14}$'
! exec devvm restart
stderr '^devvm: vm_unfinished vm=devvm-web-[0-9a-f]{14}$'
stub_calls
! stdout 'limactl (start|stop)'
# rm: base has no agents, so nothing is exported; only this VM is
# deleted, with its state, logs (the rotated ones too), host keys and ssh config entry, and .git's
# locks taken off.
mkdir $WORK/api
cd $WORK/api
exec devvm --no-network-policy base
cd $WORK/web
exec sh -c 'l="$XDG_DATA_HOME/devvm/logs/$(basename "$VMS"/devvm-web-*)" && touch "$l.jsonl" "$l.jsonl.1" "$l.proxy.log" "$l.proxy.log.1"'
exec sh -c ': > "$STUB_LOG"'
exec devvm rm --force
stdout '^==> deleted vm=devvm-web-[0-9a-f]{14}$'
! stdout exported
stub_calls
stdout '^limactl delete -f devvm-web-[0-9a-f]{14}$'
! stdout 'delete -f devvm-api'
! stdout 'limactl (start|shell)'
[darwin] stdout '^chflags -R -P nouchg /\S*/web/\.git/config$'
exec sh -c 'ls "$VMS"'
! stdout devvm-web
stdout devvm-api
exec sh -c 'ls "$XDG_DATA_HOME/devvm/logs"'
! stdout devvm-web
exec cat $KNOWN
! stdout devvm-web
stdout devvm-api
exec cat $XDG_CONFIG_HOME/devvm/ssh_config
! stdout devvm-web
stdout devvm-api
! exec devvm rm --force
stderr '^devvm: no_vm dir=/\S*/web$'
! exec devvm restart
stderr '^devvm: no_vm dir=/\S*/web$'
! exec devvm tools update
stderr '^devvm: no_vm dir=/\S*/web$'
! exec devvm tools
stderr '^devvm: no_vm dir=/\S*/web$'
! exec devvm adopt
stderr '^devvm: no_vm dir=/\S*/web$'
# A delete that fails but leaves no VM cleans up like one that worked.
cd $WORK/api
exec sh -c ': > "$STUB_DIR/delete-fails"'
exec devvm rm --force --no-export
stdout '^==> deleted vm=devvm-api-[0-9a-f]{14}$'
exec sh -c 'ls "$VMS"'
! stdout devvm-api
rm $STUB_DIR/delete-fails
# A folder made again at the same path: rm and adopt ask first, so
# without a terminal neither deletes nor takes the VM over.
mkdir $WORK/site
cd $WORK/site
exec devvm --no-network-policy base
cd $WORK
rm site
mkdir site
cd site
exec sh -c ': > "$STUB_LOG"'
! exec devvm
stderr '^devvm: vm_other_folder vm=devvm-site-[0-9a-f]{14} was=/\S*/site$'
! exec devvm rm --force --no-export
stderr '^devvm: vm_other_folder_rm vm=devvm-site-[0-9a-f]{14} was=/\S*/site$'
! exec devvm adopt
stderr '^devvm: vm_other_folder_adopt vm=devvm-site-[0-9a-f]{14} was=/\S*/site$'
! exec devvm restart
stderr '^devvm: vm_other_folder '
stub_calls
! stdout 'limactl (delete|stop|start)'
exec sh -c 'ls "$VMS"'
stdout devvm-site