统一:DSH 智能分析、Top100 与图表静默恢复
接入 DSH 专用运行时和对话界面,保留模型原始回答,支持会话分页、连续追问与显式报告。 补齐组合筛选、各维度 Top100、分组查询到排名图的转换,图表故障静默省略并基于保存数据自动恢复。 优化报告风格、图表顺序和表格换行,更新接入说明及构建输入。 验证:独立目录前后端构建通过;118 项 Java、102 项前端、102 项图表、14 项 DSH 应用和 13 项组合筛选检查通过。 仅提交相关源码、锁定依赖与测试;不包含凭据、会话、业务数据或本地产物。
This commit is contained in:
@@ -96,6 +96,64 @@ class ModelGateTests(unittest.TestCase):
|
||||
self.assertEqual(self.request(model='different-model')[0], 400)
|
||||
self.assertEqual(len(self.calls), 0)
|
||||
|
||||
def test_dsh_keeps_only_its_bound_quality_tool_at_the_provider_boundary(self):
|
||||
self.gate.runtime_engine='DSH'
|
||||
names=['mcp__quality__quality_data','bash','mcp_call','story','mcp__other__quality_data']
|
||||
tools=[{'type':'function','function':{'name':name,'parameters':{'type':'object'}}} for name in names]
|
||||
self.assertEqual(self.request(extra={'tools':tools})[0],200)
|
||||
self.assertEqual([x['function']['name'] for x in self.calls[-1]['tools']],['mcp__quality__quality_data'])
|
||||
|
||||
def test_dsh_stream_separates_complete_calls_when_the_provider_reuses_an_index(self):
|
||||
from unittest.mock import Mock
|
||||
from nao_thinking_stream import ProviderStream
|
||||
self.gate.runtime_engine='DSH'
|
||||
name='mcp__quality__quality_data'
|
||||
tool={'type':'function','function':{'name':name,'parameters':{'type':'object'}}}
|
||||
frames=[{'choices':[{'index':0,'delta':{'tool_calls':[{'index':index,'id':identity,'type':'function',
|
||||
'function':{'name':name,'arguments':json.dumps({'probe':identity})}}]},'finish_reason':None}]}
|
||||
for index,identity in [(0,'a'),(1,'b'),(1,'c'),(2,'d')]]
|
||||
frames.append({'choices':[{'index':0,'delta':{},'finish_reason':'tool_calls'}]})
|
||||
chunks=[('data: '+json.dumps(frame)+'\n\n').encode() for frame in frames]+[b'data: [DONE]\n\n']
|
||||
upstream=HeldOpenProviderResponse(chunks);upstream.release.set()
|
||||
self.gate._opener=Mock();self.gate._opener.open.return_value=upstream
|
||||
code,body=self.request(extra={'stream':True,'tools':[tool]})
|
||||
self.assertEqual(code,200)
|
||||
observer=ProviderStream(lambda _:None);observer.feed(body.encode());observer.finish()
|
||||
calls=observer.completion()['choices'][0]['message']['tool_calls']
|
||||
self.assertEqual([call['id'] for call in calls],['a','b','c','d'])
|
||||
self.assertEqual([call['function']['name'] for call in calls],[name]*4)
|
||||
self.assertEqual([json.loads(call['function']['arguments']) for call in calls],[{'probe':x} for x in 'abcd'])
|
||||
|
||||
def test_revocation_interrupts_an_inflight_provider_read(self):
|
||||
from unittest.mock import Mock
|
||||
class StalledResponse:
|
||||
status=200
|
||||
headers={'Content-Type':'text/event-stream'}
|
||||
def __init__(self):
|
||||
self.reading=threading.Event();self.released=threading.Event()
|
||||
def __enter__(self):return self
|
||||
def __exit__(self,*_):self.close()
|
||||
def read1(self,_):
|
||||
self.reading.set();self.released.wait(5);return b''
|
||||
def close(self):self.released.set()
|
||||
stalled=StalledResponse();self.gate._opener=Mock()
|
||||
self.gate._opener.open.return_value=stalled
|
||||
done=threading.Event();result=[]
|
||||
def query():
|
||||
try:result.append(self.request())
|
||||
finally:done.set()
|
||||
worker=threading.Thread(target=query,daemon=True);worker.start()
|
||||
self.assertTrue(stalled.reading.wait(1))
|
||||
self.gate.revoke()
|
||||
self.assertTrue(done.wait(1),'revoked provider read was left waiting for its timeout')
|
||||
worker.join(1)
|
||||
# SSE headers may have been sent before revocation; HTTP 200 alone is
|
||||
# not a completion receipt. The interrupted body has no terminal event.
|
||||
self.assertIn(result[0][0],(200,502))
|
||||
self.assertNotIn('[DONE]',result[0][1])
|
||||
self.assertNotIn('"finish_reason": "stop"',result[0][1])
|
||||
self.assertEqual(self.request()[0],403)
|
||||
|
||||
def test_quality_api_charts_do_not_advertise_incompatible_sql_renderer(self):
|
||||
data_tool={'type':'function','function':{'name':'mcp_call','parameters':{'type':'object'}}}
|
||||
chart_tool={'type':'function','function':{'name':'display_chart','parameters':{'type':'object'}}}
|
||||
@@ -123,6 +181,14 @@ class ModelGateTests(unittest.TestCase):
|
||||
self.gate._opener=Mock();self.gate._opener.open.return_value=upstream
|
||||
code,body=self.request(extra={'tools':[data_tool]})
|
||||
self.assertEqual(code,502);self.assertNotIn('clarification',body)
|
||||
self.assertEqual(self.gate.rejected_tool_names,['clarification'])
|
||||
from types import SimpleNamespace
|
||||
from nao_model_gate import ToolPolicyError
|
||||
observer=SimpleNamespace(tools={0:{0:{'function':{'name':'secret=never-log','arguments':'private argument'}}}},
|
||||
choices={0:{'finish_reason':'tool_calls'}},done=True)
|
||||
with self.assertRaises(ToolPolicyError):
|
||||
self.gate.check_returned_tools(observer,{'mcp_call'},final=True)
|
||||
self.assertEqual(self.gate.rejected_tool_names,['clarification','<invalid_name>'])
|
||||
for newline in (True,False):
|
||||
prefix=b'data: {"choices":[{"index":0,"delta":{"content":"Preserved text"}}]}\n\n'
|
||||
bad=('data: '+json.dumps({'choices':[{'index':0,'delta':{'tool_calls':[tool]},'finish_reason':'tool_calls'}]})+ ('\n\n' if newline else '')).encode()
|
||||
@@ -215,6 +281,20 @@ class ModelGateTests(unittest.TestCase):
|
||||
self.assertNotIn('reasoning_effort',body)
|
||||
self.assertEqual(self.gate.request_audit[-1]['reasoningEffort'],native)
|
||||
|
||||
def test_mimo_disables_thinking_only_for_native_tool_requests(self):
|
||||
self.gate._model='mimo-v2.6-flash'
|
||||
self.gate.runtime_engine='DSH'
|
||||
self.gate._thinking={'enabled':True,'effort':'auto','protocol':'thinking'}
|
||||
tool={'type':'function','function':{'name':'mcp__quality__quality_data','parameters':{'type':'object'}}}
|
||||
for native,tools in ((False,[]),(True,[tool]),(True,[])):
|
||||
with self.subTest(native=native,tools=bool(tools)):
|
||||
self.gate.native_agent=native
|
||||
self.assertEqual(self.request(model=self.gate._model,extra={'tools':tools})[0],200)
|
||||
expected=not(native and tools)
|
||||
self.assertEqual(self.calls[-1]['thinking'],{'type':'enabled' if expected else 'disabled'})
|
||||
self.assertTrue(self.gate._thinking['enabled'])
|
||||
self.assertTrue(self.gate.request_audit[-1]['requestedEnabled'])
|
||||
|
||||
def test_qwen_switch_uses_chat_template_control_and_removes_conflicting_flags(self):
|
||||
self.gate._thinking={'enabled':False,'effort':'medium','protocol':'chat_template'}
|
||||
self.assertEqual(self.request(extra={'thinking':{'type':'enabled'},'reasoning_effort':'high','chat_template_kwargs':{'enable_thinking':True}})[0],200)
|
||||
|
||||
Reference in New Issue
Block a user