V10.586 加速比價補抓並提升覆蓋率
All checks were successful
CD Pipeline / deploy (push) Successful in 1m7s

This commit is contained in:
OoO
2026-06-04 19:31:24 +08:00
parent 1dd4181fab
commit 5347c95b97
4 changed files with 106 additions and 11 deletions

View File

@@ -493,8 +493,10 @@ def test_ai_product_pick_agent_uses_real_competitor_data_and_dashboard_action():
assert "MAX_SEARCH_TERMS" in feeder_source
assert "_build_search_keywords" in feeder_source
assert "_search_pchome_candidates" in feeder_source
assert "search_limit = SEARCH_LIMIT * max(1, SEARCH_MAX_PAGES)" in feeder_source
assert "crawler.search_products(keyword, limit=search_limit, max_pages=SEARCH_MAX_PAGES)" in feeder_source
assert "page_cap = max(1, int(max_pages or SEARCH_MAX_PAGES))" in feeder_source
assert "search_limit = SEARCH_LIMIT * page_cap" in feeder_source
assert "bounded_search=True" in feeder_source
assert "crawler.search_products(keyword, limit=search_limit, max_pages=page_cap)" in feeder_source
assert "_fetch_unmatched_priority_skus" in feeder_source
assert "_fetch_expired_identity_skus" in feeder_source
assert "run_expired_identity_refresh" in feeder_source

View File

@@ -218,3 +218,54 @@ def test_feeder_search_candidate_passes_page_cap(monkeypatch):
assert candidates == [product]
assert calls[0][1]["limit"] == 40
assert calls[0][1]["max_pages"] == 2
def test_feeder_search_candidate_respects_bounded_budget(monkeypatch):
from services.competitor_price_feeder import _search_pchome_candidates
from services.pchome_crawler import PChomeProduct
product = PChomeProduct(
product_id="DDAB01-FAST",
name="理膚寶水 B5 修復霜 40ml",
price=679,
original_price=799,
discount=15,
image_url="",
product_url="https://24h.pchome.com.tw/prod/DDAB01-FAST",
stock=20,
store="24h",
rating=4.7,
review_count=8,
is_on_sale=True,
crawled_at=datetime.now(),
)
calls = []
class FakeCrawler:
def search_products(self, keyword, **kwargs):
calls.append((keyword, kwargs))
return True, "ok", [product]
monkeypatch.setattr(
"services.marketplace_product_matcher.score_marketplace_match",
lambda *_args, **_kwargs: type(
"Diagnostics",
(),
{"score": 0.80},
)(),
)
candidates = _search_pchome_candidates(
FakeCrawler(),
"理膚寶水 B5 修復霜 40ml",
keywords=["理膚寶水 B5", "理膚寶水 修復霜", "b5 cream"],
momo_price=699,
max_terms=1,
max_pages=1,
max_seconds=30,
)
assert candidates == [product]
assert [call[0] for call in calls] == ["理膚寶水 B5"]
assert calls[0][1]["limit"] == 20
assert calls[0][1]["max_pages"] == 1