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-semantic-verification.json'), 'utf8'))
if (report.schemaVersion !== 1 || report.status !== 'pass' || report.browserId !== 'chrome' || !/Chrome/i.test(report.browser?.product || '')) throw new Error('Chrome FCStd semantic verification is not passing.')
if (JSON.stringify(report.objectNames) !== JSON.stringify(['Source', 'Spreadsheet', 'Cut', 'Sketch']) || report.expression !== 'Spreadsheet.Width * 2' || report.link !== 'Source' || report.linkSub?.objectId !== 'Source' || report.linkSub.subElement !== 'Face1' || JSON.stringify(report.linkSubList) !== JSON.stringify([{ objectId: 'Source', subElement: 'Face1' }, { objectId: 'Source', subElement: 'Face2' }]) || JSON.stringify(report.sketchGeometryIds) !== JSON.stringify(['profile']) || !report.dependencyRelations.includes('expression') || !report.dependencyRelations.includes('link') || !report.dependencyRelations.includes('topo-ref') || !report.dependencyRelations.includes('topo-ref-list') || report.archiveBytes <= 0) throw new Error('Chrome FCStd Expression/Link/LinkSub/Sketcher round-trip evidence is incomplete.')
if (JSON.stringify(report.guiViews) !== JSON.stringify(['Front', 'Top']) || report.shapeResource?.path !== 'Part/Source.Shape.brp' || report.shapeResource.byteLength <= 0 || report.shapeResource.elementMap !== '1' || report.shapeResource.elementMapEntries !== 1) throw new Error('Chrome FCStd GuiDocument/BRep/ElementMap evidence is incomplete.')
if (report.opfs?.markerSuite !== 'FC-06' || report.opfs.archiveBytes !== report.archiveBytes || report.opfs.markerRemoved !== true) throw new Error('Chrome FCStd semantic OPFS marker was not verified and removed.')
console.log(JSON.stringify({ status: 'chrome-fcstd-semantic-pass', browser: report.browser.product, objects: report.objectNames.length, dependencies: report.dependencyRelations, guiViews: report.guiViews, shapeResource: report.shapeResource, archiveBytes: report.archiveBytes, opfs: report.opfs }, null, 2))
