Skip to content

Langent v3: Security hardening, logging, testing, and CI/CD#1

Merged
AlexAI-MCP merged 2 commits intomainfrom
claude/analyze-repo-quality-Q1hWh
Feb 25, 2026
Merged

Langent v3: Security hardening, logging, testing, and CI/CD#1
AlexAI-MCP merged 2 commits intomainfrom
claude/analyze-repo-quality-Q1hWh

Conversation

@AlexAI-MCP
Copy link
Owner

Summary

This PR upgrades Langent from v2 to v3 with comprehensive security fixes, structured logging, test coverage, and CI/CD infrastructure. The codebase is now production-ready with hardened input validation, removed credentials, and automated quality checks.

Key Changes

Security (Critical)

  • Removed hardcoded credentials: Replaced password: str = "yw02280228" with safe default "password" in config.py and graph.py
  • Cypher injection prevention: Added _validate_identifier() function in graph.py to sanitize Neo4j labels and property keys against injection attacks
  • API authentication: Added optional API key verification via verify_api_key() dependency in api.py
  • Input validation: Converted FastAPI endpoints to use Pydantic request models (IngestRequest, GraphQueryRequest) instead of raw query parameters
  • Removed sys.path hacks: Eliminated sys.path.insert() calls in api.py and mcp_server.py that indicated packaging issues

Logging & Observability

  • Replaced all print() with logging module: Converted custom _log() methods and print statements across all modules to use Python's standard logging framework
  • Added logger instances: Each module now has logger = logging.getLogger(__name__) for structured logging
  • Proper log levels: Uses logger.info(), logger.warning(), logger.error() instead of silent exception swallowing

Testing (New)

  • Comprehensive test suite: Added 40+ test cases across 8 test files:
    • test_vector_store.py: VectorStore deduplication, search, deletion
    • test_graph_store.py: Cypher injection prevention validation
    • test_chunker.py: Document chunking with overlap and size constraints
    • test_ingest.py: File scanning and text extraction
    • test_config.py: Configuration loading and defaults
    • test_llm_proxy.py: LLM proxy modes (fake, mcp, ollama)
    • test_workflows.py: AgentState structure and f-string interpolation fix
  • Test fixtures: Created conftest.py with reusable fixtures (tmp_workspace, vector_store, config)
  • Proper pytest structure: Replaced monolithic test script with organized test classes and assertions

Bug Fixes

  • Fixed f-string interpolation bug in workflows.py: Changed ${query}, ${context}, ${graph_str} to proper Python f-string syntax {query}, {context}, {graph_str} (lines 95-101)
  • Fixed MCP server method call: Changed agent.graph.query() to agent.graph_query() in mcp_server.py:137
  • Removed duplicate imports: Cleaned up duplicate import json in api.py
  • Removed hardcoded Windows path: Replaced personal workspace path fallback with environment variable in mcp_server.py

Code Quality & Architecture

  • FastAPI improvements:
    • Added dependency injection pattern with Depends(get_langent) and Depends(verify_api_key)
    • Converted endpoints to use Pydantic models for request/response validation
    • Added query parameter validation with Query(default=5, ge=1, le=100)
  • Type safety: Fixed type hints (Optional[str] = None instead of str = None)
  • Refactored Langent.init: Extracted graph initialization to _init_graph() method for better error handling
  • Removed global mutable state: Improved singleton pattern with proper lazy initialization

CI/CD & DevOps (New)

  • GitHub Actions workflow: Added .github/workflows/ci.yml with:
    • Linting via ruff check on Python 3.11
    • Test matrix across Python 3.10, 3.11, 3.12
    • Automated checks on push to main/develop and

https://claude.ai/code/session_016U1fwL9D4aZQaF6rsrThpC

Analyzes all 15 source files across architecture, code quality,
type safety, error handling, testing, security, documentation,
CI/CD, and dependency management. Identifies critical issues
including hardcoded credentials, Cypher injection risks, a
variable interpolation bug in workflows.py, and near-zero
test coverage. Overall score: 5.7/10 (C+).

https://claude.ai/code/session_016U1fwL9D4aZQaF6rsrThpC
…haul

P0 — Critical bug fixes:
- Remove hardcoded Neo4j password from config.py and graph.py
- Fix ${query} interpolation bug in workflows.py (was not substituting variables)
- Fix mcp_server.py calling nonexistent agent.graph.query() -> agent.graph_query()
- Remove hardcoded Windows path fallback in mcp_server.py

P1 — Security & quality:
- Add Cypher injection prevention with _validate_identifier() in GraphStore
- Replace all print() with structured logging module across all 15 source files
- Add optional API key authentication middleware for write endpoints
- Add Pydantic request models for FastAPI (IngestRequest, GraphQueryRequest)
- Add FastAPI dependency injection (replace global singleton pattern)
- Add input validation with Query() constraints on API parameters
- Add /health endpoint
- Add requests timeout for Ollama proxy
- Add missing 'requests' to dependencies

P1 — Testing:
- Add comprehensive pytest suite: 47 test cases across 7 test files
- conftest.py with shared fixtures (tmp_workspace, vector_store, config)
- test_config.py: config loading, no hardcoded creds verification
- test_chunker.py: chunking logic, edge cases, metadata preservation
- test_ingest.py: file scanning, text extraction, ingestion pipeline
- test_graph_store.py: Cypher injection prevention validation
- test_vector_store.py: CRUD, search, deduplication, collections
- test_llm_proxy.py: all LLM modes, v3 branding
- test_workflows.py: verifies ${} bug is fixed via source inspection

P2 — DevOps & tooling:
- Add GitHub Actions CI (lint + test on Python 3.10/3.11/3.12)
- Add Dockerfile for containerized deployment
- Add .dockerignore
- Add ruff config (pyproject.toml) for linting
- Add mypy config for type checking
- Add pytest config (testpaths, asyncio_mode)
- Remove sys.path.insert() hacks from api.py and mcp_server.py
- Add 'status' CLI command
- Update README with v3 changes, Docker instructions, dev workflow

All 47 tests pass.

https://claude.ai/code/session_016U1fwL9D4aZQaF6rsrThpC
@AlexAI-MCP AlexAI-MCP merged commit 815d516 into main Feb 25, 2026
0 of 4 checks passed
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.

2 participants