test(server): unit-test task-analytics aggregations + Pro-Max usage window (#273 follow-up) #290
No reviewers
Labels
No labels
area:agents
area:dashboard
area:database
area:design
area:design-review
area:flows
area:infra
area:meta
area:security
area:sessions
area:webhook
area:workdir
security
type:bug
type:chore
type:meta
type:user-story
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
charles/claude-hooks!290
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "test/s11-task-analytics"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
PR #273 s11 extraction follow-up. Covers
task-analytics.ts.Coverage (18 tests)
computeStats(7) — empty-table zeros, 6-row rollup with all terminal statuses, 7d/all window bounds, by_agent averages, by_repo DESC sort, by_day ASC + force_merge, agent+repo filter narrowingcomputeUsage(6) — Wed→Monday step-back, Sunday 23:59 UTC step-back-6-days (not forward), day window 24h span + midnight anchor, all→since=epoch/reset_at=null, token bucket rollup with NULL-as-0, by_agent tokens-desc ranking withsinceexclusionhasRecentDispatch(2) — window boundary in/out, (repo, issue_number) keyinglistZeroOutputSuccesses(3) — picks turns=0/NULL/cost=NULL, ignores non-success statuses, respects window + newest-first orderBehaviour notes worth knowing
computeStatswindow boundary usesfinished_at BETWEEN fromMs AND toMs(both inclusive). Pinned.success_ratedenom only countssuccess + failure—cancelled,interrupted,cost_cappedexcluded. One-success-only windows return 1.0 by design (operator-abort shouldn't skew the score).(dayOfWeek + 6) % 7steps BACK — Sunday steps back 6 days, not forward 1. Dedicated Sunday edge test.finished_at(>= fromMsonly) — deliberate per comment (future-clock-skew rows still count). No equivalentBETWEENtocomputeStats.hasRecentDispatchkeys onstarted_at > since(strict). Tests use clearly-in vs clearly-out fixtures.listZeroOutputSuccessesOR-condition(turns = 0 OR turns IS NULL OR cost_usd IS NULL)— three separate fixture rows cover each disjunct plus a combined dedup assertion.Checks
bunx tsc --noEmit -p apps/server/tsconfig.json— EXIT=0bun test apps/server/src/domain/analytics/task-analytics.test.ts— 18/18 pass