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>
147 lines
8.4 KiB
JavaScript
147 lines
8.4 KiB
JavaScript
#!/usr/bin/env node
|
|
/**
|
|
* M4 case 2 replay: desktop-test.Mod.BIM.bimtests.TestArchAxis.
|
|
* Transport is page-route: bim.testArchAxis is not in BIM_NATIVE_DESKTOP_COMMANDS
|
|
* nor explicitly allowed, so module-router returns native_source_required.
|
|
*/
|
|
import fs from "node:fs";
|
|
import path from "node:path";
|
|
import { spawn } from "node:child_process";
|
|
import { createRequire } from "node:module";
|
|
import { fileURLToPath } from "node:url";
|
|
import { findChrome, startStaticHost } from "../static-host.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 require = createRequire(path.join(root, "web", "package.json"));
|
|
const { chromium } = require("playwright");
|
|
|
|
const CASE_ID = "desktop-test.Mod.BIM.bimtests.TestArchAxis";
|
|
const EXPECTED_HEADLESS = ["test_make_axis_default", "test_make_axis_custom", "test_axis_properties", "test_makeAxis", "test_makeAxisSystem"];
|
|
const TIMEOUT_MS = 120000;
|
|
const evidenceDir = path.join(root, "web", "docs", "current", "mcp-evidence", `desktop-test-arch-axis-${new Date().toISOString().slice(0, 10).replaceAll("-", "")}`);
|
|
fs.mkdirSync(evidenceDir, { recursive: true });
|
|
|
|
const host = await startStaticHost(distRoot, "bim.html");
|
|
const browser = await chromium.launch({ executablePath: findChrome(), headless: process.env.HEADLESS !== "0", args: ["--no-sandbox", "--disable-dev-shm-usage"] });
|
|
|
|
async function waitFor(page, label, predicate) {
|
|
const deadline = Date.now() + TIMEOUT_MS;
|
|
let last = null;
|
|
while (Date.now() < deadline) {
|
|
last = await page.evaluate(() => window.__freecadBimState ?? null);
|
|
if (predicate(last)) return last;
|
|
if (last?.stage === "error") throw new Error(`${label} failed: ${JSON.stringify(last).slice(0, 500)}`);
|
|
await new Promise((r) => setTimeout(r, 100));
|
|
}
|
|
throw new Error(`${label} timed out: ${JSON.stringify(last).slice(0, 500)}`);
|
|
}
|
|
|
|
async function runViewport(name, viewport) {
|
|
const page = await browser.newPage({ viewport });
|
|
const pageErrors = [];
|
|
const failedRequests = [];
|
|
page.on("pageerror", (e) => pageErrors.push(String(e)));
|
|
page.on("requestfailed", (r) => failedRequests.push(`${r.url()} ${r.failure()?.errorText ?? ""}`));
|
|
const out = { viewport: name, dimensions: viewport, pageErrors, failedRequests };
|
|
try {
|
|
await page.goto(`${host.origin}/bim.html?action=testArchAxis`, { waitUntil: "domcontentloaded", timeout: 60000 });
|
|
out.ready = (await waitFor(page, "BIM ready", (v) => v?.stage === "ready")).stage;
|
|
out.layout = await page.evaluate(() => {
|
|
const canvas = document.querySelector(".canvas")?.getBoundingClientRect();
|
|
return {
|
|
crossOriginIsolated: globalThis.crossOriginIsolated === true,
|
|
bodyOverflow: document.documentElement.scrollWidth > innerWidth,
|
|
canvasIntersectsViewport: Boolean(canvas && canvas.right > 0 && canvas.left < innerWidth && canvas.bottom > 0 && canvas.top < innerHeight),
|
|
};
|
|
});
|
|
await page.click("#inspect");
|
|
const state = await waitFor(page, "BIM TestArchAxis", (v) => v?.stage === "test-arch-axis-success");
|
|
const result = state.response?.result ?? null;
|
|
out.kind = state.response?.kind ?? null;
|
|
out.result = result;
|
|
out.testCount = Array.isArray(result?.tests) ? result.tests.length : 0;
|
|
out.allPassed = out.testCount > 0 && result.tests.every((t) => t.passed === true);
|
|
out.failing = (result?.tests ?? []).filter((t) => t.passed !== true).map((t) => t.name);
|
|
out.methods = (result?.tests ?? []).map((t) => t.name);
|
|
out.guiSkipped = result?.guiSkipped ?? null;
|
|
out.resourcesReleased = result?.resourcesReleased ?? null;
|
|
out.bubbles = await page.evaluate(() => ({
|
|
labelCount: document.querySelectorAll("[data-axis-bubble], .axis-bubble, .bubble").length,
|
|
canvasLabels: document.querySelectorAll("canvas").length,
|
|
}));
|
|
out.screenshot = path.join(evidenceDir, `arch-axis-${name}.png`);
|
|
await page.screenshot({ path: out.screenshot, fullPage: true });
|
|
await page.click("#reset");
|
|
out.reset = (await waitFor(page, "BIM reset", (v) => v?.stage === "reset")).stage;
|
|
} finally { await page.close(); }
|
|
return out;
|
|
}
|
|
|
|
const desktop = await runViewport("desktop", { width: 1440, height: 900 });
|
|
const mobile = await runViewport("mobile", { width: 390, height: 844 });
|
|
|
|
const audit = await new Promise((resolve) => {
|
|
const child = spawn(process.execPath, [path.join(root, "tools", "ui-workbench-surface-audit.mjs")], { cwd: root, env: { ...process.env, FREECAD_BROWSER_ORIGIN: host.origin } });
|
|
let output = "";
|
|
child.stdout.on("data", (c) => { output += c.toString(); });
|
|
child.stderr.on("data", (c) => { output += c.toString(); });
|
|
child.once("close", (code) => resolve({ code, output: output.trim().slice(-1200) }));
|
|
});
|
|
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",
|
|
exitCode: audit.code, records: auditReport?.records?.length ?? null, failures: auditReport?.failures?.length ?? null, origin: host.origin, output: audit.output,
|
|
};
|
|
|
|
const assertions = [];
|
|
const A = (n, ok, actual, expected) => assertions.push({ name: n, ok, actual, expected });
|
|
for (const [label, r] of [["desktop", desktop], ["mobile", mobile]]) {
|
|
A(`${label} worker ready`, r.ready === "ready", r.ready, "ready");
|
|
A(`${label} 5 headless methods`, r.testCount === 5, r.testCount, 5);
|
|
A(`${label} all methods passed`, r.allPassed === true, r.allPassed, true);
|
|
A(`${label} method names match workflow evidence`, JSON.stringify(r.methods) === JSON.stringify(EXPECTED_HEADLESS), r.methods, EXPECTED_HEADLESS);
|
|
A(`${label} gui skipped`, r.guiSkipped === true, r.guiSkipped, true);
|
|
A(`${label} resources released`, r.resourcesReleased === true, r.resourcesReleased, true);
|
|
A(`${label} crossOriginIsolated`, r.layout.crossOriginIsolated === true, r.layout.crossOriginIsolated, true);
|
|
A(`${label} no horizontal overflow`, r.layout.bodyOverflow === false, r.layout.bodyOverflow, false);
|
|
A(`${label} canvas intersects viewport`, r.layout.canvasIntersectsViewport === true, r.layout.canvasIntersectsViewport, true);
|
|
A(`${label} no page errors`, r.pageErrors.length === 0, r.pageErrors, []);
|
|
A(`${label} no failed requests`, r.failedRequests.length === 0, r.failedRequests, []);
|
|
A(`${label} reset works`, r.reset === "reset", r.reset, "reset");
|
|
}
|
|
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: "page-route",
|
|
transportReason: "bim.testArchAxis is absent from BIM_NATIVE_DESKTOP_COMMANDS and from the explicit allow list in web/src/native-source-policy.ts, so module-router returns native_source_required",
|
|
origin: host.origin,
|
|
contract: {
|
|
source: "freecad-source/src/Mod/BIM/bimtests/TestArchAxis.py",
|
|
expectedHeadlessMethods: EXPECTED_HEADLESS,
|
|
passConditions: ["5 headless official methods pass", "axis bubbles render in both viewports", "desktop 1440x900 and mobile 390x844 without horizontal overflow", "no page errors or failed requests", "64 workbench surface audit records pass"],
|
|
},
|
|
desktop: { result: desktop.result, layout: desktop.layout, bubbles: desktop.bubbles, pageErrors: desktop.pageErrors, failedRequests: desktop.failedRequests, screenshot: path.relative(root, desktop.screenshot) },
|
|
mobile: { result: mobile.result, layout: mobile.layout, bubbles: mobile.bubbles, pageErrors: mobile.pageErrors, failedRequests: mobile.failedRequests, screenshot: path.relative(root, mobile.screenshot) },
|
|
audit64,
|
|
assertions,
|
|
passed: failed.length === 0,
|
|
failed,
|
|
};
|
|
const evidencePath = path.join(evidenceDir, "case-replay.json");
|
|
fs.writeFileSync(evidencePath, `${JSON.stringify(evidence, null, 1)}\n`);
|
|
await browser.close();
|
|
host.close();
|
|
console.log(JSON.stringify({ passed: evidence.passed, failed, testCount: desktop.testCount, audit64: audit64.status, evidence: path.relative(root, evidencePath) }, null, 1));
|
|
process.exitCode = evidence.passed ? 0 : 1;
|