2026-09-30 09:15:57 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* T09 预审工作台与沙盘界面源码守卫。
|
|
|
|
|
|
*
|
|
|
|
|
|
* 这是**源码断言**,不是浏览器端到端测试(docs/v2/06-validation.md §2 已明确
|
|
|
|
|
|
* 现有 UI 脚本的性质)。它锁住的是可机械核对的约束:数值只能来自服务端、
|
|
|
|
|
|
* 演示值只在演示域、雷达只画 3–8 维、乱序响应丢弃、失败保留基线、
|
|
|
|
|
|
* 图的等价文字与键盘可达。
|
|
|
|
|
|
*/
|
|
|
|
|
|
const assert = require("node:assert/strict");
|
|
|
|
|
|
const fs = require("node:fs");
|
|
|
|
|
|
const path = require("node:path");
|
|
|
|
|
|
|
|
|
|
|
|
const root = path.resolve(__dirname, "..");
|
|
|
|
|
|
const read = (file) => fs.readFileSync(path.join(root, file), "utf8");
|
|
|
|
|
|
|
|
|
|
|
|
const panel = read("src/components/xingbang/PrescreenPanel.tsx");
|
|
|
|
|
|
const lib = read("src/lib/prescreen-run.ts");
|
|
|
|
|
|
const workbench = read("src/app/xingbang-workbench/page.tsx");
|
|
|
|
|
|
|
2026-10-01 00:30:41 +08:00
|
|
|
|
// 1. 面板挂载在既有工作台内
|
2026-09-30 09:15:57 +08:00
|
|
|
|
assert.match(workbench, /import PrescreenPanel from "@\/components\/xingbang\/PrescreenPanel"/, "工作台应导入预审面板");
|
|
|
|
|
|
assert.match(workbench, /<PrescreenPanel /, "工作台应渲染预审面板");
|
2026-10-01 00:30:41 +08:00
|
|
|
|
// AC-55(16-delivery-corrections):不再禁止新增路由,改为禁止**重复页面**。
|
|
|
|
|
|
// 两条机械判据:① 面板自己的路由目录仍然不得出现(那是把面板搬走、旧页变空壳);
|
|
|
|
|
|
// ② 已合并的旧页必须仍是重定向,不得被重新实现成独立页面。
|
2026-09-30 09:15:57 +08:00
|
|
|
|
for (const banned of ["prescreen", "sandbox", "simulation"]) {
|
2026-10-01 00:30:41 +08:00
|
|
|
|
assert.ok(!fs.existsSync(path.join(root, "src/app", banned)), `不得把面板搬到独立路由 src/app/${banned}`);
|
|
|
|
|
|
}
|
|
|
|
|
|
for (const merged of ["trajectory", "review-workbench", "report-workbench", "collateral-workbench"]) {
|
|
|
|
|
|
assert.match(read(`src/app/${merged}/page.tsx`), /redirect\(/,
|
|
|
|
|
|
`已合并页 src/app/${merged} 必须保持重定向,不得恢复成独立页面`);
|
2026-09-30 09:15:57 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 2. 复用既有样式,不新增样式表
|
|
|
|
|
|
assert.ok(!/^import .*\.css";/m.test(panel), "面板应复用 workspace.css 既有 class,不新增样式表");
|
|
|
|
|
|
|
|
|
|
|
|
// 3. 数值只能来自服务端:前端不得复制演示情景表(AC-30/31)
|
|
|
|
|
|
for (const [name, source] of [["panel", panel], ["lib", lib]]) {
|
|
|
|
|
|
assert.ok(!/0\.(42|58|51|64)\b/.test(source), `${name} 不得硬编码演示概率值`);
|
|
|
|
|
|
assert.ok(!/"(00|10|01|11)"\s*:/.test(source), `${name} 不得在客户端复制演示情景表`);
|
|
|
|
|
|
}
|
|
|
|
|
|
assert.match(panel, /simulation\.probability_view/, "情景数值必须取自服务端响应");
|
|
|
|
|
|
|
|
|
|
|
|
// 4. 演示值只在演示域显示,且紧邻"人工设定"说明(AC-12/30、DESIGN §38)
|
2026-09-30 10:59:27 +08:00
|
|
|
|
assert.match(panel, /const domainName = run\?\.data_domain/, "演示值必须按数据域判定后才显示");
|
|
|
|
|
|
assert.match(panel, /demoValue\(domainName, simulation\?\.baseline_probability_view \|\| run\?\.probability_view\)/,
|
|
|
|
|
|
"基线演示值必须取自服务端基线视图,不能由前端合成");
|
|
|
|
|
|
assert.match(panel, /if \(first && first\.data_domain === "demo"\) await applyScenario\(\[\], first\)/,
|
|
|
|
|
|
"首屏演示值只对演示域取值,production 域不得请求演示表");
|
2026-09-30 09:15:57 +08:00
|
|
|
|
assert.match(panel, /未完成真实历史校准/, "未校准时必须说明为何不显示概率");
|
|
|
|
|
|
assert.match(panel, /正式审批由人工决定/, "演示值旁必须有用途边界说明");
|
|
|
|
|
|
assert.match(lib, /domain !== "demo"/, "lib 必须在非演示域返回 null");
|
|
|
|
|
|
|
|
|
|
|
|
// 5. 雷达只对同刻度 3–8 维绘制,其余给完整列表;空维度不补占位轴(AC-44)
|
|
|
|
|
|
assert.match(lib, /RADAR_MIN = 3/);
|
|
|
|
|
|
assert.match(lib, /RADAR_MAX = 8/);
|
2026-09-30 09:25:25 +08:00
|
|
|
|
assert.match(lib, /layout: "radar"/);
|
|
|
|
|
|
assert.match(lib, /DimensionLayout = "empty" \| "list" \| "grouped" \| "radar" \| "faceted"/, "呈现词汇必须与后端 review_plan.presentation 一致");
|
2026-09-30 09:15:57 +08:00
|
|
|
|
assert.match(lib, /EMPTY_DIMENSIONS = "当前方案尚未配置核查维度"/);
|
2026-09-30 09:25:25 +08:00
|
|
|
|
assert.match(panel, /shown\.layout === "radar" && <RadarChart/, "只有判定为雷达时才画雷达");
|
|
|
|
|
|
assert.match(panel, /shown\.layout === "empty" && <div className="ra-empty">/, "空维度用空状态,不补六轴");
|
2026-09-30 09:15:57 +08:00
|
|
|
|
assert.match(panel, /文字列表与图等价/, "图必须有等价文字列表");
|
2026-09-30 12:34:45 +08:00
|
|
|
|
// 纠偏第一批:面板必须展示本次核查结果与依据,缺证不得改写成通过
|
|
|
|
|
|
assert.match(panel, /核查结果(\{/, "面板必须展示本次核查结果");
|
|
|
|
|
|
assert.match(panel, /未完成项:\{item\.message\}/, "降级记录必须显示到界面");
|
|
|
|
|
|
assert.match(panel, /查看 \$\{item\.title \|\| item\.code\} 的依据/, "每条核查结果必须能打开依据");
|
|
|
|
|
|
assert.match(panel, /本次没有可展示的原文片段/, "没有证据时必须说明按缺证处理,不得留白或编造");
|
|
|
|
|
|
assert.match(panel, /没有发现问题不等于已经通过/, "空结果不得被读成通过");
|
2026-09-30 10:59:27 +08:00
|
|
|
|
assert.match(panel, /width=\{\d+\} height=\{\d+\} viewBox=/, "雷达必须给显式尺寸,否则会撑满容器(真渲染验证过的缺陷)");
|
|
|
|
|
|
assert.match(panel, /<text key=\{`label-\$\{item\.id\}`\}/, "雷达必须有轴标签,图不能只有形状");
|
|
|
|
|
|
assert.match(panel, /strokeDasharray="4 4"/, "基线必须用虚线,不能只靠颜色区分");
|
|
|
|
|
|
assert.match(panel, /hasScenario = Array\.from\(scenarioStages\.values\(\)\)\.some\(\(item\) => item\.assumed\)/,
|
|
|
|
|
|
"没有勾选假设时不得画出实线情景轮廓");
|
|
|
|
|
|
assert.match(panel, /阶段 \{stage \?\? "—"\} · \{stageName\(stage\)\}/, "维度必须同时给出阶段序号与名称");
|
2026-09-30 09:15:57 +08:00
|
|
|
|
|
|
|
|
|
|
// 6. 乱序与过期响应必须丢弃(AC-31)
|
|
|
|
|
|
assert.match(panel, /ticket !== seq\.current/, "旧请求晚到必须丢弃");
|
|
|
|
|
|
assert.match(panel, /returned !== \[\.\.\.keys\]\.sort\(\)\.join\(","\)/, "结果与当前选择不一致时必须丢弃");
|
|
|
|
|
|
|
|
|
|
|
|
// 7. 失败保留基线并标未完成;计算中不得先给乐观增幅
|
|
|
|
|
|
assert.match(panel, /该情景未完成。基线数值与原有意见保持不变/, "失败必须保留基线");
|
|
|
|
|
|
assert.match(panel, /不会先给一个乐观增幅/, "计算中不得预告结果");
|
|
|
|
|
|
assert.match(panel, /不是各项增量的简单相加/, "沙盘必须说明组合非加和");
|
|
|
|
|
|
|
|
|
|
|
|
// 8. 键盘可达与无障碍
|
|
|
|
|
|
assert.match(panel, /<input type="checkbox"/, "假设动作必须是原生可聚焦控件");
|
|
|
|
|
|
assert.match(panel, /aria-live="polite"/, "变化的数值区必须有 aria-live");
|
|
|
|
|
|
assert.match(panel, /aria-label=\{`查看 \$\{item\.id\} 的依据`\}/, "维度依据入口必须有可读名称");
|
|
|
|
|
|
assert.ok(/<svg[^>]*aria-label=/.test(panel.replace(/\n/g, " ")), "雷达必须有文字等价说明");
|
|
|
|
|
|
|
|
|
|
|
|
// 9. 来源与数据域用文字+图标共同区分,不靠颜色单独传意(AC-42)
|
|
|
|
|
|
assert.match(lib, /text: "历史提炼"/);
|
|
|
|
|
|
assert.match(lib, /text: "人工创建"/);
|
|
|
|
|
|
assert.match(lib, /text: "制度导入"/);
|
|
|
|
|
|
assert.match(lib, /icon: "history"/);
|
|
|
|
|
|
assert.match(panel, /domain\.text/, "数据域必须以文字呈现");
|
|
|
|
|
|
|
|
|
|
|
|
// 10. 阶段是序数,不得换算成概率
|
|
|
|
|
|
assert.match(lib, /雷达面积不换算成百分比|STAGE_LEGEND/, "必须说明阶段与概率无关");
|
|
|
|
|
|
assert.ok(!/probability\s*[:=]\s*[0-9]/.test(panel), "面板不得写入任何概率数值");
|
|
|
|
|
|
|
|
|
|
|
|
console.log("prescreen-ui: PASS");
|