This commit is contained in:
@@ -17,6 +17,7 @@ Operation Ollama-First v5.0 / Phase 3 / A8 — 日報模板路由測試
|
||||
"""
|
||||
|
||||
import os
|
||||
import logging
|
||||
from datetime import date, datetime
|
||||
from unittest.mock import patch, MagicMock
|
||||
|
||||
@@ -125,6 +126,30 @@ class TestKPIComputation:
|
||||
assert result['dod_pct'] == 0.0
|
||||
assert result['wow_pct'] == 0.0
|
||||
|
||||
def test_fetch_top_threats_logs_malformed_metadata(self, monkeypatch, caplog):
|
||||
import services.openclaw_strategist_service as svc
|
||||
|
||||
class _Rows:
|
||||
def fetchall(self):
|
||||
return [
|
||||
("SKU-1", "price gap", 0.91, "{bad-json", datetime(2026, 5, 13)),
|
||||
]
|
||||
|
||||
class _Session:
|
||||
def execute(self, *a, **kw):
|
||||
return _Rows()
|
||||
def close(self):
|
||||
pass
|
||||
|
||||
monkeypatch.setattr(svc, "get_session", lambda: _Session())
|
||||
caplog.set_level(logging.DEBUG, logger="services.openclaw_strategist_service")
|
||||
|
||||
threats = svc._fetch_top_threats(1)
|
||||
|
||||
assert threats[0]["sku"] == "SKU-1"
|
||||
assert threats[0]["gap_pct"] == 0
|
||||
assert "metadata_json decode failed" in caplog.text
|
||||
|
||||
|
||||
# ═══════════════════════════════════════════════════════════════════════════
|
||||
# T4+T5 — Template 渲染與缺欄位優雅降級
|
||||
|
||||
Reference in New Issue
Block a user