Files
quality_analyse/web/verification/agent_original_answer.test.mjs
T
lyun f1a2fbd494 统一:DSH 智能分析、Top100 与图表静默恢复
接入 DSH 专用运行时和对话界面,保留模型原始回答,支持会话分页、连续追问与显式报告。
补齐组合筛选、各维度 Top100、分组查询到排名图的转换,图表故障静默省略并基于保存数据自动恢复。
优化报告风格、图表顺序和表格换行,更新接入说明及构建输入。

验证:独立目录前后端构建通过;118 项 Java、102 项前端、102 项图表、14 项 DSH 应用和 13 项组合筛选检查通过。
仅提交相关源码、锁定依赖与测试;不包含凭据、会话、业务数据或本地产物。
2026-11-12 11:57:41 +08:00

43 lines
2.7 KiB
JavaScript

import test from 'node:test';
import assert from 'node:assert/strict';
import fs from 'node:fs';
import ts from 'typescript';
import React from 'react';
import { renderToStaticMarkup } from 'react-dom/server';
import { tableTextAlignment } from '../src/tableTextAlignment.ts';
import { sanitizeAnalysisDisplayText } from '../src/analysisDisplayText.ts';
import { analysisEvidenceParts } from '../src/analysisEvidenceRefs.ts';
const source = fs.readFileSync(new URL('../src/AiMarkdown.tsx', import.meta.url), 'utf8')
.replace(/^import .*;$/gm, '').replace('export function AiMarkdown', 'function AiMarkdown');
const Markdown = new Function('React', 'tableTextAlignment', 'sanitizeAnalysisDisplayText', 'analysisEvidenceParts',
ts.transpileModule(`${source}\nreturn AiMarkdown;`, { compilerOptions: { target: ts.ScriptTarget.ES2022, jsx: ts.JsxEmit.React } }).outputText
)(React, tableTextAlignment, sanitizeAnalysisDisplayText, analysisEvidenceParts);
test('original answers preserve wording, table headers, headings and escaped markup', () => {
const answer = '## 模型原始回答\n\n数学说明保留。\n\n| 月份 | 原始值 |\n| --- | --- |\n| 8月 | 98.35% |\n\n<script>alert(1)</script>';
const html = renderToStaticMarkup(React.createElement(Markdown, { content: answer, preserveSource: true }));
assert.match(html, /<h2>模型原始回答<\/h2>/);
assert.match(html, /数学说明保留/);
assert.match(html, /&lt;script&gt;alert\(1\)&lt;\/script&gt;/);
assert.doesNotMatch(html, /<script|序号|核心结论/);
assert.equal((html.match(/<th(?:>| )/g) || []).length, 2);
});
test('report layout preserves original Markdown instead of converting bold prose into chapters', async () => {
const { buildAgentReportLayout } = await import('../src/agent/agentReportLayout.ts');
const text = '**原始小节**\n\n原始正文。\n\n1. 原始项目。';
const report = buildAgentReportLayout(text, []);
assert.equal(report.sections.map(section => section.markdown).join('\n\n'), text);
});
test('original Markdown rules and quotes render semantically without altering their words or tables', () => {
const answer = '首句。\n---\n> **范围:**2026年10月\n> 保留 <script> 原文\n\n| 对象 | 值 |\n| --- | --- |\n| 总体 | 95.46% |\n\n***\n\n末句。';
const html = renderToStaticMarkup(React.createElement(Markdown, { content: answer, preserveSource: true }));
assert.equal((html.match(/<hr\/>/g) || []).length, 2);
assert.match(html, /<blockquote><strong>范围:<\/strong>2026年10月<br\/>保留 &lt;script&gt; 原文<\/blockquote>/);
assert.equal((html.match(/<table>/g) || []).length, 1);
assert.match(html, /首句。/); assert.match(html, /末句。/);
assert.doesNotMatch(html, /<script>|序号/);
});