Expand description
The sealed test world.
While a ## Test runs, a thread-local TestWorld intercepts the ambient
IO natives with SIMULATED resources that have real semantics: a virtual
clock frozen at a fixed epoch, an in-memory filesystem seeded by
Given a file …, an empty environment, and a per-test seeded RNG. There is
no unrecorded entropy API to misuse — a test is a pure function of
(program, seed). Capability sentences (This test may use the real filesystem.) opt individual resources back to reality under --live.
Zero cost outside tests: each native pays ONE thread-local check on an IO call (noise next to the syscall it guards); compute paths pay nothing.
Structs§
- Capabilities
- Which resources a test may touch FOR REAL (granted by capability sentences).
- Test
World - One test’s sealed world.
Constants§
- SEALED_
EPOCH_ MS - The sealed world’s fixed epoch: 2020-01-01T00:00:00Z in ms — a stable, obviously-synthetic date (no test can accidentally depend on today).
Functions§
- advance_
clock - Advance the virtual clock (
Advance time by …). Returns false when no world is installed (the caller reports the test-only error). - install
- Install a sealed world for the current thread (the runner, per test).
- intercept_
env_ get - intercept_
now - intercept_
random_ float - intercept_
random_ int - A uniform draw from
min..=maxoff the world’s seeded stream: a word at or above the largest multiple of the span is drawn again, so no value is likelier than another — the rule every real host’srandomIntdraws by. - intercept_
read - intercept_
sleep - A sealed
sleepadvances logical time INSTANTLY — the statement that turns a timeout test into a microsecond assertion. Returns true when handled. - intercept_
write - restore
- Put back a world a matching
takereturned (orNone, mirroring its absence). - seed_
file - Seed a fixture file (
Given a file "…" containing "…".). - take
- Take the installed world, if any, leaving none installed — a nested caller (a candidate page
tier compared against the reference) saves whatever world its caller had before installing its
own, and
restores it when it is done. - uninstall
- Remove the sealed world (the runner, after each test).
- with_
world - Run
fagainst the installed world, if any.