Files
devvm/testdata/script/history_import.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

151 lines
6.9 KiB
Plaintext

# history import: an export of agents' history into the folder's VM, the
# newest devvm saved for the folder or a file, streamed in as it is for
# the VM's tar, which leaves out the agents' logins and devvm's own copies
# and refuses paths outside the agents' history. A new VM with an agent
# offers the folder's newest export in a terminal, [y/N], and without one
# says how to import it later. (Each new VM here ends in a failed setup,
# after the import, so devvm's run ends and writes its coverage.)
env EXPORTS=$DATA/exports
project agent
! exec devvm history import
stderr '^devvm: no_vm dir=\S*/agent$'
# A VM with an agent, no export yet: nothing offered, nothing to import.
exec devvm --network open --no-git-protect --agents claude
! stderr 'history_import_(ask|later)'
vm_name AGENT agent
! exec devvm history import
stderr '^devvm: history_no_export dir=\S*/agent$'
# The newest export saved for this folder, streamed into the VM as it is,
# for its tar, which is told to check the paths and leave out the logins,
# ~/.claude.json and the files devvm's setup writes.
exec devvm history export
stub_reset
exec devvm history import
stdout '^==> imported 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}$'
exec sh -c 'cmp "$STUB_DIR/history-in.tgz" "$EXPORTS"/*.tar.gz'
stub_calls
# The import's script goes on the VM's input, before the export, never in its arguments.
stdout 'exec ''bash'' ''-c'' ''if IFS= read -r n '
! stdout 'quoting-style'
grep 'tar -tzf "\$t/export" --absolute-names --quoting-style=escape' $STUB_DIR/history-import.sh
grep 'devvm-history-unsafe' $STUB_DIR/history-import.sh
grep 'tar -xzf "\$t/export" -C "\$t/x" .*--no-same-owner.*--no-same-permissions.*--anchored' $STUB_DIR/history-import.sh
grep 'find "\$t/x" -type l' $STUB_DIR/history-import.sh
grep 'tar --extract --file=- --directory ~ --skip-old-files .*--no-same-owner.*--no-same-permissions' $STUB_DIR/history-import.sh
grep '--exclude=\.claude/\.credentials\.json' $STUB_DIR/history-import.sh
grep '--exclude=\.claude\.json' $STUB_DIR/history-import.sh
grep '--exclude=\.codex/auth\.json' $STUB_DIR/history-import.sh
grep '--exclude=\.local/share/opencode/auth\.json' $STUB_DIR/history-import.sh
grep '--exclude=\.claude/settings\.json' $STUB_DIR/history-import.sh
grep '--exclude=\.claude/skills' $STUB_DIR/history-import.sh
! grep 'tar (-xzf|--extract) .*(--absolute-names|-P\b)' $STUB_DIR/history-import.sh
# A file of your own, relative to here; one that isn't there fails before
# anything runs in the VM.
cp $WORK/mine.tar.gz mine.tar.gz
exec devvm history import mine.tar.gz
stdout '^==> imported file=\S*/agent/mine\.tar\.gz vm=devvm-agent-[0-9a-f]{14}$'
! stderr 'history_import_(less_strict|tier_unknown)'
cmp $STUB_DIR/history-in.tgz mine.tar.gz
stub_reset
! exec devvm history import nope.tar.gz
stderr '^devvm: import_failed reason=.*nope\.tar\.gz.*$'
stub_calls
! stdout 'IFS= read -r n '
# The VM's tar finds a path outside the agents' history: nothing imported.
# Its tar failing otherwise is a failed import.
exec sh -c ': > "$STUB_DIR/history-unsafe"'
! exec devvm history import mine.tar.gz
stderr '^devvm: history_import_unsafe file=\S*/agent/mine\.tar\.gz$'
rm $STUB_DIR/history-unsafe
exec sh -c 'echo quoting-style > "$STUB_DIR/shell-fails-on"'
! exec devvm history import mine.tar.gz
stderr '^devvm: history_not_imported file=\S*/agent/mine\.tar\.gz vm=devvm-agent-[0-9a-f]{14}$'
rm $STUB_DIR/shell-fails-on
# rm saves one more. A new VM without a terminal says how to import it.
exec devvm rm --force
stdout '^==> exported '
rm $STUB_DIR/history-in.tgz
exec sh -c 'echo "tar -xf - " > "$STUB_DIR/shell-fails-on"'
! exec devvm --network open --no-git-protect --agents claude
stderr '^history_import_later 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}$'
! exists $STUB_DIR/history-in.tgz
exec devvm rm --force --no-export
# In a terminal it asks: no imports nothing, yes imports the newest.
ttyin -stdin $WORK/no.txt
! exec devvm --network open --no-git-protect --agents claude
stderr '^history_import_ask 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} \[y/N\] '
! stdout imported
! exists $STUB_DIR/history-in.tgz
exec devvm rm --force --no-export
ttyin -stdin $WORK/yes.txt
! exec devvm --network open --no-git-protect --agents claude
stdout '^==> imported 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}$'
exists $STUB_DIR/history-in.tgz
exec devvm rm --force --no-export
rm $STUB_DIR/history-in.tgz
# A refused import still makes the VM, with a warning.
exec sh -c ': > "$STUB_DIR/history-unsafe"'
ttyin -stdin $WORK/yes.txt
! exec devvm --network open --no-git-protect --agents claude
stderr '\[y/N\] devvm: history_import_unsafe file=\S*/exports/devvm-agent-'
stderr '^devvm: sync_failed'
rm $STUB_DIR/history-unsafe
exec devvm rm --force --no-export
# An open VM's export into a new VM on a stricter tier warns, then
# imports, and so does a file of your own, whose tier devvm has no
# record of. (Its hostagent here: the test's runner, so devvm finds it
# running confined. More cases: TestImportWarnsOfTier.)
ttyin -stdin $WORK/yes.txt
! exec devvm --network allowlist --no-git-protect --agents claude
stderr '\[y/N\] devvm: history_import_less_strict file=\S*/exports/devvm-agent-[0-9a-f]{14}-[0-9]{8}-[0-9]{6}\.tar\.gz from=open tier=allowlist vm=devvm-agent-[0-9a-f]{14}$'
stdout '^==> imported '
exists $STUB_DIR/history-in.tgz
vm_name AGENT agent
exec sh -c 'echo $PPID > "$LIMA_HOME/$AGENT/ha.pid"; echo "$PPID 1" > "$AGENT_dir/run/started"'
exec devvm history import mine.tar.gz
stderr '^devvm: history_import_tier_unknown file=\S*/agent/mine\.tar\.gz tier=allowlist vm=devvm-agent-[0-9a-f]{14}$'
stdout '^==> imported '
exec devvm rm --force --no-export
rm $STUB_DIR/history-in.tgz
# A VM without an agent, and another folder's VM, are offered nothing.
! exec devvm --network open --no-git-protect --agents none
! stderr 'history_import_(ask|later)'
exec devvm rm --force --no-export
project other
! exec devvm --network open --no-git-protect --agents claude
! stderr 'history_import_(ask|later)'
rm $STUB_DIR/shell-fails-on
# An export that never ends: devvm stops it at its cap and keeps nothing
# of it, so devvm history export fails, and rm warns and goes on.
project flood
exec devvm --network open --no-git-protect --agents claude
vm_name FLOOD flood
exec sh -c ': > "$STUB_DIR/history-floods"'
env DEVVM_HISTORY_MAX=1048576
! exec devvm history export
stderr '^devvm: history_too_large vm=devvm-flood-[0-9a-f]{14}$'
exec devvm rm --force
stderr '^devvm: history_too_large vm=devvm-flood-[0-9a-f]{14}$'
! stdout exported
! exists $FLOOD_dir
! exec sh -c 'ls -a "$EXPORTS" | grep devvm-flood'
exec sh -c 'grep -l "^devvm: truncated: " "$DATA"/logs/runs/*.log'
rm $STUB_DIR/history-floods
-- mine.tar.gz --
not really a tarball: the VM's tar reads it
-- no.txt --
n
-- yes.txt --
y