挂机合成模块: 新增 convert_modules.py + 计划任务; 并修掉一个把测试跑崩的用例
用户要求: 这次不打任何关卡, 只挂机等体力恢复、把体力合成成模块, 合成完关掉游戏。
一、新增 scripts/convert_modules.py(启动游戏->合成->关掉)
单独一个脚本, 不走 AALC 的任务系统 —— AALC 的 make_enkephalin_module 是挂在
Luxcavation 流程里的(打完一次才顺手换一次), 没有独立入口, 而这次不能打关卡。
界面流程(1600x900 基准, lc_ui 负责换算):
主界面点模组图标 -> Charge Enkephalin -> [Modules]/[Use Lunacy]/[Use Boxes]
-> 停在 Modules(免费) -> » 取最大 -> Confirm -> 20 体力换 1 模块
三条硬规则:
1. 绝不点 Use Lunacy 页签。USE_LUNACY_TAB 常量只用于"确认没点到它",
并写了 AST 检查的测试: 任何 click() 传入该坐标都会让测试失败。
2. 不打任何关卡, 全程只碰底栏模组图标和合成面板。
3. 合成前后各读一次狂气做相对比对, 不一致就报错退出。
实机验证: 模组 23 -> 29(+6)、体力 132 -> 13(6x20)、狂气 6636 未变。
二、修窗口尺寸: RDP 断线重连会把客户区改成 1278x719(实测), 之后 OCR 连底栏
的 LUNACY 标签都读不出来, 狂气校验直接退化成"读不到, 跳过"。AALC 的
WindowGuard 只在跑任务时生效, 这个脚本不跑任务, 所以自己做 MoveWindow。
三、新增 scripts/install_convert_task.ps1: 每 4 小时一轮(LcMCPConvertModules)。
体力每 6 分钟回 1 点、上限 126, 合成 1 个模块要 20 点 -> 4 小时约能换 2 个。
与 LcMCPDailyCycle 完全分开, 刷取任务保持禁用。
四、修 keep_display.ps1 的一个真 bug:
(Get-Content $out -Raw) 在文件为空/被当通配时返回数组, 后面的 .Trim() 报
"does not contain a method named Trim"。看门狗本身照常工作, 但每次都会
吐一条红字, 掩盖真正的失败。改成先拼接再裁剪。
五、⛔ 修掉一个我自己写坏的测试, 它会让整个测试进程崩掉:
poll_task 的循环上限是按墙钟判的(time.time()), 而测试里把 sleep 换成空函数
却没换时钟 —— 于是 timeout_s=3600 真的空转了一小时, 每圈还往 mcp.calls 里
塞一条, 内存吃爆后进程以 0xC0000005 退出。表现就是"跑测试跑崩了"。
改成 FakeTime 快进时钟。全套从 156 秒(且崩)降到 14 秒, 246/246 通过。
新增 tests/test_convert_modules.py 13 个用例(屏幕判定/资源读数/狂气众数/禁用坐标)。
其中"禁用坐标"那条也验证过能失败: 故意把 click(*TAB_MODULES) 改成
click(*USE_LUNACY_TAB), 它准确报出违规行号。
This commit is contained in:
@@ -29,6 +29,27 @@ STALL = {'state': 'running', 'stall': {'empty_team': 30}}
|
||||
DONE = {'state': 'succeeded', 'exit_code': 0}
|
||||
|
||||
|
||||
class FakeTime:
|
||||
"""快进时钟。
|
||||
|
||||
poll_task 的循环上限是按**墙钟**判断的 (time.time() - t0 < timeout_s),
|
||||
而测试里 sleep 被换成了空函数 —— 只换 sleep 不换时钟的话, 那个循环会真的
|
||||
空转满 timeout_s 秒, 每圈还往 mcp.calls 里塞一条记录。实测这样跑会把内存
|
||||
吃爆, 让整个测试进程以 0xC0000005 退出。
|
||||
"""
|
||||
|
||||
def __init__(self, step=1.0):
|
||||
self.t = 0.0
|
||||
self.step = step
|
||||
|
||||
def time(self):
|
||||
self.t += self.step
|
||||
return self.t
|
||||
|
||||
def sleep(self, _s):
|
||||
pass
|
||||
|
||||
|
||||
class RunAalcTest(unittest.TestCase):
|
||||
|
||||
def run_aalc(self, mcp, **kw):
|
||||
@@ -36,6 +57,22 @@ class RunAalcTest(unittest.TestCase):
|
||||
mock.patch.object(auto_cycle, 'log', lambda m: None):
|
||||
return auto_cycle.run_aalc('daily', {}, 3600, sleep=lambda s: None, **kw)
|
||||
|
||||
def poll(self, mcp, timeout_s, clear=None, step=60.0):
|
||||
"""跑 poll_task, 用快进时钟, 绝不真的等。"""
|
||||
clock = FakeTime(step)
|
||||
patches = [mock.patch.object(auto_cycle, 'probe', mcp.probe),
|
||||
mock.patch.object(auto_cycle, 'log', lambda m: None),
|
||||
mock.patch.object(auto_cycle.time, 'time', clock.time)]
|
||||
if clear is not None:
|
||||
patches.append(mock.patch.object(auto_cycle, 'clear_blocking_modal', clear))
|
||||
for p in patches:
|
||||
p.start()
|
||||
try:
|
||||
return auto_cycle.poll_task('daily', timeout_s, sleep=lambda s: None)
|
||||
finally:
|
||||
for p in patches:
|
||||
p.stop()
|
||||
|
||||
def tools(self, mcp):
|
||||
return [t for t, _ in mcp.calls if t != 'task_status']
|
||||
|
||||
@@ -58,6 +95,33 @@ class RunAalcTest(unittest.TestCase):
|
||||
self.assertIn('卡死', info)
|
||||
self.assertEqual(self.tools(mcp), ['run_task', 'stop_task', 'run_task', 'stop_task'])
|
||||
|
||||
def test_resource_out_stops_without_rerun(self):
|
||||
"""反复缺模组 = 资源见底, 直接收工, 不要重跑也不要等超时。
|
||||
|
||||
实测(2026-10-13): 体力只剩 3/126、模组不足时, AALC 的 Luxcavation 流程
|
||||
会一直在"not enough Enkephalin Modules"模态框后面点被挡住的 Enter 按钮。
|
||||
每次都要烧满 10 分钟才被 no_progress 判据救回, 重跑还是同样的结果。
|
||||
"""
|
||||
mcp = FakeMcp()
|
||||
mcp.current = [RUNNING] * 40
|
||||
ok, info, stalled = self.poll(mcp, 3600, clear=lambda: '缺模组 -> 点 Cancel')
|
||||
self.assertFalse(ok)
|
||||
self.assertEqual(info, 'RESOURCE_OUT')
|
||||
self.assertFalse(stalled)
|
||||
# 只清了 RESOURCE_OUT_LIMIT 次就停, 而不是一路点到超时
|
||||
self.assertIn('stop_task', self.tools(mcp))
|
||||
|
||||
def test_occasional_modal_does_not_end_the_task(self):
|
||||
"""偶发一次模态框不该收工 —— 点掉继续跑才对。"""
|
||||
seq = ['x']
|
||||
mcp = FakeMcp()
|
||||
mcp.current = [RUNNING]
|
||||
ok, info, stalled = self.poll(
|
||||
mcp, 600, clear=lambda: seq.pop(0) if seq else None)
|
||||
self.assertNotEqual(info, 'RESOURCE_OUT')
|
||||
# 跑到超时收工, 而不是被当成资源耗尽
|
||||
self.assertIn('超时', info)
|
||||
|
||||
def test_preflight_failure_is_not_retried(self):
|
||||
failed = {'state': 'failed', 'exit_code': 3,
|
||||
'errors': ['[ERROR] [lc_mcp] preflight: 队伍 1 的 sinner_order 没有罪人']}
|
||||
@@ -197,14 +261,16 @@ class LunacyReadTest(unittest.TestCase):
|
||||
mock.patch.object(auto_cycle.time, 'sleep', lambda s: None):
|
||||
self.assertIsNone(auto_cycle.read_lunacy())
|
||||
|
||||
def test_off_main_menu_is_not_read(self):
|
||||
# 结算画面: 有 LUNACY 标签和 4 位数, 但没有主界面的按钮
|
||||
def test_reads_on_any_screen_not_just_main_menu(self):
|
||||
# 曾经加过"只在主界面取数"的限制, 结果几乎总是读不到(轮次起止常停在副本/
|
||||
# 网格/结算页), 守卫直接跳过 —— 防线等于没有。众数投票已经能压住误读,
|
||||
# 所以非主界面也读。
|
||||
fake = [{'text': 'LUNACY', 'x': 671, 'y': 795},
|
||||
{'text': '8859', 'x': 664, 'y': 823},
|
||||
{'text': '6388', 'x': 664, 'y': 823},
|
||||
{'text': 'Mirror Dungeon Result', 'x': 700, 'y': 400}]
|
||||
with mock.patch.object(auto_cycle, 'items', lambda: fake), \
|
||||
mock.patch.object(auto_cycle.time, 'sleep', lambda s: None):
|
||||
self.assertIsNone(auto_cycle.read_lunacy())
|
||||
self.assertEqual(auto_cycle.read_lunacy(), 6388)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
@@ -0,0 +1,143 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""convert_modules 的纯逻辑测试。
|
||||
|
||||
这个脚本会操作真实游戏, 所以这里只测不碰硬件的部分: 屏幕判定、资源读数、
|
||||
狂气相对比对用的解析。合成动作本身靠实机验证。
|
||||
"""
|
||||
import sys
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
from unittest import mock
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / 'scripts'))
|
||||
import convert_modules as cm # noqa: E402
|
||||
|
||||
|
||||
class ScreenDetectTest(unittest.TestCase):
|
||||
|
||||
def test_main_menu_needs_enough_markers(self):
|
||||
good = 'Window | Sinners | Drive | Theater | Extract | Dispense'
|
||||
self.assertTrue(cm.on_main_menu(good))
|
||||
|
||||
def test_partial_screen_is_not_main_menu(self):
|
||||
# 标题页只有一两个词, 不能当成主界面 —— 否则会在标题页上找模组图标
|
||||
self.assertFalse(cm.on_main_menu('TOUCH TO START | Clear all caches'))
|
||||
self.assertFalse(cm.on_main_menu('Window | Sinners'))
|
||||
|
||||
def test_panel_marker(self):
|
||||
self.assertTrue(cm.panel_open('Charge Enkephalin | Modules | Use Lunacy'))
|
||||
self.assertFalse(cm.panel_open('Window | Sinners | Drive'))
|
||||
|
||||
|
||||
class ReadOwnedTest(unittest.TestCase):
|
||||
|
||||
def test_reads_owned(self):
|
||||
its = [{'text': 'Enkephalin Module Owned 29', 'x': 820, 'y': 334}]
|
||||
with mock.patch.object(cm, 'items', lambda: its):
|
||||
self.assertEqual(cm.read_owned(), 29)
|
||||
|
||||
def test_falls_back_to_bare_number(self):
|
||||
its = [{'text': 'Owned', 'x': 820, 'y': 334},
|
||||
{'text': '29', 'x': 900, 'y': 334}]
|
||||
with mock.patch.object(cm, 'items', lambda: its):
|
||||
self.assertEqual(cm.read_owned(), 29)
|
||||
|
||||
def test_none_when_absent(self):
|
||||
with mock.patch.object(cm, 'items', lambda: [{'text': 'Window', 'x': 1, 'y': 800}]):
|
||||
self.assertIsNone(cm.read_owned())
|
||||
|
||||
|
||||
class ReadEnkephalinTest(unittest.TestCase):
|
||||
"""只认主界面底栏的 x/126。
|
||||
|
||||
合成面板里也有一个 x/126, 但那是"合成后"的预览值 —— 拿它当余额会把
|
||||
"体力不足"误判成"还有体力", 于是每轮都去点确认。
|
||||
"""
|
||||
|
||||
def test_reads_bottom_bar(self):
|
||||
its = [{'text': '13/126', 'x': 451, 'y': 827}]
|
||||
with mock.patch.object(cm, 'items', lambda: its):
|
||||
self.assertEqual(cm.read_enkephalin(), 13)
|
||||
|
||||
def test_ignores_panel_preview(self):
|
||||
# y≈508 是合成面板里的预览, 不是余额
|
||||
its = [{'text': '132/126', 'x': 709, 'y': 508}]
|
||||
with mock.patch.object(cm, 'items', lambda: its):
|
||||
self.assertIsNone(cm.read_enkephalin())
|
||||
|
||||
def test_handles_spaces_and_garbage(self):
|
||||
its = [{'text': '13 / 126', 'x': 451, 'y': 827}]
|
||||
with mock.patch.object(cm, 'items', lambda: its):
|
||||
self.assertEqual(cm.read_enkephalin(), 13)
|
||||
|
||||
|
||||
class LunacyReadTest(unittest.TestCase):
|
||||
"""狂气数字是像素艺术字, OCR 会误读(实测 6636 读成 9699)。
|
||||
|
||||
所以脚本不对绝对值下结论, 只做**前后相对比对**: 同一个画面同一套字体,
|
||||
误读方式一致, 两次读数不同就说明数字真的变了。
|
||||
"""
|
||||
|
||||
def _frames(self, values):
|
||||
seq = list(values)
|
||||
|
||||
def fake():
|
||||
v = seq.pop(0) if len(seq) > 1 else seq[0]
|
||||
return [{'text': 'LUNACY', 'x': 670, 'y': 795},
|
||||
{'text': str(v), 'x': 664, 'y': 823}]
|
||||
return fake
|
||||
|
||||
def test_majority_wins_over_outlier(self):
|
||||
with mock.patch.object(cm, 'items', self._frames([9699, 6636, 9699, 9699, 9699])), \
|
||||
mock.patch.object(cm.time, 'sleep', lambda s: None):
|
||||
self.assertEqual(cm.read_lunacy(), 9699)
|
||||
|
||||
def test_none_when_no_label(self):
|
||||
with mock.patch.object(cm, 'items', lambda: [{'text': 'Window', 'x': 1, 'y': 800}]), \
|
||||
mock.patch.object(cm.time, 'sleep', lambda s: None):
|
||||
self.assertIsNone(cm.read_lunacy())
|
||||
|
||||
|
||||
class ForbiddenCoordinateTest(unittest.TestCase):
|
||||
"""Use Lunacy 页签的坐标只能用于"确认没点到它", 不能出现在任何点击路径上。
|
||||
|
||||
这条做成测试, 是因为以后改动布局时很容易顺手把它接进某个分支 ——
|
||||
那是一步就能花掉狂气的操作。用 AST 查实参, 而不是查文本: 文本里
|
||||
文档说明本来就会提到这个常量名。
|
||||
"""
|
||||
|
||||
def _source(self):
|
||||
return (Path(__file__).resolve().parents[1] / 'scripts' / 'convert_modules.py') \
|
||||
.read_text(encoding='utf-8')
|
||||
|
||||
def test_no_click_call_passes_the_use_lunacy_tab(self):
|
||||
import ast
|
||||
tree = ast.parse(self._source())
|
||||
offenders = []
|
||||
for node in ast.walk(tree):
|
||||
if not isinstance(node, ast.Call):
|
||||
continue
|
||||
f = node.func
|
||||
name = getattr(f, 'id', None) or getattr(f, 'attr', None)
|
||||
if name != 'click':
|
||||
continue
|
||||
for arg in list(node.args):
|
||||
# click(*USE_LUNACY_TAB) 或 click(USE_LUNACY_TAB[0], ...)
|
||||
if isinstance(arg, ast.Starred):
|
||||
arg = arg.value
|
||||
if isinstance(arg, ast.Name) and arg.id == 'USE_LUNACY_TAB':
|
||||
offenders.append('line %d' % node.lineno)
|
||||
if isinstance(arg, ast.Subscript) and \
|
||||
getattr(arg.value, 'id', None) == 'USE_LUNACY_TAB':
|
||||
offenders.append('line %d' % node.lineno)
|
||||
self.assertFalse(offenders, 'click() 用到了 Use Lunacy 页签坐标: ' + ', '.join(offenders))
|
||||
|
||||
def test_the_constant_still_exists_and_is_where_we_think(self):
|
||||
"""万一布局变了, 这条会提醒重新量坐标, 而不是让上面那条静静地失效。"""
|
||||
self.assertEqual(cm.USE_LUNACY_TAB, (797, 283))
|
||||
self.assertLess(cm.TAB_MODULES[0], cm.USE_LUNACY_TAB[0]) # Modules 在左
|
||||
self.assertLess(cm.USE_LUNACY_TAB[0], cm.TAB_USE_BOXES[0]) # Use Boxes 在右
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user