71 lines
8.0 KiB
HTML
71 lines
8.0 KiB
HTML
<!doctype html>
|
|
<meta charset="utf-8">
|
|
<title>Chrome native Pocket 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 {
|
|
const [baseStep, profileStep] = await Promise.all([
|
|
fetch('/native-pocket-base.step').then((response) => response.ok ? response.text() : Promise.reject(new Error(`Pocket base fixture failed: ${response.status}`))),
|
|
fetch('/native-pocket-profile.step').then((response) => response.ok ? response.text() : Promise.reject(new Error(`Pocket profile fixture failed: ${response.status}`))),
|
|
])
|
|
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-pocket', documentVersion: 1 }
|
|
const base = await runtime.importShape({ ...context, format: 'step', text: baseStep })
|
|
const profile = await runtime.importShape({ ...context, format: 'step', text: profileStep })
|
|
const result = await runtime.pocket({ ...context, base, profile: { outer: [[0, 0, 0], [2, 0, 0], [2, 3, 0], [0, 3, 0]] }, length: 5, direction: [0, 0, 1], reversed: false, symmetricToPlane: false })
|
|
const markerDirectory = await navigator.storage.getDirectory()
|
|
const marker = await markerDirectory.getFileHandle('native-pocket-history-chrome-marker.json', { create: true })
|
|
const writable = await marker.createWritable()
|
|
await writable.write(JSON.stringify({ operation: 'pocket', provider: nativeCapabilities.providerId }))
|
|
await writable.close()
|
|
const records = await runtime.topologyHistory({ ...context, operationId: 'chrome-native-pocket-history', operation: 'pocket', inputs: [{ objectId: 'Base', shape: base }, { objectId: 'Profile', shape: profile }], direction: [0, 0, 5], result })
|
|
const twoSidedBase = await runtime.createBox({ ...context, width: 10, length: 8, height: 10, center: [0, 0, 0], originOnCenter: true })
|
|
const firstSideTool = await runtime.pad({ ...context, profile: { outer: [[0, 0, 0], [2, 0, 0], [2, 3, 0], [0, 3, 0]] }, length: 4, direction: [0, 0, 1] })
|
|
const secondSideTool = await runtime.pad({ ...context, profile: { outer: [[0, 0, 0], [2, 0, 0], [2, 3, 0], [0, 3, 0]] }, length: 4, direction: [0, 0, 1], reversed: true })
|
|
const fusedTool = await runtime.union({ ...context, shapes: [firstSideTool, secondSideTool] })
|
|
const twoSidedResult = await runtime.cut({ ...context, base: twoSidedBase, tools: [fusedTool] })
|
|
const twoSidedRecords = await runtime.topologyHistory({ ...context, operationId: 'chrome-native-pocket-two-sided-history', operation: 'pocket', inputs: [{ objectId: 'BaseTwoSided', shape: twoSidedBase }, { objectId: 'Profile', shape: profile }], stages: [{ stageId: 'Pocket:stage:0', operation: 'pocket', inputObjectIds: ['BaseTwoSided', 'Profile'], resultObjectId: 'PocketTwoSided', ordinal: 0 }], featureSides: [{ direction: [0, 0, 4] }, { direction: [0, 0, -4] }], direction: [0, 0, 4], result: twoSidedResult })
|
|
const twoSidedStages = twoSidedRecords.stageCaptures || []
|
|
const twoSidedQuality = await runtime.qualityReport(twoSidedResult)
|
|
const stageCaptures = records.stageCaptures || []
|
|
const modified = records.filter((record) => record.relation === 'modified').length
|
|
const generated = records.filter((record) => record.relation === 'generated').length
|
|
const deleted = records.filter((record) => record.relation === 'deleted').length
|
|
report.capabilities = capabilities
|
|
report.nativeCapabilities = nativeCapabilities
|
|
report.history = { recordCount: records.length, sourceObjects: [...new Set(stageCaptures.flatMap((stage) => stage.records.map((record) => record.sourceObjectId)))].sort(), relations: { modified, generated, deleted }, stages: stageCaptures.map((stage) => ({ stageId: stage.stageId, operation: stage.operation, inputObjectIds: stage.inputObjectIds, resultObjectId: stage.resultObjectId, ordinal: stage.ordinal, topologyEntries: stage.topology.entries.length, recordCount: stage.records.length })) }
|
|
report.twoSidedHistory = { recordCount: twoSidedRecords.length, structuralValid: twoSidedQuality.structuralValid, solids: twoSidedQuality.solids, sourceObjects: [...new Set(twoSidedStages.flatMap((stage) => stage.records.map((record) => record.sourceObjectId)))].sort(), stages: twoSidedStages.map((stage) => ({ stageId: stage.stageId, operation: stage.operation, inputObjectIds: stage.inputObjectIds, resultObjectId: stage.resultObjectId, ordinal: stage.ordinal, topologyEntries: stage.topology.entries.length, recordCount: stage.records.length })) }
|
|
await runtime.release(twoSidedResult)
|
|
await runtime.release(fusedTool)
|
|
await runtime.release(secondSideTool)
|
|
await runtime.release(firstSideTool)
|
|
await runtime.release(twoSidedBase)
|
|
await runtime.release(result)
|
|
await runtime.release(profile)
|
|
await runtime.release(base)
|
|
report.afterRelease = { shapeCount: runtime.capabilities().shapeCount, kernelReferenceCount: runtime.capabilities().kernelReferenceCount }
|
|
await markerDirectory.removeEntry('native-pocket-history-chrome-marker.json').catch(() => {})
|
|
report.status = report.crossOriginIsolated && capabilities.status === 'ready' && nativeCapabilities.availability === 'available' && nativeCapabilities.operations.includes('pocket') && nativeCapabilities.operations.includes('pad') && nativeCapabilities.operations.includes('fuse') && nativeCapabilities.operations.includes('cut') && records.length > 0 && modified > 0 && generated + deleted > 0 && stageCaptures.length === 2 && stageCaptures[0].operation === 'pad' && stageCaptures[0].inputObjectIds.join(',') === 'Profile' && stageCaptures[0].records.length > 0 && stageCaptures[0].topology.entries.length > 0 && stageCaptures[1].operation === 'cut' && stageCaptures[1].inputObjectIds.join(',') === `Base,${stageCaptures[0].resultObjectId}` && stageCaptures[1].records.length === records.length && stageCaptures[1].topology.entries.length > 0 && report.history.sourceObjects.includes('Base') && report.history.sourceObjects.includes('Profile') && report.history.sourceObjects.includes(stageCaptures[0].resultObjectId) && twoSidedRecords.length > 0 && twoSidedQuality.structuralValid && twoSidedQuality.solids === 1 && twoSidedStages.length === 4 && twoSidedStages[0].operation === 'pad' && twoSidedStages[0].inputObjectIds.join(',') === 'Profile' && twoSidedStages[0].topology.entries.length > 0 && twoSidedStages[1].operation === 'pad' && twoSidedStages[1].inputObjectIds.join(',') === 'Profile' && twoSidedStages[1].topology.entries.length > 0 && twoSidedStages[2].operation === 'fuse' && twoSidedStages[2].inputObjectIds.join(',') === `${twoSidedStages[0].resultObjectId},${twoSidedStages[1].resultObjectId}` && twoSidedStages[2].topology.entries.length > 0 && twoSidedStages[3].operation === 'cut' && twoSidedStages[3].inputObjectIds.join(',') === `BaseTwoSided,${twoSidedStages[2].resultObjectId}` && twoSidedStages[3].resultObjectId === 'PocketTwoSided' && twoSidedStages[3].topology.entries.length > 0 && report.twoSidedHistory.sourceObjects.includes('BaseTwoSided') && report.twoSidedHistory.sourceObjects.includes('Profile') && 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-pocket-history-report', { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify(report) })
|
|
if (report.status !== 'pass') throw new Error(report.error || 'Chrome native Pocket history harness failed.')
|
|
</script>
|