- lc_mcp/preflight.py: 启动前拦截 sinner_order 全 0、会花狂气、窗口放不进桌面 (退出码 3) - lc_mcp/aalc_patches.py: 队伍名按编号精确匹配 (TEAMS #1 不再命中 #10); 后台守护客户区 16:9 - auto_cycle.py: AALC 卡死后停掉重跑; --mirror 打镜牢; 每轮写 cycle_*.log/.json 报告 - install_unattended.ps1: 注册会话看门狗 (每 5 分钟) 与每日一轮计划任务 - lc_ui.py: pythonw 启动时子进程改用 python 且不弹窗 - vendor/aalc: 7452fad -> b0f4393 (镜牢楼层识别、困牢奖励、排队启动修复) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
85 lines
3.1 KiB
Python
85 lines
3.1 KiB
Python
from pathlib import Path
|
|
import sys
|
|
import unittest
|
|
from unittest import mock
|
|
|
|
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / 'scripts'))
|
|
import auto_cycle # noqa: E402
|
|
|
|
|
|
class FakeMcp:
|
|
"""按脚本返回 task_status, 记录 run_task / stop_task 调用。"""
|
|
|
|
def __init__(self, *runs):
|
|
self.runs = [list(r) for r in runs] # 每次 run_task 后依次返回的状态
|
|
self.calls = []
|
|
|
|
def probe(self, tool, args=None, quiet=True):
|
|
self.calls.append((tool, args))
|
|
if tool == 'run_task':
|
|
self.current = self.runs.pop(0)
|
|
return {'ok': True}
|
|
if tool == 'task_status':
|
|
return self.current.pop(0) if len(self.current) > 1 else self.current[0]
|
|
return {'ok': True}
|
|
|
|
|
|
RUNNING = {'state': 'running'}
|
|
STALL = {'state': 'running', 'stall': {'empty_team': 30}}
|
|
DONE = {'state': 'succeeded', 'exit_code': 0}
|
|
|
|
|
|
class RunAalcTest(unittest.TestCase):
|
|
|
|
def run_aalc(self, mcp, **kw):
|
|
with mock.patch.object(auto_cycle, 'probe', mcp.probe), \
|
|
mock.patch.object(auto_cycle, 'log', lambda m: None):
|
|
return auto_cycle.run_aalc('daily', {}, 3600, sleep=lambda s: None, **kw)
|
|
|
|
def tools(self, mcp):
|
|
return [t for t, _ in mcp.calls if t != 'task_status']
|
|
|
|
def test_stall_is_stopped_and_rerun_once(self):
|
|
mcp = FakeMcp([RUNNING, STALL, STALL], [RUNNING, DONE])
|
|
ok, info = self.run_aalc(mcp)
|
|
self.assertTrue(ok, info)
|
|
self.assertEqual(self.tools(mcp), ['run_task', 'stop_task', 'run_task'])
|
|
|
|
def test_single_stall_poll_is_not_enough(self):
|
|
mcp = FakeMcp([STALL, RUNNING, DONE])
|
|
ok, info = self.run_aalc(mcp)
|
|
self.assertTrue(ok, info)
|
|
self.assertEqual(self.tools(mcp), ['run_task'])
|
|
|
|
def test_gives_up_after_retries(self):
|
|
mcp = FakeMcp([STALL, STALL], [STALL, STALL])
|
|
ok, info = self.run_aalc(mcp, retries=1)
|
|
self.assertFalse(ok)
|
|
self.assertIn('卡死', info)
|
|
self.assertEqual(self.tools(mcp), ['run_task', 'stop_task', 'run_task', 'stop_task'])
|
|
|
|
def test_preflight_failure_is_not_retried(self):
|
|
failed = {'state': 'failed', 'exit_code': 3,
|
|
'errors': ['[ERROR] [lc_mcp] preflight: 队伍 1 的 sinner_order 没有罪人']}
|
|
mcp = FakeMcp([failed])
|
|
ok, info = self.run_aalc(mcp)
|
|
self.assertFalse(ok)
|
|
self.assertIn('preflight', info)
|
|
self.assertEqual(self.tools(mcp), ['run_task'])
|
|
|
|
def test_exit_zero_with_errors_is_failure(self):
|
|
mcp = FakeMcp([dict(DONE, errors=['[ERROR] 超出最大尝试次数,未能进入战斗'])])
|
|
ok, info = self.run_aalc(mcp)
|
|
self.assertFalse(ok)
|
|
|
|
def test_mirror_params_are_passed_with_task(self):
|
|
mcp = FakeMcp([DONE])
|
|
with mock.patch.object(auto_cycle, 'probe', mcp.probe), \
|
|
mock.patch.object(auto_cycle, 'log', lambda m: None):
|
|
auto_cycle.run_aalc('mirror', {'count': 2}, 3600, sleep=lambda s: None)
|
|
self.assertEqual(mcp.calls[0], ('run_task', {'count': 2, 'task': 'mirror'}))
|
|
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|