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-surface-verification.json'), 'utf8'))
if (report.schemaVersion !== 1 || report.status !== 'pass' || report.browserId !== 'chrome' || !/Chrome/i.test(report.browser?.product || '') || report.crossOriginIsolated !== true) throw new Error('Chrome surface verification is not passing.')
if (report.model?.patches !== 5 || report.model.poles !== 20 || report.model.trimmed !== 1 || report.model.sewn !== 1 || report.model.continuity !== 'C0' || report.model.fillKind !== 'bezier' || report.model.offsetDistance !== 1.5 || report.model.topoRefs !== 4 || report.model.objBytes <= 0) throw new Error('Surface fill/offset/trim/sew/TopoRef evidence is incomplete.')
if (report.persistence?.mode !== 'sqlite-opfs' || report.persistence.byteLength <= 0 || report.persistence.roundTrip !== true || report.persistence.released !== true) throw new Error('Surface OPFS resource evidence is incomplete.')
if (report.opfs?.markerSuite !== 'SURF-CORE' || report.opfs.patches !== 5 || report.opfs.markerRemoved !== true) throw new Error('Surface OPFS marker was not verified and removed.')
if (report.afterRelease?.shapeCount !== 0 || report.afterRelease.kernelReferenceCount !== 0) throw new Error('Surface harness leaked ShapeHandles.')
console.log(JSON.stringify({ status: 'chrome-surface-pass', browser: report.browser.product, model: report.model, persistence: report.persistence, opfs: report.opfs, afterRelease: report.afterRelease }, null, 2))
