test: +12 test modules — clean_release routes, gitea routes, dashboard detail, candidate_service, compliance_orchestrator, clarification_engine/orchestrator, dataset_review helpers. Fix 18 failures (assistant tools, maintence, dataset_review, approval, publication)
This commit is contained in:
@@ -162,4 +162,128 @@ async def test_search_dashboards_correct_url():
|
||||
url = args[0] if args else kwargs.get("url", "")
|
||||
assert "api/dashboards" in url
|
||||
# #endregion TestAgentChat.Tools.ToolContracts
|
||||
|
||||
|
||||
# #region TestAgentChat.Tools.HealthSummary [C:2] [TYPE Function] [SEMANTICS test,tools,health]
|
||||
# @BRIEF get_health_summary calls the correct FastAPI endpoint.
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_health_summary_calls_correct_url():
|
||||
"""get_health_summary should call GET /api/dashboards/health."""
|
||||
from src.agent.context import set_service_jwt, set_user_jwt
|
||||
from src.agent.tools import get_health_summary
|
||||
|
||||
set_user_jwt("jwt")
|
||||
set_service_jwt("svc-jwt")
|
||||
|
||||
with patch("httpx.AsyncClient") as mock_client:
|
||||
mock_instance = AsyncMock()
|
||||
mock_client.return_value.__aenter__.return_value = mock_instance
|
||||
mock_instance.get.return_value.text = '{"status": "ok"}'
|
||||
|
||||
await get_health_summary.ainvoke({})
|
||||
|
||||
call_args = mock_instance.get.call_args
|
||||
assert call_args is not None
|
||||
args, kwargs = call_args
|
||||
url = args[0] if args else kwargs.get("url", "")
|
||||
assert "api/dashboards/health" in url
|
||||
# #endregion TestAgentChat.Tools.HealthSummary
|
||||
|
||||
|
||||
# #region TestAgentChat.Tools.ListEnvironments [C:2] [TYPE Function] [SEMANTICS test,tools,environments]
|
||||
# @BRIEF list_environments calls the correct FastAPI endpoint.
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_list_environments_calls_correct_url():
|
||||
"""list_environments should call GET /api/settings/environments."""
|
||||
from src.agent.context import set_service_jwt, set_user_jwt
|
||||
from src.agent.tools import list_environments
|
||||
|
||||
set_user_jwt("jwt")
|
||||
set_service_jwt("svc-jwt")
|
||||
|
||||
with patch("httpx.AsyncClient") as mock_client:
|
||||
mock_instance = AsyncMock()
|
||||
mock_client.return_value.__aenter__.return_value = mock_instance
|
||||
mock_instance.get.return_value.text = '["prod", "dev"]'
|
||||
|
||||
await list_environments.ainvoke({})
|
||||
|
||||
call_args = mock_instance.get.call_args
|
||||
assert call_args is not None
|
||||
args, kwargs = call_args
|
||||
url = args[0] if args else kwargs.get("url", "")
|
||||
assert "api/settings/environments" in url
|
||||
# #endregion TestAgentChat.Tools.ListEnvironments
|
||||
|
||||
|
||||
# #region TestAgentChat.Tools.TaskStatus [C:2] [TYPE Function] [SEMANTICS test,tools,task]
|
||||
# @BRIEF get_task_status calls the correct FastAPI endpoint with task_id.
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_task_status_calls_correct_url():
|
||||
"""get_task_status should call GET /api/tasks/{task_id}."""
|
||||
from src.agent.context import set_service_jwt, set_user_jwt
|
||||
from src.agent.tools import get_task_status
|
||||
|
||||
set_user_jwt("jwt")
|
||||
set_service_jwt("svc-jwt")
|
||||
|
||||
with patch("httpx.AsyncClient") as mock_client:
|
||||
mock_instance = AsyncMock()
|
||||
mock_client.return_value.__aenter__.return_value = mock_instance
|
||||
mock_instance.get.return_value.text = '{"status": "running"}'
|
||||
|
||||
await get_task_status.ainvoke({"task_id": "task-123"})
|
||||
|
||||
call_args = mock_instance.get.call_args
|
||||
assert call_args is not None
|
||||
args, kwargs = call_args
|
||||
url = args[0] if args else kwargs.get("url", "")
|
||||
assert "api/tasks/task-123" in url
|
||||
# #endregion TestAgentChat.Tools.TaskStatus
|
||||
|
||||
|
||||
# #region TestAgentChat.Tools.DualAuthHeaders [C:2] [TYPE Function] [SEMANTICS test,tools,auth,headers]
|
||||
# @BRIEF _dual_auth_headers builds proper headers from ContextVars.
|
||||
|
||||
def test_dual_auth_headers_with_both_jwts():
|
||||
"""_dual_auth_headers returns Authorization + X-User-JWT when both set."""
|
||||
from src.agent.context import set_service_jwt, set_user_jwt
|
||||
from src.agent.tools import _dual_auth_headers
|
||||
|
||||
set_service_jwt("svc-token")
|
||||
set_user_jwt("user-token")
|
||||
|
||||
headers = _dual_auth_headers()
|
||||
assert headers.get("Authorization") == "Bearer svc-token"
|
||||
assert headers.get("X-User-JWT") == "user-token"
|
||||
|
||||
|
||||
def test_dual_auth_headers_no_user_jwt():
|
||||
"""_dual_auth_headers returns only Authorization when no user JWT."""
|
||||
from src.agent.context import set_service_jwt, set_user_jwt
|
||||
from src.agent.tools import _dual_auth_headers
|
||||
|
||||
set_service_jwt("svc-token")
|
||||
set_user_jwt("")
|
||||
|
||||
headers = _dual_auth_headers()
|
||||
assert headers.get("Authorization") == "Bearer svc-token"
|
||||
assert "X-User-JWT" not in headers or headers.get("X-User-JWT") == ""
|
||||
|
||||
|
||||
def test_dual_auth_headers_no_jwts(monkeypatch):
|
||||
"""_dual_auth_headers returns empty dict when no JWTs."""
|
||||
monkeypatch.delenv("SERVICE_JWT", raising=False)
|
||||
from src.agent.context import set_service_jwt, set_user_jwt
|
||||
from src.agent.tools import _dual_auth_headers
|
||||
|
||||
set_service_jwt("")
|
||||
set_user_jwt("")
|
||||
|
||||
headers = _dual_auth_headers()
|
||||
assert headers == {}
|
||||
# #endregion TestAgentChat.Tools.DualAuthHeaders
|
||||
# #endregion TestAgentChat.Tools
|
||||
|
||||
Reference in New Issue
Block a user