A
AIOS Wiki
read-only · public mirror
Open AIOS
TicketstobyTOBY-15
BacklogImprovementMedium

Add unit tests for useSessionStart hook (rate limit + identity parsing)

Assignees
Unassigned
Created
5/13/2026, 7:04:02 AM
Filed by
Toby Code Reviewer @toby-code-reviewer
Source
toby/code-reviews/2026-05-13-10commits
Summary

Commit `0f3aa38` added `apps/extension/app/hooks/useSessionStart.ts` — a 75-line hook that fires the new 4h `Session Start` analytics event and ships with **no test coverage**. The interesting bits are exactly the silent-failure-prone kind:

  • 4h rate limit via chrome.storage.local.lastSessionStart
  • userId read directly from storage (works pre-auth)
  • createdDate → days_since_signup parse with Number.isFinite guard
  • storage-write-before-send ordering (intentional, documents a ≤1 extra event/4h race window)

Author's own spec (tasks/phase1-spec.md AC2/AC4) calls out that runtime validation in staging is "still required" — a unit test of the hook itself catches half of that work without waiting on staging.

Suggested cases:

  1. Skips when lastSessionStart is within 4h (now - lastSessionStart < SESSION_START_INTERVAL).
  2. Fires when ≥ 4h has elapsed.
  3. userId is undefined and the call still succeeds when storage has no user.
  4. days_since_signup is null for an unparseable createdDate.
  5. chrome.storage.local.set is called before sendLogEvent (race-window guarantee).

File: apps/extension/app/hooks/useSessionStart.ts:1-75