video-compliance-ai/backend/tests/test_soft_risk.py
Your Name e4959d584f feat: 完善代理商端业务逻辑与前后端框架
主要更新:
- 更新代理商端文档,明确项目由品牌方分配流程
- 新增Brief配置详情页(已配置)设计稿
- 完善工作台紧急待办中品牌新任务功能
- 整理Pencil设计文件中代理商端页面顺序
- 新增后端FastAPI框架及核心API
- 新增前端Next.js页面和组件库
- 添加.gitignore排除构建和缓存文件

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-05 19:27:31 +08:00

64 lines
2.2 KiB
Python

"""
软性风控逻辑测试 (TDD - 红色阶段)
触发条件: 临界值、低置信度、历史记录
"""
import pytest
from app.schemas.review import SoftRiskContext, SoftRiskAction
from app.services.soft_risk import evaluate_soft_risk
class TestSoftRiskEvaluator:
"""软性风控判定"""
@pytest.mark.asyncio
async def test_near_threshold_warns(self):
"""临界值接近阈值触发二次确认提示"""
context = SoftRiskContext(
violation_rate=0.045,
violation_threshold=0.05,
)
warnings = evaluate_soft_risk(context)
matched = [
w for w in warnings
if w.code == "NEAR_THRESHOLD" and w.action_required == SoftRiskAction.CONFIRM
]
assert matched
assert all(w.blocking is False for w in matched)
@pytest.mark.asyncio
async def test_low_confidence_warns(self):
"""ASR/OCR 置信度处于 60%-80% 触发备注提示"""
context = SoftRiskContext(
asr_confidence=0.7,
ocr_confidence=0.65,
)
warnings = evaluate_soft_risk(context)
codes = {w.code for w in warnings}
assert "LOW_CONFIDENCE_ASR" in codes or "LOW_CONFIDENCE_OCR" in codes
assert all(w.action_required == SoftRiskAction.NOTE for w in warnings if "LOW_CONFIDENCE" in w.code)
@pytest.mark.asyncio
async def test_history_violation_warns(self):
"""历史记录存在类似违规触发备注提示"""
context = SoftRiskContext(
has_history_violation=True,
)
warnings = evaluate_soft_risk(context)
matched = [w for w in warnings if w.code == "HISTORY_RISK"]
assert matched
assert all(w.action_required == SoftRiskAction.NOTE for w in matched)
@pytest.mark.asyncio
async def test_safe_context_returns_empty(self):
"""安全场景无软性提示"""
context = SoftRiskContext(
violation_rate=0.01,
violation_threshold=0.05,
asr_confidence=0.95,
ocr_confidence=0.92,
has_history_violation=False,
)
warnings = evaluate_soft_risk(context)
assert warnings == []