The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(compat): prune dependency trees from pointer scan
fangliquan1655dcd35dfd
diff --git a/scripts/check_compat_pointers.py b/scripts/check_compat_pointers.pyindex c36bea08ecf..4db8d9136f6 100644--- a/scripts/check_compat_pointers.py+++ b/scripts/check_compat_pointers.py@@ -17,24 +17,30 @@ from __future__ import annotationsimport astimport json+import osimport reimport sysfrom pathlib import PathROOT = Path(__file__).resolve().parent.parentMANIFEST = ROOT / "compat_manifest.json"-SKIP_DIRS = {".git", "node_modules", "website", "skills", "optional-skills", "apps", "evals", "build", "MagicMock", ".worktrees", "__pycache__"}+DEPENDENCY_DIRS = {".git", ".venv", "venv", "node_modules", "__pycache__"}+ROOT_SKIP_DIRS = DEPENDENCY_DIRS | {+ "website", "skills", "optional-skills", "apps", "evals", "build", "MagicMock", ".worktrees"+}def _py_files():- for p in ROOT.rglob("*.py"):- parts = p.relative_to(ROOT).parts- if parts[0] in SKIP_DIRS or p.name == "check_compat_pointers.py":- continue- # The compat layer's own contract test uses the pointers on purpose; it is deleted with them.- if p.name == "test_compat_manifest_targets.py":- continue- yield p+ for dirpath, dirnames, filenames in os.walk(ROOT):+ excluded = ROOT_SKIP_DIRS if Path(dirpath) == ROOT else DEPENDENCY_DIRS+ dirnames[:] = [name for name in dirnames if name not in excluded]+ for filename in filenames:+ if not filename.endswith(".py") or filename == "check_compat_pointers.py":+ continue+ # The compat layer's own contract test uses the pointers on purpose; it is deleted with them.+ if filename == "test_compat_manifest_targets.py":+ continue+ yield Path(dirpath) / filenamedef main() -> int:diff --git a/tests/scripts/test_check_compat_pointers.py b/tests/scripts/test_check_compat_pointers.pynew file mode 100644index 00000000000..4e7f20c55c8--- /dev/null+++ b/tests/scripts/test_check_compat_pointers.py@@ -0,0 +1,46 @@+"""The compatibility-pointer scanner only traverses first-party Python trees."""++import importlib.util+import os+from pathlib import Path+++SCRIPT = Path(__file__).resolve().parents[2] / "scripts" / "check_compat_pointers.py"+++def _load():+ spec = importlib.util.spec_from_file_location("check_compat_pointers", SCRIPT)+ mod = importlib.util.module_from_spec(spec)+ spec.loader.exec_module(mod)+ return mod+++def test_py_files_prunes_dependency_trees_before_descent(tmp_path, monkeypatch):+ mod = _load()+ (tmp_path / "package").mkdir()+ (tmp_path / "package" / "source.py").write_text("VALUE = 1\n", encoding="utf-8")+ excluded = [+ tmp_path / ".venv",+ tmp_path / "venv",+ tmp_path / "node_modules",+ tmp_path / "package" / "__pycache__",+ tmp_path / "package" / "node_modules",+ ]+ for directory in excluded:+ directory.mkdir(parents=True)+ (directory / "dependency.py").write_text("VALUE = 2\n", encoding="utf-8")++ visited = []+ real_walk = os.walk++ def tracking_walk(root):+ for dirpath, dirnames, filenames in real_walk(root):+ visited.append(Path(dirpath))+ yield dirpath, dirnames, filenames++ monkeypatch.setattr(mod, "ROOT", tmp_path)+ monkeypatch.setattr(mod.os, "walk", tracking_walk)++ assert list(mod._py_files()) == [tmp_path / "package" / "source.py"]+ assert tmp_path in visited+ assert not set(excluded) & set(visited)\ No newline at end of file