Skip to content

The parity harness

The same engines exist twice, in two languages, and are never shared. How they are held together.

Source of recordsrc/engines/parity/parity.test.tssrc/engines/parity/dart-output.json

The score, simulation and decision engines exist twice: once in Dart on the phone, once in TypeScript on this site. They are never shared, and that is the deliberate part.

A shared engine — a package both sides import — couples a mobile release to a web deploy. Change a threshold and you have to ship two apps at once, forever, or accept that one of them is running last month's arithmetic without saying so.

So instead: two implementations, and a harness that fails the build when they disagree.

The three files

FileRepoRole
fixtures.jsonwebThe canonical corpus. Inputs only — no expected values.
parity_export_test.dartmobileRuns the fixtures through the real Dart engines and writes what they produced.
parity.test.tswebRuns the same fixtures through the TypeScript engines and asserts deep equality.

The expected values are never hand-written. They are whatever Dart actually produced, which means the harness cannot be satisfied by someone updating a number in a test file to match a change they just made.

Why the ported unit tests were not enough

Each engine was ported against the app's own test suite as its specification, and passed. That is necessary and not sufficient.

An assertion only pins the cases somebody thought to write. A port can be green against every one of them while disagreeing on the ninety cases nobody wrote a test for. The harness covers the corpus rather than the assertions.

The boundary fixtures are the load-bearing half

Every fixture named boundary * sits exactly on an engine constant, or one step off it: the band thresholds 1.0 / 0.7 / 0.4, the Building gates, the lean threshold ±3, the OS Health bands 40 / 70.

Running it

npm test

360 tests. If they go red after a change to the Dart engines, the harness is doing its job: either the port has drifted, or the change on the phone was not the change somebody intended.