feat: add momo review candidate queue
All checks were successful
CD Pipeline / deploy (push) Successful in 1m11s

This commit is contained in:
ogt
2026-06-24 13:09:56 +08:00
parent 76a89a7098
commit 06418878e0
7 changed files with 508 additions and 2 deletions

View File

@@ -429,6 +429,58 @@ def test_sync_targeted_momo_review_candidates_writes_needs_review_offer(monkeypa
assert stale_marks == [True]
def test_momo_review_candidate_queue_can_confirm_candidate(monkeypatch):
from services import external_market_offer_service as service
stale_marks = []
monkeypatch.setattr(service, "mark_pchome_growth_cache_stale", lambda: stale_marks.append(True))
engine = create_engine("sqlite:///:memory:")
_seed_external_offer_sync_tables(engine)
service.sync_targeted_momo_review_candidates_to_external_offers(engine, [
{
"product_id": "14917079",
"name": "【cle de peau 肌膚之鑰】光采柔焦蜜粉 24g (國際航空版)",
"price": 2618,
"target_pchome_product_id": "PCH-CDP",
"target_pchome_name": "cle de peau 光采柔焦蜜粉 24g #1",
"target_pchome_price": 2790,
"target_match_score": 1.0,
"target_price_basis": "none",
"target_alert_tier": "identity_review",
"target_match_type": "exact",
"target_match_reasons": ["variant_selection_review"],
"target_gap_pct": -6.16,
},
])
queue = service.list_momo_review_candidates(engine)
assert queue["success"] is True
assert queue["count"] == 1
candidate = queue["rows"][0]
assert candidate["pchome_product_name"] == "cle de peau 光采柔焦蜜粉 24g #1"
assert candidate["momo_sku"] == "14917079"
assert candidate["plain_status"] == "待確認同款或色號"
updated = service.update_momo_review_candidate(engine, candidate["id"], "confirm", note="同款 #1")
assert updated["success"] is True
assert updated["match_status"] == "verified"
assert service.list_momo_review_candidates(engine)["count"] == 0
with engine.connect() as conn:
row = conn.execute(text("""
SELECT match_status, data_quality_status, raw_payload_json
FROM external_offers
WHERE id = :id
"""), {"id": candidate["id"]}).mappings().one()
raw_payload = __import__("json").loads(row["raw_payload_json"])
assert row["match_status"] == "verified"
assert row["data_quality_status"] == "verified"
assert raw_payload["review_action"] == "confirm"
assert stale_marks == [True, True]
def test_sync_targeted_momo_candidates_keeps_best_unit_quantity_match(monkeypatch):
from services import external_market_offer_service as service
@@ -547,6 +599,10 @@ def test_external_offer_csv_dry_run_route_is_registered_as_post_only():
assert "@ai_bp.route('/api/ai/pchome-growth/external-offers/csv-dry-run', methods=['POST'])" in route_source
assert "dry_run_external_offer_csv" in route_source
assert "@ai_bp.route('/api/ai/pchome-growth/review-candidates')" in route_source
assert "@ai_bp.route('/api/ai/pchome-growth/review-candidates/<int:offer_id>', methods=['POST'])" in route_source
assert "list_momo_review_candidates" in route_source
assert "update_momo_review_candidate" in route_source
def test_external_offer_sync_is_registered_in_scheduler():

View File

@@ -421,7 +421,11 @@ def test_ai_intelligence_template_uses_pchome_growth_name_and_endpoint():
assert "PChome 業績成長自動化作戰系統" in template
assert "/api/ai/pchome-growth/opportunities" in template
assert "/api/ai/pchome-growth/external-offers/csv-dry-run" in template
assert "/api/ai/pchome-growth/review-candidates" in template
assert "growthSourceReadiness" in template
assert "MOMO 待確認候選" in template
assert "確認同款" in template
assert "不是同款" in template
assert "今日重點總覽" in template
assert "nextActionTitle" in template
assert "商品處理進度" in template