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

237 lines
10 KiB
Plaintext

# devvm group: VMs that reach each other's published ports by name,
# through links the group makes in each of them, kept in their state.
# A VM is in one group at a time, and a group's VMs all have the same
# network tier.
exec devvm --help
stdout '^Links between VMs:\n group .*\n link '
# No VM yet.
project app
! exec devvm group
stderr '^devvm: no_vm_group dir=\S*/app$'
# Usage errors, before devvm looks for the VM.
! exec devvm group nope
stderr '^devvm: no_subcommand command=devvm group commands=join, leave given=nope$'
! exec devvm group join Web
stderr '^devvm: group_name_invalid name="Web"$'
! exec devvm group join 42
stderr '^devvm: group_name_invalid name="42"$'
! exec devvm group join web --as Bad_Name
stderr '^devvm: link_name_invalid name="Bad_Name"$'
! stderr no_vm_group
# The VMs: app, db and two folders called api, open; cache on allowlist.
exec devvm --network open --no-git-protect
project db
exec devvm --network open --no-git-protect
exec devvm link publish 5432,8000-8001
mkdir $WORK/x/api
cd $WORK/x/api
exec devvm --network open --no-git-protect
exec devvm link publish 80
mkdir $WORK/y/api
cd $WORK/y/api
exec devvm --network open --no-git-protect
exec devvm link publish 3000
project cache
exec devvm --network allowlist --no-git-protect
vm_name APP app
vm_name DB db
vm_name CACHE cache
# Not in a group: said, and an empty list in JSON.
cd $WORK/app
exec devvm group
stdout '^==> group_none vm=devvm-app-[0-9a-f]{14}$'
exec devvm group --json
stdout '\A{\n "version": 1,\n "group": "",\n "members": \[\]\n}\n\z'
! exec devvm group leave
stderr '^devvm: group_none vm=devvm-app-[0-9a-f]{14}$'
# The first to join makes the group; the trust is said on every join.
exec devvm group join web
stdout '^==> group_made group=web vm=devvm-app-[0-9a-f]{14}$'
stderr '^group_trust group=web$'
vm_state $APP_dir/vm.json
stdout '^links.group=web$'
exec devvm group join web
stdout '^==> group_already group=web vm=devvm-app-[0-9a-f]{14}$'
! exec devvm group join web --as other
stderr '^devvm: group_named group=web name=app vm=devvm-app-[0-9a-f]{14}$'
! exec devvm group join other
stderr '^devvm: group_other group=web vm=devvm-app-[0-9a-f]{14}$'
# db joins: app gets a link to each port db publishes, db none to app,
# which publishes none.
cd $WORK/db
exec devvm group join web
stdout '^==> group_joined group=web vm=devvm-db-[0-9a-f]{14}$'
stdout '^==> group_links_added group=web links=db:5432,8000-8001 vm=devvm-app-[0-9a-f]{14}$'
! stdout 'group_links_added .* vm=devvm-db-'
exec sh -c 'id=$(sed -n "s/^ \"id\": \"\(.*\)\",$/\1/p" "$DB_dir/vm.json"); [ "$(grep -c "\"target_id\": \"$id\"" "$APP_dir/vm.json")" = 3 ]'
vm_state $APP_dir/vm.json
stdout '^links.links.0.name=db\nlinks.links.0.port=5432\nlinks.links.0.target=devvm-db-[0-9a-f]{14}\n'
stdout '^links.links.0.addr=127.77.0.1\nlinks.links.0.group=true\n'
stdout '^links.links.1.name=db\nlinks.links.1.port=8000\n'
stdout '^links.links.1.addr=127.77.0.1\nlinks.links.1.group=true\n'
stdout '^links.links.2.name=db\nlinks.links.2.port=8001\n'
stdout '^links.links.2.addr=127.77.0.1\nlinks.links.2.group=true\n'
! stdout '^links.links.3'
# One tier: cache, on allowlist, can't join a group whose VMs are open,
# and a group of its own refuses those on another tier.
cd $WORK/cache
! exec devvm group join web
stderr '^devvm: group_tier_mismatch group=web tier=open vm=devvm-cache-[0-9a-f]{14} vm_tier=allowlist$'
exec devvm group join safe
stdout '^==> group_made group=safe '
cd $WORK/y/api
! exec devvm group join safe
stderr '^devvm: group_tier_mismatch group=safe tier=allowlist vm=devvm-api-[0-9a-f]{14} vm_tier=open$'
# A member's tier can't change.
cd $WORK/cache
! exec devvm network open
stderr '^devvm: group_tier_fixed group=safe vm=devvm-cache-[0-9a-f]{14}$'
vm_state $CACHE_dir/vm.json
stdout '^net.tier=allowlist$'
cd $WORK/db
! exec devvm network allowlist
stderr '^devvm: group_tier_fixed group=web vm=devvm-db-[0-9a-f]{14}$'
cd $WORK/cache
exec devvm group leave
stdout '^==> group_left group=safe vm=devvm-cache-[0-9a-f]{14}$'
stdout '^==> group_gone group=safe$'
# Two members with the same folder part: the first's name would be the
# second's own hostname, so the second is refused whatever it joins as,
# until the first joins again with another name.
cd $WORK/x/api
exec devvm group join web
stdout '^==> group_links_added group=web links=api:80 vm=devvm-app-'
stdout '^==> group_links_added group=web links=api:80 vm=devvm-db-'
stdout '^==> group_links_added group=web links=db:5432,8000-8001 vm=devvm-api-'
cd $WORK/y/api
! exec devvm group join web
stderr '^devvm: group_name_hostname group=web member=devvm-api-[0-9a-f]{14} name=api vm=devvm-api-[0-9a-f]{14}$'
! exec devvm group join web --as api2
stderr '^devvm: group_name_hostname group=web member=devvm-api-[0-9a-f]{14} name=api vm=devvm-api-[0-9a-f]{14}$'
exec sh -c 'grep -l "\"group\": \"web\"" $(grep -l "\"name\": \"devvm-api-" "$VMS"/*/vm.json) | wc -l'
stdout '^ *1$'
cd $WORK/x/api
exec devvm group leave
exec devvm group join web --as api1
stdout '^==> group_links_added group=web links=api1:80 vm=devvm-app-'
cd $WORK/y/api
! exec devvm group join web
stderr '^devvm: group_name_taken group=web member=devvm-api-[0-9a-f]{14} name=api$'
! exec devvm group join web --as db
stderr '^devvm: group_name_taken group=web member=devvm-db-[0-9a-f]{14} name=db$'
! exec devvm group join web --as localhost
stderr '^devvm: group_name_host vm=devvm-api-[0-9a-f]{14}$'
exec devvm group join web --as api2
stdout '^==> group_joined group=web '
! stderr group_link_name
stdout '^==> group_links_added group=web links=api2:3000 vm=devvm-app-'
stdout '^==> group_links_added group=web links=api1:80, db:5432,8000-8001 vm=devvm-api-'
# A folder whose name is the name a member joined with: its own hostname
# would name that member.
project api1
exec devvm --network open --no-git-protect
! exec devvm group join web --as other
stderr '^devvm: group_name_hostname group=web member=devvm-api-[0-9a-f]{14} name=api1 vm=devvm-api1-[0-9a-f]{14}$'
# The group: each VM, its name, folder and published ports.
cd $WORK/app
exec devvm group
stdout '\ANAME +VM +FOLDER +PUBLISHED\n'
stdout '^api1 +devvm-api-[0-9a-f]{14} +\S*/x/api +80$'
stdout '^api2 +devvm-api-[0-9a-f]{14} +\S*/y/api +3000$'
stdout '^app +devvm-app-[0-9a-f]{14} +\S*/app +none$'
stdout '^db +devvm-db-[0-9a-f]{14} +\S*/db +5432,8000-8001$'
exec devvm group --json
stdout '\A{\n "version": 1,\n "group": "web",\n "members": \[\n {\n "name": "api1",\n "vm": "devvm-api-[0-9a-f]{14}",\n "folder": "\S*/x/api",\n "published": "80"\n },\n'
exec devvm link
stdout '^api2 +3000 +devvm-api-[0-9a-f]{14} +\S*/y/api +Running +yes$'
stdout '^db +8001 +devvm-db-[0-9a-f]{14} +\S*/db +Running +yes$'
# A group's link isn't devvm link rm's; a link of the user's to a
# member's port takes its place, and its name names the member; removed,
# the group's comes back.
! exec devvm link rm db 8000
stderr '^devvm: link_from_group group=web name=db port=8000 vm=devvm-app-[0-9a-f]{14}$'
exec devvm link add db 8000 --as pg
stdout '^==> link_added name=pg port=8000 '
stdout '^==> group_links_removed group=web links=db:5432,8000-8001 vm=devvm-app-'
stdout '^==> group_links_added group=web links=pg:5432,8001 vm=devvm-app-'
vm_state $APP_dir/vm.json
stdout '^links.links.\d+.addr=127\.77\.0\.1\nlinks.links.\d+.name=pg\nlinks.links.\d+.port=8000\nlinks.links.\d+.target=devvm-db-[0-9a-f]{14}\nlinks.links.\d+.target_id=[0-9a-f]{32}\n'
exec devvm link rm pg 8000
stdout '^==> link_removed name=pg port=8000 '
stdout '^==> group_links_added group=web links=db:5432,8000-8001 vm=devvm-app-'
# A link of the user's whose name is another member's takes it: the
# group's links to that member go, said; removed, they come back.
exec devvm link add ../y/api 3000 --as api1
stdout '^==> link_added name=api1 port=3000 '
stderr '^devvm: group_link_name_clash name=api1 target=devvm-api-[0-9a-f]{14} vm=devvm-app-[0-9a-f]{14}$'
stdout '^==> group_links_removed group=web links=api1:80, api2:3000 vm=devvm-app-'
exec devvm link rm api1 3000
stdout '^==> group_links_added group=web links=api1:80, api2:3000 vm=devvm-app-'
# Published ports reach every member's links at once.
cd $WORK/db
exec devvm link publish 6379
stdout '^==> group_links_added group=web links=db:6379 vm=devvm-app-'
stdout '^==> group_links_added group=web links=db:6379 vm=devvm-api-'
exec devvm link unpublish 6379
stdout '^==> group_links_removed group=web links=db:6379 vm=devvm-app-'
! stderr unpublished_linked
# A stopped member gets the change at its next start.
cd $WORK/x/api
exec devvm stop
cd $WORK/db
exec devvm link publish 7000
stdout '^==> group_links_added group=web links=db:7000 vm=devvm-api-[0-9a-f]{14}$'
stdout '^==> setting_set vm=devvm-api-[0-9a-f]{14}$'
# leave: only the group's links go, each named; the user's stay.
cd $WORK/app
exec devvm link add db 7000
exec devvm group leave
stdout '^==> group_left group=web vm=devvm-app-[0-9a-f]{14}$'
stdout '^==> group_links_removed group=web links=api1:80, api2:3000, db:5432,8000-8001 vm=devvm-app-[0-9a-f]{14}$'
vm_state $APP_dir/vm.json
stdout '^links.links.0.addr=127\.77\.0\.1\nlinks.links.0.name=db\nlinks.links.0.port=7000\nlinks.links.0.target=devvm-db-[0-9a-f]{14}\nlinks.links.0.target_id=[0-9a-f]{32}\n'
! stdout '^links.links.1\.'
! stdout '^links.group'
exec devvm group
stdout '^==> group_none '
cd $WORK/db
exec devvm group
! stdout '^app '
# devvm rm of a member takes it out, and the last one's leaving removes
# the group.
cd $WORK/y/api
exec devvm rm --force --no-export
stdout '^==> group_left group=web vm=devvm-api-[0-9a-f]{14}$'
cd $WORK/x/api
exec devvm group leave
stdout '^==> group_left group=web '
cd $WORK/db
exec devvm group leave
stdout '^==> group_gone group=web$'
exec sh -c 'grep -l "\"group\": \"web\"" "$VMS"/*/vm.json || true'
! stdout .
# Two VMs joining one group at once, app open and cache on allowlist:
# they take turns, so only one gets in.
exec sh -c '(cd "$WORK/app" && devvm group join race) & (cd "$WORK/cache" && devvm group join race) & wait; true'
stderr 'devvm: group_tier_mismatch group=race '
exec sh -c 'grep -l "\"group\": \"race\"" "$VMS"/*/vm.json | wc -l'
stdout '^ *1$'
exec sh -c 'for d in app cache; do (cd "$WORK/$d" && devvm group leave) || true; done'
stdout '^==> group_gone group=race$'