Files
w3cjandClaude Opus 5.5 d58b24affe refactor(ui): prompts in one place: each question declares its answer
Every question is a msg.Question that declares what answers it where
devvm can't ask: AnsweredBy("--force") names a flag or command, which the
refusal names (no_input), and RefusedWith(msg.X(...)) gives a question no
flag answers its own refusal. msg.AnswerFor and its table go.

The Reporter's Ask, Confirm and Answer, and the UI's Secret, take a
Question and return a *msg.Refusal where they can't ask: with --no-input,
without a terminal, or at the end of the input, one refusal for all three
causes. Commands return it through the failure path (showFailure ->
UI.Refused: the question, then the refusal); nothing dies on an unanswered
question any more. Questions with a usual answer fall back on it instead:
network policy on, restart no, history import later, the Include line
warned, an unenforced VM stopped, the first run's size kept.

Gone: confirmed() in cli (4 callers), force_needed and no_input_terminal,
vm.Env.CanAsk and ui.CanAsk, vm's interactive, setup's terminal, the
Reporter's StdinIsTerminal/StdoutIsTerminal and the Fake's StdoutTerminal,
and every caller's terminal check (18 in vm, netpolicy, build and
sshconfig; 3 CanAsk; 1 interactive; 2 in cli). The picker's check
(CanPick) stays in the picker, which keeps its choices with --no-input
too; setup and the first run's agents and the new-VM summary still read
CanPick, because what they save or say depends on whether the picker
showed.

A Question's About context (the network policy's, a secret's howto, the
restart's changes, the size's host) is said only when it's asked.
devvm update asks before its tools change, so a refusal leaves the VM as
it is.

The CLI tests answer through a terminal (ttyin) or, explicitly, with a
test build's DEVVM_PIPED_ANSWERS=1, a line of input each.

Tests: ui's TestConfirm, TestAsk, TestAnswer, TestPromptsOnlyAtATerminal,
TestSecret, TestNoInput, TestNoTerminal, TestNoAnswer, TestPipedAnswers,
TestRefusedInterrupted, TestPickNoInput; msg's TestQuestionRefused,
TestQuestionAbout; cli's agreement test TestQuestionsDeclareAnswers (every
AnsweredBy names devvm's flags and commands, every RefusedWith a message,
no Question made otherwise) and TestCheckAnswer; vm's
TestSizeChoiceRefused; testscript prompts.txtar (each cause, a refusal of
its own, piped answers).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-05 11:49:57 -07:00

72 lines
3.3 KiB
Plaintext

# devvm rebuild: a new key for the image (its rebuild counter), built from
# its parent as it is; then the stale images go, the old one and those
# built on it among them, and nothing else.
env IMAGES=$XDG_DATA_HOME/devvm/images
mkdir $XDG_CONFIG_HOME/devvm/layers
cp foo.sh $XDG_CONFIG_HOME/devvm/layers/foo.sh
cp bar.sh $XDG_CONFIG_HOME/devvm/layers/bar.sh
exec devvm build foo+bar
exec stub vm devvm-web-12345612345612 Stopped
exec sh -c 'for i in base foo foo+bar; do grep -lxF " \"name\": \"$i\"," "$IMAGES"/*/record.json | xargs dirname | xargs basename > "$i.key"; done'
stub_reset
# Not a terminal: it says what goes, and refuses unless --force, which
# goes ahead.
! exec devvm rebuild base+foo
stdout '^rebuild_replaces above=foo\+bar image=foo$'
stderr '^continue\ndevvm: no_input answer=--force$'
! stdout building_image
exec devvm rebuild --force base+foo
stdout '^rebuild_replaces above=foo\+bar image=foo$'
stdout '^==> building_image image=foo key=[0-9a-f]{12}$'
! stdout 'image=base'
stdout -count=2 '^==> deleted_old_image image=foo(\+bar)? key=[0-9a-f]{12}$'
grep '\{\n "backend": "lima",\n "from": "",\n "name": "foo",\n "counter": "\d{14}-[0-9a-f]{8}"\n \}' $IMAGES/rebuilds.json
stub_calls
stdout '^limactl clone --tty=false --mount-none devvm-img-[0-9a-f]{12} devvm-img-[0-9a-f]{12}$'
exec sh -c '{ echo "limactl delete -f devvm-img-$(cat foo.key)"; echo "limactl delete -f devvm-img-$(cat foo+bar.key)"; } | sort'
cp stdout want-deleted
exec sh -c 'grep "^limactl delete" "$STUB_LOG" | sort'
cmp stdout want-deleted
# What's left: base, the new foo and the project VM. foo+bar builds again
# when it's next needed.
exec sh -c 'stub vms | grep -c .'
stdout '^3$'
exec sh -c 'v=$WORK/vms; stub vms > "$v" && grep -q "^devvm-img-$(cat base.key) " "$v" && grep -q "^devvm-web-12345612345612" "$v"'
exec sh -c 'test -f "$IMAGES/$(cat base.key)/record.json" && ! test -e "$IMAGES/$(cat foo.key)" && ! test -e "$IMAGES/$(cat foo+bar.key)"'
# Nothing built on it: nothing to ask.
exec devvm rebuild foo
! stdout rebuild_replaces
stdout -count=1 '^==> deleted_old_image image=foo key=[0-9a-f]{12}$'
# A rebuild changes the base as given alone: the base from Ubuntu's
# cloud image stays current, and so is kept, after a --from base is
# rebuilt, and so does a base from ubuntu-26.04, whose counter a name made
# of ubuntu:26.04 would once have been. Registries are never reached: a
# pinned digest needs no lookup.
env PIN=ubuntu:26.04@sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
env PIN2=ubuntu-26.04@sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
env HTTPS_PROXY=http://127.0.0.1:9
env https_proxy=http://127.0.0.1:9
exec devvm --from $PIN build base
exec devvm --from $PIN2 build base
exec devvm images
stdout -count=3 '^base +.* current +\S+$'
exec devvm rebuild --from $PIN --force base
stdout -count=1 '^==> deleted_old_image image=base key=[0-9a-f]{12}$'
exec devvm images
stdout -count=1 '^base +ubuntu 26\.04 \(\d{8}\) .* current +\S+$'
stdout -count=3 '^base +.* current +\S+$'
! stdout ' stale '
grep '"backend": "lima",\n "from": "ubuntu:26.04@sha256:a{64}",\n "name": "base",' $IMAGES/rebuilds.json
! grep '"from": "ubuntu-26.04' $IMAGES/rebuilds.json
-- foo.sh --
#!/bin/bash
echo foo
-- bar.sh --
#!/bin/bash
echo bar