diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index 5b3039c..2dfd088 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -37,4 +37,4 @@ jobs: run: ruff check . - name: Run Pytest - run: pytest -s + run: pytest diff --git a/src/app/main.py b/src/app/main.py index 4ba6d20..9d14eb1 100644 --- a/src/app/main.py +++ b/src/app/main.py @@ -103,5 +103,9 @@ if __name__ == "__main__": import uvicorn uvicorn.run( - "src.app.main:app", host="0.0.0.0", port=8000, reload=True, log_level="info" + app="src.app.main:app", + host="0.0.0.0", + port=8000, + reload=True, + log_level="info", ) diff --git a/src/app/routers/health.py b/src/app/routers/health.py index a2d4175..3c1a1c4 100644 --- a/src/app/routers/health.py +++ b/src/app/routers/health.py @@ -1,5 +1,8 @@ from fastapi import APIRouter from src.app.config import settings +from src.services.chroma_store import ChromaStore +from src.services.embeddings import EmbeddingService +from datetime import datetime, timezone router = APIRouter(tags=["health"]) @@ -7,9 +10,6 @@ router = APIRouter(tags=["health"]) @router.get("/healthz") async def health_check(): try: - from src.services.chroma_store import ChromaStore - from src.services.embeddings import EmbeddingService - chroma_store = ChromaStore() doc_count = chroma_store.get_count() @@ -45,9 +45,7 @@ async def health_check(): }, } - import datetime - - health_status["timestamp"] = datetime.datetime.utcnow().isoformat() + "Z" + health_status["timestamp"] = datetime.now(timezone.utc) if doc_count == 0: health_status["status"] = "degraded" @@ -67,8 +65,6 @@ async def health_check(): @router.get("/readiness") async def readiness_check(): try: - from src.services.chroma_store import ChromaStore - chroma_store = ChromaStore() doc_count = chroma_store.get_count() diff --git a/src/app/routers/ingest.py b/src/app/routers/ingest.py index 5404782..af1ff68 100644 --- a/src/app/routers/ingest.py +++ b/src/app/routers/ingest.py @@ -3,6 +3,8 @@ from fastapi import APIRouter, HTTPException, Depends, Header from typing import Optional from src.app.config import settings +from src.ingest.ingest_cli import run_ingest +from src.services.chroma_store import ChromaStore router = APIRouter(prefix="/api/v1/admin", tags=["administration"]) @@ -24,8 +26,6 @@ def verify_admin_token(authorization: Optional[str] = Header(None)): @router.post("/ingest") async def trigger_ingest(recreate: bool = False, _: bool = Depends(verify_admin_token)): try: - from src.ingest.ingest_cli import run_ingest - data_dir = "articles_konsol_pro" platform_file = "data/platform_overview.md" persist_dir = settings.chroma_persist_dir @@ -61,8 +61,6 @@ async def trigger_ingest(recreate: bool = False, _: bool = Depends(verify_admin_ @router.get("/knowledge-base/stats") async def get_knowledge_base_stats(_: bool = Depends(verify_admin_token)): try: - from src.services.chroma_store import ChromaStore - chroma_store = ChromaStore() doc_count = chroma_store.get_count() @@ -91,8 +89,6 @@ async def get_knowledge_base_stats(_: bool = Depends(verify_admin_token)): @router.delete("/knowledge-base") async def clear_knowledge_base(_: bool = Depends(verify_admin_token)): try: - from src.services.chroma_store import ChromaStore - chroma_store = ChromaStore() chroma_store.delete_collection() diff --git a/src/tests/test_api.py b/src/tests/test_api.py index deae14b..a458105 100644 --- a/src/tests/test_api.py +++ b/src/tests/test_api.py @@ -1,3 +1,4 @@ +from unittest.mock import patch from fastapi.testclient import TestClient import sys import os @@ -7,11 +8,13 @@ sys.path.append( ) from src.app.main import app +from src.app.config import settings client = TestClient(app) -def test_health_endpoint(): +@patch("src.app.routers.health.EmbeddingService") +def test_health_endpoint(mock_embedding_service): response = client.get("/healthz") assert response.status_code == 200 data = response.json() @@ -107,8 +110,6 @@ def test_admin_endpoints_without_auth(): def test_admin_endpoints_with_auth(): - from src.app.config import settings - headers = {"Authorization": f"Bearer {settings.api_secret_key}"} response = client.get("/api/v1/admin/knowledge-base/stats", headers=headers)