test(8.0): de-flake the VFS path-cache timing assertion

`should cache paths for fast repeated access` compared a single cold vs warm
readFile with Date.now() (ms resolution). Both reads are sub-millisecond, so the
warm read intermittently measured 1ms vs the cold 0ms and the `time2 <= time1`
assertion failed on rounding noise — a non-deterministic gate that blocked a clean
release. Replace it with the average of 100 warm reads via performance.now()
against a generous absolute bound (cached path reads are sub-ms), plus a content
round-trip check. Same intent (cached access is fast), no single-shot ms flake.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
David Snelling 2026-06-23 16:02:07 -07:00
parent 1c363e8c4b
commit 0e8972c6fa

View file

@ -396,19 +396,19 @@ describe('VirtualFileSystem - Production Tests', () => {
await vfs.mkdir('/cached') await vfs.mkdir('/cached')
await vfs.writeFile(path, 'cached content') await vfs.writeFile(path, 'cached content')
// First read (cold cache) // Prime the path cache + verify the content round-trips.
const start1 = Date.now() expect((await vfs.readFile(path)).toString()).toBe('cached content')
await vfs.readFile(path)
const time1 = Date.now() - start1
// Second read (warm cache) // Cached repeated access is sub-millisecond. Average many reads so the result
const start2 = Date.now() // doesn't hinge on Date.now()'s millisecond rounding of a single sub-ms op — the
await vfs.readFile(path) // old cold-vs-warm compare spuriously failed when both rounded to 0/1ms. A
const time2 = Date.now() - start2 // generous absolute bound still catches a regression to per-read disk/index work.
const ITERATIONS = 100
const start = performance.now()
for (let i = 0; i < ITERATIONS; i++) await vfs.readFile(path)
const avgWarmMs = (performance.now() - start) / ITERATIONS
// Cache should make second read faster expect(avgWarmMs).toBeLessThan(5)
expect(time2).toBeLessThanOrEqual(time1)
console.log(`Cold read: ${time1}ms, Warm read: ${time2}ms`)
}) })
}) })