Skip to content

Commit 00faee5

Browse files
committed
fix: review findings -- style_analyzer bugs, type annotations, duplicate test
style_analyzer.py: 1. Boolean precedence bug in _check_type_hints: 'type ' alone returned True without ': ' due to and/or precedence. Added parentheses. 2. Cache key mismatch: save_to_cache read 'languages' but analyze_repository_style returns 'language_distribution'. Caching was silently broken (iterated empty dict). Fixed key + load shape. 3. load_from_cache return type: was -> Dict, returns None. Fixed to -> Optional[Dict], added Optional to imports. 4. save_to_cache: added -> None return annotation. test_multi_tenancy.py: 5. Removed duplicate assertion block in test_verify_repo_access_raises_404_for_wrong_user (exact same verify_repo_access call repeated, dead code). 284 tests pass.
1 parent 37f4997 commit 00faee5

2 files changed

Lines changed: 7 additions & 12 deletions

File tree

backend/services/style_analyzer.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Analyzes team coding patterns, naming conventions, and best practices
44
"""
55
from pathlib import Path
6-
from typing import Dict, List, Set
6+
from typing import Dict, List, Optional, Set
77
from collections import defaultdict, Counter
88
import re
99

@@ -137,7 +137,7 @@ def _check_type_hints(self, source_code: str, language: str) -> bool:
137137
if language == 'python':
138138
return '->' in source_code or ': ' in source_code
139139
else:
140-
return ': ' in source_code and 'interface' in source_code or 'type ' in source_code
140+
return ': ' in source_code and ('interface' in source_code or 'type ' in source_code)
141141

142142
def analyze_repository_style(self, repo_path: str) -> Dict:
143143
"""Analyze coding style patterns across repository"""
@@ -264,14 +264,14 @@ def analyze_repository_style(self, repo_path: str) -> Dict:
264264

265265

266266
# SUPABASE CACHING
267-
def save_to_cache(self, repo_id: str, style_data: Dict):
267+
def save_to_cache(self, repo_id: str, style_data: Dict) -> None:
268268
"""Save style analysis to Supabase for caching"""
269269
from services.supabase_service import get_supabase_service
270270

271271
db = get_supabase_service()
272272

273-
# Group by language
274-
for language, data in style_data.get("languages", {}).items():
273+
# analyze_repository_style returns "language_distribution" not "languages"
274+
for language, data in style_data.get("language_distribution", {}).items():
275275
analysis = {
276276
"naming_convention": data.get("naming_conventions"),
277277
"async_usage": data.get("async_usage"),
@@ -284,7 +284,7 @@ def save_to_cache(self, repo_id: str, style_data: Dict):
284284

285285
logger.debug("Cached code style analysis in Supabase", repo_id=repo_id)
286286

287-
def load_from_cache(self, repo_id: str) -> Dict:
287+
def load_from_cache(self, repo_id: str) -> Optional[Dict]:
288288
"""Load style analysis from Supabase cache"""
289289
from services.supabase_service import get_supabase_service
290290

@@ -318,7 +318,7 @@ def load_from_cache(self, repo_id: str) -> Dict:
318318
logger.debug("Loaded cached code style from Supabase", repo_id=repo_id)
319319

320320
return {
321-
"languages": languages,
321+
"language_distribution": languages,
322322
"top_imports": common_imports,
323323
"patterns": patterns
324324
}

backend/tests/test_multi_tenancy.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -196,11 +196,6 @@ def test_verify_repo_access_raises_404_for_wrong_user(self):
196196

197197
assert exc_info.value.status_code == 404
198198

199-
with pytest.raises(HTTPException) as exc_info:
200-
verify_repo_access("repo-user2-a", "user-1")
201-
202-
assert exc_info.value.status_code == 404
203-
204199

205200
# DEV API KEY TESTS
206201
class TestDevApiKeySecurity:

0 commit comments

Comments
 (0)