合成: 修掉一个会误触 Inventory 的坐标, 并把"能点到哪里"钉死

Browse Source
这轮做静态审计: 把脚本里所有输入调用列出来逐个确认安全(用户的两条硬约束就靠
这几个坐标)。全脚本只有 7 处, 审查面很小, 结果查出第 383 行有问题:

    click(800, 830)     # wait_main_menu 里推进标题/剧情/公告用的

对照之前 dump 的底栏 OCR:
    Inventory @(759,834) w=91    -> 跨度 759~850

(800,830) 正好落在 Inventory 按钮里。wait_main_menu 每轮虽然都先检查"是不是主界面"
再点击, 但画面恰在这一瞬切过去的话, 这一下就点在 Inventory 上了 —— 后果不重
(只是开个背包), 却会让循环卡在一个预期之外的界面上, 白等一轮。

改成 (800, 450)(屏幕中央): 任何界面上都无害, 一样能推进剧情。

并加 SafeClickTargetsTest 钉死这件事:
  * 裸坐标的 click/long_press 必须在白名单里(目前只有两个), 新增的会被拦下
  * 推进用的点击 y 必须 < 780, 不能落在底栏区

验证: 故意把坐标改回 (800,830), 两条测试分别报
"830 not less than 780: line 387 的点击落在底栏区" 和
"出现了未经审查的裸坐标点击: line 387: click(800, 830)"; 还原后通过。

全套 313/313 通过。
This commit is contained in:
Codex Agent
2026-10-16 12:11:59 +08:00
parent ce35d6191e
commit 6a8ba0e4bc
2 changed files with 70 additions and 2 deletions
+64
View File
@@ -514,6 +514,70 @@ class NoRealReportPollutionTest(unittest.TestCase):
+ ', '.join(offenders)) + ', '.join(offenders))
class SafeClickTargetsTest(QuietLogMixin, unittest.TestCase):
"""脚本能点到的地方必须逐个安全 —— 用户的两条硬约束就靠这几个坐标。
整个脚本只有 7 处输入调用(其余全在合成面板内部或底栏模组图标上), 所以这个
审查面很小, 值得把它钉死: 任何新增的裸坐标点击都要有明确的理由。
"""
SAFE_LITERALS = {
(800, 450): '屏幕中央, 推进标题/剧情/公告 —— 任何界面上都无害',
(656, 670): 'BTN_CANCEL, 只关面板',
}
def _calls(self):
import ast
src = (Path(__file__).resolve().parents[1] / 'scripts' / 'convert_modules.py') \
.read_text(encoding='utf-8')
out = []
for node in ast.walk(ast.parse(src)):
if isinstance(node, ast.Call):
name = getattr(node.func, 'id', None) or getattr(node.func, 'attr', None)
if name in ('click', 'long_press'):
out.append(node)
return out
def test_literal_click_coordinates_are_whitelisted(self):
import ast
bad = []
for node in self._calls():
if len(node.args) != 2:
continue # click(*CONST) 形式, 由常量保证
vals = []
for a in node.args:
if isinstance(a, ast.Constant) and isinstance(a.value, int):
vals.append(a.value)
else:
vals = None
break
if not vals:
continue
if tuple(vals) not in self.SAFE_LITERALS:
bad.append('line %d: click(%d, %d)' % (node.lineno, *vals))
self.assertFalse(bad,
'出现了未经审查的裸坐标点击, 请先确认它不会误触:\n '
+ '\n '.join(bad))
def test_advance_click_is_not_on_the_bottom_bar(self):
"""推进用的点击不能落在底栏 —— 那里有 Inventory 等按钮。
⛔ 曾经用 (800,830), 而 Inventory 按钮实测是 @(759,834) w=91(跨度 759~850),
正好把它包住。画面恰在检查与点击之间切到主界面时就会误触。
"""
import ast
for node in self._calls():
if len(node.args) != 2:
continue
try:
x = node.args[0].value
y = node.args[1].value
except AttributeError:
continue
self.assertLess(y, 780,
'line %d 的点击在 y=%d, 落在底栏区(>=780)' % (node.lineno, y))
class NoDeadConstantsTest(unittest.TestCase): class NoDeadConstantsTest(unittest.TestCase):
"""顶层的全大写常量必须真的被用到。 """顶层的全大写常量必须真的被用到。