From 43e7b034ff7afb3e405b4c8a5a01ddadbebb4a5c Mon Sep 17 00:00:00 2001 From: Codex Agent Date: Fri, 16 Oct 2026 11:27:13 +0800 Subject: [PATCH] =?UTF-8?q?=E5=80=BC=E5=AE=88:=20=E7=8B=82=E6=B0=94?= =?UTF-8?q?=E8=AF=BB=E6=95=B0=E8=BF=9B=E6=8A=A5=E5=91=8A=20+=20=E5=A0=B5?= =?UTF-8?q?=E4=BD=8F=E6=B5=8B=E8=AF=95=E5=BE=80=E6=8A=A5=E5=91=8A=E7=9B=AE?= =?UTF-8?q?=E5=BD=95=E5=86=99=E5=81=87=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 一、狂气读数写进 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 通过。 --- scripts/convert_modules.py | 4 ++++ scripts/modules_status.py | 32 ++++++++++++++++++++++------ tests/test_convert_modules.py | 39 +++++++++++++++++++++++++++++++++- tests/test_modules_status.py | 40 +++++++++++++++++++++++++++++++++++ 4 files changed, 108 insertions(+), 7 deletions(-) diff --git a/scripts/convert_modules.py b/scripts/convert_modules.py index 5cca04e..4dc4c94 100644 --- a/scripts/convert_modules.py +++ b/scripts/convert_modules.py @@ -579,6 +579,10 @@ def main(argv=None): % (lunacy_before, lunacy_after)) else: log('狂气校验: OK (前后读数一致 %s)' % lunacy_after) + # 记进报告: 值守看的是报告, 狂气读数不能只留在日志文本里 + _result['lunacy_before'] = lunacy_before + _result['lunacy_after'] = lunacy_after + _result['lunacy_checked'] = (lunacy_before is not None and lunacy_after is not None) if not args.keep_game: close_game() diff --git a/scripts/modules_status.py b/scripts/modules_status.py index a497eff..7e1842a 100644 --- a/scripts/modules_status.py +++ b/scripts/modules_status.py @@ -39,17 +39,33 @@ def summarize(rows): for r in rows: steps = r.get('steps') or [] conv = steps[0] if steps else {} + lb, la = r.get('lunacy_before'), r.get('lunacy_after') + checked = r.get('lunacy_checked') + if checked is None: # 老报告没这个字段 + checked = lb is not None and la is not None out.append({ 'started': r.get('started', '?'), 'ok': bool(r.get('ok')), 'result': r.get('result', ''), 'elapsed_s': r.get('elapsed_s'), 'info': conv.get('info', ''), + 'lunacy_before': lb, + 'lunacy_after': la, + 'lunacy_checked': bool(checked), 'lunacy_alarm': '狂气读数发生变化' in (r.get('result') or ''), }) return out +def lunacy_cell(r): + """狂气那格的显示。没比对上时明说, 不装作校过了。""" + if r['lunacy_alarm']: + return '⚠️ %s -> %s' % (r['lunacy_before'], r['lunacy_after']) + if not r['lunacy_checked']: + return '未比对' + return '%s 前后一致' % r['lunacy_after'] + + def fmt_secs(s): if s is None: return '-' @@ -81,13 +97,17 @@ def main(argv=None): got = sum(1 for r in rows if '+1' in r['info'] or '模组' in r['info'] and '->' in r['info']) fails = [r for r in rows if not r['ok']] alarms = [r for r in rows if r['lunacy_alarm']] + unchecked = [r for r in rows if not r['lunacy_checked']] - print('共 %d 轮: 换到模块 %d 轮, 失败 %d 轮, 狂气告警 %d 轮' - % (len(rows), got, len(fails), len(alarms))) + print('共 %d 轮: 换到模块 %d 轮, 失败 %d 轮, 狂气告警 %d 轮, 未比对 %d 轮' + % (len(rows), got, len(fails), len(alarms), len(unchecked))) if alarms: print('⚠️ 有狂气告警, 需要人工核查:') for r in alarms: print(' %s %s' % (r['started'], r['result'])) + if unchecked and not alarms: + print(' 提示: 有 %d 轮没读到狂气(前后至少一次是 None), 那几轮等于没校过。' + % len(unchecked)) # 连着失败(最新几条都不是好结果)要醒目 —— 那说明流程坏了 streak = 0 for r in rows: @@ -98,12 +118,12 @@ def main(argv=None): print('⚠️ 连续 %d 轮不成功, 可能是流程问题而不是资源不足' % streak) print() - print('%-19s %-4s %-7s %s' % ('时间', 'OK', '耗时', '结果')) - print('-' * 100) + print('%-19s %-4s %-7s %-18s %s' % ('时间', 'OK', '耗时', '狂气', '结果')) + print('-' * 110) for r in rows: - print('%-19s %-4s %-7s %s' + print('%-19s %-4s %-7s %-18s %s' % (r['started'], '✅' if r['ok'] else '❌', fmt_secs(r['elapsed_s']), - (r['result'] or r['info'])[:70])) + lunacy_cell(r), (r['result'] or r['info'])[:56])) return 0 diff --git a/tests/test_convert_modules.py b/tests/test_convert_modules.py index 72ce967..b1433aa 100644 --- a/tests/test_convert_modules.py +++ b/tests/test_convert_modules.py @@ -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 页签的坐标只能用于"确认没点到它", 不能出现在任何点击路径上。 diff --git a/tests/test_modules_status.py b/tests/test_modules_status.py index 331edd9..136add1 100644 --- a/tests/test_modules_status.py +++ b/tests/test_modules_status.py @@ -59,5 +59,45 @@ class SummarizeTest(unittest.TestCase): self.assertEqual(ms.fmt_secs(None), '-') +class LunacyColumnTest(unittest.TestCase): + """狂气读数要进报告, 并在汇总里单列一栏。 + + JSON 里原先只有一句 result 文本, 狂气读数只留在 convert.log 里 —— 值守看的是 + 报告, 而"前后读数是否一致"恰恰是最该一眼看到的一项。 + """ + + def test_checked_run_shows_agreement(self): + r = ms.summarize([{'started': 'x', 'ok': True, 'result': 'r', 'elapsed_s': 10, + 'lunacy_before': 9699, 'lunacy_after': 9699, + 'lunacy_checked': True}])[0] + self.assertTrue(r['lunacy_checked']) + self.assertIn('9699', ms.lunacy_cell(r)) + + def test_unchecked_run_says_so(self): + r = ms.summarize([{'started': 'x', 'ok': True, 'result': 'r', 'elapsed_s': 10, + 'lunacy_before': None, 'lunacy_after': 9699, + 'lunacy_checked': False}])[0] + self.assertFalse(r['lunacy_checked']) + # 不能装作校过了 + self.assertEqual(ms.lunacy_cell(r), '未比对') + + def test_alarm_is_visible_in_the_cell(self): + r = ms.summarize([{'started': 'x', 'ok': False, + 'result': '⚠️ 狂气读数发生变化 9699 -> 6300, 立即停止并人工核查', + 'elapsed_s': 10, 'lunacy_before': 9699, 'lunacy_after': 6300, + 'lunacy_checked': True}])[0] + self.assertTrue(r['lunacy_alarm']) + self.assertIn('⚠️', ms.lunacy_cell(r)) + + def test_old_reports_without_the_field_are_inferred(self): + # 老报告没有 lunacy_checked, 要按读数推 + r = ms.summarize([{'started': 'x', 'ok': True, 'result': 'r', 'elapsed_s': 10, + 'lunacy_before': 6636, 'lunacy_after': 6636}])[0] + self.assertTrue(r['lunacy_checked']) + r2 = ms.summarize([{'started': 'y', 'ok': True, 'result': 'r', + 'elapsed_s': 10}])[0] + self.assertFalse(r2['lunacy_checked']) + + if __name__ == '__main__': unittest.main()