Repository navigation
feat!: redesign LSpec v3 as a Bool-based, parallel-first, formally verified test framework - #94
Merged
Merged
Conversation
…rified test framework
Full breaking redesign of LSpec (v3.0.0) addressing import-time execution overhead and parallel test scalability observed in large consumers such as Ix, backed by a zero-sorry Lean formalization of the test runner enforced in CI:
1. **Zero import-time overhead & lazy test execution**
- Replace Prop/Testable/Decidable assertions with Bool- and AssertM-based expectations (expect, shouldBe, shouldNotBe, shouldSatisfy, shouldBeLt/Le/Gt/Ge, shouldContain, shouldThrow, shouldReturn, expectSome/Ok/Err, pending/xit) with compile-time source locations via a meta-only pos% macro (zero runtime Lean compiler dependency).
- Define AssertM as a nominal single-field structure (erased to IO (Except AssertStop α) at runtime) so do-notation cleanly lifts polymorphic IO actions such as IO.ofExcept and scoped resource getters.
- Defer every leaf test (it, itBool, prop, propWith) under a Unit thunk inside SpecM (StateT (Array TestTree) BaseIO) and declare DSL macros using non-reserved symbols (&"...") so downstream identifiers like prop/it are never shadowed; regular `def mySuite : Spec := do ...` functions work for both top-level and parameterized suites with zero import-time test execution (and test libraries with heavy closed pure expressions can set `-Dcompiler.extract_closed=false` to prevent closed-term hoisting).
- Drop #lspec, SlimCheck, and the plausible dependency so LSpec has zero external dependencies.
2. **Bounded-thread parallel execution with controlled memory usage**
- Introduce a nest-core-inspired TestTree IR, IsTest typeclass, pluggable TestProcessor pipeline (Processors.list, Processors.console), and Hspec-style SpecM DSL (describe, context, it, prop, parallel, sequential, withTag/withTags, withOptions, withResource/beforeAll, beforeEach/afterEach/aroundEach).
- Compile filtered trees into a shared pure ExecPlan IR consumed by both sequential and parallel execution paths, using ExecutionMode.combine so nested parallel scopes inside sequential remain strictly sequential.
- Implement a fixed-size WorkerPool (Std.Mutex + Std.Condvar + Std.Queue) parameterized by RunConfig.threads / CLI -j N / --threads N so CI jobs can bound concurrent memory usage while maximizing wall-clock speed.
- Drop completed test closures immediately upon completion, isolate per-test stdout/stderr via IO.FS.withIsolatedStreams, catch uncaught IO.Error per test, skip acquiring filtered-out resources, and avoid acquiring withResource after --fail-fast triggers.
3. **Deterministic, thread-safe Bool property testing**
- Add pure SplitMix64 Gen/Rng, fuel-bounded Shrinkable, Sampleable, FormatValue, arbitrary-arity PropTestable, precondition guards (==>), and forAll/forAllShrink/forAllNamed.
- Derive deterministic per-test seeds from (masterSeed, testPath) and always report seeds so failures are 100% reproducible across sequential and parallel runs.
4. **Formally verified runner (`LSpecProofs`, zero `sorry`, zero consumer overhead)**
- Convert all pure runner functions in LSpec.Runner (TestFilter.matchesTest, filterTree, listTests, ReportTree.leaves/leafCount/failures/summarize, compilePlan, computeWorkerCount) from partial to total with kernel-checked termination proofs.
- Provide an opt-in LSpecProofs library (excluded from defaultTargets so downstream consumers incur zero build or runtime overhead) proving:
- **Filtering & resource pruning (`LSpecProofs.Filter`)**: direct proofs on the executable runner that filtering is sound and complete with respect to listTests, idempotent, obeys exclusion precedence, and prunes empty scopes so filtered-out withResource blocks never survive to execute.
- **Reporting & deterministic planning (`LSpecProofs.Report`)**: direct proofs of exact pass/fail/skip accounting (total = leafCount, failed = failures.size, allPassed ↔ failures.isEmpty), permutation invariance of summary counts across arbitrary parallel completion orders, compilePlan equivalence with listTests, mode-independent deterministic per-test seed assignment, fail-fast skip accounting, and worker pool size bounds.
- **Parallel scheduler & resource safety (`LSpecProofs.Concurrency`)**: small-step operational semantics of the bounded WorkerPool and ExecPlan scheduler proving bounded concurrency (activeWorkers ≤ cap on every reachable trace), sequential exclusion and strict left-to-right ordering, withResource acquire/release bracket safety (no child executes before acquire; no release before all children finish; exact-once release on completion), deadlock freedom (including arbitrarily nested resources at cap = 1) and termination with an exact step bound, and sequential–parallel confluence (every parallel execution produces the identical ReportTree and RunSummary as sequential execution).
- **Compile-time axiom gate (`LSpecProofs.Axioms`)**: #guard_msgs in #print axioms checks on all 31 headline theorems compiled with -DwarningAsError=true, ensuring only Lean's standard axioms (propext, Quot.sound, Classical.choice) are used—never sorryAx or custom axioms.
5. **CI, tests, examples, and documentation**
- Remove all legacy v2 modules (LSpec/LSpec.lean, LSpec/Instances.lean, LSpec/Plausible.lean, LSpec/SlimCheck/, Examples/Testing.lean).
- Place internal self-tests under LSpecTests/ (LSpecTests/Main.lean, LSpecTests/ImportCheck.lean) so LSpec's build directory never collides with downstream consumers' Tests.* modules on LEAN_PATH, and update Examples/Examples.lean and README.md.
- Enforce LSpecProofs in both CI jobs (.github/workflows/ci.yml Lean job via lake build LSpecProofs --wfail and Nix job via checks.proofs in flake.nix).
- Verified with lake build --wfail, lake build LSpecProofs --wfail, lake test (35/35), lake exe tests -j 4 (35/35), Examples/Examples.lean, nix flake check (checks.tests & checks.proofs), and end-to-end migration of Ix (55/55 primary suites passing; --list 18.89s -> 6.93s; full suite 380.82s -> 157.43s at -j 4, 116.30s at -j 8, 101.22s at -j 16).
johnchandlerburnham
approved these changes
Nov 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Full breaking redesign of LSpec (v3.0.0) addressing import-time execution overhead and parallel test scalability observed in large consumers such as Ix, backed by a zero-sorry Lean formalization of the test runner enforced in CI:
Zero import-time overhead & lazy test execution
Bounded-thread parallel execution with controlled memory usage
Deterministic, thread-safe Bool property testing
Formally verified runner (
LSpecProofs, zerosorry, zero consumer overhead)LSpecProofs.Filter): direct proofs on the executable runner that filtering is sound and complete with respect to listTests, idempotent, obeys exclusion precedence, and prunes empty scopes so filtered-out withResource blocks never survive to execute.LSpecProofs.Report): direct proofs of exact pass/fail/skip accounting (total = leafCount, failed = failures.size, allPassed ↔ failures.isEmpty), permutation invariance of summary counts across arbitrary parallel completion orders, compilePlan equivalence with listTests, mode-independent deterministic per-test seed assignment, fail-fast skip accounting, and worker pool size bounds. - Parallel scheduler & resource safety (LSpecProofs.Concurrency): small-step operational semantics of the bounded WorkerPool and ExecPlan scheduler proving bounded concurrency (activeWorkers ≤ cap on every reachable trace), sequential exclusion and strict left-to-right ordering, withResource acquire/release bracket safety (no child executes before acquire; no release before all children finish; exact-once release on completion), deadlock freedom (including arbitrarily nested resources at cap = 1) and termination with an exact step bound, and sequential–parallel confluence (every parallel execution produces the identical ReportTree and RunSummary as sequential execution). - Compile-time axiom gate (LSpecProofs.Axioms): #guard_msgs in #print axioms checks on all 31 headline theorems compiled with -DwarningAsError=true, ensuring only Lean's standard axioms (propext, Quot.sound, Classical.choice) are used—never sorryAx or custom axioms.CI, tests, examples, and documentation