Files
devvm/testdata/script/desktop.txtar
T
w3cjandClaude Opus 5.5 ceda0bf925 feat(cli): --network TIER, devvm network TIER and the tier question
The command line names the four network tiers. --network TIER (open,
internet, allowlist or none) chooses a new VM's tier, checked before
anything runs (arg_not_choice). devvm network open|internet|allowlist|none
gives the folder's VM a tier through Net.SetTier, and devvm network -g
takes the tiers and ask. config.toml's and settings.json's network is ask
or a tier (settings.NetworkChoices, checked against netpolicy.TierNames
by a test, since settings can't import netpolicy).

The question on creation is Proxy.Choose(vm): net_about says what each
tier reaches, net_ask asks for one (Answer, AnsweredBy("--network")),
Enter or a refusal gives allowlist, and an answer that isn't a tier is
warned of (net_tier_unknown) and asked again. devvm setup's picker
offers ask and the four tiers (network_default_open, _internet,
_allowlist, _none). On an existing VM, --network is ignored with the
devvm network TIER command that changes it.

devvm network --json: policy is the tier or unenforced, and each policy
file whose denies alone apply (internet and none) has denies_only: true,
as the text output's "(denies only)", so a script can tell a file's
denies from all of its rules without knowing the tier rules.

Messages reworded: net_tier_backend (--network open), net_open_policy
(devvm network allowlist), net_about, net_ask, network_default*,
net_default_failed, network_failed, setting_already's and
widen_parent_vm*'s descriptions. safety/network's "Choosing a tier"
replaces its on/off section; docs, the cli skill, testscripts and e2e
use the new forms, and e2e's internet and none checks go through devvm
network.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-05 15:54:43 -07:00

107 lines
4.0 KiB
Plaintext

# devvm desktop: the folder's VM launched as devvm host does (started when
# it's stopped, set up, in devvm's ssh config), its desktop layer's
# devvm-desktop started, clipboard off unless asked for, then its desktop
# served on this machine's 127.0.0.1 with the VM's password, both kept in
# its state, until Ctrl+C or the VM stops. A VM without the layer is
# refused, and on macOS Screen Sharing (a stub open) gets the address.
# No VM.
project plain
! exec devvm desktop
stderr '^devvm: no_vm dir=\S*/plain$'
# A VM without the desktop layer: refused, nothing served. base has no
# desktop: its build doesn't run the layer's script.
exec devvm --network open --no-git-protect
vm_name PLAIN plain
grep '^# Essentials, and mise' $STUB_DIR/scripts
! grep '^# desktop: ' $STUB_DIR/scripts
cp $WORK/no-layer $STUB_DIR/shell-fails-on
! exec devvm desktop --no-open
stderr '^devvm: desktop_no_layer vm=devvm-plain-[0-9a-f]{14}$'
! stdout desktop_ready
vm_state $PLAIN_dir/vm.json
! stdout '^(ports\.host\.desktop|desktop\.made\.password)='
rm $STUB_DIR/shell-fails-on
# --layers desktop: the VM's image is desktop, built on base by the
# layer's script.
project desk
exec devvm --network open --no-git-protect --layers desktop
stdout '^==> building_image image=desktop key=[0-9a-f]{12}$'
stdout '^==> creating_from image=desktop vm=devvm-desk-[0-9a-f]{14}$'
grep '^# desktop: a built-in layer' $STUB_DIR/scripts
vm_name DESK desk
vm_state $DESK_dir/vm.json
stdout '^image=desktop$'
# A stopped VM: started, its desktop started with the clipboard off, and
# served on a port of 127.0.0.1 until Ctrl+C.
exec limactl stop $DESK
stub_reset
! exec devvm desktop --no-open &d&
exec sh $WORK/waitfor 'p=$(sed -n "s/^ *\"desktop\": \([0-9][0-9]*\).*/\1/p" "$DESK_dir/vm.json") && [ -n "$p" ] && nc -z 127.0.0.1 "$p"'
kill -INT d
wait d
stdout '^==> starting vm=devvm-desk-[0-9a-f]{14}$'
stdout '^desktop_ready address=127\.0\.0\.1:[0-9]+ password=[a-z2-9]{8} vm=devvm-desk-[0-9a-f]{14}$'
stub_calls
stdout '^limactl start --tty=false devvm-desk-[0-9a-f]{14}$'
stdout 'exec ''/usr/local/bin/devvm-desktop'' ''start'' ''off''$'
! stdout '^open '
exec sh -c 'grep -E "\"desktop\": [0-9]|\"password\": " "$DESK_dir/vm.json"'
stdout '^ *"password": "[a-z2-9]{8}"$'
stdout '^ *"desktop": [0-9]+,?$'
cp stdout $WORK/state1
# A running VM, the clipboard asked for: the same password and port. On
# macOS, Screen Sharing gets the address; one that doesn't open is warned
# about.
stub_reset
! exec devvm desktop --clipboard &d&
exec sh $WORK/waitfor 'nc -z 127.0.0.1 "$(sed -n "s/^ *\"desktop\": \([0-9][0-9]*\).*/\1/p" "$WORK/state1")"'
[darwin] exec sh $WORK/waitfor 'grep -q "^open " "$STUB_LOG"'
kill -INT d
wait d
! stdout starting
stub_calls
stdout 'exec ''/usr/local/bin/devvm-desktop'' ''start'' ''on''$'
[darwin] stdout '^open vnc://127\.0\.0\.1:[0-9]+$'
[!darwin] ! stdout '^open '
exec sh -c 'grep -E "\"desktop\": [0-9]|\"password\": " "$DESK_dir/vm.json"'
cmp stdout $WORK/state1
[darwin] exec sh -c ': > "$STUB_DIR/open-fails" && : > "$STUB_LOG"'
[darwin] ! exec devvm desktop &d&
[darwin] exec sh $WORK/waitfor 'grep -q "^open " "$STUB_LOG"'
[darwin] exec sleep 0.5
[darwin] kill -INT d
[darwin] wait d
[darwin] stderr '^devvm: desktop_open_failed url=vnc://127\.0\.0\.1:[0-9]+$'
[darwin] rm $STUB_DIR/open-fails
# The VM stops: so does devvm desktop, saying so.
exec devvm desktop --no-open &d&
exec sh $WORK/waitfor 'nc -z 127.0.0.1 "$(sed -n "s/^ *\"desktop\": \([0-9][0-9]*\).*/\1/p" "$WORK/state1")"'
exec limactl stop $DESK
wait d
stdout '^==> desktop_vm_stopped vm=devvm-desk-[0-9a-f]{14}$'
# Its desktop doesn't start: said, with the run log.
cp $WORK/start-fails $STUB_DIR/shell-fails-on
! exec devvm desktop --no-open
stderr 'desktop_start_failed vm=devvm-desk-[0-9a-f]{14}'
rm $STUB_DIR/shell-fails-on
-- waitfor --
# waitfor CMD: CMD every 0.1 s until it succeeds, for 90 s at most.
i=0
until sh -c "$1"; do
i=$((i + 1))
[ "$i" -lt 900 ] || exit 1
sleep 0.1
done
-- no-layer --
'test' '-x' '/usr/local/bin/devvm-desktop'
-- start-fails --
/usr/local/bin/devvm-desktop' 'start'