Files
devvm/testdata/script/ssh.txtar
T
w3cjandClaude Opus 5.5 39c2ff4f4e test: one Go multi-call stub for every host command
The 18 shell stubs in testdata/stubs (about 600 lines, limactl 337 of
them) are one Go binary, internal/stubtest/stub, which acts as the command
it's run as (argv[0]): limactl, docker, security, ssh, ssh-add, ssh-agent,
ssh-keygen, qemu-img, qemu-system-aarch64, qemu-system-x86_64, chflags,
tmutil, sw_vers, uname, open, code and mise, and stub, scripts' commands
on the stubs' state. stub-log is gone: each stub logs its call itself, in
one write to $STUB_LOG, its arguments on no other process's command line.

- internal/stubtest builds the binary once, into
  $TMPDIR/devvm-stubs-<hash> (its sources and Go's version) with a link
  per command, which every test process and later run reuses until the
  sources change; a day-old folder of another build is removed.
  stubtest.Bin, stubtest.Command (DEVVM_HOST_MISE's path), and Stubs'
  VM, Size, VMs, Keychain and SetKeychain on the state.
- internal/stubtest/stubstate: the stubs' state, $STUB_DIR/state.json,
  typed JSON under a file lock (Lima's instances with their status, size
  and config, the Keychain, the SSH agent and its keys, Time Machine's
  exclusions, the tools build VM's folder). The instances file wasn't
  locked; TestCreatesAtOnce and TestUpdatesAtOnce make 20 and 50 changes
  at once.
- guest.go is the VM behind limactl shell and ssh alike: a --clone VM's
  git on vmfs, a remake's home, a base build's packages, the setup's tar,
  the direct connection, host keys, a forwarder's ports, link forwards.
- A link session's master listens with a backlog of one and never
  accepts, as the Perl one did, so a killed session's socket reads as
  stale once probed (link_life). TestScript's cleanup stops the sandbox's
  masters by their -M -S arguments.
- Structure: the stubtest layers cover internal/stubtest/..., the binary
  and its state import nothing else of devvm's; execSites lists
  internal/stubtest/build.go and internal/stubtest/stub/process.go.

Renamed switch: hostkeys-fail is hostkeys-fails. Moved into the state:
instances, size-<vm>, config-<vm>, keychain/<account>, agent-up,
agent-held, tm-excluded and tools-out; scripts use stub vm, vms, size,
keychain, keychain-set, agent and agent-stop instead (build, existing,
from, gc, gc_orphans, images, ls, net_interrupted, rebuild, rm_vm,
secret, size, space, ssh, ssh_agent, up).

Tests: stub_test.go (every stub in-process, TestShellWords),
stubstate_test.go, TestBuild, TestCreatesAtOnce, TestState; the lima,
platform, vm, tools and build tests use the state helpers and
stubtest.Command. Coverage: internal/stubtest/stub and stubstate added,
stubtest, build and tools raised (and lima, netpolicy on Linux).
Docs: contributing (Stubs: the binary, logging, the state and the stub
command, switches, the guest, adding a stub or a switch; Go test
helpers; the layers), testing.md; AGENTS.md's stubtest and testdata rows.

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

95 lines
3.6 KiB
Plaintext

# devvm's ssh config: every running project VM by name (devvm-<folder>,
# and its full name), checked against its own host keys, read from the VM
# once for each start into its own record; Lima's own settings that turn
# host key checks off, share a connection or run commands left out. The
# user's ~/.ssh is never touched.
project web
exec devvm --no-network-policy --no-git-protect
vm_name WEB web
catg $DATA/ssh_config
stdout '\A# Written by devvm on every launch; edits are overwritten\.\n\nHost devvm-web devvm-web-[0-9a-f]{14}\n'
stdout '^ HostKeyAlias devvm-web-[0-9a-f]{14}$'
stdout '^ UserKnownHostsFile "/\S*/data/devvm/vms/[0-9a-f]{14}/run/known_hosts"$'
stdout '^ StrictHostKeyChecking yes$'
stdout '^ NoHostAuthenticationForLocalhost no$'
stdout '^ ForwardAgent no$'
stdout '^ ControlMaster no$'
stdout '^ ControlPath none$'
stdout '^ ForwardX11 no$'
stdout '^ ForwardX11Trusted no$'
stdout '^ Tunnel no$'
stdout '^ PermitRemoteOpen none$'
stdout '^ AddKeysToAgent no$'
stdout '^ ProxyJump none$'
stdout '^ ProxyCommand none$'
stdout '^ UpdateHostKeys no$'
stdout '^ HashKnownHosts no$'
stdout '^ Hostname 127\.0\.0\.1$'
stdout '^ Port 60022$'
stdout '^ User stub$'
stdout '^ IdentityFile "/\S*/lima/_config/user"$'
stdout '^ IdentitiesOnly yes$'
! stdout 'StrictHostKeyChecking no|/dev/null|NoHostAuthenticationForLocalhost yes'
! stdout 'ControlMaster auto|ssh\.sock|ControlPersist|LocalCommand'
catg $WEB_dir/run/known_hosts
stdout '\A# devvm: host keys of start [0-9]+ \S+\ndevvm-web-[0-9a-f]{14} ssh-ed25519 \S+\n\z'
exec grep -c ' ssh-ed25519 ' $WEB_dir/run/known_hosts
stdout '^1$'
exec sh -c 'ls -l "$DATA/ssh_config" "$WEB_dir/run/known_hosts"'
! stdout '^-.{3}[^-]'
! exists $DATA/known_hosts
! exists $HOME/.ssh
# A stopped VM drops out; its keys stay. A project folder named like an
# image (img-foo) is a project VM; images and build VMs aren't listed.
cp $WEB_dir/run/known_hosts $WORK/web-keys
exec stub vm $WEB Stopped
exec stub vm devvm-img-0123456789ab Running
exec stub vm devvm-tools-build Running
project img-foo
exec devvm --no-network-policy --no-git-protect
catg $DATA/ssh_config
stdout '^Host devvm-img-foo devvm-img-foo-[0-9a-f]{14}$'
! stdout 'devvm-web|devvm-img-0123456789ab|devvm-tools-build'
cmp $WEB_dir/run/known_hosts $WORK/web-keys
vm_name IMG img-foo
catg $IMG_dir/run/known_hosts
stdout '^devvm-img-foo-[0-9a-f]{14} ssh-ed25519 '
! cmp $IMG_dir/run/known_hosts $WEB_dir/run/known_hosts
# A second folder named web: its VM by its full name only, as the first
# VM keeps devvm-web, chosen when it was made.
exec stub vm $WEB Running
mkdir $WORK/other/web
cd $WORK/other/web
exec devvm --no-network-policy --no-git-protect
catg $DATA/ssh_config
stdout -count=1 '^Host devvm-web-[0-9a-f]{14}$'
stdout '^Host devvm-web '$WEB'$'
! stdout '^Host '$WEB'$'
# The record is read once for each start: a launch of the running VM
# keeps it, and keys recorded for another start are read again once it
# starts, not trusted.
exec sh -c 'sed "s/^\($IMG\) ssh-ed25519 .*/\1 ssh-ed25519 AAAAold/" "$IMG_dir/run/known_hosts" > "$WORK/kh" && cp "$WORK/kh" "$IMG_dir/run/known_hosts"'
cd $WORK/img-foo
exec devvm
catg $IMG_dir/run/known_hosts
stdout AAAAold
exec devvm restart
catg $IMG_dir/run/known_hosts
! stdout AAAAold
stdout '^devvm-img-foo-[0-9a-f]{14} ssh-ed25519 '
# A VM that doesn't show its host keys gets no entry: ssh couldn't check it.
exec sh -c ': > "$STUB_DIR/hostkeys-fails"'
project nokeys
exec devvm --no-network-policy --no-git-protect
vm_name NOKEYS nokeys
catg $DATA/ssh_config
! stdout devvm-nokeys
stdout '^Host devvm-img-foo '
! exists $NOKEYS_dir/run/known_hosts
rm $STUB_DIR/hostkeys-fails
! exists $HOME/.ssh