Answer architecture round 1: 0 🔴, 36 🟡 (0 misread); chunk_driver holds what both drivers share, and Jira and review-state reads have one home each
CI / tests (pull_request) Successful in 5m11s
CI / tests (pull_request) Successful in 5m11s
This commit is contained in:
@@ -6,7 +6,7 @@ import unittest
|
||||
|
||||
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
|
||||
|
||||
from loop_claude.project.records import HUMAN_RULE_DIR
|
||||
from chunk_driver.project.records import HUMAN_RULE_DIR
|
||||
from repo_checks import ROOT
|
||||
|
||||
# The review standards this repo ships. A project's config may name another folder as `standards`.
|
||||
|
||||
@@ -24,6 +24,21 @@ def package_imports(bin_folder: pathlib.Path) -> dict[str, set[str]]:
|
||||
return imported
|
||||
|
||||
|
||||
# The entry points that drive chunks. What two of them need lives in bin/chunk_driver/, so no other package imports one, its tests included.
|
||||
DRIVERS = ("do_epic", "loop_claude")
|
||||
|
||||
|
||||
def driver_imports(bin_folder: pathlib.Path, drivers: tuple[str, ...]) -> list[str]:
|
||||
"""Each module under bin_folder that imports a driver's package from outside it, tests included, as `<module> imports <driver>`."""
|
||||
found = []
|
||||
for module in sorted(bin_folder.rglob("*.py")):
|
||||
package = module.relative_to(bin_folder).parts[0]
|
||||
for node in ast.walk(ast.parse(module.read_text(encoding="utf-8"))):
|
||||
names = [alias.name for alias in node.names] if isinstance(node, ast.Import) else [node.module or ""] if isinstance(node, ast.ImportFrom) and node.level == 0 else []
|
||||
found += [f"{module.relative_to(bin_folder)} imports {top}" for name in names if (top := name.split(".")[0]) in drivers and top != package]
|
||||
return sorted(set(found))
|
||||
|
||||
|
||||
def cycle(imported: dict[str, set[str]]) -> list[str]:
|
||||
"""One cycle among the packages, as the packages along it; empty where there is none."""
|
||||
try:
|
||||
@@ -37,6 +52,17 @@ class PackageCycles(unittest.TestCase):
|
||||
def test_no_package_under_bin_imports_one_that_imports_it_back(self):
|
||||
self.assertEqual(cycle(package_imports(ROOT / "bin")), [], "move what both packages need into a package that imports neither")
|
||||
|
||||
def test_no_package_imports_a_driver_of_chunks(self):
|
||||
self.assertEqual(driver_imports(ROOT / "bin", DRIVERS), [], "move what the importer needs into bin/chunk_driver/, or a test double into the package whose code it stands in for")
|
||||
|
||||
def test_a_driver_imported_from_another_package_is_found_in_tests_too(self):
|
||||
with tempfile.TemporaryDirectory() as temp:
|
||||
folder = pathlib.Path(temp)
|
||||
for package, name, source in (("a", "mod.py", "import a.other\n"), ("b", "test_mod.py", "from a.mod import x\n"), ("b", "mod.py", "def f():\n\timport a\n"), ("c", "mod.py", "import b\n")):
|
||||
(folder / package).mkdir(exist_ok=True)
|
||||
(folder / package / name).write_text(source)
|
||||
self.assertEqual(driver_imports(folder, ("a",)), ["b/mod.py imports a", "b/test_mod.py imports a"])
|
||||
|
||||
def test_reads_an_import_deferred_into_a_function_and_leaves_out_tests(self):
|
||||
with tempfile.TemporaryDirectory() as temp:
|
||||
folder = pathlib.Path(temp)
|
||||
|
||||
Reference in New Issue
Block a user