mirror of
https://github.com/devvmhq/devvm.git
synced 2026-12-01 06:23:17 -10:00
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]>
170 lines
6.5 KiB
Plaintext
170 lines
6.5 KiB
Plaintext
# Retention: every setting off unless devvm retention sets it, and shown
|
|
# bare, off when unset; a bad key or value, or none (KEY=), refused before
|
|
# the file is written; devvm's commands apply the settings once a day,
|
|
# devvm gc --retention at once, each deleting only what its settings name,
|
|
# never a VM nor a tool any VM's state lists.
|
|
env EXPORTS=$XDG_DATA_HOME/devvm/exports
|
|
env SHARE=$XDG_DATA_HOME/devvm/tools
|
|
|
|
mkdir $EXPORTS
|
|
exec sh -c 'cd "$EXPORTS" && for f in devvm-old-12345612345612-20200101-000000 devvm-new-abcdefabcdefab-20991231-235959; do echo x > $f.tar.gz; done'
|
|
|
|
# No file: nothing is deleted, by a command or gc --retention.
|
|
exec devvm space
|
|
exec devvm gc --force --retention
|
|
stdout '^==> retention_off$'
|
|
exists $EXPORTS/devvm-old-12345612345612-20200101-000000.tar.gz
|
|
! exists $DATA/retention.run
|
|
|
|
# Bare, every setting is off.
|
|
exec devvm retention
|
|
cmp stdout want-all-off
|
|
! stderr .
|
|
! exists $DATA/retention.run
|
|
|
|
# Bad keys and values, and a key with no value, are refused, and nothing
|
|
# is written.
|
|
! exec devvm retention history.age=30
|
|
stderr '^devvm: bad_duration value=30$'
|
|
! exec devvm retention history.age=forever
|
|
stderr '^devvm: bad_duration value=forever$'
|
|
exec devvm retention history.age=90m
|
|
exec devvm retention history.age=off
|
|
! grep retention $DATA/settings.json
|
|
! exec devvm retention logs.network.size=10M
|
|
stderr '^devvm: retention_bad '
|
|
! exec devvm retention history.age=
|
|
stderr '^devvm: retention_bad reason=history\.age= has no value, and history\.age=off turns it off$'
|
|
! exec devvm retention history.age=30d tools.unused-age=
|
|
stderr '^devvm: retention_bad '
|
|
! grep retention $DATA/settings.json
|
|
|
|
# Set: devvm retention shows them, and where each came from, and devvm
|
|
# space shows each beside its row, with what it would free.
|
|
exec devvm retention history.age=30d tools.unused-age=1d
|
|
stdout '^==> retention_saved file=\S+/data/devvm/settings\.json$'
|
|
grep '^ "retention": {\n "history.age": "30d",\n "tools.unused-age": "1d"\n }$' $DATA/settings.json
|
|
exec devvm retention
|
|
cmp stdout want-shown
|
|
exec devvm retention --json
|
|
cmp stdout want-shown.json
|
|
! exec devvm retention --json history.count=5
|
|
stderr '^devvm: json_shows_only command=devvm retention$'
|
|
! exec devvm retention history.count=x
|
|
grep '^ "retention": {\n "history.age": "30d",\n "tools.unused-age": "1d"\n }$' $DATA/settings.json
|
|
|
|
# config.toml's settings win, each shown with its path; devvm retention
|
|
# refuses to change one, naming the file and the key, and changes the
|
|
# rest.
|
|
cp config.toml $CFG/config.toml
|
|
exec devvm retention
|
|
stdout '^history\.age=60d # \S*/config/devvm/config\.toml$'
|
|
stdout '^tools\.unused-age=1d # devvm: settings\.json$'
|
|
exec devvm retention --json
|
|
stdout '"history.age": "config.toml",'
|
|
! exec devvm retention history.age=off
|
|
stderr '^devvm: set_in_config file=\S*/config/devvm/config\.toml key=retention\.history\.age$'
|
|
exec devvm retention history.count=3
|
|
exec devvm retention history.count=off
|
|
rm $CFG/config.toml
|
|
exec devvm space
|
|
stdout '^history +2 +\S+ +only copy +- +gc --history +30d \(\S+\)$'
|
|
stdout 'RETAIN'
|
|
|
|
# The next command applies it, once: the old export goes, the new stays.
|
|
exec devvm ls
|
|
stderr '^retention_deleted exports=1 nix_files=0 orphans=0 tools=0$'
|
|
! exists $EXPORTS/devvm-old-12345612345612-20200101-000000.tar.gz
|
|
exists $EXPORTS/devvm-new-abcdefabcdefab-20991231-235959.tar.gz
|
|
exists $DATA/retention.run
|
|
exec sh -c 'echo x > "$EXPORTS/devvm-old-12345612345612-20200101-000001.tar.gz"'
|
|
exec devvm ls
|
|
! stderr retention_deleted
|
|
exists $EXPORTS/devvm-old-12345612345612-20200101-000001.tar.gz
|
|
|
|
# A day later (or a clock that went back) it applies again.
|
|
exec touch -t 202001010000 $DATA/retention.run
|
|
exec devvm ls
|
|
stderr '^retention_deleted exports=1 '
|
|
|
|
# Tools: a current build no VM has is recorded idle, deleted a day later;
|
|
# one a VM's state lists stays.
|
|
# A VM made with the two agents builds their tool images; once it's gone
|
|
# no VM has them.
|
|
project agents git
|
|
exec devvm --tools none --agents claude,codex --network open --no-git-protect
|
|
exec devvm rm --force --no-export
|
|
mkdir $VMS/12345612345612
|
|
exec sh -c 'printf "{\"version\": 1, \"id\": \"x\", \"name\": \"devvm-gone-12345612345612\", \"image\": \"base\", \"dir\": \"/p\", \"backend\": \"lima\", \"created\": \"2020-01-01T00:00:00Z\", \"tools\": {\"names\": [\"claude\"], \"made\": {\"files\": [\"%s\"]}}}\n" "$(cd "$SHARE" && ls claude-*.erofs)" > "$VMS/12345612345612/vm.json"'
|
|
json_set $SHARE/*.erofs.json built=2020-01-01T00:00:00Z
|
|
exec devvm gc --force --retention
|
|
stdout '^==> retention_deleted exports=0 nix_files=0 orphans=0 tools=0$'
|
|
exec sh -c 'grep -l "\"idle_since\": " "$SHARE"/*.json'
|
|
stdout '/codex-\S+\.erofs\.json$'
|
|
! stdout claude
|
|
json_set $SHARE/codex-*.erofs.json idle_since=2020-01-01T00:00:00Z
|
|
|
|
# While a VM is being made (its start hangs), retention keeps the tools
|
|
# and runs the rest; once its devvm is killed, nothing holds the lock.
|
|
project making git
|
|
exec sh -c ': > "$STUB_DIR/start-hangs"'
|
|
! exec devvm --network open &u&
|
|
wait_file $STUB_DIR/hanging
|
|
exec devvm gc --force --retention
|
|
stdout '^==> retention_deleted exports=0 nix_files=0 orphans=0 tools=0$'
|
|
exec sh -c 'grep -l "\"idle_since\": \"2020-01-01T00:00:00Z\"" "$SHARE"/codex-*.erofs.json'
|
|
kill -KILL u
|
|
wait u
|
|
rm $STUB_DIR/start-hangs
|
|
exec sh -c 'rm -f "$STUB_DIR/hanging"'
|
|
|
|
exec devvm gc --force --retention
|
|
stdout '^==> retention_deleted exports=0 nix_files=0 orphans=0 tools=1$'
|
|
exec sh -c 'ls "$SHARE"'
|
|
! stdout codex
|
|
stdout '^claude-'
|
|
|
|
# KEY=off turns a setting off.
|
|
exec devvm retention history.age=off tools.unused-age=off
|
|
! grep retention $DATA/settings.json
|
|
exec devvm retention
|
|
cmp stdout $WORK/want-all-off
|
|
|
|
-- config.toml --
|
|
[retention]
|
|
history.age = "60d"
|
|
-- want-shown --
|
|
logs.runs=off # devvm: default
|
|
history.age=30d # devvm: settings.json
|
|
history.count=off # devvm: default
|
|
tools.unused-age=1d # devvm: settings.json
|
|
orphans.age=off # devvm: default
|
|
nix-cache.size=off # devvm: default
|
|
-- want-shown.json --
|
|
{
|
|
"version": 1,
|
|
"settings": {
|
|
"history.age": "30d",
|
|
"history.count": "off",
|
|
"logs.runs": "off",
|
|
"nix-cache.size": "off",
|
|
"orphans.age": "off",
|
|
"tools.unused-age": "1d"
|
|
},
|
|
"sources": {
|
|
"history.age": "settings.json",
|
|
"history.count": "built-in",
|
|
"logs.runs": "built-in",
|
|
"nix-cache.size": "built-in",
|
|
"orphans.age": "built-in",
|
|
"tools.unused-age": "settings.json"
|
|
}
|
|
}
|
|
-- want-all-off --
|
|
logs.runs=off # devvm: default
|
|
history.age=off # devvm: default
|
|
history.count=off # devvm: default
|
|
tools.unused-age=off # devvm: default
|
|
orphans.age=off # devvm: default
|
|
nix-cache.size=off # devvm: default
|