#!/usr/bin/env node /** * M4 case 3 replay: desktop-test.Mod.PartDesign.PartDesignTests.TestChamfer. * Transport is hybrid: * - kernel arm: fc_web_partdesign_testsuite("TestChamfer") on the shipped mirror * - UI arm: tools/ui-partdesign-chamfer-native-parity.mjs under the MCP host origin * - audit64: tools/ui-workbench-surface-audit.mjs under the same origin */ import fs from "node:fs"; import path from "node:path"; import { spawn } from "node:child_process"; import { fileURLToPath } from "node:url"; import { startStaticHost } from "../static-host.mjs"; import { loadWasmProbe } from "../wasm-probe-runtime.mjs"; import { auditCoverageComplete } from "../audit64.mjs"; const here = path.dirname(fileURLToPath(import.meta.url)); const root = path.resolve(here, "..", ".."); const distRoot = path.join(root, "web", "dist"); const CASE_ID = "desktop-test.Mod.PartDesign.PartDesignTests.TestChamfer"; const evidenceDir = path.join(root, "web", "docs", "current", "mcp-evidence", `desktop-test-partdesign-testchamfer-${new Date().toISOString().slice(0, 10).replaceAll("-", "")}`); fs.mkdirSync(evidenceDir, { recursive: true }); const host = await startStaticHost(distRoot, "project.html"); const runNode = (script, env) => new Promise((resolve) => { const child = spawn(process.execPath, [path.join(root, "tools", script)], { cwd: root, env: { ...process.env, ...env } }); let out = ""; child.stdout.on("data", (c) => { out += c.toString(); }); child.stderr.on("data", (c) => { out += c.toString(); }); child.once("close", (code) => resolve({ code, output: out.trim() })); }); let kernelArm = null; try { const { kernel } = await loadWasmProbe(path.join(root, "web", "public", "kernel"), "FreeCADWebPartDesignRuntimeProbe"); try { const reply = JSON.parse(String(kernel.ccall("fc_web_partdesign_testsuite", "string", ["string"], ["TestChamfer"]))); kernelArm = { ok: reply.ok, total: reply.total, ran: reply.ran, passed: reply.passed, documentsBefore: reply.documentsBefore, documentsAfter: reply.documentsAfter, resourcesReleased: reply.resourcesReleased, failures: (reply.records ?? []).filter((r) => !r.passed).map((r) => ({ name: r.name, message: String(r.message ?? "").slice(0, 200) })), }; } finally { kernel.PThread?.terminateAllThreads(); } } catch (error) { kernelArm = { error: String(error?.message ?? error) }; } const ui = await runNode("ui-partdesign-chamfer-native-parity.mjs", { FREECAD_BROWSER_ORIGIN: host.origin }); let uiReport = null; const uiReportPath = path.join(root, "docs", "current", "ui-parity-baseline-20261011", "partdesign-chamfer-native-parity.json"); if (fs.existsSync(uiReportPath)) { uiReport = JSON.parse(fs.readFileSync(uiReportPath, "utf8")); fs.copyFileSync(uiReportPath, path.join(evidenceDir, "partdesign-chamfer-native-parity.json")); } const audit = await runNode("ui-workbench-surface-audit.mjs", { FREECAD_BROWSER_ORIGIN: host.origin }); const auditSource = path.join(root, "docs", "current", "ui-parity-baseline-20261011", "workbench-surface-audit.json"); let auditReport = null; if (fs.existsSync(auditSource)) { auditReport = JSON.parse(fs.readFileSync(auditSource, "utf8")); fs.copyFileSync(auditSource, path.join(evidenceDir, "workbench-surface-audit.json")); } const audit64 = { status: audit.code === 0 && auditReport?.status === "passed" && auditCoverageComplete(auditReport) && (auditReport?.failures?.length ?? 1) === 0 ? "passed" : "failed", records: auditReport?.records?.length ?? null, failures: auditReport?.failures?.length ?? null, origin: host.origin, }; const A = (n, ok, actual, expected) => ({ name: n, ok, actual, expected }); const uiPre = uiReport?.preCreate ?? null; const uiDesk = uiReport?.desktop ?? null; const uiMob = uiReport?.mobile ?? null; const assertions = [ A("kernel arm ok", kernelArm?.ok === true, kernelArm?.ok ?? null, true), A("kernel single official method ran", kernelArm?.ran === 1, kernelArm?.ran ?? null, 1), A("kernel method passed", kernelArm?.passed === true, kernelArm?.passed ?? null, true), A("kernel no document leak", kernelArm?.documentsBefore === 0 && kernelArm?.documentsAfter === 0, { before: kernelArm?.documentsBefore ?? null, after: kernelArm?.documentsAfter ?? null }, { before: 0, after: 0 }), A("kernel resources released", kernelArm?.resourcesReleased === true, kernelArm?.resourcesReleased ?? null, true), A("ui parity script exit 0", ui.code === 0, ui.code, 0), A("ui parity status passed", uiReport?.status === "passed", uiReport?.status ?? null, "passed"), A("task panel mounted with base and equal distance", Boolean(uiPre?.baseValue) && uiPre?.typeValue === "Equal distance" && uiPre?.createEnabled === true, uiPre ? { baseValue: uiPre.baseValue, typeValue: uiPre.typeValue, createEnabled: uiPre.createEnabled } : null, { baseValue: "Pad1", typeValue: "Equal distance", createEnabled: true }), A("invalid size disables create", uiReport?.invalidSize?.createDisabled === true, uiReport?.invalidSize ?? null, { createDisabled: true }), A("invalid second distance disables create", uiReport?.invalidSecond?.createDisabled === true, uiReport?.invalidSecond ?? null, { createDisabled: true }), A("chamfer feature created", uiReport?.created === true, uiReport?.created ?? null, true), A("desktop task panel in viewport without overflow", uiDesk?.ready === true && uiDesk?.pageOverflow === false && uiDesk?.taskOverflow === false && uiDesk?.inViewport === true, uiDesk, { ready: true, pageOverflow: false, taskOverflow: false, inViewport: true }), A("mobile task panel in viewport without overflow", uiMob?.pageOverflow === false && uiMob?.taskOverflow === false && uiMob?.inViewport === true, uiMob, { pageOverflow: false, taskOverflow: false, inViewport: true }), A("no page errors in ui arm", (uiReport?.pageErrors ?? []).length === 0, uiReport?.pageErrors ?? [], []), A("audit64 passed", audit64.status === "passed", audit64.status, "passed"), ]; const failed = assertions.filter((a) => !a.ok); const evidence = { schema: "freecad-web-mcp/case-replay/v1", caseId: CASE_ID, capturedAt: new Date().toISOString(), transport: "hybrid", transportReason: "partdesign.testChamfer is not a registry command (case-map: unmapped); the accepted path is the kernel testsuite entry plus the project-shell Chamfer task panel", origin: host.origin, contract: { source: "freecad-source/src/Mod/PartDesign/PartDesignTests/TestChamfer.py", scope: "testChamferCubeToOctahedron asserts 8 major faces for the cube corner chamfer, keeps 8 with UseAllEdges and with a deleted/replaced base link, and asserts 9 with a single-face base", expectedHeadless: { equalDistanceFaces: 8, useAllEdgesFaces: 8, deletedBaseFaceFaces: 8, singleFaceBaseFaces: 9 }, passConditions: ["the official method passes in the WASM kernel with no document leak", "desktop build parity for the same method", "Chamfer task panel creates Chamfer1 through the native owner", "invalid Size 0 and invalid second distance disable create", "workbench renders at 1440x900 and 390x844 with no page errors and no overflow"], }, kernelArm, uiArm: { exitCode: ui.code, report: uiReport, rawOutput: ui.output.slice(-1500) }, audit64, assertions, passed: failed.length === 0, failed, }; const evidencePath = path.join(evidenceDir, "case-replay.json"); fs.writeFileSync(evidencePath, `${JSON.stringify(evidence, null, 1)}\n`); host.close(); console.log(JSON.stringify({ passed: evidence.passed, failed, uiExit: ui.code, audit64: audit64.status, evidence: path.relative(root, evidencePath) }, null, 1)); process.exitCode = evidence.passed ? 0 : 1;