Files
devvm/testdata/script/ssh_code.txtar
T
w3cjandClaude Opus 5.5 06780fee5d feat(ssh): devvm ssh and devvm code, VS Code's Machine settings kept
devvm ssh gets this folder's VM ready for ssh and editors, as a launch
does without its shell, then names the host they reach it by; devvm code
does the same, then opens the folder in VS Code over Remote-SSH.

- vm: launch (from open: .git and set-id checks, a stopped VM's size,
  ports and agent forwarding, the user's agent checked, run with its
  self-check) and setUpVM (from setUp: sync, ssh config, a --clone VM's
  clone) shared by launches, SSH and Code; reach requires the backend's
  ssh, then offers the Include line (EnsureInclude). Code runs code
  --remote ssh-remote+HOST DIR in devvm's place with the environment
  devvm started with (Env.Environ), so the editor keeps the user's
  SSH_AUTH_SOCK.
- sshconfig: Host (the alias among every backend's project VMs), with
  the listing shared with Write.
- cli: ssh and code commands; CLI reference regenerated.
- Messages: ssh_host_info, no_code_command (linked to ssh.md),
  ssh_failed, code_failed.
- Tests: ssh_code.txtar (no VM, usage, a stopped VM started and set up
  without a shell, the Include line shown not added, a pending size
  waiting, code's arguments and agent, two folders named alike, no code
  on PATH, a direct route stopping the VM); guest.txtar's VS Code
  Machine settings case; a stub code. e2e: devvm ssh on a stopped VM and
  ssh reaching it, the Machine settings set and set again, devvm code
  with a stub code; network: devvm ssh's self-check, passing and
  stopping a VM started outside devvm.
- Docs: ssh.md (devvm ssh and devvm code, VS Code), commands.md,
  security.md, clone.md.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-24 22:33:29 -06:00

99 lines
3.6 KiB
Plaintext

# devvm ssh and devvm code: the folder's VM launched as devvm does without
# its shell (checked, started, self-checked, set up, in devvm's ssh
# config), then its host name shown, or its folder opened in VS Code (a
# stub code) with the SSH agent devvm started with. The Include line is
# offered for the sandbox's own ~/.ssh/config only.
env DEVVM_MESSAGES=names
env VMS=$XDG_DATA_HOME/devvm/vms
env CFG=$XDG_CONFIG_HOME/devvm
# No VM.
mkdir $WORK/web
cd $WORK/web
! exec devvm ssh
stderr '^devvm: no_vm dir=\S*/web$'
! exec devvm code
stderr '^devvm: no_vm dir=\S*/web$'
! exec devvm ssh now
stderr '^devvm: usage_error '
! exec devvm code .
stderr '^devvm: usage_error '
# A stopped VM: started and set up, no shell. Without a terminal, the
# Include line is shown, not added.
exec devvm --no-network-policy --no-git-protect base
exec sh -c 'limactl stop "$(basename "$VMS"/devvm-web-*)"'
exec sh -c ': > "$STUB_LOG"'
exec devvm ssh
stdout '^==> starting vm=devvm-web-[0-9a-f]{14}$'
stdout '^ssh_include_needed line=Include /\S*/config/devvm/ssh_config$'
stderr '^devvm: ssh_include_yourself$'
stdout '^ssh_host_info dir=/\S*/web host=devvm-web$'
stub_calls
stdout '^limactl start --tty=false devvm-web-[0-9a-f]{14}$'
stdout 'tar -xf'
! stdout 'limactl shell --workdir /\S*/web devvm-web'
exec sh -c 'cat "$CFG/ssh_config"'
stdout '^Host devvm-web devvm-web-[0-9a-f]{14}$'
! exists $HOME/.ssh
# With the line there: nothing asked. A size its state asks for waits for
# the running VM's next start, as on a launch.
exec sh -c 'mkdir -p "$HOME/.ssh" && echo "Include $CFG/ssh_config" > "$HOME/.ssh/config"'
exec sh -c 'f=$(ls "$VMS"/devvm-web-*); echo cpus=6 >> "$f"'
exec sh -c ': > "$STUB_LOG"'
exec devvm ssh
! stdout 'starting|ssh_include'
stderr '^devvm: size_next_start vm=devvm-web-[0-9a-f]{14}$'
stdout '^ssh_host_info dir=/\S*/web host=devvm-web$'
stub_calls
! stdout 'limactl (start|edit)'
# devvm code: the folder in VS Code over Remote-SSH, with the SSH agent
# devvm started with, though this VM's own connections carry none.
env SSH_AUTH_SOCK=$WORK/user-agent.sock
exec sh -c ': > "$STUB_LOG"'
exec devvm code
stub_calls
stdout '^code --remote ssh-remote\+devvm-web /\S*/web$'
exec sh -c 'cat "$STUB_DIR/code-agent"'
stdout '^\S*/user-agent\.sock$'
env SSH_AUTH_SOCK=
# Two folders named web: the VM by its full name.
mkdir $WORK/other/web
cd $WORK/other/web
exec devvm --no-network-policy --no-git-protect base
exec sh -c ': > "$STUB_LOG"'
exec devvm code
stub_calls
stdout '^code --remote ssh-remote\+devvm-web-[0-9a-f]{14} /\S*/other/web$'
# No code command on PATH: said, with the host to connect to.
exec sh -c 'mkdir "$WORK/nocode" && for f in "$(dirname "$DEVVM_HOST_MISE")"/*; do [ "${f##*/}" = code ] || ln -s "$f" "$WORK/nocode/"; done'
env SAVED_PATH=$PATH
env PATH=$DEVVM_BIN:$WORK/nocode:/usr/bin:/bin:/usr/sbin:/sbin
exec sh -c ': > "$STUB_LOG"'
! exec devvm code
stderr '^devvm: no_code_command host=devvm-web-[0-9a-f]{14}$'
stub_calls
! stdout '^code '
env PATH=$SAVED_PATH
# Network policy: a VM devvm started confined that still reaches the
# internet directly is stopped, as on a launch; no host name. (Its
# hostagent here: the test's runner, which runs on, in place of the
# stub's.)
mkdir $WORK/leak
cd $WORK/leak
exec devvm --network-policy --no-git-protect base
exec sh -c 'n=$(basename "$VMS"/devvm-leak-*); echo $PPID > "$LIMA_HOME/$n/ha.pid"; echo "$PPID 1" > "$XDG_DATA_HOME/devvm/run/$n.started"'
exec sh -c ': > "$STUB_LOG" && : > "$STUB_DIR/net-direct"'
! exec devvm ssh
stderr '^devvm: net_direct_route vm=devvm-leak-[0-9a-f]{14}$'
! stdout ssh_host_info
stub_calls
stdout '^limactl stop devvm-leak-[0-9a-f]{14}$'
! stdout 'tar -xf'
rm $STUB_DIR/net-direct