discovery
agent_cover.discovery
Module for dynamic repository exploration and module importing.
This module provides utilities to recursively walk through a directory tree, identify Python files, and dynamically import them into the current runtime.
🔗 Architectural Relationships
Discovery serves as the Pre-flight Check or "Hydration" phase of the coverage process. It ensures the environment is fully populated before instrumentation begins.
- Enables: Static Analysis.
Scanners like Structures or Raw Strings
iterate over loaded modules (
sys.modules). Without discovery, they would only see files explicitly imported by your tests, missing unused code (false negatives in coverage). - Prepares: Direct Patching.
Instrumentors need the target classes (e.g.,
MyCustomTool) to be loaded in memory to apply wrappers. - Orchestrated by: Plugin and SDK.
Called at the very beginning of the lifecycle (
pytest_configure).
⚙️ How it works
It performs a "forced import" strategy to trigger Import-Time Side Effects (like decorators registering tools) without executing the actual agent logic.
Key Features:
- Smart Filtering: Automatically ignores .git, venv, node_modules, etc.
- Safe Importing: Catches import errors to prevent crashing the test suite if a user file is broken.
Classes
Functions
discover_repository_modules(root_path=None, walker_func=None, importer_func=None)
Recursively explores a directory to find Python files and force their import.
This function performs a "Pre-flight Check" of the user's codebase. By importing
modules found in root_path, it ensures that:
1. @tool decorators run and register definitions in the registry.
2. Global prompt variables are loaded and can be scanned.
3. Class definitions are available for patching.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
root_path
|
Optional[str]
|
The root directory to start discovery. |
None
|
walker_func
|
Optional[Callable]
|
Dependency injection for file system walking (testing). |
None
|
importer_func
|
Optional[Callable]
|
Dependency injection for module importing (testing). |
None
|