Ensures the engine, timeline, and UI stay in sync as the project evolves.
| Layer | Purpose | Tooling |
|---|---|---|
| Unit | Verify individual modules (union-find wrapper, canonicalization, worklist). | Vitest |
| Contract | Compare naive vs deferred outputs for identical presets, including emitted timelines. | Vitest + snapshot fixtures |
| Visualization | Render panes against recorded timelines to ensure highlights/animations align. | Vitest DOM + Playwright (optional) |
| Preset validation | Ensure preset JSON follows schema and produces bounded timelines. | Zod schema + Vitest |
test/fixtures/presets/*.json: snapshot copies of shipping presets for regression tests.test/fixtures/timelines/{presetId}-{impl}.json: serialized arrays ofEGraphStatefor golden tests. Generated viapnpm test:update-fixturesscript.- Graphical screenshot tests (Playwright) store expected PNGs under
test/screenshots/.
- Engine Equivalence: For every fixture preset, run both naive and deferred engines; assert final canonical classes, node counts, and timeline lengths match.
- Invariant Checks: When debug mode enables
checkCongruence/checkHashcons, unit tests inject known-violating graphs and expect descriptive violation outputs. - Timeline Integrity:
- Snapshots must have strictly increasing
stepIndex. metadata.diffsmust only reference ids present in the same snapshot.- Structural sharing sanity: verifying
states[i] !== states[i-1]butstates[i].graph.nodes[j] === states[i-1].graph.nodes[j]whenever unchanged.
- Snapshots must have strictly increasing
- Controller Logic: Simulate playback store operations to ensure actions respect boundaries and that scrubbing yields deterministic indices.
- Preset Schema: Validate every preset JSON using the schema from
specs/egraph/PRESETS.md; unit tests fail if schema changes without fixture updates. - UI Rendering: Using Vitest DOM, render each pane with fixture snapshots to ensure empty/populated states match the spec (e.g., Worklist view shows “invariants restored” when empty).
pnpm test– runs unit + contract tests.pnpm test:fixtures– regenerates timeline snapshots (writes to fixtures; requires developer approval).pnpm test:ui– launches Playwright visual regression (optional).
- CI must run unit + contract suites on every push.
- Fixture updates need reviewer approval and must include textual summary in PR description.
- Large preset additions should include at least one new contract test to keep coverage broad.
Expose pnpm debug:timeline --preset <id> --impl deferred that prints step-by-step metadata to aid regressions. This command should reuse the same code paths as the app to prevent drift.
Keeping these requirements synchronized with specs/egraph/ and ./ARCHITECTURE.md ensures contributors know when they’re breaking guarantees.