Fix fudai diagnostics and redpacket guard
This commit is contained in:
1 parent
cb74a23e81
commit
28709d2d97
11 files changed
+245
-4
No files matched your search
Binary file not shown.
|
After Width: | Height: | Size: 1.8 MiB |
Binary file not shown.
|
After Width: | Height: | Size: 1.8 MiB |
Binary file not shown.
|
After Width: | Height: | Size: 2.1 MiB |
@@ -29,7 +29,7 @@ def test_v2_profile_keeps_legacy_and_adds_expected_regions(monkeypatch):
|
||||
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"] == (365, 1368, 1040, 1465)
|
||||
assert DETAIL_UI_V2_0["value"] == (300, 1518, 650, 1615)
|
||||
assert DETAIL_UI_V2_0["value"] == (300, 1518, 820, 1695)
|
||||
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)
|
||||
@@ -148,6 +148,33 @@ def test_v2_two_task_profile_covers_batu_4999_sample_regions():
|
||||
assert crop_has_bright_text(DETAIL_UI_V2_0["content"]) > 0.01
|
||||
|
||||
|
||||
def test_v2_two_task_value_region_covers_reference_value_line():
|
||||
from pathlib import Path
|
||||
from douyin.fudai.core.coords import DETAIL_UI_V2_0
|
||||
|
||||
samples = [
|
||||
Path("tests/fixtures/fudai_detail_v2_two_task_redmi_2999_regions.png"),
|
||||
Path("tests/fixtures/fudai_detail_v2_two_task_guohao_1199_regions.png"),
|
||||
]
|
||||
missing = [sample for sample in samples if not sample.exists()]
|
||||
if missing:
|
||||
pytest.skip("v2 two-task value samples are unavailable")
|
||||
|
||||
value_box = DETAIL_UI_V2_0["value"]
|
||||
assert value_box[2] >= 760
|
||||
assert value_box[3] >= 1690
|
||||
|
||||
def crop_has_reference_line_text(sample: Path) -> float:
|
||||
img = Image.open(sample).convert("RGB")
|
||||
crop = img.crop((340, 1585, min(value_box[2], 820), min(value_box[3], 1695)))
|
||||
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))
|
||||
|
||||
for sample in samples:
|
||||
assert crop_has_reference_line_text(sample) > 0.03
|
||||
|
||||
|
||||
def test_ocr_switch_defaults_and_legacy_disable_compat():
|
||||
from douyin.fudai.douyin_fudai_core_pkg.ocr_switches import (
|
||||
FudaiDetailOcrSwitches,
|
||||
|
||||
@@ -42,6 +42,7 @@ ICON_REGRESSION_CASES = [
|
||||
("false_left_coupon_x162.png", False, None, None),
|
||||
("false_no_fudai_light10.png", False, None, None),
|
||||
("false_right_coupon_strip_x366.png", False, None, None),
|
||||
("false_shopping_redpacket_left_x168.png", False, None, None),
|
||||
]
|
||||
|
||||
|
||||
@@ -177,6 +178,20 @@ class TestFudaiDetector:
|
||||
|
||||
assert elapsed_ms < 5.0
|
||||
|
||||
def test_redpacket_neighbor_detector_rejects_shopping_redpacket_entry(self):
|
||||
sample = FIXTURE_DIR / "false_shopping_redpacket_left_x168.png"
|
||||
if not sample.exists():
|
||||
pytest.skip("fixture unavailable")
|
||||
|
||||
d = FudaiDetector(FakeAnalyser())
|
||||
img = Image.open(sample).convert("RGB")
|
||||
|
||||
redpacket_like, info = d._has_redpacket_neighbor_widget(img, 168)
|
||||
|
||||
assert redpacket_like is True
|
||||
assert info["white_ratio"] >= 0.35
|
||||
assert info["pink_ratio"] >= 0.06
|
||||
|
||||
def test_current_icon_template_confirms_clean_countdown_sample(self):
|
||||
sample = Path(
|
||||
"artifacts/live_fudai_flow_20260618_0530_valid/snapshots/"
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
from datetime import datetime
|
||||
|
||||
import pytest
|
||||
|
||||
@@ -21,6 +22,7 @@ from douyin.handlers.screenshot_manager import (
|
||||
get_ocr_dir,
|
||||
reset_async_save_counters,
|
||||
)
|
||||
from douyin.handlers.screenshot_manager.cleanup import cleanup_debug_captures
|
||||
|
||||
|
||||
# ============================================================
|
||||
@@ -143,6 +145,26 @@ class TestEnsureDirs:
|
||||
ensure_debug_captures_dir()
|
||||
ensure_debug_captures_dir()
|
||||
|
||||
def test_cleanup_keeps_today_debug_captures_when_file_limit_exceeded(
|
||||
self, tmp_path, monkeypatch
|
||||
):
|
||||
base_dir = tmp_path / "debug_captures"
|
||||
today_dir = base_dir / datetime.now().strftime("%Y-%m-%d")
|
||||
today_dir.mkdir(parents=True)
|
||||
for index in range(3):
|
||||
(today_dir / f"capture_{index}.png").write_bytes(b"png")
|
||||
|
||||
monkeypatch.setattr(
|
||||
"douyin.handlers.screenshot_manager.cleanup.get_debug_captures_base_dir",
|
||||
lambda: str(base_dir),
|
||||
)
|
||||
|
||||
deleted = cleanup_debug_captures(keep_days=999, max_files=1)
|
||||
|
||||
assert deleted == 0
|
||||
assert today_dir.exists()
|
||||
assert len(list(today_dir.glob("*.png"))) == 3
|
||||
|
||||
|
||||
# ============================================================
|
||||
# _common.py — 异步计数器
|
||||
|
||||
@@ -223,6 +223,40 @@ class TestSaveImageModule:
|
||||
if g >= 160 and r <= 80 and b <= 120:
|
||||
green_pixels += 1
|
||||
assert green_pixels > 20
|
||||
|
||||
def test_maybe_auto_cleanup_skips_repeated_same_day_over_limit_scan(
|
||||
self, tmp_path, monkeypatch
|
||||
):
|
||||
from datetime import datetime
|
||||
from douyin.handlers.screenshot_manager import save_image_helpers as helpers
|
||||
|
||||
debug_base = tmp_path / "debug_captures"
|
||||
debug_base.mkdir()
|
||||
today = datetime.now().strftime("%Y-%m-%d")
|
||||
(debug_base / ".cleanup_marker").write_text(today, encoding="utf-8")
|
||||
config_path = tmp_path / "config.json"
|
||||
config_path.write_text(
|
||||
'{"debug_captures":{"max_files":1}}',
|
||||
encoding="utf-8",
|
||||
)
|
||||
calls = {"count": 0}
|
||||
|
||||
monkeypatch.setattr(helpers, "get_debug_captures_base_dir", lambda: str(debug_base))
|
||||
monkeypatch.setattr(
|
||||
"douyin.handlers.screenshot_manager.save_image_helpers.path_config.get_config_path",
|
||||
lambda: str(config_path),
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
helpers,
|
||||
"count_debug_captures_files",
|
||||
lambda: calls.__setitem__("count", calls["count"] + 1) or 2,
|
||||
)
|
||||
monkeypatch.setattr(helpers, "cleanup_debug_captures", lambda **_kwargs: 0)
|
||||
|
||||
helpers.maybe_auto_cleanup(True, lambda _msg: None)
|
||||
helpers.maybe_auto_cleanup(True, lambda _msg: None)
|
||||
|
||||
assert calls["count"] == 1
|
||||
|
||||
|
||||
class TestScreenshotManagerSubmodules:
|
||||
|
||||
Reference in new issue
Block a user