diff --git a/src/daemon/http/usage-summary.test.ts b/src/daemon/http/usage-summary.test.ts index 08af1a8..59f97df 100644 --- a/src/daemon/http/usage-summary.test.ts +++ b/src/daemon/http/usage-summary.test.ts @@ -2,7 +2,7 @@ import { describe, it, expect, beforeEach } from "bun:test"; import { createMemoryUsageTrackingDriver } from "@routstr/sdk/storage"; import type { UsageTrackingEntry } from "@routstr/sdk/storage"; import type { ClientEntry } from "../../utils/clients"; -import { getUsageSummary } from "./usage-summary"; +import { getUsageSummary, __resetUsageSummaryCacheForTest } from "./usage-summary"; // ─── Test fixtures ──────────────────────────────────────────────────────────── // @@ -116,8 +116,10 @@ describe("getUsageSummary", () => { let driver: ReturnType; beforeEach(async () => { - // Reset module-level cache between tests by creating a fresh driver with a - // distinct entry count each time — the cache key changes. + // Reset the module-level memo cache explicitly so each test starts cold. + // Without this, tests 2-10 would share the cached object from test 1 + // (all use the same fixtures → identical cache key → same TTL window). + __resetUsageSummaryCacheForTest(); driver = createMemoryUsageTrackingDriver(ENTRIES); }); diff --git a/src/daemon/http/usage-summary.ts b/src/daemon/http/usage-summary.ts index 5e164e6..a17460f 100644 --- a/src/daemon/http/usage-summary.ts +++ b/src/daemon/http/usage-summary.ts @@ -122,6 +122,11 @@ interface CacheEntry { let _cache: CacheEntry | null = null; const CACHE_TTL_MS = 60_000; +/** Clears the module-level memo cache. Intended for use in unit tests only. */ +export function __resetUsageSummaryCacheForTest(): void { + _cache = null; +} + // ─── Main builder ───────────────────────────────────────────────────────────── export async function getUsageSummary(