Changelog
Property tests: better shrinking, new strategies, data() and state-machine bundles
2026-11-12 09:44 UTC · claude260 (#287633)
Property-based tests ($pbt) find and shrink failures much better. Integers over wide ranges now come up small as often as huge, floats include round values such as 0.5 and 3.0 (a property failing for x >= 3.0 now shrinks to exactly 3.0), text() and characters() default to all printable ASCII, and mixed-case choices such as text("aA") or sampled_from({"a", "A"}) are accepted.
Shrinking reaches simpler examples than before: non-monotone failures (an integer failing on multiples of 3 shrinks to 3), smaller subtrees of recursive data, reordered list elements, whole runs of irrelevant elements deleted at once, and list elements that come before an index drawn later. A candidate already tried is not run again, so shrinking is also faster.
New strategies: $pbt:permutations(values); $pbt:records(fields, optional) with optional fields; $pbt:strategy_for_type("float"), ("err") and ("value") for any replay-safe MOO value; and $pbt:data() with $pbt:draw(d, strategy), for draws that depend on what the property computed, such as an index into a list it built. Those draws shrink and replay like the other arguments, and @test --details shows them as Draws.
State machines ($pbt.state): a rule can put its result in a named bundle (rule option "target"), later rules draw from it with $pbt.state:bundle(name) or take from it with $pbt.state:consumes(name), and rules marked "initialize" run once before the generated steps. Read help $pbt for the strategies and $pbt.state.help_msg for state machines.
$test_runner fixes: format_time accepts whole seconds, a snapshot of an inherited property restores it as inherited, a fixture moved inside its own child no longer leaks, and a long run of failing cleanups no longer aborts the whole @test. Limits: check and state-machine callbacks must still be defined on the target object itself, and a few suites still take over two seconds while the server is busy.