DEV Community

Finley Sun
Finley Sun

Posted on

Run the Property on Both Trees, Then Trust the Patch

Illustrative scenario, not a reported incident: a patch renames a usage field and changes how a unit is carried. It updates the serializer, the fixtures, and three assertions. The suite is green. Nobody can say whether the unit stayed attached to the quantity. The FOCUS 1.2 resource-usage specification is the official source for that invariant: consumed quantity is related to its unit of measure and the resource or SKU, and the unit should stay attached before comparing quantities or looking up cost. See resource usage.

That gap is the target. A green suite after a patch is one data point. It cannot separate 'the code is correct' from 'the checks got weaker.'

Prerequisites and assumptions

You need four things before this comparison is meaningful. A deterministic entry point you can call from a test. A fixture tree under version control, so edits are visible. A seed you can replay. Two checkouts: pre-patch and post-patch.

If any of those is missing, stop. Property checks on a nondeterministic harness produce noise, not evidence.

Pin the properties before you read the diff

Write the invariants first. Read the diff second. Reversing that order invites properties shaped to pass.

A property is a statement about a set of inputs. It is not one expected output. 'Sum of line items equals the invoice total' is a property. 'Invoice 4471 totals 1299' is a fixture.

For the resource-usage example, keep the list short and boring:

  • every usage record has a non-empty unit of measure;
  • two usage quantities are compared only after normalization to the same unit;
  • the resource or SKU identifier remains attached to each usage figure.

Three properties you trust beat thirty you skim.

Use an observation-based test

Inputs: a small fixture set of usage records, a base checkout, a patched checkout, and a fixed seed. Observation: run the same property list against both checkouts and record the seed, the pass or fail outcome, and the first failing input. Mismatch interpretation: if the base passes and the patched tree fails, inspect whether the patch changed unit handling or whether the property was legitimately invalidated. If both pass, you have no evidence of change; the patch may still be wrong. If the base fails and the patched tree passes, confirm that the baseline failure was real. If both fail, quarantine the property or the environment.

A documented error case is not evidence that a different success path is correct. Check each proposed outcome against the source you are relying on.

Compare both trees with the same seed

Set up two checkouts at the base revision and the patched revision. Use the same property list and the same seed in both. Record the seed and the outcome. The comparison carries meaning only when those are held constant.

Read the four cells

Two runs produce four outcomes. Each one reads differently.

baseline patched reading
pass pass no evidence of change; the patch may still be wrong
pass fail likely regression, or a property the patch legitimately invalidates
fail pass the patch fixes something; confirm the baseline failure was real
fail fail the property or environment is broken; quarantine it

Only the middle two rows carry signal. Rows one and four quietly consume review time.

Budget the fixture diff

Count changed files under the fixture directory. Set the number before review, not after. A patch touching more fixtures than production files deserves a slower read.

The budget prompts attention. It is not a gate. A rename legitimately touches many fixtures. A rename plus a changed expected total does not.

Freeze the flaky ones

A property that flips on the same tree with the same seed is not evidence. Quarantine it and write down why. Do not let it count toward the pass total.

Freezing is not fixing. It buys a trustworthy signal while the property gets repaired.

Check the harness, not just the patch

You can verify that the property set actually bites. Break one invariant on purpose in a scratch tree. If the harness stays green, the property is decorative.

Treat that as a proposed check. Run it on a throwaway branch, never on the review branch.

Failure modes worth naming

Tautological properties. The assertion restates the implementation. If the property mirrors the code line for line, it tests nothing.

Seed monoculture. One seed replayed forever. It passes, and the input space stays unexplored.

Fixture edits that redefine the property. The patch moves the data and the assertion together. The diff looks small while the meaning shifts.

Environment drift between trees. Different dependency versions, different results. Pin the environment or the comparison is void.

Time and ordering. Wall clocks and iteration order make properties nondeterministic. Inject a clock and sort before comparing.

When this is the wrong tool

Small mechanical diffs rarely justify two-tree runs. Properties that need production data cannot run in a scratch checkout. Latency and throughput properties need load harnesses, not assertions.

For everything else, the two-tree comparison is cheap. It turns a green check into a claim you can defend.


AI assistance disclosure: this draft was written with AI assistance. The checks above are proposed and were not executed. A human should verify them against the target repository and current DEV policy before publishing.

This article was created with AI assistance.

Top comments (0)