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-mesh-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 Mesh verification is not passing.')
if (report.geometry?.vertices <= 0 || report.geometry.triangles <= 0 || report.geometry.boundaryEdges !== 0 || report.geometry.nonManifoldEdges !== 0 || report.geometry.degenerateTriangles !== 0 || report.geometry.selfIntersections !== 0) throw new Error('Mesh quality evidence is incomplete.')
if (report.operations?.welded <= 0 || JSON.stringify(report.operations.transformedMin) !== JSON.stringify([-6.5, -1, -3]) || report.operations.objBytes <= 0 || report.operations.plyBytes <= 0 || report.operations.stlBytes <= 0 || report.operations.lodTriangles !== report.operations.workerLodTriangles || !/^[0-9a-f]{64}$/.test(report.operations.objHash)) throw new Error('Mesh normalize/transform/LOD/export evidence is incomplete.')
if (report.repairs?.selfIntersectionFixture !== 1 || report.repairs.nonManifoldFixture !== 1 || report.repairs.holeFilledTriangles !== 1) throw new Error('Mesh self-intersection/non-manifold/hole repair evidence is incomplete.')
if (report.persistence?.mode !== 'sqlite-opfs' || report.persistence.byteLength <= 0 || !/^[0-9a-f]{64}$/.test(report.persistence.hash) || report.persistence.roundTrip !== true || report.persistence.released !== true) throw new Error('Mesh OPFS resource evidence is incomplete.')
if (report.opfs?.markerSuite !== 'MESH-CORE' || report.opfs.triangles !== report.geometry.triangles || report.opfs.markerRemoved !== true) throw new Error('Mesh OPFS marker evidence is incomplete.')
if (report.afterRelease?.shapeCount !== 0 || report.afterRelease.kernelReferenceCount !== 0) throw new Error('Mesh harness leaked ShapeHandles.')
console.log(JSON.stringify({ status: 'chrome-mesh-pass', browser: report.browser.product, geometry: report.geometry, operations: report.operations, repairs: report.repairs, persistence: report.persistence, opfs: report.opfs, afterRelease: report.afterRelease }, null, 2))
