Files
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

106 lines
4.0 KiB
Plaintext

# A new VM's size and ports: the flags, else the defaults (config.toml's,
# else settings.json's), else the image's; checked before anything is
# built.
project sized
# Values that aren't sizes or port lists, and sizes this machine can't
# give or a disk smaller than the image's, are refused.
! exec devvm --network open --cpus 1.5
stderr '^devvm: cpus_not_number flag=--cpus value="1\.5"$'
! exec devvm --network open --cpus=0
stderr '^devvm: cpus_not_number flag=--cpus value="0"$'
! exec devvm --network open --memory 16M
stderr '^devvm: size_not_gib flag=--memory value="16M"$'
! exec devvm --network open --disk lots
stderr '^devvm: size_not_gib flag=--disk value="lots"$'
! exec devvm --network open --cpus 9999
stderr '^devvm: too_many_cpus have=8 want=9999$'
! exec devvm --network open --memory 99999
stderr '^devvm: too_much_memory have=16 max=14 want=99999$'
! exec devvm --network open --disk 50GiB
stderr '^devvm: disk_shrink have=100 vm=devvm-sized-[0-9a-f]{14} want=50$'
! exec devvm --network open --ports 0
stderr '^devvm: port_invalid value="0"$'
! exec devvm --network open --ports 8010-8000
stderr '^devvm: port_invalid value="8010-8000"$'
# Hand-edited defaults are checked too, naming config.toml's line.
cp $WORK/bad-size.toml $CFG/config.toml
! exec devvm --network open
stderr '\S*/config/devvm/config\.toml:2: size_not_gib flag=memory value="1\$\(touch x\)"$'
! exists x
cp $WORK/bad-ports.toml $CFG/config.toml
! exec devvm --network open
stderr '\S*/config/devvm/config\.toml:1: port_invalid '
rm $CFG/config.toml
stub_calls
! stdout 'create|clone'
# The flags: the VM's size changes after the clone, once, and its state
# says so and which ports it forwards, Lima's own forwards off. Its start
# edits only its proxy into its environment.
exec devvm --network open --cpus 2 --memory=3G --disk 120GiB --ports '5173, 8000-8010,5173'
stub_calls
stdout '^limactl clone .* --set \.portForwards = \[\{"guestIP":"127\.0\.0\.1","guestPortRange":\[1,65535\],"proto":"any","ignore":true\},'
stdout -count=1 '^limactl edit --tty=false devvm-sized-[0-9a-f]{14} --cpus'
stdout '^limactl edit --tty=false devvm-sized-[0-9a-f]{14} --cpus 2 --memory 3 --disk 120$'
stdout -count=2 'limactl edit --tty=false devvm-sized'
stdout '^limactl edit --tty=false devvm-sized-[0-9a-f]{14} --set \.env = '
vm_name SIZED sized
! exists $SIZED_dir/backend/ports
vm_state $SIZED_dir/vm.json
stdout '^size.cpus=2$'
stdout '^size.memory=3$'
stdout '^size.disk=120$'
stdout '^ports.forward=5173,8000-8010$'
# The defaults, for what the flags leave unset; nothing for what neither
# sets. A default of every port stores nothing. config.toml's memory wins
# over what devvm size -g saved.
project defaults
exec devvm size -g --memory 4
exec devvm ports -g none
cp $WORK/memory.toml $CFG/config.toml
stub_reset
exec devvm --network open --cpus 2
stub_calls
stdout '^limactl clone .* --set \.portForwards = \[\{"guestIP":"127\.0\.0\.1"'
stdout '^limactl edit --tty=false devvm-defaults-[0-9a-f]{14} --cpus 2 --memory 5$'
vm_name DEFAULTS defaults
vm_state $DEFAULTS_dir/vm.json
stdout '^size.cpus=2$'
stdout '^size.memory=5$'
! stdout 'disk='
stdout '^ports.forward=none$'
project all
rm $CFG/config.toml
cp $WORK/features-none.json $DATA/settings.json
stub_reset
exec devvm --network open
stub_calls
stdout '^limactl clone .* --set \.portForwards = \[\{"guestIP":"127\.0\.0\.1"'
! stdout 'limactl edit --tty=false devvm-all\S* --(cpus|memory|disk)'
vm_name ALL all
vm_state $ALL_dir/vm.json
! stdout '^size\.|^ports\.forward='
# The first run, before base's features are chosen, asks for new VMs'
# size only in a terminal: without one it asks nothing and saves none.
project first
rm $DATA/settings.json
exec devvm --network open
! stdout 'size_question|size_defaults'
! stderr 'size_'
! grep '"size"' $DATA/settings.json
grep '"features"' $DATA/settings.json
-- features-none.json --
{"features": []}
-- memory.toml --
[size]
memory = 5
-- bad-size.toml --
[size]
memory = "1$(touch x)"
-- bad-ports.toml --
ports = "80]}]|.mounts=[{\"location\":\"~\""