// Hand-written chapter cases for the chapters that ship no scenario JSON. import fs from "node:fs"; import path from "node:path"; import { dismissStartWorkspace, openRoute, root } from "../runtime.mjs"; import { runCommand, selectModule } from "./modules.mjs"; const COURSE = path.join(root, "web", "tools", "line-course"); const MEDIA = path.join(root, "web", "teaching", "media", "line-course"); export const handwrittenCases = [ { id: "CH-ch14-production-line", title: "生产线课程:规格表、收口证据与媒体资产", priority: "P1", executor: "assets", source: "web/manual/content/ch14-production-line.md", timeoutMs: 60000, async run({ step }) { await step("line-spec 规格表可解析", "27 个模型 / 88 个部件 / 三角面 > 0 / 6 分量包围盒", async () => { const spec = JSON.parse(fs.readFileSync(path.join(COURSE, "line-spec.json"), "utf8")); const bbox = spec.sceneBBox; if (spec.modelCount !== 27) throw new Error(`modelCount ${spec.modelCount} != 27`); if (spec.partCount !== 88) throw new Error(`partCount ${spec.partCount} != 88`); if (!(spec.triangleCount > 0)) throw new Error(`triangleCount ${spec.triangleCount} is not positive`); if (!Array.isArray(bbox) || bbox.length !== 6 || !bbox.every(value => typeof value === "number" && Number.isFinite(value))) throw new Error(`sceneBBox is not 6 finite numbers: ${JSON.stringify(bbox)}`); return { modelCount: spec.modelCount, partCount: spec.partCount, triangleCount: spec.triangleCount, bbox }; }); await step("收口证据可解析", "final-status.json 含 state 与 knownBoundaries", async () => { const status = JSON.parse(fs.readFileSync(path.join(COURSE, "evidence", "final-status.json"), "utf8")); if (!status.state) throw new Error("final-status.json has no state"); if (!("knownBoundaries" in status)) throw new Error("final-status.json has no knownBoundaries"); return { state: status.state, keys: Object.keys(status).length }; }); await step("媒体目录非空", "至少一集视频或截图", async () => { const count = fs.readdirSync(MEDIA).length; if (count < 1) throw new Error("media directory is empty"); return { files: count }; }); }, }, { id: "CH-ch15-help-start", title: "帮助、命令面板、偏好与快捷键(第 15 章)", priority: "P1", executor: "functional", source: "web/manual/content/ch15-help-start.md", timeoutMs: 240000, async run({ page, origin, step }) { await step("Help 工作台源码清点可执行", "help.inspectSourceInventory 返回 kind=result", async () => { await openRoute(page, { origin }, "/workbench.html?module=Help"); await dismissStartWorkspace(page); await selectModule(page, "Help"); const response = await runCommand(page, "help.inspectSourceInventory"); if (response?.kind !== "result") throw new Error(`help.inspectSourceInventory: ${JSON.stringify(response?.error ?? response).slice(0, 240)}`); return { kind: response.kind }; }); await step("Ctrl+K 打开命令面板并检索到命令", "面板可见且 Part_Box 出现在结果中", async () => { await openRoute(page, { origin }, "/project.html", { dismissStart: true }); await page.keyboard.press("Control+k"); const palette = page.locator('[role="dialog"][aria-label="Command palette"]'); await palette.waitFor({ state: "visible", timeout: 15000 }); await palette.getByLabel("Search commands").fill("Part_Box"); const hit = palette.locator("button", { has: page.locator("code", { hasText: "Part_Box" }) }).first(); await hit.waitFor({ state: "visible", timeout: 15000 }); await palette.getByLabel("Close command palette").click(); await palette.waitFor({ state: "detached", timeout: 10000 }); return { palette: "opened", match: (await hit.count()) > 0 }; }); await step("偏好对话框可从 Tools 菜单打开", "Preferences 对话框含单位/主题控件", async () => { await page.locator(".utility-menus > button", { hasText: "Tools" }).first().click(); await page.locator('[role="menu"][aria-label="Tools"] button', { hasText: "Preferences…" }).click(); const dialog = page.locator('[role="dialog"][aria-label="Preferences"]'); await dialog.waitFor({ state: "visible", timeout: 15000 }); const units = await dialog.getByLabel("Unit system").count(); const theme = await dialog.getByLabel("Theme").count(); if (!units || !theme) throw new Error(`preferences controls missing: units=${units} theme=${theme}`); await dialog.getByLabel("Close preferences").click(); await dialog.waitFor({ state: "detached", timeout: 10000 }); return { units, theme }; }); await step("快捷键管理器可从 Tools 菜单打开", "Customize shortcuts 对话框可搜索命令", async () => { await page.locator(".utility-menus > button", { hasText: "Tools" }).first().click(); await page.locator('[role="menu"][aria-label="Tools"] button', { hasText: "Customize shortcuts…" }).click(); const dialog = page.locator('[role="dialog"][aria-label="Customize shortcuts"]'); await dialog.waitFor({ state: "visible", timeout: 15000 }); await dialog.getByLabel("Search shortcuts").fill("Part_Box"); await page.waitForTimeout(300); const rows = await dialog.locator("tbody tr").count(); if (!rows) throw new Error("shortcut search returned no rows for Part_Box"); await dialog.getByLabel("Close shortcut editor").click(); await dialog.waitFor({ state: "detached", timeout: 10000 }); return { rows }; }); }, }, ];