统一:DSH 智能分析、Top100 与图表静默恢复

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

验证:独立目录前后端构建通过;118 项 Java、102 项前端、102 项图表、14 项 DSH 应用和 13 项组合筛选检查通过。
仅提交相关源码、锁定依赖与测试;不包含凭据、会话、业务数据或本地产物。
This commit is contained in:
2026-11-12 11:57:41 +08:00
parent cc8832c8e5
commit f1a2fbd494
166 changed files with 26281 additions and 2248 deletions
@@ -0,0 +1,78 @@
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 { buildAgentReportLayout, agentReportPrimary, agentReportSupplementary } from '../src/agent/agentReportLayout.ts';
import { stripDuplicateFirstMarkdownH1 } from '../src/analysisReportTitle.ts';
import { tableTextAlignment } from '../src/tableTextAlignment.ts';
import { sanitizeAnalysisDisplayText } from '../src/analysisDisplayText.ts';
import { analysisEvidenceParts } from '../src/analysisEvidenceRefs.ts';
function load(file, exported, bindings) {
const source=fs.readFileSync(new URL(file,import.meta.url),'utf8').replace(/^import .*;\n/gm,'').replaceAll('export function ','function ').replaceAll('export async function ','async function ');
return new Function(...Object.keys(bindings),ts.transpileModule(source+'\nreturn '+exported+';', {compilerOptions:{target:ts.ScriptTarget.ES2022,jsx:ts.JsxEmit.React}}).outputText.replace(/^export\s*\{\s*\};?$/gm,''))(...Object.values(bindings));
}
const AiMarkdown=load('../src/AiMarkdown.tsx','AiMarkdown',{React,tableTextAlignment,sanitizeAnalysisDisplayText,analysisEvidenceParts});
const figures=[{id:'trend',title:'月度趋势',type:'line',unit:'ratio',metric:'composite_rate',sectionKey:'trend',scope:{},categories:[],series:[],evidenceRefs:[]},
{id:'scrap',title:'报废结构',type:'bar',unit:'kg',metric:'scrap_weight',sectionKey:'category',scope:{},categories:[],series:[],evidenceRefs:[]}];
let images=[];
const Empty=()=>null;
const Document=load('../src/agent/AgentDeliverable.tsx','AgentDeliverable',{
React,useLayoutEffect:()=>{},useRef:value=>({current:value}),useState:value=>[value,()=>{}],
Alert:Empty,Spin:Empty,DownloadOutlined:Empty,Button:Empty,Modal:({children})=>React.createElement('main',null,children),
AnalysisMemberListReport:Empty,AnalysisRecordListReport:Empty,AiMarkdown,
ReportVisualFigure:({visual,image})=>image?.svg?React.createElement('figure',{'data-chart':visual.id},visual.title):React.createElement('table',{'data-fallback':visual.id},React.createElement('tbody',null,React.createElement('tr',null,React.createElement('td',null,visual.title)))),
reportVisualImageSource:image=>image?.svg||'',reportVisuals:()=>figures,
useReportVisualImages:()=>({authorized:true,loading:false,images}),analysisSnapshotResult:turn=>turn.result,
reportSnapshotIdentity:()=>'',analysisScopeText:()=>'',stripDuplicateFirstMarkdownH1,buildAgentReportLayout,agentReportPrimary,agentReportSupplementary,
captureReportLongImage:()=>{},downloadAuthorizedReport:()=>{},documentCss:'',
});
const answer='# 原始报告\n\n原始导读。\n\n## 月度趋势\n\n原始分析。\n\n| 月份 | 值 |\n|---|---|\n| 10月 | 95.46% |\n\n## 报废大类\n\n原始说明。';
function render() {return renderToStaticMarkup(React.createElement(Document,{turn:{status:'COMPLETED',question:'生成报告',result:{modelAnswer:answer,answer:'此替代回答不应显示'}},onClose:()=>{}}));}
test('every report figure precedes the original detail table, appears once, and leaves the source intact',()=>{
images=figures.map(v=>({id:v.id,svg:'data:image/svg+xml,test'}));
const html=render();
for(const id of ['trend','scrap']) {
assert.equal((html.match(new RegExp('data-chart="'+id+'"','g'))||[]).length,1);
assert.ok(html.indexOf('data-chart="'+id+'"')<html.indexOf('<table>'));
}
assert.ok(html.indexOf('原始分析。')<html.indexOf('原始说明。'));
assert.equal((html.match(/原始导读。/g)||[]).length,1);
assert.match(html,/95.46%/);assert.doesNotMatch(html,/此替代回答/);
});
test('a missing image is omitted while the healthy figure and original answer remain',()=>{
images=[{id:'trend',svg:'data:image/svg+xml,test'},{id:'scrap',failed:true}];
const html=render();
assert.equal((html.match(/data-chart=/g)||[]).length,1);
assert.doesNotMatch(html,/data-fallback|重试|暂不可用/);
assert.ok(html.indexOf('data-chart="trend"')<html.indexOf('<table>'));
assert.match(html,/原始说明。/);
});
test('no image yields no empty gallery and all original data remains accessible',()=>{
images=[];const html=render();assert.doesNotMatch(html,/agent-document-overview/);assert.match(html,/95.46%/);
assert.equal((html.match(/data-fallback=/g)||[]).length,0);
});
test('the real report figure quietly omits unavailable images',()=>{
const Figure=load('../src/AnalysisReportVisuals.tsx','ReportVisualFigure',{React,visualPeriodSummary:()=>'',visualScopeSummary:()=>''});
for(const image of [undefined,{id:'trend',failed:true}]) {
assert.equal(renderToStaticMarkup(React.createElement(Figure,{visual:{...figures[0],chartable:true},image,quiet:true})), '');
}
const image={id:'trend',svg:'data:image/svg+xml;charset=utf-8,%3Csvg%2F%3E'};
const html=renderToStaticMarkup(React.createElement(Figure,{visual:{...figures[0],chartable:true,coverage:{truncated:false}},image,quiet:true}));
assert.match(html,/<figure/);assert.match(html,/<img/);assert.doesNotMatch(html,/q-partial|暂不可用/);
});
test('ordinary AI replies never become a report even when a legacy report field exists',()=>{
const authored=load('../src/agent/AgentDeliverable.tsx','authoredReport',{analysisSnapshotResult:turn=>turn.result,stripDuplicateFirstMarkdownH1});
for(const question of ['2026年8月综合合格率是多少?','一句话回答,不生成报告。','对比9月10月,简短回答,不需要生成报告。','沿用上面,只回答这两项。']) {
assert.equal(authored({status:'COMPLETED',question,result:{modelAnswer:answer,reportMarkdown:answer}}),null);
}
assert.ok(authored({status:'COMPLETED',question:'生成亮片报废结构专题报告',result:{modelAnswer:answer}}));
assert.ok(authored({status:'COMPLETED',question:'生成质量异常诊断简报',result:{modelAnswer:answer}}));
});