One clock for the whole API, injected and overridden once #426

Closed
opened 2026-10-15 14:45:38 +00:00 by root · 7 comments
root commented 2026-10-15 14:45:38 +00:00 (Migrated from gitlab.core-project.space)

Parent

#421

What to build

The whole app runs on one clock, so Rooms, Sessions, Games and rate limits agree on the time, and a test sets the time once.

  • One clock token, defined in common/, defaulting to Date.now, provided once by the root.
  • Every service that reads the time injects it in place of its own now option: Room, Play, Auth, password reset, Games and the rate limiter.
  • The Room and Play services still take the clock directly when the Room fixtures build them by hand.
  • The profiles test, which today runs a moving Room clock beside a fixed Account clock "so no Session expires mid-test", keeps its Session alive on the shared clock. It does so by refreshing, or by moving forward in steps shorter than the access-token lifetime.

Seam: S1, the wire; S2, the Room through its services.

Acceptance criteria

  • No service takes a now option. Each reads the shared clock.
  • A new integration test overrides the clock once and shows a Room's timestamps and a Session's expiry following the same time.
  • The profiles test passes on one clock without asserting anything new.
  • Every other API test passes, changed only in how it sets the time.
## Parent #421 ## What to build The whole app runs on one clock, so Rooms, Sessions, Games and rate limits agree on the time, and a test sets the time once. - One clock token, defined in `common/`, defaulting to `Date.now`, provided once by the root. - Every service that reads the time injects it in place of its own `now` option: Room, Play, Auth, password reset, Games and the rate limiter. - The Room and Play services still take the clock directly when the Room fixtures build them by hand. - The profiles test, which today runs a moving Room clock beside a fixed Account clock "so no Session expires mid-test", keeps its Session alive on the shared clock. It does so by refreshing, or by moving forward in steps shorter than the access-token lifetime. Seam: S1, the wire; S2, the Room through its services. ## Acceptance criteria - [ ] No service takes a `now` option. Each reads the shared clock. - [ ] A new integration test overrides the clock once and shows a Room's timestamps and a Session's expiry following the same time. - [ ] The profiles test passes on one clock without asserting anything new. - [ ] Every other API test passes, changed only in how it sets the time.
root commented 2026-10-15 14:45:48 +00:00 (Migrated from gitlab.core-project.space)

mentioned in issue #428

mentioned in issue #428
root commented 2026-10-15 14:46:08 +00:00 (Migrated from gitlab.core-project.space)

marked this issue as related to #421

marked this issue as related to #421
root commented 2026-10-15 14:46:24 +00:00 (Migrated from gitlab.core-project.space)

marked this issue as related to #425

marked this issue as related to #425
root commented 2026-10-15 14:46:27 +00:00 (Migrated from gitlab.core-project.space)

marked this issue as related to #428

marked this issue as related to #428
root commented 2026-10-15 16:04:32 +00:00 (Migrated from gitlab.core-project.space)

mentioned in commit 02b96bea61

mentioned in commit 02b96bea6155a6d80a624ad014957e1e102aeba6
root commented 2026-10-15 16:04:47 +00:00 (Migrated from gitlab.core-project.space)

mentioned in merge request !536

mentioned in merge request !536
root commented 2026-10-15 16:07:36 +00:00 (Migrated from gitlab.core-project.space)

mentioned in commit 122fc4ff87

mentioned in commit 122fc4ff87ae04454283e2673589b521eac14b60
root (Migrated from gitlab.core-project.space) closed this issue 2026-10-15 19:01:50 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
amaurycoudr/chess-project#426
No description provided.