修复:DSH 自主查询、图片直显与报告稳定性

允许 Agent 在循环中查目录、修正查询和提问,保留实时权限检查及模型原始回答。
统一相同查询证据与图表资源;排名补齐阶段指标,修正 OR 重量筛选,并限制模型明细输入。
增加运行恢复、图表自适应坐标轴与两位小数,修复报告主图选择、重复图及边缘标签。

验证:独立副本通过 162 项 Python、73 项前端及 21 项后端测试,前端构建通过。
线上已用原 8 题复测,并追加两轮双期对比;TOP100 与组合筛选分别核对 100 行和 20 行。
This commit is contained in:
2026-11-12 16:14:20 +08:00
parent f1a2fbd494
commit bc19475b29
35 changed files with 983 additions and 114 deletions
+66 -3
View File
@@ -61,12 +61,13 @@ class DshApplicationTests(unittest.TestCase):
self.assertEqual(instance.access_path.stat().st_mode & 0o777, 0o600)
access_files.append(instance.access_path)
if path == '/api/analysis/protocol/task':
self.assertEqual(kwargs['payload'], task)
return {'task': task, 'attemptId': request['sessionId']}
self.assertTrue(kwargs['payload']['agentDriven'])
self.assertEqual(kwargs['payload']['filters'], {})
return {'task': kwargs['payload'], 'attemptId': request['sessionId']}
return {}
def execute(**options):
self.assertEqual(options['authority']['task'], task)
self.assertTrue(options['authority']['task']['agentDriven'])
self.assertNotIn('accessToken', options['request'])
self.assertEqual(options['connection'][0].split(':')[1], '//127.0.0.1')
self.original.current().capture_native(answer)
@@ -94,6 +95,33 @@ class DshApplicationTests(unittest.TestCase):
self.assertEqual(result['timeline'], [{'kind': 'tool_result', 'toolCallId': 'dsh-tool-fixture'}])
self.assertNotIn('fixture-only-delegation', output.getvalue())
def test_intent_errors_start_dsh_but_real_authorization_refusal_stops(self):
for error,should_start in [(ValueError('参数格式待修正'),True),
(self.context.RuntimeErrorSafe('查询条件待修正',http_status=409),True),
(self.context.RuntimeErrorSafe('当前账号无权限',http_status=403),False)]:
with self.subTest(error=type(error).__name__,start=should_start):
request=self.request('18x15x4今年合格率变化趋势')
started=[];output=io.StringIO()
def delegate(instance,path,**kwargs):
if path=='/api/analysis/protocol/task':
return {'task':kwargs['payload'],'attemptId':request['sessionId']}
return {}
def execute(**options):
started.append(True)
answer='找到多个完整规格,请确认要分析哪一个。'
self.original.current().capture_native(answer)
options['emit']({'type':'result','status':'COMPLETED','answer':answer,'agentTask':options['task']})
with (patch('setup_dsh_runtime.inspect_runtime',return_value={'ready':True}),
patch('quality_model_settings.model_configuration',return_value=('https://fixture.invalid/v1','fixture-key','fixture-model',{})),
patch.object(self.context.DelegatedApi,'call',delegate),
patch.object(self.worker,'_plan',side_effect=error),
patch('quality_native_run.run_native_exploration',side_effect=execute)):
self.worker.run_turn(request,stdin=io.StringIO(),stdout=output)
self.assertEqual(bool(started),should_start)
result=[json.loads(line) for line in output.getvalue().splitlines() if json.loads(line).get('type')=='result'][-1]
self.assertEqual(result['status'],'COMPLETED' if should_start else 'FAILED')
if should_start:self.assertEqual(result['modelAnswer'],result['answer'])
def test_engine_and_attempt_are_pinned_before_access(self):
requests = (self.request('检查指标', runtimeEngine='legacy'),
self.request('检查指标', context={'_protocol': {'version': 1, 'attemptId': str(uuid.uuid4())}}))
@@ -249,6 +277,41 @@ class DshApplicationTests(unittest.TestCase):
self.assertEqual(result['phaseTimingsMs']['synthesis'], 0)
self.assertNotIn('answerQuality', result)
def test_query_exposes_the_same_real_chart_resource_that_final_delivery_contains(self):
runner = importlib.import_module('quality_native_run')
task = {'kind': 'analysis', 'agentDriven': True, 'executionMode': 'native_agent',
'filters': {}, 'period': {'year': 2026}, 'fields': ['rate'], 'stages': []}
request = self.request('今年合格率趋势,用图片直接展示')
authority = {**{key: request[key] for key in ('sessionId', 'turnId')},
'attemptId': request['sessionId'], 'revision': 1, 'executionId': str(uuid.uuid4())}
visual = {'id': 'real-chart-id', 'title': '真实趋势图', 'scope': {'product': '完整规格'}, 'period': {'year': 2026}}
answer = '原始结论。\n\n![真实趋势图](chart:real-chart-id)'
accumulator = SimpleNamespace(answer=answer, finish_reasons=['stop'], tool_calls=[], timeline=[])
observations = []
def execute(**options):
observations.append(options['tool_handler']({'mode': 'query'}))
observations.append(options['tool_handler']({'mode': 'query', 'freshQuery': True}))
return accumulator, 'COMPLETED', 'stop', True
with tempfile.TemporaryDirectory() as directory:
root = Path(directory); (root/'private').mkdir(); (root/'evidence').mkdir()
with (patch('dsh_agent_runtime.run_dsh_agent', side_effect=execute),
patch('quality_native_exploration.NativeExplorationTools.quality_data', side_effect=[{'value': 0.9639601707533932}, {'value': 0.9639601707533932, 'reusedEvidence': True}]),
patch('quality_native_exploration.native_model_view', side_effect=lambda value, **kwargs: value),
patch('analysis_visual_evidence.protocol_visual_result', return_value={'visualSchemaVersion': 1, 'visualState': 'ready', 'visuals': [visual]})):
result = runner.run_native_exploration(request=request, task=task, authority=authority,
actor_root=root, delegated=SimpleNamespace(call=lambda *args, **kwargs: {}),
connection=('http://127.0.0.1:1/v1', 'fixture', 'fixture'),
cancel_event=threading.Event(), emit=lambda event: None, prior_evidence_files=frozenset())
image = observations[0]['presentation']['images'][0]
self.assertEqual(image['src'], 'chart:' + result['visuals'][0]['id'])
self.assertEqual(observations[0]['value'], 0.9639601707533932)
self.assertEqual(observations[0]['queryCompletion']['state'], 'data_ready')
self.assertTrue(observations[0]['queryCompletion']['newEvidence'])
self.assertTrue(observations[1]['queryCompletion']['reused'])
self.assertFalse(observations[1]['queryCompletion']['newEvidence'])
self.assertEqual(observations[0]['presentation']['images'], observations[1]['presentation']['images'])
self.assertEqual(result['answer'], answer)
def test_business_data_is_read_before_model_and_seeded_in_the_native_stream(self):
runner = importlib.import_module('quality_native_run')
task = {'kind': 'analysis', 'freshQuery': True, 'executionMode': 'native_agent', 'filters': {},