test(insights): bracket the snapshot window floor with the call's own clock

The floor reads Date.now() inside buildComparisonSnapshotForUser, so it
lands in [before - 400d, after - 400d] relative to the test's brackets.
The prior upper bound used before - 400d, which fails when a millisecond
ticks between the bracket read and the snapshot's clock read.
This commit is contained in:
Marc-André Bombeck committed 2026-06-26 09:44:35 +02:00
1 parent cd6fff9730
commit 5e701cebc0
1 file changed
+5 -4
@@ -76,11 +76,12 @@ describe("buildComparisonSnapshotForUser — bounded read window", () => {
expect(measuredAt).toBeDefined();
expect(measuredAt.gte).toBeInstanceOf(Date);
// The floor is anchored on Date.now() - 400 days (allow scheduling
// slack between the snapshot's clock read and the test's bracket).
// The floor is anchored on Date.now() - 400 days, read inside the call.
// Since before <= snapshotNow <= after, the floor brackets exactly to
// [before - 400d, after - 400d] — no tick-timing slack assumptions.
const gteMs = measuredAt.gte.getTime();
expect(gteMs).toBeLessThanOrEqual(before - 400 * DAY);
expect(gteMs).toBeGreaterThanOrEqual(after - 401 * DAY);
expect(gteMs).toBeGreaterThanOrEqual(before - 400 * DAY);
expect(gteMs).toBeLessThanOrEqual(after - 400 * DAY);
}
});