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

121 lines
5.7 KiB
Plaintext

# gc: deletes what devvm images lists as stale or unfinished, the tool
# images it lists as unused, older versions of devvm's mise and what of the
# package cache no base needs, after
# listing them; not a terminal, so it doesn't ask. Never a project VM (one named like an image included),
# a current image, or a tool image a VM's state lists.
env IMAGES=$XDG_DATA_HOME/devvm/images
env SHARE=$XDG_DATA_HOME/devvm/tools
# Nothing built.
exec devvm gc --force
stdout '^==> nothing_to_clean$'
! stderr .
# base, foo on it and claude's tools; then foo is edited (stale), and
# there's a build that didn't finish, an image whose record is corrupt,
# one without a key's shape, and project VMs, one from a folder named
# img-foo.
mkdir $XDG_CONFIG_HOME/devvm/layers
cp foo.sh $XDG_CONFIG_HOME/devvm/layers/foo.sh
exec devvm build foo
# claude's tools, built for a VM with Claude Code, deleted since.
project agentvm
exec devvm --network open --no-git-protect --tools none --agents claude
exec devvm rm --force --no-export
cd $WORK
exec sh -c 'for i in base foo; do grep -lxF " \"name\": \"$i\"," "$IMAGES"/*/record.json | xargs dirname | xargs basename > "$i.key"; done'
exec sh -c 'echo "# edited" >> "$XDG_CONFIG_HOME/devvm/layers/foo.sh"'
exec sh -c 'for vm in devvm-img-000000000000 devvm-img-111111111111 devvm-img-node devvm-img-foo-12345612345601 devvm-web-12345612345602; do stub vm "$vm" Stopped; done'
mkdir $IMAGES/111111111111
exec sh -c 'echo "not a record" > "$IMAGES/111111111111/record.json"'
# Tool images: claude's (current), an old go a VM lists, one a VM that's
# gone outside devvm still lists in its state, and an old one nothing
# lists, with its record.
exec sh -c 'cd "$SHARE" && for f in go-1.20.0 go-1.19.0 go-1.9.0; do echo x > $f-0123456789ab.erofs; done'
json_set $SHARE/go-1.20.0-0123456789ab.erofs.json sha256=x libc=gnu backend=lima built=2020-01-01T00:00:00Z
json_set $SHARE/go-1.19.0-0123456789ab.erofs.json sha256=x libc=gnu backend=lima built=2020-01-01T00:00:00Z
json_set $SHARE/go-1.9.0-0123456789ab.erofs.json sha256=x libc=gnu backend=lima built=2020-01-01T00:00:00Z
mkdir $VMS/12345612345603 $VMS/12345612345604
json_set $VMS/12345612345603/vm.json version:=1 id=x name=devvm-p-12345612345603 image=go dir=/p backend=lima tools.made.files:=["go-1.20.0-0123456789ab.erofs"]
json_set $VMS/12345612345604/vm.json version:=1 id=y name=devvm-gone-12345612345604 image=go dir=/q backend=lima tools.made.files:=["go-1.19.0-0123456789ab.erofs"]
# The builds wrote none of devvm's own files out: they stay in the binary.
! exists $XDG_DATA_HOME/devvm/assets
# devvm's own mise: an older version, and one another devvm is
# downloading (it changed just now).
mkdir $XDG_DATA_HOME/devvm/cache/mise/2020.1.1 $XDG_DATA_HOME/devvm/cache/mise/2099.1.1
exec touch -t 202001010000 $XDG_DATA_HOME/devvm/cache/mise/2020.1.1
# devvm images says how many images gc deletes, and what it frees.
exec devvm images
stdout '^foo .* stale '
stderr '^images_stale_note count=4$'
stderr '^images_unused size=\S+$'
stub_reset
exec devvm gc --force
stdout '^gc_images\n'
stdout '^gc_image image=foo key=[0-9a-f]{12}$'
stdout '^gc_unfinished key=000000000000$'
stdout '^gc_unfinished key=111111111111$'
stdout '^gc_unfinished key=node$'
stdout '^gc_tools count=1 size=\S+$'
stdout '^gc_mise count=1 size=\S+$'
stdout '^==> deleted_mise count=1$'
! exists $XDG_DATA_HOME/devvm/cache/mise/2020.1.1
exists $XDG_DATA_HOME/devvm/cache/mise/2099.1.1
stdout -count=1 '^==> deleted_image '
stdout -count=3 '^==> deleted_unfinished_build '
stdout '^==> deleted_tools count=1$'
! stdout 'image=base'
exec sh -c 'grep "^limactl delete" "$STUB_LOG" | sort'
cp stdout deleted
exec sh -c 'printf "limactl delete -f devvm-img-%s\n" 000000000000 111111111111 "$(cat foo.key)" node | sort'
cmp stdout deleted
# What's left: base, the project VMs and their records; the tool images
# that are current or listed; nothing in the share is locked.
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-img-foo-12345612345601" "$v" && grep -q "^devvm-web-12345612345602" "$v"'
exec sh -c 'test -f "$IMAGES/$(cat base.key)/record.json" && ! test -e "$IMAGES/$(cat foo.key)" && ! test -e "$IMAGES/111111111111"'
! exists $SHARE/go-1.9.0-0123456789ab.erofs
! exists $SHARE/go-1.9.0-0123456789ab.erofs.json
exists $SHARE/go-1.20.0-0123456789ab.erofs
exists $SHARE/go-1.19.0-0123456789ab.erofs
exec sh -c 'ls "$SHARE"/claude-*.erofs'
! exists $SHARE/.lock
# Again: nothing left, and devvm images says only the total.
exec devvm gc --force
stdout '^==> nothing_to_clean$'
exec devvm images
stderr '^images_total size=\S+$'
! stderr 'images_stale_note|images_unused'
# The package cache: the set of a base the backend no longer has goes, and
# with it the file only it names, as does a file no set names; so does a
# build's folder of what it gave back once it's a day old, but not a new one.
env PKGS=$XDG_DATA_HOME/devvm/packages
env A=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
env B=bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
mkdir $PKGS/sets $PKGS/.taken-old $PKGS/.taken-new
exec sh -c 'echo x > "$PKGS/$A.deb" && echo y > "$PKGS/$B.deb" && touch -t 202001010000 "$PKGS/.taken-old"'
exec sh -c 'printf "{\"recorded\": \"2020-01-01T00:00:00Z\", \"packages\": [{\"name\": \"a\", \"version\": \"1\", \"arch\": \"arm64\", \"sha256\": \"%s\", \"size\": 2, \"entry\": \"Package: a\"}]}\n" "$A" > "$PKGS/sets/222222222222.json"'
exec devvm gc --force
stdout '^gc_packages count=2 size=\S+$'
stdout '^==> deleted_packages count=2$'
! exists $PKGS/sets/222222222222.json
! exists $PKGS/$A.deb
! exists $PKGS/$B.deb
! exists $PKGS/.taken-old
exists $PKGS/.taken-new
exec devvm gc --force
stdout '^==> nothing_to_clean$'
-- foo.sh --
#!/bin/bash
echo foo