"""Router-level test for gitea#36 point 7: recipes.py translates ai_service.AIResponseError to 502, not the config-error 400. A dedicated file (not test_recipes.py) to avoid colliding with concurrent work on the copy-on-write recipe logic in that shared test module. """ from httpx import AsyncClient from sqlalchemy.ext.asyncio import AsyncSession from src.backend.models.orm.user import User from src.backend.services import ai_service from src.backend.tests.conftest import auth_headers, create_test_recipe async def test_ai_response_error_is_502( client: AsyncClient, maker_user: User, db_session: AsyncSession, monkeypatch, ): recipe = await create_test_recipe(db_session, maker_user.id, code="AI-PARSE-502") async def _raise_ai_response_error(_pdf_bytes): raise ai_service.AIResponseError("Risposta del modello AI non e' JSON valido: boom") monkeypatch.setattr(ai_service, "parse_technical_sheet", _raise_ai_response_error) resp = await client.post( f"/api/recipes/{recipe.id}/parse-technical-sheet", headers=auth_headers(maker_user), files={"file": ("sheet.pdf", b"%PDF-1.4 fake", "application/pdf")}, ) assert resp.status_code == 502