From 3a8591a8af5b6d200088d12ca75a5517cb064fa8 Mon Sep 17 00:00:00 2001 From: can1357 Date: Thu, 6 Aug 2026 14:48:57 +0200 Subject: [PATCH] test: hardened two ci-flaky timing tests - mnemopi provider parity 'diagnose, validate, graph' does ~6.7s of real work under bun --parallel=8 on loaded runners; raised its per-test timeout to 30s (default 5s flaked twice in three CI runs). - utils LRUCache updateAgeOnGet drove a 30ms TTL with real 20ms sleeps (10ms margin); now drives performance.now() via a mocked clock, so the contract is asserted deterministically with no wall-clock wait. --- .../test/provider-all-15-tools-parity.test.ts | 2 +- packages/utils/test/lru.test.ts | 29 ++++++++++++------- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/packages/mnemopi/test/provider-all-15-tools-parity.test.ts b/packages/mnemopi/test/provider-all-15-tools-parity.test.ts index 7f85a733e..019c73b38 100644 --- a/packages/mnemopi/test/provider-all-15-tools-parity.test.ts +++ b/packages/mnemopi/test/provider-all-15-tools-parity.test.ts @@ -172,5 +172,5 @@ describe("provider all-tools parity", () => { }); expect(shared.status).toBe("stored_shared"); expect((await handleToolCall("mnemopi_shared_forget", { memory_id: shared.memory_id })).status).toBe("deleted"); - }); + }, 30_000); }); diff --git a/packages/utils/test/lru.test.ts b/packages/utils/test/lru.test.ts index 5b5317537..663ad3487 100644 --- a/packages/utils/test/lru.test.ts +++ b/packages/utils/test/lru.test.ts @@ -1,4 +1,4 @@ -import { describe, expect, test } from "bun:test"; +import { describe, expect, test, vi } from "bun:test"; import { LRUCache } from "../src/lru"; describe("LRUCache", () => { @@ -86,15 +86,22 @@ describe("LRUCache", () => { }); }); - test("matches updateAgeOnGet", async () => { - const cache = new LRUCache({ max: 2, ttl: 30, updateAgeOnGet: true }); - cache.set("a", 1); - // Integration against the cache's performance-based clock requires real elapsed time. - await Bun.sleep(20); - expect(cache.get("a")).toBe(1); - await Bun.sleep(20); - expect(cache.has("a")).toBe(true); - await Bun.sleep(20); - expect(cache.has("a")).toBe(false); + test("matches updateAgeOnGet", () => { + // Drive the cache's performance.now() clock deterministically — the real + // clock version (30ms TTL, 20ms sleeps) raced CI load and flaked. + let now = 0; + const clock = vi.spyOn(performance, "now").mockImplementation(() => now); + try { + const cache = new LRUCache({ max: 2, ttl: 30, updateAgeOnGet: true }); + cache.set("a", 1); + now = 20; + expect(cache.get("a")).toBe(1); // refreshes the entry's age to t=20 + now = 40; + expect(cache.has("a")).toBe(true); // 20ms since refresh < 30ms TTL + now = 60; + expect(cache.has("a")).toBe(false); // 40ms since refresh > 30ms TTL + } finally { + clock.mockRestore(); + } }); });