修复内置流程编队滑动被当成拖拽卡片: 补 Windows 队伍滑动手势并暴露任务日志报错

Browse Source
- aalc_input_patch: 上游只有 MuMu 适配器覆盖 mouse_swipe_for_team_scroll,
  Windows 前台/后台适配器用普通列表手势(30px/0.01s escape), 在编队列表里
  会被当成拖动罪人卡: 队伍被拖乱, 缺人时后续 battle.py 报'未能进入战斗'。
  按 MuMu 参数(缩放 60px escape/保持 0.1s/分段/停稳 0.5s)补等价实现, 不改 AALC 源码。
- tasks: 退出码 0 但日志里有 [ERROR]/异常时, task_status 增加 errors 字段
  (AALC 单次战斗失败后仍会正常退出, 只看 succeeded 会被误导)。
- 新增 7 项回归测试, 全套 101 项通过。
This commit is contained in:
DSH
2026-10-03 11:24:15 +08:00
parent 2131f89e62
commit 66418dce22
5 changed files with 296 additions and 0 deletions
+106
View File
@@ -15,6 +15,7 @@ REPO = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.insert(0, REPO)
from lc_mcp import server as srv_mod # noqa: E402
from lc_mcp import aalc_input_patch # noqa: E402
from lc_mcp.engine import find_hits # noqa: E402
from lc_mcp.fake_engine import FakeEngine # noqa: E402
from lc_mcp.protocol import Server, TOOLS # noqa: E402
@@ -580,5 +581,110 @@ class TransportTest(unittest.TestCase):
self.assertEqual((state['ok'], state['items']), (True, []))
class TaskErrorSurfaceTest(unittest.TestCase):
"""AALC 每日流程单次战斗失败后仍 exit 0; 状态里必须带出日志报错。"""
CHILD = ('import sys; '
'sys.stdout.write("[ERROR] [AALC] tasks\\\\battle\\\\battle.py:83: '
'超出最大尝试次数,未能进入战斗\\n"); '
'sys.stdout.write("[lc_mcp] task daily done\\n"); '
'sys.stdout.flush()')
def test_exit_zero_with_battle_error_is_reported(self):
with tempfile.TemporaryDirectory() as d:
runner = TaskRunner(d, argv_factory=lambda t, p: [sys.executable, '-c', self.CHILD])
self.assertTrue(runner.start('daily', {'exp': 1})['ok'])
deadline = time.time() + 15
while time.time() < deadline and runner.running():
time.sleep(0.05)
status = runner.status()
self.assertEqual((status['state'], status['exit_code']), ('succeeded', 0), status)
self.assertIn('未能进入战斗', status['errors'][-1])
def test_clean_log_has_no_errors_field(self):
with tempfile.TemporaryDirectory() as d:
runner = TaskRunner(d, argv_factory=lambda t, p: [sys.executable, '-c', 'print("[lc_mcp] ok")'])
self.assertTrue(runner.start('daily', {})['ok'])
deadline = time.time() + 15
while time.time() < deadline and runner.running():
time.sleep(0.05)
status = runner.status()
self.assertEqual(status['state'], 'succeeded')
self.assertNotIn('errors', status)
class TeamScrollPatchTest(unittest.TestCase):
"""编队列表滑动: Windows 适配器缺少队伍拖拽规避, 补丁的几何必须是
"先 escape 脱离按住判定, 再按名义位移走完"。
"""
def test_zero_distance_is_noop(self):
self.assertIsNone(aalc_input_patch.team_scroll_plan(10, 20, 0, 0, 0.3, 60))
def test_upward_swipe_escapes_first_then_travels_nominal_delta(self):
start, escape, end, duration = aalc_input_patch.team_scroll_plan(100, 200, 0, -200, 0.4, 60)
self.assertEqual(start, (100.0, 200.0))
self.assertEqual(escape, (100.0, 140.0))
self.assertEqual(end, (100.0, -60.0))
self.assertAlmostEqual(end[1] - escape[1], -200.0)
self.assertEqual(duration, 0.4)
def test_downward_swipe_shifts_start_into_visible_rows(self):
start, escape, end, _ = aalc_input_patch.team_scroll_plan(100, 200, 0, 200, 0.4, 60)
self.assertEqual(start, (100.0, 140.0))
self.assertEqual(escape, (100.0, 200.0))
self.assertEqual(end, (100.0, 400.0))
self.assertAlmostEqual(end[1] - escape[1], 200.0)
def test_escape_leg_has_requested_length(self):
start, escape, end, _ = aalc_input_patch.team_scroll_plan(0, 0, 300, -400, 0.5, 50)
leg = (escape[0] - start[0], escape[1] - start[1])
self.assertAlmostEqual((leg[0] ** 2 + leg[1] ** 2) ** 0.5, 50.0)
self.assertAlmostEqual(end[0] - escape[0], 300.0)
self.assertAlmostEqual(end[1] - escape[1], -400.0)
def test_install_patches_team_scroll_on_windows_adapters(self):
import types
class FakeInput:
def mouse_swipe_for_team_scroll(self, *args, **kwargs):
raise AssertionError('未打补丁')
class FakeBackground:
def set_mouse_pos(self, *args, **kwargs):
pass
def mouse_swipe_for_team_scroll(self, *args, **kwargs):
raise AssertionError('未打补丁')
class FakeWindowMove:
"""没有 set_mouse_pos 的适配器保持原样。"""
def mouse_swipe_for_team_scroll(self, *args, **kwargs):
raise AssertionError('未打补丁')
leaf = types.ModuleType('module.automation.input_handlers.input')
leaf.Input = FakeInput
leaf.BackgroundInput = FakeBackground
leaf.WindowMoveInput = FakeWindowMove
parents = {}
for name in ('module', 'module.automation', 'module.automation.input_handlers'):
parents[name] = types.ModuleType(name)
parents[name].__path__ = []
parents['module.automation.input_handlers'].input = leaf
parents['module.automation'].input_handlers = parents['module.automation.input_handlers']
parents['module'].automation = parents['module.automation']
with mock.patch.dict(sys.modules, parents):
patched = aalc_input_patch.install()
self.assertEqual(patched, ['Input', 'BackgroundInput'])
self.assertIs(FakeInput.mouse_swipe_for_team_scroll,
aalc_input_patch._foreground_team_scroll)
self.assertIs(FakeBackground.mouse_swipe_for_team_scroll,
aalc_input_patch._adapter_team_scroll)
# 幂等: 再装一次不再重复补
self.assertEqual(aalc_input_patch.install(), [])
if __name__ == '__main__':
unittest.main()