Test Flakiness Analysis Report β micr-dev/tokens
Executive Summary
| Metric |
Value |
| Total test files |
12 |
| Test framework |
Node.js built-in node:test |
| Overall flakiness risk |
π‘ Medium |
| Files with flaky patterns |
5 of 12 |
| Critical flakiness (P0-P1) |
3 findings |
Flakiness Findings
π΄ P1 β High Risk
1. Time-dependent date generation in cli.test.ts (lines 23-46)
Pattern: recentIso() and recentDate() generate dates relative to new Date() at test runtime.
function recentIso(daysAgo = 0) {
const date = new Date();
date.setUTCDate(date.getUTCDate() - daysAgo);
return date.toISOString();
}
Risk: Tests crossing midnight UTC (or local midnight for recentDate) may generate unexpected date values. recentDate uses local time while the CLI may use UTC β this mismatch causes date-boundary failures.
Fix: Use fixed ISO date strings instead of runtime-relative dates.
2. Environment variable mutation without test isolation (droid.test.ts, gemini.test.ts, helios.test.ts, hermes.test.ts, pi.test.ts)
Pattern: Multiple test files mutate process.env and restore in t.after():
const originalHome = process.env.HOME;
t.after(() => { process.env.HOME = originalHome; });
process.env.HOME = workspace;
Risk: If two tests run concurrently and both mutate process.env.HOME, one test's env mutation leaks into the other. The cleanup may not execute before the next test starts.
Severity: P1 β Works now with sequential execution, but any future parallelism will break.
Fix: Use unique env var names per test, or enforce --test-concurrency=1.
π‘ P2 β Medium Risk
3. cli.test.ts spawns child processes β non-deterministic timing (line 16)
Risk: CLI tests spawn actual child processes. Under high system load, tests asserting on CLI output may timeout or receive partial output.
Fix: Increase timeouts for CLI integration tests.
4. SQLite-backed tests skip on Bun (helios.test.ts line 9, hermes.test.ts line 9)
const skipSqliteBackedTest = Boolean(process.versions.bun);
const sqliteBackedTest = skipSqliteBackedTest ? test.skip : test;
Risk: Tests silently skip on Bun instead of failing. Masks real regressions.
Fix: Log a warning when SQLite tests are skipped.
5. droid.test.ts β Potential env leak between HOME and provider-specific env vars
Risk: If test runner ever runs tests concurrently, env mutations break.
Fix: Use provider-specific env vars explicitly.
π’ P3 β Low Risk
6. File system temp directory collisions β stale slopmeter-* dirs from crashed runs
7. cli.test.ts fixture dates use recentIso() β not deterministic across days
8. t3-chat.test.ts β Provider merge order assertion is brittle but intentional
Files with No Flaky Patterns
| File |
Status |
packages/cli/test/export.test.ts |
β
Clean |
packages/cli/test/graph.test.ts |
β
Clean |
packages/web/test/analytics.test.ts |
β
Clean |
packages/web/test/usage.test.ts |
β
Clean |
packages/web/test/publish-usage.test.ts |
β
Clean |
Recommended Fixes (Prioritized)
- P1-1: Replace
recentIso()/recentDate() with fixed date constants
- P1-2: Document or enforce serial test execution for env-mutating tests
- P2-3: Add generous timeouts (30s+) for CLI spawn tests
- P2-4: Log warning when SQLite tests are skipped on Bun
- P3-6: Add periodic cleanup of stale temp dirs
Test Flakiness Analysis Report β
micr-dev/tokensExecutive Summary
node:testFlakiness Findings
π΄ P1 β High Risk
1. Time-dependent date generation in
cli.test.ts(lines 23-46)Pattern:
recentIso()andrecentDate()generate dates relative tonew Date()at test runtime.Risk: Tests crossing midnight UTC (or local midnight for
recentDate) may generate unexpected date values.recentDateuses local time while the CLI may use UTC β this mismatch causes date-boundary failures.Fix: Use fixed ISO date strings instead of runtime-relative dates.
2. Environment variable mutation without test isolation (
droid.test.ts,gemini.test.ts,helios.test.ts,hermes.test.ts,pi.test.ts)Pattern: Multiple test files mutate
process.envand restore int.after():Risk: If two tests run concurrently and both mutate
process.env.HOME, one test's env mutation leaks into the other. The cleanup may not execute before the next test starts.Severity: P1 β Works now with sequential execution, but any future parallelism will break.
Fix: Use unique env var names per test, or enforce
--test-concurrency=1.π‘ P2 β Medium Risk
3.
cli.test.tsspawns child processes β non-deterministic timing (line 16)Risk: CLI tests spawn actual child processes. Under high system load, tests asserting on CLI output may timeout or receive partial output.
Fix: Increase timeouts for CLI integration tests.
4. SQLite-backed tests skip on Bun (
helios.test.tsline 9,hermes.test.tsline 9)Risk: Tests silently skip on Bun instead of failing. Masks real regressions.
Fix: Log a warning when SQLite tests are skipped.
5.
droid.test.tsβ Potential env leak between HOME and provider-specific env varsRisk: If test runner ever runs tests concurrently, env mutations break.
Fix: Use provider-specific env vars explicitly.
π’ P3 β Low Risk
6. File system temp directory collisions β stale
slopmeter-*dirs from crashed runs7.
cli.test.tsfixture dates userecentIso()β not deterministic across days8.
t3-chat.test.tsβ Provider merge order assertion is brittle but intentionalFiles with No Flaky Patterns
packages/cli/test/export.test.tspackages/cli/test/graph.test.tspackages/web/test/analytics.test.tspackages/web/test/usage.test.tspackages/web/test/publish-usage.test.tsRecommended Fixes (Prioritized)
recentIso()/recentDate()with fixed date constants