Skip to content

Add unit coverage for use-activity - #877

Merged
selfcontained merged 1 commit into
mainfrom
agt_2fd045d59344/job-test-enforcer-99dd63e1
Aug 5, 2026
Merged

Add unit coverage for use-activity#877
selfcontained merged 1 commit into
mainfrom
agt_2fd045d59344/job-test-enforcer-99dd63e1

Conversation

@selfcontained

Copy link
Copy Markdown
Owner

Summary

The activity hooks (apps/web/src/hooks/use-activity.ts) power the entire activity/stats pane but had zero direct test coverage. This adds use-activity.test.tsx (27 tests) covering the pure range logic and the query-hook wiring, closing the last item of the 2026-07-31 ranked web coverage queue.

What is pinned

  • getRangeBounds, all five ranges: explicit daily date → local midnight through next local midnight; daily end lands on the next calendar midnight across a DST transition (2026-03-08), not start+24h; the default daily date is derived from the UTC date but parsed as local midnight (documented product quirk, pinned at an instant where the two disagree west of UTC); year starts at local Jan 1; 7d/30d are exact rolling epoch windows; all-time returns empty bounds.
  • Granularity mapping through real request URLs: daily→hour, 7d/30d→day, year/all→month.
  • Query-param construction: ambient tz always sent; start/end omitted entirely for all-time; useActiveHours sends raw bounds with no granularity param (distinct from the other endpoints).
  • Payload unwrapping: heatmap→days, token-by-model→models, token-by-project / working-time-by-project→projects; four passthrough endpoints return the payload as-is.
  • Query behavior: cache keyed per range + dailyDate; refetchOnMount: "always" refetches on remount while fresh.

All timezone assertions are written relative to the ambient zone (the module captures LOCAL_TZ at import), verified to hold in both America/Denver and UTC.

Validation

  • 11/11 targeted mutant battery killed (granularity halves, dailyDate ignored, DST end bound, UTC-midnight year start, off-by-one window, bounds leaking into all-time, unconditional start param, un-unwrapped payload, granularity leaking into active-hours, hardcoded heatmap window, hardcoded tz).
  • One review-agent round: 0 must-fix; 2 should-fix applied (exact ISO oracle for the daily-default test, explicit error in the calledUrl helper), 1 nit applied (dropped unnecessary casts).
  • pnpm run check, full unit suite (server 2394 / web 617 / ext 60 / scripts 4), pnpm run finalize:web, inert E2E 175 passed / 12 skipped, live lane 11 passed — all green.

🤖 Generated with Claude Code

Cover the activity hooks' pure range logic and query wiring, which had
no direct tests: getRangeBounds for all five ranges (including the
DST-transition daily end bound and the UTC-derived default daily date
parsed as local midnight), rangeLabel, the range-to-granularity
mapping, tz/start/end query-param construction with empty bounds
omitted for all-time, payload unwrapping for the heatmap and token/
project endpoints, the useActiveHours raw-bounds request (no
granularity param) feeding buildActiveHours, per-range cache keys, and
refetch-on-remount behavior.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@selfcontained
selfcontained merged commit e863c46 into main Aug 5, 2026
1 check passed
@selfcontained
selfcontained deleted the agt_2fd045d59344/job-test-enforcer-99dd63e1 branch August 5, 2026 02:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant