Test the integration between new and legacy session management
()
| 407 | |
| 408 | |
| 409 | def test_session_management_integration(): |
| 410 | """Test the integration between new and legacy session management""" |
| 411 | import agentops |
| 412 | |
| 413 | # Reset client for test |
| 414 | agentops._client = agentops.Client() |
| 415 | |
| 416 | # Test that we can use both new and legacy APIs together |
| 417 | with ( |
| 418 | patch("agentops.tracer") as mock_tracer, |
| 419 | patch("agentops.client.client.tracer", mock_tracer), |
| 420 | patch("agentops.sdk.decorators.factory.tracer", mock_tracer), |
| 421 | patch("agentops.legacy.tracer", mock_tracer), |
| 422 | ): |
| 423 | mock_tracer.initialized = True |
| 424 | |
| 425 | # Mock API client |
| 426 | with patch("agentops.client.api.ApiClient") as mock_api: |
| 427 | mock_v3 = MagicMock() |
| 428 | mock_v3.fetch_auth_token.return_value = {"token": "mock-jwt-token", "project_id": "mock-project-id"} |
| 429 | mock_api.return_value.v3 = mock_v3 |
| 430 | |
| 431 | # Initialize AgentOps |
| 432 | agentops.init(api_key="test-api-key", auto_start_session=False) |
| 433 | |
| 434 | # Reset call counts after initialization |
| 435 | mock_tracer.reset_mock() |
| 436 | |
| 437 | # Create mock trace context |
| 438 | mock_trace_context = MagicMock() |
| 439 | mock_tracer.start_trace.return_value = mock_trace_context |
| 440 | |
| 441 | # Test new API |
| 442 | trace_context = agentops.start_trace(trace_name="new_api_trace") |
| 443 | assert trace_context == mock_trace_context |
| 444 | |
| 445 | # Test legacy API |
| 446 | session = agentops.start_session(tags=["legacy"]) |
| 447 | # Check that the session's trace_context has the expected properties |
| 448 | assert session.trace_context is not None |
| 449 | |
| 450 | # Test ending both |
| 451 | agentops.end_trace(trace_context) |
| 452 | agentops.end_session(session) |
| 453 | |
| 454 | # Verify calls were made |
| 455 | assert mock_tracer.start_trace.call_count >= 2 |
| 456 | assert mock_tracer.end_trace.call_count >= 2 |
| 457 | |
| 458 | |
| 459 | # CrewAI Backwards Compatibility Tests |
nothing calls this directly
no test coverage detected
searching dependent graphs…