Files
quality_analyse/verification/test_nao_finalizer_fallback.py
lyun ff7bbe3e46 同步:完善质量分析工作台并更新主题字体
同步已上线的智能分析执行协议、来源查询、图表报告与管理页面配套代码。
补齐数据库迁移、运行依赖和回归测试,保留原有指标计算口径。
统一午夜黑及其他主题的控件细节、中文和业务数字字体。
排除本地业务数据、凭据、预览、发布与验收产物。

验证:生产构建通过,320项前端回归通过;本轮仅同步Git,不再次部署。
2026-10-30 22:40:58 +08:00

45 lines
2.0 KiB
Python

from __future__ import annotations
import io
import json
import sys
import threading
import unittest
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "scripts"))
import nao_evidence_finalizer as finalizer
class FinalizerFallbackTests(unittest.TestCase):
def test_malformed_optional_focus_uses_verified_report_without_failure(self):
evidence = [{"evidenceRef": "Q00000001", "mode": "compare", "result": {
"kind": "quality_comparison",
"current": {"period": {"year": 2026, "month": 9}, "compositeRate": 0.95,
"coverage": {"sourceMonths": [{"year": 2026, "month": 9,
"blackRows": 1, "brightRows": 1}]}},
"comparison": {"period": {"year": 2026, "month": 8}, "compositeRate": 0.96,
"coverage": {"sourceMonths": [{"year": 2026, "month": 8,
"blackRows": 1, "brightRows": 1}]}},
"delta": {"percentagePoints": -1}}}]
bad_responses = [b"not-json",
json.dumps({"choices": [{"finish_reason": "length", "message": {
"content": '{"evidenceSufficient":'}}]}).encode(),
json.dumps({"choices": [{"finish_reason": "stop", "message": {
"content": "{}"}}]}).encode()]
for payload in bad_responses:
with self.subTest(payload=payload[:20]):
result = finalizer.synthesize(
base_url="https://service.test/v1", api_key="not-real",
model="mimo-v2.6-flash", question="质量如何", evidence=evidence,
cancel_event=threading.Event(),
opener=lambda *_args, **_kwargs: io.BytesIO(payload))
self.assertTrue(result["selectionFallback"])
self.assertTrue(result["evidenceSufficient"])
self.assertIn("下降1.00个百分点", result["answer"])
if __name__ == "__main__":
unittest.main()