diff --git a/src/adapters/storage/opfs/opfs-policy.ts b/src/adapters/storage/opfs/opfs-policy.ts index f15e415d..c1dc0e56 100644 --- a/src/adapters/storage/opfs/opfs-policy.ts +++ b/src/adapters/storage/opfs/opfs-policy.ts @@ -25,8 +25,9 @@ export type OpfsRuntimePolicy = Readonly<{ /** * 05-07. How long a put may wait for its source's next bytes. The put holds * the origin mutation lock from BEGIN to FINISH, so a stalled source would - * otherwise stop every tab's writes until their lock wait ran out. Keep it - * below `mutationLockWaitTimeoutMs` so a queued writer outlasts it. + * otherwise stop every tab's writes until their lock wait ran out. It must + * be below `mutationLockWaitTimeoutMs` so a queued writer outlasts it; the + * policy check refuses one that is not ([0929] 05-09). */ putIdleTimeoutMs: number; reconciliationBudgetMs: number; @@ -107,6 +108,8 @@ export function assertOpfsRuntimePolicy(policy: OpfsRuntimePolicy): void { !Number.isSafeInteger(policy.putIdleTimeoutMs) || policy.putIdleTimeoutMs < 1_000 || policy.putIdleTimeoutMs > 60 * 60_000 || + // [0929] 05-09. A queued writer must outlast a stalled one. + policy.putIdleTimeoutMs >= policy.mutationLockWaitTimeoutMs || !Number.isSafeInteger(policy.reconciliationBudgetMs) || policy.reconciliationBudgetMs < 1 || policy.reconciliationBudgetMs > 60_000 || diff --git a/tests/unit/opfs-worker-runtime.test.ts b/tests/unit/opfs-worker-runtime.test.ts index 9b361ebc..e319754c 100644 --- a/tests/unit/opfs-worker-runtime.test.ts +++ b/tests/unit/opfs-worker-runtime.test.ts @@ -3034,6 +3034,29 @@ describe("05-07 a put whose source stops lets go of the origin lock", () => { expect(await putB).toMatchObject({ ok: true, value: { generation: 1 } }); stalled.release(); }); + + // [0929] 05-09. The test above holds only while a queued writer outlasts a + // stalled one. That ordering was a comment; a policy that breaks it is now + // refused when it is resolved. + it.each([ + ["equal to", 60_000], + ["longer than", 120_000], + ])("rejects an idle bound %s the lock wait", (_, putIdleTimeoutMs) => { + expect(() => + resolveOpfsRuntimePolicy({ + ...runtimePolicy, + mutationLockWaitTimeoutMs: 60_000, + putIdleTimeoutMs, + }), + ).toThrow(TypeError); + expect( + resolveOpfsRuntimePolicy({ + ...runtimePolicy, + mutationLockWaitTimeoutMs: putIdleTimeoutMs + 1, + putIdleTimeoutMs, + }).putIdleTimeoutMs, + ).toBe(putIdleTimeoutMs); + }); }); describe("05-10 the object id grammar is the prepared-object grammar", () => {