merge: T-103 refined prefix diagnostics
This commit is contained in:
@@ -423,8 +423,10 @@ def _crossing_price_text_mismatch_reason(text: str) -> str:
|
||||
return "non_ascii_whitespace"
|
||||
if any(marker in text for marker in ("提交订单", "支付", "下单", "优惠")):
|
||||
return "extra_or_order"
|
||||
without_leading_space = text.lstrip(" ")
|
||||
if without_leading_space.startswith("快") and not without_leading_space.startswith("快卖光"):
|
||||
without_one_leading_space = text[1:] if text.startswith(" ") else text
|
||||
if without_one_leading_space.startswith("快要抢光"):
|
||||
return "observed_prefix_kuaiyaoqiangguang"
|
||||
if without_one_leading_space.startswith("快") and not without_one_leading_space.startswith("快卖光"):
|
||||
return "known_prefix_missing"
|
||||
if "¥" not in text and "¥" not in text:
|
||||
return "currency_missing"
|
||||
|
||||
@@ -289,6 +289,12 @@ class SkuEvidenceSanitizerTests(unittest.TestCase):
|
||||
(
|
||||
"known-prefix-missing",
|
||||
_xml_with_prices(current="快要抢光 ¥12.88"),
|
||||
"observed_prefix_kuaiyaoqiangguang",
|
||||
PRICE_CURRENT_BOUNDS,
|
||||
),
|
||||
(
|
||||
"other-kuai-prefix-remains-generic",
|
||||
_xml_with_prices(current="快递地址 ¥12.88"),
|
||||
"known_prefix_missing",
|
||||
PRICE_CURRENT_BOUNDS,
|
||||
),
|
||||
@@ -354,6 +360,23 @@ class SkuEvidenceSanitizerTests(unittest.TestCase):
|
||||
for raw_fragment in (TEST_ADDRESS, FULL_PHONE, "使用微信支付", "提交订单", "¥12.88"):
|
||||
self.assertNotIn(raw_fragment, message)
|
||||
|
||||
def test_observed_prefix_diagnostic_does_not_echo_its_suffix(self) -> None:
|
||||
suffix = "地址和金额都不得回显"
|
||||
text = f"快要抢光 ¥12.88 {suffix}"
|
||||
with TemporaryDirectory() as temporary:
|
||||
raw = _write_raw(Path(temporary), xml=_xml_with_prices(current=text))
|
||||
with self.assertRaises(SkuEvidenceSanitizationError) as raised:
|
||||
sanitize_sku_panel_evidence(raw, raw.parent / "derived")
|
||||
|
||||
message = str(raised.exception)
|
||||
self.assertEqual(
|
||||
message,
|
||||
"跨界价格节点文本不匹配:slot=[396,503][712,570];"
|
||||
"reason=observed_prefix_kuaiyaoqiangguang。",
|
||||
)
|
||||
self.assertNotIn(suffix, message)
|
||||
self.assertNotIn("¥12.88", message)
|
||||
|
||||
def test_crossing_price_projection_allows_only_limited_ascii_spaces_and_yen_variants(self) -> None:
|
||||
for current in ("快卖光 ¥12.88", " 快卖光 ¥ 12.88 ", "快卖光 ¥12.88"):
|
||||
with self.subTest(current=current), TemporaryDirectory() as temporary:
|
||||
|
||||
Reference in New Issue
Block a user