Files
devvm/testdata/script/existing_agents.txtar
w3cjandClaude Opus 5.5 376f1c2ad7 fix(agents): opencode's save, plugin approvals and the history scripts' framing
devvm agent save refused a VM whose ~/.config/opencode held a bun.lock (which opencode's plugins' installs write), a package-lock.json, a .gitignore or a .DS_Store: the save's script sent every entry of that folder but node_modules and FolderOwn, while the host's listedPath refuses those files (fileSetting), so it saved nothing. notSettings is now their one list, as patterns path.Match and the shell's case read alike: fileSetting leaves them out and the script sends a file of those names no more, only a folder that isn't a link, which is a setting. TestAgentSaveScriptRuns plants them and a folder named old.lock, and failed with agent_save_unsafe before the fix.

opencode's HistoryOwn names its native client's plugin approvals, in its state folder (cli-rs's plugin/src/loader/approval.rs and tui/src/plugins/host.rs, opencode v2.4.1): plugin-approvals.json, its .lock and the .plugin-approvals.json.<pid>.<n>.tmp it's written through, and plugin-staged, the approved trees' copies, which it reuses by their hash's name without hashing them again, so a hostile VM's export could approve a project plugin for the VM that imports it. That client doesn't ship in 2.4.1. TestHistoryExportRuns and TestHistoryImportRuns plant them, with plugin-notes.json as the control, and failed on fedora without the entries.

The history scripts' framing (onInputCmd) now says why on its stderr, which goes to the VM's log, when its input was cut short: TestOnInputCutShort checks it for every cut, an empty input included, and none for a whole one, and failed before. TestHistoryScriptsOnInput holds each script under 128 KiB, Linux's limit on one argument, which bash -c "$s" passes it as. The CLI scripts match the framing's new start.

Docs: the save's and the store's table say which files stay in the VM; the import's and How it works' lists name the plugin approvals; the release page gets opencode's lock files in a save and the approvals; the changelog's opencode block gets the save's fix, and the hardening line names approved plugins. The review's optional wording: the design note's `*` matches every resource, and the plain-password steps set this machine's password first.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-25 00:03:05 -07:00

155 lines
6.3 KiB
Plaintext

# Existing VMs with network policy, shared tools and agents: a running
# VM keeps its proxy, the self-check runs on every launch, tools shows
# its tools and tools add, rm and update change them, and rm exports its
# agents' history first.
# Network policy: a running VM isn't started again, and the self-check
# runs again. (Its hostagent here: the test's runner, which runs on, in
# place of the stub's.)
project net
exec devvm --network allowlist --no-git-protect
vm_name NET net
exec sh -c 'echo $PPID > "$LIMA_HOME/$NET/ha.pid"; echo "$PPID 1" > "$NET_dir/run/started"'
stub_reset
exec devvm
! stdout starting
stub_calls
! stdout 'limactl (start|stop|edit)'
stdout 'exec ''curl'' ''--noproxy'''
# Started outside devvm: unenforced, so without a terminal to ask in,
# devvm stops it. devvm starts it again confined. (The exit keeps
# limactl start sh's child, so its hostagent is sh, soon gone: bash 5.2
# and newer as sh, Fedora's, runs a last command in sh's place, which would
# make the runner, which lasts, its hostagent.)
exec sh -c 'limactl stop "$NET" && limactl start --tty=false "$NET"; exit $?'
stub_reset
! exec devvm
stderr '^devvm: net_unenforced_stop vm=devvm-net-[0-9a-f]{14}$'
stub_calls
stdout '^limactl stop devvm-net-[0-9a-f]{14}$'
! stdout 'tar -xf'
vm_state $NET_dir/vm.json
stdout '^net.made.check=unenforced$'
exec devvm
stdout '^==> starting what=devvm-net-[0-9a-f]{14}$'
vm_state $NET_dir/vm.json
stdout '^net.made.check=ok$'
# tools update: with the lock as it is, the tools are the newest; with a
# newer go upstream, it's built and the VM moves to it. tools shows the
# VM's version and the lock's newer one, built or not, without going
# online.
project api
exec devvm --network open --no-git-protect --tools go
vm_name API api
! exec devvm tools now
stderr '^devvm: no_subcommand command=devvm tools commands=add, rm, update given=now$'
exec devvm tools
stdout '^TOOL +VERSION +NEWER +BUILT\ngo +\S+ +- +-\n\z'
exec devvm tools --json
stdout '\A{\n "version": 1,\n "tools": \[\n {\n "tool": "go",\n "version": "\S+"\n }\n \]\n}\n\z'
exec devvm tools update
stdout '^==> checking_tools$'
stdout '^==> tools_newest vm=devvm-api-[0-9a-f]{14}$'
exec sh -c 'sed "/^\[\[tools.go\]\]/,/^version/ s/^version = .*/version = \"9.9.9\"/" "$MISE_STUB_LOCK" > "$WORK/newer.lock"'
exec sh -c 'cp "$WORK/newer.lock" "$DATA/mise.lock"'
stub_reset
exec devvm tools
stdout '^go +\S+ +9\.9\.9 +no$'
stub_calls
! stdout mise
env MISE_STUB_LOCK=$WORK/newer.lock
exec devvm tools update
stdout '^==> building_tools tools=go 9\.9\.9$'
stdout '^==> tools_switch vm=devvm-api-[0-9a-f]{14}$'
vm_state $API_dir/vm.json
stdout '^tools.made.files=go-9\.9\.9-[0-9a-f]{12}\.erofs$'
exec tar -xOf $STUB_DIR/sync.tar tools
stdout '^go-9\.9\.9-[0-9a-f]{12}\.erofs go 9\.9\.9$'
# A VM whose tools are older than the lock's is told on launch.
json_set $API_dir/vm.json tools.made.files:=["go-1.0.0-0123456789ab.erofs"]
exec devvm
stderr '^devvm: newer_tools tools=go 9\.9\.9$'
exec devvm tools
stdout '^go +1\.0\.0 +9\.9\.9 +yes$'
exec devvm tools --json
stdout '\A{\n "version": 1,\n "tools": \[\n {\n "tool": "go",\n "version": "1\.0\.0",\n "newer": "9\.9\.9",\n "newer_built": true\n }\n \]\n}\n\z'
# tools rm: the tools leave its list and their files, the rest stays;
# what it lacks is refused. Names are separate words.
project web
cp $WORK/package.json package.json
exec devvm --network open --no-git-protect --agents claude
stdout '^new_vm_toolchain_for file=package\.json tool=node\nnew_vm_agent_from agent=claude from=--agents\nnew_vm_layers_none\n'
vm_name WEB web
! exec devvm tools rm node,claude
stderr '^devvm: tools_joined cmd=rm given=node,claude$'
exec devvm tools rm claude
stdout '^==> vm_tools_now tools=node vm=devvm-web-[0-9a-f]{14}$'
vm_state $WEB_dir/vm.json
stdout '^image=base$'
stdout '^tools.names=node$'
stdout '^tools.made.files=node-\S+ pnpm-\S+ bun-\S+$'
exec tar -xOf $STUB_DIR/sync.tar tools
! stdout claude
! exec devvm tools rm python
stderr '^devvm: vm_lacks has=node tool=python vm=devvm-web-[0-9a-f]{14}$'
! exec devvm tools rm
stderr '^devvm: arg_missing args=TOOL\.\.\. command=devvm tools rm$'
# The flags add nothing to a VM that exists: it opens with a warning
# naming devvm tools, and nothing changes.
exec devvm --tools python --agents claude
stderr '^devvm: new_vm_flags_ignored_run command=devvm tools flags=--tools, --agents vm=devvm-web-[0-9a-f]{14}$'
vm_state $WEB_dir/vm.json
stdout '^tools.names=node$'
# tools add: the tools it lacks join its list, those it has are said;
# only shared tools, each a separate word.
! exec devvm tools add
stderr '^devvm: arg_missing args=TOOL\.\.\. command=devvm tools add$'
! exec devvm tools add python+claude
stderr '^devvm: tools_joined cmd=add given=python\+claude$'
! exec devvm tools add docker
stderr '^devvm: unknown_tool tool=docker tools='$TOOLCHAINS' '$AGENTS'$'
exec devvm tools add node claude
stdout '^==> has_tools tools=node vm=devvm-web-[0-9a-f]{14}$'
stdout '^==> vm_tools_now tools=node claude vm=devvm-web-[0-9a-f]{14}$'
vm_state $WEB_dir/vm.json
stdout '^image=base$'
stdout '^tools.names=node claude$'
stdout '^tools.made.files=node-\S+ pnpm-\S+ bun-\S+ claude-\S+$'
exec tar -xOf $STUB_DIR/sync.tar tools
stdout claude
# rm: a VM with an agent has its history exported first, from the VM,
# started if it's stopped; a failed export keeps the VM, and -f deletes
# it without one.
project agent
exec devvm --network open --no-git-protect --agents claude
vm_name AGENT agent
exec limactl stop $AGENT
exec sh -c ': > "$STUB_DIR/shell-fails"'
! exec devvm rm --force
stdout '^==> starting what=devvm-agent-[0-9a-f]{14}$'
stderr '^devvm: export_failed_kept command=devvm rm vm=devvm-agent-[0-9a-f]{14}$'
exists $AGENT_dir/vm.json
exec sh -c 'ls "$DATA/exports" | wc -l'
stdout '^ *0$'
rm $STUB_DIR/shell-fails
stub_reset
exec devvm rm --force
stdout '^==> exported file=\S*/data/devvm/exports/devvm-agent-[0-9a-f]{14}-[0-9]{8}-[0-9]{6}\.tar\.gz vm=devvm-agent-[0-9a-f]{14}$'
stdout '^==> deleted vm=devvm-agent-[0-9a-f]{14}$'
stub_calls
stdout 'exec ''bash'' ''-c'' ''if IFS= read -r n '
grep '^devvm_opencode_clean\(\) \{$' $STUB_DIR/history-export.sh
grep '^cd ~ && ls -d \.claude \.claude\.json .*--exclude=\.claude/\.credentials\.json.* -T - ' $STUB_DIR/history-export.sh
! exists $AGENT_dir
cd $WORK/net
exec devvm rm --force --no-export
! stdout exported
-- package.json --
{}