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

49 lines
3.1 KiB
HTML

<!doctype html>
<meta charset="utf-8">
<title>Chrome native OCCT history harness</title>
<pre id="result">running</pre>
<script type="module">
import { BitbybitGeometryRuntime } from '/src/facade/geometryRuntime.ts'
import { NativeOcctHistoryWorkerProvider } from '/src/facade/nativeHistoryWorkerClient.ts'
const output = document.querySelector('#result')
const report = { schemaVersion: 1, browserId: 'chrome', crossOriginIsolated: globalThis.crossOriginIsolated === true, status: 'running' }
let runtime
let provider
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-history', documentVersion: 1 }
const base = await runtime.createBox({ ...context, width: 10, length: 10, height: 10 })
const tool = await runtime.createBox({ ...context, width: 6, length: 6, height: 6, center: [5, 5, 5], originOnCenter: true })
const result = await runtime.cut({ ...context, base, tools: [tool] })
const markerDirectory = await navigator.storage.getDirectory()
const marker = await markerDirectory.getFileHandle('native-history-chrome-marker.json', { create: true })
const writable = await marker.createWritable()
await writable.write(JSON.stringify({ operation: 'cut', provider: nativeCapabilities.providerId }))
await writable.close()
const records = await runtime.topologyHistory({ ...context, operationId: 'chrome-native-history-cut', operation: 'cut', inputs: [{ objectId: 'Base', shape: base }, { objectId: 'Tool', shape: tool }], result })
report.capabilities = capabilities
report.nativeCapabilities = nativeCapabilities
report.history = { recordCount: records.length, relations: Object.fromEntries(records.reduce((counts, record) => counts.set(record.relation, (counts.get(record.relation) || 0) + 1), new Map())) }
await runtime.release(result)
await runtime.release(tool)
await runtime.release(base)
report.afterRelease = { shapeCount: runtime.capabilities().shapeCount, kernelReferenceCount: runtime.capabilities().kernelReferenceCount }
await markerDirectory.removeEntry('native-history-chrome-marker.json').catch(() => {})
report.status = report.crossOriginIsolated && capabilities.status === 'ready' && nativeCapabilities.availability === 'available' && nativeCapabilities.operations.includes('cut') && records.length > 0 && report.afterRelease.shapeCount === 0 && report.afterRelease.kernelReferenceCount === 0 ? 'pass' : 'failed'
} catch (error) {
report.status = 'failed'
report.error = error instanceof Error ? error.message : String(error)
} finally {
provider?.dispose()
runtime?.dispose()
}
output.textContent = JSON.stringify(report, null, 2)
await fetch('/__native-history-report', { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify(report) })
if (report.status !== 'pass') throw new Error(report.error || 'Chrome native history harness failed.')
</script>