Files
lc-mcp/tests/test_system_team_selection.py
T
Codex Agent c4a42bcfaf 镜牢选队改为按体系名点选;补交接文档、待开发计划与单测
本机账号的编队按体系命名(流血/斩击/突刺/…),AALC 只认 编队#N,导致镜牢永远
报「无法寻得队伍」。新增 install_system_team_selection:按 team_system 映射的
中文队名在列表里精确匹配并点选,点完用顶栏队名确认;失败显式返回 False,
不静默回退到编号(该账号没有 编队#1~#12)。

- lc_mcp/aalc_patches.py: 新增选队补丁与区域/OCR 辅助
- lc_mcp/aalc_task.py: mirror/all 任务挂载该补丁
- tests/test_system_team_selection.py: 15 个用例,不依赖 AALC/Windows
- docs/feedback/2026-11-14/: 实测记录 + 云端开发交接文件(含体系队名表)
- docs/BACKLOG.md: 待开发计划(商店清单路径 bug、走位降级、三选一按体系等)

单测:460 passed。
2026-11-14 10:22:35 +08:00

169 lines
6.5 KiB
Python

import os
import sys
import types
import unittest
from unittest import mock
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from lc_mcp import aalc_patches # noqa: E402
class SystemTeamNamesTest(unittest.TestCase):
def test_all_ten_systems_are_mapped(self):
expected = {'burn', 'bleed', 'tremor', 'rupture', 'poise',
'sinking', 'charge', 'slash', 'pierce', 'blunt'}
self.assertEqual(set(aalc_patches.SYSTEM_TEAM_NAMES), expected)
def test_names_are_non_empty_strings(self):
for system, names in aalc_patches.SYSTEM_TEAM_NAMES.items():
self.assertIsInstance(names, tuple, system)
self.assertTrue(names, system)
for name in names:
self.assertIsInstance(name, str)
self.assertTrue(name.strip(), system)
def test_poise_accepts_both_spellings(self):
# 游戏里叫「呼吸法」, system_cn_zh 里叫「呼吸」, 两个都要能命中
self.assertIn('呼吸法', aalc_patches.SYSTEM_TEAM_NAMES['poise'])
self.assertIn('呼吸', aalc_patches.SYSTEM_TEAM_NAMES['poise'])
class RegionTest(unittest.TestCase):
def test_team_list_region(self):
self.assertTrue(aalc_patches._in_list(130, 493)) # 实测「流血」的位置
self.assertTrue(aalc_patches._in_list(255, 305))
self.assertFalse(aalc_patches._in_list(130, 120)) # 顶栏不算列表
self.assertFalse(aalc_patches._in_list(600, 493)) # 右侧面板
self.assertFalse(aalc_patches._in_list(130, 700))
def test_header_region(self):
self.assertTrue(aalc_patches._in_header(242, 125)) # 实测顶栏「流血」
self.assertFalse(aalc_patches._in_header(130, 493))
self.assertFalse(aalc_patches._in_header(900, 125))
def test_regions_do_not_overlap(self):
for x, y in [(130, 493), (242, 125), (600, 300), (1200, 600)]:
self.assertFalse(
aalc_patches._in_list(x, y) and aalc_patches._in_header(x, y),
(x, y),
)
class TeamOcrTest(unittest.TestCase):
def test_returns_list_and_strips_spaces(self):
auto = mock.Mock()
auto._run_ocr_for_text.return_value = {
'编队#20': [132.0, 340.5],
' 流血 ': [130.5, 493.0],
'': [0, 0],
}
items = aalc_patches._team_ocr(auto)
self.assertIn(('编队#20', 132.0, 340.5), items)
self.assertIn(('流血', 130.5, 493.0), items)
self.assertEqual(len(items), 2) # 空串被丢掉
def test_empty_ocr_gives_empty_list(self):
auto = mock.Mock()
auto._run_ocr_for_text.return_value = {}
self.assertEqual(aalc_patches._team_ocr(auto), [])
def test_bad_position_is_skipped_not_fatal(self):
auto = mock.Mock()
auto._run_ocr_for_text.return_value = {'流血': [], '斩击': [1.0, 2.0]}
self.assertEqual(aalc_patches._team_ocr(auto), [('斩击', 1.0, 2.0)])
class _FakeMirror:
def __init__(self, team_setting, team_num):
self.system = team_setting['system']
self.team_number = team_num
class InstallSystemTeamSelectionTest(unittest.TestCase):
"""用假模块验证挂载点与回退行为, 不依赖 AALC / Windows。"""
def setUp(self):
self.calls = []
def original(num):
self.calls.append(num)
return 'fallback'
self.original = original
self.mirror_mod = types.ModuleType('tasks.mirror.mirror')
self.mirror_mod.Mirror = _FakeMirror
self.mirror_mod.select_battle_team = original
self.auto = mock.Mock()
auto_mod = types.ModuleType('module.automation')
auto_mod.auto = self.auto
tasks_pkg = types.ModuleType('tasks')
tasks_pkg.__path__ = []
mirror_pkg = types.ModuleType('tasks.mirror')
mirror_pkg.__path__ = []
mirror_pkg.mirror = self.mirror_mod
module_pkg = types.ModuleType('module')
module_pkg.__path__ = []
self._patcher = mock.patch.dict(sys.modules, {
'tasks': tasks_pkg,
'tasks.mirror': mirror_pkg,
'tasks.mirror.mirror': self.mirror_mod,
'module': module_pkg,
'module.automation': auto_mod,
})
self._patcher.start()
self.addCleanup(self._patcher.stop)
def install(self):
return aalc_patches.install_system_team_selection(log=lambda *_: None)
def test_returns_original_and_replaces_module_global(self):
original = self.install()
self.assertIs(original, self.original)
self.assertIsNot(self.mirror_mod.select_battle_team, self.original)
# __init__ 也被包装, 但仍然正常构造
mirror = self.mirror_mod.Mirror({'system': 'bleed'}, 1)
self.assertEqual(mirror.system, 'bleed')
def test_known_system_uses_name_search(self):
self.install()
self.mirror_mod.Mirror({'system': 'bleed'}, 1)
with mock.patch.object(aalc_patches, '_select_team_by_name', return_value=True) as sel:
self.assertIs(self.mirror_mod.select_battle_team(1), True)
self.assertEqual(sel.call_args[0][1], ('流血',))
self.assertEqual(self.calls, []) # 成功后不再走编号回退
def test_name_search_failure_does_not_fall_back_to_number(self):
# 这号没有 编队#1, 静默回退到编号会选中错的队, 必须显式失败
self.install()
self.mirror_mod.Mirror({'system': 'bleed'}, 1)
with mock.patch.object(aalc_patches, '_select_team_by_name', return_value=False):
self.assertIs(self.mirror_mod.select_battle_team(1), False)
self.assertEqual(self.calls, [])
def test_exception_in_name_search_is_contained(self):
self.install()
self.mirror_mod.Mirror({'system': 'bleed'}, 1)
boom = mock.Mock(side_effect=RuntimeError('ocr down'))
with mock.patch.object(aalc_patches, '_select_team_by_name', boom):
self.assertIs(self.mirror_mod.select_battle_team(1), False)
def test_unknown_system_falls_back_to_original(self):
self.install()
self.mirror_mod.Mirror({'system': 'unknown_system'}, 3)
self.assertEqual(self.mirror_mod.select_battle_team(3), 'fallback')
self.assertEqual(self.calls, [3])
def test_missing_mirror_module_is_not_fatal(self):
with mock.patch.dict(sys.modules, {'tasks.mirror': None, 'tasks.mirror.mirror': None}):
self.assertIsNone(self.install())
if __name__ == '__main__':
unittest.main()