// Runs the untouched manual runner (tools/run_user_manual_tests.mjs) as a child // process and folds its results into the functional-suite report as LEGACY-*. import { spawn } from "node:child_process"; import fs from "node:fs"; import path from "node:path"; import { root } from "../runtime.mjs"; import { persist } from "../report.mjs"; const MAP = { passed: { status: "passed", classification: "none", failureClass: null }, blocked: { status: "blocked", classification: "precondition", failureClass: "fixture" }, failed: { status: "failed", classification: "product-regression", failureClass: "product-regression" }, }; export async function runLegacyCases(options, ctx) { const ids = options.legacyIds.includes("all") ? "" : options.legacyIds.join(","); const env = { ...process.env }; if (ids) env.FREECAD_MANUAL_IDS = ids; const child = spawn(process.execPath, [path.join(root, "tools", "run_user_manual_tests.mjs")], { cwd: root, env, stdio: ["ignore", "pipe", "pipe"], }); let stdout = ""; let stderr = ""; child.stdout.on("data", chunk => { stdout += chunk; process.stdout.write(chunk); }); child.stderr.on("data", chunk => { stderr += chunk; }); const code = await new Promise(resolve => child.on("close", resolve)); const lastJson = [...stdout.trim().split("\n")].reverse().find(line => line.startsWith("{") && line.includes('"output"')); if (!lastJson) { const message = `legacy runner exited ${code} without a result line: ${(stderr || stdout).slice(-400)}`; console.error(message); ctx.results.push({ id: "LEGACY-RUNNER", title: "Legacy manual runner", priority: "P4", executor: "legacy", status: "blocked", classification: "precondition", failureClass: "fixture", steps: [], seconds: 0, error: message, startedAt: new Date().toISOString(), artifacts: {} }); persist(ctx); return []; } const { output: legacyDir } = JSON.parse(lastJson); const legacy = JSON.parse(fs.readFileSync(path.join(legacyDir, "results.json"), "utf8")); const imported = []; for (const item of legacy.results ?? []) { const mapped = MAP[item.status] ?? MAP.failed; const result = { id: `LEGACY-${item.id}`, title: item.title ?? item.id, priority: "P4", executor: "legacy", module: null, source: path.relative(root, legacyDir) + "/results.json", status: mapped.status, classification: mapped.classification, failureClass: mapped.failureClass, steps: item.steps ?? [], seconds: item.seconds ?? 0, error: item.error ?? null, startedAt: item.startedAt ?? null, artifacts: { legacy: path.relative(root, legacyDir) }, }; ctx.results.push(result); imported.push(result); if (mapped.status !== "passed") { ctx.gaps.push({ caseId: result.id, status: mapped.status, classification: mapped.classification, failureClass: mapped.failureClass, message: result.error ?? mapped.status, evidence: result.artifacts.legacy }); } } persist(ctx); return imported; }