Files
FreeCADWasmDev/tools/run_p6_partdesign_action04_facade_r1.mjs
wangdequan 9a7c4f0335 Save FreeCAD Web workspace sources and user validation evidence
IFC native binding remains incomplete; preserve accurate test results.
2026-09-15 22:01:58 +08:00

7 lines
3.1 KiB
JavaScript

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 fp = process.argv[2]; const build = path.resolve(process.argv[3] ?? path.join(root, "freecad-source/build-web/configure/bin")); const f = await import(pathToFileURL(path.resolve(fp))); const e = await import(pathToFileURL(path.join(path.dirname(path.resolve(fp)), "facade-envelope.js"))); globalThis.__dirname = `${build}${path.sep}`; globalThis.require = createRequire(import.meta.url); const loader = await import(pathToFileURL(path.join(build, "FreeCADWebPartDesignRuntimeProbe.js"))); const kernel = await loader.default({ wasmBinary: fs.readFileSync(path.join(build, "FreeCADWebPartDesignRuntimeProbe.wasm")), print: () => {}, printErr: () => {} }); const q = new e.FacadeSerialQueue(); const dispatch = (request, source = kernel) => q.dispatch(request, (payload, signal) => f.handlePartDesignSave(payload, signal, source)); const success = await dispatch(f.createPartDesignSaveRequest("pdn-act04-r1-success")); const expectedError = await dispatch(f.createPartDesignSaveRequest("pdn-act04-r1-error", { ...f.PARTDESIGN_SAVE_FIXTURE, path: "/tmp/Bad.FCStd" })); const duplicate = await dispatch(f.createPartDesignSaveRequest("pdn-act04-r1-success")); const cancelRequest = f.createPartDesignSaveRequest("pdn-act04-r1-cancel"); const cancelledPromise = dispatch(cancelRequest, new Promise(resolve => setTimeout(() => resolve(kernel), 0))); const cancelAccepted = q.cancel(e.createCancel("pdn-act04-r1-cancel-message", cancelRequest.requestId, "partdesign-save")); const cancelled = await cancelledPromise; const after = await dispatch(f.createPartDesignSaveRequest("pdn-act04-r1-after")); const semantic = value => value.kind === "result" ? { ...value.result, sizePositive: value.result.size > 0, size: undefined } : value; assert.equal(success.kind, "result"); assert.equal(expectedError.error.code, "invalid_path"); assert.equal(duplicate.error.code, "duplicate_request"); assert.equal(cancelAccepted, true); assert.equal(cancelled.error.code, "cancelled"); assert.deepEqual(semantic(after), semantic(success)); const report = { schema: "freecad-web-p6-partdesign-action-04-facade-recovery/v1", taskId: "FW-P6-PDN-ACT-04-E", module: "PartDesign", action: "save/reopen", result: "pass", responses: { success, expectedError, duplicate, cancelled, after }, semanticReplayEqual: true, sequencing: { maxActive: 1, requestCount: 5, cancelAccepted }, schemaChecks: { noNativePointers: !JSON.stringify({ success, expectedError, duplicate, cancelled, after }).match(/pointer|native|handle/i) } }; fs.writeFileSync(path.join(root, "docs/p6/partdesign-action-04-facade-r1.json"), `${JSON.stringify(report, null, 2)}\n`); fs.writeFileSync(path.join(root, "docs/freecad-p6-partdesign-action-04-e-r1-facade.log"), `${JSON.stringify({ result: "pass", semanticReplayEqual: true, requestCount: 5, cancelAccepted })}\n`); console.log(JSON.stringify({ result: "pass", semanticReplayEqual: true, requestCount: 5, cancelAccepted }));