复查 V1.6.2 与 11-16~11-22 补丁: 返回按钮 TypeError、事件兜底连点、截图熔断线程

Browse Source
- 返回按钮(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:
yws
2026-11-22 01:17:07 +00:00
co-authored by Claude Opus 5.5
parent 3982d485c4
commit 885412f0e0
11 changed files with 538 additions and 93 deletions
+155
View File
@@ -0,0 +1,155 @@
# -*- coding: utf-8 -*-
"""返回按钮: 上游 V1.6.2 拿 click_element 的返回值当坐标(c9a884a)。
if back_button := auto.click_element("home/back_assets.png", model="normal"):
auto.mouse_click(back_button[0], back_button[1])
click_element 点完返回 True, 下一行 True[0] → TypeError。画面上出现首次引导
(home/first_prompt_assets.png)时必走这里。端到端用例执行上游真实的 select_battle_team。
"""
import ast
import sys
import types
import unittest
from pathlib import Path
from types import SimpleNamespace
from unittest import mock
REPO = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(REPO))
from lc_mcp import aalc_patches as ap # noqa: E402
AALC = REPO / 'vendor' / 'aalc'
MIRROR = AALC / 'tasks' / 'mirror' / 'mirror.py'
TEAM = AALC / 'tasks' / 'teams' / 'team_formation.py'
BACK, BACK2 = ap.BACK_BUTTONS
BACK_POS = (60, 35)
def upstream_function(path, name, cls=None, **ns):
"""把上游某个函数原样编译出来(去掉装饰器), 行号和文件名不变, inspect / linecache 都认。"""
tree = ast.parse(path.read_text(encoding='utf-8'))
body = tree.body
if cls:
body = next(n for n in body if isinstance(n, ast.ClassDef) and n.name == cls).body
node = next(n for n in body if isinstance(n, ast.FunctionDef) and n.name == name)
node.decorator_list = []
exec(compile(ast.Module(body=[node], type_ignores=[]), str(path), 'exec'), ns)
return ns[name]
class FirstPromptScreen:
"""首次引导页: 左上角有返回按钮(back 或 back2), 点一次就退出引导。
click_element 按上游 Automation 的语义: 点了返回 True, click=False 时只返回坐标。
"""
def __init__(self, button=BACK):
self.button = button
self.prompt = True
self.clicks = []
def take_screenshot(self, *args, **kwargs):
return object()
def find_element(self, target, *args, **kwargs):
if target == 'home/first_prompt_assets.png':
return self.prompt
return None
def click_element(self, target, *args, click=True, **kwargs):
if not (self.prompt and target == self.button):
return False
if not click:
return BACK_POS
self.mouse_click(*BACK_POS)
return True
def mouse_click(self, x, y, *args, **kwargs):
self.clicks.append((x, y))
self.prompt = False
def fake_modules(auto, select_battle_team=None, mirror_methods=None):
mirror_mod = types.ModuleType('tasks.mirror.mirror')
mirror_mod.Mirror = type('Mirror', (), dict(mirror_methods or {}))
team_mod = types.ModuleType('tasks.teams.team_formation')
team_mod.select_battle_team = select_battle_team or (lambda num: True)
mirror_pkg, teams_pkg = types.ModuleType('tasks.mirror'), types.ModuleType('tasks.teams')
mirror_pkg.mirror, teams_pkg.team_formation = mirror_mod, team_mod
return {'tasks': types.ModuleType('tasks'), 'tasks.mirror': mirror_pkg, 'tasks.mirror.mirror': mirror_mod,
'tasks.teams': teams_pkg, 'tasks.teams.team_formation': team_mod,
'module': types.ModuleType('module'), 'module.automation': SimpleNamespace(auto=auto)}
@unittest.skipUnless(MIRROR.is_file() and TEAM.is_file(), 'vendor/aalc 子模块未检出')
class UpstreamSelectBattleTeamTest(unittest.TestCase):
"""执行上游真实的 select_battle_team: 先处理首次引导, 之后找不到编队页就返回。"""
def play(self, screen, patched=True):
self.lines = []
ns = dict(auto=screen, cfg=SimpleNamespace(set_win_size=720), log=mock.Mock(), sleep=lambda *a: None)
select = upstream_function(TEAM, 'select_battle_team', **ns)
if patched:
with mock.patch.dict(sys.modules, fake_modules(screen, select)):
self.assertIsNotNone(ap.install_back_button_result(log=self.lines.append))
return select(1)
def test_upstream_v162_crashes_on_the_first_prompt(self):
with self.assertRaisesRegex(TypeError, "'bool' object is not subscriptable"):
self.play(FirstPromptScreen(), patched=False)
def test_back_button_is_clicked_exactly_once(self):
screen = FirstPromptScreen()
self.play(screen)
self.assertEqual(screen.clicks, [BACK_POS])
self.assertIn('返回按钮: 上游要拿坐标自己点, 这次只找不点', '\n'.join(self.lines))
def test_second_back_template_is_also_handled(self):
screen = FirstPromptScreen(button=BACK2)
self.play(screen)
self.assertEqual(screen.clicks, [BACK_POS])
def test_callers_that_only_test_truthiness_still_get_a_click(self):
# back_init_menu: if auto.click_element("home/back_assets.png") or ...: continue
screen = FirstPromptScreen()
self.play(screen, patched=True) # 引导已被 select_battle_team 点掉
screen.prompt = True
screen.clicks.clear()
self.assertIs(screen.click_element(BACK), True)
self.assertEqual(screen.clicks, [BACK_POS])
def test_other_targets_and_explicit_click_argument_untouched(self):
screen = FirstPromptScreen()
self.play(screen)
screen.prompt = True
self.assertEqual(screen.click_element(BACK, click=False), BACK_POS)
self.assertIs(screen.click_element('home/other.png'), False)
@unittest.skipUnless(MIRROR.is_file() and TEAM.is_file(), 'vendor/aalc 子模块未检出')
class InstallBackButtonResultTest(unittest.TestCase):
def install(self, **kwargs):
self.lines = []
auto = FirstPromptScreen()
with mock.patch.dict(sys.modules, fake_modules(auto, **kwargs)):
return ap.install_back_button_result(log=self.lines.append)
def test_finds_all_three_upstream_call_sites(self):
methods = {name: upstream_function(MIRROR, name, cls='Mirror') for name in ('road_to_mir', 'run')}
select = upstream_function(TEAM, 'select_battle_team')
self.assertIsNotNone(self.install(select_battle_team=select, mirror_methods=methods))
self.assertIn('patch: 返回按钮按坐标交给上游点一次(Mirror.road_to_mir/Mirror.run/select_battle_team)',
'\n'.join(self.lines))
def test_not_installed_once_upstream_stops_using_the_result(self):
def select_battle_team(num):
if auto.click_element("home/back_assets.png", model="normal"): # noqa: F821
return False
self.assertIsNone(self.install(select_battle_team=select_battle_team))
self.assertIn('返回按钮补丁不装', '\n'.join(self.lines))
if __name__ == '__main__':
unittest.main()
+74 -3
View File
@@ -73,6 +73,17 @@ class EventOptionsTest(unittest.TestCase):
options = ap.event_options(markers(1), [('继续', 900, 200 + 31)], SCALE) options = ap.event_options(markers(1), [('继续', 900, 200 + 31)], SCALE)
self.assertEqual(options[0][1], '') self.assertEqual(options[0][1], '')
def test_click_point_is_the_longest_line_of_that_option(self):
lines = [('离开', 900, 200), ('不听故事', 900, 255), ('就这样离开', 1000, 265)]
rows = ap.option_rows(markers(2), lines, SCALE)
# 第 2 项「不听故事就这样离开」: 不会因为「离开」是它的子串去点第 1 项
self.assertEqual(ap.option_click_pos(*rows[1]), (1000.0, 265.0))
self.assertEqual(ap.option_click_pos(*rows[0]), (900.0, 200.0))
def test_click_point_falls_back_to_the_marker(self):
rows = ap.option_rows(markers(1), [], SCALE)
self.assertEqual(ap.option_click_pos(*rows[0]), (float(MARKER_X), 200.0))
class ChooseEventOptionTest(unittest.TestCase): class ChooseEventOptionTest(unittest.TestCase):
@@ -197,7 +208,7 @@ class EventScreen:
def run(self, image): def run(self, image):
self.ocr_runs += 1 self.ocr_runs += 1
lines = [('事件叙述文字', 200, 60)] lines = [('事件叙述文字', 200, 60)] + list(getattr(self, 'narration', ()))
for (x, y), text in zip(markers(len(self.options or ())), self.options or ()): for (x, y), text in zip(markers(len(self.options or ())), self.options or ()):
lines.append((text, x + 200, y)) lines.append((text, x + 200, y))
return SimpleNamespace(txts=tuple(t for t, _, _ in lines), return SimpleNamespace(txts=tuple(t for t, _, _ in lines),
@@ -205,6 +216,36 @@ class EventScreen:
for _, x, y in lines]) for _, x, y in lines])
class StickyEventScreen(EventScreen):
"""点了选项后选项框还留在画面上, 要上游点「继续」才进下一屏(实机表外事件就是这样)。"""
def __init__(self, screens):
super().__init__(screens)
self.picked = False
self.continues = 0
self.clicks = 0
def mouse_click(self, x, y, *args, **kwargs):
if not self.options:
return
self.clicks += 1
if self.clicks > 50:
raise RuntimeError('同一屏点了 50 次还没走完事件')
if not self.picked:
rows = markers(len(self.options))
above = [i for i, (_, my) in enumerate(rows) if my <= y]
self.chosen.append(max(above) if above else 0)
self.picked = True
def click_element(self, target, **kwargs):
if target == 'event/continue_assets.png' and self.options and self.picked:
self.continues += 1
self.picked = False
self.stage += 1
return True
return super().click_element(target, **kwargs)
@unittest.skipUnless(MIRROR.is_file() and EVENT.is_file(), 'vendor/aalc 子模块未检出') @unittest.skipUnless(MIRROR.is_file() and EVENT.is_file(), 'vendor/aalc 子模块未检出')
class UpstreamEventHandlingTest(unittest.TestCase): class UpstreamEventHandlingTest(unittest.TestCase):
"""执行上游真实的 Mirror.event_handling, 看每屏点了第几项。""" """执行上游真实的 Mirror.event_handling, 看每屏点了第几项。"""
@@ -214,8 +255,9 @@ class UpstreamEventHandlingTest(unittest.TestCase):
self.fn_node = upstream_function(MIRROR, 'event_handling', cls='Mirror') self.fn_node = upstream_function(MIRROR, 'event_handling', cls='Mirror')
self.avoid_node = upstream_function(EVENT, 'click_option_avoiding_unknown', cls='EventHandling') self.avoid_node = upstream_function(EVENT, 'click_option_avoiding_unknown', cls='EventHandling')
def play(self, screens, patched=True, env=None, unknown=None, solo=False, ignore_clicks=0): def play(self, screens, patched=True, env=None, unknown=None, solo=False, ignore_clicks=0, screen=None):
screen = EventScreen(screens, unknown=unknown, ignore_clicks=ignore_clicks) if screen is None:
screen = EventScreen(screens, unknown=unknown, ignore_clicks=ignore_clicks)
cfg = SimpleNamespace(set_win_size=720) cfg = SimpleNamespace(set_win_size=720)
avoid_ns = dict(auto=screen, log=mock.Mock()) avoid_ns = dict(auto=screen, log=mock.Mock())
exec(compile(ast.Module(body=[self.avoid_node], type_ignores=[]), str(EVENT), 'exec'), avoid_ns) exec(compile(ast.Module(body=[self.avoid_node], type_ignores=[]), str(EVENT), 'exec'), avoid_ns)
@@ -309,6 +351,35 @@ class UpstreamEventHandlingTest(unittest.TestCase):
def test_env_zero_keeps_upstream(self): def test_env_zero_keeps_upstream(self):
self.assertIsNone(ap.install_event_choices(log=self.lines.append, env={ap.EVENT_CHOICES_ENV: '0'})) self.assertIsNone(ap.install_event_choices(log=self.lines.append, env={ap.EVENT_CHOICES_ENV: '0'}))
# ---- LCP_EVENT_FALLBACK=1: 表外事件先点第 1 项 ----
FALLBACK = {ap.EVENT_FALLBACK_ENV: '1'}
def test_fallback_clicks_first_option_once_then_lets_upstream_continue(self):
# 11-18~11-21 实机: 点完第 1 项选项框还在, 补丁每轮抢先再点, 上游走不到「继续」(同屏连点 10~110 次)
screen = StickyEventScreen([['战斗', '离开']])
with mock.patch.object(ap.decisions, 'record') as record:
self.assertEqual(self.play(None, env=self.FALLBACK, screen=screen), [0])
self.assertEqual(screen.continues, 1)
self.assertEqual(record.call_args_list, [mock.call('event', 1, 'fallback_first', options=['战斗', '离开'])])
self.assertEqual(self.log.count('兜底点第 1 项'), 1)
def test_fallback_handles_each_new_screen_once(self):
screen = StickyEventScreen([['战斗', '离开'], ['好', '不好']])
self.assertEqual(self.play(None, env=self.FALLBACK, screen=screen), [0, 0])
self.assertEqual(screen.continues, 2)
def test_fallback_still_upstream_without_env(self):
screen = StickyEventScreen([['战斗', '离开']])
self.play(None, screen=screen)
self.assertNotIn('兜底点第 1 项', self.log)
self.assertIn('表里没有这个事件, 交给 AALC', self.log)
def test_click_lands_on_the_option_row_not_on_matching_narration(self):
# 叙述里正好有「特别的」: 原来整屏找子串, 会点到叙述那一行(第 1 项上方)
screen = EventScreen([SHEEP])
screen.narration = [('特别的', 200, 60)]
self.assertEqual(self.play(None, screen=screen), [1])
class InstallEventChoicesTest(unittest.TestCase): class InstallEventChoicesTest(unittest.TestCase):
+51 -19
View File
@@ -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 再开一局, 熔断必须穿透
+13 -4
View File
@@ -20,17 +20,24 @@ class RefreshTextPosTest(unittest.TestCase):
auto = mock.Mock() auto = mock.Mock()
with mock.patch.object(ap, '_ocr_lines', return_value=[ with mock.patch.object(ap, '_ocr_lines', return_value=[
('商店', 600, 30), ('刷新', 1000, 45), ('关键词刷新', 300, 40)]): ('商店', 600, 30), ('刷新', 1000, 45), ('关键词刷新', 300, 40)]):
self.assertEqual(ap._refresh_text_pos(auto), (1000, 45)) self.assertEqual(ap._refresh_text_pos(auto, 720 / 1440), (1000, 45))
def test_ignores_shop_refresh_on_the_left(self): def test_ignores_shop_refresh_on_the_left(self):
auto = mock.Mock() auto = mock.Mock()
with mock.patch.object(ap, '_ocr_lines', return_value=[('关键词刷新', 300, 40)]): with mock.patch.object(ap, '_ocr_lines', return_value=[('关键词刷新', 300, 40)]):
self.assertIsNone(ap._refresh_text_pos(auto)) self.assertIsNone(ap._refresh_text_pos(auto, 720 / 1440))
def test_ignores_text_below_the_header(self): def test_ignores_text_below_the_header(self):
auto = mock.Mock() auto = mock.Mock()
with mock.patch.object(ap, '_ocr_lines', return_value=[('刷新', 1000, 400)]): with mock.patch.object(ap, '_ocr_lines', return_value=[('刷新', 1000, 400)]):
self.assertIsNone(ap._refresh_text_pos(auto)) self.assertIsNone(ap._refresh_text_pos(auto, 720 / 1440))
def test_box_scales_with_window_size(self):
# 1080 窗口: 右上角范围按 set_win_size / 1440 放大, 同一个按钮在 (1500, 70)
auto = mock.Mock()
with mock.patch.object(ap, '_ocr_lines', return_value=[('刷新', 1500, 70)]):
self.assertIsNone(ap._refresh_text_pos(auto, 720 / 1440))
self.assertEqual(ap._refresh_text_pos(auto, 1080 / 1440), (1500, 70))
class RefreshClickTest(unittest.TestCase): class RefreshClickTest(unittest.TestCase):
@@ -38,8 +45,10 @@ class RefreshClickTest(unittest.TestCase):
def install(self, auto): def install(self, auto):
module = types.ModuleType('module.automation') module = types.ModuleType('module.automation')
module.auto = auto module.auto = auto
config = types.ModuleType('module.config')
config.cfg = types.SimpleNamespace(set_win_size=720)
with mock.patch.dict(sys.modules, {'module': types.ModuleType('module'), with mock.patch.dict(sys.modules, {'module': types.ModuleType('module'),
'module.automation': module}): 'module.automation': module, 'module.config': config}):
return ap.install_theme_pack_refresh_click(log=lambda *_: None) return ap.install_theme_pack_refresh_click(log=lambda *_: None)
def test_clicks_ocr_position_instead_of_template(self): def test_clicks_ocr_position_instead_of_template(self):
+18 -1
View File
@@ -242,6 +242,7 @@ class UpstreamSelectThemePackTest(unittest.TestCase):
positions = [(300 + 300 * i, 300) for i in range(len(cards))] positions = [(300 + 300 * i, 300) for i in range(len(cards))]
weights = example_weights('theme_pack_list_cn', *(('theme_pack_list_hard_cn',) if hard else ())) weights = example_weights('theme_pack_list_cn', *(('theme_pack_list_hard_cn',) if hard else ()))
lookups = [] lookups = []
self.refreshes = refreshes = []
def find_language_text(zh, en, crop): def find_language_text(zh, en, crop):
# AALC: 按表的顺序, 第一个(去空格、不分大小写)是卡面文字子串的键 # AALC: 按表的顺序, 第一个(去空格、不分大小写)是卡面文字子串的键
@@ -257,7 +258,7 @@ class UpstreamSelectThemePackTest(unittest.TestCase):
model=None, take_screenshot=lambda: object(), mouse_to_blank=lambda *a, **k: None, model=None, take_screenshot=lambda: object(), mouse_to_blank=lambda *a, **k: None,
find_element=lambda target, **kw: list(positions) if 'theme_pack_features' in target else False, find_element=lambda target, **kw: list(positions) if 'theme_pack_features' in target else False,
find_language_text=find_language_text, mouse_drag_down=mock.Mock(), find_language_text=find_language_text, mouse_drag_down=mock.Mock(),
click_element=lambda *a, **k: False) click_element=lambda target, *a, **k: refreshes.append(target) or True if 'refresh' in target else False)
theme_list = SimpleNamespace(preferred_thresholds=0, get_effective_theme_pack_list=lambda *a: dict(weights)) theme_list = SimpleNamespace(preferred_thresholds=0, get_effective_theme_pack_list=lambda *a: dict(weights))
ns = dict(auto=auto, TextMatchResult=Match, sleep=lambda *a: None, back_init_menu=mock.Mock(), ns = dict(auto=auto, TextMatchResult=Match, sleep=lambda *a: None, back_init_menu=mock.Mock(),
log=logging.getLogger('AALC'), theme_list=theme_list, log=logging.getLogger('AALC'), theme_list=theme_list,
@@ -340,6 +341,22 @@ class UpstreamSelectThemePackTest(unittest.TestCase):
self.assertEqual(picked, '落泪者们') self.assertEqual(picked, '落泪者们')
self.assertEqual(lookups[0], example_weights('theme_pack_list_cn')) self.assertEqual(lookups[0], example_weights('theme_pack_list_cn'))
def test_zero_point_floor_refreshes_first_by_default(self):
# 用户 11-16「卡包均分低就刷新」: 最高 0 分时先刷新, 上游点满 4 次「刷新」后取最高分
picked, _, _ = self.play(self.FLOOR4, 'unknown_system')
self.assertEqual(picked, '落泪者们')
self.assertEqual(len(self.refreshes), 4)
self.assertIn('卡包优选阈值 0 → 1', self.log)
def test_threshold_env_zero_keeps_upstream_threshold(self):
self.play(self.FLOOR4, 'unknown_system', env={ap.THEME_PACK_THRESHOLD_ENV: '0'})
self.assertEqual(self.refreshes, [])
self.assertNotIn('卡包优选阈值', self.log)
def test_system_pack_is_taken_without_refreshing(self):
self.assertEqual(self.play(self.FLOOR4, 'charge')[0], 'WARP快车谋杀案')
self.assertEqual(self.refreshes, [])
def test_rabbit_hole_route_without_a_system(self): def test_rabbit_hole_route_without_a_system(self):
# 兔子洞编队没有体系; 困难模式 AALC 默认「绝望」「号线」都是 -5, 不加分拿 0 分的落泪者们 # 兔子洞编队没有体系; 困难模式 AALC 默认「绝望」「号线」都是 -5, 不加分拿 0 分的落泪者们
route = ap.load_rabbit_hole()['theme_packs'] route = ap.load_rabbit_hole()['theme_packs']