修复运行日志复核发现的任务控制与结果误判
This commit is contained in:
+126
-11
@@ -1,5 +1,7 @@
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
import json
|
||||||
import sys
|
import sys
|
||||||
|
import tempfile
|
||||||
import unittest
|
import unittest
|
||||||
from unittest import mock
|
from unittest import mock
|
||||||
|
|
||||||
@@ -54,6 +56,7 @@ class RunAalcTest(unittest.TestCase):
|
|||||||
|
|
||||||
def run_aalc(self, mcp, **kw):
|
def run_aalc(self, mcp, **kw):
|
||||||
with mock.patch.object(auto_cycle, 'probe', mcp.probe), \
|
with mock.patch.object(auto_cycle, 'probe', mcp.probe), \
|
||||||
|
mock.patch.object(auto_cycle, 'blocking_module_modal', return_value=None), \
|
||||||
mock.patch.object(auto_cycle, 'log', lambda m: None):
|
mock.patch.object(auto_cycle, 'log', lambda m: None):
|
||||||
return auto_cycle.run_aalc('daily', {}, 3600, sleep=lambda s: None, **kw)
|
return auto_cycle.run_aalc('daily', {}, 3600, sleep=lambda s: None, **kw)
|
||||||
|
|
||||||
@@ -62,9 +65,12 @@ class RunAalcTest(unittest.TestCase):
|
|||||||
clock = FakeTime(step)
|
clock = FakeTime(step)
|
||||||
patches = [mock.patch.object(auto_cycle, 'probe', mcp.probe),
|
patches = [mock.patch.object(auto_cycle, 'probe', mcp.probe),
|
||||||
mock.patch.object(auto_cycle, 'log', lambda m: None),
|
mock.patch.object(auto_cycle, 'log', lambda m: None),
|
||||||
mock.patch.object(auto_cycle.time, 'time', clock.time)]
|
mock.patch.object(auto_cycle.time, 'time', clock.time),
|
||||||
|
mock.patch.object(auto_cycle, 'clear_blocking_modal', return_value='已发送 Cancel')]
|
||||||
if clear is not None:
|
if clear is not None:
|
||||||
patches.append(mock.patch.object(auto_cycle, 'clear_blocking_modal', clear))
|
patches.append(mock.patch.object(auto_cycle, 'blocking_module_modal', clear))
|
||||||
|
else:
|
||||||
|
patches.append(mock.patch.object(auto_cycle, 'blocking_module_modal', return_value=None))
|
||||||
for p in patches:
|
for p in patches:
|
||||||
p.start()
|
p.start()
|
||||||
try:
|
try:
|
||||||
@@ -108,11 +114,11 @@ class RunAalcTest(unittest.TestCase):
|
|||||||
self.assertFalse(ok)
|
self.assertFalse(ok)
|
||||||
self.assertEqual(info, 'RESOURCE_OUT')
|
self.assertEqual(info, 'RESOURCE_OUT')
|
||||||
self.assertFalse(stalled)
|
self.assertFalse(stalled)
|
||||||
# 只清了 RESOURCE_OUT_LIMIT 次就停, 而不是一路点到超时
|
# 连续观察到 RESOURCE_OUT_LIMIT 次就停, 不在任务运行时点击
|
||||||
self.assertIn('stop_task', self.tools(mcp))
|
self.assertIn('stop_task', self.tools(mcp))
|
||||||
|
|
||||||
def test_occasional_modal_does_not_end_the_task(self):
|
def test_occasional_modal_does_not_end_the_task(self):
|
||||||
"""偶发一次模态框不该收工 —— 点掉继续跑才对。"""
|
"""偶发一次模态框不该收工, 继续观察任务。"""
|
||||||
seq = ['x']
|
seq = ['x']
|
||||||
mcp = FakeMcp()
|
mcp = FakeMcp()
|
||||||
mcp.current = [RUNNING]
|
mcp.current = [RUNNING]
|
||||||
@@ -122,6 +128,33 @@ class RunAalcTest(unittest.TestCase):
|
|||||||
# 跑到超时收工, 而不是被当成资源耗尽
|
# 跑到超时收工, 而不是被当成资源耗尽
|
||||||
self.assertIn('超时', info)
|
self.assertIn('超时', info)
|
||||||
|
|
||||||
|
def test_separate_shortage_sightings_are_not_consecutive(self):
|
||||||
|
seq = iter(['x', None, 'x', None, 'x', None])
|
||||||
|
mcp = FakeMcp()
|
||||||
|
mcp.current = [RUNNING] * 6 + [DONE]
|
||||||
|
ok, info, _ = self.poll(mcp, 3600, clear=lambda: next(seq))
|
||||||
|
self.assertTrue(ok, info)
|
||||||
|
self.assertNotIn('stop_task', self.tools(mcp))
|
||||||
|
|
||||||
|
def test_failed_stop_prevents_retry(self):
|
||||||
|
mcp = FakeMcp([STALL, STALL], [DONE])
|
||||||
|
original = mcp.probe
|
||||||
|
|
||||||
|
def probe(tool, args=None):
|
||||||
|
result = original(tool, args)
|
||||||
|
return {'ok': False, 'error': '进程未退出'} if tool == 'stop_task' else result
|
||||||
|
|
||||||
|
mcp.probe = probe
|
||||||
|
with self.assertRaisesRegex(RuntimeError, '停止 AALC 任务失败'):
|
||||||
|
self.run_aalc(mcp)
|
||||||
|
self.assertEqual(self.tools(mcp), ['run_task', 'stop_task'])
|
||||||
|
|
||||||
|
def test_status_error_stops_the_task_before_reporting_failure(self):
|
||||||
|
mcp = FakeMcp([{'ok': False, 'error': '连接中断'}])
|
||||||
|
with self.assertRaisesRegex(RuntimeError, '无法读取任务状态'):
|
||||||
|
self.run_aalc(mcp)
|
||||||
|
self.assertEqual(self.tools(mcp), ['run_task', 'stop_task'])
|
||||||
|
|
||||||
def test_preflight_failure_is_not_retried(self):
|
def test_preflight_failure_is_not_retried(self):
|
||||||
failed = {'state': 'failed', 'exit_code': 3,
|
failed = {'state': 'failed', 'exit_code': 3,
|
||||||
'errors': ['[ERROR] [lc_mcp] preflight: 队伍 1 的 sinner_order 没有罪人']}
|
'errors': ['[ERROR] [lc_mcp] preflight: 队伍 1 的 sinner_order 没有罪人']}
|
||||||
@@ -177,9 +210,8 @@ class BlockingModalTest(unittest.TestCase):
|
|||||||
|
|
||||||
2026-10-13 实测: 模组不足时游戏弹
|
2026-10-13 实测: 模组不足时游戏弹
|
||||||
"You don't have enough Enkephalin Modules. / Would you like to go assemble some?"
|
"You don't have enough Enkephalin Modules. / Would you like to go assemble some?"
|
||||||
AALC 的 Luxcavation 流程不认它, 一直在后面点被挡住的 Enter 按钮, 每次卡满
|
AALC 的 Luxcavation 流程不认它, 一直在后面点被挡住的 Enter 按钮。
|
||||||
10 分钟才被 no_progress 判据救回来。清道夫点 Cancel 之后 AALC 就能继续降级
|
连续观察到缺资源后先停止任务, 再重新识别并点 Cancel。
|
||||||
试下一关。
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
MODAL = [{'text': "You don't have enough Enkephalin Modules.", 'x': 554, 'y': 404, 'w': 460, 'h': 24},
|
MODAL = [{'text': "You don't have enough Enkephalin Modules.", 'x': 554, 'y': 404, 'w': 460, 'h': 24},
|
||||||
@@ -190,7 +222,8 @@ class BlockingModalTest(unittest.TestCase):
|
|||||||
def test_clicks_cancel_centre(self):
|
def test_clicks_cancel_centre(self):
|
||||||
clicked = []
|
clicked = []
|
||||||
with mock.patch.object(auto_cycle, 'items', lambda: list(self.MODAL)), \
|
with mock.patch.object(auto_cycle, 'items', lambda: list(self.MODAL)), \
|
||||||
mock.patch.object(auto_cycle, 'click', lambda x, y: clicked.append((x, y))):
|
mock.patch.object(auto_cycle, 'click',
|
||||||
|
lambda x, y: (clicked.append((x, y)) or {'ok': True})):
|
||||||
msg = auto_cycle.clear_blocking_modal()
|
msg = auto_cycle.clear_blocking_modal()
|
||||||
self.assertIn('Cancel', msg)
|
self.assertIn('Cancel', msg)
|
||||||
# 点的是识别框中心, 不是左上角 —— 实测点左上角常常落空
|
# 点的是识别框中心, 不是左上角 —— 实测点左上角常常落空
|
||||||
@@ -201,7 +234,8 @@ class BlockingModalTest(unittest.TestCase):
|
|||||||
grid = [{'text': 'TEAMS#1', 'x': 100, 'y': 300},
|
grid = [{'text': 'TEAMS#1', 'x': 100, 'y': 300},
|
||||||
{'text': 'IDENTITIES', 'x': 200, 'y': 300}]
|
{'text': 'IDENTITIES', 'x': 200, 'y': 300}]
|
||||||
with mock.patch.object(auto_cycle, 'items', lambda: grid), \
|
with mock.patch.object(auto_cycle, 'items', lambda: grid), \
|
||||||
mock.patch.object(auto_cycle, 'click', lambda x, y: clicked.append((x, y))):
|
mock.patch.object(auto_cycle, 'click',
|
||||||
|
lambda x, y: (clicked.append((x, y)) or {'ok': True})):
|
||||||
self.assertIsNone(auto_cycle.clear_blocking_modal())
|
self.assertIsNone(auto_cycle.clear_blocking_modal())
|
||||||
self.assertEqual(clicked, [])
|
self.assertEqual(clicked, [])
|
||||||
|
|
||||||
@@ -211,13 +245,77 @@ class BlockingModalTest(unittest.TestCase):
|
|||||||
{'text': 'Cancel', 'x': 30, 'y': 40, 'w': 10, 'h': 10}]
|
{'text': 'Cancel', 'x': 30, 'y': 40, 'w': 10, 'h': 10}]
|
||||||
clicked = []
|
clicked = []
|
||||||
with mock.patch.object(auto_cycle, 'items', lambda: modal), \
|
with mock.patch.object(auto_cycle, 'items', lambda: modal), \
|
||||||
mock.patch.object(auto_cycle, 'click', lambda x, y: clicked.append((x, y))):
|
mock.patch.object(auto_cycle, 'click',
|
||||||
|
lambda x, y: (clicked.append((x, y)) or {'ok': True})):
|
||||||
self.assertIsNotNone(auto_cycle.clear_blocking_modal())
|
self.assertIsNotNone(auto_cycle.clear_blocking_modal())
|
||||||
self.assertEqual(clicked, [(35, 45)])
|
self.assertEqual(clicked, [(35, 45)])
|
||||||
|
|
||||||
|
def test_rejected_click_is_not_reported_as_cleared(self):
|
||||||
|
with mock.patch.object(auto_cycle, 'items', return_value=self.MODAL), \
|
||||||
|
mock.patch.object(auto_cycle, 'click', return_value={'ok': False, 'error': '先 stop_task'}):
|
||||||
|
with self.assertRaisesRegex(RuntimeError, '先 stop_task'):
|
||||||
|
auto_cycle.clear_blocking_modal()
|
||||||
|
|
||||||
|
def test_real_protocol_receives_cancel_only_after_task_stops(self):
|
||||||
|
# 使用真实 Server 的输入互斥逻辑, 避免假 click 掩盖“运行中点击被拒绝”。
|
||||||
|
from lc_mcp.fake_engine import FakeEngine
|
||||||
|
from lc_mcp.protocol import Server
|
||||||
|
runner = mock.Mock()
|
||||||
|
runner.info = {'task': 'daily'}
|
||||||
|
runner.running.return_value = True
|
||||||
|
runner.status.return_value = {'ok': True, 'state': 'running'}
|
||||||
|
|
||||||
|
def stop():
|
||||||
|
runner.running.return_value = False
|
||||||
|
return {'ok': True, 'state': 'stopped'}
|
||||||
|
|
||||||
|
runner.stop.side_effect = stop
|
||||||
|
engine = FakeEngine(frames=[self.MODAL])
|
||||||
|
server = Server(engine, runner)
|
||||||
|
click_states = []
|
||||||
|
|
||||||
|
def click(x, y):
|
||||||
|
click_states.append(runner.running())
|
||||||
|
return server.call_tool('click', {'x': x, 'y': y})
|
||||||
|
|
||||||
|
with mock.patch.object(auto_cycle, 'probe', lambda tool, args=None: server.call_tool(tool, args or {})), \
|
||||||
|
mock.patch.object(auto_cycle, 'items', lambda: server.call_tool('get_state', {})['items']), \
|
||||||
|
mock.patch.object(auto_cycle, 'click', click), \
|
||||||
|
mock.patch.object(auto_cycle, 'log'), \
|
||||||
|
mock.patch.object(auto_cycle.time, 'time', FakeTime().time):
|
||||||
|
ok, info, stalled = auto_cycle.poll_task('daily', 3600, sleep=lambda s: None)
|
||||||
|
self.assertEqual((ok, info, stalled), (False, 'RESOURCE_OUT', False))
|
||||||
|
self.assertEqual(click_states, [False])
|
||||||
|
self.assertEqual(engine.actions, [('click', 637, 612, 1)])
|
||||||
|
runner.stop.assert_called_once()
|
||||||
|
|
||||||
|
|
||||||
|
class CycleReportTest(unittest.TestCase):
|
||||||
|
|
||||||
|
def test_crashed_levelup_is_a_failed_report_with_diagnostics(self):
|
||||||
|
with tempfile.TemporaryDirectory() as tmp:
|
||||||
|
script = Path(tmp, 'broken_levelup.py')
|
||||||
|
script.write_text('raise RuntimeError("levelup crashed")\n', encoding='utf-8')
|
||||||
|
with mock.patch.multiple(auto_cycle, PY=sys.executable, LEVELUP=str(script)), \
|
||||||
|
mock.patch.object(auto_cycle, 'lunacy_guard', return_value=(True, '读数一致')), \
|
||||||
|
mock.patch.object(auto_cycle, 'ensure_team1', return_value=True), \
|
||||||
|
mock.patch.object(auto_cycle, 'run_aalc', return_value=(True, '已完成')), \
|
||||||
|
mock.patch.object(auto_cycle, 'goto_identities', return_value=True), \
|
||||||
|
mock.patch.object(auto_cycle, 'report_grid', return_value='grid'), \
|
||||||
|
mock.patch.object(auto_cycle.time, 'sleep'), \
|
||||||
|
mock.patch('builtins.print'):
|
||||||
|
code = auto_cycle.main(['--report-dir', tmp])
|
||||||
|
report = json.loads(next(Path(tmp).glob('cycle_*.json')).read_text(encoding='utf-8'))
|
||||||
|
output = next(Path(tmp).glob('cycle_*.log')).read_text(encoding='utf-8')
|
||||||
|
self.assertEqual(code, 1)
|
||||||
|
self.assertFalse(report['ok'])
|
||||||
|
self.assertIn('levelup crashed', output)
|
||||||
|
self.assertNotIn('无需升级', output)
|
||||||
|
self.assertIsNone(auto_cycle._log_file)
|
||||||
|
|
||||||
|
|
||||||
class LunacyReadTest(unittest.TestCase):
|
class LunacyReadTest(unittest.TestCase):
|
||||||
"""狂气校验是"不许消费"的唯一防线, 读不到就是没校验, 所以要重试。
|
"""狂气 OCR 是辅助核查, 读不到就是没校验, 所以要重试。
|
||||||
|
|
||||||
2026-10-13 实测更麻烦的一种情况: 同一个画面上 OCR 会给出**两个不同的值**
|
2026-10-13 实测更麻烦的一种情况: 同一个画面上 OCR 会给出**两个不同的值**
|
||||||
(放大 6 倍肉眼确认余额是 6388, 而连读 5 次得到 6388 四次、8859 一次)。
|
(放大 6 倍肉眼确认余额是 6388, 而连读 5 次得到 6388 四次、8859 一次)。
|
||||||
@@ -250,6 +348,23 @@ class LunacyReadTest(unittest.TestCase):
|
|||||||
mock.patch.object(auto_cycle.time, 'sleep', lambda s: None):
|
mock.patch.object(auto_cycle.time, 'sleep', lambda s: None):
|
||||||
self.assertEqual(auto_cycle.read_lunacy(), 6388)
|
self.assertEqual(auto_cycle.read_lunacy(), 6388)
|
||||||
|
|
||||||
|
def test_first_pair_does_not_override_later_majority(self):
|
||||||
|
with mock.patch.object(auto_cycle, 'items', self._frames([8859, 8859, 6388, 6388, 6388])), \
|
||||||
|
mock.patch.object(auto_cycle.time, 'sleep'):
|
||||||
|
self.assertEqual(auto_cycle.read_lunacy(), 6388)
|
||||||
|
|
||||||
|
def test_tied_readings_are_unknown(self):
|
||||||
|
with mock.patch.object(auto_cycle, 'items', self._frames([8859, 8859, 6388, 6388, None])), \
|
||||||
|
mock.patch.object(auto_cycle.time, 'sleep'):
|
||||||
|
self.assertIsNone(auto_cycle.read_lunacy())
|
||||||
|
|
||||||
|
def test_truncated_label_and_low_balance_are_read(self):
|
||||||
|
frame = [{'text': 'UNACY', 'x': 671, 'y': 795},
|
||||||
|
{'text': '0', 'x': 664, 'y': 823}]
|
||||||
|
with mock.patch.object(auto_cycle, 'items', return_value=frame), \
|
||||||
|
mock.patch.object(auto_cycle.time, 'sleep'):
|
||||||
|
self.assertEqual(auto_cycle.read_lunacy(), 0)
|
||||||
|
|
||||||
def test_retries_until_the_label_shows_up(self):
|
def test_retries_until_the_label_shows_up(self):
|
||||||
with mock.patch.object(auto_cycle, 'items', self._frames([None, None, 5864, 5864, 5864])), \
|
with mock.patch.object(auto_cycle, 'items', self._frames([None, None, 5864, 5864, 5864])), \
|
||||||
mock.patch.object(auto_cycle.time, 'sleep', lambda s: None):
|
mock.patch.object(auto_cycle.time, 'sleep', lambda s: None):
|
||||||
|
|||||||
@@ -131,11 +131,7 @@ class ReadEnkephalinTest(QuietLogMixin, unittest.TestCase):
|
|||||||
|
|
||||||
|
|
||||||
class LunacyReadTest(QuietLogMixin, unittest.TestCase):
|
class LunacyReadTest(QuietLogMixin, unittest.TestCase):
|
||||||
"""狂气数字是像素艺术字, OCR 会误读(实测 6636 读成 9699)。
|
"""狂气数字会有多种 OCR 误读; 同帧取数、多帧投票仍只提供核查线索。"""
|
||||||
|
|
||||||
所以脚本不对绝对值下结论, 只做**前后相对比对**: 同一个画面同一套字体,
|
|
||||||
误读方式一致, 两次读数不同就说明数字真的变了。
|
|
||||||
"""
|
|
||||||
|
|
||||||
def _frames(self, values):
|
def _frames(self, values):
|
||||||
seq = list(values)
|
seq = list(values)
|
||||||
@@ -156,6 +152,25 @@ class LunacyReadTest(QuietLogMixin, unittest.TestCase):
|
|||||||
mock.patch.object(cm.time, 'sleep', lambda s: None):
|
mock.patch.object(cm.time, 'sleep', lambda s: None):
|
||||||
self.assertIsNone(cm.read_lunacy())
|
self.assertIsNone(cm.read_lunacy())
|
||||||
|
|
||||||
|
def test_first_pair_does_not_override_later_majority(self):
|
||||||
|
with mock.patch.object(cm, 'items', self._frames([8859, 8859, 6388, 6388, 6388])), \
|
||||||
|
mock.patch.object(cm.time, 'sleep'):
|
||||||
|
self.assertEqual(cm.read_lunacy(), 6388)
|
||||||
|
|
||||||
|
def test_label_and_balance_must_come_from_the_same_frame(self):
|
||||||
|
# 数字和标签从未同时出现, 跨帧拼接会伪造一个有效读数。
|
||||||
|
frames = [[{'text': '9999', 'x': 664, 'y': 823}],
|
||||||
|
[{'text': 'LUNACY', 'x': 670, 'y': 795}]] * 5
|
||||||
|
with mock.patch.object(cm, 'items', side_effect=frames) as sample, \
|
||||||
|
mock.patch.object(cm.time, 'sleep'):
|
||||||
|
self.assertIsNone(cm.read_lunacy())
|
||||||
|
self.assertEqual(sample.call_count, 5)
|
||||||
|
|
||||||
|
def test_tied_readings_are_unknown(self):
|
||||||
|
with mock.patch.object(cm, 'items', self._frames([8859, 8859, 6388, 6388, 1000])), \
|
||||||
|
mock.patch.object(cm.time, 'sleep'):
|
||||||
|
self.assertIsNone(cm.read_lunacy())
|
||||||
|
|
||||||
|
|
||||||
class EnkephalinGateTest(QuietLogMixin, unittest.TestCase):
|
class EnkephalinGateTest(QuietLogMixin, unittest.TestCase):
|
||||||
"""体力读数是"要不要合成"的闸门, 读不到时不能贸然去点合成。
|
"""体力读数是"要不要合成"的闸门, 读不到时不能贸然去点合成。
|
||||||
@@ -305,6 +320,10 @@ class LunacyVerdictTest(unittest.TestCase):
|
|||||||
suspicious2, _ = cm.lunacy_verdict(4000, 3000)
|
suspicious2, _ = cm.lunacy_verdict(4000, 3000)
|
||||||
self.assertTrue(suspicious2)
|
self.assertTrue(suspicious2)
|
||||||
|
|
||||||
|
def test_new_balance_must_not_be_silently_folded_into_old_readings(self):
|
||||||
|
suspicious, _ = cm.lunacy_verdict(10000, 6636)
|
||||||
|
self.assertTrue(suspicious)
|
||||||
|
|
||||||
|
|
||||||
class LunacyFalseAlarmTest(QuietLogMixin, unittest.TestCase):
|
class LunacyFalseAlarmTest(QuietLogMixin, unittest.TestCase):
|
||||||
"""整轮跑下来: 已知读法抖动不该让这一轮 FAIL。"""
|
"""整轮跑下来: 已知读法抖动不该让这一轮 FAIL。"""
|
||||||
@@ -388,6 +407,13 @@ class ConvertAttemptVerifiedTest(QuietLogMixin, unittest.TestCase):
|
|||||||
self.assertFalse(ok)
|
self.assertFalse(ok)
|
||||||
self.assertIn('没变', info)
|
self.assertIn('没变', info)
|
||||||
|
|
||||||
|
def test_decrease_is_not_a_successful_negative_conversion(self):
|
||||||
|
seq = [35]
|
||||||
|
ok, info, got = self._attempt(lambda: seq.pop(0) if seq else 33)
|
||||||
|
self.assertFalse(ok)
|
||||||
|
self.assertEqual(got, 0)
|
||||||
|
self.assertIn('读数下降', info)
|
||||||
|
|
||||||
def test_unchanged_message_does_not_blame_enkephalin(self):
|
def test_unchanged_message_does_not_blame_enkephalin(self):
|
||||||
"""走到这一步时体力 >= 20 已经确认过, 所以"体力不足"不可能是原因。
|
"""走到这一步时体力 >= 20 已经确认过, 所以"体力不足"不可能是原因。
|
||||||
|
|
||||||
@@ -601,6 +627,14 @@ class CliRoutingTest(QuietLogMixin, unittest.TestCase):
|
|||||||
self.assertEqual(code, 0)
|
self.assertEqual(code, 0)
|
||||||
self.assertEqual(closed, [], '--keep-game 时不该关游戏')
|
self.assertEqual(closed, [], '--keep-game 时不该关游戏')
|
||||||
|
|
||||||
|
def test_a_skipped_run_does_not_reuse_previous_lunacy_result(self):
|
||||||
|
cm._result.update(lunacy_after=9699, lunacy_checked=True, converted=True)
|
||||||
|
code, _, _ = self._main([]) # 体力不足, 不合成也不做后读。
|
||||||
|
self.assertEqual(code, 0)
|
||||||
|
self.assertNotIn('lunacy_after', cm._result)
|
||||||
|
self.assertNotIn('lunacy_checked', cm._result)
|
||||||
|
self.assertFalse(cm._result['converted'])
|
||||||
|
|
||||||
def test_report_is_written_with_the_expected_fields(self):
|
def test_report_is_written_with_the_expected_fields(self):
|
||||||
"""报告字段要齐全 —— 值守就靠 lunacy_* 和 converted 那几项下结论。"""
|
"""报告字段要齐全 —— 值守就靠 lunacy_* 和 converted 那几项下结论。"""
|
||||||
import json
|
import json
|
||||||
|
|||||||
@@ -46,6 +46,40 @@ class ScaleTest(unittest.TestCase):
|
|||||||
self.assertEqual(calls, [('get_state', None), ('click', {'x': 120, 'y': 120, 'times': 1})])
|
self.assertEqual(calls, [('get_state', None), ('click', {'x': 120, 'y': 120, 'times': 1})])
|
||||||
|
|
||||||
|
|
||||||
|
class ProgressResultTest(unittest.TestCase):
|
||||||
|
|
||||||
|
def run_progress(self, detail=True, level=40, uptie=True):
|
||||||
|
card = (0, 0, 300, 400, 40, True, 'identity')
|
||||||
|
with mock.patch.object(levelup, 'state', return_value={'items': []}), \
|
||||||
|
mock.patch.object(levelup, 'scan_grid', return_value=[card]), \
|
||||||
|
mock.patch.object(levelup, 'dismiss_modal', return_value=True), \
|
||||||
|
mock.patch.object(levelup, 'long_press'), \
|
||||||
|
mock.patch.object(levelup, 'click'), \
|
||||||
|
mock.patch.object(levelup, 'detail_page_open', return_value=detail), \
|
||||||
|
mock.patch.object(levelup, 'read_detail', return_value=(level, 'identity', None)), \
|
||||||
|
mock.patch.object(levelup, 'do_level_up', return_value=(True, '等级增加')) as upgrade, \
|
||||||
|
mock.patch.object(levelup, 'do_uptie', return_value=(uptie, '同步结果')), \
|
||||||
|
mock.patch.object(levelup.time, 'sleep'), \
|
||||||
|
mock.patch('builtins.print'):
|
||||||
|
code = levelup.cmd_progress(target=34)
|
||||||
|
return code, upgrade.call_count
|
||||||
|
|
||||||
|
def test_unopened_details_are_not_a_successful_noop(self):
|
||||||
|
self.assertEqual(self.run_progress(detail=False), (1, 0))
|
||||||
|
|
||||||
|
def test_unreadable_details_do_not_trust_grid_level(self):
|
||||||
|
self.assertEqual(self.run_progress(level=None), (1, 0))
|
||||||
|
|
||||||
|
def test_verified_max_level_is_a_successful_noop(self):
|
||||||
|
self.assertEqual(self.run_progress(level=40), (0, 0))
|
||||||
|
|
||||||
|
def test_failed_uptie_is_a_failed_command(self):
|
||||||
|
self.assertEqual(self.run_progress(level=30, uptie=False), (1, 1))
|
||||||
|
|
||||||
|
def test_successful_upgrade_and_uptie(self):
|
||||||
|
self.assertEqual(self.run_progress(level=30), (0, 1))
|
||||||
|
|
||||||
|
|
||||||
class Screens:
|
class Screens:
|
||||||
"""按顺序返回预设画面的假 state(), 记录点击。"""
|
"""按顺序返回预设画面的假 state(), 记录点击。"""
|
||||||
|
|
||||||
|
|||||||
@@ -9,9 +9,11 @@ AALC 把镜牢入口误认成经验本界面, 把 home/luxcavation_assets.png
|
|||||||
修法是加一条与日志内容无关的判据: 里程碑(开始执行/结束执行)多久没前进。
|
修法是加一条与日志内容无关的判据: 里程碑(开始执行/结束执行)多久没前进。
|
||||||
"""
|
"""
|
||||||
import os
|
import os
|
||||||
|
import gzip
|
||||||
import tempfile
|
import tempfile
|
||||||
import time
|
import time
|
||||||
import unittest
|
import unittest
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
from lc_mcp import tasks
|
from lc_mcp import tasks
|
||||||
|
|
||||||
@@ -61,6 +63,13 @@ class NoProgressStall(unittest.TestCase):
|
|||||||
])
|
])
|
||||||
self.assertNotIn('no_progress', tasks.log_stalls(p))
|
self.assertNotIn('no_progress', tasks.log_stalls(p))
|
||||||
|
|
||||||
|
def test_frozen_log_does_not_freeze_stall_clock(self):
|
||||||
|
old = tasks.STALL_NO_PROGRESS_S + 120
|
||||||
|
p = self._make(['[INFO] %s [AALC] 开始执行 一次纽本' % _stamp(old)])
|
||||||
|
frozen = time.time() - old
|
||||||
|
os.utime(p, (frozen, frozen))
|
||||||
|
self.assertIn('no_progress', tasks.log_stalls(p))
|
||||||
|
|
||||||
def test_no_milestone_at_all_is_not_reported(self):
|
def test_no_milestone_at_all_is_not_reported(self):
|
||||||
"""一条里程碑都没有时不下结论(可能只是还没走到), 避免误杀启动阶段。"""
|
"""一条里程碑都没有时不下结论(可能只是还没走到), 避免误杀启动阶段。"""
|
||||||
p = self._make([
|
p = self._make([
|
||||||
@@ -86,6 +95,20 @@ class NoProgressStall(unittest.TestCase):
|
|||||||
self.assertGreater(os.path.getsize(p), 64 * 1024) # 确定超出了 tail() 的 64KB 窗口
|
self.assertGreater(os.path.getsize(p), 64 * 1024) # 确定超出了 tail() 的 64KB 窗口
|
||||||
self.assertIn('no_progress', tasks.log_stalls(p))
|
self.assertIn('no_progress', tasks.log_stalls(p))
|
||||||
|
|
||||||
|
def test_archived_windows_runs_distinguish_stalled_and_healthy_tasks(self):
|
||||||
|
root = Path(__file__).resolve().parents[1] / 'docs/feedback/2026-10-13/results/runs'
|
||||||
|
for name, stalled in [('task_20261013_124337_daily.log.gz', True),
|
||||||
|
('task_20261013_132845_daily.log.gz', False),
|
||||||
|
('task_20261013_135050_mirror.log.gz', False)]:
|
||||||
|
with self.subTest(log=name):
|
||||||
|
with gzip.open(root / name, 'rt', encoding='utf-8') as f:
|
||||||
|
lines = f.read().splitlines()
|
||||||
|
stamp = next(tasks.TIMESTAMP_RE.search(line).group(1)
|
||||||
|
for line in reversed(lines) if tasks.TIMESTAMP_RE.search(line))
|
||||||
|
observed_at = time.mktime(time.strptime(stamp, '%Y-%m-%d %H:%M:%S'))
|
||||||
|
path = self._make(lines)
|
||||||
|
self.assertEqual('no_progress' in tasks.log_stalls(path, now=observed_at), stalled)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|||||||
Reference in New Issue
Block a user