Fix v2 fudai detail recognition

This commit is contained in:
Your Name committed 2026-06-18 13:27:27 +08:00
1 parent fc96549bd2
commit 8dbaab9d27
6 files changed
+106 -12

No files matched your search

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 MiB

+48 -3
View File
@@ -28,9 +28,9 @@ def test_v2_profile_keeps_legacy_and_adds_expected_regions(monkeypatch):
assert auto is DETAIL_UI_V2_0
assert one_task is DETAIL_UI_V2_0_ONE_TASK
assert DETAIL_UI_LEGACY["content"] == (389, 1273, 1000, 1534)
assert DETAIL_UI_V2_0["content"] == (360, 1410, 1035, 1495)
assert DETAIL_UI_V2_0["value"] == (300, 1585, 650, 1685)
assert DETAIL_UI_V2_0["countdown_full"] == (760, 1328, 1038, 1398)
assert DETAIL_UI_V2_0["content"] == (365, 1368, 1040, 1465)
assert DETAIL_UI_V2_0["value"] == (300, 1518, 650, 1615)
assert DETAIL_UI_V2_0["countdown_full"] == (760, 1265, 1040, 1345)
assert DETAIL_UI_V2_0["task_list"] == (60, 1840, 1030, 2005)
assert DETAIL_UI_V2_0["task_count"] == (860, 1770, 1035, 1875)
assert DETAIL_UI_V2_0["participants"] == (520, 1325, 760, 1415)
@@ -103,6 +103,51 @@ def test_detail_profile_ignores_invalid_config_overrides(monkeypatch):
assert profile["content"] == coords.DETAIL_UI_V2_0["content"]
def test_detail_profile_ignores_stale_v2_two_task_runtime_defaults(monkeypatch):
from douyin.fudai.core import coords
monkeypatch.setattr(
coords,
"_read_runtime_region_config",
lambda: {
"fudai_detail_regions": {
"v2_0_two_task": {
"content": [360, 1410, 1035, 1495],
"value": [300, 1585, 650, 1685],
"countdown_full": [760, 1328, 1038, 1398],
}
}
},
)
profile = coords.get_fudai_detail_profile("v2_0", task_count=2)
assert profile["content"] == coords.DETAIL_UI_V2_0["content"]
assert profile["value"] == coords.DETAIL_UI_V2_0["value"]
assert profile["countdown_full"] == coords.DETAIL_UI_V2_0["countdown_full"]
def test_v2_two_task_profile_covers_batu_4999_sample_regions():
from PIL import Image
from pathlib import Path
from douyin.fudai.core.coords import DETAIL_UI_V2_0
sample = Path("tests/fixtures/fudai_detail_v2_two_task_batu_4999_regions.png")
if not sample.exists():
pytest.skip("batu 4999 debug sample is unavailable")
img = Image.open(sample).convert("RGB")
def crop_has_bright_text(box):
crop = img.crop(box)
pixels = list(crop.getdata())
bright = sum(1 for r, g, b in pixels if r > 185 and g > 185 and b > 185)
return bright / max(1, len(pixels))
assert crop_has_bright_text(DETAIL_UI_V2_0["countdown_full"]) > 0.01
assert crop_has_bright_text(DETAIL_UI_V2_0["content"]) > 0.01
def test_ocr_switch_defaults_and_legacy_disable_compat():
from douyin.fudai.douyin_fudai_core_pkg.ocr_switches import (
FudaiDetailOcrSwitches,
+15
View File
@@ -80,6 +80,21 @@ class TestValidateFudaiDetail:
assert isinstance(is_valid, bool)
assert isinstance(reason, str)
def test_value_raw_accepts_zero_yuan_marketing_prefix(self):
from types import SimpleNamespace
from douyin.fudai.core.fudai_detail_validator import validate_fudai_detail
analyser = SimpleNamespace(
value_raw="0元带走¥999参考价值",
countdown_mm_raw="07",
countdown_ss_raw="59",
)
detail = ("福袋内容", "07:59", 0, 0, 999.0, (1000.0, 1479.0))
is_valid, reason = validate_fudai_detail(detail, analyser)
assert is_valid is True, reason
class TestFudaiDetailShimConsistency:
"""验证 fudai_detail shim 与子模块导出一致。"""