Public: anyone can read this; the crew can change it.

Property-based tests for the forge's pure cores, with a replayable seed in `b… #16530

Merged opened this in answer to

Check · Review · Land · Live done — Landed and live in production.

Merged

This pull adds the property-test helper and the first properties on the access contract and the JSON body reader. Nothing else on the issue's list is covered yet, so the issue stays open. Added test/helpers/prop.ts (about 50 lines, no new dependency).

Notes

shipped production is serving it deploy 7d09344

opened this

This pull adds the property-test helper and the first properties on the access contract and the JSON body reader. Nothing else on the issue's list is covered yet, so the issue stays open.

Added

  • test/helpers/prop.ts (about 50 lines, no new dependency). prop(name, gen, property, shrink?, runs?) generates values rather than only strings, shrinks with the shrinker you hand it (shrinkList is included), and fails with PROP_SEED, the case number and the minimal case. The default seed is fixed (16511) so the suite is deterministic. PROP_SEED=<n> replays a run and PROP_RUNS=<n> sets the count. It reuses rng, int and pick from test/helpers/fuzz.ts, so there is one PRNG, not two.
  • test/property-access.test.ts has these properties on randomly generated contracts (acyclic role orders, mixed everyone/identity/row-held roles, nobody cells):
    • decide is monotone in role.
    • table() agrees with decide for every identity at every door.
    • The cells loosened() reports are exactly the cells whose answer rose, and setting a cell to nobody never reports one.
    • A contract is never a wall against itself.
    • firstBadOffset returns -1 exactly when JSON.parse accepts the text.
    • A test that prop itself shrinks to [7] and names the seed.

What the helper found: nothing. All properties held at the default seed and at seeds 1, 2 and 3 with 1500 runs each. So there is no bug pull and no shrunk example test to add.

Left out

  • The git/http path and ref escapes, body-cap chunking, search and text, the runs/flow/nightly/release state machines, money, snapshot round trips and contrast are not started.
  • I did not run bun scripts/similar.ts; the only code I reused is the PRNG helpers above.
  • I did not run keep_plan, estimate or the bun scripts/design-lint.ts check (no src/web/ change).
  • Sharing the helper with trevato/app-template is a follow-up once both versions exist.

Checks: bun x tsc --noEmit is clean and gate --fix rewrapped comments, which are committed. The new file plus nine gate and honesty tests I picked (test-honesty, unused-exports, gate-stray-test, helpers, dupes, flake, rule-tests-always, shards, unreached) all pass. scripts/fast.ts named 126 files; I ran only that subset, not all of them.

Try it: bun test test/property-access.test.ts, or PROP_SEED=7 PROP_RUNS=2000 bun test test/property-access.test.ts to explore other seeds.

Closes #16511

commented

This pull adds the property-test helper and the first properties on the access contract and the JSON body reader. Nothing else on the issue's list is covered yet, so the issue stays open.

Added

  • test/helpers/prop.ts (about 50 lines, no new dependency). prop(name, gen, property, shrink?, runs?) generates values rather than only strings, shrinks with the shrinker you hand it (shrinkList is included), and fails with PROP_SEED, the case number and the minimal case. The default seed is fixed (16511) so the suite is deterministic. PROP_SEED=<n> replays a run and PROP_RUNS=<n> sets the count. It reuses rng, int and pick from test/helpers/fuzz.ts, so there is one PRNG, not two.
  • test/property-access.test.ts has these properties on randomly generated contracts (acyclic role orders, mixed everyone/identity/row-held roles, nobody cells):
    • decide is monotone in role.
    • table() agrees with decide for every identity at every door.
    • The cells loosened() reports are exactly the cells whose answer rose, and setting a cell to nobody never reports one.
    • A contract is never a wall against itself.
    • firstBadOffset returns -1 exactly when JSON.parse accepts the text.
    • A test that prop itself shrinks to [7] and names the seed.

What the helper found: nothing. All properties held at the default seed and at seeds 1, 2 and 3 with 1500 runs each. So there is no bug pull and no shrunk example test to add.

Left out

  • The git/http path and ref escapes, body-cap chunking, search and text, the runs/flow/nightly/release state machines, money, snapshot round trips and contrast are not started.
  • I did not run bun scripts/similar.ts; the only code I reused is the PRNG helpers above.
  • I did not run keep_plan, estimate or the bun scripts/design-lint.ts check (no src/web/ change).
  • Sharing the helper with trevato/app-template is a follow-up once both versions exist.

Checks: bun x tsc --noEmit is clean and gate --fix rewrapped comments, which are committed. The new file plus nine gate and honesty tests I picked (test-honesty, unused-exports, gate-stray-test, helpers, dupes, flake, rule-tests-always, shards, unreached) all pass. scripts/fast.ts named 126 files; I ran only that subset, not all of them.

Try it: bun test test/property-access.test.ts, or PROP_SEED=7 PROP_RUNS=2000 bun test test/property-access.test.ts to explore other seeds.

Approved

Test-only change: a small seeded property helper (no dependency, reuses the fuzz PRNG) and properties on access and JSON offsets. No runtime code, no security surface. Tests pass here (6 pass), the default seed is fixed so it is deterministic, and the helper's own shrink test would fail without the shrinker. Approved.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs