fix: clear ruff so the pre-push gate passes

105 findings to zero. Most were mechanical — 67 unused imports, and assorted
f-strings without placeholders. Three groups needed a decision.

The 15 F821 "undefined name" were forward references, not runtime errors. Each
annotation is quoted — `-> "WikiService"`, `Optional["IngestionService"]` — with
the real import inside the function body to break an import cycle. A quoted
annotation is never evaluated, so the code ran; the names were simply
unresolvable to any checker. They now have a TYPE_CHECKING block, which costs
nothing at import time and keeps the cycle broken.

The 6 E402 split two ways. `import secrets`, `Security`, `Request` and
`HTTPBearer` in dependencies.py had drifted below several hundred lines of
factory functions for no reason — stdlib and fastapi, no cycle to avoid — and
moved up. The other three are deliberate and now say so: the VectorService and
GraphService aliases import back into dependencies.py, and main.py's routers
expect a configured app, so both must stay put.

Bare `except:` narrowed to `except Exception:` in three places, which stops them
swallowing KeyboardInterrupt and SystemExit.

The 5 unused locals were all genuinely dead. One is worth naming rather than
fixing: qdrant_client.delete()'s return value was bound and never read, so a
failed delete is indistinguishable from a successful one — the assignment is
gone, but nothing checks the status either way and that has not changed here.
`timing = {}` in _retrieve_parallel looked like it might mean the reported
per-leg timings were always zero; traced, and they come from output["timing"],
so the local was only vestigial.

426 passed, 29 skipped, unchanged. The app imports and the service aliases still
resolve, which is the check that mattered after moving imports in
dependencies.py.

The gate still prints "not gated here yet: test (T-56)" — lint is green, tests
remain unwired, and that is left visible rather than silently absent.

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2026-08-11 17:04:58 +02:00
co-authored by Claude
parent 4ad6598129
commit a687b770ef
36 changed files with 95 additions and 99 deletions
+2 -5
View File
@@ -12,9 +12,7 @@ Run with: pytest tests/test_consolidation.py -v -s
"""
import pytest
import pytest_asyncio
from unittest.mock import AsyncMock, MagicMock, patch
from typing import AsyncGenerator
from unittest.mock import AsyncMock, MagicMock
from datetime import datetime
import json
@@ -22,8 +20,7 @@ from src.services.consolidation_service import ConsolidationService
from src.models.consolidation import (
ConsolidationRequest,
ConsolidationResponse,
ConsolidationResult,
SearchQueryInfo
ConsolidationResult
)
# Test constants
+1 -1
View File
@@ -480,4 +480,4 @@ async def test_cleanup_entity_linking_test_data(neo4j_client):
"""
await neo4j_client.execute_query(cleanup_query)
print(f"\n✓ Cleaned up entity linking test data")
print("\n✓ Cleaned up entity linking test data")
+1 -3
View File
@@ -10,9 +10,7 @@ Run with: pytest tests/test_graph_service.py -v -s
"""
import pytest
import pytest_asyncio
from unittest.mock import AsyncMock, MagicMock, patch
from typing import AsyncGenerator
from unittest.mock import AsyncMock
from src.services.graph_service import GraphService
+7 -7
View File
@@ -29,7 +29,7 @@ from src.clients.content_extractor import ContentExtractor
from src.services.hybrid_rag_service import HybridRAGService
from src.services.vector_service import VectorService
from src.services.graph_service import GraphService
from src.models.hybrid_rag import HybridRAGConfig, HybridRAGRequest
from src.models.hybrid_rag import HybridRAGConfig
from src.config import get_settings
# Test user to isolate test data
@@ -176,7 +176,7 @@ We deploy microservices using Helm charts and manage them with kubectl.
# Cleanup
try:
await wiki_client.delete_page(page["id"])
except:
except Exception:
pass
except Exception as e:
pytest.skip(f"Could not create test page: {e}")
@@ -531,7 +531,7 @@ class TestPhase6_Persistence:
result = await neo4j_client.execute_query(query, {"search_id": search_id})
assert len(result) == 1
assert result[0]["query"] == "test query"
assert result[0]["processed"] == False
assert not result[0]["processed"]
# Cleanup
cleanup_query = f"""
@@ -614,7 +614,7 @@ class TestHybridRAG_EndToEnd:
assert len(response.context) > 0
# Log results for inspection
print(f"\n=== HybridRAG E2E Test Results ===")
print("\n=== HybridRAG E2E Test Results ===")
print(f"Query: {response.query}")
print(f"Total Results: {response.total_results}")
print(f"Source Counts: {response.source_counts}")
@@ -623,7 +623,7 @@ class TestHybridRAG_EndToEnd:
print(f"Search ID: {response.search_id}")
if response.results:
print(f"\nTop Result:")
print("\nTop Result:")
top = response.results[0]
print(f" Title: {top.title}")
print(f" Source: {top.source_type}")
@@ -674,7 +674,7 @@ class TestHybridRAG_EndToEnd:
config = HybridRAGConfig()
start = time.time()
response = await hybrid_rag_service.search(
await hybrid_rag_service.search(
query="kubernetes orchestration",
user=TEST_USER,
config=config
@@ -722,7 +722,7 @@ async def test_cleanup_test_data(neo4j_client, qdrant_client):
collection_name = get_qdrant_collection_name(TEST_USER)
try:
await qdrant_client.delete_collection(collection_name)
except:
except Exception:
pass
print(f"\n✓ Cleaned up test data for user: {TEST_USER}")
+2 -6
View File
@@ -11,16 +11,12 @@ Run with: pytest tests/test_ingestion.py -v -s
"""
import pytest
import pytest_asyncio
from unittest.mock import AsyncMock, MagicMock, patch
from typing import AsyncGenerator
from unittest.mock import AsyncMock, MagicMock
from src.services.ingestion_service import IngestionService
from src.models.ingestion import (
IngestionRequest,
IngestionResult,
BatchIngestionRequest,
BatchIngestionResult
BatchIngestionRequest
)
+2 -4
View File
@@ -8,7 +8,7 @@ Tests cleanup of:
"""
import pytest
from unittest.mock import AsyncMock, MagicMock, patch
from unittest.mock import AsyncMock, MagicMock
from src.routers.maintenance import (
cleanup_vectors,
cleanup_graph,
@@ -18,9 +18,7 @@ from src.routers.maintenance import (
CleanupResult,
VectorCleanupResponse,
GraphCleanupResponse,
FullCleanupResponse,
HealthCheckResponse,
ReindexResponse
HealthCheckResponse
)
+1 -1
View File
@@ -1,7 +1,7 @@
"""Tests for RAG search service and endpoints."""
import pytest
from unittest.mock import AsyncMock, MagicMock, patch
from unittest.mock import AsyncMock, MagicMock
from src.models.rag_search import (
SearchType,
-2
View File
@@ -538,8 +538,6 @@ class TestSmartCreateEndpoint:
@pytest.mark.asyncio
async def test_endpoint_returns_201(self, mock_clients):
"""Test that successful creation returns 201 status."""
from fastapi.testclient import TestClient
from unittest.mock import patch
# This test would require more setup with FastAPI TestClient
# For now, we test the model validation
+1 -1
View File
@@ -539,7 +539,7 @@ class TestVolatileCleanupEndpoint:
@pytest.mark.asyncio
async def test_cleanup_volatile(self):
"""Test volatile cleanup endpoint."""
from src.routers.maintenance import cleanup_volatile, VolatileCleanupResponse
from src.routers.maintenance import cleanup_volatile
mock_qdrant = AsyncMock()
mock_qdrant.get_volatile_collections = AsyncMock(return_value=[
+1 -2
View File
@@ -10,7 +10,6 @@ Tests the PostgreSQL NOTIFY/LISTEN change detection system including:
"""
import pytest
import asyncio
from unittest.mock import AsyncMock, MagicMock, patch
from datetime import datetime, timedelta
@@ -238,7 +237,7 @@ class TestWikiChangeListener:
async def test_process_page_delete_calls_cleanup(self, listener):
"""Test that DELETE events call cleanup_deleted_page."""
with patch('src.routers.webhooks.cleanup_deleted_page', new_callable=AsyncMock) as mock_cleanup, \
patch('src.services.wiki_change_listener.get_ingestion_service') as mock_service:
patch('src.services.wiki_change_listener.get_ingestion_service'):
await listener._process_page_change(
page_id=123,