diff --git a/.github/workflows/unittest.yml b/.github/workflows/unittest.yml index 733215e7..80fbf45b 100644 --- a/.github/workflows/unittest.yml +++ b/.github/workflows/unittest.yml @@ -46,10 +46,9 @@ jobs: - name: Run Tests run: uv run pytest -x env: - CONNECTION_URI: postgresql+psycopg://postgres:postgres@localhost:5432/test_db - USE_AUTH: false + DB_CONNECTION_URI: postgresql+psycopg://postgres:postgres@localhost:5432/test_db + AUTH_USE_AUTH: false SENTRY_ENABLED: false - OPENTELEMETRY_ENABLED: false OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} diff --git a/src/config.py b/src/config.py index 28093788..ac425d6a 100644 --- a/src/config.py +++ b/src/config.py @@ -5,7 +5,7 @@ from typing import Annotated, Any, ClassVar, Optional import tomllib from dotenv import load_dotenv from pydantic import Field, field_validator -from pydantic_core.core_schema import FieldValidationInfo +from pydantic_core.core_schema import ValidationInfo from pydantic_settings import ( BaseSettings, PydanticBaseSettingsSource, @@ -140,7 +140,7 @@ class AuthSettings(TomlSettings): @field_validator("JWT_SECRET") @classmethod def _require_jwt_secret( - cls, v: Optional[str], info: FieldValidationInfo + cls, v: Optional[str], info: ValidationInfo ) -> Optional[str]: if info.data.get("USE_AUTH") and v is None: raise ValueError("JWT_SECRET must be set if USE_AUTH is true") diff --git a/tests/routes/test_validation_api.py b/tests/routes/test_validation_api.py index c8b4d4c9..e8cc1d22 100644 --- a/tests/routes/test_validation_api.py +++ b/tests/routes/test_validation_api.py @@ -373,63 +373,15 @@ def test_session_validations_api(client, sample_data): def test_agent_query_validations_api(client, sample_data, monkeypatch): - # Mock the functions in agent.py that are causing the database issues - - # Create a mock collection with a public_id - class MockCollection: - def __init__(self): - self.public_id = "mock_collection_id" - - # Mock collection retrieval/creation function - async def mock_get_or_create_collection(*args, **kwargs): - return MockCollection() - - async def mock_chat_history(*args, **kwargs): - return "Mock chat history", [], [] - - async def mock_get_long_term_facts(*args, **kwargs): - return ["Mock fact 1", "Mock fact 2"] - - async def mock_run_tom_inference(*args, **kwargs): - return "Mock TOM inference" - - async def mock_generate_user_representation(*args, **kwargs): - return "Mock user representation" - - # Mock the Dialectic.call method - async def mock_dialectic_call(self): - # Create a mock response that will work with line 300 in agent.py: - # return schemas.AgentChat(content=response[0]["text"]) - return [{"text": "Mock response"}] - - # Mock the Dialectic.stream method - def mock_dialectic_stream(self): - class MockStream: - def __enter__(self): - return self - - def __exit__(self, *args): - pass - - @property - def text_stream(self): - yield "Mock streamed response" - - return MockStream() - - # Apply the monkeypatches - monkeypatch.setattr( - "src.crud.get_or_create_user_protected_collection", - mock_get_or_create_collection, - ) - monkeypatch.setattr("src.utils.history.get_summarized_history", mock_chat_history) - monkeypatch.setattr("src.agent.get_long_term_facts", mock_get_long_term_facts) - monkeypatch.setattr("src.agent.run_tom_inference", mock_run_tom_inference) - monkeypatch.setattr( - "src.agent.generate_user_representation", mock_generate_user_representation - ) - monkeypatch.setattr("src.agent.Dialectic.call", mock_dialectic_call) - monkeypatch.setattr("src.agent.Dialectic.stream", mock_dialectic_stream) + # Mock the entire agent.chat function to avoid database queries + from src import schemas + + async def mock_agent_chat(*args, **kwargs): + # Return a simple mock response + return schemas.DialecticResponse(content="Mock response") + + # Apply the monkeypatch to the agent.chat function + monkeypatch.setattr("src.agent.chat", mock_agent_chat) test_app, test_user = sample_data # Create a session first since agent queries are likely session-based