统一: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
@@ -4,6 +4,7 @@ import json
import copy
import sys
import tempfile
import threading
import unittest
from contextlib import ExitStack
from pathlib import Path
@@ -11,7 +12,7 @@ from unittest.mock import MagicMock, patch
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / 'scripts'))
import nao_quality_runtime as runtime
from nao_product_identification import identify_products
from nao_product_identification import identify_products, resolve_clarification_choice
ACTOR = '11111111-1111-4111-8111-111111111111'
SESSION = '22222222-2222-4222-8222-222222222222'
@@ -20,6 +21,89 @@ TURN = '55555555-5555-4555-8555-555555555555'
class ProductClarificationRuntimeTests(unittest.TestCase):
def test_catalog_prefix_with_multiple_candidates_forces_explicit_choice(self):
question = ('查询2026年10月合成产品0的黑片合格率;如果名称不能唯一确定,'
'请让我明确选择,不要自行猜产品。')
authorized = [f'合成产品0{i}' for i in range(1, 7)]
options = {'products': authorized, 'organizationPaths': []}
match = identify_products(question, options)['productMatch']
self.assertEqual(match['status'], 'ambiguous')
self.assertEqual(match['query'], '合成产品0')
self.assertEqual(match['candidateCount'], 6)
self.assertFalse(match['truncated'])
self.assertEqual([item['name'] for item in match['candidates']], authorized)
# Even if the planner mistakenly forwards the partial name as a filter
# and omits needsClarification, the deterministic authorized catalog
# overrides it while preserving the user's metric and scope.
from nao_agent_task import plan_task
planned = {
'goal': question, 'kind': 'metrics', 'freshQuery': True,
'dimensions': [], 'dimensionStages': {}, 'stages': ['black'],
'fields': ['rate'], 'period': {'year': 2026, 'month': 10},
'comparisonRequired': False, 'trendRequired': False,
'verifySource': False, 'fullDetails': False,
'visualPreference': 'none', 'responseStyle': 'standard',
'needsClarification': False, 'clarification': '',
'filterUpdates': {'product': '合成产品0'},
}
context = {'_protocol': {'version': 1, 'autonomousEnabled': True},
'_businessCatalog': {'productMatch': match}}
with patch('nao_agent_task._model_json', return_value=planned):
pending = plan_task(base_url='https://offline.invalid/v1', api_key='synthetic', model='m',
question=question, context=context, cancel_event=threading.Event())
self.assertTrue(pending['needsClarification'])
self.assertNotIn('product', pending['filters'])
self.assertEqual(pending['period'], {'year': 2026, 'month': 10})
self.assertEqual(pending['fields'], ['rate'])
self.assertEqual(pending['stages'], ['black'])
self.assertEqual([item['value'] for item in pending['clarificationRequest']['options']], authorized)
selected = resolve_clarification_choice('选择合成产品03', options, pending)
self.assertEqual(selected['productMatch']['status'], 'exact')
self.assertTrue(selected['productMatch']['selectedFromClarification'])
self.assertEqual(selected['productMatch']['candidates'][0]['name'], '合成产品03')
def test_prefix_matching_stays_with_current_authorized_catalog_and_candidate_cap(self):
question = '查询合成产品0的黑片合格率'
names = [f'合成产品0{i:02d}' for i in range(25)]
match = identify_products(question, {'products': names})['productMatch']
self.assertEqual(match['status'], 'ambiguous')
self.assertEqual(match['candidateCount'], 25)
self.assertEqual(len(match['candidates']), 20)
self.assertTrue(match['truncated'])
self.assertEqual(set(item['name'] for item in match['candidates']), set(names[:20]))
not_authorized = identify_products('查询合成产品99的黑片合格率', {'products': names})['productMatch']
self.assertEqual(not_authorized['status'], 'none')
self.assertEqual(not_authorized['candidates'], [])
unique = identify_products('查询合成产品0的黑片合格率', {'products': ['合成产品01']})['productMatch']
self.assertEqual(unique['status'], 'unique')
self.assertEqual([item['name'] for item in unique['candidates']], ['合成产品01'])
# A unique partial prefix is bound to the full authorized directory
# name, never sent to the API as a partial product filter.
from nao_agent_task import plan_task
question = '查询合成产品0的黑片合格率'
planned = {
'goal': question, 'kind': 'metrics', 'freshQuery': True,
'dimensions': [], 'dimensionStages': {}, 'stages': ['black'],
'fields': ['rate'], 'period': {'year': 2026, 'month': 10},
'comparisonRequired': False, 'trendRequired': False,
'verifySource': False, 'fullDetails': False,
'visualPreference': 'none', 'responseStyle': 'standard',
'needsClarification': False, 'clarification': '',
'filterUpdates': {'product': '合成产品0'},
}
context = {'_protocol': {'version': 1, 'autonomousEnabled': True},
'_businessCatalog': {'productMatch': unique}}
with patch('nao_agent_task._model_json', return_value=planned):
task = plan_task(base_url='https://offline.invalid/v1', api_key='synthetic', model='m',
question=question, context=context, cancel_event=threading.Event())
self.assertFalse(task['needsClarification'])
self.assertEqual(task['filters']['product'], '合成产品01')
def exercise(self, *, restart=False, revoke=False, other_release=False):
opts = {'products': ['18X15X4+T', '18X15X4+Z'], 'organizationPaths': []}
pending_match = identify_products('今年18x15x4合格率变化趋势', opts)['productMatch']