vps-health-api/__tests__
le king fu 9084d90609 feat(server): archive closed Claude usage days by month, serve them on /claude-usage/history
POST /claude-usage now merges every day of the sanitized snapshot except
the last one (today, still open) into <dir of CLAUDE_USAGE_PATH>/history/
YYYY-MM.json, after the snapshot itself is written. The latest snapshot
wins, so a day leaving the 30-day window keeps the value the agent froze
at D+2. Each month file is written atomically (same-dir temp, mode 600,
rename). A month file that cannot be read back is never overwritten, and
an archive failure is logged (months and error codes only) without
changing the 204.

GET /claude-usage/history?from=YYYY-MM&to=YYYY-MM (read token) serves the
archived days, defaulting to the 12 months up to the last archived month,
400 on a bad format, from > to or a span over 36 months. Month files are
re-read through the snapshot's per-day whitelist, now exported from
claude-usage.js as sanitizeDay().

The new module also carries the one-shot import command used by the
backfill (`node claude-usage-history.js --import <file|->`), where an
already archived date always wins.

Refs #55

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-08 20:41:30 -04:00
..
fixtures/claude-usage feat(agent): add the claude-usage agent: plan limits, local cache, push 2026-10-04 15:26:15 -04:00
agent-claude-usage.test.js test(agent): pin ENOENT as a read error below the root, note the subagent-copy limit 2026-10-07 20:53:27 -04:00
agent.test.js feat(agent): push workstation metrics to /hosts/<id> from cron 2026-08-16 12:21:59 -04:00
auth.test.js feat(server): archive closed Claude usage days by month, serve them on /claude-usage/history 2026-10-08 20:41:30 -04:00
ci.test.js feat(server): archive closed Claude usage days by month, serve them on /claude-usage/history 2026-10-08 20:41:30 -04:00
claude-usage-history.test.js feat(server): archive closed Claude usage days by month, serve them on /claude-usage/history 2026-10-08 20:41:30 -04:00
claude-usage.test.js feat(server): archive closed Claude usage days by month, serve them on /claude-usage/history 2026-10-08 20:41:30 -04:00
findings.test.js feat(defenseurs): add GET /defenseurs/findings?project=X route 2026-05-12 20:56:56 -04:00
health.test.js refactor: extract CPU/RAM/disk collection into metrics.js 2026-08-16 11:30:03 -04:00
hosts.test.js fix(server): require a full ISO receivedAt on read, cover the temp-file cleanup 2026-10-07 20:25:26 -04:00
state.test.js feat(defenseurs): serve the Sergent's findings state at GET /defenseurs/state 2026-09-24 20:42:20 -04:00
writes.test.js feat(server): archive closed Claude usage days by month, serve them on /claude-usage/history 2026-10-08 20:41:30 -04:00