From e3a4b0eb5b61cb2462a2db64aed8af1f49b7fcbd Mon Sep 17 00:00:00 2001 From: t Date: Sun, 15 Nov 2026 03:47:42 -0400 Subject: [PATCH] route_port_lock_test: see a C++ route test, and fail by name when it has no lock MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #2504 fixed the instance — http_guard_test gained an httplib::Server and took no RESOURCE_LOCK route_ports — but the checker that exists for exactly this could not see it: route_script() only accepts COMMAND args ending in .sh, so a test whose COMMAND is an executable is None to the census and never examined. Two route tests needed that lock by hand inside one hour (http_guard, and coder_llm_ticketed in #2496), which is the measured cost of the blind spot. route_source() adds the shape: a tests/*.cpp containing bind_to_any_port or httplib::Server is a route test, keyed by the executable name the tree already uses (http_guard_test.cpp -> http_guard_test). The census includes it, and 'http_guard' is named in the anti-vacuity arm so a reader that stops seeing this shape fails by name instead of reporting a smaller census that clears the floor. Verified with a stub ctest (this box has no configured build tree, and disk is below the floor for a full build) emitting the real -N --show-only=json-v1 shape: main's checker, C++ route test WITHOUT the lock -> OK (blind) this checker, same input -> FAIL ['http_guard (http_guard_test.cpp)'] this checker, lock present (= main today) -> OK --- tests/route_port_lock_test.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/route_port_lock_test.py b/tests/route_port_lock_test.py index 06b16ebaf..87e2c398c 100644 --- a/tests/route_port_lock_test.py +++ b/tests/route_port_lock_test.py @@ -66,6 +66,25 @@ def binds_a_port(script): return bool(BIND_RE.search(f.read())) +# A `tests/*.cpp` that starts a loopback server: the shape `route_script` cannot see, because such a +# test's COMMAND is an executable rather than a .sh (engine#2504: `http_guard` gained an httplib::Server +# and took no lock, and this census reported nothing about it). +EXE_BIND_RE = re.compile(r'bind_to_any_port|httplib::Server') + + +def route_source(test): + """The tests/*.cpp an executable test is built from, if that source binds a loopback port.""" + for arg in test.get("command", []): + if not isinstance(arg, str): + continue + src = os.path.join(TESTS_DIR, os.path.basename(arg) + ".cpp") + if os.path.exists(src): + with open(src, encoding="utf-8", errors="replace") as f: + if EXE_BIND_RE.search(f.read()): + return src + return None + + def lock_of(test): for prop in test.get("properties", []): if prop.get("name") == "RESOURCE_LOCK": @@ -85,6 +104,10 @@ def census(self): script = route_script(test) if script and binds_a_port(script): found[test["name"]] = script + continue + src = route_source(test) # engine#2504: a C++ route test is the same hazard + if src: + found[test["name"]] = src return found def test_the_census_finds_the_route_tests(self): @@ -100,6 +123,11 @@ def test_the_census_finds_the_route_tests(self): # the number the CI build has, not the number a developer's build may have. It counted 15 before engine #1485 # moved fifteen scripts to `serve --port 0`; the rest of the old # list was `bench_selftest` (binds through tools/bench.py, pinned by its own case below). + # engine#2504: the census read .sh only, so a C++ route test was invisible here. Named for the same + # reason the three above are: a reader that stops seeing this shape must fail by name, not report a + # smaller census that still clears the floor. + self.assertIn("http_guard", found, + "http_guard starts an httplib::Server from C++; the census must see it (engine#2504)") self.assertGreaterEqual(len(found), 5, "fewer route tests found than the suite has: " + ", ".join(sorted(found)))