Open History to see the last commit
1/**
2 * Browser checkpoint assertions for the OPFS refinement. Expected public rows
3 * are rebuilt from the scenario IDs rather than from production output. The
4 * neutral case proves cold-query reach; the storm case requires no K=1
5 * violation. Failure-before-checkpoint, semantic mismatch, driver cleanup, and
6 * OPFS cleanup remain distinct outcomes so setup or teardown cannot satisfy the
7 * scheduling law.
8 */
9import { expect, test } from '@playwright/test'
10import type { Page } from '@playwright/test'
11import type { OPFSOracleResult } from './shared-driver-fairness.opfs'
12
13async function readOracleResult(
14 page: Page,
15 mode: `neutral` | `storm`,
16): Promise<OPFSOracleResult> {
17 let rejectPageError!: (error: Error) => void
18 const pageError = new Promise<never>((_resolve, reject) => {
19 rejectPageError = reject
20 })
21 void pageError.catch(() => undefined)
22 const onPageError = (error: Error) => {
23 rejectPageError(
24 new Error(
25 `OPFS fairness page failed before publishing a result: ${error.message}`,
26 ),
27 )
28 }
29 page.on(`pageerror`, onPageError)
30
31 try {
32 await page.goto(`/e2e/shared-driver-fairness.opfs.html?mode=${mode}`)
33 await Promise.race([
34 page.waitForFunction(
35 () => window.__tanstackDriverFairnessOracle !== undefined,
36 ),
37 pageError,
38 ])
39 return page.evaluate(() => window.__tanstackDriverFairnessOracle!)
40 } finally {
41 page.off(`pageerror`, onPageError)
42 }
43}
44
45function expectedHydratedCollections(scenarioId: string, count: number) {
46 return Array.from({ length: count }, (_, index) => ({
47 collectionId: `${scenarioId}-hydrate-${index}`,
48 rows: [
49 { id: `row-${index}-0`, value: index * 10 },
50 { id: `row-${index}-1`, value: index * 10 + 1 },
51 ],
52 }))
53}
54
55test(`real Chromium OPFS fixture reaches and cleans up cold hydration`, async ({
56 page,
57}) => {
58 const result = await readOracleResult(page, `neutral`)
59
60 if (result.status !== `complete`) throw new Error(result.primaryFailure)
61 expect(result.provider).toBe(`Chromium OPFSCoopSyncVFS worker`)
62 expect(result.observation.admittedHydrateIds).toHaveLength(2)
63 // These are actual public Collection rows captured after preload, compared
64 // with seed values built independently by this browser assertion.
65 expect(result.observation.hydratedCollections).toEqual(
66 expectedHydratedCollections(`opfs-neutral-reach`, 2),
67 )
68 expect(
69 result.observation.rawDequeues.some((entry) =>
70 entry.sql.startsWith(`SELECT key, value, metadata, row_version FROM`),
71 ),
72 ).toBe(true)
73 expect(result.observation.cleanupFailures).toEqual([])
74 expect(result.opfsCleanupFailures).toEqual([])
75})
76
77test(`real Chromium OPFS fixture bounds pending cold hydration behind persists`, async ({
78 page,
79}) => {
80 const result = await readOracleResult(page, `storm`)
81
82 if (result.status !== `complete`) throw new Error(result.primaryFailure)
83 expect(result.provider).toBe(`Chromium OPFSCoopSyncVFS worker`)
84 expect(result.observation.admittedHydrateIds).toHaveLength(4)
85 expect(result.observation.hydratedCollections).toEqual(
86 expectedHydratedCollections(`opfs-fixed-persist-storm`, 4),
87 )
88 // This is the semantic RED checkpoint. Setup, wall time, and cleanup are
89 // reported independently and cannot satisfy this assertion.
90 if (result.violation !== undefined) {
91 throw new Error(
92 `real OPFS fairness mismatch: ${JSON.stringify(result.violation)}; ` +
93 `logical completion order: ${JSON.stringify(result.observation.logicalCompletionOrder)}; ` +
94 `driver admissions: ${result.observation.driverAdmissions.length}; ` +
95 `raw dequeues: ${result.observation.rawDequeues.length}; ` +
96 `driver cleanup diagnostics: ${JSON.stringify(result.observation.cleanupFailures)}; ` +
97 `OPFS cleanup diagnostics: ${JSON.stringify(result.opfsCleanupFailures)}`,
98 )
99 }
100 expect(result.observation.cleanupFailures).toEqual([])
101 expect(result.opfsCleanupFailures).toEqual([])
102})