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

151 lines
4.9 KiB
Plaintext

# devvm git-protect: shows a folder's VM's .git protection, and turns it on,
# strict or off while the VM is stopped; a running VM's change is saved and
# applied when it next stops. Strict also keeps host git status and diff
# out of submodules (diff.ignoreSubmodules=all in .git/config). Locks need
# macOS: elsewhere on and strict are refused. The chflags stub changes no
# flags.
# No VM yet.
project web
! exec devvm git-protect
stderr '^devvm: no_vm_git_protect dir=\S*/web$'
! exec devvm git-protect maybe
stderr '^devvm: arg_not_choice choices=on, strict, off command=devvm git-protect given=maybe$'
# A new VM, running: shown, but on macOS changed only when it next stops
# (it could race the locks), the last choice kept; elsewhere off, and on
# is refused.
exec git init -q
exec devvm --network open
vm_name WEB web
exec devvm git-protect
[darwin] stdout '\Aon\n\z'
[linux] stdout '\Aoff\n\z'
[linux] exec devvm git-protect off
[linux] stdout '^==> git_unlocked vm=devvm-web-[0-9a-f]{14}$'
[linux] ! exec devvm git-protect strict
[linux] stderr '^devvm: git_protect_on_needs_macos$'
[linux] stop 'no locks off macOS'
stub_reset
exec devvm git-protect strict
stdout '^==> git_protect_next_stop mode=strict vm=devvm-web-[0-9a-f]{14}$'
exec devvm git-protect off
stdout '^==> git_protect_next_stop mode=off vm=devvm-web-[0-9a-f]{14}$'
stub_calls
! stdout chflags
exec devvm git-protect
stdout '\Aon\n\z'
vm_state $WEB_dir/vm.json
stdout '^git.next=off$'
# devvm stop applies it.
exec devvm stop
stdout '^==> git_unlocked vm=devvm-web-[0-9a-f]{14}$'
stub_calls
stdout '^chflags -R -P nouchg /\S*/web/\.git/config$'
exec devvm git-protect
stdout '\Aoff\n\z'
vm_state $WEB_dir/vm.json
! stdout '^git.next=.'
# Stopped outside devvm: the next launch applies it before the VM starts.
exec devvm
exec devvm git-protect on
stdout '^==> git_protect_next_stop mode=on vm=devvm-web-[0-9a-f]{14}$'
exec limactl stop $WEB
stub_reset
exec devvm
stdout '^==> git_locked vm=devvm-web-[0-9a-f]{14}$'
stub_calls
stdout '^chflags -R -P uchg /\S*/web/\.git/config\n(.*\n)*limactl .*start'
exec devvm git-protect
stdout '\Aon\n\z'
# A .git the VM replaced while it ran is named when it stops, before the
# mode saved meanwhile is set and takes .git as it is.
exec devvm git-protect strict
stdout '^==> git_protect_next_stop mode=strict vm=devvm-web-[0-9a-f]{14}$'
mv .git .git-old
exec git init -q
exec devvm stop
stderr '^devvm: git_replaced git=\S*/web/\.git$'
stdout '^==> git_locked_strict vm=devvm-web-[0-9a-f]{14}$'
exec devvm
exec devvm git-protect
stdout '\Astrict\n\z'
rm .git-old
# Stopped: strict sets diff.ignoreSubmodules with .git/config unlocked,
# then locks .git again.
exec limactl stop $WEB
stub_reset
exec devvm git-protect strict
stdout '^==> git_locked_strict vm=devvm-web-[0-9a-f]{14}$'
exec git config --file .git/config diff.ignoreSubmodules
stdout '\Aall\n\z'
stub_calls
stdout '^chflags -R -P nouchg /\S*/web/\.git/config\n(.*\n)*chflags -R -P uchg /\S*/web/\.git/config$'
stdout '^chflags -R -P uchg /\S*/web/\.git/hooks$'
! stdout 'limactl (start|edit)'
exec devvm git-protect
stdout '\Astrict\n\z'
exec devvm git-protect --json
stdout '\A{\n "version": 1,\n "mode": "strict"\n}\n\z'
! exec devvm git-protect --json off
stderr '^devvm: json_shows_only command=devvm git-protect$'
vm_state $WEB_dir/vm.json
stdout '^git.mode=strict$'
stdout '^git.made.git_id=[0-9]+:[0-9]+'
# On takes diff.ignoreSubmodules back out.
exec devvm git-protect on
stdout '^==> git_locked vm=devvm-web-[0-9a-f]{14}$'
! exec git config --file .git/config diff.ignoreSubmodules
# Off unlocks, and takes it out too; a launch then locks nothing.
exec devvm git-protect strict
stub_reset
exec devvm git-protect off
stdout '^==> git_unlocked vm=devvm-web-[0-9a-f]{14}$'
! exec git config --file .git/config diff.ignoreSubmodules
stub_calls
stdout '^chflags -R -P nouchg /\S*/web/\.git/hooks$'
stdout '^chflags -R -P nouchg /\S*/web/\.git/config$'
! stdout ' uchg '
exec devvm git-protect
stdout '\Aoff\n\z'
exec limactl stop $WEB
stub_reset
exec devvm
stub_calls
! stdout chflags
# --no-git-protect on an existing VM names devvm git-protect off.
exec devvm --no-git-protect
stderr '^devvm: new_vm_flags_ignored_run command=devvm git-protect off flags=--no-git-protect vm=devvm-web-[0-9a-f]{14}$'
# Strict is kept on launches, and rm unlocks it.
exec limactl stop $WEB
exec devvm git-protect strict
stub_reset
exec devvm
stub_calls
stdout '^chflags -R -P uchg /\S*/web/\.git/config$'
stub_reset
exec devvm rm --force --no-export
stub_calls
stdout '^chflags -R -P nouchg /\S*/web/\.git/config$'
# Without a .git yet: locked when one appears.
project nogit
exec devvm --network open
vm_name NOGIT nogit
exec limactl stop $NOGIT
exec devvm git-protect on
stdout '^==> git_lock_later vm=devvm-nogit-[0-9a-f]{14}$'
# A --clone VM mounts no .git: shown as clone, never changed.
json_set $NOGIT_dir/vm.json clone.on:=true git.mode=clone
exec devvm git-protect
stdout '\Aclone\n\z'
! exec devvm git-protect on
stderr '^devvm: git_protect_clone vm=devvm-nogit-[0-9a-f]{14}$'