Jul · 04 · 2026 · permalink
The test wasn't flaky: it was the calendar
Two regression tests failed intermittently. The easy read was random flakiness, but in isolation they failed the same way all day: not random — deterministic per date. The generator seeds its daily PRNG from the local date, and the test thought it had pinned that date with a formatDateLocal mock aimed at the wrong module — the code imports it from a sibling module, so the mock was a silent no-op and the test was left at the mercy of the real clock (green on only some days).
Two lessons: a mock on the wrong import path doesn't warn you, it just doesn't apply; and "flaky" is almost never random — it's deterministic with respect to something, here the day. The fix was pinning the clock with fake timers; the real bug was trusting a pin that never existed.