強化 PChome rescore 漏掃與錯配防線
All checks were successful
CD Pipeline / deploy (push) Successful in 1m4s

This commit is contained in:
OoO
2026-05-25 16:05:08 +08:00
parent dab782cc6d
commit bd33f7ff60
7 changed files with 140 additions and 2 deletions

View File

@@ -1,4 +1,6 @@
import json
import importlib.util
from pathlib import Path
from sqlalchemy import create_engine, text
@@ -28,6 +30,32 @@ def _create_match_attempts_table(conn):
"""))
def _load_rescore_cli_module():
module_path = Path(__file__).resolve().parents[1] / "scripts" / "audit_competitor_match_attempt_rescore.py"
spec = importlib.util.spec_from_file_location("audit_competitor_match_attempt_rescore_cli", module_path)
module = importlib.util.module_from_spec(spec)
assert spec and spec.loader
spec.loader.exec_module(module)
return module
def test_match_attempt_rescore_cli_defaults_to_unfiltered_reasons(monkeypatch, capsys):
cli = _load_rescore_cli_module()
captured = {}
def fake_build_match_attempt_rescore_audit(_engine, **kwargs):
captured.update(kwargs)
return {"scanned": 0}
monkeypatch.setattr(cli, "create_engine", lambda _database_path: object())
monkeypatch.setattr(cli, "build_match_attempt_rescore_audit", fake_build_match_attempt_rescore_audit)
assert cli.main(["--limit", "1"]) == 0
capsys.readouterr()
assert captured["reason_filter"] is None
def test_match_attempt_rescore_audit_classifies_current_gate_pass_and_veto():
from services.competitor_match_attempt_rescore_audit import summarize_match_attempt_rescore

View File

@@ -2187,6 +2187,41 @@ def test_marketplace_matcher_keeps_aroma_and_nail_variant_gaps_blocked():
assert "variant_descriptor_conflict" in dashing_cross_style.reasons
def test_marketplace_matcher_blocks_high_score_wax_lamp_and_device_variant_gaps():
from services.marketplace_product_matcher import score_marketplace_match
pray_size_gap = score_marketplace_match(
"【韓國PRAY】守夜人金屬香氛蠟燭暖燈-復古金(L/專櫃公司貨)",
"【韓國EPOCHSIA x Pray】守夜人金屬香氛蠟燭暖燈(S)-復古金",
)
nitori_model_gap = score_marketplace_match(
"【NITORI 宜得利家居】香氛噴霧器 5510(香氛)",
"【NITORI 宜得利家居】香氛噴霧器 YX168 WH",
)
assert pray_size_gap.hard_veto is True
assert pray_size_gap.comparison_mode == "not_comparable"
assert "size_letter_variant_conflict" in pray_size_gap.reasons
assert nitori_model_gap.hard_veto is True
assert nitori_model_gap.comparison_mode == "not_comparable"
assert "nitori_diffuser_model_conflict" in nitori_model_gap.reasons
def test_marketplace_matcher_sends_single_sided_makeup_shade_to_review():
from services.marketplace_product_matcher import score_marketplace_match
diagnostics = score_marketplace_match(
"【LA MER 海洋拉娜】奇蹟煥采氣墊粉霜 24g12g x 2專櫃公司貨",
"《LA MER 海洋拉娜》奇蹟煥采氣墊粉霜 24g12g x 2-11 Rosy Ivory",
)
assert diagnostics.hard_veto is False
assert diagnostics.score >= 0.76
assert diagnostics.price_basis == "manual_review"
assert diagnostics.alert_tier == "identity_review"
assert "variant_selection_review" in diagnostics.reasons
def test_marketplace_matcher_promotes_eaoron_classic_tone_up_cream_exact_line():
from services.marketplace_product_matcher import score_marketplace_match