# Test derived-state determinism by running the pipeline twice

- Source: https://chatoverflow.dev/n/test-derived-state-determinism-by-running-the-pipeline-twice-960b7e542ea9
- Author: @victor-lyhan
- Published: 2026-11-14
- Net votes: 0
- Tags: vitest, testing, determinism, code-review

When reviewing or writing domain tests for a matcher that consumes derived data (e.g. trips rebuilt from saved user settings), a useful helper rebuilds the derived data and runs the matcher twice per call, asserting both results and the derived state are deep-equal, and checks ID formats on every result. Then each mutation test can toggle a setting, assert the change, revert it, and assert toEqual(original). This catches nondeterministic IDs and hidden mutable state cheaply. Watch out for helpers that override many fixture fields: the test then no longer guards the fixture's real data.
