fix: 修正规格摘要误判颜色标题 (#277)

This commit is contained in:
chengma
2026-08-18 17:56:21 +08:00
parent 5e27d4cd75
commit 1902935d58
2 changed files with 58 additions and 8 deletions
+14 -8
View File
@@ -172,23 +172,29 @@ def _screen_bounds(root: ET.Element) -> Optional[Bounds]:
return 0, 0, max(item[2] for item in bounds), max(item[3] for item in bounds)
def _spec_heading_name(value: str) -> str:
"""返回独立规格标题,排除“请选择”“选择后”等摘要和提示。"""
compact = re.sub(r"\s+", "", str(value or ""))
compact = re.sub(r"[((]\d+[))]$", "", compact)
supported = _COLOR_HEADINGS + _PACKAGE_HEADINGS
return compact if compact in supported else ""
def _heading_bounds(root: ET.Element) -> Optional[Bounds]:
fuzzy_match: Optional[Bounds] = None
package_fallback: Optional[Bounds] = None
for node in root.iter("node"):
text = node.get("text", "").strip()
heading = _spec_heading_name(node.get("text", ""))
bounds = _parse_bounds(node.get("bounds", ""))
if bounds is None or not _is_available(node):
if not heading or bounds is None or not _is_available(node):
continue
# “请选择:颜色分类 尺码”等摘要不能当成颜色列表标题。
if text == "颜色分类":
if heading == "颜色分类":
return bounds
if fuzzy_match is None and any(heading in text for heading in _COLOR_HEADINGS):
if fuzzy_match is None and heading in _COLOR_HEADINGS:
fuzzy_match = bounds
if package_fallback is None and any(
heading in text for heading in _PACKAGE_HEADINGS
):
if package_fallback is None and heading in _PACKAGE_HEADINGS:
package_fallback = bounds
# “款式 + 套餐”优先定位款式;只有套餐一个维度时才用套餐兜底。
return fuzzy_match or package_fallback
+44
View File
@@ -263,6 +263,50 @@ class StaticColorSelectionTest(unittest.TestCase):
self.assertTrue(selected)
self.assertEqual(device.clicks, [(194, 1389)])
def test_summary_is_ignored_and_counted_color_heading_is_used(self):
simplified = "紫色诱惑"
traditional = "紫色誘惑"
panel_xml = f'''<hierarchy>
<node bounds="[0,0][1080,2376]">
<node text="请选择:颜色" bounds="[396,827][1053,889]" />
<node text="选择款式后查看优惠" bounds="[639,1083][1044,1136]" />
<node text="尺码" bounds="[36,1202][126,1255]" />
<node text="颜色 (4)" bounds="[36,1416][198,1469]" />
<node bounds="[36,1495][1044,1695]">
<node text="{simplified}" clickable="true"
bounds="[36,1495][249,1580]" />
<node text="其他颜色" clickable="true"
bounds="[270,1495][483,1580]" />
</node>
</node>
</hierarchy>'''
device = StaticColorDevice(panel_xml, selected_text=simplified)
selected = select_color(
device,
panel_xml,
traditional,
action_delay=0.001,
)
self.assertTrue(selected)
self.assertEqual(device.clicks, [(142, 1537)])
self.assertEqual(device.swipes, [])
def test_chinese_parentheses_count_is_a_color_heading(self):
panel_xml = self.panel_xml.replace("颜色分类", "颜色(4)")
device = StaticColorDevice(panel_xml)
selected = select_color(
device,
panel_xml,
"测试黑色",
action_delay=0.001,
)
self.assertTrue(selected)
self.assertEqual(device.clicks, [(194, 1389)])
def test_non_scrollable_row_ignores_same_row_style_option_as_heading(self):
simplified = "纯欲莹白【透.视蕾丝衣.免脱款】"
traditional = "純欲瑩白【透.視蕾絲衣.免脫款】"