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

23 lines
4.7 KiB
HTML

<!doctype html><meta charset="utf-8"><title>Chrome native Thickness 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'
import { NativeOcctHistoryCoordinator } from '/src/facade/nativeHistoryProtocol.ts'
const output = document.querySelector('#result'); const report = { schemaVersion: 1, browserId: 'chrome', executionContext: 'geometry-and-history-workers', crossOriginIsolated: globalThis.crossOriginIsolated === true, status: 'running' }
let runtime, provider, base, result, stage = 'init'
try {
stage = 'initialize'; 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-thickness', documentVersion: 1 }
stage = 'create-box'; base = await runtime.createBox({ ...context, width: 6, length: 6, height: 6 })
stage = 'bitbybit-thickness'; result = await runtime.thickness({ ...context, base, offset: -0.4, removeFaceIndexes: [1], joinType: 'Arc' })
stage = 'quality'; const [quality, mass] = await Promise.all([runtime.qualityReport(result), runtime.massProperties(result)])
const directory = await navigator.storage.getDirectory(); const markerName = 'native-thickness-history-chrome-marker.json'; const marker = await directory.getFileHandle(markerName, { create: true }); const writable = await marker.createWritable(); await writable.write(JSON.stringify({ operation: 'thickness', provider: nativeCapabilities.providerId })); await writable.close(); const markerText = await (await marker.getFile()).text()
stage = 'native-history'; const baseStep = await runtime.exportStep(base, 'Base.step'); const execution = await new NativeOcctHistoryCoordinator(() => 1).capture(provider, { ...context, operationId: 'chrome-native-thickness-history', operation: 'thickness', objectStep: baseStep.text, offset: -0.4, joinType: 'Arc', faceIndex: 1 }); if (execution.status !== 'completed' || !execution.response) throw new Error(`Native Thickness history ${execution.status}.`); const records = execution.response.history.records
const relations = { modified: records.filter((record) => record.relation === 'modified').length, generated: records.filter((record) => record.relation === 'generated').length, deleted: records.filter((record) => record.relation === 'deleted').length }
report.capabilities = capabilities; report.nativeCapabilities = nativeCapabilities; report.history = { recordCount: records.length, relations, sourceObjects: [...new Set(records.map((record) => record.source === 'object' ? 'Base' : 'Tool'))] }; 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 = { markerCreated: true, markerSuite: JSON.parse(markerText).operation, markerRemoved: false }
await directory.removeEntry(markerName); report.opfs.markerRemoved = true; await runtime.release(result); result = undefined; await runtime.release(base); base = undefined; report.afterRelease = { shapeCount: runtime.capabilities().shapeCount, kernelReferenceCount: runtime.capabilities().kernelReferenceCount }
report.status = report.crossOriginIsolated && capabilities.status === 'ready' && nativeCapabilities.operations.includes('thickness') && records.length > 0 && relations.modified > 0 && quality.solids === 1 && mass.volume > 0 && report.result.nativeStructuralValid && report.result.nativeSolids === 1 && report.result.nativeVolume > 0 && report.opfs.markerRemoved && report.afterRelease.shapeCount === 0 && report.afterRelease.kernelReferenceCount === 0 ? 'pass' : 'failed'
} catch (error) { report.status = 'failed'; report.error = `${stage}: ${error instanceof Error ? `${error.name}: ${error.message}` : String(error)}` } finally { if (result) await runtime?.release(result).catch(() => {}); if (base) await runtime?.release(base).catch(() => {}); provider?.dispose(); runtime?.dispose() }
output.textContent = JSON.stringify(report, null, 2); await fetch('/__native-thickness-history-report', { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify(report) }); if (report.status !== 'pass') throw new Error(report.error || 'Chrome native Thickness history harness failed.')
</script>