scanner
agent_cover.instrumentation.structures.scanner
This module provides functionality to scan and analyze data structures (Pydantic models, dataclasses) within a given codebase.
It uses an abstraction layer for the inspect module to improve testability and isolate the scanning process from the actual filesystem and inspection calls.
Classes
InspectionProvider
Helper class to abstract the calls to inspect that touch the filesystem.
Methods:
| Name | Description |
|---|---|
get_file |
Any) -> str: Returns the file path of the given object. |
get_source_lines |
Any) -> Tuple[List[str], int]: Returns the source code lines and starting line number of the given object. |
Source code in src/agent_cover/instrumentation/structures/scanner.py
Functions
get_file(obj)
Returns the file path of the given object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
Any
|
The object to get the file path for. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The file path of the object. |
get_source_lines(obj)
Returns the source code lines and starting line number of the given object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
Any
|
The object to get the source code lines for. |
required |
Returns:
| Type | Description |
|---|---|
Tuple[List[str], int]
|
A tuple containing the source code lines as a list of strings and the starting line number. |
Source code in src/agent_cover/instrumentation/structures/scanner.py
Functions
scan_pydantic_models(registry=None, config=None, root_path=None, adapter_registry=None, module_iterator=None, inspector=None)
Scans loaded modules to automatically generate Business Logic decisions.
This function inspects Pydantic models and Dataclasses to find fields with
finite sets of expected values. It automatically populates the
AgentCoverConfig with these rules.
Supported Types:
- Enum: Expects all enum members.
- Literal: Expects all literal values (e.g., Literal["yes", "no"]).
- Bool: Expects True and False.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
registry
|
Optional[AgentRegistry]
|
The AgentRegistry instance. Defaults to the result of get_registry(). |
None
|
config
|
Optional[AgentCoverConfig]
|
The AgentCoverConfig instance. Defaults to the result of get_config(). |
None
|
root_path
|
Optional[str]
|
The root path to scan for modules. Defaults to the current working directory. |
None
|
adapter_registry
|
Optional[AdapterRegistry]
|
The AdapterRegistry instance. Defaults to the result of get_default_adapter_registry(). |
None
|
module_iterator
|
Optional[Callable[[], Dict[str, Any]]]
|
A callable that returns an iterator over the modules. Defaults to _default_module_iterator. |
None
|
inspector
|
Optional[InspectionProvider]
|
An instance of InspectionProvider for abstracting inspect calls. Defaults to None. |
None
|
Examples:
If you have this model:
This scanner creates a Decision rule expecting both "POSITIVE" and "NEGATIVE" to appear in thelabel field during testing.
Source code in src/agent_cover/instrumentation/structures/scanner.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 | |