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.
| Layer | Lives in | May touch | Must not |
|---|---|---|---|
| Core flows | crates/buildl-core/tests/flows, with the fakes in common.rs | buildl-core's public API and the fakes | Lua, the file system, a process, a thread |
| Lua | crates/buildl-lua/tests/flows, with fixtures in crates/buildl-lua/tests/fixtures, and unit tests beside the code | real airsl; fixture build files, or files written into a temp workspace, turned into exact StagedFiles | anything of buildl |
| Adapter unit | crates/buildl/src/<module>/, beside the code | its own module, state, search_path, buildl-core, one temp directory; exec starts system tools | another adapter module; the process's current directory; setting an environment variable |
| End to end | crates/buildl/tests/e2e, with fixtures in crates/buildl/tests/fixtures | buildl's public API; a temp copy of a fixture | a private item; a path outside the package |
| CLI unit | crates/buildl/src/cli, beside the code | argument parsing, the exit mapping, terminal detection, a command's flow over byte buffers and a temp workspace | a process; a terminal |
| CLI binary | crates/buildl-cli/tests/cli | the built binary, with a chosen working directory and environment, its output piped | buildl 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.
| Port | Fake | What the test no longer needs |
|---|---|---|
DeclarationSource | FakeSource: a fixed build file, missing file or failed evaluation per directory; other files once the root is evaluated again or handed a discovery result | airsl, Lua |
Manifest | FakeManifest: one fixed workspace and ceiling | a buildl.toml |
Host | FakeHost: a fixed platform and fixed variables, some of which it can be told to fail on | the real environment |
Digester | FakeDigester: files held as bytes with their metadata, counting every call | a file system |
StatCache | FakeStatCache: in memory, counting commits | a file system |
ToolResolver | FakeTools: fixed fingerprints, recording every lookup | a PATH |
ContentStore and Sweep | FakeCas: 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 lose | a file system |
ActionCache | FakeCache: rows in memory, labels it can be told to fail on, and the labels it forgot | a file system |
EventLog and RunHistory | FakeLog, and FakeHistory for history alone: what was appended, and whether to fail | a file system |
ExecStrategy | FakeStrategy: 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 nothing | starting processes |
Dispatcher | FakeDispatcher: 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 result | threads; results are deterministic |
Clock | FakeClock: a counter, one tick per read | the wall clock |
GraphRecord | FakeGraphRecord: the graphs recorded, and whether to fail | a file system |
Reporter | FakeReporter: every call kept, in order | a terminal |
Approver | FakeApprover: one answer, given every time, and every set it was asked about with its attribution | a terminal, a data directory |
RemoteCache | FakeRemote: results in memory, every call kept in order; it can be told to fail any call, serve tampered bytes, or answer that an input changed | a 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 fakes | Proves |
|---|---|
//:a fails under --keep-going | the summary is 1 failed, 2 skipped, 2 built |
| the cas write succeeds, the cache write fails | there is no row for the target: crash safety |
| a rebuilt output is byte-identical | downstream targets stay clean: early cutoff |
| one input changed | the reason the target is dirty is the difference between its old and new KeyComponents |
the [execution] settings all change after a build | every target stays clean: none is part of a key |
| a wanted program outside the ceiling | Error::Refused before any strategy runs |
| a plugin's target wants what its plugin may not have | Error::PluginRefused, naming the plugin, before the ceiling is asked |
| the dispatcher loses a task | Error::DispatcherFault, naming every target left without an outcome |
| a build with a discovery target | the discovery target runs first, then what it declared; a second build is all cached |
| a target the fake remote holds | it ends Fetched, no strategy is called, and its row is written after its content |
| a remote call fails | lenient: one warning and the target runs; strict: the build fails |
In crates/buildl/tests/e2e, against real adapters | Proves |
|---|---|
| a fixture built in two directories, with four workers and with one | out/, cache.json, graph.json and the cas are byte-identical |
| a second build | every target cached; cache.json and graph.json unchanged |
out/ removed | every output put back without running, the executable bit kept |
| the states an interrupted build leaves | the next build finishes, trusts no blob without a row, and clears what was half done |
a corrupt cache.json | Error::CorruptState naming the file; check, graph and query still work |
| a target that reads a file it did not declare | it fails under sandbox and builds under bare |
the same chain under bare and under sandbox | out/ is byte-identical across the two |
verify over a target that writes its process id | that target is reported as mismatched, naming its output |
| a second checkout against the server a first build uploaded to | every 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:
| Target | Call | cargo runs |
|---|---|---|
buildl | rust.binary("buildl", …) on rust.package("buildl-cli") | cargo build --locked --bin buildl --profile dev --target-dir target -p buildl-cli |
cargo-buildl | rust.binary("cargo-buildl", …) on rust.package("buildl-cargo") | the same, for cargo-buildl and -p buildl-cargo |
tests | rust.test("tests", …) | cargo test --locked --profile dev --target-dir target --workspace --all-targets --all-features |
doctests | rust.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"]
| key | buildl-<os>-<pin>-<sha256 of rustc -vV>-<hash of the inputs> |
| restore key | buildl-<os>-<pin>-: the newest cache for the same OS and release |
| inputs hashed | Cargo.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.