Files
devvm/testdata/script/nested_replaced.txtar
T
w3cjandClaude Opus 5.5 78530c3a35 feat(vm): warn when a project folder is inside another VM's mounted folder
A project VM mounts its whole folder read-write, so a nested project with
a VM of its own is in the parent folder's VM too: code there can change
the nested project's files, .git included where .git protection doesn't
cover it, and replace its folder (which devvm's start refuses since the
nested-replaced checks). devvm now says so each time it makes or opens
such a VM: once per run of devvm, naming the nearest parent folder's VM
that mounts the project (project_in_vm_folder, linked to using/vms.md's
"A nested project replaced").

The finder owns the walk up: parentVM's loop over project.Parents is now
finder.parents, which mountedBy shares. mountedBy reads only the states,
so a stopped parent VM counts (it writes whenever it runs), and it passes
over --clone VMs, which mount nothing, and states made for another
folder. warnMounted skips a --clone VM of the folder's own, new or not.
Only Up warns; devvm restart and the other commands don't.

Docs: using/vms.md says when devvm warns and why; internals/overview.md
how the finder finds the VM; attack-vectors.md's nested entry mentions it.

Tests: TestWarnMounted (the nested VM's creation and next launch with the
parent stopped warn once; the parent's own launch, the parent's VM in a
subfolder, a new --clone VM and a parent --clone VM don't);
nested_replaced.txtar checks the same through the CLI, and that devvm
restart doesn't warn.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-06 08:02:00 -07:00

64 lines
2.5 KiB
Plaintext

# A nested project folder, a repo of its own inside a folder with a VM,
# replaced with a link after devvm found its VM, as the parent folder's
# VM could do through its mount: devvm never starts the nested VM on the
# link. Replaced once devvm restart's stop ends, devvm refuses before the
# start, its .git checks never run on the link's folder; replaced as Lima
# starts the VM, devvm stops it again and refuses. Put back, it starts.
# Each launch of the nested VM, its creation included, warns once that
# the parent folder's VM mounts it, running or not; the parent's own
# launch, a --clone VM's and devvm restart don't.
env GIT_AUTHOR_NAME=t GIT_AUTHOR_EMAIL=t@t GIT_COMMITTER_NAME=t GIT_COMMITTER_EMAIL=t@t
mkdir $WORK/app/inner
mkdir $WORK/app/cloned
mkdir $WORK/decoy
cd $WORK/app
exec git init -q
exec devvm --network open
! stderr project_in_vm_folder
exec devvm stop
cd $WORK/app/inner
exec git init -q
exec devvm --network open
stdout '^==> creating_from image=base vm=devvm-inner-[0-9a-f]{14}$'
stderr -count=1 '^devvm: project_in_vm_folder dir=/\S*/app/inner vm=devvm-app-[0-9a-f]{14}$'
exec devvm
stderr -count=1 '^devvm: project_in_vm_folder dir=/\S*/app/inner vm=devvm-app-[0-9a-f]{14}$'
cd $WORK/app/cloned
exec git init -q
exec git commit -q --allow-empty -m init
exec devvm --clone --network open
! stderr project_in_vm_folder
cd $WORK/app/inner
# Replaced once its stop ends: refused before the start.
exec sh -c 'echo "$WORK/app/inner $WORK/decoy" > "$STUB_DIR/stop-links"'
stub_reset
! exec devvm restart
stderr '^devvm: project_folder_changed dir=/\S*/app/inner vm=devvm-inner-[0-9a-f]{14}$'
! stderr project_in_vm_folder
stub_calls
stdout '^limactl stop devvm-inner-[0-9a-f]{14}$'
! stdout 'limactl start'
! stdout 'limactl shell'
! exists $WORK/decoy/.git
# Put back, then replaced as Lima starts it: stopped again, refused.
exec sh -c 'rm "$WORK/app/inner" && mv "$WORK/app/inner.real" "$WORK/app/inner"'
cd $WORK/app/inner
exec sh -c 'echo "$WORK/app/inner $WORK/decoy" > "$STUB_DIR/start-links"'
stub_reset
! exec devvm
stderr '^devvm: project_folder_changed_stopped dir=/\S*/app/inner vm=devvm-inner-[0-9a-f]{14}$'
stub_calls
stdout '^limactl start .*devvm-inner-[0-9a-f]{14}\n(limactl list --json\n)*limactl stop devvm-inner-[0-9a-f]{14}$'
! stdout 'limactl shell'
# Put back: it starts, and opens its shell.
exec sh -c 'rm "$WORK/app/inner" && mv "$WORK/app/inner.real" "$WORK/app/inner"'
cd $WORK/app/inner
stub_reset
exec devvm
stub_calls
stdout '^limactl start .*devvm-inner-[0-9a-f]{14}$'
stdout '^limactl shell --workdir /\S*/app/inner devvm-inner-[0-9a-f]{14}$'