mirror of
https://github.com/devvmhq/devvm.git
synced 2026-12-01 16:27:33 -10:00
macOS numbers its disks' devices in the order they appear at boot, so after a restart an unchanged project folder's identity (dev:ino:btime) can have another device. The finder then refused its VM as made for an earlier folder (vm_other_folder), a stopped VM's start refused it as replaced (project_folder_changed), and the next .git check called it replaced (git_replaced). platform.SameFolder is now the one comparison of two folder identities: the same ID, or at the same path the same inode and birth time on another device. On another device the ID must also be the one read from the folder opened at the path with no link followed (OpenNoLinks, then fstat and fstatfs on it: openFolderID), on a file system whose IDs are their folder's alone, so a link swapped in while the caller read the ID can't pass a copy's (a snapshot's, a cloned disk's) off as the folder's. A folder at another path (moved) matches only exactly. platform.Renumbered says when the record needs the folder's ID as it is now. The finder's sameFolder, here.movedFrom, gitprotect's protectRepo and the strict conversion's checks use it. A start records the project folder's identity as it is now under the VM's state lock (renumbered, in bringUp) before the backend mounts it by Want.ProjectID, so vz's /.vol/<dev>/<ino> mount names the current boot's device, in the one limactl edit; folderChanged's checks after it then compare exactly. A .git check that accepts a renumbered .git records its current identity. The move's check stays exact, as both its IDs are read in one run. The structure test's folder-ids rule fails on == or != on a field named Folder or GitID, or a call of FolderID or folderID, outside internal/platform and tests, unless exactFolderIDs lists the function with why: the agents' and exports' Folder paths, recordMove's unchanged-state check and folderChanged. Tests: TestSameFolder (platform), TestRenumberedFolder (vm), TestReportsRenumbered (gitprotect), a renumbered vz case in TestProjectMountByInode (lima), existing.txtar's renumbered folder, and fixture_v010_renumbered.txtar on the frozen v0.1.0 state, through the new renumber script command and stubtest.Renumbered. Co-Authored-By: Claude Opus 5.5 <[email protected]>
203 lines
7.1 KiB
Plaintext
203 lines
7.1 KiB
Plaintext
# A VM that exists: devvm opens it as it is, starting it if it's stopped,
|
|
# and sets it up again; flags for new VMs are ignored with a warning, and
|
|
# what its state asks of a stopped VM's size and ports is applied.
|
|
# restart stops it first.
|
|
project web git
|
|
exec devvm --network open
|
|
vm_name WEB web
|
|
|
|
# Running: opened without a start, its host keys kept, set up again.
|
|
stub_reset
|
|
exec devvm
|
|
! stdout 'starting|creating'
|
|
# Each launch on Linux says .git is unprotected (git_watch.txtar).
|
|
[!linux] ! stderr .
|
|
[linux] stderr '\Adevvm: git_unprotected vm=devvm-web-[0-9a-f]{14}\n\z'
|
|
stub_calls
|
|
! stdout 'limactl (start|stop|clone|create|edit|delete)'
|
|
stdout '^limactl shell --workdir / devvm-web-[0-9a-f]{14} sh -c .*tar -xf - '
|
|
stdout '^limactl shell --workdir /\S*/web devvm-web-[0-9a-f]{14}\n\z'
|
|
exec grep -c '^devvm-web-' $WEB_dir/run/known_hosts
|
|
stdout '^1$'
|
|
|
|
# Flags for new VMs: ignored, with a warning for each command that
|
|
# changes the same on the VM.
|
|
exec devvm --network allowlist --cpus 2 --disk 50 --ports none
|
|
stderr '^devvm: new_vm_flags_ignored_run command=devvm network allowlist flags=--network vm=devvm-web-[0-9a-f]{14}$'
|
|
stderr '^devvm: new_vm_flags_ignored_run command=devvm size flags=--cpus, --disk vm=devvm-web-[0-9a-f]{14}$'
|
|
stderr '^devvm: new_vm_flags_ignored_run command=devvm ports LIST flags=--ports vm=devvm-web-[0-9a-f]{14}$'
|
|
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}$'
|
|
vm_state $WEB_dir/vm.json
|
|
stdout '^net.tier=open$'
|
|
|
|
# A size its state asks for: a running VM's waits for its next start; a
|
|
# stopped one's is applied once.
|
|
json_set $WEB_dir/vm.json size.cpus=6
|
|
stub_reset
|
|
exec devvm
|
|
stderr '^devvm: next_start_size vm=devvm-web-[0-9a-f]{14}\ndevvm: next_start count=1 vm=devvm-web-[0-9a-f]{14}$'
|
|
stub_calls
|
|
! stdout 'limactl edit'
|
|
|
|
# Stopped: started, its host keys read again.
|
|
exec limactl stop $WEB
|
|
stub_reset
|
|
exec devvm
|
|
stdout '^==> starting what=devvm-web-[0-9a-f]{14}$'
|
|
! stderr 'next_start'
|
|
stub_calls
|
|
stdout '^limactl edit --tty=false devvm-web-[0-9a-f]{14} --cpus 6$'
|
|
! stdout 'limactl edit .*portForwards'
|
|
stdout '^limactl start --tty=false devvm-web-[0-9a-f]{14}$'
|
|
stdout '^ssh -F none -M .* -l stub 127\.0\.0\.1 sh -s$'
|
|
stdout 'sh -c .*/etc/ssh/ssh_host_'
|
|
# (The stub's VM gets the size its edit asked for.)
|
|
exec stub size $WEB 6 8589934592 107374182400
|
|
exec limactl stop $WEB
|
|
stub_reset
|
|
exec devvm
|
|
stub_calls
|
|
! stdout 'limactl edit'
|
|
|
|
# restart: stopped, then opened.
|
|
stub_reset
|
|
exec devvm restart
|
|
stdout '^==> starting what=devvm-web-[0-9a-f]{14}$'
|
|
stub_calls
|
|
stdout '^limactl stop devvm-web-[0-9a-f]{14}\n(.*\n)*limactl start --tty=false devvm-web-[0-9a-f]{14}\n'
|
|
stdout '^limactl shell --workdir /\S*/web devvm-web-[0-9a-f]{14}\n\z'
|
|
|
|
# --tools, --agents and --layers change nothing on a VM that exists: it
|
|
# opens as it is, warning that devvm tools changes its shared tools and
|
|
# devvm layer add its layers.
|
|
exec devvm --tools go --layers docker
|
|
stderr '^devvm: new_vm_flags_ignored_run command=devvm tools flags=--tools vm=devvm-web-[0-9a-f]{14}$'
|
|
stderr '^devvm: new_vm_flags_ignored_run command=devvm layer add flags=--layers vm=devvm-web-[0-9a-f]{14}$'
|
|
! stdout new_vm_gets
|
|
vm_state $WEB_dir/vm.json
|
|
stdout '^image=base$'
|
|
! stdout '^tools.names=.'
|
|
# Without them, nothing is said.
|
|
exec devvm
|
|
! stderr new_vm_flags_ignored
|
|
|
|
# A VM whose creation didn't finish (its state records no created time)
|
|
# never starts: without a terminal devvm refuses it, and rm deletes it.
|
|
json_set $WEB_dir/vm.json created:=null
|
|
exec limactl stop $WEB
|
|
stub_reset
|
|
! exec devvm
|
|
stderr '^devvm: vm_unfinished vm=devvm-web-[0-9a-f]{14}$'
|
|
! exec devvm restart
|
|
stderr '^devvm: vm_unfinished vm=devvm-web-[0-9a-f]{14}$'
|
|
stub_calls
|
|
! stdout 'limactl (start|stop)'
|
|
# With --no-input in a terminal, nothing is asked either.
|
|
ttyin -stdin $WORK/yes.txt
|
|
! exec devvm --no-input
|
|
stderr '^devvm: vm_unfinished vm=devvm-web-[0-9a-f]{14}$'
|
|
! stderr remake_unfinished
|
|
# In a terminal devvm offers to delete it and make it again: no keeps it.
|
|
ttyin -stdin $WORK/no.txt
|
|
! exec devvm --network open
|
|
stderr '^remake_unfinished vm=devvm-web-[0-9a-f]{14} \[y/N\] devvm: vm_unfinished vm=devvm-web-[0-9a-f]{14}$'
|
|
stub_calls
|
|
! stdout 'limactl (start|stop|delete|clone|create)'
|
|
exists $WEB_dir/vm.json
|
|
# Yes deletes it, then makes it again, finished this time.
|
|
stub_reset
|
|
ttyin -stdin $WORK/yes.txt
|
|
exec devvm --network open
|
|
stdout '^==> deleted vm=devvm-web-[0-9a-f]{14}$'
|
|
stub_calls
|
|
stdout '^limactl delete -f devvm-web-[0-9a-f]{14}\n(.*\n)*limactl clone --tty=false \S+ devvm-web-[0-9a-f]{14} (.*\n)*limactl start --tty=false devvm-web-[0-9a-f]{14}\n'
|
|
vm_state $WEB_dir/vm.json
|
|
! stdout '^created=$'
|
|
stdout '^created=.'
|
|
|
|
# rm: base has no agents, so nothing is exported; only this VM is
|
|
# deleted, with its state, logs (the rotated ones too), host keys and ssh config entry, and .git's
|
|
# locks taken off.
|
|
project api
|
|
exec devvm --network open
|
|
vm_name API api
|
|
cd $WORK/web
|
|
exec sh -c 'l="$WEB_dir/logs" && mkdir -p "$l" && touch "$l/network.jsonl" "$l/network.jsonl.1" "$l/proxy.log" "$l/proxy.log.1"'
|
|
stub_reset
|
|
exec devvm rm --force
|
|
stdout '^==> deleted vm=devvm-web-[0-9a-f]{14}$'
|
|
! stdout exported
|
|
stub_calls
|
|
stdout '^limactl delete -f devvm-web-[0-9a-f]{14}$'
|
|
! stdout 'delete -f devvm-api'
|
|
! stdout 'limactl (start|shell)'
|
|
[darwin] stdout '^chflags -R -P nouchg /\S*/web/\.git/config$'
|
|
! exists $WEB_dir
|
|
exists $API_dir/vm.json
|
|
exec cat $API_dir/run/known_hosts
|
|
stdout devvm-api
|
|
exec cat $DATA/ssh_config
|
|
! stdout devvm-web
|
|
stdout devvm-api
|
|
! exec devvm rm --force
|
|
stderr '^devvm: no_vm dir=/\S*/web$'
|
|
! exec devvm restart
|
|
stderr '^devvm: no_vm dir=/\S*/web$'
|
|
! exec devvm tools update
|
|
stderr '^devvm: no_vm dir=/\S*/web$'
|
|
! exec devvm tools
|
|
stderr '^devvm: no_vm dir=/\S*/web$'
|
|
! exec devvm adopt
|
|
stderr '^devvm: no_vm dir=/\S*/web$'
|
|
|
|
# A delete that fails but leaves no VM cleans up like one that worked.
|
|
cd $WORK/api
|
|
exec sh -c ': > "$STUB_DIR/delete-fails"'
|
|
exec devvm rm --force --no-export
|
|
stdout '^==> deleted vm=devvm-api-[0-9a-f]{14}$'
|
|
! exists $API_dir
|
|
rm $STUB_DIR/delete-fails
|
|
|
|
# A boot that numbered the folder's disk anew, as macOS does: the same
|
|
# folder and .git, so its VM starts, and its state records them on the
|
|
# device they're on now.
|
|
project boot git
|
|
exec devvm --network open
|
|
vm_name BOOT boot
|
|
exec devvm stop
|
|
renumber $BOOT_dir/vm.json
|
|
exec devvm
|
|
! stderr 'vm_other_folder|project_folder_changed|git_replaced'
|
|
vm_state $BOOT_dir/vm.json
|
|
stdout '^folder='$FOLDER_ID'$'
|
|
[darwin] stdout '^git\.made\.git_id='$GIT_ID'$'
|
|
cd $WORK
|
|
|
|
# A folder made again at the same path: rm and adopt ask first, so
|
|
# without a terminal neither deletes nor takes the VM over.
|
|
project site
|
|
exec devvm --network open
|
|
cd $WORK
|
|
rm site
|
|
mkdir site
|
|
cd site
|
|
stub_reset
|
|
! exec devvm
|
|
stderr '^devvm: vm_other_folder vm=devvm-site-[0-9a-f]{14} was=/\S*/site$'
|
|
! exec devvm rm --force --no-export
|
|
stderr '^devvm: vm_other_folder_rm vm=devvm-site-[0-9a-f]{14} was=/\S*/site$'
|
|
! exec devvm adopt
|
|
stderr '^devvm: vm_other_folder_adopt vm=devvm-site-[0-9a-f]{14} was=/\S*/site$'
|
|
! exec devvm restart
|
|
stderr '^devvm: vm_other_folder '
|
|
stub_calls
|
|
! stdout 'limactl (delete|stop|start)'
|
|
vm_name SITE site
|
|
exists $SITE_dir/vm.json
|
|
|
|
-- yes.txt --
|
|
y
|
|
-- no.txt --
|
|
n
|