A lesson-oriented page plus a loopback job service: click a lesson and the page really runs tools/web-freecad-functional-suite.mjs, tools/layout-probe.mjs or tools/static-host.mjs, streaming logs and rendering verdicts from the suite's own manifest/checkpoint/results files. - web/tools/teaching-console: catalog derived from scenarios + registry, 73 workbench lessons, template, builder (--check), Playwright gate, no-browser self-test for every spawn validation path - web/teaching/suite-runner.mjs: argv whitelist, env whitelist, single concurrent job, process-group cancel, ring-buffered logs, preflight - web/teaching/server.mjs: /api/console/* routes with startup token, Origin check, SSE events, artifact serving; existing routes untouched - preflight blocks runs (E_PREFLIGHT) instead of starting without dist, Chrome, DISPLAY, kernel or Playwright - gates: self-test OK, build --check idempotent, offline + live Playwright (MOD-Part-01 pass, cancel path) OK Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
85 lines
3.2 KiB
JavaScript
85 lines
3.2 KiB
JavaScript
/**
|
|
* Build-time case catalog for the teaching console.
|
|
*
|
|
* Derives the real case ids from their sources instead of copying them:
|
|
* - P0 shell ids and P3 crosscut ids are regex-extracted from the suites;
|
|
* - P1 chapter ids are `CH-<chapter>-<workflow>` from web/manual/scenarios;
|
|
* - P2 module ids are `MOD-<Module>-01` from the capability registry, minus
|
|
* the two modules the suite itself skips (OpenSCAD is not implemented on
|
|
* the Web, AddonManager has no interactive command).
|
|
*
|
|
* Importing the suite modules directly would pull in Playwright; the builder
|
|
* must stay runnable without a browser.
|
|
*/
|
|
import fs from "node:fs";
|
|
import path from "node:path";
|
|
import { fileURLToPath } from "node:url";
|
|
|
|
const HERE = path.dirname(fileURLToPath(import.meta.url));
|
|
export const REPO_ROOT = path.resolve(HERE, "../../..");
|
|
|
|
const SCENARIO_DIR = path.join(HERE, "../../manual/scenarios");
|
|
const AND_UP = fs.existsSync(SCENARIO_DIR) ? null : "web/manual/scenarios 不存在";
|
|
const REGISTRY = path.join(REPO_ROOT, "docs/current/feature-capability-registry.json");
|
|
const SKIP_MODULES = new Set(["OpenSCAD", "AddonManager"]);
|
|
|
|
function readIds(file) {
|
|
const source = fs.readFileSync(file, "utf8");
|
|
return [...source.matchAll(/id:\s*"([A-Z][A-Za-z0-9-]*)"/g)].map((match) => match[1]);
|
|
}
|
|
|
|
function loadChapters() {
|
|
const fromScenarios = fs.readdirSync(SCENARIO_DIR)
|
|
.filter((name) => name.endsWith(".json"))
|
|
.sort()
|
|
.map((name) => {
|
|
const scenario = JSON.parse(fs.readFileSync(path.join(SCENARIO_DIR, name), "utf8"));
|
|
return {
|
|
id: `CH-${scenario.chapter}-${scenario.workflow}`,
|
|
chapter: scenario.chapter,
|
|
workflow: scenario.workflow,
|
|
title: scenario.title ?? scenario.workflow,
|
|
};
|
|
});
|
|
// Two P1 cases are handwritten (production line + help centre), not scenarios.
|
|
const source = fs.readFileSync(path.join(REPO_ROOT, "tools/functional-suite/cases/handwritten.mjs"), "utf8");
|
|
const handwritten = [...source.matchAll(/id:\s*"(CH-[^"]+)"[\s\S]{0,200}?title:\s*"([^"]+)"/g)].map((match) => {
|
|
const [, id, title] = match;
|
|
const rest = id.slice("CH-".length);
|
|
const separator = rest.indexOf("-");
|
|
return { id, chapter: rest.slice(0, separator), workflow: rest.slice(separator + 1), title };
|
|
});
|
|
return [...fromScenarios, ...handwritten];
|
|
}
|
|
|
|
function loadModules() {
|
|
const registry = JSON.parse(fs.readFileSync(REGISTRY, "utf8"));
|
|
return registry.modules
|
|
.map((meta) => meta.module)
|
|
.filter((name) => !SKIP_MODULES.has(name))
|
|
.sort();
|
|
}
|
|
|
|
export function loadCatalog() {
|
|
if (AND_UP) throw new Error(`catalog: ${AND_UP}`);
|
|
const shell = readIds(path.join(REPO_ROOT, "tools/functional-suite/cases/shell.mjs"));
|
|
const crosscut = readIds(path.join(REPO_ROOT, "tools/functional-suite/cases/crosscut.mjs"));
|
|
const chapters = loadChapters();
|
|
const modules = loadModules();
|
|
const ids = new Set([
|
|
...shell,
|
|
...crosscut,
|
|
...chapters.map((item) => item.id),
|
|
...modules.map((name) => `MOD-${name}-01`),
|
|
]);
|
|
return {
|
|
schema: "freecad-web/teaching-console-catalog/v1",
|
|
shell,
|
|
crosscut,
|
|
chapters,
|
|
modules,
|
|
ids: [...ids].sort(),
|
|
counts: { shell: shell.length, chapters: chapters.length, modules: modules.length, crosscut: crosscut.length },
|
|
};
|
|
}
|