Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Testing Layers

The phases of buildl talk to each other through plain values, and to the outside world through ports. That makes the narrow places between them the natural place to test. Every flow is tested first in buildl-core, against fake ports, with no Lua, no file system, no processes and no threads. Then it is tested again against the real adapters, in the crate that owns them.

%% Testing layers — the widest coverage at the bottom
graph BT
    CORE["buildl-core<br/>every flow against fake ports<br/>no Lua, no filesystem, no processes, no threads"]
    ADP["buildl adapters<br/>each module alone: a temp directory, system tools run by argv"]
    LUA["buildl-lua<br/>real airsl: build.lua fixtures to exact declarations"]
    E2E["buildl/tests/e2e<br/>real adapters through the Workspace facade:<br/>a fixture workspace built twice, byte-identical"]
    CLIT["buildl::cli and buildl-cli<br/>argument parsing and exit mapping in process,<br/>then the built binary"]
    CORE --> ADP --> LUA --> E2E --> CLIT

The widest coverage is at the bottom, where tests are fastest and need nothing.

LayerLives inMay touchMust not
Core flowscrates/buildl-core/tests/flows, with the fakes in common.rsbuildl-core's public API and the fakesLua, the file system, a process, a thread
Luacrates/buildl-lua/tests/flows, with fixtures in crates/buildl-lua/tests/fixtures, and unit tests beside the codereal airsl; fixture build files, or files written into a temp workspace, turned into exact StagedFilesanything of buildl
Adapter unitcrates/buildl/src/<module>/, beside the codeits own module, state, search_path, buildl-core, one temp directory; exec starts system toolsanother adapter module; the process's current directory; setting an environment variable
End to endcrates/buildl/tests/e2e, with fixtures in crates/buildl/tests/fixturesbuildl's public API; a temp copy of a fixturea private item; a path outside the package
CLI unitcrates/buildl/src/cli, beside the codeargument parsing, the exit mapping, terminal detection, a command's flow over byte buffers and a temp workspacea process; a terminal
CLI binarycrates/buildl-cli/tests/clithe built binary, with a chosen working directory and environment, its output pipedbuildl internals; a terminal

buildl-core forbids threads even in its tests: crates/buildl-core/clippy.toml bans std::thread::spawn and its kin for the whole crate, test code included. A test that needs real workers belongs to buildl.

The tools the tests run

Tests that run actions run system tools, sh, cp, sort, true, false, sleep and their like, by argv. sh -c appears in tests only, never in buildl. There is no compiled helper program and no shared kit of fakes; Decision Records says why.

The one thing the layers share is a server. The remote cache adapter's tests, buildl's end-to-end tests and buildl-cli's binary tests all talk to the in-memory Remote Execution API server that buildl's test-server feature builds, on loopback. No test reaches the internet, and the shipped binary does not hold the server.

The fakes

The fakes live in buildl-core's integration tests, crates/buildl-core/tests/flows/common.rs, not under #[cfg(test)]. They implement the public traits through the public API alone, so whatever a fake can do, an adapter in another crate can do too, and the compiler checks that on every test build.

PortFakeWhat the test no longer needs
DeclarationSourceFakeSource: a fixed build file, missing file or failed evaluation per directory; other files once the root is evaluated again or handed a discovery resultairsl, Lua
ManifestFakeManifest: one fixed workspace and ceilinga buildl.toml
HostFakeHost: a fixed platform and fixed variables, some of which it can be told to fail onthe real environment
DigesterFakeDigester: files held as bytes with their metadata, counting every calla file system
StatCacheFakeStatCache: in memory, counting commitsa file system
ToolResolverFakeTools: fixed fingerprints, recording every lookupa PATH
ContentStore and SweepFakeCas: blobs and placed paths in memory, each with its mode; digests it can be told to forget, paths it can be told to fail on, reads it can be told to losea file system
ActionCacheFakeCache: rows in memory, labels it can be told to fail on, and the labels it forgota file system
EventLog and RunHistoryFakeLog, and FakeHistory for history alone: what was appended, and whether to faila file system
ExecStrategyFakeStrategy: scripted per label, how the action exits, what it prints, and what is left at each output: a file, an executable, a directory, a symbolic link, something special, or nothingstarting processes
DispatcherFakeDispatcher: runs tasks inline on the test thread, oldest or newest first; it can be told to lose a task, or run one and drop its resultthreads; results are deterministic
ClockFakeClock: a counter, one tick per readthe wall clock
GraphRecordFakeGraphRecord: the graphs recorded, and whether to faila file system
ReporterFakeReporter: every call kept, in ordera terminal
ApproverFakeApprover: one answer, given every time, and every set it was asked about with its attributiona terminal, a data directory
RemoteCacheFakeRemote: results in memory, every call kept in order; it can be told to fail any call, serve tampered bytes, or answer that an input changeda network, a server

The watch loop's own ports, Changes, Cycles and WatchReport, have unit-test fakes beside the loop, in crates/buildl-core/src/watch/run.rs, and a scripted Changes in buildl's end-to-end watch tests.

What runs where

A sample of what each layer proves. The core flows check the decisions; the end-to-end tests check the same promises against real files and processes.

In buildl-core, against fakesProves
//:a fails under --keep-goingthe summary is 1 failed, 2 skipped, 2 built
the cas write succeeds, the cache write failsthere is no row for the target: crash safety
a rebuilt output is byte-identicaldownstream targets stay clean: early cutoff
one input changedthe reason the target is dirty is the difference between its old and new KeyComponents
the [execution] settings all change after a buildevery target stays clean: none is part of a key
a wanted program outside the ceilingError::Refused before any strategy runs
a plugin's target wants what its plugin may not haveError::PluginRefused, naming the plugin, before the ceiling is asked
the dispatcher loses a taskError::DispatcherFault, naming every target left without an outcome
a build with a discovery targetthe discovery target runs first, then what it declared; a second build is all cached
a target the fake remote holdsit ends Fetched, no strategy is called, and its row is written after its content
a remote call failslenient: one warning and the target runs; strict: the build fails
In crates/buildl/tests/e2e, against real adaptersProves
a fixture built in two directories, with four workers and with oneout/, cache.json, graph.json and the cas are byte-identical
a second buildevery target cached; cache.json and graph.json unchanged
out/ removedevery output put back without running, the executable bit kept
the states an interrupted build leavesthe next build finishes, trusts no blob without a row, and clears what was half done
a corrupt cache.jsonError::CorruptState naming the file; check, graph and query still work
a target that reads a file it did not declareit fails under sandbox and builds under bare
the same chain under bare and under sandboxout/ is byte-identical across the two
verify over a target that writes its process idthat target is reported as mismatched, naming its output
a second checkout against the server a first build uploaded toevery target fetched, no action run, outputs byte-identical

A real server, once per CI run

The in-memory server answers as the protocol says, but it is still buildl's own. One CI job, remote-execution, runs crates/buildl-cli/tests/real_remote.rs against NativeLink v1.4.0, built from ci/nativelink.Dockerfile. The file's tests run only when BUILDL_TEST_REAPI_URL names a server, which the job sets, and skip otherwise. A workspace built with --remote-execute ends with every target remote, and a second build in a fresh checkout ends with every target fetched and byte-identical outputs.

buildl builds buildl

The last layer is buildl building and testing this repository, with a released buildl. The repository root is a buildl workspace: build.lua, buildl.toml, buildl.lock, .buildlignore and .buildl-version. cargo make dod stays the gate; this layer shows that the release can run it.

build.lua is written by hand, not by cargo buildl init or cargo buildl sync, and makes four calls on the rust plugin, pinned at plugin-rust-v0.2.1:

TargetCallcargo runs
buildlrust.binary("buildl", …) on rust.package("buildl-cli")cargo build --locked --bin buildl --profile dev --target-dir target -p buildl-cli
cargo-buildlrust.binary("cargo-buildl", …) on rust.package("buildl-cargo")the same, for cargo-buildl and -p buildl-cargo
testsrust.test("tests", …)cargo test --locked --profile dev --target-dir target --workspace --all-targets --all-features
doctestsrust.test("doctests", …)cargo test --locked --profile dev --target-dir target --workspace --all-features --doc

tests and doctests carry the arguments of cargo make test and cargo make test-doc, so a pass means what the gate's two test steps mean. buildl.toml holds what cargo buildl init writes, plus [execution] timeout = "30m", a margin over the default ten minutes: a cold buildl test took 238 seconds on an aarch64 macOS machine, and a CI runner has fewer cores.

What is an input

The rust plugin takes every file under the workspace as an input of every target. The root .buildlignore keeps only what cargo reads:

/*
!/Cargo.toml
!/Cargo.lock
!/rust-toolchain.toml
!/crates/
.DS_*
*.rs.bk
mutants.out*/

The first line leaves out everything at the root; the next four bring back the workspace manifest, the lock file, the toolchain file and the crates. buildl reads no .gitignore, so the last three leave out three kinds of stray file the repository's .gitignore also lists: .DS_*, *.rs.bk and mutants.out*/. Each cargo target then has 529 inputs, and an edit to book/, examples/, skills/ or any other root folder rebuilds no cargo target. A new file at the root stays out; a new file cargo reads outside crates/ needs a !/<path> line. Any other file left under crates/ is an input, and makes every target dirty on that machine.

The pin

.buildl-version holds one line, the version without a v: 0.3.0. buildl never reads it; people and CI install that release with it:

$ curl -LsSf https://airsstack.github.io/buildl/install.sh | BUILDL_VERSION="$(cat .buildl-version)" sh
$ export PATH="$HOME/.local/bin:$PATH"
$ buildl plugins fetch
$ buildl build
$ buildl test

The installer refuses a malformed or unreleased version, but an empty pin, or latest, installs the newest release. So CI checks that buildl --version prints exactly buildl <pin> before any buildl command runs.

The toolchain probe

rust-toolchain.toml tracks stable, so a rustup update changes the compiler without changing an input. Each call passes version_probe = true, which declares a <name>.version target running rustc -vV and puts its output in the key, so a new compiler rebuilds. The cost shows in plan: right after a full build it reads 4 to run, 2 conditional, 0 clean, and a build that changes nothing ends 4 built, 2 cached, the four being the probes.

The probe runs in the sandbox, without rust-toolchain.toml, so it reports rustup's default toolchain. On a machine whose default is not stable, an update to stable changes what cargo uses without changing what the probe reports, and a stale result can stay cached. The remedy there is to delete .buildl/, then run buildl plugins fetch.

The CI job

The self-build job, on Linux and macOS, installs the pinned release, builds and tests twice, and keeps .buildl/ in GitHub's Actions cache:

flowchart TD
    install["install the pinned buildl, check its version"] --> restore["restore .buildl/"]
    restore --> fetch["buildl plugins fetch"]
    fetch --> first["buildl build, buildl test"]
    first --> second["second pass: 4 built, 2 cached, then tests: 2 passed (2 cached)"]
    second --> gc["buildl gc"]
    gc -- "miss, job passed" --> save["save .buildl/ under the key"]
    gc -- "exact hit" --> done["save nothing"]
keybuildl-<os>-<pin>-<sha256 of rustc -vV>-<hash of the inputs>
restore keybuildl-<os>-<pin>-: the newest cache for the same OS and release
inputs hashedCargo.toml, Cargo.lock, rust-toolchain.toml, crates/**, build.lua, buildl.toml, buildl.lock, .buildlignore, .buildl-version

The key only decides what is restored; buildl decides what is clean from its own action keys, so a restored older store is rebuilt where its inputs changed. The second pass must end with the two lines in the diagram, which buildl prints on stderr. buildl gc then drops what the current results no longer need, so the saved store does not grow. The cache is saved only on a miss, and only when the job passed.

After each release

The pin can name only a published release, so it moves after the release is out, in its own change: .buildl-version names the new version, and the build files change in the same change if the release needs it. The new pin is a cache miss, and the restore key never brings back a store another release wrote.