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
20 lines
636 B
TypeScript
20 lines
636 B
TypeScript
/**
|
|
* @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 () => {} });
|
|
}
|
|
}
|