修复:完整展示AI原文并穿插图表,统一运行反馈与变化符号

This commit is contained in:
2026-11-02 12:03:37 +08:00
parent cf8e25a30d
commit 903fa94c00
35 changed files with 1016 additions and 172 deletions
+7 -3
View File
@@ -1,3 +1,4 @@
import { originalAnalysisBody, originalAnalysisSections } from '../src/analysisOriginalBody.ts';
import test from 'node:test';
import assert from 'node:assert/strict';
import { readFileSync } from 'node:fs';
@@ -22,7 +23,9 @@ const turn = (readingSummary = summary()) => ({ id: 'turn', question: '9月合
releaseId: 'release', visuals: [chart], queryEvidenceRefs: ['Q11111111', 'Q22222222'], readingSummary,
} });
let OriginalContent=()=>null;
function component(source, name, bindings) {
bindings={originalAnalysisBody,AnalysisOriginalContent:props=>React.createElement(OriginalContent,props),...bindings};
const cleaned = source.replace(/^import .*;\n/gm, '').replace(/^export /gm, '');
return new Function('React', ...Object.keys(bindings), ts.transpileModule(`${cleaned}\nreturn ${name};`, {
fileName: `${name}.tsx`, compilerOptions: { target: ts.ScriptTarget.ES2022, jsx: ts.JsxEmit.React },
@@ -30,6 +33,7 @@ function component(source, name, bindings) {
}
const markdownSource = readFileSync(new URL('../src/AiMarkdown.tsx', import.meta.url), 'utf8');
const AiMarkdown = component(markdownSource, 'AiMarkdown', { sanitizeAnalysisDisplayText, analysisEvidenceParts });
OriginalContent=component(readFileSync(new URL('../src/AnalysisOriginalContent.tsx',import.meta.url),'utf8'),'AnalysisOriginalContent',{AiMarkdown,originalAnalysisSections});
test('conclusion layout separates the lead, findings and table titles without rewriting checked facts', () => {
const content = '9月综合合格率**95.13%**,较8月的**95.57%**下降**0.44个百分点**。主要来自**黑片阶段**,正式影响为**-0.30个百分点**;亮片影响**-0.15个百分点**。\n\n'
@@ -81,7 +85,7 @@ const visibleSummary = html => html.match(/<div class="ai-markdown[^"]*">([\s\S]
test('comparison readout uses the checked change, preserving rounded stage values and explicit scope', () => {
const sentence='汽车交通2026年9月黑片合格率**97.27%**,较8月的**97.58%**下降**0.30个百分点**。';
const value=checkedConclusionComparison(sentence);
assert.equal(value.change,'0.30'); assert.equal(value.currentLabel,'汽车交通2026年9月');
assert.equal(value.change,'-0.30'); assert.equal(value.currentLabel,'汽车交通2026年9月');
assert.equal(value.previousLabel,'8月'); assert.equal(value.current,'97.27%'); assert.equal(value.previous,'97.58%');
for (const invalid of ['9月合格率95.13%。','9月合格率95.13%,较8月95.57%。','9月合格率101.00%,较8月95.57%下降0.44个百分点。']) assert.equal(checkedConclusionComparison(invalid),null);
assert.equal(checkedConclusionComparison('9月合格率0.00%,较8月95.57%下降95.57个百分点。').current,'0.00%');
@@ -93,7 +97,7 @@ test('conclusion chapters put each authorized figure beside its cited topic, wit
'**重点规格**:甲规格报废增加128.45 kg。[Q11111111]']});
const figures=[{...chart,id:'department',metric:'rate_drop_pp',dimension:'department',evidenceRefs:['Q22222222']},{...chart,id:'product',metric:'scrap_delta',dimension:'product'}];
const document=buildConclusionDocument(buildAnalysisReadingModel('',[],data.question,data).reading,figures);
assert.equal(document.comparison.change,'0.44');
assert.equal(document.comparison.change,'-0.44');
assert.deepEqual(document.sections.find(x=>x.title==='产业部变化').visuals.map(v=>v.id),['department']);
assert.deepEqual(document.sections.find(x=>x.title==='重点规格').visuals.map(v=>v.id),['product']);
assert.deepEqual(document.sections.flatMap(x=>x.visuals.map(v=>v.id)),['department','product']);
@@ -109,7 +113,7 @@ test('reference-style cards and chapters keep chat/report values, figures and or
data.result.answer=data.result.readingSummary.lead+'\n\n'+data.result.readingSummary.evidence[0];
for(const html of [renderChat(data),renderReport(data)]) {
assert.match(html,/analysis-comparison-current[^>]*><span>2026年9月<\/span><strong>95.13%<\/strong>/);
assert.match(html,/下降 0.44/); assert.match(html,/95.57%/);
assert.match(html,/-0.44/); assert.match(html,/95.57%/);
assert.equal((html.match(/<table>/g)||[]).length,1);
assert.doesNotMatch(html,/Q11111111|Q22222222|关键依据|数据依据|analysis-full-appendix/);
}