Files
Web_FreeCAD_Bitbybit/scripts/check-freecad-property-linksubhidden-roundtrip.mjs
wangdequan 54649da16c
Some checks are pending
real-verification / chrome (push) Waiting to run
real-verification / freecad-oracle (push) Waiting to run
real-verification / wasm (push) Waiting to run
feat: close link sub property codecs
2026-08-17 21:37:33 -04:00

23 lines
5.4 KiB
JavaScript

import { createHash } from 'node:crypto'
import { isDeepStrictEqual } from 'node:util'
import { readFile, stat } from 'node:fs/promises'
import { resolve } from 'node:path'
const root = resolve(new URL('..', import.meta.url).pathname)
const report = JSON.parse(await readFile(resolve(root, 'config/freecad-property-linksubhidden-roundtrip.json'), 'utf8'))
const fail = (message) => { throw new Error(`FreeCAD PropertyLinkSubHidden roundtrip check failed: ${message}`) }
if (report.schemaVersion !== 1 || report.status !== 'pass' || report.baselineId !== 'freecad-1.1.1-property-linksubhidden-roundtrip' || report.freecadVersion !== '1.1.1' || report.gitCommit !== '0108fd4b4850cc46e625b60e53cea7a7bbe69f8d' || report.propertyType !== 'App::PropertyLinkSubHidden') fail('baseline is invalid')
const initial = { schemaVersion: 1, objectId: 'ColorSourceA', subElements: ['Face1', 'Face3'] }
const target = { schemaVersion: 1, objectId: 'ColorSourceB', subElements: ['Face5'] }
const objectSet = [{ name: 'LinkGroupProbe', typeId: 'App::LinkGroup' }, { name: 'ColorSourceA', typeId: 'Part::Feature' }, { name: 'ColorSourceB', typeId: 'Part::Feature' }]
for (const [phase, snapshot, value] of [['nativeInitial', report.nativeInitial, { object: 'ColorSourceA', subElements: ['Face1', 'Face3'] }], ['nativeReopened', report.nativeAfter?.reopened, { object: 'ColorSourceB', subElements: ['Face5'] }], ['nativeResaved', report.nativeAfter?.resaved, { object: 'ColorSourceB', subElements: ['Face5'] }]]) {
if (!isDeepStrictEqual(snapshot?.objectSet, objectSet) || snapshot.object?.name !== 'LinkGroupProbe' || snapshot.object.typeId !== 'App::LinkGroup' || snapshot.object.propertyName !== 'ColoredElements' || snapshot.object.propertyTypeId !== 'App::PropertyLinkSubHidden' || snapshot.object.group !== ' Link' || !isDeepStrictEqual(snapshot.object.value, value) || !isDeepStrictEqual(snapshot.object.propertyStatus, ['LockDynamic', '26']) || !isDeepStrictEqual(snapshot.object.editorMode, ['Hidden']) || !isDeepStrictEqual(snapshot.object.state, ['Up-to-date']) || snapshot.object.statusString !== 'Valid' || !isDeepStrictEqual(snapshot.object.outList, [])) fail(`${phase} native hidden sub-link semantics changed`)
if (snapshot.object.shape?.applicable !== false) fail(`${phase} owner Shape boundary changed`)
for (const targetName of ['ColorSourceA', 'ColorSourceB']) { const item = snapshot.targets?.[targetName]; if (item?.typeId !== 'Part::Feature' || !isDeepStrictEqual(item.inList, []) || item.shape?.applicable !== true || item.shape.isNull !== false || item.shape.valid !== true || item.shape.shapeType !== 'Solid' || item.shape.solids !== 1 || !/^[0-9a-f]{64}$/.test(item.shape.brepSha256)) fail(`${phase} ${targetName} changed`) }
}
if (report.web.before?.typeId !== 'App::PropertyLinkSubHidden' || report.web.before.element !== 'LinkSub' || report.web.after?.typeId !== 'App::PropertyLinkSubHidden' || report.web.after.element !== 'LinkSub' || report.web.targetMarkedTouched !== true || !isDeepStrictEqual(report.web.initialDependencyTargets, ['ColorSourceA']) || !isDeepStrictEqual(report.web.webDependencyTargets, ['ColorSourceA']) || report.web.hiddenDependencyMetadataPreserved !== true || report.web.webOutputMatches !== true || report.web.objectSetPreserved !== true || report.web.semanticObjectsPreserved !== true || report.web.opaqueEntriesPreserved !== true || !Number.isSafeInteger(report.web.opaquePathsPreserved) || report.web.opaquePathsPreserved < 1) fail('Web edit did not preserve the native archive boundary')
if (!isDeepStrictEqual(report.classification?.requestedValue, target) || !isDeepStrictEqual(report.classification.webValue, target) || !isDeepStrictEqual(report.classification.reopenedValue, target) || !isDeepStrictEqual(report.classification.resavedValue, target) || report.classification.nativeOutputMatches !== true || report.classification.hiddenLinksPreserved !== true || !isDeepStrictEqual(report.classification.nativeResavedDependencyTargets, ['ColorSourceB']) || report.classification.nativeDependencyMetadataNormalized !== true || report.classification.targetShapeStructurePreserved !== true || report.classification.ownerShapePreserved !== true || report.classification.unknownSemanticDrift !== false || report.classification.zeroUnknownDrift !== true || report.classification.nativeTargetBrepHashes?.length !== 3) fail('roundtrip classification is incomplete')
for (const hashes of report.classification.nativeTargetBrepHashes) if (!/^[0-9a-f]{64}$/.test(hashes.ColorSourceA) || !/^[0-9a-f]{64}$/.test(hashes.ColorSourceB)) fail('native target BREP evidence is incomplete')
for (const archive of Object.values(report.archives ?? {})) { const path = resolve(root, archive.path ?? ''); const content = await readFile(path); if ((await stat(path)).size !== archive.bytes || createHash('sha256').update(content).digest('hex') !== archive.sha256) fail(`archive is stale: ${archive.path}`) }
console.log(JSON.stringify({ status: 'freecad-property-linksubhidden-roundtrip-pass', values: { nativeInitial: initial, webEdited: report.classification.webValue, nativeReopened: report.classification.reopenedValue, nativeResaved: report.classification.resavedValue }, hiddenLinksPreserved: report.classification.hiddenLinksPreserved, targetShapeStructurePreserved: report.classification.targetShapeStructurePreserved, opaquePathsPreserved: report.web.opaquePathsPreserved, zeroUnknownDrift: report.classification.zeroUnknownDrift }, null, 2))