Nondeterministic Golden Cases Quietly Poison Your Evals

2026-12-03来源 dev.toEnglish

A golden file is useful only when its expected differences mean something. If the contract permits the order of an unordered collection to vary, a byte-for-byte golden can turn a harmless permutation into a regression. If the contract requires sorting by priority, applying the exact same normalization can hide a real defect.

Pick one case and run a pinned reference implementation against the same input several times with the relevant environment and seed policy recorded. Inspect the differences before normalizing them. Equality across that finite sample means no variation was observed in the sample; it cannot prove determinism. Preserve a sanitized trace of the raw discrepancy when needed, subject to the same data-retention limits as other test artifacts.

Give each normalization rule a counterexample

Suppose the output is an array of labels with order unspecified but duplicates meaningful. Sorting both arrays before comparing them should accept [red, blue] versus [blue, red]. It should still reject [red, red, blue] versus [red, blue]. Converting to a set would let the second pair pass and silently change the contract.

A timestamp generated by the program might be compared using a controlled clock rather than removed from every fixture. Floating-point tolerances need units, scale and a reason; stripping digits until a flaky case goes green can hide an error near a decision boundary. For ordered results, a difference in position may be exactly what the test needs to reveal.

Version the normalization rule with the checker. Run both an allowed variation and a deliberately wrong control after every change to it. If variation cannot yet be classified, mark that case separately and keep it out of release decisions that assume exact reproducibility. A stable suite with an over-permissive comparator is no better evidence than a noisy suite with a brittle one.

Test the comparator in both directions

Use two fixtures for the unordered-label contract: a reordered sequence that should pass, and the same sequence with one duplicate removed that should fail. Add an ordered-priority fixture with the first two entries swapped; it should fail under its own comparator. Store all three expected results with the rule version. If the same normalizer accepts every fixture, it has erased behavior the suite is meant to protect.

This article was created with AI assistance.

原文:https://www.a8q9.cn/en/article/nondeterministic-golden-cases-quietly-poison-your-evals-55dafb.html

相关文章