diigo-cache: the caches take their clock as a constructor argument

Ocap discipline: no ambient time in logic. PagedCache reads time and
waits only through a Clock { now, sleep }, a default constructor
argument (the live clock; the runtime constructs DOs with ctx and env
only). The fill job's timestamps and alarms, the etch time, and the
diigo-call pacing all go through it.

Tests interpose through the constructor: tests/test-worker.ts (now the
tests' main module) adds FixedClockCache, bound as CLOCKED_DO, and a
test pins startedAt, updatedAt, and the alarm time to the fixed clock
(an ambient new Date() fails it).

Generated-by: Claude Opus 5.5
This commit is contained in:
dckc committed 2026-10-07 04:34:48 -05:00
1 parent 7d2100bf77
commit b6823867ff
4 files changed
+76 -17

No files matched your search

+19
View File
@@ -0,0 +1,19 @@
/**
* @file the tests' main module: the real worker, plus a DiigoCache on a
* fixed clock (bound as CLOCKED_DO in wrangler.tests.jsonc), so tests can
* interpose time through the constructor.
*/
import { DiigoCache } from "../src/cache.js";
import type { CacheEnv } from "../src/cache.js";
export * from "../src/index.js";
export { default } from "../src/index.js";
/** 2026-10-07T12:00:00Z */
export const FIXED_NOW = Date.UTC(2026, 9, 7, 12, 0, 0);
export class FixedClockCache extends DiigoCache {
constructor(ctx: DurableObjectState, env: CacheEnv) {
super(ctx, env, { now: () => FIXED_NOW, sleep: async () => {} });
}
}