Files
devvm/testdata/script/space.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

116 lines
5.9 KiB
Plaintext

# space: each kind of thing devvm keeps, with its count, size, whether
# devvm makes it again, what gc frees of it now and what frees the rest,
# then a total; Lima's caches apart. It changes nothing: no Lima command
# but listings.
env SHARE=$XDG_DATA_HOME/devvm/tools
# Nothing yet: devvm's state and the total.
exec devvm space
stdout '^WHAT +COUNT +SIZE +KEPT +GC +FREED BY +RETAIN\n'
stdout '^state +1 +\S+ +state +- +- +-\n'
stdout '^total +- +\S+ +- +- +- +-\n'
! stdout '^images'
! stderr .
# base and foo, then foo is stale; claude's tools, current, an old go a VM
# has and one nothing has; a Lima VM, and the state of one Lima no longer
# has; an export, network and run logs.
mkdir $XDG_CONFIG_HOME/devvm/layers
cp foo.sh $XDG_CONFIG_HOME/devvm/layers/foo.sh
exec devvm build foo
project ag
exec devvm --tools none --agents claude --network open --no-git-protect
exec devvm rm --force --no-export
exec sh -c 'echo "# edited" >> "$XDG_CONFIG_HOME/devvm/layers/foo.sh"'
exec sh -c 'cd "$SHARE" && echo x > go-1.20.0-0123456789ab.erofs && echo x > go-1.9.0-0123456789ab.erofs'
json_set $SHARE/go-1.20.0-0123456789ab.erofs.json sha256=x libc=gnu backend=lima built=2020-01-01T00:00:00Z
mkdir $VMS/12345612345601/logs $VMS/12345612345602/logs
json_set $VMS/12345612345601/vm.json version:=1 id=p name=devvm-p-12345612345601 image=base dir=/p backend=lima created=2020-01-01T00:00:00Z tools.names:=["go"] tools.made.libc=gnu tools.made.files:=["go-1.20.0-0123456789ab.erofs"]
# The one Lima no longer has was made in this run's Lima home, its state
# unchanged for over an hour: what devvm gc --orphans would forget.
exec sh -c 'printf %s "$DEVVM_LIMA_HOME" | { sha256sum 2>/dev/null || shasum -a 256; } | cut -c1-16 > at'
exec sh -c 'printf "{\"version\": 1, \"id\": \"gone\", \"name\": \"devvm-gone-12345612345602\", \"image\": \"base\", \"dir\": \"/q\", \"backend\": \"lima\", \"backend_at\": \"%s\", \"created\": \"2020-01-01T00:00:00Z\", \"tools\": {\"names\": [\"go\"], \"made\": {\"libc\": \"gnu\"}}}\n" "$(cat at)" > "$VMS/12345612345602/vm.json" && touch -t 202001010000 "$VMS/12345612345602/vm.json"'
exec stub vm devvm-p-12345612345601 Stopped
mkdir $DATA/exports $DATA/logs $DATA/cache/mise/2026.1.1
exec sh -c 'echo x > "$DATA/exports/devvm-old-12345612345612-20260101-000000.tar.gz"'
# The VM's network and proxy logs are network logs; the gone one's are
# part of its leftover state.
exec sh -c 'echo x > "$VMS/12345612345601/logs/network.jsonl" && echo x > "$VMS/12345612345601/logs/proxy.log" && echo x > "$VMS/12345612345602/logs/proxy.log"'
stub_reset
exec devvm space
stdout '^VMs +1 +\S+ +only copy +- +devvm rm +-$'
stdout '^images +2 +\S+ +remade +\S+ +images rm +-$'
stdout '^tools gnu +\d+ +\S+ +remade +- +gc --tool-images +-$'
stdout '^tools - +1 +\S+ +remade +\S+ +gc --tool-images +-$'
stdout '^history +1 +\S+ +only copy +- +gc --history +-$'
stdout '^network logs +2 +\S+ +log +- +devvm rm +-$'
stdout '^run logs +\d+ +\S+ +log +- +the newest 20 stay +-$'
stdout '^mise +1 +'
stdout '^leftover state +1 +\S+ +leftover +- +gc --orphans +-$'
stdout '^total +- +\S+ +- +\S+ +- +-$'
! stdout '^devvm.s files'
# The VM's folder, /p, is gone: named, while the one Lima lost isn't.
stderr '\Aspace_folder_gone dir=/p vm=devvm-p-12345612345601\n\z'
stub_calls
! stdout 'create|clone|delete|start|stop|edit|rm |prune|shell'
# Leftover state is only what devvm gc --orphans would forget: never a VM
# Lima no longer has whose state changed in the last hour (it may be being
# made), nor one made in another Lima home.
mkdir $VMS/12345612345604 $VMS/12345612345605
exec sh -c 'printf "{\"version\": 1, \"id\": \"new\", \"name\": \"devvm-new-12345612345604\", \"image\": \"base\", \"dir\": \"/n\", \"backend\": \"lima\", \"backend_at\": \"%s\", \"created\": \"2020-01-01T00:00:00Z\"}\n" "$(cat at)" > "$VMS/12345612345604/vm.json"'
json_set $VMS/12345612345605/vm.json version:=1 id=moved name=devvm-moved-12345612345605 image=base dir=/m backend=lima backend_at=0000000000000000 created=2020-01-01T00:00:00Z
exec touch -t 202001010000 $VMS/12345612345605/vm.json
exec devvm space
stdout '^leftover state +1 +\S+ +leftover +- +gc --orphans +-$'
# gc lists the same one, and without a terminal or --force deletes nothing.
! exec devvm gc --orphans
stdout '^gc_orphans count=1$'
stdout '^gc_orphan backend=lima dir=/q vm=devvm-gone-12345612345602$'
stderr '^devvm: no_input answer=--force$'
stderr '^gc_orphan_recent vm=devvm-new-12345612345604$'
stderr '^gc_orphan_elsewhere vm=devvm-moved-12345612345605$'
rm $VMS/12345612345604 $VMS/12345612345605
# --backend is no flag of space's.
! exec devvm space --backend lima
stderr '^devvm: flag_unknown command=devvm space flag=--backend$'
# --json, for scripts.
exec devvm space --json
stdout '^{\n "version": 1,\n "devvm": \[\n'
stdout '"what": "leftover state"'
stdout '"kept": "only copy"'
stdout '"total": \d+'
# A backend a VM's state names that doesn't answer is named, and its VMs
# are never leftovers.
mkdir $VMS/12345612345603
json_set $VMS/12345612345603/vm.json version:=1 id=s name=devvm-s-12345612345603 image=base dir=/s backend=lima created=2020-01-01T00:00:00Z
exec sh -c 'touch "$STUB_DIR/list-fails"'
exec devvm space
stderr '^space_backend_unknown backend=lima$'
! stdout '^leftover state '
# A backend slower than the timeout is named the same way, and its VMs
# aren't leftovers either.
rm $STUB_DIR/list-fails
exec sh -c 'touch "$STUB_DIR/list-hangs"'
env DEVVM_TEST_LIST_TIMEOUT=10m,lima:1s
exec devvm space
stderr '^space_backend_unknown backend=lima$'
! stdout '^leftover state '
rm $STUB_DIR/list-hangs
env DEVVM_TEST_LIST_TIMEOUT=10m
# Lima's download cache, which every Lima home shares: shown apart.
[darwin] mkdir $HOME/Library/Caches/lima/download/by-url-sha256/0123
[darwin] exec sh -c 'echo x > "$HOME/Library/Caches/lima/download/by-url-sha256/0123/data"'
[darwin] exec devvm space
[darwin] stdout '^CACHE +COUNT +SIZE +PATH\ndownload cache +1 +\S+ +\S+/Library/Caches/lima\n'
[darwin] stderr '^space_caches_note$'
-- foo.sh --
#!/bin/bash
echo foo