Files
devvm/testdata/script/subfolder.txtar
T
w3cjandClaude Opus 5.5 1812867162 fix(vm): a subfolder's lookup stops at the nearest parent with state; widening a parent's VM asks
The parent-folder lookup passed over a parent whose VM was made for an
earlier folder or that its backend had lost, and went on to a VM further
out. A VM can rename a nested project folder through its mount (a new
device and inode), so devvm skipped the nested folder's VM and acted on
the outer one, the VM that replaced it. parentVM now stops at the first
parent folder with state of its own: its VM is used only when its backend
has it and it was made for that folder, else the folder devvm runs in has
no VM (no_vm; devvm makes a new one). Only folders without state are
passed over.

Commands that give a parent folder's VM more access, run from a
subfolder, ask first ([y/N]), naming the VM and its folder, and refuse
without a terminal: devvm secret use, ssh-agent on and devvm, network
off, policy allow, policy rm of a deny, and git-protect off (found.widen).

Messages: widen_parent_vm (the prompt), widen_parent_vm_refused (linked
to getting-started/commands#a-subfolder).

Tests: TestLookupParents (a parent's lost VM and another folder's VM stop
the search: no VM, no_vm), TestWidenParentVM (each command refused
without a terminal, a no changing nothing, a yes changing it; taking
access away asks nothing), subfolder.txtar (the refusals without a
terminal).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-30 23:51:07 -07:00

120 lines
4.1 KiB
Plaintext

# devvm in a subfolder of a folder with a VM: without a terminal it opens
# that VM in the subfolder, saying so; --here and --clone make the
# subfolder its own; stop acts on the parent's VM, naming it first; rm
# refuses it without a terminal. adopt doesn't look upward, and nothing
# does from a repo of its own below the parent's folder. Commands that
# give the parent's VM more access are refused without a terminal.
env DEVVM_MESSAGES=names
env VMS=$XDG_DATA_HOME/devvm/vms
mkdir $WORK/app/src/lib
cd $WORK/app
exec git init -q
exec devvm --no-network-policy base
# The parent's VM, its shell in the subfolder.
cd $WORK/app/src/lib
exec sh -c ': > "$STUB_LOG"'
exec devvm
stdout '^==> using_parent_vm dir=/\S*/app vm=devvm-app-[0-9a-f]{14}$'
! stdout creating
stub_calls
! stdout 'limactl (clone|create)'
stdout '^limactl shell --workdir /\S*/app/src/lib devvm-app-[0-9a-f]{14}\n\z'
exec sh -c 'ls "$VMS" | wc -l'
stdout '^ *1$'
# adopt is for this path's VM only.
! exec devvm adopt
stderr '^devvm: no_vm dir=/\S*/app/src/lib$'
# stop: the parent's, named first.
exec sh -c ': > "$STUB_LOG"'
exec devvm stop
stdout '^==> using_parent_vm dir=/\S*/app vm=devvm-app-[0-9a-f]{14}\n==> stopped vm=devvm-app-[0-9a-f]{14}$'
stub_calls
stdout '^limactl stop devvm-app-[0-9a-f]{14}$'
# --here: a new VM for the subfolder, nothing asked; then it's the
# subfolder's own.
cd $WORK/app/src
exec devvm --here --no-network-policy base
stdout '^==> creating_from image=base vm=devvm-src-[0-9a-f]{14}$'
! stdout using_parent_vm
exec sh -c ': > "$STUB_LOG"'
exec devvm
! stdout using_parent_vm
stub_calls
stdout '^limactl shell --workdir /\S*/app/src devvm-src-[0-9a-f]{14}\n\z'
# The nearest folder with a VM wins.
cd $WORK/app/src/lib
exec devvm stop
stdout '^==> using_parent_vm dir=/\S*/app/src vm=devvm-src-[0-9a-f]{14}$'
# A repo of its own below the parent's folder: other commands find no VM,
# and without a terminal devvm makes the subfolder's own.
mkdir $WORK/app/tool/bin
cd $WORK/app/tool
exec git init -q
cd $WORK/app/tool/bin
! exec devvm stop
stderr '^devvm: no_vm dir=/\S*/app/tool/bin$'
! stdout using_parent_vm
exec devvm --no-network-policy base
stdout '^==> creating_from image=base vm=devvm-bin-[0-9a-f]{14}$'
! stdout using_parent_vm
exec devvm rm -f
# --clone: a new VM for the subfolder's own repo, as --here, nothing
# asked.
mkdir $WORK/app/repo
cd $WORK/app/repo
env GIT_AUTHOR_NAME=t GIT_AUTHOR_EMAIL=t@t GIT_COMMITTER_NAME=t GIT_COMMITTER_EMAIL=t@t
exec git init -q -b main
exec git commit -q --allow-empty -m one
exec devvm --clone --no-network-policy base
stdout '^==> creating_from image=base vm=devvm-repo-[0-9a-f]{14}$'
! stdout using_parent_vm
exec devvm rm -f
# rm: never a parent's without asking. Without a terminal it's refused,
# -f or not, and nothing is deleted; in the parent's folder it goes.
cd $WORK/app/src
exec devvm rm
cd $WORK/app/src/lib
# Commands that give a parent's VM more access are refused without a
# terminal, naming the VM and its folder, and change nothing.
! exec devvm secret use github
stderr '^devvm: widen_parent_vm_refused cmd=devvm secret use dir=/\S*/app vm=devvm-app-[0-9a-f]{14}$'
! exec devvm ssh-agent on
stderr '^devvm: widen_parent_vm_refused cmd=devvm ssh-agent on dir=/\S*/app vm=devvm-app-[0-9a-f]{14}$'
exec devvm ssh-agent
stdout '^off$'
! exec devvm policy allow example.com
stderr '^devvm: widen_parent_vm_refused cmd=devvm policy allow dir=/\S*/app vm=devvm-app-[0-9a-f]{14}$'
exec devvm policy deny bad.example.com
stdout 'rule_added'
! exec devvm policy rm '!bad.example.com'
stderr '^devvm: widen_parent_vm_refused cmd=devvm policy rm dir=/\S*/app vm=devvm-app-[0-9a-f]{14}$'
exec devvm policy
stdout '!bad.example.com'
! stdout '^example.com'
exec sh -c ': > "$STUB_LOG"'
! exec devvm rm -f
stdout '^==> using_parent_vm dir=/\S*/app vm=devvm-app-[0-9a-f]{14}$'
stderr '^devvm: rm_parent_vm dir=/\S*/app vm=devvm-app-[0-9a-f]{14}$'
stub_calls
! stdout 'limactl delete'
exec sh -c 'ls "$VMS" | grep -v "\.policy$" | wc -l'
stdout '^ *1$'
cd $WORK/app
exec devvm rm
stdout '^==> deleted vm=devvm-app-[0-9a-f]{14}$'
exec ls $VMS
! stdout .
cd $WORK/app/src/lib
! exec devvm rm
stderr '^devvm: no_vm dir=/\S*/app/src/lib$'