允许 Agent 在循环中查目录、修正查询和提问,保留实时权限检查及模型原始回答。 统一相同查询证据与图表资源;排名补齐阶段指标,修正 OR 重量筛选,并限制模型明细输入。 增加运行恢复、图表自适应坐标轴与两位小数,修复报告主图选择、重复图及边缘标签。 验证:独立副本通过 162 项 Python、73 项前端及 21 项后端测试,前端构建通过。 线上已用原 8 题复测,并追加两轮双期对比;TOP100 与组合筛选分别核对 100 行和 20 行。
69 lines
4.5 KiB
JavaScript
69 lines
4.5 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('image syntax renders as a chart reference or caption without rewriting source or fetching URLs', () => {
|
|
const answer = '前文。 后文。\n\n\n\n``';
|
|
const html = renderToStaticMarkup(React.createElement(Markdown, { content: answer, preserveSource: true, imageTargets: { 'chart:actual-chart': 'actual-chart' } }));
|
|
assert.match(html, /href="#actual-chart">趋势标题<\/a>/);
|
|
assert.match(html, /前文。/); assert.match(html, /后文。/);
|
|
assert.match(html, /ai-markdown-image-caption[^>]*>未绑定标题<\/span>/);
|
|
assert.match(html, /<code>!\[代码示例\]\(chart:example\)<\/code>/);
|
|
assert.doesNotMatch(html, /<img|tracker\.png|chart:actual-chart/);
|
|
assert.ok(answer.includes(''));
|
|
});
|
|
|
|
test('a bound chart image renders in place while surrounding prose and code examples remain intact', () => {
|
|
const answer = '分析前文。\n\n\n\n分析后文。\n\n```markdown\n\n```';
|
|
const source = 'data:image/svg+xml;charset=utf-8,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%2F%3E';
|
|
const html = renderToStaticMarkup(React.createElement(Markdown, {
|
|
content: answer, preserveSource: true,
|
|
renderImage: (alt, target, key) => target === 'chart:verified' ? React.createElement('img', { key, src: source, alt }) : undefined,
|
|
}));
|
|
assert.match(html, /<img[^>]+alt="产品趋势"/);
|
|
assert.equal((html.match(/<img /g) || []).length, 1);
|
|
assert.ok(html.indexOf('分析前文') < html.indexOf('<img'));
|
|
assert.ok(html.indexOf('<img') < html.indexOf('分析后文'));
|
|
assert.match(html, /<pre><code>!\[代码示例\]\(chart:verified\)/);
|
|
assert.ok(answer.includes(''));
|
|
});
|
|
|
|
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, /<script>alert\(1\)<\/script>/);
|
|
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\/>保留 <script> 原文<\/blockquote>/);
|
|
assert.equal((html.match(/<table>/g) || []).length, 1);
|
|
assert.match(html, /首句。/); assert.match(html, /末句。/);
|
|
assert.doesNotMatch(html, /<script>|序号/);
|
|
});
|