复查 V1.6.2 与 11-16~11-22 补丁: 返回按钮 TypeError、事件兜底连点、截图熔断线程
- 返回按钮(I-15): V1.6.2 在首次引导页拿 click_element 的返回值当坐标再点, 它返回 True → TypeError, 镜牢任务退出。install_back_button_result 只在 `x := auto.click_element(返回)` 这种调用时只找不点, 由上游点一次; 只看真假的调用照常点; 上游源码里没有这种写法就不装 - 事件兜底(I-16): LCP_EVENT_FALLBACK=1 时每轮都抢先点第 1 项, 上游走不到判定/继续/开始战斗; runs 里 1014 条 fallback_first, 73 段同屏连点 10~11 次, 最长 110 次。改成每屏只点一次、与按表共用 5 次上限 - 事件点击点只在这一项自己那行 OCR 字里取(原来整屏找子串, 叙述或别的选项是它的子串时会点错) - 截图熔断(I-17): 只在任务主线程计数和中止(retry_monitor 线程里抛只会打死那条线程, 两次熔断都记了两条); 要求连续出错满 30 秒、至少 20 次, 一闪而过的坏帧不再停掉任务 - 卡包: 优选阈值默认 1 与注释/提交说明/实机一致(LCP_THEME_PACK_THRESHOLD=0 不动上游); 「刷新」OCR 范围按 set_win_size/1440 缩放 - .gitignore 放行 docs/feedback/runs/**/logs/*.log(INDEX 说的过滤日志此前被 *.log 挡掉, 没进仓库) - README 补 LCP_EVENT_FALLBACK / LCP_THEME_PACK_THRESHOLD; BACKLOG 记 V1.6.2 影响; ISSUES 加 I-15~I-17 单测: 769 passed(新增上游真实 select_battle_team 端到端: 不装补丁 TypeError, 装了点一次)。 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -3,8 +3,10 @@
|
|||||||
|
|
||||||
2026-11-16 实测: 游戏窗口被最小化/关掉后, AALC 每帧在 cv2.matchTemplate 上抛
|
2026-11-16 实测: 游戏窗口被最小化/关掉后, AALC 每帧在 cv2.matchTemplate 上抛
|
||||||
「corr.rows <= img.rows + templ.rows - 1」断言, 只记 ERROR 继续跑, 第 2 局空转 4.5 小时。
|
「corr.rows <= img.rows + templ.rows - 1」断言, 只记 ERROR 继续跑, 第 2 局空转 4.5 小时。
|
||||||
|
2026-11-22 复查: 只在任务主线程里中止(retry_monitor 线程里抛只会打死那条线程); 要连续出错持续一段时间才算。
|
||||||
"""
|
"""
|
||||||
import sys
|
import sys
|
||||||
|
import threading
|
||||||
import types
|
import types
|
||||||
import unittest
|
import unittest
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
@@ -31,7 +33,7 @@ class FakeImageUtils:
|
|||||||
|
|
||||||
class ImageErrorGuardTest(unittest.TestCase):
|
class ImageErrorGuardTest(unittest.TestCase):
|
||||||
|
|
||||||
def install(self, fake, clock=None, window=120, limit=3):
|
def install(self, fake, clock=None, span=30, limit=3):
|
||||||
self.lines = []
|
self.lines = []
|
||||||
module = types.ModuleType('utils.image_utils')
|
module = types.ModuleType('utils.image_utils')
|
||||||
module.ImageUtils = fake
|
module.ImageUtils = fake
|
||||||
@@ -39,36 +41,66 @@ class ImageErrorGuardTest(unittest.TestCase):
|
|||||||
'utils.image_utils': module}):
|
'utils.image_utils': module}):
|
||||||
self.assertIsNotNone(ap.install_image_error_guard(
|
self.assertIsNotNone(ap.install_image_error_guard(
|
||||||
log=self.lines.append, clock=clock or (lambda: self.now[0]),
|
log=self.lines.append, clock=clock or (lambda: self.now[0]),
|
||||||
window=window, limit=limit))
|
span=span, limit=limit))
|
||||||
|
self.lines.clear() # 安装时那行 "patch: …" 不算
|
||||||
return fake
|
return fake
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.now = [0.0]
|
self.now = [0.0]
|
||||||
|
|
||||||
|
def fail_frames(self, fake, times, step):
|
||||||
|
for _ in range(times):
|
||||||
|
self.now[0] += step
|
||||||
|
fake.match_template(None, None, None)
|
||||||
|
|
||||||
def test_ok_results_never_abort(self):
|
def test_ok_results_never_abort(self):
|
||||||
fake = self.install(FakeImageUtils([((5, 5), 0.9)] * 10))
|
fake = self.install(FakeImageUtils([((5, 5), 0.9)] * 10))
|
||||||
for _ in range(10):
|
for _ in range(10):
|
||||||
self.now[0] += 0.1
|
self.now[0] += 0.1
|
||||||
self.assertEqual(fake.match_template(None, None, 0.8), ((5, 5), 0.9))
|
self.assertEqual(fake.match_template(None, None, None), ((5, 5), 0.9))
|
||||||
|
|
||||||
def test_sparse_failures_do_not_abort(self):
|
def test_short_burst_does_not_abort(self):
|
||||||
fake = self.install(FakeImageUtils([None, None] + [((1, 1), 0.9)] * 5))
|
# 68 次/秒的坏帧只持续 1 秒(重启游戏/切分辨率一闪而过): 原来 0.3 秒就停掉整个任务
|
||||||
self.lines.clear() # 安装时那行 "patch: 截图连续识别失败…" 不算
|
fake = self.install(FakeImageUtils([None] * 68), limit=20)
|
||||||
fake.match_template(None, None, 0.8)
|
self.fail_frames(fake, 68, 1 / 68)
|
||||||
fake.match_template(None, None, 0.8)
|
self.assertEqual(self.lines, [])
|
||||||
self.now[0] += 200 # 窗口滑过去
|
|
||||||
fake.match_template(None, None, 0.8)
|
|
||||||
self.assertEqual(len(self.lines), 0)
|
|
||||||
|
|
||||||
def test_storm_aborts_with_clear_message(self):
|
def test_a_success_resets_the_streak(self):
|
||||||
fake = self.install(FakeImageUtils([None] * 10), limit=3)
|
fake = self.install(FakeImageUtils([None] * 5 + [((1, 1), 0.9)] + [None] * 5), span=30, limit=3)
|
||||||
|
self.fail_frames(fake, 5, 5) # 25 秒的连续失败
|
||||||
|
self.now[0] += 1
|
||||||
|
fake.match_template(None, None, None) # 成功一次
|
||||||
|
self.fail_frames(fake, 5, 5) # 又 25 秒: 每段都不到 30 秒
|
||||||
|
self.assertEqual(self.lines, [])
|
||||||
|
|
||||||
|
def test_sustained_failure_aborts_with_clear_message(self):
|
||||||
|
fake = self.install(FakeImageUtils([None] * 100), span=30, limit=20)
|
||||||
with mock.patch.object(ap.decisions, 'record') as record:
|
with mock.patch.object(ap.decisions, 'record') as record:
|
||||||
with self.assertRaises(ap.TaskAbort):
|
with self.assertRaises(ap.TaskAbort) as caught:
|
||||||
for _ in range(3):
|
self.fail_frames(fake, 100, 1)
|
||||||
self.now[0] += 0.05
|
self.assertEqual(fake.calls, 31) # 第 1 次起算, 持续满 30 秒那一次就停
|
||||||
fake.match_template(None, None, 0.8)
|
self.assertIn('截图连续识别失败(31 次/30 秒)', str(caught.exception))
|
||||||
self.assertIn('截图连续识别失败', '\n'.join(self.lines))
|
self.assertIn('[ERROR]', '\n'.join(self.lines))
|
||||||
record.assert_called_once()
|
record.assert_called_once_with('image_error', None, 'abort', count=31, seconds=30)
|
||||||
|
|
||||||
|
def test_other_threads_never_abort_and_never_count(self):
|
||||||
|
# retry_monitor 线程也调 match_template; 在那条线程里抛只会打死它, 任务照跑
|
||||||
|
fake = self.install(FakeImageUtils([None] * 200), span=1, limit=3)
|
||||||
|
errors = []
|
||||||
|
|
||||||
|
def monitor():
|
||||||
|
try:
|
||||||
|
self.fail_frames(fake, 50, 1)
|
||||||
|
except BaseException as e: # noqa: B902 - 要看 TaskAbort 是否漏到这条线程
|
||||||
|
errors.append(e)
|
||||||
|
|
||||||
|
worker = threading.Thread(target=monitor)
|
||||||
|
worker.start()
|
||||||
|
worker.join()
|
||||||
|
self.assertEqual(errors, [])
|
||||||
|
self.assertEqual(self.lines, [])
|
||||||
|
with self.assertRaises(ap.TaskAbort), mock.patch.object(ap.decisions, 'record'):
|
||||||
|
self.fail_frames(fake, 3, 1) # 主线程自己的计数从 0 开始: 第 3 次、持续 2 秒才停
|
||||||
|
|
||||||
def test_abort_is_not_a_normal_exception(self):
|
def test_abort_is_not_a_normal_exception(self):
|
||||||
# AALC 的 onetime_mir_process 会吞 Exception 再开一局, 熔断必须穿透
|
# AALC 的 onetime_mir_process 会吞 Exception 再开一局, 熔断必须穿透
|
||||||
|
|||||||
Reference in New Issue
Block a user