Skip to content

test(usage-aggregator): fix timeout flake by building against an empty HOME#503

Merged
iamtoruk merged 1 commit into
mainfrom
test/usage-aggregator-hermetic
Jun 18, 2026
Merged

test(usage-aggregator): fix timeout flake by building against an empty HOME#503
iamtoruk merged 1 commit into
mainfrom
test/usage-aggregator-hermetic

Conversation

@iamtoruk

Copy link
Copy Markdown
Member

Problem

tests/usage-aggregator.test.ts calls buildMenubarPayloadForRange(getDateRange('today'), ...), which parses the developer's real on-disk session data for today against a fixed 5s timeout. On a heavy-usage day this exceeds the timeout and the test fails locally. It stays green on CI because CI has no real session data.

Fix

Point HOME, CLAUDE_CONFIG_DIR, XDG_CONFIG_HOME, and CODEBURN_CACHE_DIR at an empty temp dir for this test so the payload is built from an empty dataset. The test still asserts the payload shape and the optimize:false short-circuit, but now runs deterministically in ~0.3s (was timing out at 5s). Env is saved/restored in beforeAll/afterAll; vitest's default forks pool isolates the file in its own process, and the daily-cache test already uses the same env-override pattern.

Verification

  • The test passes in ~330ms across repeated runs (was a 5s timeout).
  • Full suite: the previously-failing usage-aggregator test now passes; no other test regressed (the env override is confined to this file).

…meout flake

buildMenubarPayloadForRange('today') parsed the developer's real on-disk
session data under a fixed 5s timeout, so on a heavy-usage day the test
timed out locally (it stayed green on CI, which has no real data). Point
HOME and the config dirs at an empty temp dir so the payload is built from
an empty dataset: deterministic and fast (~0.3s) while still asserting the
payload shape and the optimize:false short-circuit.
@iamtoruk iamtoruk merged commit a9c0273 into main Jun 18, 2026
3 checks passed
@iamtoruk iamtoruk deleted the test/usage-aggregator-hermetic branch June 18, 2026 10:50
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