Skip to content

Commit f3e9d34

Browse files
author
GeNa8880
committed
refactor: fix all project-wide quality issues found by full audit
- Fix 5 failing multilingual tests (rate limiter accumulation across tests) - Add autouse fixture to reset rate limiter between tests - Fix all ruff lint errors (E402, F401, I001, E501) - Fix ruff formatting for 5 test files - Fix all 6 mypy errors (pydantic-settings call-arg, arg-type, assignment) - Add mypy, vulture, interrogate to dev dependencies - Remove unused import in test_api_rate_limiting.py
1 parent df40637 commit f3e9d34

16 files changed

Lines changed: 280 additions & 43 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,4 @@ CLAUDE.md
4444
docs/audit-fixes.md
4545
docs/audit-technical-spec.md
4646
.hypothesis/
47+
AUDIT-PLAN.md

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ dev = [
3535
"schemathesis>=3.38",
3636
"bandit>=1.7.0",
3737
"pip-audit>=2.7.0",
38+
"mypy>=1.19.1",
39+
"vulture>=2.15",
40+
"interrogate>=1.7.0",
3841
]
3942

4043
[build-system]

src/rag_engine/api/app.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from rag_engine.models.config import Settings
1111
from rag_engine.utils.logging import setup_logging
1212

13-
settings = Settings()
13+
settings = Settings() # type: ignore[call-arg]
1414

1515

1616
def create_app() -> FastAPI:
@@ -25,7 +25,7 @@ def create_app() -> FastAPI:
2525

2626
# Rate limiting
2727
app.state.limiter = limiter
28-
app.add_exception_handler(RateLimitExceeded, _rate_limit_exceeded_handler)
28+
app.add_exception_handler(RateLimitExceeded, _rate_limit_exceeded_handler) # type: ignore[arg-type]
2929

3030
app.add_middleware(
3131
CORSMiddleware,

src/rag_engine/api/dependencies.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from rag_engine.storage.knowledge_graph import KnowledgeGraphStore
1313
from rag_engine.storage.qdrant_store import QdrantStore
1414

15-
_settings = Settings()
15+
_settings = Settings() # type: ignore[call-arg]
1616
_logger = structlog.get_logger()
1717

1818
VALID_ID_PATTERN = re.compile(r"^[a-zA-Z0-9_-]{1,128}$")

src/rag_engine/api/routes/health.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from rag_engine.models.health import HealthResponse, HealthStatus
77

88
router = APIRouter(tags=["system"])
9-
settings = Settings()
9+
settings = Settings() # type: ignore[call-arg]
1010

1111

1212
@router.get("/health", response_model=HealthResponse)

src/rag_engine/ingestion/parsers/docx_parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def parse(self, file_path: Path) -> str:
2121
Concatenated text from all paragraphs.
2222
"""
2323
try:
24-
document = Document(file_path)
24+
document = Document(str(file_path))
2525
except Exception as exc:
2626
raise IngestionError(f"Failed to open DOCX: {file_path}") from exc
2727

src/rag_engine/services/embedding.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def __init__(self, model_name: str = "intfloat/multilingual-e5-large") -> None:
2525
model_name: HuggingFace model identifier.
2626
"""
2727
self._model_name = model_name
28-
self._model = None
28+
self._model: Any = None
2929

3030
@property
3131
def model(self) -> Any:

tests/conftest.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,16 @@
1212
)
1313
settings.load_profile(os.getenv("HYPOTHESIS_PROFILE", "default"))
1414

15-
import pytest
16-
from fastapi.testclient import TestClient
17-
from qdrant_client import QdrantClient
15+
import pytest # noqa: E402
16+
from fastapi.testclient import TestClient # noqa: E402
17+
from qdrant_client import QdrantClient # noqa: E402
1818

19-
from rag_engine.api.app import create_app
20-
from rag_engine.services.gdpr import GDPRService
21-
from rag_engine.storage.bm25_store import BM25Store
22-
from rag_engine.storage.knowledge_graph import KnowledgeGraphStore
23-
from rag_engine.storage.qdrant_store import QdrantStore
19+
from rag_engine.api.app import create_app # noqa: E402
20+
from rag_engine.api.routes.rate_limit import limiter # noqa: E402
21+
from rag_engine.services.gdpr import GDPRService # noqa: E402
22+
from rag_engine.storage.bm25_store import BM25Store # noqa: E402
23+
from rag_engine.storage.knowledge_graph import KnowledgeGraphStore # noqa: E402
24+
from rag_engine.storage.qdrant_store import QdrantStore # noqa: E402
2425

2526
TEST_API_KEY = "test-api-key"
2627

@@ -65,8 +66,15 @@ def gdpr_service(
6566
return GDPRService(bm25_store, graph_store, qdrant_store)
6667

6768

69+
@pytest.fixture(autouse=True)
70+
def _fresh_rate_limiter():
71+
"""Reset the rate limiter before each test to avoid cross-test 429 errors."""
72+
limiter.reset()
73+
yield
74+
75+
6876
@pytest.fixture
6977
def test_client() -> TestClient:
70-
"""FastAPI test client."""
78+
"""FastAPI test client with a fresh rate limiter."""
7179
app = create_app()
7280
return TestClient(app)

tests/integration/test_api_rate_limiting.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
from slowapi.errors import RateLimitExceeded
77
from slowapi.util import get_remote_address
88

9-
from rag_engine.api.dependencies import verify_api_key
10-
119

1210
class TestAPIRateLimiting:
1311
"""Verify rate limiter returns 429 when limits are exceeded."""

tests/integration/test_api_schema.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
"""API schema validation tests using Schemathesis."""
22

33
import schemathesis
4+
from schemathesis.openapi import from_asgi
45
from slowapi import Limiter
56
from slowapi.util import get_remote_address
6-
from schemathesis.openapi import from_asgi
77

88
from rag_engine.api.app import create_app
99
from rag_engine.api.routes import rate_limit

0 commit comments

Comments
 (0)