feat: establish reproducible FreeCAD web compatibility baseline
This commit is contained in:
64
scripts/generate-freecad-gui-command-inventory.mjs
Normal file
64
scripts/generate-freecad-gui-command-inventory.mjs
Normal file
@@ -0,0 +1,64 @@
|
||||
import { createHash } from 'node:crypto'
|
||||
import { readFile, writeFile } from 'node:fs/promises'
|
||||
import { resolve } from 'node:path'
|
||||
|
||||
const root = resolve(new URL('..', import.meta.url).pathname)
|
||||
const reportPath = resolve(root, process.env.FREECAD_GUI_COMMAND_REPORT || '.cache/freecad/reference-desktop.json')
|
||||
const outputPath = resolve(root, process.env.FREECAD_GUI_COMMAND_INVENTORY || 'config/freecad-gui-command-inventory.json')
|
||||
const sourceInventory = JSON.parse(await readFile(resolve(root, 'config/freecad-source-inventory.json'), 'utf8'))
|
||||
const reportBytes = await readFile(reportPath)
|
||||
const report = JSON.parse(reportBytes)
|
||||
if (report.baselineId !== 'freecad-1.1.1' || report.freecadVersion !== '1.1.1' || report.guiUp !== true) throw new Error('A verified desktop FreeCAD GUI report is required.')
|
||||
if (!report.guiCommands?.available || !Array.isArray(report.guiCommands.commands)) throw new Error('Desktop report does not contain GUI command observations.')
|
||||
|
||||
const sourceCommandModules = new Map()
|
||||
for (const module of sourceInventory.modules) for (const commandId of module.commandIds) {
|
||||
const modules = sourceCommandModules.get(commandId) || []
|
||||
modules.push(module.name)
|
||||
sourceCommandModules.set(commandId, modules)
|
||||
}
|
||||
const normalizeState = (state) => typeof state === 'boolean' ? state : state && typeof state === 'object' ? 'error' : 'no-action'
|
||||
const unique = (values) => [...new Set(values)].sort()
|
||||
const commands = report.guiCommands.commands.map((command) => {
|
||||
const observations = command.observations || []
|
||||
const emptyStates = unique(observations.map((entry) => normalizeState(entry.emptySelection)))
|
||||
const selectedStates = unique(observations.map((entry) => normalizeState(entry.selectedPartBox)))
|
||||
const selectionSensitive = observations.some((entry) => typeof entry.emptySelection === 'boolean' && typeof entry.selectedPartBox === 'boolean' && entry.emptySelection !== entry.selectedPartBox)
|
||||
return {
|
||||
id: command.id,
|
||||
sourceModules: unique(sourceCommandModules.get(command.id) || ['GuiCore']),
|
||||
workbenches: unique(observations.map((entry) => entry.workbench)),
|
||||
cases: {
|
||||
emptySelection: { states: emptyStates, observed: true },
|
||||
selectedPartBox: { states: selectedStates, observed: true },
|
||||
},
|
||||
selectionSensitive,
|
||||
status: 'runtime-probed',
|
||||
}
|
||||
}).sort((a, b) => a.id.localeCompare(b.id))
|
||||
|
||||
const sourceOnlyCommands = [...sourceCommandModules.entries()]
|
||||
.filter(([id]) => !commands.some((command) => command.id === id))
|
||||
.map(([id, modules]) => ({
|
||||
id,
|
||||
sourceModules: unique(modules),
|
||||
reason: modules.some((module) => ['Cloud', 'JtReader', 'Sandbox', 'TemplatePyMod'].includes(module)) ? 'module-not-built' : 'source-registration-not-loaded',
|
||||
}))
|
||||
.sort((a, b) => a.id.localeCompare(b.id))
|
||||
|
||||
const inventory = {
|
||||
schemaVersion: 1,
|
||||
baseline: { freecadVersion: '1.1.1', commit: '0108fd4b4850cc46e625b60e53cea7a7bbe69f8d' },
|
||||
generatedBy: 'scripts/generate-freecad-gui-command-inventory.mjs',
|
||||
sourceInventory: 'config/freecad-source-inventory.json',
|
||||
runtimeEvidence: {
|
||||
report: '.cache/freecad/reference-desktop.json',
|
||||
reportSha256: createHash('sha256').update(reportBytes).digest('hex'),
|
||||
workbenchCount: report.guiCommands.workbenches.length,
|
||||
},
|
||||
commandCount: commands.length,
|
||||
commands,
|
||||
sourceOnlyCommands,
|
||||
}
|
||||
await writeFile(outputPath, `${JSON.stringify(inventory, null, 2)}\n`, 'utf8')
|
||||
console.log(JSON.stringify({ status: 'gui-command-inventory-generated', output: outputPath, commandCount: commands.length, sourceOnlyCount: sourceOnlyCommands.length }, null, 2))
|
||||
Reference in New Issue
Block a user