fix(api): make auth HTTP tests pass in CI without local .env secrets.

Mock COS storage for auth router DI and skip Postgres integration tests when the database is unreachable.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Kevin
2026-05-22 16:01:03 +08:00
parent 8f66f94a1a
commit f4e18f2b9b
3 changed files with 12 additions and 1 deletions

View File

@@ -14,7 +14,7 @@ from sqlalchemy.ext.asyncio import AsyncSession, async_sessionmaker
from app.core.config import settings
from app.core.db import get_async_db, utc_now
from app.core.dependencies import get_sms_sender
from app.core.dependencies import get_object_storage, get_sms_sender
from app.features.auth import repo
from app.features.auth.router import router as auth_router
from tests.conftest import install_test_error_handlers
@@ -33,6 +33,7 @@ async def refresh_http_app(
app.include_router(auth_router)
app.dependency_overrides[get_async_db] = _override_db
app.dependency_overrides[get_sms_sender] = lambda: MagicMock()
app.dependency_overrides[get_object_storage] = lambda: MagicMock()
return app

View File

@@ -8,6 +8,7 @@ import pytest
from fastapi import FastAPI
from httpx import ASGITransport, AsyncClient
from app.core.dependencies import get_object_storage
from app.core.errors import BadRequestError, NotFoundError
from app.features.auth.deps import get_auth_service
from app.features.auth.router import router as auth_router
@@ -21,6 +22,7 @@ from tests.conftest import install_test_error_handlers
async def test_auth_register_validation_returns_unified_422() -> None:
app = install_test_error_handlers(FastAPI())
app.include_router(auth_router)
app.dependency_overrides[get_object_storage] = lambda: MagicMock()
transport = ASGITransport(app=app, raise_app_exceptions=False)
async with AsyncClient(transport=transport, base_url="http://test") as client:

View File

@@ -133,10 +133,18 @@ async def test_record_human_ai_turn_with_segment_postgres_flush_order() -> None:
if not settings.database_url.startswith("postgresql"):
pytest.skip("requires PostgreSQL")
from sqlalchemy import text
from app.core.db import AsyncSessionLocal, transactional
from app.features.conversation.models import Conversation
from app.features.user.models import User
try:
async with AsyncSessionLocal() as db:
await db.execute(text("SELECT 1"))
except Exception:
pytest.skip("PostgreSQL not reachable")
uid = str(uuid.uuid4())
cid = str(uuid.uuid4())
sid = str(uuid.uuid4())