Files
FreeCADWasmDev/tools/part-desktop-alias-cases.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

51 lines
2.6 KiB
JavaScript

import assert from "node:assert/strict";
import fs from "node:fs";
import { registerHooks } from "node:module";
import { fileURLToPath } from "node:url";
import ts from "../web/node_modules/typescript/lib/typescript.js";
const hooks = registerHooks({
resolve(specifier, context, next) {
if (specifier.endsWith("?worker&url"))
return { url: `data:text/javascript,export default ${JSON.stringify(specifier)}`, shortCircuit: true };
if (specifier.startsWith(".") && specifier.endsWith(".js") && context.parentURL?.includes("/web/src/"))
return next(specifier.slice(0, -3) + ".ts", context);
return next(specifier, context);
},
load(url, context, next) {
if (url.endsWith(".ts")) return { format: "module", shortCircuit: true,
source: ts.transpileModule(fs.readFileSync(fileURLToPath(url), "utf8"), {
compilerOptions: { target: ts.ScriptTarget.ES2022, module: ts.ModuleKind.ESNext },
}).outputText };
return next(url, context);
},
});
const { DesktopCommandDispatcher } = await import("../web/src/desktop-command-dispatcher.ts");
const index = JSON.parse(fs.readFileSync("web/public/api/desktop-command-routes.json", "utf8"));
globalThis.fetch = async () => ({ ok: true, json: async () => index });
const calls = [];
const dispatcher = new DesktopCommandDispatcher({ request: async (...args) => {
calls.push(args);
return { kind: "error", requestId: "native-boundary", error: { code: "test_boundary" } };
} });
for (const command of ["Part_CheckGeometry", "Part_Builder"]) {
const record = { id: `OpenSCAD:desktop:${command}`, module: "OpenSCAD", command };
for (const args of [{}, { activeTask: true }, { selection: [{ documentId: "Other", object: "Box" }] }]) {
const response = await dispatcher.execute(record, args, "Current");
assert.equal(response.kind, "error");
assert.equal(response.error.code, "invalid_request");
}
assert.equal(calls.length, command === "Part_Builder" ? 1 : 0);
const args = command === "Part_CheckGeometry"
? { selection: [{ documentId: "Current", object: "Box" }] }
: { points: [[0, 0, 0], [1, 0, 0], [0, 1, 0]] };
await dispatcher.execute(record, args, "Current");
const [module, route, payload, document] = calls.at(-1);
assert.equal(module, "Part");
assert.equal(route, "part.pythonFamilyBatch");
assert.equal(document, "Current");
assert.equal(payload.records[0].apiId, `Part:desktop:${command}`);
}
console.log("PASS: six invalid alias requests rejected before Worker dispatch; two valid requests preserve canonical Part routing. No native business acceptance claimed.");
hooks.deregister();