Files
captoys/diigo-cache/tests/test-worker.ts
T
dckc cffb1fa9b2 diigo-cache: diigo counts pages from 0; migrate stored pages (schema v2)
Comparing a cache with diigo's RSS export: the size-100 walk had missed
exactly the 100 newest bookmarks (everything updated since 2026-09-16).
diigo's page_num is 0-based, and we sent our 1-based page number
unchanged, so "page 1" was really page 2 and the newest page was never
fetched. diigo's total (16744) was right; the "total-overstated"
reading was a misdiagnosis.

- page() asks for page_num = n - 1
- BREAKING for stored state, agreed beforehand, migrated in place:
  schema v2 renumbers every stored page +1 (pages and page_members, via
  negation so no number collides), once, recorded as kv "schema" = 2;
  nothing is refetched, page 1 just becomes a miss
- fill jobs record their numbering; a job saved without it fails ("page
  numbering changed …; start the fill again") instead of resuming
- the fake pages from 0 like diigo (7 tests failed until the fix);
  tests feed v1-shaped storage and a v1-numbered job to the new code
- the next-page peek guard stays; its comments no longer claim diigo
  overstates its total
- the fixed test clock moves to 2099: pinned to "today" its alarms came
  due in real time and fired on their own

Generated-by: Claude Opus 5.5
2026-10-07 08:26:13 -05:00

36 lines
1.0 KiB
TypeScript

/**
* @file the tests' main module — their edge: the real worker (whose own
* edge supplies the live clock), plus the private cache's logic on a fixed
* clock (bound as CLOCKED_DO in wrangler.tests.jsonc).
*/
import { DiigoCacheLogic } from "../src/cache.js";
import type { CacheEnv } from "../src/cache.js";
export * from "../src/index.js";
export { default } from "../src/index.js";
/** 2099-01-01T00:00:00Z: in the future, so an alarm set by this clock is
* never due in real time — tests run it with runDurableObjectAlarm */
export const FIXED_NOW = Date.UTC(2099, 0, 1, 0, 0, 0);
/** a fixed clock that records each sleep it is asked for */
export class FixedClockCache extends DiigoCacheLogic {
#sleeps: number[] = [];
constructor(ctx: DurableObjectState, env: CacheEnv) {
const sleeps: number[] = [];
super(ctx, env, {
now: () => FIXED_NOW,
sleep: async (ms) => {
sleeps.push(ms);
},
});
this.#sleeps = sleeps;
}
/** the sleeps so far (test hook) */
async sleeps(): Promise<number[]> {
return [...this.#sleeps];
}
}