# devvm in a subfolder of a folder with a VM: 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 unless --parent. Commands that give # the parent's VM more access are refused without a terminal. mkdir $WORK/app/src/lib cd $WORK/app exec git init -q exec devvm --network open # The parent's VM, its shell in the subfolder. cd $WORK/app/src/lib stub_reset 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 --start=false --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. stub_reset 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 --network open stdout '^==> creating_from image=base vm=devvm-src-[0-9a-f]{14}$' ! stdout using_parent_vm stub_reset exec devvm ! stdout using_parent_vm stub_calls stdout '^limactl shell --start=false --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 devvm makes the subfolder's own. --parent takes the parent's # across the repo. 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 stub_reset exec devvm --parent stdout '^==> using_parent_vm dir=/\S*/app vm=devvm-app-[0-9a-f]{14}$' stub_calls stdout '^limactl shell --start=false --workdir /\S*/app/tool/bin devvm-app-[0-9a-f]{14}\n\z' exec devvm stop --parent stdout '^==> using_parent_vm dir=/\S*/app vm=devvm-app-[0-9a-f]{14}\n==> stopped vm=devvm-app-[0-9a-f]{14}$' exec devvm --network open stdout '^==> creating_from image=base vm=devvm-bin-[0-9a-f]{14}$' ! stdout using_parent_vm # Once it has its own: --parent passes over it, --here keeps to it, and # the two don't go together. exec devvm stop --parent stdout '^==> already_stopped vm=devvm-app-[0-9a-f]{14}$' exec devvm stop --here ! stdout using_parent_vm stdout '^==> stopped vm=devvm-bin-[0-9a-f]{14}$' ! exec devvm stop --here --parent stderr '^devvm: flags_exclusive flag=--here other=--parent$' ! exec devvm --clone --parent stderr '^devvm: flags_exclusive flag=--clone other=--parent$' ! exec devvm rm devvm-bin-0123456789abcd --here stderr '^devvm: rm_vm_folder_flag flag=--here$' exec devvm rm --force --no-export # --parent where no folder above has a VM. cd $WORK/app ! exec devvm stop --parent stderr '^devvm: no_parent_vm dir=/\S*/app$' # --clone: the subfolder's own repo's VM, as --here, never the parent's. 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 # The parent's VM mounts the repo, so its seed's host git could be swapped # from there: refused before anything is made, naming that VM. ! exec devvm --clone --network open stderr '^devvm: clone_folder_mounted dir=/\S*/app/repo vm=devvm-app-[0-9a-f]{14}$' ! stdout 'using_parent_vm|creating_from' # rm: never a parent's without asking. Without a terminal it's refused, # --force or not, and nothing is deleted; in the parent's folder it goes. cd $WORK/app/src exec devvm rm --force 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 network allow example.com stderr '^devvm: widen_parent_vm_refused cmd=devvm network allow dir=/\S*/app vm=devvm-app-[0-9a-f]{14}$' exec devvm network deny bad.example.com stdout 'rule_added' ! exec devvm network rm '!bad.example.com' stderr '^devvm: widen_parent_vm_refused cmd=devvm network rm dir=/\S*/app vm=devvm-app-[0-9a-f]{14}$' vm_name APP app exec cat $APP_dir/policy stdout '!bad.example.com' ! stdout '^example.com' stub_reset ! exec devvm rm --force --no-export 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 --force stdout '^==> deleted vm=devvm-app-[0-9a-f]{14}$' exec ls $VMS ! stdout . cd $WORK/app/src/lib ! exec devvm rm --force stderr '^devvm: no_vm dir=/\S*/app/src/lib$'