4 lines
3.3 KiB
JavaScript
4 lines
3.3 KiB
JavaScript
#!/usr/bin/env node
|
|
import crypto from "node:crypto"; import assert from "node:assert/strict"; import fs from "node:fs"; import path from "node:path"; import { createRequire } from "node:module"; import { pathToFileURL } from "node:url";
|
|
const root = path.resolve(path.dirname(new URL(import.meta.url).pathname), ".."); const build = path.resolve(process.argv[2] ?? path.join(root, "freecad-source/build-web/configure/bin")); globalThis.__dirname = `${build}${path.sep}`; globalThis.require = createRequire(import.meta.url); const loader = await import(pathToFileURL(path.join(build, "FreeCADWebMaterialPythonKernelProbe.js"))); const kernel = await loader.default({ wasmBinary: fs.readFileSync(path.join(build, "FreeCADWebMaterialPythonKernelProbe.wasm")) }); const c = (name, type = "number", argTypes = [], args = []) => kernel.ccall(name, type, argTypes, args); const state = () => ({ name: c("fc_web_material_python_name", "string"), uuidPresent: c("fc_web_material_python_uuid", "string").length > 0, resourcesReleased: c("fc_web_material_python_resources_released") }); const run = (name) => ({ run: c("fc_web_material_python_api_validate", "number", ["string"], [name]), state: state(), code: c("fc_web_material_python_error_code", "string"), message: c("fc_web_material_python_error_message", "string") }); const baseline = run("Web Python Fixture"); const rejected = run(""); const recovered = run("Web Python Fixture"); const repeatedReject = run(""); const hash = (value) => crypto.createHash("sha256").update(JSON.stringify(value)).digest("hex"); const before = hash(baseline.state); const after = hash(recovered.state); assert.equal(baseline.run, 1); assert.equal(rejected.run, 0); assert.equal(rejected.code, "invalid_argument"); assert.match(rejected.message, /Name must not be empty/); assert.equal(recovered.run, 1); assert.equal(before, after); assert.equal(repeatedReject.code, rejected.code); const report = { schema: "freecad-web-p6-material-action-03-recovery/v1", taskId: "FW-P6-MAT-ACT-03-D", module: "Material", action: "python-api", result: "pass", invalidInput: { field: "Name", value: "", inputSha256: crypto.createHash("sha256").update("").digest("hex") }, baseline, rejected, repeatedReject, recovered, recovery: { unchangedAfterReject: before === after, repeatedErrorStable: rejected.code === repeatedReject.code, resourcesReleased: recovered.state.resourcesReleased === 1 }, state: { beforeSha256: before, afterRejectSha256: hash(rejected.state), afterRecoverySha256: after }, commands: ["node tools/run_p6_material_action03_recovery_smoke.mjs freecad-source/build-web/configure/bin"], artifacts: { kernel: "docs/p6/material-action-03-kernel.json", workerLog: "docs/freecad-p6-material-action-03-d-recovery.log" }, boundaries: ["Only empty Material.Name recovery is covered; manager library and concurrent mutation remain out of scope."] }; fs.writeFileSync(path.join(root, "docs/p6/material-action-03-recovery.json"), `${JSON.stringify(report, null, 2)}\n`); fs.writeFileSync(path.join(root, "docs/freecad-p6-material-action-03-d-recovery.log"), `${JSON.stringify({ result: report.result, rejectedCode: rejected.code, unchangedAfterReject: report.recovery.unchangedAfterReject, repeatedErrorStable: report.recovery.repeatedErrorStable })}\n`); console.log(JSON.stringify({ result: report.result, rejectedCode: rejected.code, unchangedAfterReject: report.recovery.unchangedAfterReject }));
|