Test agent
FixedResponseModel
Bases: Model
A Mock LLM Implementation for deterministic testing.
Instead of calling OpenAI, this class returns pre-defined response_parts.
This allows us to simulate specific LLM behaviors (e.g., calling a tool,
generating text, or even hallucinating a malicious command) to test how
the Agent loop responds.
Attributes:
| Name | Type | Description |
|---|---|---|
response_parts |
list[Any]
|
The content the "LLM" should return in the first turn. |
Source code in api/tests/integration/test_agent.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | |
mock_deps()
Creates mocked Agent Dependencies (Database).
Simulates a DuckDB connection to avoid needing a real database file on disk.
Source code in api/tests/integration/test_agent.py
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | |
orchestrator()
Initializes the Orchestrator with Test settings.
Source code in api/tests/integration/test_agent.py
72 73 74 75 76 | |
test_agent_sql_guardrail_interception(orchestrator, mock_deps)
async
Integration Test: Ensures the Guardrail actively stops a compromised Agent.
This test forces the Mock LLM to emit a malicious DROP TABLE tool call.
We assert that pydantic-ai-guardrails intercepts this before it reaches
the tool execution layer.
Flow:
- Setup
FixedResponseModelto return aDROPSQL query. - Run Agent.
- Assert: An
OutputGuardrailViolationexception is raised.
Source code in api/tests/integration/test_agent.py
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 | |
test_agent_tool_routing_success(orchestrator, mock_deps)
async
Integration Test: Verifies successful tool routing for valid queries.
Ensures that when the LLM emits a valid SELECT call, the arguments are
passed correctly to the underlying database connection.
Source code in api/tests/integration/test_agent.py
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 | |
test_full_report_flow_integration(client)
End-to-End API Test: Checks the /report endpoint wiring.
This test mocks the internal orchestrator.run() method to isolate the
FastAPI layer from the AI logic. It verifies that inputs (focus_area)
are passed down and outputs (markdown) are returned up correctly.
Checks:
- Status Code 200.
- JSON response structure matches
AgentResponse. - Prompt injection logic (Focus Area appending) works as expected.
Source code in api/tests/integration/test_agent.py
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 | |