// tests/docgen/test_intent_frontend.mjs —— DC-INTENT-CASES-01~30(前端 node 双跑) // 唯一事实源:docs/team/cases_intent.md;数据:tests/docgen/data/intent_cases.json // 执行:bash tests/docgen/run_all.sh intent(或 node tests/docgen/test_intent_frontend.mjs) // 前提:ui/src/intent.js 为纯函数(无 Vue 依赖),dev3 交付后可直接 import。 import { readFileSync, existsSync } from "node:fs"; import { fileURLToPath, pathToFileURL } from "node:url"; import path from "node:path"; const here = path.dirname(fileURLToPath(import.meta.url)); const repo = path.resolve(here, "../.."); const cases = JSON.parse(readFileSync(path.join(here, "data/intent_cases.json"), "utf-8")); const intentPath = path.join(repo, "ui/src/intent.js"); if (!existsSync(intentPath)) { console.log("[PENDING] ui/src/intent.js 未交付(dev3),本脚本 SKIP"); process.exit(77); } const { route } = await import(pathToFileURL(intentPath).href); if (typeof route !== "function") { console.error("intent.js 未导出 route 函数"); process.exit(1); } let fail = 0; for (const c of cases) { const got = route(c.text, c.has_attachments, c.has_active_artifact); const ok = got === c.expected; if (!ok) fail++; console.log(`${ok ? "PASS" : "FAIL"} #${String(c.num).padStart(2, "0")} ${c.text} -> ${got}(期望 ${c.expected})`); } console.log(`===== 前端 intent 30 条:${30 - fail}/30 PASS =====`); process.exit(fail === 0 ? 0 : 1);