補 OpenClaw 報表資料解析診斷
All checks were successful
CD Pipeline / deploy (push) Successful in 55s

This commit is contained in:
OoO
2026-05-13 12:53:57 +08:00
parent bff8c4941c
commit 0bdb993914
2 changed files with 27 additions and 2 deletions

View File

@@ -462,7 +462,7 @@ def _fetch_top_threats(limit: int = 10) -> List[Dict]:
try:
meta = json.loads(r[3]) if r[3] else {}
except Exception:
pass
logger.debug("[OpenClaw] price_alert metadata_json decode failed sku=%s", r[0], exc_info=True)
result.append({
"sku": r[0],
"summary": (r[1] or "")[:200],
@@ -996,7 +996,7 @@ def _call_gemini(
output=getattr(usage, 'candidates_token_count', 0) or 0,
)
except Exception:
pass
logger.debug("[OpenClaw] Gemini usage metadata parse failed caller=%s", caller, exc_info=True)
return response.text or ""
except Exception as e:
logger.error("[OpenClaw] Gemini 呼叫失敗: %s", e)

View File

@@ -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 渲染與缺欄位優雅降級