From a7b8281a16ef751e663adebd57f0abc2eb1ae670 Mon Sep 17 00:00:00 2001 From: Jack Lau <72348727+jackulau@users.noreply.github.com> Date: Mon, 17 Aug 2026 22:22:28 -0500 Subject: [PATCH] test(desktop): pin the clock in the session-row timestamp test The sidebar row's Tip trigger test derives its fixture from the wall clock: const startedAt = Math.floor(Date.now() / 1000) - 5 * 60 ... expect(age.getAttribute('aria-label')).toMatch(/^5m, Today at /) "Five minutes ago" is only today when the run does not straddle local midnight. Between 00:00 and 00:05 the timestamp falls into the previous day, formatMessageTimestamp correctly returns the yesterday label, and the test fails on a day boundary it was never written to exercise: AssertionError: expected '5m, Yesterday at 11:56 PM' to match /^5m, Today at / This is a real CI failure, not a theoretical one - it took down a check:test:ui shard on an unrelated desktop PR at 00:01 UTC, and it will do so for any PR whose shard happens to land in that five-minute window. Pin the clock to local noon before deriving the timestamp so the fixture can never cross a day boundary. Only Date is faked (toFake: ['Date']), so the component's own timers - the running arc and the tooltip open delay - keep running for real; the neighbouring tooltip tests that advance timers are unaffected. The describe block gains the useRealTimers teardown its sibling already had. The production formatter is not changed: rendering "Yesterday at 11:56 PM" for a session started five minutes before midnight is correct, and the assertion is about the label's composition, not about which day it names. --- .../src/app/chat/sidebar/session-row.test.tsx | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/apps/desktop/src/app/chat/sidebar/session-row.test.tsx b/apps/desktop/src/app/chat/sidebar/session-row.test.tsx index bfbb0f77c9..932a8070c9 100644 --- a/apps/desktop/src/app/chat/sidebar/session-row.test.tsx +++ b/apps/desktop/src/app/chat/sidebar/session-row.test.tsx @@ -231,6 +231,10 @@ describe('SidebarSessionRow running arc', () => { }) describe('SidebarSessionRow', () => { + afterEach(() => { + vi.useRealTimers() + }) + it('keeps an aria-label on the kebab without wrapping it in a Tip', () => { render( { }) it('exposes the exact session time through a focusable Tip trigger', () => { + // Pin the clock before deriving the timestamp. The assertion below is + // about the *composition* of the label (relative age + absolute time), + // but "5 minutes ago" only falls on today when the run does not straddle + // local midnight. Between 00:00 and 00:05 the row correctly renders + // "Yesterday at 11:5x PM" and this test failed for a day boundary it was + // never written to exercise. Only `Date` is faked, so the component's + // own timers (the running arc, the tooltip open delay) keep running for + // real. + vi.useFakeTimers({ toFake: ['Date'] }) + vi.setSystemTime(new Date(2026, 2, 5, 12, 0, 0)) + const startedAt = Math.floor(Date.now() / 1000) - 5 * 60 render(