Files
FreeCADWasmDev/tools/run_p6_cam_chrome.mjs
wangdequan dd7a940c37 Derive workbench audit coverage from modules x viewports
The workbench surface audit scrapes module names out of the web module
registry and iterates two viewports, so its record count is a product,
never a constant. Removing OpenSCAD dropped the registry from 32 to 31
modules and moved the expected count from 64 to 62, while 65 places in
the tooling still asserted 64 - re-running the audit would have failed
every gate with no actual regression behind it.

Add tools/audit64.mjs as the single owner of the coverage rule:
auditCoverage(), auditCoverageComplete() and audit64Satisfied(). The
success test requires records === expectedRecords only when the snapshot
carries an expectation, so freshly produced evidence (62 records plus
expectedRecords 62) and historical evidence captured before the removal
(64 records, no expectation) are both judged against their own coverage.
The 111 archived CAM snapshots stay valid instead of being reclassified
as regressions, and a real 62-vs-64 shortfall still fails.

Converted callers: 56 build_cam_*_profile.mjs, 5 tools/mcp/replay-*.mjs,
close-official-case.mjs, run_partdesign_official_suite.mjs,
run_p6_assembly_testcore_chrome.mjs, run_p6_bim_arch_component_chrome.mjs
and run-official-native-shape-profile.mjs. The producer in
run_p6_cam_chrome.mjs now writes the derived expectedRecords so downstream
gates compare against an authoritative expectation.

Also fix artifacts that would have revived the removed module:
sync-assets.mjs unconditionally re-copied the OpenSCAD runtime probe into
public/kernel on every sync-kernel run, and its sources still exist in the
build tree. Drop that loop, the dead displayOwners entry in
audit-geometry-boundary.mjs, and the 14 MB vendored openscad-wasm.

Keep the parity matrix self-consistent: module_count follows rows (31),
and the business completion audit derives its expected module count from
the matrix instead of hardcoding 32, which would otherwise make completion
unreachable.

Rebuilt dist and re-ran the audit against an ephemeral isolated static
host: 31 modules, 2 viewports, 62 records, 0 failures.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 09:11:21 +08:00

450 lines
57 KiB
JavaScript

#!/usr/bin/env node
import crypto from "node:crypto";
import fs from "node:fs";
import os from "node:os";
import path from "node:path";
import { spawn } from "node:child_process";
import { fileURLToPath } from "node:url";
import { auditCoverage, auditCoverageComplete } from "./audit64.mjs";
import { findChrome, startStaticHost } from "./static-host.mjs";
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
const distRoot = path.join(root, "web", "dist");
const docsRoot = path.join(root, "docs");
const isCentroid = process.env.FREECAD_CAM_CASE === "centroid";
const isCentroidPost = process.env.FREECAD_CAM_CASE === "centroid-post";
const isDressup = process.env.FREECAD_CAM_CASE === "dressup";
const isFanuc = process.env.FREECAD_CAM_CASE === "fanuc";
const isGcodeUtils = process.env.FREECAD_CAM_CASE === "gcode-utils";
const isGenericPlasma = process.env.FREECAD_CAM_CASE === "generic-plasma";
const isGenericPost = process.env.FREECAD_CAM_CASE === "generic-post";
const isGrbl = process.env.FREECAD_CAM_CASE === "grbl";
const isGrblPost = process.env.FREECAD_CAM_CASE === "grbl-post";
const isLinking = process.env.FREECAD_CAM_CASE === "linking";
const isLinux = process.env.FREECAD_CAM_CASE === "linux";
const isLinuxPost = process.env.FREECAD_CAM_CASE === "linux-post";
const isMach = process.env.FREECAD_CAM_CASE === "mach";
const isMachPost = process.env.FREECAD_CAM_CASE === "mach-post";
const isMachine = process.env.FREECAD_CAM_CASE === "machine";
const isMasso = process.env.FREECAD_CAM_CASE === "masso";
const isAdaptive = process.env.FREECAD_CAM_CASE === "adaptive";
const isAnnotations = process.env.FREECAD_CAM_CASE === "annotations";
const isPathCore = process.env.FREECAD_CAM_CASE === "path-core";
const isDepthParams = process.env.FREECAD_CAM_CASE === "depth-params";
const isDressArray = process.env.FREECAD_CAM_CASE === "dress-array";
const isDogbone = process.env.FREECAD_CAM_CASE === "dogbone";
const isTags = process.env.FREECAD_CAM_CASE === "tags";
const isDrillGen = process.env.FREECAD_CAM_CASE === "drill-gen";
const isDrillable = process.env.FREECAD_CAM_CASE === "drillable";
const isFacingGen = process.env.FREECAD_CAM_CASE === "facing-gen";
const isGenDogbone = process.env.FREECAD_CAM_CASE === "gen-dogbone";
const isPathGeom = process.env.FREECAD_CAM_CASE === "path-geom";
const isHelix = process.env.FREECAD_CAM_CASE === "helix";
const isTspSolver = process.env.FREECAD_CAM_CASE === "tsp-solver";
const isHelixGen = process.env.FREECAD_CAM_CASE === "helix-gen";
const isHelpers = process.env.FREECAD_CAM_CASE === "helpers";
const isLanguage = process.env.FREECAD_CAM_CASE === "language";
const isPathLog = process.env.FREECAD_CAM_CASE === "path-log";
const isDeburr = process.env.FREECAD_CAM_CASE === "deburr";
const isOpUtil = process.env.FREECAD_CAM_CASE === "op-util";
const isPrefs = process.env.FREECAD_CAM_CASE === "prefs";
const isProfileOp = process.env.FREECAD_CAM_CASE === "profile-op";
const isPropBag = process.env.FREECAD_CAM_CASE === "prop-bag";
const isRotationGen = process.env.FREECAD_CAM_CASE === "rotation-gen";
const isSetupSheet = process.env.FREECAD_CAM_CASE === "setup-sheet";
const isSpiralGen = process.env.FREECAD_CAM_CASE === "spiral-gen";
const isStock = process.env.FREECAD_CAM_CASE === "stock";
const isTapGen = process.env.FREECAD_CAM_CASE === "tap-gen";
const isThread = process.env.FREECAD_CAM_CASE === "thread";
const isThreadGen = process.env.FREECAD_CAM_CASE === "thread-gen";
const isToolAsset = process.env.FREECAD_CAM_CASE === "tool-asset";
const isToolAssetCache = process.env.FREECAD_CAM_CASE === "tool-asset-cache";
const isToolAssetManager = process.env.FREECAD_CAM_CASE === "tool-asset-manager";
const isToolAssetStore = process.env.FREECAD_CAM_CASE === "tool-asset-store";
const isToolAssetUri = process.env.FREECAD_CAM_CASE === "tool-asset-uri";
const isToolBit = process.env.FREECAD_CAM_CASE === "tool-bit";
const isToolBitSerializer = process.env.FREECAD_CAM_CASE === "tool-bit-serializer";
const isToolChange = process.env.FREECAD_CAM_CASE === "tool-change";
const isToolController = process.env.FREECAD_CAM_CASE === "tool-controller";
const isToolLibrary = process.env.FREECAD_CAM_CASE === "tool-library";
const isToolLibrarySerializer = process.env.FREECAD_CAM_CASE === "tool-library-serializer";
const isToolShape = process.env.FREECAD_CAM_CASE === "tool-shape";
const isShapeDoc = process.env.FREECAD_CAM_CASE === "shape-doc";
const isPathUtil = process.env.FREECAD_CAM_CASE === "path-util";
const isVcarve = process.env.FREECAD_CAM_CASE === "vcarve";
const isVoronoi = process.env.FREECAD_CAM_CASE === "voronoi";
const isPostCore = process.env.FREECAD_CAM_CASE === "post-core";
const isDrillCycle = process.env.FREECAD_CAM_CASE === "drill-cycle";
const isPostMCodes = process.env.FREECAD_CAM_CASE === "post-mcodes";
const isTestPost = process.env.FREECAD_CAM_CASE === "test-post";
const isPostSnapmaker = process.env.FREECAD_CAM_CASE === "post-snapmaker";
const isPostGCodes = process.env.FREECAD_CAM_CASE === "post-gcodes";
const materialSuite = process.env.FREECAD_MATERIAL_SUITE || "";
const isMaterial = materialSuite !== "";
const isSpecialCase = isTspSolver || isCentroid || isCentroidPost || isDressup || isFanuc || isGcodeUtils || isGenericPlasma || isGenericPost || isGrbl || isGrblPost || isLinking || isLinux || isLinuxPost || isMach || isMachPost || isMachine || isMasso || isAdaptive || isAnnotations || isPathCore || isDepthParams || isDressArray || isDogbone || isTags || isDrillGen || isDrillable || isFacingGen || isGenDogbone || isPathGeom || isHelix || isHelixGen || isHelpers || isLanguage || isPathLog || isDeburr || isOpUtil || isPrefs || isProfileOp || isPropBag || isRotationGen || isSetupSheet || isSpiralGen || isStock || isTapGen || isThread || isThreadGen || isToolAsset || isToolAssetCache || isToolAssetManager || isToolAssetStore || isToolAssetUri || isToolBit || isToolBitSerializer || isToolChange || isToolController || isToolLibrary || isToolLibrarySerializer || isToolShape || isShapeDoc || isPathUtil || isVcarve || isVoronoi || isPostCore || isDrillCycle || isPostMCodes || isTestPost || isPostSnapmaker || isPostGCodes || isMaterial;
const evidenceRoot = path.join(docsRoot, "current", "business-evidence", isMaterial ? `desktop-test-material-${materialSuite}-20261031` : isPostGCodes ? "desktop-test-cam-testpostgcodes-20261031" : isTestPost ? "desktop-test-cam-testtestpost-20261031" : isPostSnapmaker ? "desktop-test-cam-testsnapmakerpost-20261031" : isPostMCodes ? "desktop-test-cam-testpostmcodes-20261031" : isDrillCycle ? "desktop-test-cam-testdrillcycleexpander-20261031" : isPostCore ? "desktop-test-cam-testpostcore-20261030" : isVoronoi ? "desktop-test-cam-testpathvoronoi-20261030" : isVcarve ? "desktop-test-cam-testpathvcarve-20261030" : isPathUtil ? "desktop-test-cam-testpathutil-20261030" : isShapeDoc ? "desktop-test-cam-testpathtoolshapedoc-20261030" : isToolShape ? "desktop-test-cam-testpathtoolshapeclasses-20261030" : isToolLibrarySerializer ? "desktop-test-cam-testpathtoollibraryserializer-20261030" : isToolLibrary ? "desktop-test-cam-testpathtoollibrary-20261030" : isToolController ? "desktop-test-cam-testpathtoolcontroller-20261030" : isToolChange ? "desktop-test-cam-testpathtoolchangegenerator-20261030" : isToolBitSerializer ? "desktop-test-cam-testpathtoolbitserializer-20261030" : isToolBit ? "desktop-test-cam-testpathtoolbit-20261030" : isToolAssetUri ? "desktop-test-cam-testpathtoolasseturi-20261030" : isToolAssetStore ? "desktop-test-cam-testpathtoolassetstore-20261030" : isToolAssetManager ? "desktop-test-cam-testpathtoolassetmanager-20261030" : isToolAssetCache ? "desktop-test-cam-testpathtoolassetcache-20261030" : isToolAsset ? "desktop-test-cam-testpathtoolasset-20261030" : isThreadGen ? "desktop-test-cam-testpaththreadmillinggenerator-20261030" : isThread ? "desktop-test-cam-testpaththreadmilling-20261030" : isTapGen ? "desktop-test-cam-testpathtapgenerator-20261030" : isStock ? "desktop-test-cam-testpathstock-20261030" : isSpiralGen ? "desktop-test-cam-testpathspiralgenerator-20261030" : isSetupSheet ? "desktop-test-cam-testpathsetupsheet-20261030" : isRotationGen ? "desktop-test-cam-testpathrotationgenerator-20261030" : isPropBag ? "desktop-test-cam-testpathpropertybag-20261030" : isProfileOp ? "desktop-test-cam-testpathprofile-20261030" : isPrefs ? "desktop-test-cam-testpathpreferences-20261030" : isOpUtil ? "desktop-test-cam-testpathoputil-20261030" : isDeburr ? "desktop-test-cam-testpathopdeburr-20261030" : isPathLog ? "desktop-test-cam-testpathlog-20261030" : isLanguage ? "desktop-test-cam-testpathlanguage-20261030" : isHelpers ? "desktop-test-cam-testpathhelpers-20261030" : isHelixGen ? "desktop-test-cam-testpathhelixgenerator-20261030" : isHelix ? "desktop-test-cam-testpathhelix-20261030" : isPathGeom ? "desktop-test-cam-testpathgeom-20261030" : isGenDogbone ? "desktop-test-cam-testpathgeneratordogboneii-20261030" : isFacingGen ? "desktop-test-cam-testpathfacinggenerator-20261030" : isDrillable ? "desktop-test-cam-testpathdrillable-20261030" : isDrillGen ? "desktop-test-cam-testpathdrillgenerator-20261030" : isTags ? "desktop-test-cam-testpathdressupholdingtags-20261030" : isDogbone ? "desktop-test-cam-testpathdressupdogboneii-20261030" : isDressArray ? "desktop-test-cam-testpathdressuparray-20261029" : isDepthParams ? "desktop-test-cam-testpathdepthparams-20261029" : isPathCore ? "desktop-test-cam-testpathcore-20261029" : isAnnotations ? "desktop-test-cam-testpathcommandannotations-20261029" : isAdaptive ? "desktop-test-cam-testpathadaptive-20261029" : isTspSolver ? "desktop-test-cam-testtspsolver-20261101" : isMasso ? "desktop-test-cam-testmassog3post-20261029" : isMachine ? "desktop-test-cam-testmachine-20261029" : isMachPost ? "desktop-test-cam-testmach3mach4post-20261029" : isMach ? "desktop-test-cam-testmach3mach4legacypost-20261029" : isLinuxPost ? "desktop-test-cam-testlinuxcncpost-20261029" : isLinux ? "desktop-test-cam-testlinuxcnclegacypost-20261029" : isLinking ? "desktop-test-cam-testlinkinggenerator-20261029" : isGrblPost ? "desktop-test-cam-testgrblpost-20261029" : isGrbl ? "desktop-test-cam-testgrbllegacypost-20261029" : isGenericPost ? "desktop-test-cam-testgenericpost-20261029" : isGenericPlasma ? "desktop-test-cam-testgenericplasma-20261029" : isGcodeUtils ? "desktop-test-cam-testgcodeprocessingutils-20261029" : isFanuc ? "desktop-test-cam-testfanucpost-20261028" : isDressup ? "desktop-test-cam-testdressuppost-20261028" : isCentroidPost ? "desktop-test-cam-testcentroidpost-20261028" : isCentroid ? "desktop-test-cam-testcentroidlegacypost-20261028" : "desktop-test-cam-testsanity-20261028");
fs.mkdirSync(evidenceRoot, { recursive: true });
const isMobile = process.env.FREECAD_CAM_VIEWPORT === "mobile";
const outputPath = path.join(docsRoot, "p6", isMaterial ? (isMobile ? `material-${materialSuite}-chrome-mobile.json` : `material-${materialSuite}-chrome.json`) : isPostGCodes ? (isMobile ? "cam-post-gcodes-chrome-mobile.json" : "cam-post-gcodes-chrome.json") : isTestPost ? (isMobile ? "cam-test-post-chrome-mobile.json" : "cam-test-post-chrome.json") : isPostSnapmaker ? (isMobile ? "cam-post-snapmaker-chrome-mobile.json" : "cam-post-snapmaker-chrome.json") : isPostMCodes ? (isMobile ? "cam-post-mcodes-chrome-mobile.json" : "cam-post-mcodes-chrome.json") : isDrillCycle ? (isMobile ? "cam-drill-cycle-chrome-mobile.json" : "cam-drill-cycle-chrome.json") : isPostCore ? (isMobile ? "cam-post-core-chrome-mobile.json" : "cam-post-core-chrome.json") : isVoronoi ? (isMobile ? "cam-voronoi-chrome-mobile.json" : "cam-voronoi-chrome.json") : isVcarve ? (isMobile ? "cam-vcarve-chrome-mobile.json" : "cam-vcarve-chrome.json") : isPathUtil ? (isMobile ? "cam-path-util-chrome-mobile.json" : "cam-path-util-chrome.json") : isShapeDoc ? (isMobile ? "cam-shape-doc-chrome-mobile.json" : "cam-shape-doc-chrome.json") : isToolShape ? (isMobile ? "cam-tool-shape-chrome-mobile.json" : "cam-tool-shape-chrome.json") : isToolLibrarySerializer ? (isMobile ? "cam-tool-library-serializer-chrome-mobile.json" : "cam-tool-library-serializer-chrome.json") : isToolLibrary ? (isMobile ? "cam-tool-library-chrome-mobile.json" : "cam-tool-library-chrome.json") : isToolController ? (isMobile ? "cam-tool-controller-chrome-mobile.json" : "cam-tool-controller-chrome.json") : isToolChange ? (isMobile ? "cam-tool-change-chrome-mobile.json" : "cam-tool-change-chrome.json") : isToolBitSerializer ? (isMobile ? "cam-tool-bit-serializer-chrome-mobile.json" : "cam-tool-bit-serializer-chrome.json") : isToolBit ? (isMobile ? "cam-tool-bit-chrome-mobile.json" : "cam-tool-bit-chrome.json") : isToolAssetUri ? (isMobile ? "cam-tool-asset-uri-chrome-mobile.json" : "cam-tool-asset-uri-chrome.json") : isToolAssetStore ? (isMobile ? "cam-tool-asset-store-chrome-mobile.json" : "cam-tool-asset-store-chrome.json") : isToolAssetManager ? (isMobile ? "cam-tool-asset-manager-chrome-mobile.json" : "cam-tool-asset-manager-chrome.json") : isToolAssetCache ? (isMobile ? "cam-tool-asset-cache-chrome-mobile.json" : "cam-tool-asset-cache-chrome.json") : isToolAsset ? (isMobile ? "cam-tool-asset-chrome-mobile.json" : "cam-tool-asset-chrome.json") : isThreadGen ? (isMobile ? "cam-thread-gen-chrome-mobile.json" : "cam-thread-gen-chrome.json") : isThread ? (isMobile ? "cam-thread-chrome-mobile.json" : "cam-thread-chrome.json") : isTapGen ? (isMobile ? "cam-tap-gen-chrome-mobile.json" : "cam-tap-gen-chrome.json") : isStock ? (isMobile ? "cam-stock-chrome-mobile.json" : "cam-stock-chrome.json") : isSpiralGen ? (isMobile ? "cam-spiral-gen-chrome-mobile.json" : "cam-spiral-gen-chrome.json") : isSetupSheet ? (isMobile ? "cam-setup-sheet-chrome-mobile.json" : "cam-setup-sheet-chrome.json") : isRotationGen ? (isMobile ? "cam-rotation-gen-chrome-mobile.json" : "cam-rotation-gen-chrome.json") : isPropBag ? (isMobile ? "cam-prop-bag-chrome-mobile.json" : "cam-prop-bag-chrome.json") : isProfileOp ? (isMobile ? "cam-profile-op-chrome-mobile.json" : "cam-profile-op-chrome.json") : isPrefs ? (isMobile ? "cam-prefs-chrome-mobile.json" : "cam-prefs-chrome.json") : isOpUtil ? (isMobile ? "cam-op-util-chrome-mobile.json" : "cam-op-util-chrome.json") : isDeburr ? (isMobile ? "cam-deburr-chrome-mobile.json" : "cam-deburr-chrome.json") : isPathLog ? (isMobile ? "cam-path-log-chrome-mobile.json" : "cam-path-log-chrome.json") : isLanguage ? (isMobile ? "cam-language-chrome-mobile.json" : "cam-language-chrome.json") : isHelpers ? (isMobile ? "cam-helpers-chrome-mobile.json" : "cam-helpers-chrome.json") : isHelixGen ? (isMobile ? "cam-helix-gen-chrome-mobile.json" : "cam-helix-gen-chrome.json") : isHelix ? (isMobile ? "cam-helix-chrome-mobile.json" : "cam-helix-chrome.json") : isPathGeom ? (isMobile ? "cam-path-geom-chrome-mobile.json" : "cam-path-geom-chrome.json") : isGenDogbone ? (isMobile ? "cam-gen-dogbone-chrome-mobile.json" : "cam-gen-dogbone-chrome.json") : isFacingGen ? (isMobile ? "cam-facing-gen-chrome-mobile.json" : "cam-facing-gen-chrome.json") : isDrillable ? (isMobile ? "cam-drillable-chrome-mobile.json" : "cam-drillable-chrome.json") : isDrillGen ? (isMobile ? "cam-drill-gen-chrome-mobile.json" : "cam-drill-gen-chrome.json") : isTags ? (isMobile ? "cam-tags-chrome-mobile.json" : "cam-tags-chrome.json") : isDogbone ? (isMobile ? "cam-dogbone-chrome-mobile.json" : "cam-dogbone-chrome.json") : isDressArray ? (isMobile ? "cam-dress-array-chrome-mobile.json" : "cam-dress-array-chrome.json") : isDepthParams ? (isMobile ? "cam-depth-params-chrome-mobile.json" : "cam-depth-params-chrome.json") : isPathCore ? (isMobile ? "cam-path-core-chrome-mobile.json" : "cam-path-core-chrome.json") : isAnnotations ? (isMobile ? "cam-annotations-chrome-mobile.json" : "cam-annotations-chrome.json") : isAdaptive ? (isMobile ? "cam-adaptive-chrome-mobile.json" : "cam-adaptive-chrome.json") : isTspSolver ? (isMobile ? "cam-tsp-solver-chrome-mobile.json" : "cam-tsp-solver-chrome.json") : isMasso ? (isMobile ? "cam-masso-chrome-mobile.json" : "cam-masso-chrome.json") : isMachine ? (isMobile ? "cam-machine-chrome-mobile.json" : "cam-machine-chrome.json") : isMachPost ? (isMobile ? "cam-mach-post-chrome-mobile.json" : "cam-mach-post-chrome.json") : isMach ? (isMobile ? "cam-mach-chrome-mobile.json" : "cam-mach-chrome.json") : isLinuxPost ? (isMobile ? "cam-linux-post-chrome-mobile.json" : "cam-linux-post-chrome.json") : isLinux ? (isMobile ? "cam-linux-chrome-mobile.json" : "cam-linux-chrome.json") : isLinking ? (isMobile ? "cam-linking-chrome-mobile.json" : "cam-linking-chrome.json") : isGrblPost ? (isMobile ? "cam-grbl-post-chrome-mobile.json" : "cam-grbl-post-chrome.json") : isGrbl ? (isMobile ? "cam-grbl-chrome-mobile.json" : "cam-grbl-chrome.json") : isGenericPost ? (isMobile ? "cam-generic-post-chrome-mobile.json" : "cam-generic-post-chrome.json") : isGenericPlasma ? (isMobile ? "cam-generic-plasma-chrome-mobile.json" : "cam-generic-plasma-chrome.json") : isGcodeUtils ? (isMobile ? "cam-gcode-utils-chrome-mobile.json" : "cam-gcode-utils-chrome.json") : isFanuc ? (isMobile ? "cam-fanuc-chrome-mobile.json" : "cam-fanuc-chrome.json") : isDressup ? (isMobile ? "cam-dressup-chrome-mobile.json" : "cam-dressup-chrome.json") : isCentroidPost ? (isMobile ? "cam-centroid-post-chrome-mobile.json" : "cam-centroid-post-chrome.json") : isCentroid ? (isMobile ? "cam-centroid-chrome-mobile.json" : "cam-centroid-chrome.json") : (isMobile ? "cam-chrome-mobile.json" : "cam-chrome.json"));
const logPath = path.join(docsRoot, isMach ? (isMobile ? "freecad-p6-cam-mach-chrome-mobile.log" : "freecad-p6-cam-mach-chrome.log") : isLinuxPost ? (isMobile ? "freecad-p6-cam-linux-post-chrome-mobile.log" : "freecad-p6-cam-linux-post-chrome.log") : isGrblPost ? (isMobile ? "freecad-p6-cam-grbl-post-chrome-mobile.log" : "freecad-p6-cam-grbl-post-chrome.log") : isGrbl ? (isMobile ? "freecad-p6-cam-grbl-chrome-mobile.log" : "freecad-p6-cam-grbl-chrome.log") : isGenericPost ? (isMobile ? "freecad-p6-cam-generic-post-chrome-mobile.log" : "freecad-p6-cam-generic-post-chrome.log") : isGenericPlasma ? (isMobile ? "freecad-p6-cam-generic-plasma-chrome-mobile.log" : "freecad-p6-cam-generic-plasma-chrome.log") : isGcodeUtils ? (isMobile ? "freecad-p6-cam-gcode-utils-chrome-mobile.log" : "freecad-p6-cam-gcode-utils-chrome.log") : isFanuc ? (isMobile ? "freecad-p6-cam-fanuc-chrome-mobile.log" : "freecad-p6-cam-fanuc-chrome.log") : isDressup ? (isMobile ? "freecad-p6-cam-dressup-chrome-mobile.log" : "freecad-p6-cam-dressup-chrome.log") : isCentroidPost ? (isMobile ? "freecad-p6-cam-centroid-post-chrome-mobile.log" : "freecad-p6-cam-centroid-post-chrome.log") : isCentroid ? (isMobile ? "freecad-p6-cam-centroid-chrome-mobile.log" : "freecad-p6-cam-centroid-chrome.log") : (isMobile ? "freecad-p6-cam-f-chrome-mobile.log" : "freecad-p6-cam-f-chrome.log"));
const screenshotPath = path.join(docsRoot, "p6", isLinuxPost ? (isMobile ? "cam-linux-post-chrome-mobile.png" : "cam-linux-post-chrome.png") : isGrblPost ? (isMobile ? "cam-grbl-post-chrome-mobile.png" : "cam-grbl-post-chrome.png") : isGrbl ? (isMobile ? "cam-grbl-chrome-mobile.png" : "cam-grbl-chrome.png") : isGenericPost ? (isMobile ? "cam-generic-post-chrome-mobile.png" : "cam-generic-post-chrome.png") : isGenericPlasma ? (isMobile ? "cam-generic-plasma-chrome-mobile.png" : "cam-generic-plasma-chrome.png") : isGcodeUtils ? (isMobile ? "cam-gcode-utils-chrome-mobile.png" : "cam-gcode-utils-chrome.png") : isFanuc ? (isMobile ? "cam-fanuc-chrome-mobile.png" : "cam-fanuc-chrome.png") : isDressup ? (isMobile ? "cam-dressup-chrome-mobile.png" : "cam-dressup-chrome.png") : isCentroidPost ? (isMobile ? "cam-centroid-post-chrome-mobile.png" : "cam-centroid-post-chrome.png") : isCentroid ? (isMobile ? "cam-centroid-chrome-mobile.png" : "cam-centroid-chrome.png") : (isMobile ? "cam-chrome-mobile.png" : "cam-chrome.png"));
const viewport = isMobile ? { width: 390, height: 844, deviceScaleFactor: 1 } : { width: 1440, height: 900, deviceScaleFactor: 1 };
const timeoutMs = isLinking ? 120000 : 30000;
const sha256 = (value) => crypto.createHash("sha256").update(value).digest("hex");
const chromePath = findChrome();
if (!chromePath) {
const blocked = { schema: "freecad-web-p6-cam-chrome/v1", result: "blocked_chrome_unavailable", policy: { browser: "Google Chrome only", nonChromeBrowsersAttempted: false } };
fs.writeFileSync(outputPath, `${JSON.stringify(blocked, null, 2)}\n`);
fs.writeFileSync(logPath, "Google Chrome executable was not found; no alternate browser was attempted\n");
process.exitCode = 2;
} else {
if (!fs.existsSync(path.join(distRoot, "cam.html"))) throw new Error("web/dist/cam.html is missing; run npm run build first");
const host = await startStaticHost(distRoot, "cam.html");
const server = host.server;
const origin = host.origin;
const userDataDir = fs.mkdtempSync(path.join(os.tmpdir(), "freecad-p6-cam-chrome-"));
const chrome = spawn(chromePath, ["--headless=new", "--no-sandbox", "--disable-gpu", "--disable-dev-shm-usage", "--remote-debugging-port=0", "--remote-allow-origins=*", `--user-data-dir=${userDataDir}`, `--window-size=${viewport.width},${viewport.height}`, `${origin}/cam.html`], { stdio: ["ignore", "pipe", "pipe"] });
let chromeOutput = "";
chrome.stdout.on("data", (chunk) => { chromeOutput += chunk.toString(); });
chrome.stderr.on("data", (chunk) => { chromeOutput += chunk.toString(); });
class CdpSession {
constructor(url) {
this.socket = new WebSocket(url); this.nextId = 1; this.pending = new Map(); this.listeners = new Map();
this.ready = new Promise((resolve, reject) => { this.socket.addEventListener("open", resolve, { once: true }); this.socket.addEventListener("error", reject, { once: true }); });
this.socket.addEventListener("message", (event) => { const message = JSON.parse(event.data); if (message.id !== undefined) { const pending = this.pending.get(message.id); if (!pending) return; this.pending.delete(message.id); if (message.error) pending.reject(new Error(`${pending.method}: ${message.error.message}`)); else pending.resolve(message.result); return; } for (const listener of this.listeners.get(message.method) ?? []) listener(message.params); });
}
async send(method, params = {}) { await this.ready; const id = this.nextId++; return new Promise((resolve, reject) => { this.pending.set(id, { resolve, reject, method }); this.socket.send(JSON.stringify({ id, method, params })); }); }
on(method, listener) { this.listeners.set(method, [...(this.listeners.get(method) ?? []), listener]); }
close() { this.socket.close(); }
}
async function waitFor(label, predicate, evaluate) {
const deadline = Date.now() + timeoutMs; let last;
while (Date.now() < deadline) { last = await evaluate(); if (predicate(last)) return last; if (last?.stage === "error") throw new Error(`${label} failed: ${JSON.stringify(last)}`); await new Promise((resolve) => setTimeout(resolve, 100)); }
throw new Error(`${label} timed out: ${JSON.stringify(last)}`);
}
let cdp;
try {
let target; const deadline = Date.now() + timeoutMs;
while (!target && Date.now() < deadline) {
const match = chromeOutput.match(/DevTools listening on ws:\/\/([^\s]+)/);
if (match) { const port = match[1].split(":")[1].split("/")[0]; const targets = await fetch(`http://127.0.0.1:${port}/json/list`).then((response) => response.json()); target = targets.find((item) => item.type === "page"); }
if (!target) await new Promise((resolve) => setTimeout(resolve, 100));
}
if (!target?.webSocketDebuggerUrl) throw new Error(`Chrome CDP target unavailable: ${chromeOutput.trim()}`);
cdp = new CdpSession(target.webSocketDebuggerUrl);
const requests = []; const responses = []; const consoleEntries = []; const exceptions = [];
cdp.on("Network.requestWillBeSent", (event) => requests.push({ url: event.request.url, method: event.request.method, type: event.type }));
cdp.on("Network.responseReceived", (event) => responses.push({ url: event.response.url, status: event.response.status }));
cdp.on("Runtime.consoleAPICalled", (event) => consoleEntries.push({ type: event.type, text: event.args?.map((arg) => arg.value ?? arg.description ?? "").join(" ") ?? "" }));
cdp.on("Runtime.exceptionThrown", (event) => exceptions.push(event.exceptionDetails?.text ?? "runtime exception"));
cdp.on("Log.entryAdded", (event) => { if (event.entry.level === "error") consoleEntries.push({ type: "log", text: event.entry.text }); });
await cdp.send("Runtime.enable"); await cdp.send("Network.enable"); await cdp.send("Log.enable"); await cdp.send("Page.enable");
await cdp.send("Emulation.setDeviceMetricsOverride", { ...viewport, mobile: isMobile });
const evaluate = async (expression) => { const result = await cdp.send("Runtime.evaluate", { expression, returnByValue: true, awaitPromise: true }); if (result.exceptionDetails) throw new Error(result.exceptionDetails.text ?? "Runtime.evaluate failed"); return result.result?.value; };
const state = () => evaluate("window.__freecadCamState");
const ready = await waitFor("CAM ready", (value) => value?.stage === "ready", state);
const layout = await evaluate("(() => { const box=document.querySelector('.properties')?.getBoundingClientRect(); return { crossOriginIsolated: globalThis.crossOriginIsolated === true, bodyOverflow: document.documentElement.scrollWidth > innerWidth, propertiesInViewport: Boolean(box && box.left >= 0 && box.right <= innerWidth && box.top < innerHeight && box.bottom > 0), httpStatus: 200 }; })()");
let sanity = null; let centroid = null; let success = null; let expectedError = null;
if (isCentroid) {
await evaluate("document.querySelector('#test-centroid').click()");
centroid = await waitFor("CAM Centroid legacy tests", (value) => value?.stage === "centroid-success", state);
} else if (isCentroidPost) {
await evaluate("document.querySelector('#test-centroid-post').click()");
centroid = await waitFor("CAM Centroid post tests", (value) => value?.stage === "centroid-post-success", state);
} else if (isDressup) {
await evaluate("document.querySelector('#test-dressup').click()");
centroid = await waitFor("CAM Dressup post tests", (value) => value?.stage === "dressup-success", state);
} else if (isFanuc) {
await evaluate("document.querySelector('#test-fanuc').click()");
centroid = await waitFor("CAM Fanuc post tests", (value) => value?.stage === "fanuc-success", state);
} else if (isGcodeUtils) {
await evaluate("document.querySelector('#test-gcode-utils').click()");
centroid = await waitFor("CAM G-code utility tests", (value) => value?.stage === "gcode-utils-success", state);
} else if (isGenericPlasma) {
await evaluate("document.querySelector('#test-generic-plasma').click()");
centroid = await waitFor("CAM GenericPlasma tests", (value) => value?.stage === "generic-plasma-success", state);
} else if (isGenericPost) {
await evaluate("document.querySelector('#test-generic-post').click()");
centroid = await waitFor("CAM Generic post tests", (value) => value?.stage === "generic-post-success", state);
} else if (isGrbl) {
await evaluate("document.querySelector('#test-grbl').click()");
centroid = await waitFor("CAM GRBL legacy tests", (value) => value?.stage === "grbl-success", state);
} else if (isGrblPost) {
await evaluate("document.querySelector('#test-grbl-post').click()");
centroid = await waitFor("CAM GRBL post tests", (value) => value?.stage === "grbl-post-success", state);
} else if (isLinuxPost) {
await evaluate("document.querySelector('#test-linux-post').click()");
centroid = await waitFor("CAM LinuxCNC post tests", (value) => value?.stage === "linux-post-success", state);
} else if (isLinux) {
await evaluate("document.querySelector('#test-linux').click()");
centroid = await waitFor("CAM LinuxCNC tests", (value) => value?.stage === "linux-success", state);
} else if (isMaterial) {
await evaluate("document.querySelector('#test-material').click()");
centroid = await waitFor("CAM material", (value) => value?.stage === "material-success", state);
} else if (isPostGCodes) {
await evaluate("document.querySelector('#test-post-gcodes').click()");
centroid = await waitFor("CAM post gcodes", (value) => value?.stage === "post-gcodes-success", state);
} else if (isTestPost) {
await evaluate("document.querySelector('#test-test-post').click()");
centroid = await waitFor("CAM test post", (value) => value?.stage === "test-post-success", state);
} else if (isPostSnapmaker) {
await evaluate("document.querySelector('#test-post-snapmaker').click()");
centroid = await waitFor("CAM snapmaker post", (value) => value?.stage === "post-snapmaker-success", state);
} else if (isPostMCodes) {
await evaluate("document.querySelector('#test-post-mcodes').click()");
centroid = await waitFor("CAM post mcodes", (value) => value?.stage === "post-mcodes-success", state);
} else if (isDrillCycle) {
await evaluate("document.querySelector('#test-drill-cycle').click()");
centroid = await waitFor("CAM drill cycle", (value) => value?.stage === "drill-cycle-success", state);
} else if (isPostCore) {
await evaluate("document.querySelector('#test-post-core').click()");
centroid = await waitFor("CAM post core", (value) => value?.stage === "post-core-success", state);
} else if (isVoronoi) {
await evaluate("document.querySelector('#test-voronoi').click()");
centroid = await waitFor("CAM voronoi", (value) => value?.stage === "voronoi-success", state);
} else if (isVcarve) {
await evaluate("document.querySelector('#test-vcarve').click()");
centroid = await waitFor("CAM vcarve", (value) => value?.stage === "vcarve-success", state);
} else if (isPathUtil) {
await evaluate("document.querySelector('#test-path-util').click()");
centroid = await waitFor("CAM path util", (value) => value?.stage === "path-util-success", state);
} else if (isShapeDoc) {
await evaluate("document.querySelector('#test-shape-doc').click()");
centroid = await waitFor("CAM shape doc", (value) => value?.stage === "shape-doc-success", state);
} else if (isToolShape) {
await evaluate("document.querySelector('#test-tool-shape').click()");
centroid = await waitFor("CAM tool shape", (value) => value?.stage === "tool-shape-success", state);
} else if (isToolLibrarySerializer) {
await evaluate("document.querySelector('#test-tool-library-serializer').click()");
centroid = await waitFor("CAM tool library serializer", (value) => value?.stage === "tool-library-serializer-success", state);
} else if (isToolLibrary) {
await evaluate("document.querySelector('#test-tool-library').click()");
centroid = await waitFor("CAM tool library", (value) => value?.stage === "tool-library-success", state);
} else if (isToolController) {
await evaluate("document.querySelector('#test-tool-controller').click()");
centroid = await waitFor("CAM tool controller", (value) => value?.stage === "tool-controller-success", state);
} else if (isToolChange) {
await evaluate("document.querySelector('#test-tool-change').click()");
centroid = await waitFor("CAM tool change", (value) => value?.stage === "tool-change-success", state);
} else if (isToolBitSerializer) {
await evaluate("document.querySelector('#test-tool-bit-serializer').click()");
centroid = await waitFor("CAM tool bit serializer", (value) => value?.stage === "tool-bit-serializer-success", state);
} else if (isToolBit) {
await evaluate("document.querySelector('#test-tool-bit').click()");
centroid = await waitFor("CAM tool bit", (value) => value?.stage === "tool-bit-success", state);
} else if (isToolAssetUri) {
await evaluate("document.querySelector('#test-tool-asset-uri').click()");
centroid = await waitFor("CAM asset uri", (value) => value?.stage === "tool-asset-uri-success", state);
} else if (isToolAssetStore) {
await evaluate("document.querySelector('#test-tool-asset-store').click()");
centroid = await waitFor("CAM asset store", (value) => value?.stage === "tool-asset-store-success", state);
} else if (isToolAssetManager) {
await evaluate("document.querySelector('#test-tool-asset-manager').click()");
centroid = await waitFor("CAM asset manager", (value) => value?.stage === "tool-asset-manager-success", state);
} else if (isToolAssetCache) {
await evaluate("document.querySelector('#test-tool-asset-cache').click()");
centroid = await waitFor("CAM asset cache", (value) => value?.stage === "tool-asset-cache-success", state);
} else if (isToolAsset) {
await evaluate("document.querySelector('#test-tool-asset').click()");
centroid = await waitFor("CAM tool asset", (value) => value?.stage === "tool-asset-success", state);
} else if (isThreadGen) {
await evaluate("document.querySelector('#test-thread-gen').click()");
centroid = await waitFor("CAM thread generator", (value) => value?.stage === "thread-gen-success", state);
} else if (isThread) {
await evaluate("document.querySelector('#test-thread').click()");
centroid = await waitFor("CAM thread milling", (value) => value?.stage === "thread-success", state);
} else if (isTapGen) {
await evaluate("document.querySelector('#test-tap-gen').click()");
centroid = await waitFor("CAM tap generator", (value) => value?.stage === "tap-gen-success", state);
} else if (isStock) {
await evaluate("document.querySelector('#test-stock').click()");
centroid = await waitFor("CAM path stock", (value) => value?.stage === "stock-success", state);
} else if (isSpiralGen) {
await evaluate("document.querySelector('#test-spiral-gen').click()");
centroid = await waitFor("CAM spiral generator", (value) => value?.stage === "spiral-gen-success", state);
} else if (isSetupSheet) {
await evaluate("document.querySelector('#test-setup-sheet').click()");
centroid = await waitFor("CAM setup sheet", (value) => value?.stage === "setup-sheet-success", state);
} else if (isRotationGen) {
await evaluate("document.querySelector('#test-rotation-gen').click()");
centroid = await waitFor("CAM rotation generator", (value) => value?.stage === "rotation-gen-success", state);
} else if (isPropBag) {
await evaluate("document.querySelector('#test-prop-bag').click()");
centroid = await waitFor("CAM property bag", (value) => value?.stage === "prop-bag-success", state);
} else if (isProfileOp) {
await evaluate("document.querySelector('#test-profile-op').click()");
centroid = await waitFor("CAM profile op", (value) => value?.stage === "profile-op-success", state);
} else if (isPrefs) {
await evaluate("document.querySelector('#test-prefs').click()");
centroid = await waitFor("CAM path preferences", (value) => value?.stage === "prefs-success", state);
} else if (isOpUtil) {
await evaluate("document.querySelector('#test-op-util').click()");
centroid = await waitFor("CAM op util", (value) => value?.stage === "op-util-success", state);
} else if (isDeburr) {
await evaluate("document.querySelector('#test-deburr').click()");
centroid = await waitFor("CAM deburr op", (value) => value?.stage === "deburr-success", state);
} else if (isPathLog) {
await evaluate("document.querySelector('#test-path-log').click()");
centroid = await waitFor("CAM path log", (value) => value?.stage === "path-log-success", state);
} else if (isLanguage) {
await evaluate("document.querySelector('#test-language').click()");
centroid = await waitFor("CAM path language", (value) => value?.stage === "language-success", state);
} else if (isHelpers) {
await evaluate("document.querySelector('#test-helpers').click()");
centroid = await waitFor("CAM path helpers", (value) => value?.stage === "helpers-success", state);
} else if (isHelixGen) {
await evaluate("document.querySelector('#test-helix-gen').click()");
centroid = await waitFor("CAM helix generator", (value) => value?.stage === "helix-gen-success", state);
} else if (isHelix) {
await evaluate("document.querySelector('#test-helix').click()");
centroid = await waitFor("CAM Helix op", (value) => value?.stage === "helix-success", state);
} else if (isPathGeom) {
await evaluate("document.querySelector('#test-path-geom').click()");
centroid = await waitFor("CAM Path Geom", (value) => value?.stage === "path-geom-success", state);
} else if (isGenDogbone) {
await evaluate("document.querySelector('#test-gen-dogbone').click()");
centroid = await waitFor("CAM dogbone generator", (value) => value?.stage === "gen-dogbone-success", state);
} else if (isFacingGen) {
await evaluate("document.querySelector('#test-facing-gen').click()");
centroid = await waitFor("CAM facing generator", (value) => value?.stage === "facing-gen-success", state);
} else if (isDrillable) {
await evaluate("document.querySelector('#test-drillable').click()");
centroid = await waitFor("CAM drillable", (value) => value?.stage === "drillable-success", state);
} else if (isDrillGen) {
await evaluate("document.querySelector('#test-drill-gen').click()");
centroid = await waitFor("CAM drill generator", (value) => value?.stage === "drill-gen-success", state);
} else if (isTags) {
await evaluate("document.querySelector('#test-tags').click()");
centroid = await waitFor("CAM holding tags", (value) => value?.stage === "tags-success", state);
} else if (isDogbone) {
await evaluate("document.querySelector('#test-dogbone').click()");
centroid = await waitFor("CAM DogboneII dressup", (value) => value?.stage === "dogbone-success", state);
} else if (isDressArray) {
await evaluate("document.querySelector('#test-dress-array').click()");
centroid = await waitFor("CAM dressup array", (value) => value?.stage === "dress-array-success", state);
} else if (isDepthParams) {
await evaluate("document.querySelector('#test-depth-params').click()");
centroid = await waitFor("CAM depth params", (value) => value?.stage === "depth-params-success", state);
} else if (isPathCore) {
await evaluate("document.querySelector('#test-path-core').click()");
centroid = await waitFor("CAM Path core", (value) => value?.stage === "path-core-success", state);
} else if (isAnnotations) {
await evaluate("document.querySelector('#test-annotations').click()");
centroid = await waitFor("CAM Path annotations", (value) => value?.stage === "annotations-success", state);
} else if (isAdaptive) {
await evaluate("document.querySelector('#test-adaptive').click()");
centroid = await waitFor("CAM Adaptive tests", (value) => value?.stage === "adaptive-success", state);
} else if (isTspSolver) {
await evaluate("document.querySelector('#test-tsp-solver').click()");
centroid = await waitFor("CAM TSP solver tests", (value) => value?.stage === "tsp-solver-success", state);
} else if (isMasso) {
await evaluate("document.querySelector('#test-masso').click()");
centroid = await waitFor("CAM Masso G3 tests", (value) => value?.stage === "masso-success", state);
} else if (isMachine) {
await evaluate("document.querySelector('#test-machine').click()");
centroid = await waitFor("CAM Machine tests", (value) => value?.stage === "machine-success", state);
} else if (isMachPost) {
await evaluate("document.querySelector('#test-mach-post').click()");
centroid = await waitFor("CAM Mach3/Mach4 post tests", (value) => value?.stage === "mach-post-success", state);
} else if (isMach) {
await evaluate("document.querySelector('#test-mach').click()");
centroid = await waitFor("CAM Mach3/Mach4 tests", (value) => value?.stage === "mach-success", state);
} else if (isLinking) {
const linkingButton = await evaluate("(() => { const b=document.querySelector('#test-linking'); return { exists:Boolean(b), disabled:Boolean(b?.disabled) }; })()");
if (!linkingButton.exists || linkingButton.disabled) throw new Error(`CAM linking button is unavailable: ${JSON.stringify(linkingButton)}`);
await evaluate("document.querySelector('#test-linking').click()");
centroid = await waitFor("CAM linking tests", (value) => value?.stage === "linking-success", state);
} else {
await evaluate("document.querySelector('#test-sanity').click()");
sanity = await waitFor("CAM official sanity", (value) => value?.stage === "sanity-success", state);
await evaluate("document.querySelector('#create').click()");
success = await waitFor("CAM create/recompute", (value) => value?.stage === "success", state);
await evaluate("document.querySelector('#error').click()");
expectedError = await waitFor("CAM expected error", (value) => value?.stage === "expected-error", state);
}
await evaluate("document.querySelector('#reset').click()");
const reset = await waitFor("CAM reset", (value) => value?.stage === "reset", state);
const screenshot = await cdp.send("Page.captureScreenshot", { format: "png", fromSurface: true });
const screenshotBytes = Buffer.from(screenshot.data, "base64"); fs.writeFileSync(screenshotPath, screenshotBytes);
const viewportName = isMobile ? "mobile" : "desktop";
const evidenceStem = isMaterial ? `material-${materialSuite}` : isPostGCodes ? "cam-post-gcodes" : isTestPost ? "cam-test-post" : isPostSnapmaker ? "cam-post-snapmaker" : isPostMCodes ? "cam-post-mcodes" : isDrillCycle ? "cam-drill-cycle" : isPostCore ? "cam-post-core" : isVoronoi ? "cam-voronoi" : isVcarve ? "cam-vcarve" : isPathUtil ? "cam-path-util" : isShapeDoc ? "cam-shape-doc" : isToolShape ? "cam-tool-shape" : isToolLibrarySerializer ? "cam-tool-library-serializer" : isToolLibrary ? "cam-tool-library" : isToolController ? "cam-tool-controller" : isToolChange ? "cam-tool-change" : isToolBitSerializer ? "cam-tool-bit-serializer" : isToolBit ? "cam-tool-bit" : isToolAssetUri ? "cam-tool-asset-uri" : isToolAssetStore ? "cam-tool-asset-store" : isToolAssetManager ? "cam-tool-asset-manager" : isToolAssetCache ? "cam-tool-asset-cache" : isToolAsset ? "cam-tool-asset" : isThreadGen ? "cam-thread-gen" : isThread ? "cam-thread" : isTapGen ? "cam-tap-gen" : isStock ? "cam-stock" : isSpiralGen ? "cam-spiral-gen" : isSetupSheet ? "cam-setup-sheet" : isRotationGen ? "cam-rotation-gen" : isPropBag ? "cam-prop-bag" : isProfileOp ? "cam-profile-op" : isPrefs ? "cam-prefs" : isOpUtil ? "cam-op-util" : isDeburr ? "cam-deburr" : isPathLog ? "cam-path-log" : isLanguage ? "cam-language" : isHelpers ? "cam-helpers" : isHelixGen ? "cam-helix-gen" : isHelix ? "cam-helix" : isPathGeom ? "cam-path-geom" : isGenDogbone ? "cam-gen-dogbone" : isFacingGen ? "cam-facing-gen" : isDrillable ? "cam-drillable" : isDrillGen ? "cam-drill-gen" : isTags ? "cam-tags" : isDogbone ? "cam-dogbone" : isDressArray ? "cam-dress-array" : isDepthParams ? "cam-depth-params" : isPathCore ? "cam-path-core" : isAnnotations ? "cam-annotations" : isAdaptive ? "cam-adaptive" : isTspSolver ? "cam-tsp-solver" : isMasso ? "cam-masso" : isMachine ? "cam-machine" : isMachPost ? "cam-mach-post" : isMach ? "cam-mach" : isLinuxPost ? "cam-linux-post" : isLinux ? "cam-linux" : isLinking ? "cam-linking" : isGrblPost ? "cam-grbl-post" : isGrbl ? "cam-grbl" : isGenericPost ? "cam-generic-post" : isGenericPlasma ? "cam-generic-plasma" : isGcodeUtils ? "cam-gcode-utils" : isFanuc ? "cam-fanuc" : isDressup ? "cam-dressup" : isCentroidPost ? "cam-centroid-post" : isCentroid ? "cam-centroid" : "cam-sanity";
const evidenceScreenshot = path.join(evidenceRoot, `${evidenceStem}-${viewportName}.png`);
fs.copyFileSync(screenshotPath, evidenceScreenshot);
const externalRequests = requests.filter((request) => !request.url.startsWith(origin)).map((request) => request.url);
const httpFailures = responses.filter((response) => response.status >= 400);
const runtimeErrors = consoleEntries.filter((entry) => entry.type === "error" || entry.type === "log");
const auditProcess = await new Promise((resolve, reject) => {
const child = spawn(process.execPath, [path.join(root, "tools", "ui-workbench-surface-audit.mjs")], { cwd: root, env: { ...process.env, FREECAD_BROWSER_ORIGIN: origin } });
let output = "";
child.stdout.on("data", chunk => { output += chunk.toString(); });
child.stderr.on("data", chunk => { output += chunk.toString(); });
child.once("error", reject);
child.once("close", code => resolve({ code, output }));
});
const auditSource = path.join(docsRoot, "current", "ui-parity-baseline-20261011", "workbench-surface-audit.json");
const auditReport = JSON.parse(fs.readFileSync(auditSource, "utf8"));
const auditEvidence = path.join(evidenceRoot, `workbench-surface-audit-${viewportName}.json`);
fs.copyFileSync(auditSource, auditEvidence);
const audit64 = { status: auditProcess.code === 0 && auditReport.status === "passed" && auditCoverageComplete(auditReport) && auditReport.failures.length === 0 ? "passed" : "failed", origin, records: auditReport.records.length, expectedRecords: auditCoverage(auditReport).expected, failures: auditReport.failures.length, evidence: path.relative(root, auditEvidence), runnerOutput: auditProcess.output.trim().slice(-1000) };
const officialResponse = isSpecialCase ? centroid.response : sanity.response;
const materialCounts = { materials: 7, models: 5, filter: 2, document: 2, creation: 1 };
const officialCount = isMaterial ? (materialCounts[materialSuite] || 0) : isPostGCodes ? 73 : isTestPost ? 31 : isPostSnapmaker ? 16 : isPostMCodes ? 14 : isDrillCycle ? 12 : isPostCore ? 20 : isVoronoi ? 9 : isVcarve ? 15 : isPathUtil ? 21 : isShapeDoc ? 9 : isToolShape ? 24 : isToolLibrarySerializer ? 4 : isToolLibrary ? 11 : isToolController ? 2 : isToolChange ? 1 : isToolBitSerializer ? 9 : isToolBit ? 4 : isToolAssetUri ? 9 : isToolAssetStore ? 34 : isToolAssetManager ? 14 : isToolAssetCache ? 10 : isToolAsset ? 2 : isThreadGen ? 7 : isThread ? 10 : isTapGen ? 6 : isStock ? 5 : isSpiralGen ? 2 : isSetupSheet ? 8 : isRotationGen ? 6 : isPropBag ? 4 : isProfileOp ? 4 : isPrefs ? 8 : isOpUtil ? 32 : isDeburr ? 7 : isPathLog ? 21 : isLanguage ? 7 : isHelpers ? 3 : isHelixGen ? 6 : isHelix ? 8 : isPathGeom ? 25 : isGenDogbone ? 7 : isFacingGen ? 40 : isDrillable ? 3 : isDrillGen ? 14 : isTags ? 5 : isDogbone ? 16 : isDressArray ? 3 : isDepthParams ? 12 : isPathCore ? 3 : isAnnotations ? 21 : isAdaptive ? 11 : isTspSolver ? 9 : isMasso ? 10 : isMachine ? 26 : isMachPost ? 10 : isMach ? 10 : isLinuxPost ? 23 : isLinux ? 21 : isLinking ? 8 : isGrblPost ? 11 : isGrbl ? 8 : isGenericPost ? 10 : isGenericPlasma ? 9 : isGcodeUtils ? 47 : isDressup ? 3 : 10;
const workflowPassed = isSpecialCase
? officialResponse?.kind === "result" && officialResponse.result.tests.length === officialCount && officialResponse.result.tests.every((test) => test.passed === true) && officialResponse.result.preflight.passed === true && officialResponse.result.guiUp[0] === "bool" && officialResponse.result.guiUp[1] === false && reset.stage === "reset"
: success.response?.kind === "result"
&& success.response.result.object.type === "Path::Feature"
&& success.response.result.path.commandCount === 3
&& success.response.result.path.length === 20
&& success.response.result.recompute.count === 1
&& sanity.response?.kind === "result"
&& sanity.response.result.tests.length === 12
&& sanity.response.result.tests.every((test) => test.passed === true)
&& sanity.response.result.preflight.passed === true
&& sanity.response.result.guiUp[0] === "bool"
&& sanity.response.result.guiUp[1] === false
&& expectedError.response?.kind === "error"
&& expectedError.response.error.code === "invalid_gcode"
&& reset.stage === "reset"
&& layout.crossOriginIsolated === true && layout.bodyOverflow === false && layout.propertiesInViewport === true
&& externalRequests.length === 0 && httpFailures.length === 0 && exceptions.length === 0 && runtimeErrors.length === 0
&& audit64.status === "passed";
const passed = workflowPassed && layout.crossOriginIsolated === true && layout.bodyOverflow === false && layout.propertiesInViewport === true && externalRequests.length === 0 && httpFailures.length === 0 && exceptions.length === 0 && runtimeErrors.length === 0 && audit64.status === "passed";
const result = {
schema: "freecad-web-p6-cam-chrome/v1", task_id: "FW-P6-CAM-F", result: passed ? "pass" : "fail",
chrome: { path: chromePath, version: (await new Promise((resolve) => { const version = spawn(chromePath, ["--version"], { stdio: ["ignore", "pipe", "ignore"] }); let output = ""; version.stdout.on("data", (chunk) => { output += chunk; }); version.on("close", () => resolve(output.trim())); })) },
mode: "headless-new", origin, viewport, timeoutMs,
cases: { ready: { status: "pass", state: ready }, layout: { status: "pass", state: layout }, ...(isSpecialCase ? { centroid: { status: "pass", state: centroid } } : { sanity: { status: "pass", state: sanity }, success: { status: "pass", state: success }, expectedError: { status: "pass", state: expectedError } }), reset: { status: "pass", state: reset } },
network: { requests, responses, externalRequests, externalRequestCount: externalRequests.length, httpFailures }, console: consoleEntries, exceptions,
audit64,
evidence: { screenshot: path.relative(root, evidenceScreenshot), screenshotSha256: sha256(screenshotBytes), resultHash: sha256(JSON.stringify({ sanity, centroid, success, expectedError, reset })) },
commands: ["cd FreeCAD/web && npm run build", "node FreeCAD/tools/run_p6_cam_chrome.mjs"],
policy: { browser: "Google Chrome only", nonChromeBrowsersAttempted: false },
boundaries: ["Desktop viewport only; no non-Chrome or mobile compatibility claim.", "The browser slice covers one CAM create/recompute action."],
};
fs.writeFileSync(outputPath, `${JSON.stringify(result, null, 2)}\n`);
const caseLabel = isMaterial ? `Material:${materialSuite}` : isPostGCodes ? "PostGCodes" : isTestPost ? "TestPost" : isPostSnapmaker ? "SnapmakerPost" : isPostMCodes ? "PostMCodes" : isDrillCycle ? "DrillCycleExpander" : isPostCore ? "PostCore" : isVoronoi ? "PathVoronoi" : isVcarve ? "PathVcarve" : isPathUtil ? "PathUtil" : isShapeDoc ? "PathToolShapeDoc" : isToolShape ? "PathToolShapeClasses" : isToolLibrarySerializer ? "PathToolLibrarySerializer" : isToolLibrary ? "PathToolLibrary" : isToolController ? "PathToolController" : isToolChange ? "PathToolChangeGenerator" : isToolBitSerializer ? "PathToolBitSerializer" : isToolBit ? "PathToolBit" : isToolAssetUri ? "PathToolAssetUri" : isToolAssetStore ? "PathToolAssetStore" : isToolAssetManager ? "PathToolAssetManager" : isToolAssetCache ? "PathToolAssetCache" : isToolAsset ? "PathToolAsset" : isThreadGen ? "PathThreadMillingGenerator" : isThread ? "PathThreadMilling" : isTapGen ? "PathTapGenerator" : isStock ? "PathStock" : isSpiralGen ? "PathSpiralGenerator" : isSetupSheet ? "PathSetupSheet" : isRotationGen ? "PathRotationGenerator" : isPropBag ? "PathPropertyBag" : isProfileOp ? "PathProfile" : isPrefs ? "PathPreferences" : isOpUtil ? "PathOpUtil" : isDeburr ? "PathOpDeburr" : isPathLog ? "PathLog" : isLanguage ? "PathLanguage" : isHelpers ? "PathHelpers" : isHelixGen ? "PathHelixGenerator" : isHelix ? "PathHelix" : isPathGeom ? "PathGeom" : isGenDogbone ? "PathGeneratorDogboneII" : isFacingGen ? "PathFacingGenerator" : isDrillable ? "PathDrillable" : isDrillGen ? "PathDrillGenerator" : isTags ? "PathDressupHoldingTags" : isDogbone ? "PathDressupDogboneII" : isDressArray ? "PathDressupArray" : isDepthParams ? "PathDepthParams" : isPathCore ? "PathCore" : isAnnotations ? "PathCommandAnnotations" : isAdaptive ? "PathAdaptive" : isTspSolver ? "TSPSolver" : isMasso ? "MassoG3Post" : isMachine ? "Machine" : isMachPost ? "Mach3Mach4Post" : isMach ? "Mach3Mach4LegacyPost" : isLinuxPost ? "LinuxCNCPost" : isLinux ? "LinuxCNCLegacyPost" : isLinking ? "LinkingGenerator" : isGrblPost ? "GrblPost" : isGrbl ? "GrblLegacyPost" : isGenericPost ? "GenericPost" : isGenericPlasma ? "GenericPlasma" : isGcodeUtils ? "GcodeProcessingUtils" : isFanuc ? "FanucPost" : isDressup ? "DressupPost" : isCentroidPost ? "CentroidPost" : isCentroid ? "CentroidLegacyPost" : "CAMSanity";
const nativeEvidence = path.join(evidenceRoot, `${evidenceStem}-native-${viewportName}.json`);
fs.writeFileSync(nativeEvidence, `${JSON.stringify({ schema: `freecad-web-cam-test-${evidenceStem}-native/v1`, caseId: `desktop-test.Mod.CAM.CAMTests.Test${caseLabel}`, origin, viewport, result: officialResponse?.result, requestId: (isSpecialCase ? centroid : sanity).requestId, guiUp: officialResponse?.result?.guiUp, documentCountBefore: officialResponse?.result?.documentCountBefore, documentCountAfter: officialResponse?.result?.documentCountAfter, dataTypes: officialResponse?.result?.dataTypes }, null, 2)}\n`);
fs.copyFileSync(outputPath, path.join(evidenceRoot, `${evidenceStem}-browser-${viewportName}.json`));
const desktopReportPath = path.join(docsRoot, "p6", "cam-chrome.json");
const mobileReportPath = path.join(docsRoot, "p6", "cam-chrome-mobile.json");
if (!isSpecialCase && fs.existsSync(desktopReportPath) && fs.existsSync(mobileReportPath)) {
const desktopReport = JSON.parse(fs.readFileSync(desktopReportPath, "utf8"));
const mobileReport = JSON.parse(fs.readFileSync(mobileReportPath, "utf8"));
const contract = { schema: "freecad-web-official-case-acceptance-contract/v1", caseId: "desktop-test.Mod.CAM.CAMTests.TestCAMSanity", source: "freecad-source/src/Mod/CAM/CAMTests/TestCAMSanity.py", enabledOfficialMethods: ["test00", "test010", "test020", "test050", "test060", "test070", "test080", "test090", "test100", "test110", "test120", "test130"], prerequisites: ["absolute WASM cwd and normalized fixture path", "mounted TestCAMSanity.py, Sanity.py and boxtest.fcstd", "CAM worker ready and crossOriginIsolated", "headless FreeCAD.GuiUp is bool false", "document and object runtime types recorded", "bundled NumPy package and Emscripten extension files exist in site-packages"], passConditions: ["all 12 official unittest methods pass in the WASM Python runtime", "temporary document count returns to baseline", "desktop 1440x900 and mobile 390x844 show properties in viewport with no horizontal overflow", "no page errors, failed HTTP requests or external requests", "64 workbench surface audit records pass on each host"], failureClassification: { prerequisite: "paths, fixture, worker, or runtime isolation fail before unittest methods", product: "official method assertion/error after prerequisites pass", presentation: "viewport, overflow, page/console errors", audit: "64-record workbench audit fails" }, persistence: { applicable: false, reason: "official sanity methods read CAM report data and close their temporary FCStd fixture; they do not save application state or create a database", database: "not used; when needed the project standard is SQLite WASM with database files in OPFS" } };
fs.writeFileSync(path.join(evidenceRoot, "acceptance-contract.json"), `${JSON.stringify(contract, null, 2)}\n`);
const complete = desktopReport.result === "pass" && mobileReport.result === "pass" && desktopReport.audit64?.status === "passed" && mobileReport.audit64?.status === "passed";
const profile = { schema: "freecad-web-official-case-profile/v1", caseId: contract.caseId, status: complete ? "passed" : "incomplete", sourceMapped: true, implementationStatus: "native_web_owner_ready", integrationStatus: complete ? "passed" : "integration_pending", acceptancePassed: complete, preflight: desktopReport.cases.sanity.state.response.result.preflight, officialMethods: { expected: 12, desktop: desktopReport.cases.sanity.state.response.result.tests, mobile: mobileReport.cases.sanity.state.response.result.tests }, viewports: { desktop: { viewport: desktopReport.viewport, layout: desktopReport.cases.layout.state, pageErrors: desktopReport.exceptions, overflow: desktopReport.cases.layout.state.bodyOverflow }, mobile: { viewport: mobileReport.viewport, layout: mobileReport.cases.layout.state, pageErrors: mobileReport.exceptions, overflow: mobileReport.cases.layout.state.bodyOverflow } }, audit64: { desktop: desktopReport.audit64, mobile: mobileReport.audit64 }, persistence: contract.persistence, evidence: ["acceptance-contract.json", "cam-sanity-native-desktop.json", "cam-sanity-native-mobile.json", "cam-sanity-browser-desktop.json", "cam-sanity-browser-mobile.json", "workbench-surface-audit-desktop.json", "workbench-surface-audit-mobile.json", "cam-sanity-desktop.png", "cam-sanity-mobile.png"].map(file => `docs/current/business-evidence/desktop-test-cam-testsanity-20261028/${file}`) };
fs.writeFileSync(path.join(evidenceRoot, "desktop-test-cam-sanity-profile.json"), `${JSON.stringify(profile, null, 2)}\n`);
}
fs.writeFileSync(logPath, `chrome=${result.chrome.version}\nmode=${result.mode}\nviewport=${JSON.stringify(viewport)}\nrequests=${requests.length}\nexternalRequests=${externalRequests.length}\nexceptions=${exceptions.length}\nresult=${result.result}\n`);
console.log(JSON.stringify({ result: result.result, externalRequests: externalRequests.length, exceptions: exceptions.length }));
if (result.result !== "pass") process.exitCode = 1;
} finally { cdp?.close(); chrome.kill("SIGTERM"); server.close(); }
}