vivarium
Run and debug vivarium tests (nixidae's NixOS test runner on UML, QEMU, krun and container guests) -- choose sandboxed or by-hand runs, wait with `vivarium monitor`, pause on failure and reach into live guests with `vivarium ctl` or the vivarium MCP tools, read events.jsonl. Load before running any vivarium `mkTest`/`fromNixosTest` attribute, a `.driver`, or a test suite that runs in vivarium guests (pynixd, nixkube, easykubenix and others).
- License 许可
- Apache-2.0
- 所属仓库
- nixidae/nixidae
- 最近更新
- 2026-11-15
- Stars
- ★ 1
- Forks
- 0
01 前言 Front Matter
- name
- vivarium
- description
- Run and debug vivarium tests (nixidae's NixOS test runner on UML, QEMU, krun and container guests) -- choose sandboxed or by-hand runs, wait with `vivarium monitor`, pause on failure and reach into live guests with `vivarium ctl` or the vivarium MCP tools, read events.jsonl. Load before running any vivarium `mkTest`/`fromNixosTest` attribute, a `.driver`, or a test suite that runs in vivarium guests (pynixd, nixkube, easykubenix and others).
03 SKILL.md 正文
vivarium
A test is mkTest: guests (nodes.<name>, NixOS modules) plus phases (async def test(vms) files or pytest), ordered by after. Every test attribute has run variants; the guests are the same in each.
Choose the run
| attribute | when |
|---|---|
nix build --file . <test> |
the verdict, as CI runs it. No network, no way in. A failure keeps its output: nix eval --raw --file . <test>.attempt |
nix run --file . <test>.driverDebug -- --out DIR |
anything that may fail: pauses at the first failure, guests stay up |
nix run --file . <test>.driver -- --out DIR |
by hand, exits at the first failure. Add --break-on-failure for the same pause as driverDebug |
<test>.uml .qemu .krun .container |
the same test on one backend |
- A test that pulls from the internet must run as a driver. In the sandbox it fails on DNS, which reads like a broken test.
--offlinemakes a by-hand run match the sandbox. A sandbox failure reproduces this way; there is no way into a sandboxed run.- Driver flags:
--break PHASE|start|failure|end,--only PHASE(runs itsafterphases too, nothing after it),-v(every command sent),--keep,--cpus [GUEST=]N/--cpu-scale [GUEST=]S(processors of one guest, or of every guest not named; QEMU and krun default to all host cores; MCPstarttakescpus/cpu_scaleas a number or{guest: n}). --outmay be relative; use a new directory per run, in the scratchpad. Files a container guest wrote there can be owned by a sub-uid and resistrm(nixidae/nixidae#1064): pick a new name instead.- Never edit a phase and start a new run to test the edit. Pause and send it, or
vivarium reload(below).
Wait
One command, in the background, run bare: it starts the run detached (its output in $OUT/run.log) and exits at the first pause or at the verdict, with the monitor's codes. The guests stay up after it exits 4.
vivarium run <test> --out "$OUT" --break-on-failure --until-pause # background
vivarium ctl --out "$OUT" continue --wait # after probing: next pause or verdict
Without the vivarium CLI, start the driver and the monitor together, both in the background:
nix run --file . <test>.driverDebug -- --out "$OUT" > "$OUT.log" 2>&1 # background
vivarium monitor "$OUT" --quiet # background
- The monitor waits up to
--wait(1800 s) for the run to start, because the driver evaluates and builds first. Nountil [ -e ... ]loop, nosleep. For a runvivarium runstarted, it prints each derivation as it starts building (not with--quiet), and exits 2 with the error if evaluating or building fails;$OUT/build.jsonlholds every Nix log record, build log lines included. - Exit: 0 passed, 1 failed, 2 no verdict (crash, eval error), 3 stream lost or no run started, 4 paused, 5 stopped, 6 ready (an environment). Re-arm after each
continue, or usectl continue --wait: it exits at the next pause or the verdict with the same codes. --through-pausesruns to the verdict; without--quietit also prints each phase start and pass.- With a
nix rundriver, the driver's own exit is the other half: a build or eval failure ends the driver and the monitor then times out. Read$OUT.logwhen the driver task ends first. - A background task exiting 0 is not a pass. Read the monitor's exit code,
status, orphases.json. - Run the monitor bare.
vivarium monitor ... | tailor...; echo rc=$?makes the task exit 0 at a pause; a paused run then reads as "completed (exit code 0)". - Name what you wait on when you stop: "waiting on the monitor for <test> (task X); then <next step>".
- Never wait on GitHub Actions. A local pass is the verdict.
Environments
Guests that stay up after the phases, for work from the host (a cluster to kubectl against):
vivarium up <test> --out "$OUT" # background; exits 0 at ready with access.json on stdout, 4 if a phase failed (paused)
vivarium ls # runs up on this host: state, test, --out
vivarium down --out "$OUT" # 0 if every phase passed
upisrun --holddetached; the runner's--hold(MCPstart(hold=True)) pauses atreadyafter the last phase passes.ctl stopat ready ends the run with its verdict (exit 0), notstopped.- Way in, written before boot:
$OUT/access.json(each guest's ssh and forwards),ssh -F $OUT/ssh_config <guest>(root,vivarium.rootPassword),$OUT/access/(what phases write viavms.access;bring_upwritesaccess/kubeconfigwhen the control plane forwards 6443, themodules/k8s.nixdefault). - A host port reaches only
vivarium.forward, fixed at boot;{ guest = N; }(nohost) gets N or the next free port, named inaccess.json.ctl,switch,reloadwork at ready as at a pause;continueat ready runs what a reload added and holds again; onlystopends it. - Plain Nix:
nix run --file . <test>.up -- --out DIR, in the foreground. checks.k8s-host: a one-node cluster, ready toup.
At a pause
vivarium is on PATH in the dev shell of each project that runs vivarium tests (packages.vivarium, built on huggorm). The run also prints absolute command lines at start and at each pause, and $OUT/run.json holds them, with the test's name, guests, phases and spec. A run the vivarium CLI started prints vivarium lines; a nix run driver prints its runner's path. Never scrape $OUT.log for them.
vivarium ctl --out "$OUT" state
vivarium ctl --out "$OUT" exec 'print(await one.succeed("systemctl --failed"))'
vivarium ctl --out "$OUT" exec - < probe.py
vivarium ctl --out "$OUT" inject ./tests/check.py # a file's async def test(vms), read fresh
vivarium ctl --out "$OUT" pytest ./tests/guest -- -k etcd
vivarium ctl --out "$OUT" run check # a declared phase
vivarium ctl --out "$OUT" continue
vivarium ctl --out "$OUT" continue --wait # then wait: exit 4 at the next pause, else the verdict
vivarium ctl --out "$OUT" watch # progress, pauses, verdict: one line each, to the end
vivarium ctl --out "$OUT" stop # end it here, guests down
exec: Python on the host, top-level await;vms,session,anyioand each guest by name in scope; names persist between calls.execandinjectprint the code's output as it comes, andpytestone line per case as it ends (--json: the whole reply at the end).exec,inject,stateandstopalso work while phases run;pytest,run,continueneed a pause.- Loop: read the failure, probe with
exec, edit the test file,inject/pytestagain, repeat until it passes, thencontinue. injectreads the phase file fresh, but a helper module on the test'spythonPathstays the store copy the run imported. To test an edited helper, name its working-tree directory:vivarium ctl --out "$OUT" inject ./phases/x.py --reload ./lib(repeatable;pytesttakes it too). The directory goes first onsys.path, and the modules it provides are dropped.- A run started by
vivarium run <attr>also printsvivarium reload --out O: evaluate the test again and give the paused run its edited phases (scripts, pytest specs,after,nodes, settings), guests kept. Thenctl run <phase>orcontinue. Refused if a guest changed. A phase that ran keeps its verdict until run again. - A run started by
vivarium run <attr>also prints aswitchline (vivarium switch --out O --node N --module ./module.nix; the attribute comes fromrun.json): edit a NixOS module, switch one guest to it, no new run. Anix rundriver prints none. ctl stopends the run, paused or running: guests down, exit 5, verdictstopped. It returns once the run has exited. Never kill the driver by pid or pattern.ctl stateprintspaused before <phase>(orrunning), thenphase\tstate, with the first line of the error on a failed phase.ctl --json <op>prints the whole reply as one JSON object:pause,state,errors(full text).- Do not pipe
ctlintotail/head: a refusal goes to stderr and exit 1, and the pipe hides both. - Guest helpers:
succeed,execute(rc, out),fail,wait_for_unit,wait_until_succeeds/wait_until_fails(cmd, timeout),until(what, check, timeout, evidence=)(async check returns a value, orNonefor not yet),never(what, check, timeout),vms.until(what, check(vm), timeout, machines=): no hand-written retry loops.journal(unit),processes(),meminfo(),switch_to(name), screen methods on QEMU guests withvivarium.display. - Links:
await vms.segment("core").cut("leaf1")/.restore(...)drops a member's frames on the host, carrier up;.capture()writes<out>/pcap/core.pcap(segments.core.capture = true: from boot). Only a hub segment (segments.core.hub = true, or three members); nonftortcpdumpin the guest. By hand:vivarium ctl --out "$OUT" segment core cut leaf1.
MCP
The vivarium server (vivarium-mcp) does the same through tools: start(attr, file, env, breaks, break_on_failure, only, hold), state, exec, inject, run_pytest, run_phase, resume, segment, switch, reload, screenshot, events, runs, stop.
starttakesattr(withfile, the directory or file to evaluate) orspec, neverfilealone. It runs with--break-on-failure.startreturnsmonitor: run it with the Monitor tool or in the background, exactly as above.- The
vivarium-runsmod (share/claude-plugins/vivarium-runs, if loaded) shows each run in a pane with Continue and Stop; it followsstartandvivarium run --out <literal>by itself,/vivarium-runs <out>any other. eventsreplies have no size limit: always passkind,machine,phaseorcontains, and a smalllimit. One unfilteredcasequery returned 233k characters.
Evidence
In --out (by hand) or result/ / .attempt (sandboxed):
| file | holds |
|---|---|
run.json |
written before the first guest boots: vivarium (the CLI), socket, pid, commands |
events.jsonl |
every event, with kind, machine, phase, seconds. Query with jq, not grep |
phases.json |
each phase's state and why one was skipped |
console/<guest>.log |
one guest's console |
log |
everything, readable |
report.json |
where the time went: .slowest, .by_command |
artifacts/<guest>/ |
what the guest wrote to /artifacts, including journal.jsonl |
jq -r 'select(.kind=="phase_finished") | "\(.phase)\t\(.data.state)"' "$OUT/events.jsonl"
jq -c 'select(.kind=="journal" and .data.priority <= 3)' "$OUT/events.jsonl"
jq -c 'select(.kind=="case" and .data.outcome=="failed") | .text' "$OUT/events.jsonl"
Traps
vivarium.memorybelow ~192M OOM-kills the guest agent; it looks like a hang.- A guest agent failure surfaces as an exception from
vm.execute; the traceback is inawait vm.journal("vivarium-agent"). - Writes to
/nix/storein a guest vanish at poweroff, by design. - A run cleans up however it ends, SIGKILL included. A guest process (QEMU, libkrun, UML) left after the run ended is a vivarium bug worth an issue.
- The working copy reaches a run only through Nix: in a jj repository a new file needs a jj command first.
04 同仓库更多 Skills
pytest-agent
How to run pytest and read its results when the pytest-agent plugin is installed. Use when running tests, investigating a test failure, deciding whether a failure is new, re-running failures, profiling a slow test, or diagnosing a hung or killed run.
pynix
Run Nix through the pynix CLI instead of the nix CLI -- eval, build, develop, print-dev-env, path-info, log, why-depends, copy, store, search, flake, config, registry. Load before any Nix command; fall back to nix only for what pynix lacks.
pytest-agent
暂无简介