Skip to content

Feature/cgai increase coverage#18

Closed
Yosoyepa wants to merge 10 commits intomainfrom
feature/CGAI-increase-coverage
Closed

Feature/cgai increase coverage#18
Yosoyepa wants to merge 10 commits intomainfrom
feature/CGAI-increase-coverage

Conversation

@Yosoyepa
Copy link
Owner

@Yosoyepa Yosoyepa commented Dec 1, 2025

📋 Descripción

Este PR aumenta la cobertura de tests del backend de 96.25% a 97.46% con 175 tests pasando.

🎯 Cambios Realizados

Nuevos Tests Agregados

Archivo Tests Cobertura Anterior Cobertura Nueva
tests/unit/models/test_code_review.py 4 tests 89% 100%
tests/unit/models/test_finding.py 8 tests 88% 100%
tests/unit/dependencies/test_get_db.py 4 tests 50% 100%

Tests Corregidos

  • test_auth_router.py: Corregidos tests de "missing token" para aceptar 401 o 403 (diferencia entre versiones de FastAPI/Starlette)
  • test_finding.py: Corregido assertion de severity para esperar "HIGH" (mayúsculas) según el enum

📊 Métricas de Cobertura

  • TOTAL 907 23 97%
  • Required test coverage of 75% reached. Tota coverage: 97.46%
  • 175 passed, 6 warnings in 19.17s

✅ Checklist

  • Tests pasan localmente (pytest tests/ --cov=src -v)
  • Tests pasan en GitHub Actions (Linux Python 3.11)
  • Cobertura supera el umbral mínimo (75%)
  • Sin errores de lint
  • Código sigue los principios de diseño del proyecto

🔗 Relacionado

  • Branch: feature/CGAI-increase-coverage
  • Issue: Mejora de cobertura de tests

📝 Notas

Los archivos con cobertura < 100% restantes son:

  • security_agent.py (92%) - Ramas de edge cases complejos
  • code_review_repository.py (89%) - Líneas 74-77 de manejo de errores
  • settings.py (95%) - Línea 57 de configuración condicional
  • observers.py (83%) - Línea 22 de logging
  • schemas/analysis.py (99%) - Línea 80

Yosoyepa and others added 10 commits November 27, 2025 02:23
- Add UserEntity with Clerk ID, rate limiting, and role management
- Add CodeReviewEntity with encrypted code storage support
- Add AgentFindingEntity with severity and quality metrics
- Create enums: SeverityEnum, UserRole aligned with PostgreSQL ENUMs
- Configure Alembic env.py for model discovery and autogenerate
- Implement relationships with cascade delete for data integrity

Related CGAI-15
- Create users table with Clerk ID, role, rate limiting fields
- Create code_reviews table with encrypted code storage
- Create agent_findings table with severity and metrics
- Add PostgreSQL ENUMs: userrole, reviewstatus, severityenum
- Add indexes for performance optimization
- Configure cascade delete for data integrity

Migration ID: ba48c1bb8e18
Related CGAI-15
feat(database): integrate Supabase PostgreSQL with SQLAlchemy models and Alembic migrations
- Add ClerkClient for JWT validation with HS256 algorithm
- Add UserRepository for CRUD operations on users table
- Add AuthService to orchestrate login and token validation
- Add auth dependency (get_current_user, get_optional_user)
- Add /api/v1/auth/login and /api/v1/auth/me endpoints
- Sync users from Clerk to Supabase on login
- Add email-validator dependency for pydantic EmailStr

Closes CGAI-28
feat(auth): Clerk JWT authentication with Supabase user sync

- Add ClerkClient for JWT validation with HS256 algorithm
- Add UserRepository for CRUD operations on users table
- Add AuthService to orchestrate login and token validation
- Add auth dependency (get_current_user, get_optional_user)
- Add /api/v1/auth/login and /api/v1/auth/me endpoints
- Sync users from Clerk to Supabase on login
- Add email-validator dependency for pydantic EmailStr

Closes CGAI-28
- Add 12 tests for UserRepository (get_by_id, create, update, delete)
- Add 10 tests for UserEntity (can_analyze, increment_analysis_count)
- Add 9 integration tests for auth endpoints (/login, /me)
- Coverage increased from 92% to 96%
- Add tests for CodeReviewEntity (__repr__, calculate_quality_score)
- Add tests for AgentFindingEntity (penalty, to_dict, __repr__)
- Add tests for get_db dependency (session lifecycle)
- Fix auth router tests to accept 401/403 for missing token
- Fix severity assertion to expect uppercase enum values

Coverage improvements:
- code_review.py: 89% -> 100%
- finding.py: 88% -> 100%
- get_db.py: 50% -> 100%

Total: 175 tests, 97.46% coverage
@Yosoyepa Yosoyepa closed this Dec 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant