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-sketcher-editor-verification.json'), 'utf8'))
if (report.schemaVersion !== 1 || report.browserId !== 'chrome' || report.status !== 'pass' || report.crossOriginIsolated !== true) throw new Error('Chrome Sketcher editor verification is not passing.')
const operations = report.operations ?? {}
if (operations.drag?.start?.y !== 2 || operations.drag?.end?.x !== 8 || operations.drag.end.y !== 2 || operations.drag.sourceUnchanged !== true) throw new Error('Chrome drag evidence is incomplete.')
if (JSON.stringify(operations.split?.ids) !== JSON.stringify(['line', 'line-2']) || JSON.stringify(operations.split.constraintTypes) !== JSON.stringify(['coincident']) || operations.extend?.end?.x !== 15 || operations.extend.sourceUnchanged !== true || operations.trim?.end?.x !== 7 || JSON.stringify(operations.trim.constraintTypes) !== JSON.stringify(['pointOnObject']) || operations.trim.sourceUnchanged !== true) throw new Error('Chrome trim/extend/split evidence is incomplete.')
if (operations.construction?.enabled !== true || operations.construction.sourceUnchanged !== true) throw new Error('Chrome construction-toggle evidence is incomplete.')
if (JSON.stringify(operations.autoConstraint?.suggestionReasons) !== JSON.stringify(['coincident', 'horizontal']) || operations.autoConstraint.appliedIds.length !== 2 || operations.autoConstraint.sourceUnchanged !== true) throw new Error('Chrome autoconstraint evidence is incomplete.')
if (operations.replay?.applied !== 2 || operations.replay.undone !== 1 || operations.replay.redone !== 1 || operations.replay.finalEnd?.x !== 6) throw new Error('Chrome undo/redo replay evidence is incomplete.')
const interactions = report.interactions ?? {}
if (interactions.nativeEvents?.pointer !== 3 || interactions.nativeEvents.keyboard !== 3 || interactions.start?.y !== 2 || interactions.end?.x !== 8 || interactions.end?.y !== 2 || interactions.tool !== 'select' || interactions.pointerActive !== false || interactions.applied !== 1 || interactions.undone !== 1 || interactions.redone !== 1) throw new Error('Chrome native pointer/keyboard interaction evidence is incomplete.')
if (report.opfs?.markerSuite !== 'SK-09' || report.opfs.markerOperations !== 9 || report.opfs.markerRemoved !== true) throw new Error('Chrome Sketcher editor OPFS marker was not verified and removed.')
console.log(JSON.stringify({ status: 'chrome-sketcher-editor-pass', browser: report.browserId, operations: report.operations, interactions: report.interactions, opfs: report.opfs }, null, 2))
