import json import httpx import pytest from ai_platform.infrastructure.aihub import AiHubClient, AiHubError @pytest.mark.asyncio async def test_rejects_vkey_echo_after_json_unescaping(): vkey = 'mock-key-with-"-and-\\' response = { "choices": [ { "message": { "content": json.dumps({"score": 70, "confidence": 0.8, "reasoning": vkey}) } } ] } client = AiHubClient( "https://aihub.test", httpx.AsyncClient( transport=httpx.MockTransport(lambda _request: httpx.Response(200, json=response)) ), ) try: with pytest.raises(AiHubError) as error: await client.score( model="openai/gpt-4o-mini", system_prompt="prompt", user_prompt="snapshot", vkey=vkey, ) finally: await client.aclose() assert error.value.error_code == "aihub_invalid_response" assert vkey not in str(error.value)