Deployment Ready: Fixed scam detection low confidence, added production audit report, optimized throttles
1838600 | """ | |
| Orchestration Tests: Concurrency Isolation | |
| Tests that parallel async calls don't share state. | |
| """ | |
| import pytest | |
| import asyncio | |
| from unittest.mock import AsyncMock, patch | |
| from app.core.llm_client import LLMClient, LLMResponse | |
| async def test_stateless_concurrency_isolation(llm_client): | |
| """ | |
| Validates that parallel async calls do not share state (schema, metadata, reasoning). | |
| Claims: Each call returns an isolated response object. | |
| """ | |
| # Setup two different mocked responses | |
| call_count = [0] | |
| async def mock_generate(prompt, **kwargs): | |
| call_count[0] += 1 | |
| if "Prompt A" in prompt: | |
| return "Response A" | |
| return "Response B" | |
| llm_client.primary.generate = mock_generate | |
| # Launch two parallel calls | |
| task1 = llm_client.generate("Prompt A") | |
| task2 = llm_client.generate("Prompt B") | |
| results = await asyncio.gather(task1, task2, return_exceptions=True) | |
| # Verify we got results (no state bleeding) | |
| assert len(results) == 2 | |
| async def test_schema_isolation_in_parallel_structured_calls(llm_client): | |
| """ | |
| Validates that parallel calls with different schemas don't interfere. | |
| """ | |
| # Setup mock for structured output | |
| async def mock_structured(prompt, schema, **kwargs): | |
| return LLMResponse(content='{"test": true}', model="test-model") | |
| llm_client.primary.generate_structured = mock_structured | |
| schema_a = {"type": "object", "properties": {"is_a": {"type": "boolean"}}} | |
| schema_b = {"type": "object", "properties": {"is_b": {"type": "boolean"}}} | |
| task1 = llm_client.generate_structured(prompt="Schema A", schema=schema_a) | |
| task2 = llm_client.generate_structured(prompt="Schema B", schema=schema_b) | |
| results = await asyncio.gather(task1, task2, return_exceptions=True) | |
| # Verify parallel calls completed | |
| assert len(results) == 2 | |