mirror of
https://github.com/devvmhq/devvm.git
synced 2026-12-01 06:23:17 -10:00
An export leaves out opencode's worktree folder, as a git repository's config can name a command that git runs, so the uncommitted changes in the worktrees opencode makes there (~/.local/share/opencode/worktree/<project>/<name>, opencode v2.4.1's worktree/strategies.ts) went with the VM's disk on devvm rm, and on a remake with --clean-home, with nothing to say so. The registry gets Worktrees (opencode's worktree/*/*, below its HistoryOwn, TestDefsComplete holding each to a plain pattern there). rm's unsaved-work check, cloneCheck, becomes workCheck: the clone (cloneLost, as before) and the agents' worktrees (agentTrees), one question for both. agentTreesState reads them in the running VM in one command, in its home folder, each * of a pattern sent as *, .[!.]* and ..?* (treeGlobs), so a name that starts with a dot is found: each folder with a .git, its git status and a detached HEAD's commit nothing else has; past 100 it says more. devvm reads at most 8 MiB of the answer, cancelling the command past it, and waits at most treesWait (2 minutes). parseAgentTrees takes the answer as untrusted: whole records of a glob asked for, each path clean, matched by its pattern and once, at most 100, each with one status. Dirty, detached, unreadable (wfail) and more are shown and asked about (delete_anyway or remake_anyway), which --force never answers; refused without a terminal (no_terminal_delete_trees, naming --no-worktree-check, or the clone's no_terminal_delete when it has work too). --no-worktree-check skips the check and warns (trees_check_skipped). A failed, late or hostile answer keeps the VM (trees_check_failed), and so does a VM that doesn't start for it (trees_check_not_started). Rm and rmGone run it, and rmGone refuses a stopped VM with opencode, which starting would make its folder again (rm_gone_stopped_trees, naming --no-export --no-worktree-check); stillGone takes the refusal to give. remaking.checkWork runs it before a remake with --clean-home (remakeTo, Update, SetClone, whose clone check it joins), its messages naming the command as typed (remakeInVM.typed), with --clean-home, which --no-worktree-check needs (needs), so devvm clone off --clean-home's clone check messages name it too. A remake's flag has its own help. The stub guest runs the read in vmhome-<vm>. Tests that fail without the check: TestRmAgentTrees, TestRmVMAgentTrees, TestRemakeAgentTrees, TestUpdateAgentTrees, TestSetCloneAgentTrees and the rm_agent_trees script; TestAgentTreesBounded (an endless answer cancelled, a silent VM given up on, in a synctest bubble); TestAgentTreesState runs the script under sh on real worktrees, a dot-named one included; TestParseAgentTrees holds the answer's checks, TestCloneGit the stub's. TestSetCloneOff names the command with --clean-home. e2e's network section makes a worktree in opencode's folder in the real VM, and devvm rm refuses, then --no-worktree-check deletes it. Docs: coding agents' opencode's worktrees, How it works' opencode's worktrees, deleting a VM, a VM whose folder is gone, images, clone, the overview's remake, Commands, extending and rm's help; the changelog's What to do step 4 names --no-worktree-check for scripts and devvm rm VM of a stopped VM, and opencode's block gets the check; the release page has its section. Co-Authored-By: Claude Opus 5.5 <[email protected]>
70 lines
2.8 KiB
Plaintext
70 lines
2.8 KiB
Plaintext
# devvm rm checks the worktrees opencode made in the VM first, as an
|
|
# export leaves them out: one with uncommitted changes is shown under its
|
|
# path and asked about, which --force never answers, so without a
|
|
# terminal rm refuses, naming --no-worktree-check, and in one no keeps
|
|
# the VM. --no-worktree-check warns and deletes it unchecked. A remake
|
|
# with --clean-home checks them too, after its own question, and
|
|
# --no-worktree-check goes only with --clean-home. (The stubs keep the
|
|
# VM's home folder in $STUB_DIR/vmhome-<vm>.)
|
|
env GIT_AUTHOR_NAME=t GIT_AUTHOR_EMAIL=t@t GIT_COMMITTER_NAME=t GIT_COMMITTER_EMAIL=t@t
|
|
project web
|
|
exec git init -q -b main
|
|
exec git commit -q --allow-empty -m one
|
|
exec devvm --network open --no-git-protect --agents opencode
|
|
vm_name WEB web
|
|
|
|
# An uncommitted change in a worktree: shown, and without a terminal rm
|
|
# keeps the VM. A folder that isn't a worktree is passed over.
|
|
exec sh -c 'r="$STUB_DIR/vmhome-$WEB/.local/share/opencode/worktree/abc123"; git worktree add -q -b brave "$r/brave" && mkdir -p "$r/plain" && echo x > "$r/brave/new"'
|
|
! exec devvm rm --force --no-export
|
|
stdout '^agent_tree_dirty agent=opencode path=~/\.local/share/opencode/worktree/abc123/brave$'
|
|
stdout '^\?\? new$'
|
|
stderr '^devvm: no_terminal_delete_trees command=devvm rm$'
|
|
exists $WEB_dir/vm.json
|
|
|
|
# In a terminal: yes to rm, then no keeps it.
|
|
ttyin -stdin $WORK/yes-no.txt
|
|
exec devvm rm --no-export
|
|
stderr 'delete_anyway \[y/N\] '
|
|
stdout '^==> kept vm=devvm-web-[0-9a-f]{14}$'
|
|
exists $WEB_dir/vm.json
|
|
|
|
# A remake with --clean-home checks them too; one that keeps the home
|
|
# folder doesn't. --no-worktree-check goes only with --clean-home.
|
|
! exec devvm layer add docker --force --no-export --no-worktree-check
|
|
stderr '^devvm: flag_needs_flag flag=--no-worktree-check needs=--clean-home$'
|
|
! exec devvm layer add docker --force --no-export --clean-home
|
|
stdout '^agent_tree_dirty agent=opencode path=~/\.local/share/opencode/worktree/abc123/brave$'
|
|
stderr '^devvm: no_terminal_delete_trees command=devvm layer add docker --clean-home\n'
|
|
vm_state $WEB_dir/vm.json
|
|
stdout '^image=base$'
|
|
|
|
# --no-worktree-check: warned, and deleted with the change.
|
|
exec devvm rm --force --no-export --no-worktree-check
|
|
stderr '^devvm: trees_check_skipped command=devvm rm vm=devvm-web-[0-9a-f]{14}$'
|
|
! stdout agent_tree
|
|
stdout '^==> deleted vm=devvm-web-[0-9a-f]{14}$'
|
|
! exists $WEB_dir
|
|
|
|
# Clean worktrees: deleted without the question.
|
|
project api
|
|
exec git init -q -b main
|
|
exec git commit -q --allow-empty -m one
|
|
exec devvm --network open --no-git-protect --agents opencode
|
|
vm_name API api
|
|
exec sh -c 'git worktree add -q -b calm "$STUB_DIR/vmhome-$API/.local/share/opencode/worktree/def456/calm"'
|
|
exec devvm rm --force --no-export
|
|
! stdout agent_tree
|
|
! stderr 'trees|delete_anyway'
|
|
stdout '^==> deleted vm=devvm-api-[0-9a-f]{14}$'
|
|
stub_calls
|
|
stdout 'cd ~ \|\| exit 1'
|
|
|
|
-- yes.txt --
|
|
y
|
|
-- no.txt --
|
|
n
|
|
-- yes-no.txt --
|
|
y
|
|
n
|