test(desktop): pin the clock in the session-row timestamp test - #88876
Open
jackulau wants to merge 1 commit into
Open
test(desktop): pin the clock in the session-row timestamp test#88876jackulau wants to merge 1 commit into
jackulau wants to merge 1 commit into
Conversation
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.
19 tasks
Contributor
Nice flake fix with an unusual degree of care for a test-only change: No blocking issues found. — reviewer-a · automated agent review (Hermes week-review) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Removes a time-of-day flake from
session-row.test.tsxthat fails CI for any PR whosecheck:test:uishard happens to run within five minutes of local midnight.The test derives its fixture from the wall clock:
"Five minutes ago" is only today when the run does not straddle a day boundary. Between
00:00 and 00:05 local,
startedAtlands in the previous day,formatMessageTimestampcorrectly returns the
yesterdaylabel, and the assertion fails:This is not theoretical. It took down
JS & TS checks / apps/desktop / check:test:ui:shard-2of3at 00:01 UTC on an unrelated desktop PR of mine
(run 32082698353),
in a shard where the other 1401 tests passed. Every PR that lands in that window pays for it,
and because the window is five minutes wide the failure looks random rather than reproducible.
The production formatter is not changed, deliberately. Rendering "Yesterday at 11:56 PM"
for a session started five minutes before midnight is the correct thing to do, and the
assertion is about the composition of the label (relative age plus absolute time), not about
which day it names. The bug is that the test hard-codes one side of a boundary it never meant
to test.
The fix pins the clock to local noon before deriving the timestamp. Only
Dateis faked(
toFake: ['Date']) so the component's own timers, the running arc and the tooltip opendelay, keep running for real; the neighbouring tooltip tests that call
vi.advanceTimersByTimeare untouched. The
describeblock gains theuseRealTimersteardown its sibling blockalready had, so a pinned clock cannot leak into a later test.
Local noon rather than a UTC instant is deliberate: the offset is applied by the runner's own
timezone, so
new Date(2026, 2, 5, 12, 0, 0)is midday in whatever zone CI runs in, and fiveminutes earlier is the same day everywhere.
Related Issue
No issue: found by reading the CI failure on one of my own PRs. Happy to file one first if
maintainers prefer that for flakes.
Fixes #
Type of Change
Changes Made
apps/desktop/src/app/chat/sidebar/session-row.test.tsx: pin the clock withvi.useFakeTimers({ toFake: ['Date'] })plusvi.setSystemTime(...)before derivingstartedAtinexposes the exact session time through a focusable Tip trigger, and add avi.useRealTimers()teardown to the enclosingdescribe. A comment records why theboundary matters, so the pin is not mistaken for ceremony and removed later.
How to Test
The test passes as written:
Test Files 1 passed · Tests 11 passed (11)Proof the pin is what makes it deterministic. Move the pinned instant into the failing
window, changing
new Date(2026, 2, 5, 12, 0, 0)tonew Date(2026, 2, 5, 0, 2, 0), andre-run:
That is the CI failure reproduced exactly, on demand, from a clock offset alone: same
assertion, same message shape, only the minute differs. Restore noon and all 11 pass again.
This also demonstrates the test still genuinely exercises the label: it is pinned, not
loosened.
npx eslint src/app/chat/sidebar/session-row.test.tsxis clean.npx tsc -p . --noEmitexits 0.Checklist
Code
fix(scope):,feat(scope):, etc.)pytest tests/ -qand all tests pass. N/A here, this is a TypeScript-only change; the affected vitest file is run above and the whole shard is exercised by CIDocumentation & Housekeeping
docs/, docstrings). The comment in the test explains the boundary; no user-facing docs affectedDateconstructor rather than a UTC instant precisely so it is timezone-independent, which is what makes it correct on every runnerScreenshots / Logs
The CI failure this removes, from
run 32082698353
at 00:02 UTC:
The same failure, reproduced locally on demand by moving the pin into the window: