Files
hermes-agent/tests/scripts/test_check_tool_discovery.py
alt-glitch e6f7b6732d fix(code-health): a folder made from a root module ships, and the guard needs __init__.py
Two review findings on the folder rule:

- A root module or an acp_adapter/ module turned into a folder drops out
  of setup.py's _root_py_modules and ships only if
  [tool.setuptools.packages.find] include matches it. The FILE_LINES fix
  text now names that step, and
  test_every_package_packaged_code_imports_is_found fails when packaged
  code imports a regular package the wheel would not ship (moving
  toolsets.py to toolsets/__init__.py fails it with ['toolsets']).
- Discovery skips a tool package without __init__.py, so
  check_tool_discovery counts only candidates whose package has one,
  and its message says so. An intent-added tools/newpkg/tool.py with no
  __init__.py now fails the guard.

Both changes are the reviewer's patches as suggested.
2026-11-16 11:52:44 +05:30

49 lines
1.7 KiB
Python

"""scripts/check_tool_discovery.py: a tool registered where discovery never looks is flagged."""
import subprocess
from pathlib import Path
from scripts.check_tool_discovery import unreached_registrations
_REGISTERS = (
"from tools.registry import registry\n"
"registry.register(name='x', toolset='x', schema={}, handler=lambda *_a, **_k: '{}')\n"
)
def _tracked_tools(tmp_path: Path, files: dict[str, str]) -> Path:
tools_dir = tmp_path / "tools"
for rel, text in files.items():
(tools_dir / rel).parent.mkdir(parents=True, exist_ok=True)
(tools_dir / rel).write_text(text, encoding="utf-8")
subprocess.run(["git", "init", "-q"], cwd=tmp_path, check=True, timeout=60)
subprocess.run(["git", "add", "-A"], cwd=tmp_path, check=True, timeout=60)
return tools_dir
def test_registration_outside_tool_py_in_a_package_is_flagged(tmp_path):
tools_dir = _tracked_tools(tmp_path, {
"__init__.py": "",
"flat_tool.py": _REGISTERS,
"pkg/__init__.py": "",
"pkg/tool.py": _REGISTERS,
"pkg/extra.py": _REGISTERS,
})
assert unreached_registrations(tools_dir) == [tools_dir / "pkg/extra.py"]
def test_flat_modules_and_package_tool_py_pass(tmp_path):
tools_dir = _tracked_tools(tmp_path, {
"__init__.py": "",
"flat_tool.py": _REGISTERS,
"pkg/__init__.py": "",
"pkg/tool.py": _REGISTERS,
"pkg/helpers.py": "def helper():\n return 1\n",
})
assert unreached_registrations(tools_dir) == []
def test_package_tool_py_without_init_is_flagged(tmp_path):
tools_dir = _tracked_tools(tmp_path, {"__init__.py": "", "pkg/tool.py": _REGISTERS})
assert unreached_registrations(tools_dir) == [tools_dir / "pkg/tool.py"]