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-native-fillet-history-verification.json'), 'utf8'))
if (report.schemaVersion !== 1 || report.browserId !== 'chrome' || report.executionContext !== 'geometry-and-history-workers' || report.crossOriginIsolated !== true || report.status !== 'pass') throw new Error('Chrome native Fillet history evidence is invalid.')
if (report.capabilities?.status !== 'ready' || report.nativeCapabilities?.availability !== 'available' || report.nativeCapabilities?.operations?.includes('fillet') !== true) throw new Error('Native OCCT Fillet Worker capability evidence is incomplete.')
if (!Number.isSafeInteger(report.history?.recordCount) || report.history.recordCount <= 0 || report.history.relations?.modified <= 0 || report.history.relations?.generated <= 0 || report.history.relations?.deleted <= 0 || JSON.stringify(report.history.sourceObjects) !== JSON.stringify(['Base'])) throw new Error('Native OCCT Fillet relation evidence is incomplete.')
if (report.result?.structuralValid !== true || report.result?.solids !== 1 || !(report.result.volume > 0 && report.result.volume < 216)) throw new Error('Native OCCT Fillet result evidence is invalid.')
if (report.opfs?.markerCreated !== true || report.opfs?.markerSuite !== 'fillet' || report.opfs?.markerRemoved !== true) throw new Error('Chrome native Fillet OPFS evidence is incomplete.')
if (report.afterRelease?.shapeCount !== 0 || report.afterRelease?.kernelReferenceCount !== 0) throw new Error('Chrome native Fillet history handles were not released.')
console.log(JSON.stringify({ status: 'chrome-native-fillet-history-pass', browserId: report.browserId, occtVersion: report.nativeCapabilities.occtVersion, records: report.history.recordCount, relations: report.history.relations, volume: report.result.volume, opfs: report.opfs, afterRelease: report.afterRelease }, null, 2))
