From 0bdb993914a6f2edeeca6aa0970bb81de583e3f7 Mon Sep 17 00:00:00 2001 From: OoO Date: Wed, 13 May 2026 12:53:57 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A3=9C=20OpenClaw=20=E5=A0=B1=E8=A1=A8?= =?UTF-8?q?=E8=B3=87=E6=96=99=E8=A7=A3=E6=9E=90=E8=A8=BA=E6=96=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- services/openclaw_strategist_service.py | 4 ++-- tests/test_openclaw_daily_template.py | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/services/openclaw_strategist_service.py b/services/openclaw_strategist_service.py index a295070..f0d6bb5 100644 --- a/services/openclaw_strategist_service.py +++ b/services/openclaw_strategist_service.py @@ -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) diff --git a/tests/test_openclaw_daily_template.py b/tests/test_openclaw_daily_template.py index 404fca4..630169f 100644 --- a/tests/test_openclaw_daily_template.py +++ b/tests/test_openclaw_daily_template.py @@ -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 渲染與缺欄位優雅降級