diff --git a/src/subpaths/throttle.ts b/src/subpaths/throttle.ts index d446f4b..2c6f18b 100644 Binary files a/src/subpaths/throttle.ts and b/src/subpaths/throttle.ts differ diff --git a/tests/52_throttle.test.ts b/tests/52_throttle.test.ts index 02ca18e..6dd683e 100644 --- a/tests/52_throttle.test.ts +++ b/tests/52_throttle.test.ts @@ -90,6 +90,19 @@ describe("throttle (M4.7)", () => { expect(metaOf(logs[1]).repeated).toBe(1); }); + test("different nested dates pass through while equal timestamps collapse", () => { + const clock = fakeClock(); + const { logger, logs } = createTestLogger(); + logger.use(throttle({ windowMs: 1000, now: clock.now })); + + logger.info({ at: new Date(1234) }, "completed"); + logger.info({ at: new Date(1234) }, "completed"); + logger.info({ at: new Date(5678) }, "completed"); + + expect(logs).toHaveLength(2); + expect(metaOf(logs[1]).repeated).toBe(1); + }); + test("off by default — no throttle middleware means no effect", () => { const { logger, logs } = createTestLogger(); @@ -239,6 +252,15 @@ describe("throttle (M4.7)", () => { expect(keyFor({ x: null })).not.toBe(keyFor({ x: 0 })); }); + test("dates inside nested arrays retain their timestamp and type", () => { + const key = keyFor({ nested: [new Date(1234)] }); + expect(key).toBe(keyFor({ nested: [new Date(1234)] })); + expect(key).not.toBe(keyFor({ nested: [new Date(5678)] })); + expect(key).not.toBe(keyFor({ nested: [1234] })); + expect(key).not.toBe(keyFor({ nested: ["d:1234"] })); + expect(key).not.toBe(keyFor({ nested: [{}] })); + }); + test("depth beyond the cap collapses to an ellipsis placeholder", () => { // Build a chain 8 levels deep; past depth 6 the digest stops recursing and emits "…". const deep = (n: number): unknown => (n === 0 ? "leaf" : { next: deep(n - 1) });