普通镜牢转交 AALC,核对镜牢实际完成局数,合成与任务互斥

Browse Source
转交与互斥(原未提交改动,合入选队分支后提交):
- MCP 初始化说明和工具描述引导常规日常/领奖/普通镜牢走
  task_status -> run_task -> 轮询;jev_mirror_agent 默认转交 AALC,
  明确的速通配置、决策模型或未完成速通局仍走逐步模式。
- 新增 ~/lc_mcp/game.lock:run_task 子进程与模块合成脚本互斥,
  合成脚本另查 task_status,状态不明时不接管游戏。
- all 任务的 HDR 提示无 GUI 时直接确认并记录;预检按窗口位置
  决定是否计标题栏,set_windows=false 跳过;levelup card/weakest
  同步失败返回非零。急停提示改为 End 键。

镜牢结果(对接文档指出的缺口):
- 预检拒绝空队列和没有适用当前难度队伍的配置:AALC 会一局不打
  就以 0 退出。可用判定与 Mirror_task 的固定用途规则一致。
- 监听 mirror_signal 统计实际完成局数;少于应打局数记 [ERROR]
  并以退出码 4 结束,task_status 为 failed。
- mirror 指定 count 时临时关闭 infinite_dungeons(否则次数变成
  9999),原值写入恢复文件,结束或强杀后写回。

验证:Linux / Python 3.12 全套 507 项通过;git diff --check 通过。
用上游真实 Mirror_task 回放了无可用队伍和正常完成两种情况;
Windows 实机仍需回归。

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
yws
2026-11-14 03:27:03 +00:00
co-authored by Claude Opus 5.5
parent 1aa823ea2e
commit 5fdb9fd221
17 changed files with 904 additions and 46 deletions
+66 -1
View File
@@ -14,6 +14,7 @@ from unittest import mock
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / 'scripts')) sys.path.insert(0, str(Path(__file__).resolve().parents[1] / 'scripts'))
import convert_modules as cm # noqa: E402 import convert_modules as cm # noqa: E402
from lc_mcp import game_lock
class QuietLogMixin: class QuietLogMixin:
@@ -28,6 +29,62 @@ class QuietLogMixin:
patcher = mock.patch.object(cm, 'log', lambda m: None) patcher = mock.patch.object(cm, 'log', lambda m: None)
patcher.start() patcher.start()
self.addCleanup(patcher.stop) self.addCleanup(patcher.stop)
tmp = tempfile.TemporaryDirectory()
self.addCleanup(tmp.cleanup)
patcher = mock.patch.object(game_lock, 'default_lock_path',
return_value=os.path.join(tmp.name, 'game.lock'))
patcher.start()
self.addCleanup(patcher.stop)
patcher = mock.patch.object(cm, 'probe', return_value={'ok': True, 'state': 'idle'})
patcher.start()
self.addCleanup(patcher.stop)
class GameOwnershipTest(QuietLogMixin, unittest.TestCase):
def test_running_task_is_not_navigated_or_closed(self):
from lc_mcp.fake_engine import FakeEngine
from lc_mcp.protocol import Server
from lc_mcp.tasks import TaskRunner
with tempfile.TemporaryDirectory() as tmp:
runner = TaskRunner(tmp, argv_factory=lambda *a: [
sys.executable, '-c', 'import time; time.sleep(30)'])
server = Server(FakeEngine(), runner)
runner.start('daily', {}) # Emulate an older process without the shared lock.
try:
with mock.patch.object(cm, 'probe', side_effect=server.call_tool), \
mock.patch.object(cm, 'ensure_server', return_value=True), \
mock.patch.object(cm, 'ensure_display') as display, \
mock.patch.object(cm, 'launch_game') as launch, \
mock.patch.object(cm, 'close_game') as close:
self.assertEqual(cm.main(['--report-dir', tmp]), 1)
display.assert_not_called()
launch.assert_not_called()
close.assert_not_called()
self.assertTrue(runner.running())
self.assertEqual(server.engine.actions, [])
finally:
runner.stop()
def test_unknown_status_does_not_touch_the_game(self):
for status in ({}, {'ok': False}, {'ok': True, 'state': 'unknown'}):
with self.subTest(status=status), tempfile.TemporaryDirectory() as tmp, \
mock.patch.object(cm, 'probe', return_value=status), \
mock.patch.object(cm, 'ensure_server', return_value=True), \
mock.patch.object(cm, 'ensure_display') as display, \
mock.patch.object(cm, 'close_game') as close:
self.assertEqual(cm.main(['--report-dir', tmp]), 1)
display.assert_not_called()
close.assert_not_called()
def test_existing_owner_prevents_even_service_startup(self):
with tempfile.TemporaryDirectory() as tmp, \
mock.patch.object(cm, 'ensure_server') as server, \
mock.patch.object(cm, 'close_game') as close, \
game_lock.exclusive_game():
self.assertEqual(cm.main(['--report-dir', tmp]), 1)
server.assert_not_called()
close.assert_not_called()
class ScreenDetectTest(QuietLogMixin, unittest.TestCase): class ScreenDetectTest(QuietLogMixin, unittest.TestCase):
@@ -603,6 +660,14 @@ class CliRoutingTest(QuietLogMixin, unittest.TestCase):
done = [] done = []
tmp = tempfile.mkdtemp() tmp = tempfile.mkdtemp()
self.addCleanup(shutil.rmtree, tmp, True) self.addCleanup(shutil.rmtree, tmp, True)
def close_owned_game():
# Ownership must cover shutdown too, so a new task cannot start here.
with self.assertRaises(game_lock.GameBusyError):
with game_lock.exclusive_game():
pass
closed.append(1)
with mock.patch.object(cm, 'read_enkephalin', lambda: 4), \ with mock.patch.object(cm, 'read_enkephalin', lambda: 4), \
mock.patch.object(cm, 'read_lunacy', lambda **k: 9699), \ mock.patch.object(cm, 'read_lunacy', lambda **k: 9699), \
mock.patch.object(cm, 'ensure_server', lambda *a: True), \ mock.patch.object(cm, 'ensure_server', lambda *a: True), \
@@ -611,7 +676,7 @@ class CliRoutingTest(QuietLogMixin, unittest.TestCase):
mock.patch.object(cm, 'wait_main_menu', lambda *a: True), \ mock.patch.object(cm, 'wait_main_menu', lambda *a: True), \
mock.patch.object(cm, 'ensure_window_size', lambda *a: (1600, 900)), \ mock.patch.object(cm, 'ensure_window_size', lambda *a: (1600, 900)), \
mock.patch.object(cm, 'close_panel', lambda: True), \ mock.patch.object(cm, 'close_panel', lambda: True), \
mock.patch.object(cm, 'close_game', lambda: closed.append(1)), \ mock.patch.object(cm, 'close_game', close_owned_game), \
mock.patch.object(cm.time, 'sleep', lambda s: None): mock.patch.object(cm.time, 'sleep', lambda s: None):
code = cm.main(argv + ['--report-dir', tmp]) code = cm.main(argv + ['--report-dir', tmp])
done.append(os.listdir(tmp)) done.append(os.listdir(tmp))