This website requires JavaScript.
0
Issues
Pull Requests
Milestones
Explore
0
Create…
New Repository
New Migration
New Organization
public
Signed in as
public
Profile
Starred
Subscriptions
Settings
Help
Sign Out
yws
/
lc-mcp
Watch
1
Star
0
Fork
0
Code
Issues
Pull Requests
Actions
Packages
Projects
Releases
Wiki
Activity
Files
lc-mcp
/
tests
/
or
Cancel
Edit File
Preview
Preview Changes
Spaces
Tabs
2
4
8
Wrap
No wrap
# -*- coding: utf-8 -*- """镜牢「兔子洞」速刷: 黑兽 - 卯 魁首 浮士德每回合放 E.G.O「空洞」。 AALC 战斗只会 P+Enter; 补丁接管一回合: P → 长按浮士德打开 E.G.O 列表 → OCR 找「空洞」→ Enter。 每场第一回合长按卡片(超频, 直接打人), 之后单击(弹孔不低于 1 发时游戏改用「填补空洞」)。 长按点(press_at)要在实机上量, 没量时不点任何东西, 照 AALC 原来的 P+Enter 打。 """ import ast import json import os import sys import tempfile 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 from lc_mcp import aalc_task # noqa: E402 BATTLE = REPO / 'vendor' / 'aalc' / 'tasks' / 'battle' / 'battle.py' CONFIG = {'team_names': ('兔子洞',), 'ego_names': ('空洞',), 'press_at': (0.25, 0.8), 'hold_seconds': 1.0} PRESS = (0.25 * 1280, 0.8 * 720) class BattleScreen: """战斗面板: 长按到浮士德(±20 像素)才弹出 E.G.O 列表; 点到或长按可用的「空洞」列表就关。""" def __init__(self, usable=True, popup_text='空洞', press=PRESS): self.usable = usable self.popup_text = popup_text self.press = press self.popup = False self.selected = False self.overclocked = False self.calls = [] @property def screenshot(self): return self def take_screenshot(self): return self def read(self): lines = [('回合 1', 640, 30), ('胜率', 1100, 600)] if self.popup: lines += [(self.popup_text, self.press[0] + 40, self.press[1] - 160), ('表象放射体', self.press[0] + 40, self.press[1] - 220)] return SimpleNamespace(txts=tuple(t for t, _, _ in lines), boxes=[[[x - 10, y - 5], [x + 10, y - 5], [x + 10, y + 5], [x - 10, y + 5]] for _, x, y in lines]) def key_press(self, key): self.calls.append(('key', key)) def on_card(self, x, y): return abs(x - (self.press[0] + 40)) <= 10 and abs(y - (self.press[1] - 160)) <= 10 def mouse_drag(self, x, y, drag_time=0.1, dx=0, dy=0): self.calls.append(('hold', round(x), round(y), drag_time, dx, dy)) if self.popup and self.on_card(x, y): if self.usable: self.popup, self.selected, self.overclocked = False, True, True elif abs(x - self.press[0]) <= 20 and abs(y - self.press[1]) <= 20: self.popup = True def mouse_click(self, x, y, *args, **kwargs): self.calls.append(('click', round(x), round(y))) if self.popup and self.usable and self.on_card(x, y): self.popup, self.selected = False, True def mouse_click_blank(self, *args, **kwargs): self.calls.append(('blank',)) self.popup = False class RabbitHoleTurnTest(unittest.TestCase): def setUp(self): self.lines = [] engine = SimpleNamespace(ocr=SimpleNamespace(run=lambda screen: screen.read())) for patcher in (mock.patch.dict(sys.modules, {'module': types.ModuleType('module'), 'module.ocr': engine}), mock.patch.object(ap.time, 'sleep')): patcher.start() self.addCleanup(patcher.stop) record = mock.patch.object(ap.decisions, 'record') self.record = record.start() self.addCleanup(record.stop) self.cfg = SimpleNamespace(set_win_size=720) def turn(self, screen, config=CONFIG, overclock=False): return ap.rabbit_hole_turn(screen, self.cfg, config, log=self.lines.append, overclock=overclock) def test_selects_hollow_between_p_and_enter(self): screen = BattleScreen() self.assertEqual(self.turn(screen), 'ego') self.assertTrue(screen.selected) self.assertEqual(screen.calls, [('key', 'p'), ('hold', 320, 576, 1.0, 0, 0), ('click', 360, 416), ('key', 'enter')]) self.record.assert_called_once_with('battle', 'hollow', 'ego') def test_overclock_holds_the_card_instead_of_clicking(self): # 游戏教程: 选择 E.G.O 技能时长按 E.G.O 卡片 = 超频 screen = BattleScreen() self.assertEqual(self.turn(screen, overclock=True), 'overclock') self.assertTrue(screen.overclocked) self.assertEqual(screen.calls, [('key', 'p'), ('hold', 320, 576, 1.0, 0, 0), ('hold', 360, 416, 1.0, 0, 0), ('key', 'enter')]) self.record.assert_called_once_with('battle', 'hollow', 'overclock') def test_overclock_on_a_greyed_out_card_closes_the_list(self): screen = BattleScreen(usable=False) self.assertEqual(self.turn(screen, overclock=True), 'ego_unavailable') self.assertFalse(screen.overclocked) self.assertEqual(screen.calls[-2:], [('blank',), ('key', 'enter')]) self.assertIn('兔子洞: 长按「空洞」后列表还在', '\n'.join(self.lines)) def test_fill_in_name_is_matched_after_normalising(self): screen = BattleScreen(popup_text='空 洞') self.assertEqual(self.turn(screen), 'ego') def test_greyed_out_hollow_closes_the_list_and_still_fights(self): screen = BattleScreen(usable=False) self.assertEqual(self.turn(screen), 'ego_unavailable') self.assertEqual(screen.calls[-2:], [('blank',), ('key', 'enter')]) self.assertIn('兔子洞: 点了「空洞」后列表还在(可能 E.G.O 资源不够)', '\n'.join(self.lines)) def test_wrong_press_point_reports_what_was_on_screen(self): screen = BattleScreen(press=(900, 500)) self.assertEqual(self.turn(screen), 'no_option') self.assertEqual(screen.calls[-2:], [('blank',), ('key', 'enter')]) self.assertIn('长按 (320,576) 后没找到 E.G.O「空洞」; 这一屏: 回合 1/胜率', '\n'.join(self.lines)) def test_error_after_p_still_presses_enter(self): # 交回 AALC 会再按一次 P, 而 P 在胜率/伤害之间切换 screen = BattleScreen() screen.mouse_drag = mock.Mock(side_effect=RuntimeError('input lost')) with self.assertRaises(RuntimeError): self.turn(screen) self.assertEqual(screen.calls, [('key', 'p'), ('key', 'enter')]) class LoadRabbitHoleTest(unittest.TestCase): def test_shipped_config_is_uncalibrated(self): config = ap.load_rabbit_hole() self.assertEqual(config['team_names'], ('兔子洞',)) self.assertEqual(config['ego_names'], ('空洞',)) self.assertIsNone(config['press_at']) self.assertIs(config['overclock_first_turn'], True) self.assertEqual(config['theme_packs'], {'身无分文的赌徒': 10, '地狱鸡': 10, '去·海·边': 10, '憎恶与绝望': 12, '2号线': 10}) def test_shipped_route_packs_are_in_the_pack_table(self): _, packs = ap.load_theme_pack_systems() floors = {pack['zh']: pack['hard'].split(',') for pack in packs} route = ap.load_rabbit_hole()['theme_packs'] # OurPlay 全程困难路线: 1~5 层各一个 for floor, name in enumerate(route, 1): with self.subTest(name=name): self.assertIn('%dF' % floor, floors[name]) def test_bad_configs(self): base = {'team_names': ['兔子洞'], 'ego_names': ['空洞'], 'press_at': None, 'hold_seconds': 1} for change in ({'team_names': []}, {'ego_names': ['']}, {'press_at': [0.5]}, {'press_at': [1.2, 0.5]}, {'press_at': [0, 0.5]}, {'hold_seconds': 9}, {'hold_seconds': True}, {'overclock_first_turn': 'yes'}, {'theme_packs': ['地狱鸡']}, {'theme_packs': {'地狱鸡': 0}}, {'theme_packs': {'地狱鸡': True}}, {'theme_packs': {' ': 3}}): with self.subTest(change=change), tempfile.TemporaryDirectory() as d: path = os.path.join(d, 'r.json') with open(path, 'w', encoding='utf-8') as fh: json.dump(dict(base, **change), fh) with self.assertRaises(ValueError): ap.load_rabbit_hole(path) def test_calibrated_point(self): with tempfile.TemporaryDirectory() as d: path = os.path.join(d, 'r.json') with open(path, 'w', encoding='utf-8') as fh: json.dump({'team_names': ['兔子洞'], 'ego_names': ['空洞'], 'press_at': [0.3, 0.85]}, fh) config = ap.load_rabbit_hole(path) self.assertEqual(config['press_at'], (0.3, 0.85)) self.assertEqual((config['overclock_first_turn'], config['theme_packs']), (False, {})) class FakeBattle: def _battle_operation(self, first_turn, defense_first_round, avoid_skill_3, **kwargs): if kwargs.get('never'): # 只给安装时的源码检查看, 测试里走不到 auto.key_press("p") # noqa: F821 auto.key_press("enter") # noqa: F821 return 'upstream' class InstallRabbitHoleTest(unittest.TestCase): def install(self, config, battle_cls=None): self.lines = [] self.battle_cls = battle_cls or type('Battle', (FakeBattle,), {}) self.original = self.battle_cls._battle_operation self.original_calls = [] original = self.original def counted(this, *args, **kwargs): self.original_calls.append(args) return original(this, *args, **kwargs) counted.__wrapped__ = original self.battle_cls._battle_operation = counted battle_mod = types.ModuleType('tasks.battle.battle') battle_mod.Battle = self.battle_cls self.auto = SimpleNamespace() modules = {'tasks': types.ModuleType('tasks'), 'tasks.battle': types.ModuleType('tasks.battle'), 'tasks.battle.battle': battle_mod, 'module': types.ModuleType('module'), 'module.automation': SimpleNamespace(auto=self.auto), 'module.config': SimpleNamespace(cfg=SimpleNamespace(set_win_size=720))} patcher = mock.patch.dict(sys.modules, modules) patcher.start() self.addCleanup(patcher.stop) return ap.install_rabbit_hole(log=self.lines.append, config=config) def test_uncalibrated_keeps_upstream_and_says_so_once(self): self.assertIsNotNone(self.install(dict(CONFIG, press_at=None))) battle = self.battle_cls() with mock.patch.object(ap, 'rabbit_hole_turn') as turn: self.assertEqual(battle._battle_operation(True, False, False), 'upstream') self.assertEqual(battle._battle_operation(False, False, False), 'upstream') turn.assert_not_called() log = '\n'.join(self.lines) self.assertEqual(log.count('[ERROR] [lc_mcp] 兔子洞: rabbit_hole.json 的 press_at 还没在实机上量'), 1) self.assertIn('patch: 镜牢兔子洞: 每回合给浮士德放 E.G.O「空洞」(长按点未校准, 先按 P+Enter)', log) def test_calibrated_turn_replaces_upstream(self): self.install(CONFIG) with mock.patch.object(ap, 'rabbit_hole_turn', return_value='ego') as turn: self.assertIs(self.battle_cls()._battle_operation(True, False, False), False) turn.assert_called_once() self.assertEqual(self.original_calls, []) def test_overclock_only_on_the_first_turn(self): self.install(dict(CONFIG, overclock_first_turn=True)) battle = self.battle_cls() with mock.patch.object(ap, 'rabbit_hole_turn', return_value='ego') as turn: battle._battle_operation(True, False, False) # 上游 fight 按关键字传, 位置参数也要认 battle._battle_operation(first_turn=False, defense_first_round=False, avoid_skill_3=False) battle._battle_operation(first_turn=True, defense_first_round=False, avoid_skill_3=False, prioritize_skill_3=False) self.assertEqual([c.kwargs['overclock'] for c in turn.call_args_list], [True, False, True]) self.assertIn('每回合给浮士德放 E.G.O「空洞」, 每场第一回合超频(长按 0.250,0.800)', '\n'.join(self.lines)) def test_overclock_off_never_holds_the_card(self): self.install(dict(CONFIG, overclock_first_turn=False)) with mock.patch.object(ap, 'rabbit_hole_turn', return_value='ego') as turn: self.battle_cls()._battle_operation(True, False, False) self.assertIs(turn.call_args.kwargs['overclock'], False) def test_upstream_without_first_turn_disables_overclock(self): class NoFirstTurn: def _battle_operation(self, *args, **kwargs): if kwargs.get('never'): auto.key_press("p") # noqa: F821 auto.key_press("enter") # noqa: F821 self.install(dict(CONFIG, overclock_first_turn=True), battle_cls=NoFirstTurn) with mock.patch.object(ap, 'rabbit_hole_turn', return_value='ego') as turn: NoFirstTurn()._battle_operation(True, False, False) self.assertIs(turn.call_args.kwargs['overclock'], False) self.assertIn('[ERROR] [lc_mcp] 上游 Battle._battle_operation 没有 first_turn 参数', '\n'.join(self.lines)) def test_turn_error_is_contained(self): self.install(CONFIG) with mock.patch.object(ap, 'rabbit_hole_turn', side_effect=RuntimeError('ocr down')): self.assertIs(self.battle_cls()._battle_operation(True, False, False), False) self.assertIn('兔子洞: 这回合出错(RuntimeError: ocr down), 已按 Enter', '\n'.join(self.lines)) def test_interrupt_is_not_swallowed(self): self.install(CONFIG) with mock.patch.object(ap, 'rabbit_hole_turn', side_effect=InterruptedError): with self.assertRaises(InterruptedError): self.battle_cls()._battle_operation(True, False, False) def test_upstream_without_p_enter_is_an_error(self): class Other: def _battle_operation(self, *args): return None self.assertIsNone(self.install(CONFIG, battle_cls=Other)) self.assertIn('[ERROR] [lc_mcp] 上游 Battle._battle_operation 不再是 P+Enter 出手', '\n'.join(self.lines)) @unittest.skipUnless(BATTLE.is_file(), 'vendor/aalc 子模块未检出') def test_current_upstream_turn_is_p_then_enter(self): source = BATTLE.read_text(encoding='utf-8') cls = next(n for n in ast.parse(source).body if isinstance(n, ast.ClassDef) and n.name == 'Battle') node = next(n for n in cls.body if isinstance(n, ast.FunctionDef) and n.name == '_battle_operation') body = ast.get_source_segment(source, node) self.assertIn('auto.key_press("p")', body) self.assertIn('auto.key_press("enter")', body) self.assertEqual(node.args.args[1].arg, 'first_turn') fight = next(n for n in cls.body if isinstance(n, ast.FunctionDef) and n.name == 'fight') self.assertIn('first_turn=first_turn', ast.get_source_segment(source, fight)) class StrategyOptionTest(unittest.TestCase): def test_options_are_split_from_counts(self): self.assertEqual(aalc_task.split_options('mirror', {'count': 2, 'strategy': 'rabbit_hole'}), ({'count': 2}, {'strategy': 'rabbit_hole'})) self.assertEqual(aalc_task.split_options('daily', {'exp': 1}), ({'exp': 1}, {})) def test_cli_rejects_unknown_strategy_and_strategy_on_other_tasks(self): for argv in (['x', 'mirror', '{"strategy": "fast"}'], ['x', 'daily', '{"strategy": "rabbit_hole"}']): with self.subTest(argv=argv), mock.patch.object(aalc_task, 'run') as run, \ mock.patch('sys.stderr'): self.assertEqual(aalc_task.main(argv), 2) run.assert_not_called() def test_cli_passes_the_strategy_through(self): with mock.patch.object(aalc_task, 'run', return_value=0) as run, mock.patch('builtins.print'): self.assertEqual(aalc_task.main(['x', 'mirror', '{"count": 1, "strategy": "rabbit_hole"}']), 0) run.assert_called_once_with('mirror', {'count': 1, 'strategy': 'rabbit_hole'}) def test_team_names_override_the_system(self): mirror_mod = types.ModuleType('tasks.mirror.mirror') mirror_mod.Mirror = type('Mirror', (), {'__init__': lambda self, setting, num: setattr(self, 'system', 'bleed')}) mirror_mod.select_battle_team = lambda num: False package = types.ModuleType('tasks.mirror') package.mirror = mirror_mod modules = {'tasks': types.ModuleType('tasks'), 'tasks.mirror': package, 'tasks.mirror.mirror': mirror_mod, 'module': types.ModuleType('module'), 'module.automation': SimpleNamespace(auto=mock.Mock())} lines = [] with mock.patch.dict(sys.modules, modules): ap.install_system_team_selection(log=lines.append, names=('兔子洞',)) mirror_mod.Mirror({}, 1) with mock.patch.object(ap, '_select_team_by_name', return_value=True) as select: mirror_mod.select_battle_team(1) self.assertEqual(select.call_args[0][1], ('兔子洞',)) self.assertIn('镜牢体系 bleed -> 目标编队 兔子洞', '\n'.join(lines)) if __name__ == '__main__': unittest.main()
Commit Changes
Add a Signed-off-by trailer by the committer at the end of the commit log message.
Commit directly to the
codex/feedback-unattended-setup-20261004
branch.
Create a
new branch
for this commit and start a pull request.
Commit Changes
Cancel