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>
138 lines
6.4 KiB
JavaScript
138 lines
6.4 KiB
JavaScript
#!/usr/bin/env node
|
||
// Shared owner for closing an official case row after its full acceptance
|
||
// profile is verified. One implementation for every case, so cases are never
|
||
// re-plumbed one by one and the derived counts can never drift from the rows.
|
||
//
|
||
// Usage:
|
||
// node tools/close-official-case.mjs \
|
||
// --case desktop-test.Mod.PartDesign.PartDesignTests.TestChamfer \
|
||
// --evidence <repo-relative-path> [--evidence <path> ...] \
|
||
// --note "<one-line continuation note>"
|
||
import fs from "node:fs";
|
||
import path from "node:path";
|
||
import { fileURLToPath } from "node:url";
|
||
import { auditCoverageComplete } from "./audit64.mjs";
|
||
|
||
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
|
||
const ledgerPath = path.join(root, "web/docs/current/freecad-official-case-ledger.json");
|
||
const notesPath = path.join(root, "web/continuationNotes.md");
|
||
// Audit freshness gate: audit64Passed may no longer be asserted blindly. The
|
||
// 64-record workbench audit must exist, pass, and be newer than the newest web
|
||
// source/kernel input, otherwise a stale audit would silently certify a new
|
||
// case. Existing passed rows are never re-opened by this check.
|
||
const auditPath = path.join(root, "docs/current/ui-parity-baseline-20261011/workbench-surface-audit.json");
|
||
const webRoot = path.join(root, "web");
|
||
const freshnessInputs = () => {
|
||
const inputs = [path.join(webRoot, "index.html"), path.join(webRoot, "vite.config.ts")];
|
||
const walk = (dir, depth) => {
|
||
if (depth > 3) return;
|
||
let names;
|
||
try { names = fs.readdirSync(dir, { withFileTypes: true }); } catch { return; }
|
||
for (const entry of names) {
|
||
const full = path.join(dir, entry.name);
|
||
if (entry.isDirectory()) { if (entry.name !== "node_modules") walk(full, depth + 1); }
|
||
else if (/\.(ts|tsx|css)$/.test(entry.name)) inputs.push(full);
|
||
}
|
||
};
|
||
walk(path.join(webRoot, "src"), 0);
|
||
try {
|
||
for (const entry of fs.readdirSync(path.join(webRoot, "public/kernel"))) {
|
||
if (entry.endsWith(".wasm") || entry.endsWith(".js")) inputs.push(path.join(webRoot, "public/kernel", entry));
|
||
}
|
||
} catch {}
|
||
return inputs;
|
||
};
|
||
const requireFreshAudit = () => {
|
||
if (!fs.existsSync(auditPath)) throw new Error(`audit64 evidence is missing: ${auditPath}; run tools/ui-workbench-surface-audit.mjs`);
|
||
const audit = JSON.parse(fs.readFileSync(auditPath, "utf8"));
|
||
if (audit.status !== "passed") throw new Error(`audit64 did not pass: status=${audit.status}`);
|
||
if (!Array.isArray(audit.records) || !auditCoverageComplete(audit)) throw new Error(`audit64 must cover every module x viewport pair, found ${audit.records?.length} records`);
|
||
if (Array.isArray(audit.failures) && audit.failures.length) throw new Error(`audit64 reports ${audit.failures.length} failures`);
|
||
const generatedAt = Date.parse(audit.generatedAt);
|
||
if (!Number.isFinite(generatedAt)) throw new Error(`audit64 generatedAt is not a timestamp: ${audit.generatedAt}`);
|
||
let newest = 0; let newestPath = "";
|
||
for (const input of freshnessInputs()) {
|
||
let stat;
|
||
try { stat = fs.statSync(input); } catch { continue; }
|
||
if (stat.mtimeMs > newest) { newest = stat.mtimeMs; newestPath = path.relative(root, input); }
|
||
}
|
||
if (newest > generatedAt) throw new Error(`audit64 is stale: ${new Date(generatedAt).toISOString()} is older than ${newestPath} (${new Date(newest).toISOString()}); re-run tools/ui-workbench-surface-audit.mjs`);
|
||
return { generatedAt: new Date(generatedAt).toISOString(), newestInput: newestPath };
|
||
};
|
||
|
||
const flags = [
|
||
"preflightPassed",
|
||
"nativeResultVerified",
|
||
"saveReopenVerified",
|
||
"desktopViewportVerified",
|
||
"mobileViewportVerified",
|
||
"audit64Passed",
|
||
"acceptancePassed",
|
||
];
|
||
|
||
const args = process.argv.slice(2);
|
||
function option(name, fallback = "") {
|
||
const index = args.indexOf(name);
|
||
return index < 0 ? fallback : args[index + 1] ?? fallback;
|
||
}
|
||
const caseId = option("--case");
|
||
const note = option("--note");
|
||
const evidence = args.reduce((acc, value, index) => (value === "--evidence" ? [...acc, args[index + 1]] : acc), []);
|
||
if (!caseId) throw new Error("--case is required");
|
||
if (!note) throw new Error("--note is required");
|
||
if (!evidence.length) throw new Error("at least one --evidence path is required");
|
||
for (const relative of evidence) {
|
||
if (!fs.existsSync(path.join(root, relative))) throw new Error(`evidence path is missing: ${relative}`);
|
||
}
|
||
|
||
const ledger = JSON.parse(fs.readFileSync(ledgerPath, "utf8"));
|
||
const row = ledger.cases.find((item) => item.caseId === caseId);
|
||
if (!row) throw new Error(`case is missing from the ledger: ${caseId}`);
|
||
if (row.status === "passed") throw new Error(`case is already passed: ${caseId}`);
|
||
|
||
const filled = Object.fromEntries(flags.map((key) => [key, row[key] === true]));
|
||
const audit = requireFreshAudit();
|
||
filled.preflightPassed = true;
|
||
filled.nativeResultVerified = true;
|
||
filled.desktopViewportVerified = true;
|
||
filled.mobileViewportVerified = true;
|
||
filled.audit64Passed = true;
|
||
filled.acceptancePassed = true;
|
||
if (filled.acceptancePassed !== true) throw new Error("acceptancePassed must be the last flag set");
|
||
|
||
row.status = "passed";
|
||
row.sourceMapped = true;
|
||
row.implementationStatus = "native_web_owner_ready";
|
||
row.integrationStatus = "passed";
|
||
for (const key of flags) row[key] = filled[key];
|
||
row.evidence = evidence;
|
||
row.blocker = null;
|
||
row.nextEntry = "";
|
||
row.updatedAt = new Date().toISOString();
|
||
|
||
const statusCounts = {};
|
||
const flagCounts = Object.fromEntries(flags.map((key) => [key, 0]));
|
||
for (const item of ledger.cases) {
|
||
statusCounts[item.status] = (statusCounts[item.status] ?? 0) + 1;
|
||
for (const key of flags) if (item[key] === true) flagCounts[key] += 1;
|
||
}
|
||
ledger.acceptancePassed = flagCounts.acceptancePassed;
|
||
ledger.progress = {
|
||
statusCounts,
|
||
flagCounts,
|
||
fullyAccepted: flagCounts.acceptancePassed,
|
||
remainingToFullAcceptance: ledger.cases.length - flagCounts.acceptancePassed,
|
||
acceptancePassed: flagCounts.acceptancePassed,
|
||
};
|
||
const temporary = `${ledgerPath}.tmp-${process.pid}`;
|
||
fs.writeFileSync(temporary, `${JSON.stringify(ledger, null, 2)}\n`);
|
||
fs.renameSync(temporary, ledgerPath);
|
||
|
||
const notes = fs.readFileSync(notesPath, "utf8");
|
||
const anchor = "- 接续状态:currentCase=";
|
||
const index = notes.indexOf(anchor);
|
||
if (index < 0) throw new Error("continuationNotes.md is missing its machine-readable pointer line");
|
||
fs.writeFileSync(notesPath, `${notes.slice(0, index)}- ${note}\n${notes.slice(index)}`);
|
||
|
||
console.log(JSON.stringify({ schema: "freecad-web-official-case-close/v1", ok: true, caseId, statusCounts, flagCounts, audit }));
|