值守: 狂气读数进报告 + 堵住测试往报告目录写假记录

Browse Source
一、狂气读数写进 JSON(原先只在 convert.log 文本里)
   报告加 lunacy_before / lunacy_after / lunacy_checked 三个字段。
   值守看的是报告, 而"前后读数是否一致"恰恰是最该一眼看到的一项。
   modules_status.py 据此多了一栏: 一致显示 "N 前后一致", 没比对上明写
   "未比对", 告警显示 "⚠️ A -> B"; 开头统计也加了"未比对 N 轮"。

二、⛔ 测试在往真实报告目录里写假记录(实测已产生 7 条)
   EnkephalinGateTest 调 cm.main() 时没指 --report-dir, 于是往
   ~/lc_mcp/modules/convert_*.json 里写了一批 elapsed_s=0、内容为
   "读不到体力读数"的记录。值守翻报告时会以为真出过这些事。
   日志那边上次用 QuietLogMixin 堵住了, 报告这边漏了 —— 同一类问题的另一面。

   修法: main() 调用一律带 --report-dir 指向临时目录; 再加一条 AST 检查
   (NoRealReportPollutionTest), 以后谁再漏就红。
   已清掉那 7 条假记录, 验证: 跑完测试报告数 6 -> 6 不变。

三、实跑汇总立刻见效: 现有 6 份报告全部显示"未比对" —— 因为它们都是
   "LUNACY 被 OCR 读成 UNACY"那个 bug 修好之前跑的, 等于没校过。这正是
   这一栏存在的意义: 把"看起来校过了"和"真的校过了"分开。

全套 282/282 通过。
This commit is contained in:
Codex Agent
2026-10-16 11:27:13 +08:00
parent 21f84473ba
commit 43e7b034ff
4 changed files with 108 additions and 7 deletions
+38 -1
View File
@@ -4,7 +4,9 @@
这个脚本会操作真实游戏, 所以这里只测不碰硬件的部分: 屏幕判定、资源读数、
狂气相对比对用的解析。合成动作本身靠实机验证。
"""
import shutil
import sys
import tempfile
import unittest
from pathlib import Path
from unittest import mock
@@ -160,11 +162,17 @@ class EnkephalinGateTest(QuietLogMixin, unittest.TestCase):
单次读成 None 的话, 原来那层"体力不足就收工"的判断会被整个跳过 —— 于是明明
只是体力不够, 却要去点合成、最后报成 FAIL(退出码 1), 给值守留下一条误导性
的失败记录。底栏淡入时读不到是实测发生过的(2026-10-16 11:01 的狂气读数)。
⛔ main() 会把报告写进 ~/lc_mcp/modules/convert_*.json —— 那是值守要看的历史。
调用时必须把 --report-dir 指到临时目录, 否则测试会伪造出一批
"读不到体力读数" 的假记录(实测已经产生过 7 条)。
"""
def _main(self, enk_seq):
seq = list(enk_seq)
called = []
tmp = tempfile.mkdtemp()
self.addCleanup(shutil.rmtree, tmp, True)
with mock.patch.object(cm, 'read_enkephalin', lambda: seq.pop(0) if seq else None), \
mock.patch.object(cm, 'read_lunacy', lambda **k: 9699), \
mock.patch.object(cm, 'ensure_server', lambda *a: True), \
@@ -178,7 +186,7 @@ class EnkephalinGateTest(QuietLogMixin, unittest.TestCase):
lambda tries=2: (called.append(1),
(True, '模组 29 -> 30 (+1)', 1))[1]), \
mock.patch.object(cm.time, 'sleep', lambda s: None):
code = cm.main([])
code = cm.main(['--report-dir', tmp])
return code, bool(called)
def test_enough_enkephalin_goes_ahead(self):
@@ -382,6 +390,35 @@ class ServerBootstrapTest(QuietLogMixin, unittest.TestCase):
self.assertEqual(cm.SERVER_PORT, 8765)
class NoRealReportPollutionTest(unittest.TestCase):
"""测试不许往真实报告目录里写东西。
⛔ 实测: EnkephalinGateTest 调 main() 时没指 --report-dir, 于是往
~/lc_mcp/modules/convert_*.json 里写了一批 elapsed_s=0 的假记录
(内容是"读不到体力读数"), 一共 7 条。值守看报告时会以为真出过这些事。
日志那边已经用 QuietLogMixin 堵住了, 报告这边靠这条 AST 检查兜住。
"""
def test_every_main_call_passes_report_dir(self):
import ast
src = Path(__file__).read_text(encoding='utf-8')
tree = ast.parse(src)
offenders = []
for node in ast.walk(tree):
if not isinstance(node, ast.Call):
continue
f = node.func
if (getattr(f, 'attr', None) != 'main' or
getattr(getattr(f, 'value', None), 'id', None) != 'cm'):
continue
flat = ast.dump(node)
if 'report-dir' not in flat:
offenders.append('line %d' % node.lineno)
self.assertFalse(offenders,
'cm.main() 没带 --report-dir, 会写进真实报告目录: '
+ ', '.join(offenders))
class ForbiddenCoordinateTest(QuietLogMixin, unittest.TestCase):
"""Use Lunacy 页签的坐标只能用于"确认没点到它", 不能出现在任何点击路径上。