Implement first-pass load reduction controls

This commit is contained in:
dirtydishes 2026-05-08 02:46:41 -04:00
parent 5d488fd7f5
commit e7f4805ccc
17 changed files with 1191 additions and 608 deletions

View file

@ -1,5 +1,5 @@
import { describe, expect, test } from "bun:test";
import { computeSnapshot, computeStats } from "../src/rolling-stats";
import { computeSnapshot, computeStats, RollingWindowStore } from "../src/rolling-stats";
describe("rolling stats helpers", () => {
test("computeStats handles empty baseline", () => {
@ -21,4 +21,18 @@ describe("rolling stats helpers", () => {
expect(snapshot.baselineCount).toBe(3);
expect(snapshot.zscore).toBeCloseTo(1.84, 2);
});
test("RollingWindowStore prunes stale keys by ttl", () => {
const store = new RollingWindowStore({
windowSize: 3,
ttlSeconds: 1,
flushIntervalMs: 30_000,
maxKeys: 10
});
store.update("rolling:premium:ABC", 10, 0);
expect(store.size).toBe(1);
expect(store.prune(1_500)).toBe(1);
expect(store.size).toBe(0);
});
});