统一: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
+87
View File
@@ -295,6 +295,54 @@ class RawPlanExecutionTests(unittest.TestCase):
self.assertNotIn('recordList',result)
self.assertEqual({doc['mode'] for doc in documents},{'investigate'})
def test_autonomous_source_and_records_only_plan_uses_finalizer_and_keeps_raw_coverage(self):
task=self.root_task(purposes=('source','records'))
api=InvestigationApi(total_rows=1)
for purpose in ('source','records'):
api.add_scope(purpose,purpose+'-scope',purpose,task)
captured={}
def synthesize_stub(**kwargs):
captured['evidence']=copy.deepcopy(kwargs['evidence'])
captured['question']=kwargs['question']
return {'answer':'仅确认了原表核验,原问题仍缺少正式分析依据。',
'evidenceSufficient':False,'missingEvidence':['原问题所需正式分析依据未取得。'],
'modelDeclaredEvidenceSufficient':None,'usage':{},'finishReason':'stop',
'selectedFactIds':[]}
with tempfile.TemporaryDirectory() as folder:
root=Path(folder);(root/'evidence').mkdir();(root/'private').mkdir()
with patch('nao_evidence_finalizer.synthesize',side_effect=synthesize_stub) as synth:
result=execute(request={'releaseId':RELEASE,'turnId':TURN,
'question':task['question'],'_autonomousAnswer':True},task=task,
authority={**identity(),'task':task},actor_root=root,delegated=api,
connection=('http://offline','synthetic','model'),
cancel_event=threading.Event(),emit=lambda _:None)
self.assertTrue(synth.called)
source_docs=[doc for doc in captured['evidence'] if doc.get('mode')=='investigate'
and (doc.get('result') or {}).get('action')=='source']
self.assertEqual(len(source_docs),1)
self.assertFalse(any((doc.get('result') or {}).get('action')=='rows'
for doc in captured['evidence']))
self.assertEqual(source_docs[0]['result']['current']['sourceVerification']['verifiedRows'],1)
self.assertIn('已按稳定分页读全1条',result['answer'])
self.assertEqual(result['status'],'PARTIAL')
self.assertIn('原问题所需正式分析依据未取得。',result['evidenceCompletion']['missingEvidence'])
def test_autonomous_records_only_plan_stays_deterministic(self):
task=self.root_task(purposes=('records',))
api=InvestigationApi(total_rows=1)
api.add_scope('records','records-scope','records',task)
with tempfile.TemporaryDirectory() as folder:
root=Path(folder);(root/'evidence').mkdir();(root/'private').mkdir()
with patch('nao_evidence_finalizer.synthesize') as synth:
result=execute(request={'releaseId':RELEASE,'turnId':TURN,
'question':task['question'],'_autonomousAnswer':True},task=task,
authority={**identity(),'task':task},actor_root=root,delegated=api,
connection=('http://offline','synthetic','model'),
cancel_event=threading.Event(),emit=lambda _:None)
self.assertFalse(synth.called)
self.assertEqual(result['status'],'COMPLETED')
self.assertIn('已按本轮服务器授权范围核对原始数据。',result['answer'])
def test_unselected_column_filters_accept_canonical_empty_context_echo(self):
api=InvestigationApi(total_rows=2)
result,_,_=self.run_query(api,with_column_filters=False)
@@ -468,6 +516,45 @@ class MixedRawPlanExecutionTests(unittest.TestCase):
self.assertIn('原表值与存储记录一致',result['answer'])
self.assertNotIn('PRIVATE_RAW_VALUE',result['answer'])
def test_autonomous_mixed_synthesis_receives_source_proof_without_record_rows(self):
plan=[
{'nodeId':'records','purpose':'records','fields':[],'stages':['bright'],
'selector':{'kind':'base'},'visualType':None,'visualPreference':'none',
'comparisonRequired':False},
{'nodeId':'verify','purpose':'source','fields':[],'stages':['bright'],
'selector':{'kind':'base'},'visualType':None,'visualPreference':'none',
'comparisonRequired':False},
{'nodeId':'metric','purpose':'metrics','fields':['scrapRate'],'stages':['bright'],
'selector':{'kind':'base'},'visualType':None,'visualPreference':'none',
'comparisonRequired':False},
]
value=task_value(kind='details',dimensions=[],stages=['bright'],fields=['scrapRate'],
verifySource=True,fullDetails=True,period={'year':2026,'month':9},queryPlan=plan,
visualPreference='none',visualType=None,comparisonRequired=False,trendRequired=False)
task=normalize_task(value,'查询亮片报废率,并核验原表及读取明细',{'_protocol':{'version':1}})
api=MixedRawMetricsApi(task,task['queryPlan'])
captured={}
def synthesize_stub(**kwargs):
captured['evidence']=copy.deepcopy(kwargs['evidence'])
return {'answer':'已基于正式指标和原表核验完成说明。','evidenceSufficient':True,
'missingEvidence':[],'modelDeclaredEvidenceSufficient':True,'usage':{},
'finishReason':'stop','selectedFactIds':[]}
with tempfile.TemporaryDirectory() as folder:
root=Path(folder);(root/'evidence').mkdir();(root/'private').mkdir()
with patch('nao_evidence_finalizer.synthesize',side_effect=synthesize_stub):
result=execute(request={'releaseId':RELEASE,'turnId':TURN,'question':task['question'],
'_autonomousAnswer':True},task=task,authority={**identity(),'task':task},
actor_root=root,delegated=api,connection=('http://offline','synthetic','model'),
cancel_event=threading.Event(),emit=lambda _:None)
docs=captured['evidence']
self.assertTrue(any(doc.get('mode')=='query' for doc in docs))
source_docs=[doc for doc in docs if doc.get('mode')=='investigate'
and (doc.get('result') or {}).get('action')=='source']
self.assertTrue(source_docs)
self.assertFalse(any((doc.get('result') or {}).get('action')=='rows' for doc in docs))
self.assertNotIn('PRIVATE_RAW_VALUE',json.dumps(docs,ensure_ascii=False))
self.assertEqual(result['status'],'COMPLETED',result['evidenceCompletion']['missingEvidence'])
if __name__ == '__main__':
unittest.main()