import { readFile } from 'node:fs/promises'
import { resolve } from 'node:path'

const root = resolve(new URL('..', import.meta.url).pathname)
const report = JSON.parse(await readFile(resolve(root, 'config/chrome-persistence-verification.json'), 'utf8'))
if (report.schemaVersion !== 1 || report.browserId !== 'chrome' || report.status !== 'pass' || report.crossOriginIsolated !== true) throw new Error('Chrome OPFS persistence verification is not passing.')
const capabilities = report.capabilities
const roundTrip = report.roundTrip
if (capabilities?.mode !== 'sqlite-opfs' || capabilities.sqliteWasm !== true || capabilities.opfs !== true || roundTrip?.savedMode !== 'sqlite-opfs' || roundTrip.loadedVersion !== 7 || roundTrip.checkpointVersion !== 7 || roundTrip.resourceRoundTrip !== true || roundTrip.recoveryIntegrity !== 'ok') throw new Error('Chrome SQLite OPFS round-trip evidence is invalid.')
console.log(JSON.stringify({ status: 'chrome-persistence-verification-pass', browserId: report.browserId, capabilities, roundTrip }, null, 2))
