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-fcstd-roundtrip-verification.json'), 'utf8'))
if (report.schemaVersion !== 1 || report.status !== 'pass' || report.browserId !== 'chrome' || !/Chrome/i.test(report.browser?.product || '') || report.baseline?.freecadVersion !== '1.1.1' || report.baseline?.bitbybitVersion !== '1.1.1') throw new Error('Chrome FCStd round-trip verification is not passing.')
if (JSON.stringify(report.directions) !== '["freecad-web-freecad","web-freecad-web"]' || !Array.isArray(report.scenarios) || report.scenarios.length !== 2 || report.scenarios.some((scenario) => scenario.status !== 'pass' || scenario.differences.length !== 0)) throw new Error('FC-10 direction or difference evidence is incomplete.')
if (report.persistence?.mode !== 'sqlite-opfs' || report.persistence.bytes <= 0 || report.persistence.roundTrip !== true || report.persistence.released !== true || report.opfs?.markerSuite !== 'FC-10' || report.opfs.markerRemoved !== true || report.afterRelease?.shapeCount !== 0 || report.afterRelease.kernelReferenceCount !== 0) throw new Error('FC-10 OPFS or resource release evidence is incomplete.')
console.log(JSON.stringify({ status: 'chrome-fcstd-roundtrip-pass', browser: report.browser.product, directions: report.directions, scenarios: report.scenarios, persistence: report.persistence, opfs: report.opfs }, null, 2))
