From 0650f9d0cb59fe6b5c48a01a7df0361ee3b24f33 Mon Sep 17 00:00:00 2001 From: bong-water-water-bong Date: Sat, 14 Nov 2026 22:24:08 -0400 Subject: [PATCH] Fixes #2464: strip comments from the text #2445's selftest_named reads MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #2460 made the gate require an invocation, and fixed `_statements()` counting parentheses inside comments. That covers every path that goes through `invokes()`. #2445 added one that does not: `selftest_named` runs a raw-text regex over `path.read_text()` — comments included — and it only ever REMOVES a finding. So a comment naming the tool silenced the check: ``` input: "# someday: tools/ci/helper.py --self-test" match: ['helper'] -> selftest_named gets helper_test.py -> the finding is dropped ``` One line: the test half collects `_strip_line_comments(path.read_text(...))`, the helper #2460 already added for exactly this. The tool half is untouched — it goes through `invokes()` -> `_statements()`, which strips comments itself. The arm is proven both directions: ``` with the fix: 0 failure(s), --check green (92 scripts / 58 tool self-tests / 48 python tests, rc 0) with the fix reverted, arm kept: FAIL rc was right but the output does not name tests/helper_test.py ``` Green on the real tree with the same three counts as before the change, so the strip removes no support that any test was actually relying on. --- tools/ci/tests_referenced_check.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tools/ci/tests_referenced_check.py b/tools/ci/tests_referenced_check.py index 9c83fecbd..2a6ea640a 100644 --- a/tools/ci/tests_referenced_check.py +++ b/tools/ci/tests_referenced_check.py @@ -308,7 +308,9 @@ def unregistered_py_tests(root): if base.is_dir() else []) for path in paths: try: - runner_text.append(path.read_text(errors="replace")) + # engine#2464: this half reads raw text, and `selftest_named` only REMOVES a finding -- so a comment + # naming `tools/ci/.py --self-test` was enough to make the gate go quiet about a test nothing runs. + runner_text.append(_strip_line_comments(path.read_text(errors="replace"))) except OSError: continue # engine#2445: a row that runs `tools/ci/.py --self-test` DOES run tests/_test.py -- that @@ -427,6 +429,12 @@ def root_with(files): "add_test(NAME helper_self COMMAND bash scripts/helper.sh --self-test)\n"}) cases.append(("an unclosed ( in a comment does not hide the row after it", check(r), 0, None)) + # engine#2464: the test half reads raw text; #2445's selftest_named only suppresses findings, so a MENTION cleared one + r = root_with({"tests/helper_test.py": "print('x')\n", + "CMakeLists.txt": "add_test(NAME ok COMMAND bash tests/ok.sh)\n# someday: tools/ci/helper.py --self-test\n"}) + cases.append(("a comment naming a tool does NOT clear tests/_test.py", check(r), 1, "tests/helper_test.py")) + cases_root["a comment naming a tool does NOT clear tests/_test.py"] = r + # the invocation goes INSIDE the already-registered test: a new tests/*.sh would be drift for a different, correct reason r = root_with({"tests/ok.sh": "#!/bin/sh\npython3 scripts/helper.sh --self-test\n", "CMakeLists.txt": "add_test(NAME ok COMMAND bash tests/ok.sh)\n",