Files
lc-mcp/tests/test_preset_formation.py
T
ywsandClaude Opus 5.5 337f433930 罪人编队沿用游戏编队预设, 不再清空后按 1~12 全选(R-09)
- 用户「选角色哪里不能根据角色进行选择吗,而是按顺序全选,或者用选好的配对」。
  上游每局第一场战斗前先「清除选择」再按 sinner_order 点人; 本机是默认 1~12, 11-18 16:21 日志:
  清除确认框 0.896(原来选好了人) + 12 次按座位点击, 覆盖了游戏里流血/震颤等编队预设的出战人员和顺序。
- install_preset_formation: 镜牢 team_formation 默认不清不点, 直接用预设(formation/kept);
  游戏弹「没有选罪人」(none_sinner)时这一局改回上游按顺序选(formation/preset_empty), 下一局重新用预设。
  LCP_SINNER_FORMATION=aalc 还原上游。
- tests: test_preset_formation 8 例(含上游源码契约); ISSUES 记 R-09。

单测: 803 passed。

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 09:15:13 +00:00

111 lines
5.1 KiB
Python

# -*- coding: utf-8 -*-
"""镜牢罪人编队沿用游戏编队预设。
2026-11-22 用户「选角色哪里不能根据角色进行选择吗,而是按顺序全选,或者用选好的配对」:
上游每局先「清除选择」再按 sinner_order(本机默认 1~12)把 12 人按座位顺序全点一遍, 覆盖了游戏编队的预设。
"""
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
MIRROR = REPO / 'vendor' / 'aalc' / 'tasks' / 'mirror' / 'mirror.py'
class PresetFormationTest(unittest.TestCase):
def setUp(self):
self.lines = []
self.formed = []
self.popup = False # 游戏是否弹「没有选罪人」
self.mirror = types.ModuleType('tasks.mirror.mirror')
self.mirror.team_formation = lambda sinner_team: self.formed.append(list(sinner_team))
self.mirror.Mirror = type('Mirror', (), {'__init__': lambda self, *a: setattr(self, 'ready', True)})
self.auto = SimpleNamespace(click_element=lambda target, *a, **k: self.popup and target == ap.NONE_SINNER)
def install(self, env=None):
automation = types.ModuleType('module.automation')
automation.auto = self.auto
package = types.ModuleType('tasks.mirror')
package.mirror = self.mirror
modules = {'module': types.ModuleType('module'), 'module.automation': automation,
'tasks': types.ModuleType('tasks'), 'tasks.mirror': package, 'tasks.mirror.mirror': self.mirror}
with mock.patch.dict(sys.modules, modules):
return ap.install_preset_formation(log=self.lines.append, env=env or {})
@property
def log(self):
return '\n'.join(self.lines)
def test_keeps_the_game_preset_instead_of_clicking_everyone(self):
self.assertIsNotNone(self.install())
self.mirror.Mirror()
with mock.patch.object(ap.decisions, 'record') as record:
self.assertIsNone(self.mirror.team_formation(list(range(1, 13))))
self.assertEqual(self.formed, [])
record.assert_called_once_with('formation', 'preset', 'kept')
self.assertIn('patch: 罪人编队沿用游戏编队预设', self.log)
self.assertIn('沿用游戏编队预设, 不清空、不按 sinner_order 重选', self.log)
def test_empty_preset_falls_back_to_aalc_order_for_the_rest_of_the_run(self):
self.install()
self.mirror.Mirror()
self.mirror.team_formation([1, 2, 3]) # 第一次: 用预设
self.popup = True
with mock.patch.object(ap.decisions, 'record') as record:
self.assertTrue(self.auto.click_element(ap.NONE_SINNER, model='clam')) # 上游点掉提示, first_battle 置回
self.auto.click_element(ap.NONE_SINNER) # 同一局再弹也只记一次
record.assert_called_once_with('formation', 'aalc_order', 'preset_empty')
self.mirror.team_formation([1, 2, 3]) # 上游重新编队: 这次按 sinner_order 选
self.assertEqual(self.formed, [[1, 2, 3]])
self.assertIn('编队预设是空的, 这一局改回 AALC 按顺序选', self.log)
def test_next_run_trusts_the_preset_again(self):
self.install()
self.mirror.Mirror()
self.popup = True
self.auto.click_element(ap.NONE_SINNER)
self.mirror.Mirror() # 新的一局
self.mirror.team_formation([1, 2])
self.assertEqual(self.formed, [])
def test_other_clicks_pass_through(self):
self.install()
self.mirror.Mirror()
self.assertFalse(self.auto.click_element('teams/identify_assets.png'))
self.mirror.team_formation([1])
self.assertEqual(self.formed, [])
def test_env_aalc_keeps_upstream(self):
inner = self.mirror.team_formation
self.assertIsNone(self.install({ap.SINNER_FORMATION_ENV: 'aalc'}))
self.assertIs(self.mirror.team_formation, inner)
self.assertIn('罪人编队按 AALC 的 sinner_order 重选', self.log)
def test_unknown_env_value_means_preset(self):
self.assertIsNotNone(self.install({ap.SINNER_FORMATION_ENV: 'whatever'}))
self.assertIn("LCP_SINNER_FORMATION='whatever' 不认识", self.log)
def test_skips_without_aalc(self):
with mock.patch.dict(sys.modules, {'tasks': None}):
self.assertIsNone(ap.install_preset_formation(log=self.lines.append, env={}))
self.assertIn('编队预设补丁跳过', self.log)
@unittest.skipUnless(MIRROR.is_file(), 'vendor/aalc 子模块未检出')
def test_upstream_contract(self):
# 补丁依赖: mirror 模块按模块全局名调 team_formation; 「没有选罪人」点掉后把 first_battle 置回重新编队
source = MIRROR.read_text(encoding='utf-8')
self.assertIn('from tasks.teams.team_formation import', source)
self.assertIn('team_formation(self.sinner_team)', source)
self.assertRegex(source, r'click_element\("teams/none_sinner_assets\.png"[^\n]*\):\n\s+self\.first_battle = True')
if __name__ == '__main__':
unittest.main()