pg_durable icon indicating copy to clipboard operation
pg_durable copied to clipboard

Fix for Issue #232: generative + invariant-driven DSL testing (Phases 1-6)

Open crprashant opened this issue 5 months ago • 0 comments

Implements the full six-phase roadmap from #232 — moving DSL coverage from hand-written E2E tests to generative + invariant-driven testing. Each phase is independently shippable; all six are included here (Phase 1 as a documented slice — see Deferred below).

What's in this PR

Phase Deliverable Status
6 docs/dsl-semantics.md — one-page operational-semantics contract for every combinator under nesting ✅
1 df.assert_structural_invariants(instance_id, fail_on_violation) post-run oracle (6 pure-state invariants) + tests/e2e/sql/24_structural_invariants.sql ✅ (slice)
2 tests/e2e/generated/ combinator-nesting matrix generator — depth-2 exhaustive: 154 shapes (128 live / 26 quarantined) — plus CI wiring ✅
4 Metamorphic-relations registry (7 issue-#232 equivalences) in the same generator crate ✅
3 proptest::Strategy random-tree generator with shrinking (model-level, over the reference interpreter) + failure corpus + nightly job ✅
5 Synchronous tree-walking reference interpreter (pomset / causal-order oracle) + live causal-order assertions emitted into every clean generated test ✅

Highlights

  • Phase 1 is a sound post-run snapshot checker (reachable-completed, join-all-completed, untaken-if-pending, race-one-completed, join-name-disjoint, query-json-wellformed). New src/db.rs node loader; loop-scope relaxations keep it false-positive-free. Packaged as extension 0.2.4 with upgrade script sql/pg_durable--0.2.3--0.2.4.sql.
  • Phase 2 is a standalone std-only crate (no pgrx/duroxide dep) that enumerates nestings → renders live SQL E2E tests with marker leaves → asserts the Phase 1 oracle + per-path counts. A classifier splits clean shapes (blocking) from the known loop-bug zone (quarantined / xfail, non-blocking).
  • Phase 5 adds the causal-order dimension the count-based oracles can't see: for every happens-before (≺) edge the reference interpreter predicts, the generated SQL asserts the earlier marker's wall_clock precedes the later one; concurrent siblings carry no edge (no flakiness). The order oracle is fail-closed — a missing trace endpoint is a violation, never silently dropped.

Validation

  • cargo fmt / cargo clippy -D warnings clean; 196 extension unit tests + the generator's own unit tests pass.
  • Live ./scripts/test-e2e-local.sh --include-generated: 169 passed / 0 failed (128 generated + 7 metamorphic shapes exercise the new causal-order block with zero false positives).
  • Each phase was put through a multi-specialist review; triage records live under the testing dir.

Deferred (documented, per the issue's acceptance criteria)

The two count-based invariants that would directly catch #227 (single_execution_outside_loop) and #230 (loop_body_iteration_count_matches) are deferred: df.nodes.status is current-state (in-place UPDATE), not an append-only trace, so iteration/execution counts need a new df.node_events log (or duroxide-history integration). The generated matrix (Phases 2–5) already catches that same class differentially via the df_gen_trace marker table today; the standalone oracle slice ships exactly the invariants that are checkable from df.nodes alone.

New defect surfaced (bug-as-seed)

Per the issue's "treat every reported bug as a generator seed" recommendation, the Phase 2 matrix surfaced a new runtime-boundary defect — a loop nested inside a join/race branch (the inverse of #230; root cause: continue_as_new is host-context-unaware) — filed as #233. A blast-radius experiment found it is not a cluster DoS (parked hangs ~0 CPU, no pool/connection exhaustion); the harms are permanently-stuck instances + silent over-execution.

Implements all six phases of #232; maintainers to decide on closing the umbrella given the documented Phase 1 deferral.

crprashant avatar Jun 14 '26 04:06 crprashant