import { loadGoldenManifest } from './freecad-golden-contract.mjs'
import { compareSemanticResult } from './freecad-semantic-comparator.mjs'
import { resolve } from 'node:path'

const root = resolve(new URL('..', import.meta.url).pathname)
const manifest = await loadGoldenManifest(resolve(root, 'fixtures/freecad-golden/manifest.json'))
for (const entry of manifest.scenarios) {
  const report = compareSemanticResult(entry.scenario, entry.scenario.expected)
  if (report.status !== 'pass' || report.differences.length) throw new Error(`Semantic comparator self-check failed for ${entry.id}.`)
  const drift = structuredClone(entry.scenario.expected)
  drift.volume += entry.scenario.tolerance.scalar * 2
  const driftReport = compareSemanticResult(entry.scenario, drift)
  if (driftReport.status !== 'fail-unknown-difference' || !driftReport.differences.some((difference) => difference.path.endsWith('.volume') && difference.classification === 'unknown')) throw new Error(`Semantic comparator drift check failed for ${entry.id}.`)
}
console.log(JSON.stringify({ status: 'freecad-semantic-comparator-pass', scenarioCount: manifest.scenarios.length, reportSchemaVersion: 1, unknownDifferencesFail: true }, null, 2))
