fix: refcount StatsCache keys, keep registrations across config change, and tidy GPU/usage render paths

This commit is contained in:
c4ch3c4d3
2026-08-14 13:04:56 -06:00
parent d04eb6b524
commit 21d2e45f9e
5 changed files with 75 additions and 48 deletions
+23
View File
@@ -83,3 +83,26 @@ test("fetch failure keeps the last-known value", async () => {
assert.equal(cache.get("a"), undefined);
cache.unregister("a");
});
test("ref-counted register: a sibling unregister keeps the key active", async () => {
const calls = { count: 0 };
const cache = new StatsCache(cfg, stubFetch({ totalRequests: 5, totalInputTokens: 1, totalOutputTokens: 1, genP95: 1 }, calls), 10000, 30);
cache.register("all");
cache.register("all");
cache.unregister("all");
await flush();
assert.equal(cache.get("all")!.totalRequests, 5);
assert.equal(calls.count, 1);
cache.unregister("all");
assert.equal(cache.get("all"), undefined);
});
test("setConfig keeps registrations but clears cached values", async () => {
const cache = new StatsCache(cfg, async (_c, key) => ({ totalRequests: 5, totalInputTokens: 1, totalOutputTokens: 1, genP95: 1 }), 10000, 30);
cache.register("all");
await flush();
assert.equal(cache.get("all")!.totalRequests, 5);
cache.setConfig({ baseUrl: "http://new" });
assert.equal(cache.get("all"), undefined);
cache.unregister("all");
});