fix(growth): partition Yahoo promotion candidates
Some checks failed
CD Pipeline / deploy (push) Has been cancelled

This commit is contained in:
ogt
2026-07-15 13:15:33 +08:00
parent 4670f80f98
commit c091c466c2
6 changed files with 139 additions and 13 deletions

View File

@@ -746,6 +746,104 @@ def test_backfill_rolls_back_failed_write_before_source_activation(monkeypatch):
assert rollback_calls[0]["activation_receipt"]["applied"] is False
def test_backfill_source_profile_defers_disallowed_unit_price(monkeypatch):
from services import pchome_growth_momo_backfill_service as service
engine = create_engine("sqlite:///:memory:")
exact = {
"product_id": "Y-EXACT",
"target_pchome_product_id": "PCH-1",
"auto_compare_type": "total_price",
}
unit = {
"product_id": "Y-UNIT",
"target_pchome_product_id": "PCH-2",
"auto_compare_type": "unit_price",
}
payload = {
"success": True,
"stats": {"candidate_validation_count": 2, "unmatched_count": 0},
"opportunities": [
{
"pchome_product_id": "PCH-1",
"product_name": "Exact 商品",
"pchome_price": 900,
"sales_7d": 1000,
"external_price": None,
"recommended_action": {"code": "map_external_product"},
}
],
}
captured = {}
monkeypatch.setattr(
service,
"ensure_evidence_receipt_table",
lambda _engine: {"success": True},
)
monkeypatch.setattr(
service,
"verify_same_item_candidates",
lambda _targets, _candidates, *, identity: {
"verified_candidates": [exact, unit],
"review_candidates": [],
"blocked_candidate_count": 0,
"identity": identity,
},
)
monkeypatch.setattr(
service,
"build_coverage_post_verifier",
lambda **_kwargs: {
"all_checks_passed": True,
"status": "verified",
"readback_pass_count": 1,
"count_coverage_delta": 0,
"revenue_coverage_delta": 0,
"after": {"candidate_validation_count": 1, "unmatched_count": 0},
},
)
monkeypatch.setattr(
service,
"persist_reconciliation_receipts",
lambda *_args, **_kwargs: {"success": True, "readback_count": 1},
)
def sync(_engine, candidates):
captured["formal"] = candidates
return {"success": True, "status": "synced", "written_count": 1}
def sync_review(_engine, candidates):
captured["candidate_only"] = candidates
return {"success": True, "status": "artifact_candidate_only", "written_count": 0}
result = service.run_pchome_growth_momo_backfill(
engine,
limit=1,
build_payload_func=lambda _engine, _limit: payload,
search_func=lambda _targets, _limit: (True, "found", [exact, unit]),
sync_func=sync,
sync_review_func=sync_review,
readback_func=lambda _engine, _candidates: {
"success": True,
"readback_pass_count": 1,
},
source_profile={
"work_item_id": "GROWTH-P0-001-C",
"formal_compare_types": ["total_price"],
},
)
assert result["success"] is True
assert [item["product_id"] for item in captured["formal"]] == ["Y-EXACT"]
assert [item["product_id"] for item in captured["candidate_only"]] == ["Y-UNIT"]
assert captured["candidate_only"][0]["promotion_policy_status"] == "candidate_only"
assert result["data"]["auto_compare_count"] == 1
assert result["data"]["unit_compare_count"] == 0
assert result["data"]["review_count"] == 1
assert result["data"]["promotion_policy_deferred_count"] == 1
def test_pchome_growth_momo_backfill_default_search_uses_deeper_terms(monkeypatch):
from services import pchome_growth_momo_backfill_service as service