Part II — Intermediate Development · Chapter 10 · Lesson 6 of 6 · 9 min read
Chapter 10 Checkpoint: Production-Grade Test Suite
Checkpoint level: Intermediate
Purpose: Integrate native tests, filtering, coverage baselines, fixtures, determinism, boundary cases, differential and fuzz testing, conformance, and performance gates into one release-ready test suite for the Chapter 9 order-discount project.
Release note: commands and syntax in this checkpoint are illustrative. Verify every command, option, and output format against the installed v0.63 release before relying on it.
Checkpoint outcomes
By completing this checkpoint, you will demonstrate that you can:
- organize unit, boundary, property, differential, conformance, and performance tests into clearly named layers;
- build deterministic fixtures and builders that keep tests short and independent;
- cover every reason code and every exact threshold of the order-discount rules;
- compare interpreter and VM behavior on the same inputs;
- generate seeded fuzz inputs and preserve failures as regression tests;
- define coverage and performance baselines with explicit tolerances;
- combine all gates into one repeatable local and CI command sequence; and
- explain what each test layer proves and what it cannot prove.
Project scenario: Release gate for the order-discount rules
The Chapter 9 business-rules project calculates a discount decision from a customer tier and a quantity. Its stable reason codes are GOLD_BULK, GOLD, BULK, NONE, and VALIDATION_ERROR, and the bulk threshold is 10. A team now wants a single test suite that must pass before the rules module may be released.
You will not change the business rules. You will build the evidence that proves they behave correctly, deterministically, equivalently across engines, and within an agreed performance budget. All data is synthetic.
10C.1 Required inputs and outputs
The suite exercises the pure rules function with these inputs and expects these outputs:
| Item | Type | Contract |
|---|---|---|
| tier | string | "standard" or "gold"; any other value is a validation error |
| quantity | integer | Zero or greater; negative or non-integer values are validation errors |
| decision.reason | string | One of the five stable reason codes |
| decision.percent | number | The discount percentage for the matching rule, or 0 when none applies |
| decision.ok | boolean | False only for VALIDATION_ERROR |
The suite itself must also report a pass or fail status, a count of executed tests, a coverage figure, an instruction-count measurement for the performance gate, and an engine-comparison result.
10C.2 Implementation constraints
- Use only synthetic data and no secrets.
- Keep tests independent: no test may rely on another test having run first.
- Use fixed seeds for every generated input and print the seed on failure.
- Do not read the clock, random sources, or the network inside a test.
- Keep fixtures and builders in a separate test-support module.
- Use the instruction count, not wall-clock time, as the primary performance measure.
- Do not weaken a threshold or delete a test to make a gate pass.
10C.3 Acceptance criteria
- Every reason code is produced by at least one test and asserted by name.
- Every threshold is tested below, at, and above its boundary.
- Invalid tiers and invalid quantities each have their own test.
- The suite passes with a fixed seed three times in a row with identical results.
- Interpreter and VM results match for every case and every generated input.
- Coverage meets or exceeds the recorded baseline for the rules module.
- The instruction count stays within the recorded budget and tolerance.
- A deliberately injected defect is caught by at least two different layers.
- The local and CI command sequences are documented and use the same checks.
10C.4 Suite layout
order_rules/
src/
rules.pea
tests/
support/
builders.pea
fixtures.pea
unit_test.pea
boundary_test.pea
property_test.pea
differential_test.pea
conformance_test.pea
perf_test.pea
baselines/
coverage.json
perf.json
Each layer answers a different question. Unit tests ask whether named examples behave as documented. Boundary tests ask whether each edge sits on the correct side. Property tests ask whether invariants hold across many generated inputs. Differential tests ask whether engines agree. Conformance tests ask whether the published contract is honored. Performance tests ask whether cost has stayed within budget.
10C.5 Reference implementation: support and unit layers
Attempt the suite independently before comparing it with this reference. The builder keeps each test focused on the one field it varies.
# tests/support/builders.pea
function order(tier, quantity) {
return {"tier": tier, "quantity": quantity}
}
function gold(quantity) { return order("gold", quantity) }
function standard(quantity) { return order("standard", quantity) }
The unit layer asserts named examples, one reason code per test:
# tests/unit_test.pea
test "gold bulk order" {
let d = decide(gold(10))
expect d.reason == "GOLD_BULK"
expect d.ok == true
}
test "gold below bulk" {
expect decide(gold(9)).reason == "GOLD"
}
test "standard bulk order" {
expect decide(standard(10)).reason == "BULK"
}
test "standard below bulk" {
expect decide(standard(9)).reason == "NONE"
}
test "unknown tier is rejected" {
let d = decide(order("platinum", 5))
expect d.reason == "VALIDATION_ERROR"
expect d.ok == false
}
test "negative quantity is rejected" {
expect decide(gold(-1)).reason == "VALIDATION_ERROR"
}
The test and expect forms above follow the native syntax introduced in Lesson 1 of this chapter. Confirm the exact keywords against the installed release.
10C.6 Reference implementation: boundary and property layers
The boundary layer tests every threshold below, at, and above its edge. The property layer states invariants that must hold for every generated input.
# tests/boundary_test.pea
const cases = [
["standard", 0, "NONE"],
["standard", 9, "NONE"],
["standard", 10, "BULK"],
["standard", 11, "BULK"],
["gold", 0, "GOLD"],
["gold", 9, "GOLD"],
["gold", 10, "GOLD_BULK"],
["gold", 11, "GOLD_BULK"]
]
for c in cases {
test "boundary {c[0]} {c[1]}" {
expect decide(order(c[0], c[1])).reason == c[2]
}
}
# tests/property_test.pea
const seed = 20260101
test "reason is always a known code" {
let rng = seeded(seed)
for i in range(0, 200) {
let d = decide(order(pick(rng, ["standard", "gold", "bogus"]), int_in(rng, -5, 50)))
expect d.reason in KNOWN_REASONS
}
}
test "ok is false only for validation errors" {
let rng = seeded(seed)
for i in range(0, 200) {
let d = decide(order(pick(rng, ["standard", "gold"]), int_in(rng, -5, 50)))
expect (d.ok == false) == (d.reason == "VALIDATION_ERROR")
}
}
test "gold never receives less than standard" {
let rng = seeded(seed)
for i in range(0, 200) {
let q = int_in(rng, 0, 50)
expect decide(gold(q)).percent >= decide(standard(q)).percent
}
}
Each property prints its seed when it fails, so the exact generated input can be reproduced and then promoted to a named regression test.
10C.7 Reference implementation: differential, conformance, and performance layers
# tests/differential_test.pea
test "interpreter and VM agree" {
let rng = seeded(seed)
for i in range(0, 100) {
let o = order(pick(rng, ["standard", "gold"]), int_in(rng, 0, 50))
expect run_interpreter(o) == run_vm(o)
}
}
# tests/conformance_test.pea
test "decision shape is stable" {
let d = decide(gold(10))
expect keys(d) == ["ok", "percent", "reason"]
}
# tests/perf_test.pea
test "decision stays within instruction budget" {
let used = measure_instructions(function() { decide(gold(10)) })
expect used <= baseline.instructions * (1 + baseline.tolerance)
}
Helper names such as seeded, pick, int_in, run_interpreter, run_vm, and measure_instructions are teaching placeholders. Implement them with the facilities available in your installed release or in your own support module.
10C.8 Required test matrix
| Case | Tier | Quantity | Expected reason | Layer |
|---|---|---|---|---|
| A | standard | 0 | NONE | Boundary |
| B | standard | 9 | NONE | Boundary |
| C | standard | 10 | BULK | Boundary |
| D | standard | 11 | BULK | Boundary |
| E | gold | 0 | GOLD | Boundary |
| F | gold | 9 | GOLD | Boundary |
| G | gold | 10 | GOLD_BULK | Boundary |
| H | gold | 11 | GOLD_BULK | Boundary |
| I | platinum | 5 | VALIDATION_ERROR | Unit |
| J | gold | -1 | VALIDATION_ERROR | Unit |
| K | standard | 2.5 | VALIDATION_ERROR | Unit |
Cases A–H cover every valid reason code on both sides of the bulk threshold. Cases I–K cover each invalid-input path. The property, differential, and performance layers add many more generated cases on top of these named ones.
10C.9 Validation workflow
Run the gates in order from cheapest to most expensive, and stop at the first failure so the signal stays clear:
pea fmt --check .
pea check .
pea test
pea test --filter boundary
pea test --coverage
pea test --filter differential
pea test --filter perf
Format and static checks must pass before any test runs.
The full suite must pass with the fixed seed, then pass again on a second and third run with identical results.
Coverage must meet the recorded baseline for the rules module.
Differential tests must report zero engine disagreements.
The performance test must stay within the recorded budget and tolerance.
Record the command, exit status, and result of every step in the evidence table.
10C.10 Baselines
| Baseline | Recorded value | Tolerance | Rule for changing it |
|---|---|---|---|
| Coverage of rules.pea | Value from the first green run | No decrease | Raise only after adding tests; never lower to pass |
| Instruction count for decide(gold(10)) | Value from the first green run | Small agreed percentage | Update only with a reviewed explanation of the cause |
| Seed | 20260101 | None | Change only to add exploration, never to hide a failure |
Record baseline values from an actual run on your installed release. This book does not supply numbers, because they depend on the release and platform.
10C.11 Debugging requirement: inject and detect a defect
Introduce one temporary defect in the rules module, such as changing the bulk comparison from >= to >. Run the whole suite and record which layers fail.
- The boundary layer should fail for cases C and G.
- The unit layer should fail for the bulk examples.
- The property layer may fail, depending on the generated values.
- The differential layer should still pass, because both engines run the same defective source.
The last point is the lesson: differential testing finds engine disagreement, not wrong business logic. Restore the correct operator, rerun the full suite, and confirm a clean pass. Then add a regression test for any failure that your original suite did not catch.
10C.12 Reproducing a fuzz failure
Suppose a seeded property run fails. Follow this sequence:
- Copy the printed seed and the failing generated input.
- Rerun with the same seed and confirm the failure repeats.
- Reduce the input to the smallest case that still fails.
- Add that case to the boundary or unit layer under a descriptive name.
- Fix the cause and confirm the new named test passes.
- Keep the property test so it continues to explore nearby inputs.
10C.13 Submission package
- the complete tests directory in canonical formatting;
- a test-results table covering cases A through K;
- evidence of three identical seeded runs;
- the coverage report and the recorded baseline;
- the instruction-count measurement and budget;
- the differential-testing result;
- a defect-injection note listing which layers failed and why;
- a regression test for any gap the injected defect exposed; and
- a short description of the local and CI command sequences.
10C.14 Assessment rubric
| Area | Evidence of mastery |
|---|---|
| Coverage of rules | Every reason code and validation path is asserted by name. |
| Boundary testing | Each threshold is tested below, at, and above its edge. |
| Determinism | Seeds are fixed, printed, and three runs match. |
| Fixture design | Builders keep tests short, independent, and readable. |
| Differential testing | Engine agreement is checked on named and generated inputs. |
| Performance gating | Instruction counts use a recorded baseline and tolerance. |
| Defect detection | An injected defect is detected and explained by layer. |
| Automation | Local and CI sequences use the same checks in the same order. |
| Honesty about limits | The learner can state what each layer cannot prove. |
Completion standard: Every named case passes, every gate is green with recorded evidence, the injected defect is caught and explained, and the learner can justify each baseline and tolerance.
10C.15 Reflection questions
- Which layer caught the injected defect first, and why?
- Why did the differential layer not detect the wrong comparison operator?
- What makes a fixture or builder safe to share across tests?
- Why is instruction count a better primary gate than elapsed time?
- When is it acceptable to change a baseline, and who should approve it?
- Which risks does this suite still leave uncovered?
10C.16 Optional extensions
- Add a new tier and extend every layer, recording which tests had to change.
- Add a mutation exercise: apply several small defects in turn and measure how many the suite detects.
- Add a conformance test that reads a published contract table and checks each row.
- Add a scaling test that measures instruction growth as batch size increases.
- Write a short release checklist that references each gate by name.
Chapter 10 summary
You can now write native tests, select and watch them, track coverage, build deterministic fixtures, test boundaries, compare engines, generate seeded fuzz inputs, check conformance, and gate performance. The checkpoint combined these into one layered, repeatable suite whose evidence supports a release decision.
Transition to Chapter 11
Chapter 11 turns from one project to many. The next lesson covers pea.toml manifests and semantic-version constraints, showing how a project declares its identity, its dependencies, and the version ranges it will accept, so that the suite you built here can run against reproducible inputs.
Checkpoint status: Ready for review.