test(ci): sweep every module for dangling imports (t41)
Two defects shipped with a green suite: button.py imported a helper that had been deleted (no harness ever loaded the file), and the drift sweep only judged `homeassistant.*`, so a relative import of a name that no longer exists was invisible to it. Both are now impossible to ship silently. * tests/test_module_coverage.py loads EVERY *.py file of the package, in a clean interpreter, under the stub harness — exhaustive by construction (a new platform is covered the moment the file exists; there is no list and no special case). It asserts the reported set equals the files on disk, so a silently skipped module fails too; * entity_stublib.load_entity_modules() now also loads button.py (the named gap); the sweep is what keeps that list from needing to be complete; * ha_api_drift gained pass 5: the package's own relative imports. Pure AST, no homeassistant required, with its own entry point `scan_package_imports()` for the fast suite — it checks the target file exists and defines every imported name (submodule imports still resolve), instead of trusting that the modules a harness happened to load are the ones that matter; * the file walk in both AST passes is recursive, and the non-vacuity floors moved with it (modules 10 → 20, relative_imports ≥ 100 — a shallow-glob regression trips the floor instead of looking green); * two permanent red proofs, both on a copy of the tree with the reverted `from .helpers import discover_adb_host` reference in button.py: the stub-harness sweep fails with "FAIL button.py", and the static pass fails with "button.py:1: broken-relative-import: … not defined in helpers.py". Manual runs confirm the engine's other direction on the real pre-fix tree (c588a7c: exit 1 with the t40 entity-contract finding) and exit 0 on HEAD. No Home-Assistant API drift (23 modules, 58 imports, 148 relative imports, 36 call arguments, 6 awaited HA calls). Verified: 334 passed / 2 skipped, 335 / 1 with androidtvremote2, ruff clean. Note (pre-existing, not introduced here): running a SUBSET of test files in an order the suite was not written for (e.g. test_init.py alone after test_standalone_setup.py) fails 3 import-step tests with "ModuleNotFoundError: No module named 'voluptuous'" — the per-file stub scoping assumes the suite's order. Verified identical on the pre-t41 tree (60d884b), so it is left alone here.
This commit is contained in:
1 parent
151c49a0da
commit
130dee4bc6
4 files changed
+449
-10
No files matched your search
@@ -471,6 +471,11 @@ def load_entity_modules() -> dict:
|
||||
"media_player",
|
||||
"remote",
|
||||
"diagnostics",
|
||||
# t41: button.py was the file nobody loaded — a deleted helper it still
|
||||
# imported shipped silently. It is a platform like the others, so it
|
||||
# belongs here; tests/test_module_coverage.py sweeps EVERY module, which
|
||||
# is what keeps this list from having to be complete.
|
||||
"button",
|
||||
"init",
|
||||
): # "init" maps the integration __init__.py (t29 G8 async_setup)
|
||||
if name == "init" and "nsh.init" in sys.modules:
|
||||
|
||||
Reference in new issue
Block a user