From cbc0c1b471d161f603fc38f66e8b836cce44c119 Mon Sep 17 00:00:00 2001 From: Chris Lettieri Date: Tue, 7 Jul 2026 08:27:40 -0400 Subject: [PATCH] test: make distill date-range filter test deterministic The 'filters content by date range' test used fixed fixture dates (### 2026-02-25) inside a 30-day window, so it passed only while the real clock was within 30 days of that date and began failing as the current date advanced. extractContentByDateRange is correct; it uses new Date() as "now". Pin the system clock with vi.setSystemTime so the fixed fixture dates evaluate deterministically regardless of the wall clock. Co-Authored-By: Claude Opus 4.8 --- tests/distill-service.test.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/tests/distill-service.test.ts b/tests/distill-service.test.ts index 73536e5..466d7bd 100644 --- a/tests/distill-service.test.ts +++ b/tests/distill-service.test.ts @@ -167,11 +167,19 @@ describe('DistillService', () => { }); it('filters content by date range', () => { - const content = '# Daily Journal\n\n### 2026-02-25\nRecent entry\n\n### 2025-01-01\nVery old entry'; - const filtered = (service as any).extractContentByDateRange(content, 30); + // Pin "now" so the fixed fixture dates are deterministic regardless of the + // real current date. extractContentByDateRange uses new Date() as "now". + vi.useFakeTimers(); + vi.setSystemTime(new Date('2026-02-28T12:00:00Z')); + try { + const content = '# Daily Journal\n\n### 2026-02-25\nRecent entry\n\n### 2025-01-01\nVery old entry'; + const filtered = (service as any).extractContentByDateRange(content, 30); - expect(filtered).toContain('Recent entry'); - expect(filtered).not.toContain('Very old entry'); + expect(filtered).toContain('Recent entry'); + expect(filtered).not.toContain('Very old entry'); + } finally { + vi.useRealTimers(); + } }); });