Files
PlantAI-rag-new/tests/paper/test_paper_intent_frontend.mjs
T
admin 91f6a1c242 feat: 新增论文撰写功能 paper-writer(独立 MCP 服务 + BFF 大脑 + 前端三卡)
- paper_writer_service(8097):FastAPI + MCP streamable-http 单端点,9 工具
  (propose_paper_outline/write_paper_section/get_paper_progress/search_refs/
  revise_paper_section/revise_paper/get_paper/complete_paper/cancel_paper),
  SQLite 三表(papers/paper_sections/citations,WAL),GB/T 7714 引用协议
- BFF:services/paper/{mcp_client,agent}.py(裸 JSON-RPC 客户端 + 规则状态机)、
  routers/paper.py、schemas.py 4 个 Paper*Block + ArtifactBlock 加 paper_id/citation_count、
  config.py 开关、main.py 条件注册、docgen.py 抽 insert_artifact 公共 helper
- 前端:intent.js paperIntent 纯函数、Composer docgen 分支 sub-route、sendPaper/轮询、
  PaperBriefCard/PaperOutlineCard/PaperProgressCard、DocPane cite-chip
- deploy/paper_restart.sh + toggle_paper.sh;compile_sdk.sh 白名单追加 paper 文件
- tests/paper 26 条(工具逻辑 + MCP 协议 + BFF 状态机 + 块 schema + 前端 intent 单测)
2026-09-30 22:29:22 +08:00

43 lines
1.6 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// tests/paper/test_paper_intent_frontend.mjs —— 论文撰写意图前端单测(node 直测)
// 验证 paperIntent 纯函数 + route() 零变化抽样(30 条全量由 test_intent_frontend.mjs 兜底)。
import { pathToFileURL } from 'node:url';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
const here = path.dirname(fileURLToPath(import.meta.url));
const repo = path.resolve(here, '../..');
const { paperIntent, route } = await import(pathToFileURL(path.join(repo, 'ui/src/intent.js')).href);
const cases = [
['帮我写一篇水稻 SPL 基因家族综述论文', true],
['撰写一篇关于小麦育种的论文', true],
['拟一份综述', true],
['帮我写一个关于疫情防控的通知', false],
['写一份项目总结报告', false],
['写一首诗', false],
['水稻基因是什么?', false],
['', false],
];
let fail = 0;
for (const [t, exp] of cases) {
const got = paperIntent(t);
const ok = got === exp;
if (!ok) fail++;
console.log(`${ok ? 'PASS' : 'FAIL'} paperIntent(${JSON.stringify(t)}) = ${got}(期望 ${exp})`);
}
const routeChecks = [
['给我写一篇关于小麦育种的论文', false, false, 'docgen'],
['写一段水稻基因的介绍', false, false, 'qa'],
];
for (const [t, a, b, exp] of routeChecks) {
const got = route(t, a, b);
const ok = got === exp;
if (!ok) fail++;
console.log(`${ok ? 'PASS' : 'FAIL'} route(${JSON.stringify(t)}) = ${got}(期望 ${exp})`);
}
const total = cases.length + routeChecks.length;
console.log(`===== paperIntent 前端单测:${total - fail}/${total} PASS =====`);
process.exit(fail === 0 ? 0 : 1);