修复福袋详情OCR v2与调试日志
This commit is contained in:
1 parent
2c6f024a24
commit
1d37d57c90
119 files changed
+5582
-767
No files matched your search
@@ -0,0 +1,18 @@
|
||||
# 福袋详情页 OCR 2.0 handoff
|
||||
|
||||
1. 目标:按 1080x2400 新福袋详情页更新 OCR 区域,保留 legacy,并支持 `auto/legacy/v2_0`。
|
||||
2. 已新增字段开关:内容、价值、倒计时、任务、任务数量、按钮默认开;人数、直播间标题默认关。
|
||||
3. 旧开关 `fudai_disable_content_recognition` / `fudai_disable_task_recognition` 仅作新开关缺省兜底。
|
||||
4. 2.0 双任务 profile 在 `douyin/fudai/core/coords.py` 的 `DETAIL_UI_V2_0`。
|
||||
5. 2.0 单任务下移 profile 在 `DETAIL_UI_V2_0_ONE_TASK`,按当前 ADB 截图微调。
|
||||
6. 当前单任务标注图:`logs/fudai_detail_v2_regions_onetask_precise3.png`。
|
||||
7. 当前 ADB 原图:`logs/fudai_detail_v2_current_20260602_234012.png`。
|
||||
8. 单任务任务框已缩到左侧任务文案,避免混入右侧“未达成”。
|
||||
9. 任务数量优先 OCR `(0/1)` / `(1/2)`,失败回退 legacy 像素检测。
|
||||
10. debug 截图 extra_info 已包含 `ui_version`、`ocr_enabled`、`region_name` 等信息。
|
||||
11. 桌面 GUI 与 Web GUI 已加入 UI 版本和所有 OCR 字段开关。
|
||||
12. “参考价值”按实际价值解析,继续写 `prize_value_yuan`。
|
||||
13. 验证日志:`logs/pytest_fudai_detail_v2_final4.log` PASS。
|
||||
14. 验证日志:`logs/py_compile_fudai_detail_v2_final4.log` PASS。
|
||||
15. 验证日志:`logs/web_gui_config_sync_fudai_v2_final4.log` PASS。
|
||||
16. 验证日志:`logs/git_diff_check_fudai_v2_final4.log` PASS。
|
||||
@@ -0,0 +1,239 @@
|
||||
# 2026-06-02 全量代码审查进展
|
||||
|
||||
目标:对 `C:\Users\12742\Desktop\douyin_guaji-main` 做仓库级 code review,并对确认的高风险功能缺陷直接修复。
|
||||
|
||||
## 已确认并已修复
|
||||
|
||||
1. `gui/web_gui.py`
|
||||
- `force_stop()` / `atexit` 会误杀同仓库其他 `run_cli.py` 进程。
|
||||
- 已改为只清理当前 Web GUI 自己启动过的 PID。
|
||||
|
||||
2. `gui/webgui_launcher.py`
|
||||
- `stop_old_processes()` 会按 `*web_gui.py*` 全局杀进程。
|
||||
- 已改为限定当前仓库路径。
|
||||
|
||||
3. `gui/gui_core_pkg/config.py`
|
||||
- 配置写入是浅 `update` + 直接覆盖,存在并发丢字段和半写风险。
|
||||
- 已改为深合并 + 进程内锁 + `.tmp` + `os.replace()`。
|
||||
|
||||
4. `operations/screenshot_service.py`
|
||||
- `start()` 在持锁状态下调用 `stop()`,设备切换时可能死锁。
|
||||
- 已改为先释放锁再等待旧线程退出。
|
||||
|
||||
5. `gui/gui_core_pkg/wifi_adb.py`
|
||||
- `disconnect_wifi_adb("ip:port")` 会拼成 `ip:port:5555`。
|
||||
- 已修复为支持直接 `ip:port` 输入。
|
||||
|
||||
6. `gui/web_gui_pkg/routes.py`
|
||||
- `/api/*` GET/POST、`/pic/*` 以及静态页都可被非本地来源访问。
|
||||
- 已全部限制为 local-only。
|
||||
|
||||
7. `douyin/core/douyin_fudai.py`
|
||||
- `_maybe_run_yanghao_during_run()` 注释说触发推荐页养号,实际只调用 `_yanghao_wait()`。
|
||||
- 已改为真正调用 `_yanghao_recommend_flow()`。
|
||||
|
||||
8. `douyin/fudai/core/fudai_detail_orchestrator_pkg/read_with_retries.py`
|
||||
- `read_once_callback` 参数未被真正使用。
|
||||
- `status="ok"` 但 tuple 无效时会走未定义局部变量路径。
|
||||
- `task_count_zero` 补救逻辑与 `read_once()` 返回的 `not_in_fudai_detail` 不一致。
|
||||
- 已修复以上三点。
|
||||
|
||||
9. `douyin/fudai/core/fudai_detail_orchestrator_pkg/read_once.py`
|
||||
- 停止后台截图服务后未恢复。
|
||||
- 复用阶段截图时不验证可读性,坏图会直接落到 `screenshot_failed`。
|
||||
- 已补恢复逻辑和坏图自动 fresh screenshot。
|
||||
|
||||
10. `douyin/core/fudai_modules/handle_detail_*`
|
||||
- first-open / second-open / 错误分支存在多处状态残留:
|
||||
- first-open 可能误标 second-open
|
||||
- second-open 重读终止状态后不清 flag
|
||||
- second-open 重读失败后仍卡 second-open
|
||||
- task_count_zero / not_in_fudai_detail 被消费后不清 `_last_fudai_detail_status/_extra`
|
||||
- coupon/watch/validation_failed 被消费后不清 `_last_fudai_detail_status`
|
||||
- 以上已逐项修复。
|
||||
|
||||
11. `douyin/detection/detection_pkg/finder.py`
|
||||
- 命中后不写回 `last_fudai_x`。
|
||||
- 非 1080 宽屏下历史坐标比较混用坐标系。
|
||||
- `fudai_icon_max_wait_seconds=0` 时会 0 次检测直接退出。
|
||||
- 已修复。
|
||||
|
||||
12. `douyin/detection/detection_pkg/finder_template_match.py`
|
||||
- 模板兜底命中后不写回 `last_fudai_x`,与其他两条检测路径不一致。
|
||||
- 已修复。
|
||||
|
||||
13. 导入链缺依赖即崩
|
||||
- 已逐步把以下模块的顶层 `PIL` 依赖改成按需导入:
|
||||
- `operations.__init__`
|
||||
- `operations.screenshot_service`
|
||||
- `douyin.detection.pixel._common`
|
||||
- `douyin.detection.pixel.buttons`
|
||||
- `douyin.detection.pixel.popups`
|
||||
- `douyin.detection.pixel.stage`
|
||||
- `douyin.detection.detection_pkg.detail`
|
||||
- `douyin.detection.detection_pkg.finder`
|
||||
- `douyin.fudai.core.fudai_debug_utils`
|
||||
- `douyin.fudai.core.fudai_detail_coupon_detection`
|
||||
- `douyin.fudai.core.fudai_detail_orchestrator_pkg.read_once`
|
||||
- `douyin.fudai.core.fudai_detail_orchestrator_pkg.read_with_retries`
|
||||
- `douyin.core.douyin_fudai`
|
||||
- `douyin.core.underlying_operations`
|
||||
- 当前机器上已实证:
|
||||
- `import operations`:PASS
|
||||
- `import operations.screenshot_service`:PASS
|
||||
- `import douyin.detection.douyin_detection`:PASS
|
||||
- `import douyin.core.douyin_fudai`:PASS
|
||||
|
||||
14. `douyin/handlers/douyin_screenshot_handler.py`
|
||||
- `save_step_screenshot()` 用 `dirname(__file__)` 锚到错误 `pic` 目录。
|
||||
- 已改为统一使用 `path_config.get_pic_dir()`。
|
||||
|
||||
15. `douyin/core/fudai_modules/handle_detail_*`
|
||||
- `check_invalid_detail_fallback()` 早退时不清 `_fudai_detail_first_read/_last_fudai_detail_tuple`。
|
||||
- `handle_first_open_branch()` 的早退路径不清 first-open/缓存状态。
|
||||
- `handle_second_open_branch()` 重读无效详情时不清 second-open 标志。
|
||||
- 已修复。
|
||||
|
||||
16. `douyin/core/fudai_modules/handle_detail_helpers.py`
|
||||
- 终止类状态(coupon/watch/validation_failed)消费后不清 `_last_fudai_detail_status`。
|
||||
- task_count_zero / not_in_fudai_detail 错误被消费后不清 `_last_fudai_detail_status/_last_fudai_detail_extra`。
|
||||
- 已修复。
|
||||
|
||||
17. `douyin/detection/detection_pkg/finder.py`
|
||||
- `fudai_icon_max_wait_seconds=0` 时会 0 次检测直接退出。
|
||||
- 旧实现还会把显式配置的 `0` 通过 `or 5.0` 偷偷退回默认值。
|
||||
- 已修复为保留显式 `0`,并至少执行一轮即时检测。
|
||||
|
||||
18. `douyin/fudai/core/fudai_detail_coupon_detection.py`
|
||||
- 顶层 `PIL` 依赖会继续阻塞 `douyin_fudai` 导入链。
|
||||
- 已改为按需导入。
|
||||
|
||||
19. `douyin/detection/pixel/*`
|
||||
- `popups.py` / `buttons.py` / `stage.py` / `_common.py` 顶层 `PIL` 依赖会阻塞 detection 导入链。
|
||||
- 已改为按需导入。
|
||||
|
||||
20. `douyin/fudai/core/fudai_detail_orchestrator_pkg/read_once.py`
|
||||
- 第二次打开重读后若仍无有效 detail,会继续保留 second-open 状态。
|
||||
- 已修复。
|
||||
|
||||
21. `douyin/core/fudai_modules/handle_detail_first_open.py`
|
||||
- `branch_result == "return"` / 验证失败早退时,`_fudai_detail_first_read/_last_fudai_detail_tuple` 不清理。
|
||||
- 已修复。
|
||||
|
||||
22. `douyin/core/fudai_modules/handle_detail_helpers.py`
|
||||
- `check_invalid_detail_fallback()` 早退时不清 `_fudai_detail_first_read/_last_fudai_detail_tuple`。
|
||||
- 已修复。
|
||||
|
||||
23. `douyin/detection/detection_pkg/finder_template_match.py`
|
||||
- 模板兜底命中后只写 `last_find_fudai_time`,不写 `last_fudai_x`。
|
||||
- 已修复。
|
||||
|
||||
24. `operations/screenshot_operations.py` / `douyin/core/underlying_operations_pkg/screenshot_direct.py`
|
||||
- `target_pic` fallback 路径仍相对模块目录拼接。
|
||||
- 已统一锚到 `<project_root>/target_pic`。
|
||||
|
||||
25. `operations/screenshot_operations.py`
|
||||
- `_find_pic_path(..., for_reading=True)` 会把 `operations/` 当前目录作为图片搜索路径,可能误命中同名文件。
|
||||
- 已修复为只搜索项目根 `pic/` 与 `target_pic/`。
|
||||
|
||||
26. `douyin/detection/pixel/stage.py`
|
||||
- 并行阶段检测里实际调用了 popup/button helper,但文件头没导入,对应检测项运行时会静默掉成 False。
|
||||
- 已补齐导入。
|
||||
|
||||
27. `douyin/core/douyin_flow_control_pkg/stage_handler.py`
|
||||
- 直接调用 `find_and_open_fudai_detail()` 却未导入。
|
||||
- 已修复。
|
||||
|
||||
28. `douyin/core/underlying_operations_pkg/countdown.py`
|
||||
- 使用 `Optional` 但未导入。
|
||||
- 已修复。
|
||||
|
||||
29. `douyin/core/fudai_modules/handle_detail_filter.py`
|
||||
- 高价值预约分支里 `basic_join_decision()` 失败也会被当成“已记录预约并完成”。
|
||||
- 已修复为只有真成功才消费该分支。
|
||||
|
||||
30. `douyin/reservation/reservation_logic/add.py` / `attend_window.py`
|
||||
- 日志里的旧静态检查结果显示两处反复引用 `_RESERVATION_ERROR_UTILS_AVAILABLE`,但模块本身漏导入,属于确定性的 `NameError`/静态错误来源。
|
||||
- 已补齐从 `reservation_logic._common` 的导入。
|
||||
|
||||
31. `gui/web_gui_pkg/request_parsing.py`
|
||||
- `send_json()` 在客户端主动断开连接时会把正常断链打成 `ConnectionAbortedError` traceback,已在 `logs/web_gui_runtime.err.log` 中出现。
|
||||
- 已改为对 `BrokenPipeError` / `ConnectionAbortedError` / `ConnectionResetError` 静默收口,不再把正常断链记成服务端异常。
|
||||
|
||||
32. `douyin/logging/douyin_logging_pkg/monitor.py`
|
||||
- `logs` 中出现 `cannot import name 'start_log_monitor' from partially initialized module ... monitor`,根因是 `monitor.py` 顶层反向导入 `config.py`,同时模块导入末尾又主动调用 `configure_logging()`,形成循环导入。
|
||||
- 已去掉 `monitor -> config` 的顶层依赖,以及 `monitor` 模块导入时的自动配置副作用,当前 `monitor/config/douyin_logging` 导入链已可直接通过。
|
||||
|
||||
33. `douyin/logging/action_logger.py`
|
||||
- `ActionLogger.log_operation()` 之前只认 `elapsed`,会把调用方已经传进来的 `elapsed_seconds` 吞掉并重写成 `0.0`,导致 `actions.log` 大量出现假的 `耗时=0.00ms`。
|
||||
- 已改为同时正确接受 `elapsed` / `elapsed_seconds`,只在确实有值时才写入耗时字段,日志耗时保真恢复正常。
|
||||
|
||||
34. `douyin/fudai/douyin_fudai_contain_impl.py`
|
||||
- 重 OCR 分支里 `picked_heavy` 只在部分条件下赋值,后续却无条件读取,存在继续污染运行日志的局部变量边界风险。
|
||||
- 已补默认初始化,避免该分支再出现这类局部变量异常。
|
||||
|
||||
35. `douyin/logging/douyin_logging_wrapper_pkg/simple.py`
|
||||
- 行为日志桥接层之前只识别 `elapsed_ms` / `total_ms`,但 finder 一类日志大量传的是 `total_elapsed_ms`,导致这些本来已有总耗时的操作仍被桥接成缺失耗时或误导性 `0.00ms`。
|
||||
- 已补 `total_elapsed_ms -> elapsed_seconds` 的统一映射,后续 `actions.log` 能更真实反映 finder 总耗时。
|
||||
|
||||
36. `douyin/logging/douyin_logging_wrapper_pkg/detailed.py`
|
||||
- detailed 模式下的行为日志桥接也存在同样问题:只识别 `elapsed_ms` / `total_ms`,未覆盖 `total_elapsed_ms`,会让不同日志模式下的耗时记录不一致。
|
||||
- 已与 simple 模式对齐,补上 `total_elapsed_ms` 识别。
|
||||
|
||||
37. `douyin/reservation/reservation_logic/attend_window.py`
|
||||
- 运行时分支里仍残留一组高风险未定义符号:`cleanup_expired_reservations` 未导入,以及 `target_room_title / target_room_title_raw / target_content / target_value` 在成功回退分支会被直接使用。
|
||||
- 已补齐导入与目标预约字段的本地初始化,避免这些分支在运行时直接 `NameError`。
|
||||
|
||||
38. `douyin/fudai/core/fudai_attend.py`
|
||||
- `attend_choujiang()` 之前会在 5 秒有效期内无条件复用 `_fudai_button_status/_fudai_button_text`,没有校验缓存是否来自当前直播间,存在把上一个房间按钮状态误用到当前房间的风险。
|
||||
- 已改为:5 秒内复用也必须满足 `current_room_pos == _fudai_button_room_pos`(或其中一方缺失),避免跨房间误复用按钮 OCR 缓存。
|
||||
|
||||
39. `douyin/reservation/douyin_reservation_handler_pkg/seek_room.py`
|
||||
- 回退成功后会直接调用 `_dump_room_pos_map_to_state(analyser)`,但文件头之前没导入这个 helper,属于命中成功回退分支就可能触发的运行时 `NameError`。
|
||||
- 已补从 `dump_state.py` 的显式导入,并加了最小导入回归验证。
|
||||
|
||||
40. `douyin/fudai/core/fudai_attend.py`
|
||||
- 当 `room_pos` 不命中时,`attend_choujiang()` 之前只会从当前 `room_pos` 的映射表项回收 `button_text`,容易在房间位置漂移时直接掉到 `no_parallel_ocr_result`。
|
||||
- 已补按 `current_room_title/current_room_title_raw` 匹配映射表标题的兜底回收路径,减少按钮 OCR 缓存因为位置漂移而失效。
|
||||
|
||||
41. `douyin/fudai/core/fudai_attend.py`
|
||||
- `button_text_raw` 作为全局缓存之前会被直接信任,但它本身没有房间归属校验,存在把上一个直播间的裸按钮文本误用到当前直播间的风险。
|
||||
- 已改为:只有确认 `_fudai_button_room_pos` 与当前 `room_pos` 同房间(或任一方缺失)时,才允许直接信任 `button_text_raw`。
|
||||
|
||||
42. `douyin/fudai/core/fudai_attend.py`
|
||||
- “点击参与抽奖”分支里那两段调试 JSON 写盘之前完全裸奔,遇到不可 JSON 序列化对象时会直接把主流程打断。
|
||||
- 已改为真正的 best-effort:写盘整体包裹在 `try/except` 中,并对关键字段做基础类型收敛,`json.dumps(..., default=str)` 不再让调试写盘反咬业务路径。
|
||||
|
||||
43. `douyin/fudai/douyin_fudai_contain_impl.py`
|
||||
- 主并行 OCR 写按钮状态时会记录 `_fudai_button_room_pos`,但 fallback 并行 OCR 之前没传 `record_room_pos=True`,导致备用 OCR 成功后仍可能缺失房间归属信息,进而削弱后续跨房间缓存保护。
|
||||
- 已补齐 fallback 路径的 `record_room_pos=True`,并加了最小回归验证。
|
||||
|
||||
44. `gui/components/wifi_adb_dialog.py`
|
||||
- `toggle_maximize` 之前被错误定义在 `auto_connect_wifi()` 内部,但“放大/恢复”按钮是在外层直接绑定 `command=toggle_maximize`,属于打开对话框就可能命中的真作用域错误。
|
||||
- 已把 `toggle_maximize` 提升到 `open_wifi_adb_dialog()` 同级作用域,并补了最小 smoke test 证明按钮命令可正常绑定。
|
||||
|
||||
## 仍建议继续深挖
|
||||
|
||||
1. `douyin/detection/detection_pkg/finder.py`
|
||||
- 坏截图/半写图补拍恢复的一致性。
|
||||
- 模板兜底与像素路径在日志、计时和状态清理上的一致性。
|
||||
|
||||
2. `douyin/fudai/core/fudai_detail_orchestrator_pkg/read_once.py`
|
||||
- 运行期截图/OCR异常回退的进一步收口。
|
||||
|
||||
## 仍未修复但已确认的风险
|
||||
|
||||
1. `config/config.json`
|
||||
- 仍混有明显的本机运行态/本地偏好数据(如 `last_wifi_target`),不适合作为稳定仓库默认值。
|
||||
- 因文件属于当前工作树活跃修改内容,未直接重写,避免覆盖用户现场状态。
|
||||
|
||||
2. `pyright`
|
||||
- 仓库仍存在一批历史静态类型错误,当前没有被系统性清理。
|
||||
|
||||
3. `pytest`
|
||||
- 当前环境缺 `pytest`,无法在本会话中把新增回归测试正式跑绿;目前主要依赖语法检查与轻量行为探针。
|
||||
|
||||
## 当前验证约束
|
||||
|
||||
1. 当前环境缺 `pytest`,不能直接在此会话里把新增测试跑绿。
|
||||
2. 当前环境缺 `PIL` / OCR 相关依赖,但这反而帮助暴露了导入链的真实缺陷;多处“缺依赖即崩”的问题已被修复并通过轻量 import 探针验证。
|
||||
Reference in new issue
Block a user