refactor(realtime): merge snapshot and race helpers, move shared parsers to kernel (Q-6.4-8)
Realtime kept three DataSnapshot readers and about ten hand-written abort/timeout races, and two parsers had drifted copies in other adapters. Snapshot: reconnect-coordinator and bounded-poll now use result.ts captureRealtimeDataSnapshot (+ `source`, variadic hasExactSnapshotKeys). Kept the result.ts rules, the stricter ones: Object.hasOwn instead of `"value" in` (prototype pollution), enumerable fields only, keys read from one descriptor snapshot, frozen computed at snapshot time instead of a later Object.isFrozen. Poll therefore now rejects non-enumerable fields; it also accepts null-prototype records, which the other two copies already did (pure data, no inherited accessors). Characterization test added for both in bounded-poll-coordinator.test.ts. Race: one raceRealtimeTask(task, signal, deadline) in result.ts, built on kernel createAbortableOperation, replaces fetch-sse timed/cancelReader, reconnect race/drain (the drain keeps a host timer via timerDeadline, since the clock itself may hang), poll awaitTaskOrAbort/awaitWithinLease, live-poll checkpoint + two quiescence races (now one), stream-coordinator deadline/recovery-wait/close-drain, and the two WS inline races. Kept semantics: deadline armed first and wins a tie (poll lease), task still starts when the clock throws (reader cancel), collaborator rejections still reach stream-coordinator callers, scheduler install failure still fails closed as a timeout. Small change: nothing starts once the signal is already aborted (WS apply / SSE onEvent / reader.read could run just before being reported ABORTED). The mapping adds one microtask per race, so the reconnect test flush() helper gets 16 turns instead of 8. Kernel: parseRetryAfterDelay moves to platform/retry-after.ts (realtime re-exports it; http retry-policy parseRetryAfter now delegates, so it rejects "", " ", "1e3", "1.5", "0x10" and non-IMF dates it used to accept). json-member-scanner moves to platform/; web-push push-codec uses it instead of its top-level-only duplicate-key check, so nested duplicates are rejected too. INVENTORY 136 -> 137, detail tables updated. Tests: RED for http strict Retry-After, web-push nested duplicate, poll snapshot rules; new direct raceRealtimeTask tests. Gates: architecture, types app/test (+ service-worker/web-worker), lint, adapter-inventory (abort ratchet 21/21), test:unit, test:component, realtime-boundaries, integration/platform all pass. Realtime bundle 40346 -> 39433 gzip. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
54e6bce9d2
commit
ae2f006b6d
@@ -137,6 +137,29 @@ describe("Web Push contracts", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("rejects duplicate keys at any depth without a nesting budget", () => {
|
||||
const deepDeclarative = {
|
||||
web_push: 8030,
|
||||
notification: { title: "t", data: { a: [[[[{ b: 1 }]]]] } },
|
||||
};
|
||||
expect(
|
||||
decodeWebPushHint(encoded(deepDeclarative), now),
|
||||
).toMatchObject({
|
||||
ok: false,
|
||||
error: { code: "DECLARATIVE_PUSH_FORBIDDEN" },
|
||||
});
|
||||
const nestedDuplicate = JSON.stringify(deepDeclarative).replace(
|
||||
'"title":"t"',
|
||||
'"title":"t","title":"u"',
|
||||
);
|
||||
expect(
|
||||
decodeWebPushHint(new TextEncoder().encode(nestedDuplicate), now),
|
||||
).toMatchObject({
|
||||
ok: false,
|
||||
error: { code: "CONTRACT_REJECTED" },
|
||||
});
|
||||
});
|
||||
|
||||
it("uses an injected closed notification and route registry", async () => {
|
||||
const registry = createWebPushNotificationRegistry([
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user