28 lines
2.3 KiB
JavaScript
28 lines
2.3 KiB
JavaScript
import { existsSync } from 'node:fs'
|
|
import { readFile } from 'node:fs/promises'
|
|
import { spawnSync } from 'node:child_process'
|
|
import { resolve } from 'node:path'
|
|
|
|
const root = resolve(new URL('..', import.meta.url).pathname)
|
|
const executable = process.env.FREECAD_CMD || resolve(root, '.cache/freecad/install-desktop/bin/FreeCADCmd')
|
|
const sysroot = resolve(root, '.cache/freecad/sysroot')
|
|
const scriptPath = resolve(root, 'scripts/freecad-property-boollist-mutation.py')
|
|
const outputPath = resolve(root, 'config/freecad-property-boollist-mutation.json')
|
|
if (!existsSync(executable)) throw new Error(`FreeCAD PropertyBoolList mutation executable is missing: ${executable}`)
|
|
const execution = spawnSync(executable, ['--python-path', resolve(sysroot, 'usr/lib/python3/dist-packages'), scriptPath], {
|
|
cwd: root,
|
|
encoding: 'utf8',
|
|
timeout: 120_000,
|
|
maxBuffer: 32 * 1024 * 1024,
|
|
env: {
|
|
...process.env,
|
|
FREECAD_PROPERTY_BOOLLIST_MUTATION_OUTPUT: outputPath,
|
|
PYTHONPATH: `${resolve(sysroot, 'usr/lib/python3/dist-packages')}${process.env.PYTHONPATH ? `:${process.env.PYTHONPATH}` : ''}`,
|
|
LD_LIBRARY_PATH: `${resolve(sysroot, 'usr/lib/x86_64-linux-gnu')}${process.env.LD_LIBRARY_PATH ? `:${process.env.LD_LIBRARY_PATH}` : ''}`,
|
|
},
|
|
})
|
|
const output = `${execution.stdout || ''}\n${execution.stderr || ''}`
|
|
if (execution.error || execution.status !== 0 || !output.includes('FREECAD_PROPERTY_BOOLLIST_MUTATION_RESULT=')) throw new Error(`FreeCAD PropertyBoolList mutation probe failed with status ${execution.status}: ${execution.error?.message || output.trim()}`)
|
|
const report = JSON.parse(await readFile(outputPath, 'utf8'))
|
|
console.log(JSON.stringify({ status: report.status, output: 'config/freecad-property-boollist-mutation.json', cases: report.cases.map(({ objectTypeId, mode, before, touchedAfterEdit, edited, touchedAfterRestore, restored, valueRestored, shapeRestored, objectsRestored }) => ({ objectTypeId, mode, values: { before: before.value, touchedAfterEdit: touchedAfterEdit.value, edited: edited.value, touchedAfterRestore: touchedAfterRestore.value, restored: restored.value }, states: { before: before.objectState, touchedAfterEdit: touchedAfterEdit.objectState, edited: edited.objectState, touchedAfterRestore: touchedAfterRestore.objectState, restored: restored.objectState }, valueRestored, shapeRestored, objectsRestored })) }, null, 2))
|