Files
Web_FreeCAD_Bitbybit/public/chrome-native-mirrored-history-harness.html

32 lines
4.4 KiB
HTML

<!doctype html>
<meta charset="utf-8">
<title>Chrome native Mirrored history</title>
<pre id="result">running</pre>
<script type="module">
import { BitbybitGeometryRuntime } from '/src/facade/geometryRuntime.ts'
import { NativeOcctHistoryWorkerProvider } from '/src/facade/nativeHistoryWorkerClient.ts'
import { NativeOcctHistoryCoordinator } from '/src/facade/nativeHistoryProtocol.ts'
const output = document.querySelector('#result')
const report = { schemaVersion: 1, browserId: 'chrome', crossOriginIsolated: globalThis.crossOriginIsolated === true, status: 'running' }
let runtime, provider, base, copy, result
try {
runtime = new BitbybitGeometryRuntime(); const capabilities = await runtime.initialize()
provider = new NativeOcctHistoryWorkerProvider({ moduleUrl: '/native/occt-history/bitbybit-occt-history.js' }); const nativeCapabilities = await provider.initialize(); runtime.configureNativeHistory(provider)
const context = { documentId: 'chrome-native-mirrored', documentVersion: 1 }
base = await runtime.createBox({ ...context, width: 2, length: 1, height: 1, center: [0.5, 0, 0], originOnCenter: true })
copy = await runtime.mirror({ ...context, shape: base, origin: [0, 0, 0], normal: [1, 0, 0] })
result = await runtime.union({ ...context, shapes: [base, copy] })
const [quality, mass, baseStep] = await Promise.all([runtime.qualityReport(result), runtime.massProperties(result), runtime.exportStep(base, 'Base.step')])
const execution = await new NativeOcctHistoryCoordinator(() => 1).capture(provider, { ...context, operationId: 'mirrored-history', operation: 'mirrored', objectStep: baseStep.text, axisOrigin: [0, 0, 0], direction: [1, 0, 0] })
if (execution.status !== 'completed' || !execution.response) throw new Error(`Native Mirrored history ${execution.status}.`)
const records = execution.response.history.records
const relations = { modified: records.filter((entry) => entry.relation === 'modified').length, generated: records.filter((entry) => entry.relation === 'generated').length, deleted: records.filter((entry) => entry.relation === 'deleted').length }
const directory = await navigator.storage.getDirectory(); const markerName = 'native-mirrored-history-marker.json'; const marker = await directory.getFileHandle(markerName, { create: true }); const writable = await marker.createWritable(); await writable.write(JSON.stringify({ operation: 'mirrored' })); await writable.close(); const markerSuite = JSON.parse(await (await marker.getFile()).text()).operation; await directory.removeEntry(markerName)
report.capabilities = capabilities; report.nativeCapabilities = nativeCapabilities; report.history = { recordCount: records.length, relations, sourceObjects: ['Base'] }; report.result = { bitbybitStructuralValid: quality.structuralValid, bitbybitSolids: quality.solids, bitbybitVolume: mass.volume, nativeStructuralValid: execution.response.history.summary.isValid, nativeSolids: execution.response.history.summary.solids, nativeVolume: execution.response.history.summary.volume }; report.opfs = { markerSuite, markerRemoved: true }
await runtime.release(result); result = undefined; await runtime.release(copy); copy = undefined; await runtime.release(base); base = undefined; report.afterRelease = { shapeCount: runtime.capabilities().shapeCount, kernelReferenceCount: runtime.capabilities().kernelReferenceCount }
report.status = report.crossOriginIsolated && nativeCapabilities.operations.includes('mirrored') && records.length > 0 && quality.solids === 1 && Math.abs(mass.volume - 3) < 1e-7 && report.result.nativeStructuralValid && report.result.nativeSolids === 1 && Math.abs(report.result.nativeVolume - 3) < 1e-7 && markerSuite === 'mirrored' && report.afterRelease.shapeCount === 0 && report.afterRelease.kernelReferenceCount === 0 ? 'pass' : 'failed'
} catch (error) { report.status = 'failed'; report.error = error instanceof Error ? error.stack || error.message : String(error) }
finally { if (result) await runtime?.release(result).catch(() => {}); if (copy) await runtime?.release(copy).catch(() => {}); if (base) await runtime?.release(base).catch(() => {}); provider?.dispose(); runtime?.dispose() }
output.textContent = JSON.stringify(report, null, 2); await fetch('/__native-mirrored-history-report', { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify(report) }); if (report.status !== 'pass') throw new Error(report.error || 'failed')
</script>