From a93be4285d040c2918b61a31db4d36cf84d92668 Mon Sep 17 00:00:00 2001 From: Miguel Angel Simon Sierra Date: Wed, 9 Sep 2026 20:22:03 -0400 Subject: [PATCH] test(engine): keep the probe cache bound test off the filesystem The eviction test wrote, stat'ed and deleted 129 temp files to exercise an in-memory LRU rule. Its runtime tracked filesystem contention rather than the code under test, and on a busy Windows runner the file churn alone pushed a ~300ms test past the 5s timeout, failing unrelated pull requests. Cache identity comes from stat, so the test now synthesises stat results and never touches disk. While here, the test also asserts the LRU touch: re-probing an entry before the bound is hit must keep it resident and evict the next-oldest one instead. The previous shape never hit the cache during the fill, so that branch was untested. --- packages/engine/src/utils/ffprobe.test.ts | 35 +++++++++++++++++------ 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/packages/engine/src/utils/ffprobe.test.ts b/packages/engine/src/utils/ffprobe.test.ts index 2030dc1054..20186127dc 100644 --- a/packages/engine/src/utils/ffprobe.test.ts +++ b/packages/engine/src/utils/ffprobe.test.ts @@ -251,11 +251,10 @@ describe("probeMediaProfile", () => { }); it("bounds the process-scoped probe cache", async () => { - const fixtureDir = mkdtempSync(resolve(tmpdir(), "hf-media-probe-lru-")); - const fixturePaths = Array.from({ length: 129 }, (_, index) => - resolve(fixtureDir, `asset-${index}`), - ); - for (const fixturePath of fixturePaths) writeFileSync(fixturePath, "probe identity"); + // Cache identity is derived from stat, so synthesise it instead of writing + // 129 real files: the eviction rule is in-memory, and on a contended + // Windows runner the file churn alone pushed this past the test timeout. + const paths = Array.from({ length: 129 }, (_, index) => `/probe-lru/asset-${index}`); const outcome = { kind: "exit" as const, code: 0, @@ -267,13 +266,31 @@ describe("probeMediaProfile", () => { const { spawn, calls } = createSpawnSpy([outcome]); vi.resetModules(); vi.doMock("child_process", () => ({ spawn })); - const { probeMediaProfile } = await import("./ffprobe.js"); + vi.doMock("fs", async () => { + const actual = await vi.importActual("fs"); + const statSync = (filePath: string) => ({ + dev: 1n, + ino: BigInt(paths.indexOf(filePath)), + size: 1n, + mtimeNs: 0n, + ctimeNs: 0n, + }); + return { ...actual, statSync }; + }); try { - for (const fixturePath of fixturePaths) await probeMediaProfile(fixturePath); - await probeMediaProfile(fixturePaths[0]!); + const { probeMediaProfile } = await import("./ffprobe.js"); + const [first, second, ...rest] = paths; + for (const filePath of paths.slice(0, 128)) await probeMediaProfile(filePath); + // A hit refreshes the entry, so the 129th insert evicts `second`, not `first`. + await probeMediaProfile(first!); + await probeMediaProfile(rest.at(-1)!); + expect(calls).toHaveLength(129); + await probeMediaProfile(first!); + expect(calls).toHaveLength(129); + await probeMediaProfile(second!); expect(calls).toHaveLength(130); } finally { - rmSync(fixtureDir, { recursive: true, force: true }); + vi.doUnmock("fs"); } });