OUT-3988: L0.4 — clock / determinism control toolkit - #122
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Greptile SummaryThis PR adds a test-only deterministic-time toolkit without changing production behavior.
Confidence Score: 5/5The PR appears safe to merge, with no concrete blocking or independently actionable non-blocking issue identified. The new utilities are confined to tests, cover the repository’s current JavaScript timer APIs, explicitly separate fake JavaScript time from real database time, and restore global timer state after unit tests. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart LR
T[Test case] -->|JS time behavior| F[useFakeClock]
F --> D[Fake Date.now and new Date]
F --> M[Advance fake timers]
M --> S[Resolve sleep without waiting]
T -->|PostgreSQL NOW behavior| O[Offset helpers]
O --> P[Seed timestamps relative to real time]
P --> Q[SQL boundary query]
T -->|Retry wait assertion| I[mockSleepInstant]
I --> A[Record duration and resolve immediately]
Reviews (1): Last reviewed commit: "test(OUT-3988): add two-world boundary e..." | Re-trigger Greptile |
priosshrsth
approved these changes
Aug 6, 2026
SandipBajracharya
force-pushed
the
OUT-3987
branch
from
August 7, 2026 08:08
9e4266c to
5f87ffe
Compare
Wraps vitest fake timers so a test can freeze/advance "now" with no real waiting. toFake is scoped to Date + timer fns (never nextTick/microtask) and advancing is async so pending sleep() calls flush. Adds a unit-only afterEach(vi.useRealTimers()) net so a forgotten restore can't leak. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Pure Date-math helpers (msAgo/secondsAgo/minutesAgo/hoursAgo/daysAgo/fromNow) off the live Date.now(). Value-agnostic so they work under a frozen clock (exact) and against real Postgres NOW() (for SQL-side boundary seeding). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
mockSleepInstant() swaps sleep() for an instant spy so a test can assert the intended wait (toHaveBeenCalledWith) with no delay. Clears call history since clearMocks is off in the unit project. Adds the test/time barrel. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Executable docs for the JS-world (frozen-clock debounce boundary) and SQL-world (offset-seed template, real assertion deferred to L2.3) usage. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
SandipBajracharya
force-pushed
the
OUT-3988
branch
from
August 7, 2026 08:12
18cab33 to
3ad402a
Compare
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.
L0.4 — Clock / determinism control
Test-only toolkit (
test/time/) so time-dependent code can be tested deterministically and fast, with zero production change. Foundation primitive consumed by the resync backoff-boundary tests (L2.3) and webhook debounce tests (L3.3).Linear: OUT-3988 · parent OUT-3984 · base branch:
OUT-3987The two-world model
Time is read in two places that need different tools:
sleep()/Date.now()/new Date()sleep(5000)useFakeClock/mockSleepInstant(no real waiting)NOW()5min × attemptsminutesAgo(6), …) — JS can't fake SQLNOW()What's here
useFakeClock(iso?)— freeze / advance / setNow / restore over vitest fake timers;toFakescoped to Date + timer fns (never nextTick/microtask); async advance sosleep()flushes.msAgo/secondsAgo/minutesAgo/hoursAgo/daysAgo/fromNow, value-agnostic pureDate-math.mockSleepInstant()— instant spy over@/utils/sleep; assert the intended wait with no delay.boundary-examples.test.ts— executable docs of the two-world usage.vitest.setup.ts— oneafterEach(vi.useRealTimers())safety net (unit project only).Verification
pnpm typecheckclean ·pnpm lintclean · full unit suite 164/164 (14 new).🤖 Generated with Claude Code