同步已上线的智能分析执行协议、来源查询、图表报告与管理页面配套代码。 补齐数据库迁移、运行依赖和回归测试,保留原有指标计算口径。 统一午夜黑及其他主题的控件细节、中文和业务数字字体。 排除本地业务数据、凭据、预览、发布与验收产物。 验证:生产构建通过,320项前端回归通过;本轮仅同步Git,不再次部署。
72 lines
3.6 KiB
Python
72 lines
3.6 KiB
Python
"""One system policy must reach planning, native calls and finalization."""
|
|
import io
|
|
import ast
|
|
import json
|
|
import re
|
|
import sys
|
|
import threading
|
|
import unittest
|
|
from pathlib import Path
|
|
from unittest.mock import patch
|
|
|
|
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / 'scripts'))
|
|
|
|
|
|
class RuntimePolicyTest(unittest.TestCase):
|
|
def test_production_model_callers_have_no_independent_literal_budget(self):
|
|
root = Path(__file__).resolve().parents[1]
|
|
for path in (root/'scripts').glob('nao*.py'):
|
|
for node in ast.walk(ast.parse(path.read_text())):
|
|
if isinstance(node,ast.Dict):
|
|
for key,value in zip(node.keys,node.values):
|
|
if isinstance(key,ast.Constant) and key.value in ('max_completion_tokens','max_tokens'):
|
|
self.assertIsInstance(value,ast.Name,str(path))
|
|
self.assertEqual(value.id,'MAX_OUTPUT_TOKENS',str(path))
|
|
for path in (root/'backend/src/main/java/cn/yunsheng/quality/analysis').glob('*.java'):
|
|
for value in re.findall(r'"max_(?:completion_)?tokens",\s*([^,\n]+)',path.read_text()):
|
|
self.assertEqual(value,'AnalysisRuntimePolicy.MAX_OUTPUT_TOKENS',str(path))
|
|
|
|
def test_planner_uses_global_budget(self):
|
|
from nao_agent_task import _model_json
|
|
from nao_quality_runtime import native_output_budget
|
|
bodies = []
|
|
def provider(request, timeout):
|
|
bodies.append(json.loads(request.data))
|
|
return io.BytesIO(b'{"choices":[{"finish_reason":"stop","message":{"content":"{}"}}]}')
|
|
_model_json(base_url='http://localhost/v1', api_key='fixture', model='fixture',
|
|
system='fixture', payload={}, cancel_event=threading.Event(), opener=provider)
|
|
self.assertEqual(bodies[0]['max_completion_tokens'], native_output_budget())
|
|
|
|
def test_stale_environment_cannot_create_another_budget(self):
|
|
from nao_quality_runtime import native_output_budget
|
|
baseline = native_output_budget()
|
|
with patch.dict('os.environ', {'QUALITY_ANALYSIS_MAX_OUTPUT_TOKENS': '2048'}):
|
|
self.assertEqual(native_output_budget(), baseline)
|
|
|
|
def test_gate_replaces_both_legacy_caps_even_when_thinking_off(self):
|
|
from nao_model_gate import ModelGate
|
|
from nao_quality_runtime import native_output_budget
|
|
gate = ModelGate(upstream_base='http://localhost/v1', upstream_key='fixture', model='fixture',
|
|
port=0, client_key='fixture', authorize=lambda: None,
|
|
thinking_options={'enabled':False, 'effort':'auto', 'protocol':'thinking'})
|
|
try:
|
|
body = gate.apply_thinking({'max_tokens':1024, 'max_completion_tokens':4096})
|
|
self.assertNotIn('max_tokens', body)
|
|
self.assertEqual(body['max_completion_tokens'], native_output_budget())
|
|
finally:
|
|
gate.close()
|
|
|
|
def test_finalization_time_is_reserved_and_deadline_is_shared(self):
|
|
from nao_runtime_policy import turn_scope, remaining_seconds, request_timeout, native_timeout
|
|
with patch('nao_runtime_policy.time.monotonic', return_value=100):
|
|
with turn_scope():
|
|
total = remaining_seconds()
|
|
self.assertLess(native_timeout(), total)
|
|
with patch('nao_runtime_policy.time.monotonic', return_value=100+total-40):
|
|
self.assertLessEqual(request_timeout('final'), 35)
|
|
with self.assertRaises(TimeoutError):
|
|
request_timeout('planning')
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|