Files
devvm/testdata/script/sync.txtar
T
2f0cc97392 feat(paste): devvm paste and devvm paste rm (#38)
feat(paste): devvm paste, an image, PDF or copied file from the clipboard into the VM (#38)

devvm paste reads the host's clipboard and streams what's on it into the
running VM's paste folder over the backend's Exec, with no SSH agent and no
new channel, then copies the file's path in the VM to the host clipboard for
the agent's prompt. devvm paste rm empties the folder after a question, and
a launch that starts a stopped VM offers to.

What it reads:
- an image (PNG, JPEG, GIF, WebP; TIFF is converted to PNG), checked by its
  bytes; browsers hand over a PNG, so an animated GIF arrives as one frame
- PDF data, sent as it is, and preferred over a file reference beside it
  (Preview's page copies)
- one copied file, after a question that shows its path on this machine;
  --send-file answers it only for a file inside the project folder reached
  without links, and never for a --clone VM
- never text; several files are refused

Security:
- macOS reads file URLs only through NSPasteboard (FileURLsOnly): AppleScript's
  «class furl» coercion turned any text, such as a path a web page or the
  VM's OSC 52 put there, into a file to send
- copied files are opened with openat and O_NOFOLLOW|O_NOCTTY|O_NONBLOCK,
  following a root-owned link only in a folder only root can change, and read
  through internal/safefile (Checked), capped at 64 MiB
- osascript and pbcopy by absolute path, Linux's tools only from system
  folders, never PATH
- time limits on every clipboard tool and on paste.sh in the VM; bounded
  reads of everything the VM prints
- the path copied back is built on the host, keeping only the file's
  extension: nothing the VM says reaches the clipboard

Also: the paste-dir setting (default /tmp/devvm-paste, made at each
launch), --json with sent, the agents' guide line, messages with doc links,
stubs, CLI tests, an e2e check in the project section, and docs on
coding-agents, settings, design, security and attack-vectors.

Co-authored-by: dustypolk <[email protected]>
Co-authored-by: w3cj <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-11 22:29:46 -07:00

189 lines
9.7 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.
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\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 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.
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_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"}