補競品 Feeder 搜尋詞 fallback 診斷
All checks were successful
CD Pipeline / deploy (push) Successful in 56s

This commit is contained in:
OoO
2026-05-13 12:49:03 +08:00
parent 28c95558ab
commit c227bb4078
2 changed files with 22 additions and 1 deletions

View File

@@ -145,7 +145,11 @@ def _build_search_keywords(momo_name: str) -> list:
elif parsed.keywords:
terms.append(" ".join(parsed.keywords[:4]))
except Exception:
pass
logger.debug(
"[Feeder] ProductNameParser failed while building search keywords; "
"fallback to cleaned product name",
exc_info=True,
)
return _dedupe_terms(terms)

View File

@@ -1,4 +1,5 @@
from pathlib import Path
import logging
ROOT = Path(__file__).resolve().parents[1]
@@ -26,3 +27,19 @@ def test_competitor_feeder_persists_all_match_attempt_outcomes():
assert "best_match_score" in migration
assert "error_message" in migration
assert "idx_comp_match_attempts_sku_source_time" in migration
def test_competitor_feeder_logs_keyword_parser_fallback(monkeypatch, caplog):
from services import competitor_price_feeder
from services.price_comparison import ProductNameParser
def broken_parse(self, *_args, **_kwargs):
raise RuntimeError("parser unavailable")
monkeypatch.setattr(ProductNameParser, "parse", broken_parse)
caplog.set_level(logging.DEBUG, logger="services.competitor_price_feeder")
terms = competitor_price_feeder._build_search_keywords("理膚寶水 B5 修復霜 40ml")
assert terms
assert "fallback to cleaned product name" in caplog.text