Files
devvm/testdata/script/sync.txtar
T
w3cjandClaude Opus 5.5 e97db057fd fix(agents): Claude Code's plugins get a folder of each VM's own, the store's a read-only seed (#56)
A VM's ~/.claude/plugins was the agent store's plugins folder, mounted
read-only, so everything Claude Code writes there failed with EROFS: a
plugin's data (${CLAUDE_PLUGIN_DATA}), installs, marketplace refreshes,
mcpb/ and the rest. Making the store writable would let one VM change
what Claude Code runs in every other VM, so each VM's ~/.claude/plugins
is now its own folder on its disk (CLAUDE_CODE_PLUGIN_CACHE_DIR), and the
store's folder is linked at ~/.claude/plugins-seed and read as Claude
Code's own read-only seed (CLAUDE_CODE_PLUGIN_SEED_DIR). Checked on a
devvm VM first: a seed-cached plugin from a GitHub-style marketplace
loads with only enabledPlugins, its hook writes ${CLAUDE_PLUGIN_DATA} in
the VM's own folder, installs in the VM work, and seed marketplaces
refuse updates.

- agents: Def.Seeds (Rel, Link, Entries), Seeds, SeedOf, MachineOwn;
  Env gains Home; Claude's Env sets both variables below $HOME.
- vm: the setup links a seed at its Link and stages own-dirs, which
  sync.sh makes a folder in place of a link; agentEnv writes Home values
  through homeValue (shared with toolchainEnv); a remake keeps the VM's
  own folder and skips the seed's link.
- devvm agent import copies only a seed's entries (known_marketplaces.json,
  marketplaces, cache), directly and through followed links, so the
  host's plugins' data, mcpb, synced, .trash, store and
  installed_plugins.json never reach the store.
- devvm agent save: the VM's script excludes a seed folder's other
  entries by name, and readSent refuses any (listedPath); a seed folder
  adds and changes, never removes or prunes; claudeRecords renames the
  VM's plugins path to the store's and joins known_marketplaces.json by
  key, leaving records Claude Code registered from the seed as the
  store's, and the store's file as it is when nothing changed.
- History: an export leaves the VM's plugins folder out and an import
  skips it and the seed's link: it's settings and plugin data (which can
  hold a plugin's own logins), not history, and reaches other VMs only
  through devvm agent save's reviewed diff.
- Review fixes (security-audit): historyImport refuses a name with a
  ., .. or empty part (GNU tar's anchored excludes missed
  .claude/./plugins and .claude//plugins, which now reach a writable
  folder) and deletes importSkips by path after the link sweep; the save
  script never excludes a name with a wildcard's character (it's sent
  and refused); only a marketplace record whose exact installLocation is
  clean and in the store's marketplaces joins the store's.
- Tests: claude_test.go (TestClaudePluginsSeed, TestClaudePluginsHistory,
  TestAgentImportClaudePlugins, TestAgentSaveScriptClaudePlugins,
  TestReadSentClaudePlugins, TestAgentSaveClaudePlugins), TestSeeds,
  TestListedPath cases, the agent, agent_save and sync CLI tests, goldens,
  and e2e project checks of the seed, the VM's folder and a plugin's data.
- Docs: coding-agents (store table, Claude Code's plugins under Mounts,
  the save's plugin example), internals/agents, a design note with its
  threat check, extending.md, CHANGELOG Fixed and After you upgrade.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-18 11:37:40 -07:00

196 lines
10 KiB
Plaintext

# A VM's setup on every launch: the host's settings, its agents' settings
# and logins from devvm's store (never their history), their folders
# mounted read-only, and on every tier the VM's own CA and placeholders
# for its tokens and logins.
env TZ=Europe/Paris
env LANG=en_US.UTF-8
exec git config --global user.name 'Test User'
exec git config --global user.email [email protected]
# The agents' files in the home folder, and their history: a VM gets
# nothing of them before devvm agent import copies them into the store.
mkdir $HOME/.claude/skills $HOME/.claude/projects/p $HOME/.codex/prompts
cp $WORK/settings.json $HOME/.claude/settings.json
cp $WORK/claude.json $HOME/.claude.json
cp $WORK/codex.json $HOME/.codex/auth.json
cp $WORK/config.toml $HOME/.codex/config.toml
cp $WORK/history.jsonl $HOME/.claude/projects/p/history.jsonl
cp $WORK/history.jsonl $HOME/.codex/history.jsonl
project before
exec devvm --network open --no-git-protect --agents claude,codex
exec tar -tf $STUB_DIR/sync.tar
! stdout '^home/|^claude\.json$'
exec tar -xOf $STUB_DIR/sync.tar links
! stdout /home/
exec devvm agent import
! exists $CFG/agents/claude/.claude/projects
! exists $CFG/agents/codex/.codex/history.jsonl
# An open VM: the agents' folders in the store mounted read-only, and as
# on every tier, the VM's own CA, its tokens' and logins' placeholders,
# and the settings files with their keys taken out. It holds no real
# secret.
project plain
env CLAUDE_CODE_OAUTH_TOKEN=sk-ant-oat01-testfake
exec devvm --network open --no-git-protect --agents claude,codex
stderr '^config_redacted file=\S*/agents/claude/\.claude/settings\.json keys=env\.ANTHROPIC_API_KEY vm=devvm-plain-[0-9a-f]{14}$'
stderr '^devvm: config_not_copied file=\S*/agents/codex/\.codex/config\.toml vm=devvm-plain-[0-9a-f]{14}$'
stub_calls
stdout '^limactl clone --tty=false \S+ devvm-plain-[0-9a-f]{14} --mount-none --set \.mounts = \[\{"location":"\S*/plain","writable":true(,"9p":\{"cache":"none"\})?\},\{"location":"\S*/config/devvm/agents/claude/\.claude/skills","writable":false\},\{"location":"\S*/config/devvm/agents/codex/\.codex/prompts","writable":false\},\{"location":"\S*/data/devvm/tools","mountPoint":"/mnt/devvm-tools","writable":false\}\]'
exec tar -tf $STUB_DIR/sync.tar
stdout '^home/\.claude/settings\.json$'
stdout '^home/\.codex/auth\.json$'
! stdout '^home/\.codex/config\.toml$'
stdout '^claude\.json$'
stdout '^ca/devvm-proxy\.crt$'
stdout '^ca/devvm-proxy-next\.crt$'
! stdout 'history|projects'
vm_name PLAIN plain
exec tar -xOf $STUB_DIR/sync.tar ca/devvm-proxy.crt
cmp stdout $PLAIN_dir/run/ca/ca.pem
exec sh -c 'tar -xOf "$STUB_DIR/sync.tar" home/.claude/settings.json home/.codex/auth.json claude.json env'
! stdout testfake
stdout '"OPENAI_API_KEY": *"sk-devvm-proxy-managed'
exec sh -c 'salt=$(sed -n "s/.*\"proxy_salt\": \"\([^\"]*\)\".*/\1/p" "$PLAIN_dir/vm.json"); tar -xOf "$STUB_DIR/sync.tar" env | grep -Fx "export CLAUDE_CODE_OAUTH_TOKEN=''sk-ant-oat01-devvm-proxy-managed-$salt''"'
# ~/.claude.json's copy holds only settings, account state and MCP servers:
# never an API key or the projects' history.
exec tar -xOf $STUB_DIR/sync.tar claude.json
stdout '"theme": *"dark"'
stdout '"API_KEY": *"devvm-redacted"'
! stdout 'testfake|primaryApiKey|customApiKeyResponses|projects'
# Each folder to link: its path in the VM's home, then its mount's. Claude Code's plugins are its
# seed, linked beside the VM's own plugins folder, which Claude Code writes, and which a link
# from before is replaced by (own-dirs); its environment names both.
exec tar -xOf $STUB_DIR/sync.tar links
stdout '^\.claude/skills\n\S+/config/devvm/agents/claude/\.claude/skills\n\.claude/agents\n\S+/agents/claude/\.claude/agents\n\.claude/commands\n\S+/agents/claude/\.claude/commands\n\.claude/output-styles\n\S+/agents/claude/\.claude/output-styles\n\.claude/plugins-seed\n\S+/agents/claude/\.claude/plugins\n\.codex/prompts\n\S+/config/devvm/agents/codex/\.codex/prompts\n\.codex/skills\n\S+/agents/codex/\.codex/skills\n\z'
exec tar -xOf $STUB_DIR/sync.tar own-dirs
stdout '\A\.claude/plugins\n\z'
exec tar -xOf $STUB_DIR/sync.tar agent-env
stdout '^export CLAUDE_CODE_PLUGIN_CACHE_DIR="\$HOME"/''\.claude/plugins''$'
stdout '^export CLAUDE_CODE_PLUGIN_SEED_DIR="\$HOME"/''\.claude/plugins-seed''$'
exec tar -xOf $STUB_DIR/sync.tar vm
stdout '\A\QDEVVM_HOSTNAME=''plain''\E\n\QDEVVM_TZ=''Europe/Paris''\E\n\QDEVVM_LANG=''en_US.UTF-8''\E\n\QDEVVM_GIT_NAME=''Test User''\E\n\QDEVVM_GIT_EMAIL=''[email protected]''\E\n'
# An open VM's proxy too, as its environment has it, where its local proxy listens, and devvm
# paste's folder; no transparent mode, which is for confined VMs, and the system's own resolver.
stdout '^DEVVM_PROXY=''http://devvm:[0-9a-f]{64}@192\.168\.5\.2:[0-9]+''\n\QDEVVM_NO_PROXY=''localhost,127.0.0.1,::1''\E\n\QDEVVM_LOCAL_PROXY=''127.0.77.1:3128''\E\n\QDEVVM_TRANSPARENT_ADDR=''''\E\n\QDEVVM_TRANSPARENT_HOST=''transparent.devvm.proxy''\E\n\QDEVVM_RESOLVER=''''\E\n\QDEVVM_PASTE_DIR=''/tmp/devvm-paste''\E\n\z'
exec tar -tf $STUB_DIR/sync.tar
stdout '^transparent\.sh$'
# Without links, the hosts file for /etc/hosts is empty.
exec tar -xOf $STUB_DIR/sync.tar hosts
! stdout .
exec tar -xOf $STUB_DIR/sync.tar env
stdout '^export LANG=''en_US\.UTF-8''\nexport CLAUDE_CODE_OAUTH_TOKEN=''sk-ant-oat01-devvm-proxy-managed-[0-9a-f]+''\n\z'
# A Claude token that isn't a setup-token token isn't sent; no token at
# all is named too.
project badtoken
env CLAUDE_CODE_OAUTH_TOKEN=not-a-setup-token
exec devvm --network open --no-git-protect --agents claude
stderr '^devvm: claude_token_invalid$'
exec tar -xOf $STUB_DIR/sync.tar env
! stdout CLAUDE_CODE_OAUTH_TOKEN
project notoken
env CLAUDE_CODE_OAUTH_TOKEN=
exec devvm --network open --no-git-protect --agents claude
stderr '^devvm: no_claude_token vm=devvm-notoken-[0-9a-f]{14}$'
# An allowlist VM gets the same: the VM's own CA and its next, the VM's own placeholders, the logins'
# copies with placeholders (the host's files unchanged), and the
# settings files with their keys taken out; one devvm can't read that way
# isn't sent, and neither is an opencode file that isn't settings or
# Markdown, such as a .env.
mkdir $HOME/.config/opencode
cp $WORK/opencode-env $HOME/.config/opencode/.env
cp $WORK/opencode-agents $HOME/.config/opencode/AGENTS.md
exec devvm agent import opencode
project net
env CLAUDE_CODE_OAUTH_TOKEN=sk-ant-oat01-testfake
exec devvm --network allowlist --no-git-protect --agents claude,codex,opencode
stderr '^config_redacted file=\S*/agents/claude/\.claude/settings\.json keys=env\.ANTHROPIC_API_KEY vm=devvm-net-[0-9a-f]{14}$'
stderr '^devvm: config_not_copied file=\S*/agents/codex/\.codex/config\.toml vm=devvm-net-[0-9a-f]{14}$'
stderr '^devvm: config_not_copied file=\S*/agents/opencode/\.config/opencode/\.env vm=devvm-net-[0-9a-f]{14}$'
exec tar -tf $STUB_DIR/sync.tar
! stdout '^home/\.codex/config\.toml$'
! stdout '^home/\.config/opencode/\.env$'
stdout '^home/\.config/opencode/AGENTS\.md$'
vm_name NET net
exec tar -xOf $STUB_DIR/sync.tar ca/devvm-proxy.crt
cmp stdout $NET_dir/run/ca/ca.pem
exec tar -xOf $STUB_DIR/sync.tar ca/devvm-proxy-next.crt
cmp stdout $NET_dir/run/ca/next.pem
exec tar -xOf $STUB_DIR/sync.tar
! stdout 'PRIVATE KEY'
exec sh -c 'tar -xOf "$STUB_DIR/sync.tar" home/.claude/settings.json home/.codex/auth.json claude.json env'
! stdout testfake
stdout devvm-redacted
stdout '"OPENAI_API_KEY": *"sk-devvm-proxy-managed'
! stdout projects
exec sh -c 'salt=$(sed -n "s/.*\"proxy_salt\": \"\([^\"]*\)\".*/\1/p" "$NET_dir/vm.json"); tar -xOf "$STUB_DIR/sync.tar" env | grep -Fx "export CLAUDE_CODE_OAUTH_TOKEN=''sk-ant-oat01-devvm-proxy-managed-$salt''"'
exec sh -c 'key=$(sed -n "s/.*\"proxy_key\": \"\([^\"]*\)\".*/\1/p" "$NET_dir/vm.json"); tar -xOf "$STUB_DIR/sync.tar" vm | grep -E "^DEVVM_PROXY=''http://devvm:$key@[0-9.]+:[0-9]+''$"'
cmp $HOME/.codex/auth.json $WORK/codex.json
cmp $DATA/logins/codex/.codex/auth.json $WORK/codex.json
cmp $HOME/.claude.json $WORK/claude.json
# A .claude.json in the store devvm can't read stops the setup.
cp $DATA/logins/claude/.claude.json $WORK/store-claude.json
cp $WORK/bad.json $DATA/logins/claude/.claude.json
project badclaude
! exec devvm --network open --no-git-protect --agents claude
stderr '^devvm: login_copy_failed agent=claude reason=.* vm=devvm-badclaude-[0-9a-f]{14}$'
cp $WORK/store-claude.json $DATA/logins/claude/.claude.json
# A setup that fails says so, and leaves nothing of what it was sent.
mkdir $WORK/tmp $WORK/fails
cd $WORK/fails
env TMPDIR=$WORK/tmp
exec sh -c ': > "$STUB_DIR/shell-fails"'
! exec devvm --network open --no-git-protect --agents claude
stderr '^devvm: sync_failed vm=devvm-fails-[0-9a-f]{14}$'
exec sh -c 'ls -A "$TMPDIR"'
! stdout .
rm $STUB_DIR/shell-fails
# A shared tool the VM couldn't mount stops the launch, named by the VM's
# own tool list: a line naming any other file doesn't count, and with
# none left it's the setup that failed.
vm_name FAILS fails
exec bash $WORK/unmounted.sh '' ../../etc/passwd
! exec devvm --network open --no-git-protect
stderr '^devvm: tools_unmounted tools=claude [0-9][0-9.]* vm=devvm-fails-[0-9a-f]{14}$'
exec bash $WORK/unmounted.sh claude-9.9.9-000000000000.erofs
! exec devvm --network open --no-git-protect
stderr '^devvm: sync_failed vm=devvm-fails-[0-9a-f]{14}$'
rm $STUB_DIR/sync-fails-with
exec devvm --network open --no-git-protect
! stderr 'tools_unmounted|sync_failed'
-- unmounted.sh --
# The report tools.sh writes when it fails, listing each file named ('' for
# the VM's first tool image) after lines of its own, and with a last line
# cut short.
first=$(sed -n '/"files": \[/{n;s/.*"\([^"]*\)".*/\1/p;}' "$FAILS_dir/vm.json")
{
echo "devvm-tools: can't mount something"
printf '%s\n' "${first%% *} and more"
for f in "$@"; do echo "${f:-${first%% *}}"; done
printf '%s' "${first%% *}"
} > "$STUB_DIR/sync-fails-with"
-- settings.json --
{"env":{"ANTHROPIC_API_KEY":"testfake-settings"},"theme":"dark"}
-- claude.json --
{"theme":"dark","primaryApiKey":"testfake-apikey","customApiKeyResponses":{"approved":["testfake-apikey"]},"mcpServers":{"srv":{"command":"x","env":{"API_KEY":"testfake-mcp"}}},"projects":{"/p":{"history":["testfake-history"]}}}
-- codex.json --
{"OPENAI_API_KEY":"sk-testfake-codex","last_refresh":null}
-- config.toml --
note = """
testfake-unclosed
-- bad.json --
{"theme":
-- opencode-env --
MY_SERVICE=testfake-dotenv
-- opencode-agents --
Be brief.
-- history.jsonl --
{"prompt":"testfake-history"}