02d2e56ef6
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
48 lines
1.6 KiB
Python
48 lines
1.6 KiB
Python
"""classify_cancelled_fallback / make_hit 单测。"""
|
|
from app.services.compare_alert import classify_cancelled_fallback, make_hit
|
|
|
|
|
|
class _Rec:
|
|
def __init__(self, **kw):
|
|
self.trace_id = kw.get("trace_id", "t")
|
|
self.status = kw.get("status", "cancelled")
|
|
self.total_ms = kw.get("total_ms")
|
|
self.step_count = kw.get("step_count")
|
|
self.fail_reason = kw.get("fail_reason")
|
|
self.information = kw.get("information")
|
|
self.app_version = kw.get("app_version")
|
|
self.created_at = kw.get("created_at")
|
|
self.trace_url = kw.get("trace_url")
|
|
self.user_id = kw.get("user_id")
|
|
|
|
|
|
def test_fallback_deep_by_ms():
|
|
hit = classify_cancelled_fallback(
|
|
_Rec(total_ms=95000, step_count=5),
|
|
cancelled_ms_threshold=90000, cancelled_step_threshold=30,
|
|
)
|
|
assert hit is not None and hit.alert_type == "T5" and "深度放弃" in hit.reason
|
|
|
|
|
|
def test_fallback_deep_by_step():
|
|
hit = classify_cancelled_fallback(
|
|
_Rec(total_ms=1000, step_count=35),
|
|
cancelled_ms_threshold=90000, cancelled_step_threshold=30,
|
|
)
|
|
assert hit is not None and hit.alert_type == "T5"
|
|
|
|
|
|
def test_fallback_shallow_none():
|
|
hit = classify_cancelled_fallback(
|
|
_Rec(total_ms=5000, step_count=3),
|
|
cancelled_ms_threshold=90000, cancelled_step_threshold=30,
|
|
)
|
|
assert hit is None
|
|
|
|
|
|
def test_make_hit_carries_fields():
|
|
hit = make_hit(_Rec(trace_id="tx", app_version="0.6.0"), "T5", "卡在 美团·加菜")
|
|
assert hit.trace_id == "tx"
|
|
assert hit.reason == "卡在 美团·加菜"
|
|
assert hit.app_version == "0.6.0"
|