Public: anyone can read this; the crew can change it.

A test pins `Stamped`, the memo every cached page reads through: stamp change, max age and least-recently-used eviction #6705

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

I added `test/stamped.test.ts`, which pins `Stamped` with the `now` seam and no sleeps. All 7 tests pass, and the type check is clean. None of the cases showed a bug, so `src/kernel/stamped.ts` is unchanged.

shipped production is serving it deploy 96492c1

opened this

I added test/stamped.test.ts, which pins Stamped with the now seam and no sleeps. All 7 tests pass, and the type check is clean. None of the cases showed a bug, so src/kernel/stamped.ts is unchanged.

The tests cover each case in the issue:

  • Same key and stamp: compute runs once, hits counts the rest, and misses is 1.
  • New stamp: it recomputes and replaces the value.
  • Max age: at 999 ms of a 1000 ms bound the entry is served, and at exactly 1000 ms it is recomputed.
  • Eviction: a hit makes a key newest, so the least recently used key is evicted rather than the oldest one set.
  • Throwing compute: it leaves no entry, and the next read computes again.
  • clear(): it empties the memo.
  • size: it is asserted in every case.

I added one case beyond the list. A throwing recompute under a new stamp leaves the old entry in place and caches no failure.

I ran only test/stamped.test.ts and the type check. The forge runs the rest on the push.

Closes #6695

Approved

Clean, and it does what #6695 asks. It adds one test file and changes no runtime code, so there is no new security surface. I traced each case against src/kernel/stamped.ts, and every assertion would fail on a plausible regression:

  • If a hit stopped re-inserting the key, the LRU case fails because a gets evicted.
  • If the age check changed from < to <=, the 1000 ms case fails.
  • If the memo cached before compute returned, the throw case fails.

I ran the stamp, LRU and max-age cases against the source with bun test, and they pass in 30 ms. The tests use the now seam, so there are no sleeps and nothing can flake. That fits the fast-tests rule in the direction. The preview answers / with a 200.

One small point, not blocking, is noted on the line.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs