import { readFile } from 'node:fs/promises'
import { resolve } from 'node:path'
const report = JSON.parse(await readFile(resolve(new URL('..', import.meta.url).pathname, 'config/chrome-native-multi-transform-history-verification.json'), 'utf8'))
const stages = report.history?.stages || []
const lineage = report.history?.finalRecordLineage
if (report.status !== 'pass' || report.browserId !== 'chrome' || report.nativeCapabilities?.operations?.includes('multi-transform') !== true || report.history?.recordCount <= 0 || report.history?.relations?.modified <= 0 || report.history?.relations?.generated <= 0 || JSON.stringify(report.history?.transformKinds) !== JSON.stringify(['linear', 'mirrored']) || JSON.stringify(report.history?.sourceObjects) !== JSON.stringify(['Base']) || stages.length !== 2 || stages[0]?.operation !== 'linear-pattern' || stages[1]?.operation !== 'mirrored' || JSON.stringify(stages[0]?.inputObjectIds) !== JSON.stringify(['Base']) || stages[1]?.inputObjectIds?.[0] !== stages[0]?.resultObjectId || stages[1]?.resultObjectId !== 'MultiTransform' || stages.some((stage) => stage.topologyEntries <= 0 || stage.recordCount <= 0) || lineage?.records !== report.history?.stagedRecordCount || JSON.stringify(lineage?.sourceObjectIds) !== JSON.stringify([stages[0]?.resultObjectId]) || JSON.stringify(lineage?.sourceStageIds) !== JSON.stringify([stages[0]?.stageId]) || JSON.stringify(lineage?.resultStageIds) !== JSON.stringify([stages[1]?.stageId]) || report.result?.bitbybitSolids !== 1 || Math.abs(report.result.bitbybitVolume - 5) > 1e-7 || report.result?.nativeStructuralValid !== true || report.result?.nativeSolids !== 1 || Math.abs(report.result.nativeVolume - 5) > 1e-7 || JSON.stringify(report.opfs?.markerPayload?.transformKinds) !== JSON.stringify(['linear', 'mirrored']) || report.opfs?.markerRemoved !== true || report.afterRelease?.shapeCount !== 0 || report.afterRelease?.kernelReferenceCount !== 0) throw new Error('Chrome native MultiTransform evidence is invalid.')
console.log(JSON.stringify({ status: 'chrome-native-multi-transform-history-pass', records: report.history.recordCount, relations: report.history.relations, stages, result: report.result, afterRelease: report.afterRelease }, null, 2))
