@selfbuilding/testing
v0.1.0
Published
scriptedHarness, tmpdirProvider and emulator setup for offline tests.
Maintainers
Readme
@selfbuilding/testing
The offline test kit: everything here runs with no model, no Docker daemon, no credentials and no network beyond localhost.
tmpdirProvider()
A full SandboxProvider backed by temp directories and local child processes.
- Each box is a directory,
<fsRoot>/<sandboxId>, standing in for/. Execs run/bin/sh -cwith that box's root inSELFBUILDING_FS_ROOT(always the box's own root, whatever the host passed),HOME=/selfbuilding/homeandTMPDIR=/tmpmapped into the box, and none of the host's environment exceptPATH. - Canonical paths (
/selfbuilding/...,/run/selfbuilding/...,/tmp/...) in commands,cwd,readFileandwriteFilesare mapped into the box. Write commands with the canonical paths, exactly as for a real box. pausesends SIGSTOP to every process group the box started andopensends SIGCONT (expireKeeps: "memory"). Handle calls on a paused box throwSandboxUnavailableError; reopen withprovider.open(ref).snapshotcopies the box (snap-...ids; create a box from one withimage.ref = snapshotId),forkcopies it per child. Both skip/runand/tmp, so secrets never land in a copy. Fork children are keyed<parent scope>/fork[<index>]and labelledselfbuilding.parent.- Lifetimes are enforced lazily: an expired box is paused or killed (per
onExpire) on the next provider call. - Fault injection:
provider.faults.inject(kind, op, { times })with kinds503,network,timeout(the call takes effect, then the response is lost),429,401,refuse(pause only).provider.ghost(ref, kind)leaves the listing row and removes the box. - Two providers given the same
rootsee the same boxes, like two processes talking to one vendor. - Call
close()(orawait using) to kill every box and remove the root.
scriptedHarness(script, opts)
A real Harness whose CLI is a small node player shipped into the box by prepare(). It replays scripted steps
(scripted.* builders: say, sh, submit, invalidThenValid, askHuman, notifyHuman, crash,
hangUntilCancelled, error), runs shell steps for real, sends tool calls through the selfbuilding MCP server
from PrepareContext.mcpServers (or the tool socket with toolTransport: "socket"), and prints Claude Code or Codex
native stream JSON (format). Follow-up turns (resumes, ask answers) take opts.turns in order. A script can be a
function of { runId, callPath, attempt }, so one harness value can play a different script per agent call.
runHarnessTurn(box, harness) plays one turn without the runtime, for harness and fixture tests.
Emulators
startGitHubEmulator() and startSlackEmulator() start emulate.dev (pinned [email protected]) with the spec seeds.
seedPlayground(gh) builds a local bare repo (the git remote: the emulator has no smart HTTP) and mirrors it into the
emulator; openPlaygroundPr() commits a branch, mirrors it and opens a PR. mirrorRefs() copies any pushed refs.
Golden streams
toGoldenJsonl(events, { roots }) normalises volatile values (<sandbox:1>, <session:1>, <time>, <usd>, ...)
for expect(...).toMatchFileSnapshot("__golden__/<name>.jsonl").
