mirror of
https://github.com/norandom/OpenUltraSAST.git
synced 2026-10-16 03:49:26 +00:00
fix(audit): the module audit checks real imports before the spec-owned list
model/audit.py classified anything named in SPEC_OWNED or STANDALONE before looking at the import graph, so five modules nothing imports were reported load_bearing and the committed manifest said 0 orphans. - Reachability from the gates, the CLI and every module with a __main__ block (python -m, the plane runner) now decides the class; the lists only supply reason text, and an unreachable listed module is orphaned with its listing. - `from .pkg import sub` now records the submodule edge (plane.engine_alerts was only reachable by its SPEC_OWNED entry). - `python -m openultrasast.model.audit` regenerates the manifest. - Manifest regenerated: 145 load_bearing, 5 standalone, 5 orphaned (model.calibrate, model.execution, model.judge, slot_contract, stage_processors). The zero-orphan test is strict-xfail until they go. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01EmM1j46qgKMh3zqD1QMwEo
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
7b17eacd44
commit
b7f1f3d05b
@@ -5,10 +5,13 @@ from __future__ import annotations
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
SRC = Path("src/openultrasast")
|
||||
MANIFEST = Path("benchmarks/measurements/2026-09-08-module-audit.json")
|
||||
|
||||
|
||||
@pytest.mark.xfail(strict=True, reason="five dead modules the fixed audit found; removed in the next commit")
|
||||
def test_no_module_in_the_tree_is_orphaned() -> None:
|
||||
from openultrasast.model.audit import audit
|
||||
|
||||
@@ -44,4 +47,46 @@ def test_the_manifest_matches_the_tree() -> None:
|
||||
committed = json.loads(MANIFEST.read_text())
|
||||
current = to_dict(audit(SRC))
|
||||
assert committed["counts"] == current["counts"], "the tree drifted from its committed audit"
|
||||
assert committed["orphaned"] == current["orphaned"] == []
|
||||
assert committed["orphaned"] == current["orphaned"]
|
||||
|
||||
|
||||
def _tree(root: Path, files: dict[str, str]) -> Path:
|
||||
for name, text in files.items():
|
||||
path = root / name
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
path.write_text(text)
|
||||
return root
|
||||
|
||||
|
||||
def test_a_spec_listed_module_nothing_imports_is_still_orphaned(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
"""Reachability decides; SPEC_OWNED and STANDALONE only supply the reason (the list hid five dead modules)."""
|
||||
from openultrasast.model import audit as module
|
||||
|
||||
src = _tree(tmp_path, {"cli.py": "from . import used\n", "used.py": "", "ghost.py": "", "lonely.py": ""})
|
||||
monkeypatch.setitem(module.SPEC_OWNED, "ghost", "some spec Req 1: still listed")
|
||||
monkeypatch.setitem(module.STANDALONE, "lonely", "its own entry point, supposedly")
|
||||
rows = {row.module: row for row in module.audit(src)}
|
||||
assert rows["used"].classification == "load_bearing"
|
||||
assert rows["ghost"].classification == "orphaned"
|
||||
assert "still listed" in rows["ghost"].reason
|
||||
assert rows["lonely"].classification == "orphaned"
|
||||
|
||||
|
||||
def test_submodule_imports_and_python_m_modules_count_as_reachable(tmp_path: Path) -> None:
|
||||
from openultrasast.model.audit import audit
|
||||
|
||||
src = _tree(
|
||||
tmp_path,
|
||||
{
|
||||
"cli.py": "def run():\n from .pkg import sub\n",
|
||||
"pkg/__init__.py": "",
|
||||
"pkg/sub.py": "",
|
||||
"tool.py": 'from . import helper\n\nif __name__ == "__main__":\n pass\n',
|
||||
"helper.py": "",
|
||||
"dead.py": "from . import deader\n",
|
||||
"deader.py": "",
|
||||
},
|
||||
)
|
||||
rows = {row.module: row.classification for row in audit(src)}
|
||||
assert rows["pkg.sub"] == rows["tool"] == rows["helper"] == "load_bearing"
|
||||
assert rows["dead"] == rows["deader"] == "orphaned"
|
||||
|
||||
Reference in New Issue
Block a user