Open History to see the last commit
1/**
2 * Real-provider refinement of the law/driver in hydration-commit.opfs.ts.
3 * The insert history retains baseline+r1. The rich history replaces all rows,
4 * ends with r2=3, cursor=8 and r2 ownership metadata. Both append an ordinary
5 * tail after their receipt cut. Held histories additionally require scope exit. These literal expectations are a
6 * second formulation of the core edit-log oracle, not derived from its model.
7 * Peer B's schema/data and C's ordinary write must survive A's nested work.
8 * A cycle is an assertion at a reached causal boundary, never a timeout waiver.
9 */
10import { expect, test } from '@playwright/test'
11import type { HydrationCommitObservation } from './hydration-commit.opfs'
12
13for (const phase of [`startup`, `subscription`, `after-ready`] as const) {
14 for (const baseline of [false, true]) {
15 for (const coordinator of [`default`, `browser`] as const) {
16 for (const rich of [false, true]) {
17 test(`${phase}, baseline=${baseline}, coordinator=${coordinator}, rich=${rich}: preserves source and peer durability`, async ({
18 page,
19 }) => {
20 await page.goto(
21 `/e2e/hydration-commit.opfs.html?phase=${phase}&baseline=${baseline}&coordinator=${coordinator}&rich=${rich}`,
22 )
23 await page.waitForFunction(
24 () => window.__hydrationCommitDone === true,
25 )
26 const result = await page.evaluate(() => ({
27 observation: window.__hydrationCommitResult,
28 error: window.__hydrationCommitError,
29 cleanupErrors: window.__hydrationCommitCleanupErrors,
30 }))
31 const observed: HydrationCommitObservation | undefined =
32 result.observation
33 expect(
34 observed,
35 `fixture must reach its observation cut: ${JSON.stringify(result)}`,
36 ).toBeDefined()
37 if (!observed) return
38 expect(observed.rowReads).toBeGreaterThan(0)
39 if (phase !== `after-ready`)
40 expect(observed.held).toEqual({
41 receipts: Array.from({ length: rich ? 6 : 1 }, () => `pending`),
42 rows: [],
43 ordinary: `pending`,
44 interleavedSql: [],
45 peerHydrationAdmitted: true,
46 ordinaryAdmitted: true,
47 })
48 expect(observed.cycleCalls, JSON.stringify(result)).toBe(0)
49 expect(observed.errors).toEqual([])
50 expect(
51 observed.ordinaryCommitSqlCalls,
52 `the ordinary SQL observer must be reached`,
53 ).toBe(1)
54 expect(
55 observed.tailScheduling,
56 `the tail must reenter ordinary scheduling exactly once`,
57 ).toEqual([
58 coordinator === `browser` ? `regular-scope` : `public-apply`,
59 ])
60 expect(
61 observed.peerWorkBeforeScopeExit,
62 `peer work cannot preempt the whole owning callback`,
63 ).toEqual([])
64 expect({
65 receipts: observed.receipts,
66 source: observed.sourceStatus,
67 peer: observed.peerStatus,
68 ordinary: observed.ordinaryReceipt,
69 exited: observed.owningScopeExited,
70 }).toEqual({
71 receipts: Array.from({ length: rich ? 7 : 2 }, () => `fulfilled`),
72 source: `ready`,
73 peer: `ready`,
74 ordinary: `fulfilled`,
75 exited: phase === `after-ready` ? null : true,
76 })
77 const expected = rich
78 ? [
79 { id: `r2`, value: 3 },
80 { id: `tail`, value: 9 },
81 ]
82 : [
83 ...(baseline ? [{ id: `baseline`, value: 0 }] : []),
84 { id: `r1`, value: 1 },
85 { id: `tail`, value: 9 },
86 ]
87 expect(observed.rows).toEqual(expected)
88 expect(observed.durableRows).toEqual(expected)
89 expect(observed.reopenedRows).toEqual(expected)
90 expect(observed.durableMetadata).toEqual(
91 rich ? [{ key: `cursor`, value: 8 }] : [],
92 )
93 expect(observed.durableRowMetadata).toEqual(
94 rich ? [{ key: `r2`, metadata: { owner: `source` } }] : [],
95 )
96 expect(observed.peerRows).toEqual([
97 { id: `peer-baseline`, value: 22 },
98 ])
99 expect(observed.ordinaryRows).toEqual([{ id: `ordinary`, value: 33 }])
100 expect(observed.schemas).toEqual([
101 { collection_id: `a`, schema_version: 11 },
102 { collection_id: `b`, schema_version: 22 },
103 { collection_id: `c`, schema_version: 33 },
104 ])
105 expect(result.error).toBeUndefined()
106 expect(result.cleanupErrors).toEqual([])
107 })
108 }
109 }
110 }
111}
112
113// ORC-010 calibration: two teardown failures cannot erase the independently
114// captured observation, mutate its receipt errors, or hide one another.
115test(`preserves the primary observation through multiple cleanup failures`, async ({
116 page,
117}) => {
118 await page.goto(
119 `/e2e/hydration-commit.opfs.html?phase=after-ready&baseline=false&coordinator=browser&rich=false&cleanupFault=true`,
120 )
121 await page.waitForFunction(() => window.__hydrationCommitDone === true)
122 const result = await page.evaluate(() => ({
123 observation: window.__hydrationCommitResult,
124 error: window.__hydrationCommitError,
125 cleanup: window.__hydrationCommitCleanupErrors,
126 }))
127 expect(result.error).toBeUndefined()
128 expect(result.observation?.cycleCalls).toBe(0)
129 expect(result.observation?.errors).toEqual([])
130 expect(result.observation?.reopenedRows).toEqual([
131 { id: `r1`, value: 1 },
132 { id: `tail`, value: 9 },
133 ])
134 expect(result.cleanup).toEqual([
135 `Error: injected first cleanup failure`,
136 `Error: injected last cleanup failure`,
137 ])
138})