#!/usr/bin/env node import fs from "node:fs"; import path from "node:path"; import { fileURLToPath } from "node:url"; import { audit64Satisfied } from "./audit64.mjs"; const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), ".."); const docs = path.join(root, "docs"); const dir = path.join(docs, "current", "business-evidence", "desktop-test-cam-testtoolbitrecomputestate-20261101"); const desktop = JSON.parse(fs.readFileSync(path.join(docs, "p6", "cam-tool-controller-chrome.json"), "utf8")); const mobile = JSON.parse(fs.readFileSync(path.join(docs, "p6", "cam-tool-controller-chrome-mobile.json"), "utf8")); const caseId = "desktop-test.Mod.CAM.CAMTests.TestToolBitRecomputeState"; const method = "testToolbitExpressionRecomputeState"; const contract = { schema: "freecad-web-official-case-acceptance-contract/v1", caseId, source: "freecad-source/src/Mod/CAM/CAMTests/TestToolBitRecomputeState.py", enabledOfficialMethods: 1, prerequisites: [ "absolute source and builtin endmill.fcstd asset paths resolve in the CAM worker", "PartDesign::Body is registered before FCStd restore and its Shape property is available", "GuiUp is false and the socketpair-free asyncio loop adapter supports PathTestWithAssets", "the official method creates and closes its own document without leaking document objects", ], passConditions: [ "the official testToolbitExpressionRecomputeState method passes in desktop and mobile browser workers", "the source FCStd fixture selects a PartDesign Body with Shape, and Part::FeaturePython exposes Shape", "the Python worker reports no leaked documents, page errors, overflow or external requests", "the 64-workbench audit passes on both viewports", "save/reopen is inapplicable because the official test closes its temporary document and does not persist it", ], failureClassification: { prerequisite: "source, asset, module registration, document or asyncio setup fails before the official method", product: "the official unitless-expression recompute assertion fails after prerequisites pass", presentation: "viewport, network or console failure", audit: "workbench audit failure", }, persistence: { applicable: false, reason: "the official test creates an in-memory document and closes it in tearDown" }, }; function result(report) { return report.cases.centroid.state.response?.result; } function complete(report) { const r = result(report); const binding = r?.preflight?.binding; const body = binding?.sourceDocument?.selected; const tests = r?.additionalOfficialMethods?.tests; return ( report.result === "pass" && r?.ok === true && r?.preflight?.passed === true && r?.additionalOfficialMethods?.caseId === caseId && r?.additionalOfficialMethods?.expected === 1 && Array.isArray(tests) && tests.length === 1 && tests[0]?.name === method && tests[0]?.passed === true && binding?.typeId === "'Part::FeaturePython'" && binding?.hasShape === true && body?.typeId === "'PartDesign::Body'" && body?.hasShape === true && binding?.makeBodyResult?.typeId === "'PartDesign::Body'" && binding?.makeBodyResult?.hasShape === true && r?.guiUp?.[0] === "bool" && r?.guiUp?.[1] === false && r?.documentCountBefore === 0 && r?.documentCountAfter === 0 && r?.resourcesReleased === true && report.cases.layout.state.crossOriginIsolated === true && report.cases.layout.state.bodyOverflow === false && report.cases.layout.state.propertiesInViewport === true && report.network.externalRequestCount === 0 && report.network.httpFailures.length === 0 && report.exceptions.length === 0 && report.audit64.status === "passed" && audit64Satisfied(report.audit64) && report.audit64.failures === 0 ); } const passed = complete(desktop) && complete(mobile); const profile = { schema: "freecad-web-official-case-profile/v1", caseId, status: passed ? "passed" : "incomplete", sourceMapped: true, implementationStatus: "native_web_owner_ready", integrationStatus: passed ? "passed" : "integration_pending", acceptancePassed: passed, nativeResult: { desktop: result(desktop)?.additionalOfficialMethods, mobile: result(mobile)?.additionalOfficialMethods, sourceBodyType: result(desktop)?.preflight?.binding?.sourceDocument?.selected, toolObjectType: result(desktop)?.preflight?.binding?.typeId, }, preflight: result(desktop)?.preflight, officialMethods: { expected: 1, desktop: result(desktop)?.additionalOfficialMethods?.tests, mobile: result(mobile)?.additionalOfficialMethods?.tests }, viewports: { desktop: { viewport: desktop.viewport, layout: desktop.cases.layout.state, pageErrors: desktop.exceptions, overflow: desktop.cases.layout.state.bodyOverflow }, mobile: { viewport: mobile.viewport, layout: mobile.cases.layout.state, pageErrors: mobile.exceptions, overflow: mobile.cases.layout.state.bodyOverflow }, }, audit64: { desktop: desktop.audit64, mobile: mobile.audit64 }, persistence: contract.persistence, evidence: [ "acceptance-contract.json", "cam-tool-controller-native-desktop.json", "cam-tool-controller-native-mobile.json", "cam-tool-controller-browser-desktop.json", "cam-tool-controller-browser-mobile.json", "workbench-surface-audit-desktop.json", "workbench-surface-audit-mobile.json", "cam-tool-controller-desktop.png", "cam-tool-controller-mobile.png", ].map((file) => `docs/current/business-evidence/desktop-test-cam-testtoolbitrecomputestate-20261101/${file}`), }; fs.mkdirSync(dir, { recursive: true }); fs.writeFileSync(path.join(dir, "acceptance-contract.json"), `${JSON.stringify(contract, null, 2)}\n`); fs.writeFileSync(path.join(dir, "desktop-test-cam-toolbit-recompute-state-profile.json"), `${JSON.stringify(profile, null, 2)}\n`); console.log(JSON.stringify({ status: profile.status, method, desktop: profile.officialMethods.desktop?.[0]?.passed, mobile: profile.officialMethods.mobile?.[0]?.passed, audit64: [profile.audit64.desktop.records, profile.audit64.mobile.records] })); process.exitCode = passed ? 0 : 1;