|
11 | 11 | from typing import Any |
12 | 12 | from unittest.mock import AsyncMock, MagicMock, patch |
13 | 13 |
|
| 14 | +import httpx |
14 | 15 | import pytest |
15 | 16 | from agent_control.client import AgentControlClient |
16 | 17 | from agent_control.evaluation import ( |
@@ -418,6 +419,41 @@ async def test_mock_client_with_runtime_method_uses_runtime_auth_path( |
418 | 419 | client.post_runtime_evaluation.assert_awaited_once() |
419 | 420 | client.http_client.post.assert_not_called() |
420 | 421 |
|
| 422 | + @pytest.mark.asyncio |
| 423 | + async def test_jwt_runtime_client_without_target_raises( |
| 424 | + self, |
| 425 | + agent_name, |
| 426 | + llm_payload, |
| 427 | + ) -> None: |
| 428 | + """JWT runtime mode requires target context through local evaluation.""" |
| 429 | + controls = [ |
| 430 | + make_control_dict(1, "server_ctrl", execution="server"), |
| 431 | + ] |
| 432 | + sent_requests: list[httpx.Request] = [] |
| 433 | + |
| 434 | + def handler(request: httpx.Request) -> httpx.Response: |
| 435 | + sent_requests.append(request) |
| 436 | + return httpx.Response(200, json={"is_safe": True, "confidence": 1.0}) |
| 437 | + |
| 438 | + transport = httpx.MockTransport(handler) |
| 439 | + |
| 440 | + async with AgentControlClient( |
| 441 | + base_url="https://agent-control.test", |
| 442 | + api_key="test-key", |
| 443 | + runtime_auth_mode="jwt", |
| 444 | + transport=transport, |
| 445 | + ) as client: |
| 446 | + with pytest.raises(RuntimeError, match="requires target_type and target_id"): |
| 447 | + await check_evaluation_with_local( |
| 448 | + client=client, |
| 449 | + agent_name=agent_name, |
| 450 | + step=llm_payload, |
| 451 | + stage="pre", |
| 452 | + controls=controls, |
| 453 | + ) |
| 454 | + |
| 455 | + assert sent_requests == [] |
| 456 | + |
421 | 457 | @pytest.mark.asyncio |
422 | 458 | async def test_server_only_template_backed_controls_still_call_server( |
423 | 459 | self, |
|
0 commit comments