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
@@ -108,11 +108,17 @@ def test_the_sweep_reports_the_same_findings_as_this_check(tmp_path):
|
||||
report = ha_api_drift.scan(tmp_path)
|
||||
kinds = [finding.kind for finding in report.findings]
|
||||
|
||||
# The contract pass runs FIRST (pure AST). Without homeassistant installed the
|
||||
# sweep then adds "cannot judge the API surface" — that path is covered in
|
||||
# tests/test_ha_api_drift.py.
|
||||
# The contract pass runs FIRST (pure AST). What the API passes add after it
|
||||
# depends on the interpreter: with homeassistant installed they judge the
|
||||
# module's imports, without it the sweep says it cannot judge (both are
|
||||
# covered here so the check holds in either variant).
|
||||
assert kinds[0] == "entity-attribute-is-a-method"
|
||||
assert "no-homeassistant" in kinds
|
||||
rest = set(kinds[1:])
|
||||
if ha_api_drift.homeassistant_available():
|
||||
# the API passes ran and found nothing wrong with this module
|
||||
assert rest == set(), rest
|
||||
else:
|
||||
assert "no-homeassistant" in rest
|
||||
|
||||
|
||||
def test_the_check_ignores_missing_paths_instead_of_raising():
|
||||
|
||||
Reference in new issue
Block a user