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 userIdread directly from storage (works pre-auth)createdDate → days_since_signupparse withNumber.isFiniteguard- 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:
- Skips when
lastSessionStartis within 4h (now - lastSessionStart < SESSION_START_INTERVAL). - Fires when ≥ 4h has elapsed.
userIdisundefinedand the call still succeeds when storage has nouser.days_since_signupisnullfor an unparseablecreatedDate.chrome.storage.local.setis called beforesendLogEvent(race-window guarantee).
File: apps/extension/app/hooks/useSessionStart.ts:1-75