76 KiB
Tests
Go test helpers
Every change to devvm's logic comes with a test, and Go tests are table tests next to the code they test. Neither the Go tests nor the CLI tests touch the Keychain, real VMs or your own folders. A Go test that writes state points the XDG folders at t.TempDir(), and a Go test makes VMs only on the fake backend, backendtest. The CLI tests run the built devvm against the stubs, so only the end-to-end tests make real VMs. The Go tests share a few helpers, so each one reads the same way:
stubtest.New(t)puts the stubs first onPATHfor one test, as the CLI tests have them, with a new folder under/tmpas theirSTUB_DIRand itscallsfile as theirSTUB_LOG. The folder goes when the test ends.stubtest.New(t, "ssh")puts only the stubs it names onPATH, so the host's other commands, such as git, stay. ItsCallsreturns the calls the stubs logged,Resetforgets them, andTouch,WriteandReadwork on the files the stubs read, such as a switch, a file whose presence makes a stub fail.VM,SizeandVMsset and read Lima's instances in the stubs' state, andKeychainandSetKeychainthe Keychain's items.stubtest.Command(t, "mise")returns the path of one stub, for a test that runs it by its path, asDEVVM_HOST_MISEdoes.stubtest.Git(ctx, args...)is plain git for a test's own repo, and a test runs git only through it, which the structure test checks. Its environment is the test's without git's variables that pick a repo, its files or its config, such asGIT_DIR,GIT_WORK_TREEandGIT_CONFIG_PARAMETERS(stubtest.GitEnv), and it reads no global or system config. A git that runs the tests, such as a hook's orgit rebase --exec's, sets some of those variables, and a test's git that kept them would work on the checkout itself, writing its config and commits there. A test that runs something else that runs git, such as a script or a stub, callsstubtest.NoGitRepo(t)first, which takes the same variables out of the test's environment until it ends, andstubtest.Newcalls it for the stubs. The CLI tests' environment leaves them out too.stubtest.ExecRunneris a backend's runner that runs each command as it is, with no run log, so a backend under test runs the stubs.msg.IDOf(err)returns the ID of the message an error carries, or "" when it carries none, andmsg.NamesOf(err)returns the message's names, as names mode prints them, or the error's own text when it isn't a message. A test compares either with what it expects.- A
msg.Fakeis themsg.Reportera package under test prints and asks through. Its zero value is quiet: it prints nothing, has no terminal, so it refuses every question as the UI does where it can't ask, and runs a logged command as it is. Its fields change that:OnInfo,OnWarnand the otherOnfuncs are given each message or question of their kind, with a question's context going toOnNotefirst,OnAnyevery message, andTerminal,Picks,Interruptand the writers stand for the terminal, the picker, an interrupt and the output.OnStatusis given each status line's label and each logged command's step, andShowingreturns the one showing now, for a test that checks slow work runs under its status line (status lines). - A
msg.Recorderkeeps the messages it's given. Set amsg.Fake'sOnInfoorOnWarnto the recorder'sAdd, then compare itsNamesor itsIDs. backendtest.Storedis the fake backend with its disks on the host, for the free-space checks.- The proxy's child in a test's process gets
IO'sconfine, a confinement that confines nothing (noConfine), becauseconfineChildwould confine the test's whole process on Linux.ChildMainusesconfineChildonly when the field is nil, andrunChildOnrefuses to start without one. A test ofconfineChild's own logic callsconfineWithwith a confinement of its own. A test's server made withnewServerlooks up its names and connects in the test's process, becausenewChildServergives it the broker itself. The tests that run the child over a real socketpair (inProcess) send every lookup and connection through the broker instead, and a broker in a test connects through a seam of its own (broker.net'sconnect) wherever it could reach the internet.internal/landlock'sTestSelfruns the test binary again as a child that confines itself and logs what it could still do. It runs only without cgo (CGO_ENABLED=0), as CI'snocgojob and a hand run on a Linux host do, and skips under the race detector, whose cgo keeps Go from reaching every thread. The CLI tests' devvm is built without cgo, so on Linux their VMs' proxies' children run confined too.
Goroutine leaks
A goroutine that outlives its test is one that would outlive its command in devvm, such as a tunnel the proxy carries after it has closed, or a goroutine that passes signals on after its child has ended. internal/leaktest finds them in every package that starts goroutines: internal/proxy, vmssh, daemon, desktop, ui, vm, backend/lima, platform, cli, gitprotect, vmlog and memnet. It imports only the standard library, so the proxy's and the daemon's tests use it too.
leaktest.Main(m), in a package'sTestMain, runs the tests and, once they've passed, reads every goroutine's stack. It gives the goroutines that are still ending, such as a closed listener's accept loop, five seconds, then fails the test binary with the stacks of any still running. It leaves out the standard library's own goroutines that outlive every test and that no test can end, whichallowedlists with why:signal.Notify's loop and an HTTP client's idle connections. It then reads Go'sgoroutineleakprofile, which names each goroutine blocked for good on a channel, a lock or a wait group that nothing still running can reach, and fails on any it names. ATestMainthat makes the test binary a helper process runs the helper first and callsleaktest.Mainlast.leaktest.Check(t), called first in a test, fails that test when a goroutine started while it ran is still running once it has ended, its context cancelled and its cleanups run, after the same five seconds. It counts the goroutines the test started, and theirs, followed through those still running, so a test running in parallel doesn't count. Nor does a goroutine that a server shared between tests starts for the test, such as a server thatTestMainor async.Oncestarted. That goroutine leads back to the server's own goroutine, which ran before the test, andMainfinds such goroutines at the end.Check's failure names the test, whereMain's names only the binary, so a test of something that starts and stops goroutines, such as a link session, the port forwarder or the desktop's relay, calls it.
Anything Main or Check finds is a leak to fix, with a test that fails without the fix. Only a goroutine that the standard library starts and that outlives every test goes in allowed. A new package that starts goroutines gets a main_test.go that calls leaktest.Main, which the structure test checks, and the structure test also lists every goroutine devvm's code starts, with what waits for it to end (goroutineSites).
Time and lifecycles
A test of a timeout, a grace or a close, such as the relay's grace, the forwarder's close or the proxy's ClientHello deadline, runs in a testing/synctest bubble, synctest.Test(t, func(t *testing.T) { … }), rather than sleeping on the real clock. Inside the bubble, time is fake and moves only when every goroutine of the test is blocked, so time.Sleep(30 * time.Second) returns at once, and synctest.Wait() returns once every other goroutine has done what it can. Such a test takes no time, and a loaded CI machine can't make it fail, so it never needs the margins a real-clock test does.
A test checks that something happens at the moment it's due and not a nanosecond before. It sleeps to just short of the moment, calls synctest.Wait() and checks, then sleeps the last nanosecond and checks again. A goroutine that never ends fails the bubble as a deadlock, and a test of something that starts and stops goroutines calls leaktest.Check(t) before the bubble as well.
Time moves only while each goroutine waits on something inside the bubble: a channel, a timer, time.Sleep, a sync.Cond or a wait group. A socket's read, a process's wait or any system call that blocks keeps it from moving, so the code under test gets seams. Like every test seam, each one is a field that a test sets to a stand-in in memory:
internal/memnetis a network in memory for tests.memnet.Pipe()makes a connection, and amemnet.Networkholds listeners by address, whoseListen,DialandDialContextstand in for a socket's. Its connections close their writing side alone (CloseWrite), as TCP's do andnet.Pipe's don't. They hold up to 64 KiB that the other end hasn't read before a write waits, as a socket's buffer does. They have deadlines on the bubble's clock, and so do its listeners, throughSetDeadline. It uses only the standard library, so the proxy's tests use it.- The forwarder and the link sessions take their listeners from their
Listenfields, so a test gives them amemnet.Network's. - The relays carry each connection through an
sshRelay, whosestartfield starts itsssh -W. In production it'sexecSSH, and a test's stand-in,memSSH, is a VM in memory that sends what the test tells it and ends only when its context does, asexec.CommandContextkills ssh. - The proxy connects to the far ends through its egress's
connectfield, whichmemServepoints at amemnet.Networkwhile it serves the proxy on a listener in memory. - A
daemon.Procasks itsAlive,ArgsandSignalfields about its process, so a test ofStopgives it a process table of its own (fakeProc). - A test's own HTTP server, when the test sends the requests itself, is
httptest.NewTestServer's, which serves in memory, and the test sends through itsClient(), which reaches it whatever the request's host.
A stand-in can't show what the real thing does with a kernel's buffers, a real ssh or a real process, so each kind of lifecycle keeps one test that runs the real one, on the real clock: TestPipeSSHGrace, TestPipeSSHGraceSlowClient and TestPipeSSHGraceWriteError run the relay with an ssh stand-in on PATH, TestForwarderEndsStuckRelay closes a forward whose relay's ssh never ends, TestLinksBurst fills a link's real Unix socket, TestSpliceKeepsAnEarlyAnswer splices over TCP and TestProcStop stops real processes. A new seam keeps the real test of its kind.
The proxy's tests that start a whole proxy, such as TestMainRuns and TestAgentRelay, run its child in the test's process (inProcess), on real sockets, so they can't run in a bubble. Their broker waits testStartWait, 30 seconds, for the child to say it's ready, through IO's startWait field, where devvm's own proxy waits 4 seconds, and each test waits as long for the proxy to listen (retryFor). Under the race detector on a loaded Linux host, those starts can take more than 4 seconds, most of it spent hashing the test's executable, which each broker does as it starts, so a wait of 4 seconds would fail them.
CLI tests
CLI tests are testscript scripts in testdata/script/*.txtar, run by internal/cli/script_test.go against a freshly built devvm. Call it with exec devvm …:
# An unknown flag fails.
! exec devvm --nope
stderr '^devvm: flag_unknown command=devvm flag=--nope$'
Scripts see messages by their names, so the example checks which message devvm printed, not its wording. A script that checks a message's text sets env DEVVM_MESSAGES= first.
Run one script with mise exec -- go test ./internal/cli -run TestScript/<name>.
Each script runs in a sandbox under /tmp, never the real folders:
| Variable | Points to |
|---|---|
HOME |
home/ |
XDG_DATA_HOME |
data/ |
XDG_CONFIG_HOME |
config/ |
DEVVM_LIMA_HOME, LIMA_HOME |
lima/ (short, for Lima's socket paths) |
DATA, VMS, RUN |
devvm's data folder, data/devvm/, and its vms/ and run/ folders |
CFG |
devvm's config folder, config/devvm/ |
DEVVM_MESSAGES |
names, so messages print as their names |
STUB_DIR |
stub/, for stubs' state |
STUB_LOG |
stub/calls, the stubs' call log |
DEVVM_SECRET_SERVICE |
devvm-test, the Keychain service name |
DEVVM_UBUNTU_URL |
ubuntu/, with a dated release as Ubuntu signed it. Its cloud image is a gigabyte, so the sandbox has a stand-in for this host's in data/devvm/images/ubuntu/, named for its SHA-256 in the release's checksums, as if devvm had downloaded it, and a script that tests the download or the import from Lima's cache removes it |
DEVVM_TOOL_SLOTS |
1, so tool images build one at a time and the stubs' calls keep their order, and tools_side_by_side.txtar sets 3 |
DEVVM_KVM |
stub/kvm, a file standing in for Linux's /dev/kvm |
DEVVM_TEST_CPUS, DEVVM_TEST_MEMORY_GIB, DEVVM_TEST_FREE_GIB |
8, 16 and 500: a large host, whatever runs the tests (details) |
DEVVM_HOST_MISE |
the mise stub, which resolves the shared tools in place of devvm's own mise |
DEVVM_CLIP_TOOLS |
the stubs' folder, so devvm paste runs the clipboard stubs in place of the system's tools, such as macOS's /usr/bin/osascript, and no script reaches the real clipboard |
MISE_STUB_LOCK |
testdata/mise.lock, the lock the mise stub writes |
TOOLCHAINS, AGENTS |
the toolchains' and the coding agents' names, in the registries' order and joined with spaces, as devvm's messages list them, so a script that checks a list names no toolchain or agent itself (stderr 'names='$TOOLCHAINS'$') |
AGENT_CHOICES, LOGIN_AGENTS, KEY_AGENTS |
every agent's name, those that devvm agent login logs in, and those with a key for each provider, in the registry's order and joined with a comma and a space, as a message of choices lists them (stderr 'choices='$AGENT_CHOICES' command=') |
DEVVM_BIN |
the folder of the built devvm, alone |
DEVVM_REPO |
the checkout, for the scripts in scripts/, which tests copy into a throwaway repo before running, and the scripts in assets/, which tests source to check their pieces |
DEVVM_SSH_PORTS, SANDBOX_PORT_NEXT, SANDBOX_PORT_END, DEVVM_PORT_RANGE |
the sandbox's own ports, as the next paragraph says |
Each sandbox has a block of 160 ports of its own, between 10000 and 19999, below both the range devvm chooses ports from and the system's ephemeral range, so neither a devvm that a script runs nor an outgoing connection takes one. The sandbox holds the block's lock file in /tmp/devvm-test-ports-<uid>/, a folder of your user's alone, while it lasts, so no other sandbox has the same block, whether it's in the same test process or in another one running at once, such as a second worktree's gate. While every block is held, a new sandbox waits for one, up to 5 minutes. The block's first 60 ports are for the scripts. The VMs' ssh ports (DEVVM_SSH_PORTS) come first, and then the ports for free_port VAR… and the fixtures. Each of those is taken in turn from SANDBOX_PORT_NEXT up to SANDBOX_PORT_END, and it's free on every address, 127.0.0.1 included, when it's taken (free_port -range FIRST LAST takes two in a row). The other 100 are the range the sandbox's devvm chooses its VMs' proxy and desktop ports from (DEVVM_PORT_RANGE, which only a test build reads), so two sandboxes' devvms never choose the same port.
The built devvm is a test build, so it reads the stand-ins above that a release ignores, such as DEVVM_KVM and DEVVM_HOST_MISE. A script answers a question in one of two ways: ttyin -stdin FILE gives the next exec a terminal whose input is the file, so devvm asks as it does in yours, and env DEVVM_PIPED_ANSWERS=1 with stdin FILE has each question read its answer as a line of the file instead, without its prompt. Without either, devvm has no terminal, so it refuses every question, as a script's devvm does. It has the checkout's assets/ embedded, as a release has, and no test build reads them from elsewhere: a script that needs other files for devvm (layers, features, policies) puts them in the user's folders in the sandbox, as a user would.
$WORK, the script's own folder, is the current folder. project NAME makes the folder $WORK/NAME and goes to it, as a project's folder, and project NAME git makes it a git repo too. Once devvm has made the folder's VM, vm_name VAR NAME finds it among the states in $VMS and sets $VAR to the VM's name, which ends in an ID the test can't know, so a script can pass it to a stub (exec limactl stop $WEB). It also sets $VAR_dir to the VM's folder, $VMS/<hash>, so a script reads the VM's state as $WEB_dir/vm.json and its network log as $WEB_dir/logs/network.jsonl. catg GLOB prints the one file a glob matches, and fails when the glob matches none or more than one, so a check never reads two files by mistake. vm_state GLOB prints the one VM state a glob matches as sorted KEY=VALUE lines for stdout to match: a section's fields are dotted (net.on=true, ports.host.ssh=23456), a list of strings is joined with spaces (tools.names=node claude), a list of objects is indexed (links.links.0.name=db), and anything but a string is JSON. Negated, ! catg GLOB and ! vm_name VAR NAME pass when there isn't exactly one. json_set GLOB KEY=VALUE… sets string fields in each JSON file the glob matches and keeps the rest, or makes the file when a glob without wildcards matches none. KEY:=JSON sets any JSON value, and a dotted key sets a field of an object, which it makes when it's missing. Scripts write devvm's JSON records with it, such as a tool image's record (json_set $SHARE/node-*.json built=2020-01-01T00:00:00Z), because a record's times are in the file, where touch can't change them. renumber FILE changes a VM's state as a boot that numbered the disks' devices anew leaves it, as macOS does. The folder's identity and each .git's git_id get another device, with their inodes and birth times as they were, and $FOLDER_ID and $GIT_ID hold the folder's and its own .git's identities from before the change. fixture VERSION puts a release's state into the sandbox, and json_superset [-shape] [-changes PATH] WANT GOT checks that one JSON file has everything another has, as Released state says. A VM state a script writes as a fixture needs version, id, name, image, dir and backend, created for a VM whose creation finished, and a hash of its own for its folder (json_set $VMS/12345612345601/vm.json version:=1 id=x name=devvm-live-12345612345601 image=base dir=/p/live backend=lima created=2020-01-01T00:00:00Z net.on:=false).
Tests never touch the network. Downloads are served from a test server (net/http/httptest) or read from a file:// folder. DEVVM_UBUNTU_URL replaces https://cloud-images.ubuntu.com/releases/resolute, where devvm finds Ubuntu's dated releases: point it at a folder of release-YYYYMMDD/ folders, each with its SHA256SUMS and SHA256SUMS.gpg, as file:///path/to/folder. The CLI tests serve internal/ubuntu/testdata/resolute, a release as Ubuntu published and signed it, and Go tests sign their own releases with a key they make (internal/ubuntu/pgp_test.go). devvm's own releases, which devvm upgrade installs, come from internal/upgrade/upgradetest: a TLS test server laid out as GitHub's releases, with keys of the test's own (Signers, which internal/minisign/minisigntest makes) that sign each release's SHA256SUMS as minisign does, as a release is signed while releases bridge from the old release key: by CI's and the co-signer's keys, and by the old key. A script starts one with release_server [-badsig] [-legacy|-keys] LATEST [VERSION...], which serves a release of each version, the first the newest, each devvm in it a script that prints its version. -legacy has only the old key sign them, as 0.1 and 0.2's releases are, -keys only the release keys, and -badsig other keys. It points a test build at the server with DEVVM_REPO_URL, at the release keys with DEVVM_RELEASE_KEYS, as ci=KEY cosign=KEY recovery=KEY, at the old key with DEVVM_RELEASE_KEY and at its certificate with DEVVM_RELEASE_CA, and DEVVM_TEST_VERSION gives the test build a release's version. Container registries (--from) are a TLS test server in Go tests; scripts use pinned digests, which need no lookup, or set HTTPS_PROXY to a closed port, so lookups fail as offline ones do.
A command left running in the background (exec devvm … &name&) can be interrupted with kill -INT name. wait_file FILE waits up to 60 seconds for a file to appear, such as one a stub writes when it gets somewhere, and fails at once when every background command has ended. For anything else, wait_until SCRIPT runs sh -c SCRIPT every 100 ms until it succeeds, for up to 90 seconds. It fails at once when every background command has ended, or when SCRIPT exits 100, which is how a check that can no longer succeed says so, as when it waits on a session that ended. Wait with these two rather than a loop of your own. A script that runs a copy of devvm makes it with cp_exe SRC DST, not cp: on Linux, a command another script starts while the copy is being written keeps the file open for writing until it runs, so running the copy then fails with "text file busy", and cp_exe writes the file while no command can start.
Stubs
The stubs stand in for every host command devvm runs, so tests never run the real tools: 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, mise, and the clipboard tools wl-paste, wl-copy, xclip, osascript and pbcopy, which read a clipboard the test lays out in $STUB_DIR (clip-types, clip, clip-file) and write what's copied to $STUB_DIR/copied. They are one Go program, internal/stubtest/stub, which does what the command it's run as would do: the binary is named stub, each command's name is a link to it, and it reads its name from its argv[0]. internal/stubtest builds it once, into $TMPDIR/devvm-stubs-<hash> with its links, where the hash covers the stub's sources and Go's version. Every test process, and every later run until the sources change, finds that folder and uses it, so the binary builds only once, and a folder of an older build is removed once it's a day old. TestScript puts that folder on PATH right after devvm's, ahead of the real commands.
Each stub logs its call to $STUB_LOG as one line, its name and its arguments joined by spaces. The stub writes the line itself, in one write to the log opened for appending, so lines from stubs running at once never mix, and its arguments never go to another process's command line. That matters because endpoint security tools such as CrowdStrike Falcon kill a process whose arguments look like an ssh option next to a proxy URL with a password, which is what a start's limactl edit passes. stub_calls prints the log for stdout or cmp to check, ! stub_calls fails if anything was logged, and stub_reset empties the log, so the next check sees only the calls after it:
exec devvm …
stub_calls
cmp stdout calls
-- calls --
limactl list
uname and sw_vers pretend to be another host when these are set, and run the real command otherwise:
| Variable | Printed by |
|---|---|
STUB_UNAME_S |
uname -s |
STUB_UNAME_M |
uname -m |
STUB_SW_VERS |
sw_vers -productVersion |
What the stubs keep between their calls is their state, $STUB_DIR/state.json, which internal/stubtest/stubstate reads and writes as typed JSON under a file lock, so stubs running at once never lose each other's changes. It holds Lima's instances, each with its status, size and config, the Keychain's items, the SSH agent and its keys, and Time Machine's exclusions. Scripts read and change it with the stub command, and Go tests with the stubtest.Stubs methods VM, Size, VMs, Keychain and SetKeychain:
| Command | What it does |
|---|---|
stub vm NAME STATUS |
Lima lists the instance NAME in STATUS, such as Stopped, Running or Broken, with Lima's default size when it's new |
stub vms |
prints Lima's instances, one NAME STATUS line each, sorted |
stub size NAME CPUS MEMORY DISK |
gives an instance its size, with the memory and disk in bytes |
stub keychain ACCOUNT |
prints the Keychain's item for ACCOUNT, and fails when there's none |
stub keychain-set ACCOUNT |
saves the item for ACCOUNT from its input, so the value is in no process's arguments |
stub agent |
prints the SSH agent's keys as ssh-add -l lists them, and fails when no agent runs |
stub agent-stop |
stops the SSH agent |
stub names |
prints every stub's name |
A switch is a file a test makes in $STUB_DIR to change what a stub does, such as start-fails, which makes limactl start fail. The comment above each stub's function lists its switches, and every switch is named for the command and what happens to it: -fails, -hangs, -fails-on and -waits-on, where an -on switch holds the text that a call's arguments must contain. A stub that hangs touches $STUB_DIR/hanging first, so wait_file can wait for it. The files a stub writes in $STUB_DIR are what a test checks, such as $STUB_DIR/sync.tar, what a VM's setup was sent.
limactl keeps its instances in the state and fails or hangs on request. It keeps each instance's size and config as create, clone and edit set them, and a contract test checks that it does so as real Lima does. Its shell reaches the guest, the VM the stubs make believe in, which ssh reaches too. One module, guest.go, answers whatever devvm runs in a VM, with one set of switches whichever way devvm gets there. limactl shell is also the shell devvm opens in a VM, which then ends, so a script sees it as devvm's last call. In the shared tools' build VM, its shell writes the images build.sh is asked for into the build's folder (or, on request, a symlink instead), and it keeps what a VM's setup is sent as $STUB_DIR/sync.tar. A base build's packages go in as $STUB_DIR/packages-in.tar, and what the build gives back is $STUB_DIR/packages-out.tar, or no packages. In the --from build VM, its shell writes what oci/build.sh would (or, on request, a hostile disk, command line, C library or symlink), and a call naming $STUB_DIR/interrupt-on's text interrupts devvm, as Ctrl+C would. The VM's ssh host keys are one made-up key for each VM, unless $STUB_DIR/hostkeys-fails exists.
docker stands in only for what --from asks of it. It has an image only when $STUB_DIR/docker-image holds its ID, its save writes a tarball naming that image (or $STUB_DIR/docker-saved's, a tag that moved), and it isn't running when $STUB_DIR/docker-down exists. ssh answers a port forwarder's master with $STUB_DIR/guest-ports, and a link session's master listens on its control socket. Either master outlives the process that started it, as ssh's does, until the sandbox's cleanup stops it or 5 minutes pass. A direct connection from a VM (the self-check's) fails, as a confined VM's does, unless $STUB_DIR/net-direct exists. A --clone VM's git and its seed's scripts run on the host, with real bash, git and tar, on $STUB_DIR/vmfs/<folder>, and ssh fetches from there (it fails with $STUB_DIR/ssh-fails). A clone's command fails, as any shell does, when $STUB_DIR/shell-fails-on holds text its arguments hold, such as index-pack for the seed's apply. security stands in for the Keychain and tmutil for Time Machine, both keeping their items in the state, never in the real ones. mise writes $MISE_STUB_LOCK as the lock ($MISE_STUB_OLDER_LOCK for a list of versions), lists $MISE_STUB_VERSIONS, and fails like mise offline with MISE_STUB_FAIL set. With MISE_STUB_FAIL=404, it fails like mise when node's newest version, and one of the older versions a step back locks together, have no musl download yet. A lock of named tools then adds only their entries, for the platforms it names, to the lock that's there, and a lock naming $MISE_STUB_OFFLINE_TOOL fails like mise offline. chflags sets no flags, so .git protection leaves test folders deletable. qemu-img and QEMU are there so Linux hosts pass devvm's checks.
To add a stub, write its function in internal/stubtest/stub, with a comment that says what it does and lists its switches, and add it to stubs() under the command's name. It logs its call with c.log() first, keeps what it must remember in the state through c.update, and reads its switches with c.on and c.text. A new command the state needs goes in control. To add a switch, read it in the stub's function, name it for what it does as above, and add it to that function's comment. Each stub has unit tests in stub_test.go, which run it in the test's own process. Where a stub prints what devvm parses, such as limactl list --json, the golden fixtures check that it prints what the real tool prints.
devvm runs in $WORK or a folder made in it (mkdir, then cd), never in HOME or devvm's own folders, which it refuses as project folders.
Coverage
mise run test measures each package's test coverage, then fails when a package's coverage is more than a point below its line in the baseline, so coverage only goes up. That point of room is there because the same tests can cover a little less from one run to the next, with timing or the tools a machine has installed. A package inside it passes and keeps its line. Each system has a baseline of its own, testdata/coverage/darwin.txt and testdata/coverage/linux.txt, because macOS and Linux run different code and skip different tests. On a system without one, mise run test says so and checks nothing. A package's coverage counts its own Go tests and the CLI tests together. scripts/test.sh sets CLI_GOCOVERDIR, so TestScript builds devvm with -cover for every package of devvm's, and each devvm a script runs writes its counters to that script's own folder inside it. Scripts run in parallel, and devvm runs that started at the same moment in one folder would race to write the same meta-data file, so one of them would print coverage meta-data emit failed on stderr and fail any script that checks it. go tool covdata then merges every script's folder with the Go tests' own counters. That way internal/cli, and code that only the CLI tests reach, such as a backend's real runner, count as tested. The end-to-end tests don't count.
When a change raises a package's coverage, raise its baseline in the same commit. Run mise run coverage, which runs the tests as mise run test does, then writes each package's coverage to this system's baseline where it went up, and commit the file. A change that raises coverage on both systems raises both baselines, so run it on a Linux host too. It never lowers a line: a package within a point below its baseline keeps the line it has, and when a package is more than a point below, it fails and writes nothing. A new package gets its line from mise run coverage too, and a package that's gone loses its line there, because mise run test fails on both until then. coverage.txtar checks scripts/coverage.sh, which compares the coverage with the baseline.
There's no target percentage: a package is judged by what's untested in it, not by its number.
End-to-end tests
mise run e2e runs devvm against real VMs, so it needs Lima and takes minutes: run it in the background. It runs TestE2E in tests/e2e, with the run's flags after --. First it checks that this machine has every command the chosen sections use, and it names each one that's missing with what installs it (the list). Then it builds devvm from the checkout into its sandbox, its files embedded, and runs every check through that binary:
| Lima home | ~/.lt-e2e-go (or $DEVVM_E2E_LIMA_HOME); it refuses ~/.lima and devvm's own |
| State | /tmp/devvm-go-e2e (XDG_DATA_HOME, XDG_CONFIG_HOME) |
| Keychain | service devvm-go-e2e (DEVVM_SECRET_SERVICE), fake tokens only, deleted at the end |
| Lock | /tmp/devvm-go-e2e.lock, a symlink to the pid of the run that holds it, so only one run uses the sandbox at a time |
| Git identity | GIT_AUTHOR_* and GIT_COMMITTER_* of its own, so the harness's commits and tags work on a machine with no git config, and yours never goes into them; devvm's own git ignores them |
mise run e2e # every section but desktop and from
mise run e2e -- --from # every section, from too, and base with every feature: the longest
mise run e2e -- --only images,gc # just these sections
mise run e2e -- --clean # delete the sandbox's cached images and tool images first
mise run e2e -- --every-feature # base with every feature, as a run with from builds it
mise run e2e -- --slots 3 # the sections spread over 3 sandboxes that run at once
mise run e2e -- --slot 1 # run in slot 1's sandbox, its images as it has them
mise run e2e -- --newest-base # base from Ubuntu's newest image and packages, in a sandbox of its own
mise run e2e -- --golden # also capture the stubs' golden fixtures from the real tools
End-to-end tests in Go says how to run go test yourself, write a check and add a section.
A change that touches VMs passes the sections for what it changed, with --only, and a run with --only that names from builds base with every feature, as --from does. Before you merge a change to assets/ or to --from, run --from, because only it runs every section on base with every feature. GitHub's hosted runners can't run the end-to-end tests on macOS, so a Mac of your own runs them there.
--newest-base builds base as a user's first build does, in place of the pinned release that the other runs use, and Maintaining says when to run it and what to do when it fails. --golden writes the golden fixtures of this system into the checkout, for you to commit.
The sections so far:
images: building base and fixture layers, rebuilds, a failed script and Ctrl+C during a build, then base's recorded packages, each in the cache under its SHA-256, and base built again under the same key withubuntu-mirrorset to an address nothing answers on, whose apt reads only the build's own folder of packages.project: devvm in a new project folder (under/tmp/devvm-go-e2e/p) makes a VM from base and opens a shell there, which reads its commands from devvm's input. The folder and the shared tools are mounted and nothing else is, there's no SSH agent, no Docker (no docker layer) and the hostname is the folder's. The ssh config lists it asdevvm-webwith its host keys pinned; through an~/.ssh/configof the run's own that includes it under aHost *forwarding the agent,ssh devvm-webworks, forwards no agent (a throwaway one), and refuses a changed host key..gitis locked (macOS) and git in the VM can still commit.devvm stopstops it and drops its entry, and on macOS reports and locks a submodule git folder the VM added. With stand-in clipboard tools inDEVVM_CLIP_TOOLS,devvm paste --jsonputs the copied image into the running VM's paste folder, where its SHA-256 matches, mode 600 in a folder of mode 700, and the stand-in copier got the path;devvm paste rm --forcedeletes it and leaves a file of the user's; and a stopped VM is refused before the clipboard is read.TestE2EExecQuotingininternal/backend/registry, which runs only there (DEVVM_E2E_VMnames the VM), checks that arguments with spaces, quotes,$, newlines and globs, a folder and input reach the guest as given, through theExecof the backend the VM's state records, so one test covers every backend. Then a VM from adevcontainer.json, with no ports by default: itsforwardPortssaid and not forwarded, none reaching this machine, itscontainerEnvin the shell and its commands, itspostCreateCommandrun once in the folder, itspostStartCommandat each start (again afterdevvm restart), nothing written to the folder, and a changed file warned about without changing the VM. Then a claude VM with a fake agent config, history, git identity and token in a home of its own:devvm agent importcopies the agent's settings into the sandbox's agent store without the history or the links out of its folder, naming each link it leaves out, and withconfig.toml'sfollow-linksnaming a dotfiles folder, it copies the skill folder a link leads to there as a folder, never a link, and still none of the links to a file outside it. The store's folder is mounted read-only and linked into the VM's home, the linked skill's copy with it, which root can't write either, and the home folder's isn't mounted, its settings are copied and its history isn't, the VM gets the git identity, the timezone and its hostname, and, open as it is, the token's placeholder and never the token.devvm agent savewithout a terminal shows the VM's changedsettings.jsonas a diff and its newcommandsfolder's file, then refuses and saves nothing, and after a yes it saves both into the store, but neither the VM's fake login beside them nor the folder's link out of it. Then SSH agents, with a home of their own and throwaway keys: a--ssh-agentVM uses a throwaway agent standing for yours; afterdevvm ssh-agent addanddevvm ssh-agent devvmit keeps yours, in its shell and by name, until a restart, then uses only devvm's own agent's key, in its shells and by name; afterdevvm ssh-agent off, none.clone:--clonewith a throwaway repo, and host git and devvm run with a home of the section's own, so neither reads your~/.ssh/configor your git settings, and the Include line isn't offered. The VM has its own clone with every branch, even though the repo'surl.*.insteadOfsends its URL elsewhere, only the shared tools are mounted, and its shell opens in the clone. The repo gets adevvmremote named after the VM, and nothing of.gitis locked or watched. Without a terminal,devvm rm --forcerefuses while the clone has commits that weren't fetched and keeps the VM. Oncegit fetch devvmthrough devvm's ssh config has brought the VM's commit,devvm rmrefuses for uncommitted changes in the clone, and then for those in a worktree in the clone, shown under its path, anddevvm rm --no-clone-checkdeletes the VM after a warning, the worktree's change with it, and removes the remote, while the fetched work stays as a local branch. A git worktree's VM gets a clone of only its branch and that branch's upstream. On a VM that mounts its folder,devvm clone onwithout a terminal is refused, anddevvm cloneshows off.devvm clone on --forcethen makes it again with its own clone of every branch, only the shared tools mounted and.gitunlocked, and it keeps its home and its ID.devvm clone off --forcewithout a terminal refuses while the clone has commits that weren't fetched and keeps the clone, and once they're fetched, it mounts the folder again with.gitprotected, keeps the VM's home and ID, removes the remote and leaves the work as a local branch. Last,devvm --clone --repos allin a folder of repos gives one VM a clone of each repo at its path, with every branch, the folder's own file, and nothing mounted but the shared tools.devvm clone fetchbrings both repos' work back and lists the branch with both repos,devvm clone addcopies a third repo into the VM at its path, with a remote,devvm rmwithout a terminal refuses for the work in one repo that wasn't fetched, naming that repo, anddevvm rm --no-clone-checkdeletes the VM and removes each repo's remote. A repo with a detachedHEAD, an annotated tag, origin's branches and an older VM's remote gets a clone detached at the same commit, with the tag still annotated and origin's branches, and none of the VM remote's. The same repo's staged, unstaged and intent-to-add changes and a tracked file turned into a folder give the samegit statusin the VM, which has neither the untracked.envnor the folder, and devvm names the folder. Its clone has origin's URL, another remote's https URL without the user and token it has here, a branch as far ahead of its upstream as here, and the repo'suser.nameanduser.email, which a commit there takes with no identity given, none of its credential settings, and its pre-commit hook, which runs there.devvm clone fetchbrings back a commit only the VM's detachedHEADhas, assaved/devvm/HEAD, anddevvm rmnames another, but not the uncommitted changes copied in, which the VM left as they came. A repo whose rebase, started with--autostash, stopped on a conflict, after a reset, with a stash of a plain entry and a--allone, gets a clone in the same rebase, whichgit rebase --continuefinishes there, bringing the autostash back; its stash is the repo's but for the--allentry, which devvm names, the commit only the reset'sORIG_HEADreached isn't there, anddevvm rmnames a stash entry the VM made, not the one copied in. Ablob:noneclone of a small public repo, on the internet tier, gets a promisor clone whose git fetches a blob it lacks from the repo's origin. Work in the VM that names another blob neither side has doesn't come back, anddevvm clone fetchsays so withclone_fetch_partial, then brings it back once git in the VM has read the blob. Both checks are skipped when github.com can't be reached. A repo with a submodule that has one of its own, both initialised, gets clones of them in the VM, wheregit submodule status --recursiveis as here; a VM commit in the submodule comes back into its repo here withdevvm clone fetch, anddevvm rmwithout a terminal names a commit in the nested one that wasn't fetched, and keeps the VM. A repo that uses Git LFS, made withoutgit-lfson this machine, has its LFS file's content in the VM, whosegit statusis clean, with git-lfs's filter in the clone's own config and not in the VM's system or global config; a file the VM'sgit-lfsadds comes back withdevvm clone fetch, its object in the repo here, and an object in the VM that isn't what its pointer names stays out, named withclone_lfs_kept.gc: a VM from a folder namedimg-keep, which is named like an image, and a fixture layer edited after its build:devvm gcdeletes the stale image and its record and an old tool image no VM lists (once there's a tools lock), and keeps base and the VM.tools: first, the shared tools resolve to upstream's newest versions, with devvm's pinned mise (downloaded once), each download with its checksum. This section is the only one that uses the newest versions, and no other step checks for them (DEVVM_NO_TOOL_CHECK). At the section's end, e2e puts the pinned lock back. Then a node project's VM: node, npm, pnpm, bun and yarn at the locked versions, each a read-only EROFS image, the share read-only even for root,npm i -ginto the VM's home, a non-login shell over SSH, an.nvmrc's own version, the tools mounted at boot without devvm, and a second node VM that builds nothing. Last, a .NET project's VM on the allowlist tier, chosen by its solution file: the shared SDK at the locked version from the share, a console project that restores a package from NuGet, builds and runs,dotnet tool install -ginto~/.dotnet/toolswith the tool run from a non-login shell, every toolchain's environment andPATHfolders in a login shell and a non-login one, a workload installed into~/.dotnet, nothing of it blocked, and aglobal.json's own SDK installed into the VM.network: a VM with Claude Code, Codex, opencode and pi and--network allowlist, a fake token in devvm's environment and a fake~/.claude.jsonand Codex login in a home of its own, whichdevvm agent importcopies into the sandbox's agent store, only yours to read. Its proxy runs and the self-check passed; its password was in no host process's arguments while devvm launched it (ps, sampled), and the guest has it;ssh devvm-netreaches it; with transparent mode stopped, direct connections fail, even as root, to an address and to other ports, TCP to a public server's port 53 included, and with it running a public DNS server and Lima's DNS addresses answer only with the stand-in address, TTL 0, or nothing; an allowed host works and others, or other ports, are blocked; a line in the VM's policy file that reads as a deny but isn't a rule makes the running proxy refuse an allowed host, with no allow command indevvm network log --blocked,devvm network rmwarns of it, and the host works again once it's gone; with transparent mode stopped, DNS fails at once,/etc/resolv.confnames127.0.0.1alone, and Lima's DNS addresses answer nothing. Transparent mode runs: its service, the stand-in address onloand dnsmasq and socat on that address alone; names with a dot resolve to it, a name without a dot to nothing, IPv6 has none at once, and/etc/hosts' names keep theirs; curl without proxy settings and a static Go client with its own resolver reach github.com with its own certificate, loggedwithout proxy settings; a blocked host gets the403over the VM's CA; port 5432 of a name is refused at once anddevvm-whynames it, while an IPv6 connection on loopback that works isn't listed as refused; a port a rule names, on a TLS server on this machine, is redirected while the rule is there and refused at once afterdevvm network rm; servers of the VM's own bind0.0.0.0:443and:80; the service comes back when it's killed or its table flushed;devvm network transparent offtakes it out at the next launch andonputs it back. In a VM of the docker layer, containers without proxy settings reach github.com on the default bridge and on a network of their own, a blocked host is logged, no other port of the stand-in address answers them, a container's published 5432 isn't reached through the stand-in address from the VM or another container while its published 443 keeps the VM's connections off it, and an--internalnetwork reaches nothing. The host's loopback services are out of reach, directly or through the proxy. Behind the run's company proxy on this machine's loopback, named in the shell'sHTTPS_PROXY, the VM's proxy sends an allowed host there by name and refuses a blocked one before it gets there. Thenconfig.toml's[proxy]names the same company proxy with its user alone, and the shell sets no proxy: the launch is refused untildevvm secret set proxy --stdinsaves the password, and once it's saved, the VM's proxy config names the secret and holds no password, and the company proxy, which refuses any request without that password, carries GitHub. After each launch, the password is in no process's arguments, in no log and nowhere in the guest, and after theconfig.tomllaunch it isn't in the VM's proxy config either. The launch after that, with neither setting, goes directly. The section's leak scan, run once its secrets are used and again at its end, looks for each company proxy's password as it is, as a URL'suser:password, as Basic's base64 and as the wholeProxy-Authorizationvalue, in devvm's logs, the VMs' proxies' logs and Lima's. Before the section starts, it deletes any of its secrets that a killed run left behind. The proxy refuses requests without the VM's password; the token is nowhere in the VM, which has its own CA and the next one, its own placeholder and logins' copies with placeholders only; the proxy puts the token in for its host (for the VM's own placeholder only), an MCP server's header and Codex's key for theirs, over TLS the VM verifies; a second allowlist VM has CAs of its own, each VM trusts only its own and has no key, each proxy serves and presents only its own VM's CAs, anddevvm rmdeletes one VM's CAs and leaves the other's; the home folder's and the store's login files are unchanged.devvm agent savesaves the VM's changed~/.claude.jsonwith the store's MCP header in place of its placeholder, and once the VM changes that server's URL it leaves the file out, so the store keeps the server as it was.devvm secret set github --stdinsaves a fake token (in the Keychain on macOS, under the run's service, found through a link to~/Library/Keychainsin the VM's home), read from a file so it's in no process's arguments, anddevvm secretlists it saved, while askingdevvm secretfor agetsubcommand is refused without printing it;secret use githubbinds it to the running proxy at once, and on the next launch the VM has its own placeholder inGH_TOKEN, never the token, which the proxy puts in forapi.github.com;secret unuseandrmtake the binding and the token away.TestE2ESelfCheckininternal/netpolicyruns the self-check on the VM: it passes, then, once the VM is started outside devvm, it fails and stops the VM.devvm stopstops the VM and its proxy at once.devvm network openmakes its next start direct, its proxy set in the guest and answering, and the open VM holds no real secret either: the token is nowhere in it, its environment and Codex's login hold only its placeholders, its proxy puts the token in over TLS the VM verifies with its own CA, and a request that goes around the proxy carries only the placeholder and gets a 401 from the token's host. Thendevvm network internetanddevvm network nonechange its tier at once, the VM running on. Restarted behind the run's company proxy on this machine's loopback, named in the shell'sHTTPS_PROXYwith a fake password that the check reads from a file, the guest has the proxy and reaches GitHub through it, while devvm's run logs hold the password only as<password>and Lima'sha.stderr.logonly as stars.devvm network allowlistwhile it runs open shows itunenforceduntildevvm restartstarts it confined;devvm network openwhile it runs confined keeps it on its proxy until it next starts. Behind a company proxy of the run's own that fakes OpenAI's token endpoint with a certificate from the run's CA, a login made in the VM is captured: the store gets the fake tokens and API key, and the VM gets placeholders. Thendevvm agent login codexruns the real Codex's login in the VM, curl on this machine opens its callback with the state Codex's address names, through the forward oflocalhost:1455, devvm names the account the store saved, the VM's Codex holds only placeholders, and the forward is gone once the login ends, and gone too after an interrupted login.devvm agent login opencode --device-coderuns the real opencode 2's Codex device code login in the VM, which the fake endpoint answers too, devvm says the store saved the login, andopencode auth exportin the VM shows only placeholders. A second VM with opencode hasOPENCODE_DISABLE_AUTOUPDATE=1in its login shell, makes its database and imports a credential of its own, thendevvm agent login opencode --api-key --provider openrouter --stdinsaves a fake key from the first VM, and at the second VM's next launch its opencode has devvm's entry with the key's placeholder, never the key, beside its own credential, and once its database is deleted and made again, the next launch gives it the key's placeholder again. With a local server's fake key and a Copilot Enterprise login added to the store's opencode login, its next launch warns that both are withheld, and neither the VM'sauth.jsonnor its opencode holds the key or the tokens. Onceconfig.toml's[pass-keys]lists both providers underopencode, the launch notes the key as passed, the VM'sauth.jsonand its opencode's database have it, and the login's tokens still stay out. pi runs in the network VM withPI_SKIP_VERSION_CHECK=1andPI_TELEMETRY=0, in a login shell and in a non-loginbash -calike, and an install it can't write to, and its policy reaches its catalog atpi.dev. Its terminal UI, started in a terminal ofscript's, finds base'sfdfindandrgand downloads nothing into~/.pi/agent/bin, while with aPATHthat has nofdfindthe same start downloadsfd, which shows the start reached that check. The same company proxy fakes Claude's token endpoint and Anthropic's API, which logs the token each request brings, or thex-api-key:devvm agent login pi --api-key --provider anthropic --stdinsaves a fake key, the VM's pi holds only its placeholder, and pi's own request reaches the API with the key the proxy put in, which no log holds. The same company proxy fakes Groq's API too, anddevvm agent login pi --api-key --provider groq --stdinsaves a fake Groq key, the VM's pi holds only its placeholder, and pi's own request reaches Groq's API with the key in itsAuthorization, which no log holds. It fakes OpenAI's API as well, and afterdevvm agent login pi --api-key --provider openai --stdinsaves a fake OpenAI key, the VM's pi holds only its placeholder, which starts withsk-, and pi's own request reaches OpenAI's API as an API key's, asking formax_output_tokens, with the key in itsAuthorization, which no log holds. The same company proxy fakes Gemini's API, and afterdevvm agent login pi --api-key --provider google --stdinsaves a fake Gemini key, the VM's pi holds only its placeholder, and pi's own request reaches Gemini's API with the key in itsx-goog-api-keyand no key in its URL, which no log holds. Thendevvm agent login opencode --api-key --provider groq --stdinsaves a fake Groq key for opencode, the VM's opencode holds only its placeholder, and the request thatopencode runmakes reaches Groq's API with the key in itsAuthorization, which no log holds. Thenclaude setup-token's request, as curl, makes the fake token theclaudesecret and gives the VM its placeholder, and the API gets the token for it, while the claude.ai connectors' host,mcp-proxy.anthropic.com, gets only the placeholder. The OAuth login's placeholder also gets the token at the API, and the connectors' host gets only that placeholder too.devvm agent login claude --setup-token, run in a terminal of its own (scripton macOS, Python'sptyon Linux), shows Claude Code's address there, and the check stops it before any login. Thendevvm agent login clauderuns the real Claude Code'sclaude auth loginin the VM, its code pasted on devvm's input with the state its address names, the store keeps the fake login and theclaudesecret is gone, the VM's~/.claude/.credentials.jsonholds only placeholders and its environment no token, and once the store's access token is due, the VM's next request makes the host refresh it at Claude's endpoint through the company proxy. The refresh trusts the VM's proxy's CAs, the run's among them, so it succeeds. The store keeps the refreshed login, the VM's requests to the API and tomcp-proxy.anthropic.comgo on with the refreshed access token, and no log holds a value.TestClaudeOAuthGetchecks the refresh too. Last, a VM made with--network learnruns on the internet tier, shown asinternet (learning), and reaches example.com and example.org;devvm network lock --jsonlists both, each with its port, and its next launch counts what it learned;devvm network lock --alladds exactly the hosts it learned to its own rules and gives it the allowlist tier at once, the VM running on, so example.com still works on 443, while its port 80 and example.net get a403.desktop: a VM of base has none of the desktop's programs, and devvm desktop refuses it, naming the layer.--layers desktopmakes a VM of the desktop image, and devvm desktop serves its desktop on this machine's127.0.0.1alone, keeping its port and its password from one run to the next. A viewer with a wrong password is refused, and one with the password gets the VM's desktop. The VM's server listens on its user's own socket and on no TCP port, with the clipboard off, and the password is in no file of the VM's, in no run log and in no host process's arguments while devvm desktop starts. With network policy, the VM still reaches only its proxy and not the desktop's port on this machine, the desktop's browsers use the VM's local proxy without a password, a blocked host still gets a403, and the local proxy isn't forwarded to this machine. When root in the VM runs a server of its own without a password, a viewer with a wrong password is still refused and one with the password gets in, and the refused viewer never reaches the VM, nor does the viewer's clipboard, only its key event. Ctrl+C ends devvm desktop and closes its port, anddevvm desktop --clipboardstarts the server again on the same port with the clipboard on, which a viewer with the password gets.nix: the nix layer. A copy ofassets/layers/nix.shas a layer of the run's own, built behind a company proxy of the run's own, reaches Nix's releases through it and leaves no proxy settings fornix-daemon(and not the company proxy's password) anywhere on its image's disk. Then a folder withpackage.json,flake.nixand.envrcgets a VM with node on the nix layer (--layers nix) on the allowlist tier: Nix and direnv at their pins, a store that's root's,sandboxon with no fallback,trusted-usersroot alone and an untrusted user's--option substitutersignored,nix-daemonwith the VM's own proxy in devvm's drop-in alone,nix run nixpkgs#hellofrom Nix's cache, a build in Nix's sandbox,sudo nixandnixover ssh, the flake's dev shell (nixpkgs at a pinned revision) loaded by direnv in an interactive shell, itsnodeahead of the shared node prompt after prompt and gone outside the folder, nix-direnv's cache in the VM's home with no.direnvin the folder, a fixed-output download from a host that isn't allowed refused with403and named bydevvm-why, and afterdevvm network openanddevvm restart, no drop-in and no proxy for the daemon.from: run with adockerthat isn't running, so nothing comes from Docker. Its container images go by their pinned digests, asnode:24@sha256:…, so devvm looks them up nowhere, except the company proxy'salpine:3.21, which keeps its tag so that devvm's registry lookup is checked too. A VM fromnode:24with node, python and Claude Code on the docker and nix layers (Debian 12, in a home of its own) boots, with its base keyed by the pinned digest, its node, python and claude at the locked versions, GNUtaras its commands find it, its tool images built in a clone of devvm's own Ubuntu base when the run builds them, the docker layer's Docker from Docker's Debian repository, and the nix layer's Nix under systemd runningnix run nixpkgs#helloand a build in Nix's sandbox, then, afterdevvm network allowlistanddevvm restart, transparent mode's checks as the network section has them, and with its service stopped, Lima's DNS and a public server answering nothing; a VM fromalpine:3with node and dotnet, which itspackage.jsonandglobal.jsoncall for, on the docker, nix and desktop layers runs node and pnpm from musl tool images, and dotnet's musl SDK with ICU, which makes and runs a console project, built in its own base and keyed and recorded by its digest, the docker layer's Docker on OpenRC, the desktop layer's programs from Alpine's packages, with no crashed services, and the nix layer's Nix as an OpenRC service, withnix run nixpkgs#helloand a sandboxed build, then afterdevvm network allowlistanddevvm restarttransparent mode's checks on OpenRC and musl, as for Debian 12, and a download only its daemon makes from a host that isn't allowed refused with the proxy's403, and with GNUtaras its commands find it,devvm history importputs an export into it, while an export with a path outside the agents' history imports nothing there, and on a Linux host, given Lima'smmapwith no mode chosen,devvm mount-cache nonegives itnoneat its next start, through the restart that a remount Alpine refuses gets, which devvm's portable check of the folder confirms; base builds fromubuntu:26.04; and the build VM and its temporary folders are gone.link: links between VMs, each check the end-to-end proof of a row of the threat check in the design note. It runs devvm with a soft limit of 256 open files, macOS's default, as the link sessions it starts get that limit too, and it makes two small open targets, each forwarding no port and running servers on its own127.0.0.1(/var/tmp/e2e-link.pl, in perl, which every base has), and a client that forwards every port. Each of the three reserves the link checks' ports (ip_local_reserved_ports), so Linux never gives one to a connection's own end, where a connection that just ended would hold it for a minute and a later server orssh -Rcouldn't bind it.sshd -Tin each VM shows remote forwards allowed on127.77.*:*alone, at the address the host asks for, and the client's own Lima rules ignore every port. A port the target doesn't publish is refused bydevvm link add, and once a port is published,devvm link addon the running client reaches it within seconds asNAME:PORTandNAME.devvm.internal:PORT, by curl and by a raw TCP client (bash's/dev/tcp), while with--as NAMEthe target's folder name doesn't resolve. Two targets on one port are each reached by their own name, port 80 is linked on port 80,devvm linkanddevvm link publishlist what they hold with"version": 1in their--json, anddevvm network allowlistis refused for the client while it links to open targets. A published port that isn't linked has nothing listening for it,devvm link unpublishrefuses the link's next connection, logs it and names the client, anddevvm link rmtakes the listener away within seconds. In the client, sshd listens only on its own port and the links' addresses, and nothing from a link listens on127.0.0.1,::1or every address, so this machine gets no forward of a link, while a server of the client's own on127.0.0.1with a link's port is forwarded as usual. Each link's socket is mode 600 in the run folder of mode 700, and the link session and every process it starts listen on no TCP port and connect only to the VMs' ssh ports.ssh -Rinto the client binds nothing outside127.77.0.0/16(rfwd_links). A program in the client that holds a link's address first fails that link alone withlink_port_taken, 256 connections at once, past the socket's backlog of 128 on macOS, are all carried, and a 257th is refused and logged aslink_limit. Root in the client then loosens its sshd and the link session connects again: withPermitListen anythe client binds only the links' addresses, because the host asks for nothing else, and withGatewayPorts yestoo, the link session still listens on no TCP port of this machine and connects only to the VMs' sshd.devvm network logshows the links' connections and refusals. A stopped target refuses the connection, logslink_target_stoppedand stays stopped, and the client's launch warns of it. Once it's restarted, the link works again.devvm rmof the target removes the client's link, names the client and removes its sockets, and a VM made again in that folder isn't linked. Then the client and one target get the allowlist tier, the target while it runs. Until the target restarts,devvm lsshows itunenforced, the client's next connection is refused and logged asunenforcedwhile the target's server runs, anddevvm link addand the client's launch warn of it (link_target_unenforced). Once both have restarted, the client reaches its link by curl through its proxy settings and by a raw TCP client while a direct connection fails. A link added while the client runs is reached at once by curl through its proxy, byGETandCONNECT, with no link name inNO_PROXYand the client's boot and host keys unchanged, and the client's proxy refuses names, ports and addresses that aren't on its own list, while the target's proxy refuses the client's link name.devvm link addrefuses an open target,devvm network openis refused for the target, and with the rule broken by hand in the target's state the next connection is refused and the client's launch warns and runs without the link until the rule holds again. In the--fromtier, an Alpine client reaches its link to port 80.devvm rmof the client leaves no link session, socket, pid file, log or link state.
Every section but tools uses the shared tools' versions pinned in tests/e2e-mise.lock, for both architectures' glibc and musl VMs, and the --from checks start from container images pinned by digest in tests/e2e/from_test.go (fromNodeDigest, fromAlpineDigest and fromUbuntuDigest). The images built from them stay valid until a pin moves. base starts from the dated release of Ubuntu's cloud image that e2eUbuntuRelease in tests/e2e/sandbox_test.go names, given to devvm as DEVVM_UBUNTU_RELEASE, in place of the newest that a user's devvm pins, so base's key stays the same between runs and on every machine of one architecture. devvm keeps a release it has pinned, so when the sandbox's pin names another release, as it does after scripts/bump.sh e2e-ubuntu moves e2eUbuntuRelease, the run deletes that pin before its first section, and the next build pins e2eUbuntuRelease. Its packages are those its key recorded at its first build in the sandbox, which stay in the sandbox's package cache through --clean, so base built again under the same key installs the same packages until assets/ or the release changes its key. scripts/bump.sh e2e-tools moves the lock to upstream's newest versions, resolved with devvm's pinned host mise, scripts/bump.sh e2e-from moves the digests to what Docker Hub has for each tag, and scripts/bump.sh e2e-ubuntu moves the release to the newest Ubuntu lists; scripts/bump.sh --check shows them against upstream. The lock's first line is the SHA-256 of the assets/shared-tools/mise.toml it was resolved from, and a run stops at once when that file has changed since, until scripts/bump.sh e2e-tools resolves the lock again.
base, the --from bases and the shared tool images stay cached between runs, except what a rebuild or gc deletes: every stale image in the sandbox (other selections' bases, whose features differ, among them) and every unused tool image (an earlier from run's musl ones, and the tools section's newest versions where they differ from the pins); every other VM a run makes is deleted at its end, and its project folders are unlocked and deleted. Each check prints [n/N], how long it took and the time left as the last complete run of each of its sections measured it, and a heartbeat every minute shows the latest output. e2e keeps each section's times in a file of its own in slot 0's state folder, timings/plain/SECTION, or timings/features/SECTION for a run whose base has every feature, because that run also checks base's features. So a run of any selection, in any slot, estimates from and compares with the sections it runs. A check fails on its first failure, except the few marked Flaky, which flake on timing, such as the network section's check that the proxy's password was in no host process's arguments, and the link section's 256-connection check and its stopped-target check. When one of these fails, e2e shows its output and runs it once more, and a second failure fails it. Its result says retried once, its line in the timings has a third field, retried, and the summary counts the retried checks and names each one. A check a run has nothing for is counted as SKIP: base's features, with base cached. A section that runs fewer checks than its last complete run with the same tests/e2e Go files fails the run, because an error ended it early, and e2e keeps the times it had. After you edit those files, each section's first complete run sets the count the next runs compare with. Checks look for devvm's messages with devvm _msg, never by their wording. The Go tests that need a real VM or desktop, TestE2EExecQuoting, TestE2ESelfCheck and TestE2EDesktop, skip unless their DEVVM_E2E_* variables are set, and e2e runs each of them through s.GoE2E, which sets those variables in the test's environment, so a value such as the desktop's password is in no process's arguments.
Each check's command has a time limit, counted from when it starts: three times the check's longest time in its section's last complete run, at least 2 minutes, or 10 minutes for a check with no time yet. The checks that build base or a --from base, which Builds() marks, get at least an hour, because their last time may have been a cached build. The steps between two checks, such as the launches that build tool images, get an hour too. When a check runs past its limit, the heartbeat stops the processes it started, with TERM as Ctrl+C would and then KILL 30 seconds later, and the check fails with the heartbeat's last line in its output. When the steps before a check run past their limit, the heartbeat stops their processes the same way, and that check fails without running. Either way, the run goes on to the next check and then to its usual cleanup.
Slots
A host with spare cores and memory can run the sections at once, each set in a sandbox of its own called a slot. mise run e2e -- --slots N spreads the chosen sections over N slots, from 1 to 9, and runs each slot as a --slot K run of its own, all at the same time. The default is one slot, which is the run described above. Slot 0 is the sandbox in the table, and slot K adds -K to its Lima home, state folder, Keychain service and lock, as ~/.lt-e2e-go-1, /tmp/devvm-go-e2e-1, devvm-go-e2e-1 and /tmp/devvm-go-e2e-1.lock. Each fixed port the checks use is slot 0's plus 100 times the slot, so slot 1's servers use 47260 where slot 0's use 47160. Slot 0's ports run from 47160 to 47199, from 47240 to 47249, and 47613, 18765 and 18766, so no two slots ever share one.
e2e places the longest sections first, each in the slot with the least time so far, using each section's time from its last complete run. A section that has never run gets a guess, from 2 minutes for gc and clone to 30 minutes for from. link always goes in the same slot as from when both run, because in the --from tier link's Alpine client starts from the image that from builds. Each slot runs its own sections in the usual order, and a slot left without a section isn't started. When go isn't on your PATH, e2e finds mise's Go once and puts its folder first on the slots' PATH, because slots that each ran mise exec at the same time would each install the repo's tools over one another. With --from, e2e passes --every-feature to every slot, so each slot's base has every feature, as a single --from run's has.
Before the slots start, e2e takes every slot's lock and gives each other slot what slot 0 has and it lacks: every image's Lima instance and record, every tool image and its record, and devvm's caches. It clones the large files and never copies them whole: on macOS each one is an APFS clone, which needs both folders on one APFS volume, and on Linux a reflink. The records and the --from digests are small files, so e2e copies them. When a file can't be cloned, as on a Linux host whose /tmp is tmpfs, e2e says so and that slot builds its own. With --clean, nothing is cloned, and each slot deletes its own cached images instead. A --slot K run of your own uses that slot's images as they are.
Each slot's output appears as it comes, each line led by its slot's number, such as [1], and stays in the slot's e2e.log. When every slot has ended, e2e prints each slot's sections, results and time, then the sums: checks passed, failed, skipped and retried, the failed checks by name, and the time the whole run took. The run fails when any slot fails or ends without its results. TERM or Ctrl+C stops every slot with TERM, and each one cleans up as a single run does.
Testing on other hosts says how many slots each kind of host runs. Testing on other hosts also covers Linux hosts, x86_64 and the checks to run by hand.
The tests behind How it works
The How it works pages say in words what the tests of a mechanism check, and this section names those tests, so you can find the one to extend when you change the mechanism. Each unit test is named with its package, the CLI tests are files in testdata/script/, and the end-to-end checks are in tests/e2e, in the section the page names. The design notes name the tests of each emulation themselves (design notes).
- How the proxy puts secrets in:
TestCheckName,TestCheckHost,TestCheckHeader,TestCheckEnv,TestCheckPrefix,TestDefineandTestChangeApply, ininternal/secrets, check what a secret of yours may be and what devvm secret set's flags change.TestReservedEnvAssetsandTestEnvReservedForSecrets, ininternal/netpolicy, check the variables a secret can't take.TestInjectSecretShapesandTestSchemeOK, ininternal/proxy, check each shape a value goes in and each that keeps the placeholder, andTestPathWithin,TestForRequestMethodsandTestInterceptSecretMethodsthat a binding's path and methods let it in only for the requests they match.TestGetChecksTheBindingchecks that a binding that isn't the secret's as it's saved gets nothing,TestValueMaxandTestKeychainLine, ininternal/platform, that a value too long for the Keychain's line is refused, andTestPlaceholdersthe placeholders' one shape.TestCustomStore,TestCustomsUnreadableandTestWriteFilesCustomcheck the list, its mode and its checks,TestValuesCachedByBinding, ininternal/proxy, that two bindings of one name are cached apart, andTestCustomSecrets, ininternal/vm, use, a new value and the question before a delete.- The CLI tests are
secret_custom.txtarandlayout.txtar, and the end-to-end checks are intests/e2e'snetworksection.
- The VM's CA:
TestInitCA,TestInitCASwitch,TestInitCAReplaced,TestInitCATogetherandTestInitCACancelled, ininternal/trust,TestPrepareOpen, ininternal/netpolicy, andTestNextCASigns,TestLoadCAandTestServersApart. The CLI tests arenetwork.txtar,sync.txtarandlayout.txtar. - Logins made in a VM:
TestCaptureLogin,TestCapturePaths,TestCaptureEarlyHintsAnswerAndSaved,TestCaptureErrorPasses,TestCaptureRefusesandTestCaptureGet, ininternal/proxy, check what goes out, what the VM gets and what's refused.TestCodexCapture,TestOpencodeCapture,TestClaudeCapture,TestClaudeSetupToken,TestClaudeOAuthGet,TestCaptureRefuses,TestEndpointsandTestPick, ininternal/agentlogin, check each agent's file, its placeholders and copies, and its refresh.TestOneClaudeLogin,TestClaudeBindingsandTestClaudeOAuthVMCopy, ininternal/secrets, check the one Claude Code login and its bindings, andTestCapturerandTestCaptureOwnAgents, ininternal/netpolicy, the endpoints in every VM's config and which agent a capture is.TestAgentLoginTerminal, ininternal/vm, andTestTerminal, ininternal/ui, check that an agent's login gets the terminal's files only when devvm's input and output are both terminals. The end-to-end checks are intests/e2e'snetworksection.
- Agents' logins and settings:
TestFormatsWithholdUnknownplants a field that no format knows in every login file,~/.claude.jsonincluded, and checks that no VM's copy holds it. - Learning from the log:
TestTickablechecks that no name devvm network lock ticks is a shared-hosting domain or under one. - A company's CA in builds:
tests/e2e'simagessection checks that a layer built with a test CA trusts it while its script runs and keeps its key once the folder is emptied, and that a copy of its image booted without devvm has none of devvm's CA files. Itsprojectandtoolssections check a company's CA in a VM, whichtests/e2eruns on real VMs.