Skip to content

[EPIC] Implement Comprehensive Test Coverage for TGB-MicroSuite #35

@maxzaikin

Description

@maxzaikin

Service Description

Current State & Problem

The TGB-MicroSuite project currently lacks a systematic, automated testing strategy. Code quality is primarily verified through manual checks and occasional ad-hoc scripting, which is slow, error-prone, and not scalable. This absence of a "test safety net" makes refactoring existing code extremely risky, slows down the development of new features, and critically, prevents the project from achieving the reliability required for production deployment.

Without a robust test suite, we cannot confidently deploy changes, leading to a high risk of introducing regressions (breaking existing functionality) and a prolonged, inefficient development cycle.

Goals & Objectives

This epic aims to establish a comprehensive, multi-layered testing framework across the entire TGB-MicroSuite project, focusing on the a-rag and tg-gateway services. The primary goal is to build a robust safety net that guarantees code quality, prevents regressions, and enables confident, rapid development and CI/CD integration. We will adopt a structured approach based on the Testing Pyramid philosophy.


1. Establish Core Testing Infrastructure

  • Description: Configure the project to fully support pytest, including dependency management, test discovery, and code coverage analysis.
  • Tasks:
    • Integrate pytest and key plugins (pytest-cov, pytest-asyncio) as development dependencies in the pyproject.toml for each service.
    • Create a standard tests/ directory structure (tests/unit, tests/integration) within both a-rag and tg-gateway services.
    • Configure pytest via pyproject.toml to correctly handle the src layout (pythonpath = ["src"]) and define test paths.

2. Implement Unit Test Coverage (The Foundation)

  • Description: Cover all critical, isolated business logic with fast and reliable unit tests. This forms the base of our testing pyramid.
  • Tasks:
    • Identify and write unit tests for all "pure" functions and classes that have no external dependencies (e.g., core/config.py, core/profiling.py, pipeline processors).
    • Write comprehensive unit tests for modules containing critical business logic, using mocking (monkeypatch) to isolate them from external systems (database, external APIs).
    • Achieve a target of >95% unit test coverage for all modules in the core, agent, and pipelines directories of the a-rag service.

3. Implement Integration Test Coverage (Service Interactions)

  • Description: Write tests to verify the interaction between different components within a service, and between the service and external infrastructure like databases.
  • Tasks:
    • Develop integration tests for all FastAPI API endpoints in the a-rag service using TestClient.
    • Verify request/response schemas, status codes, and authentication/authorization logic for all routers (auth_router, llm_router, etc.).
    • Write tests that validate the interaction with the relational database (PostgreSQL/SQLite) by using a dedicated test database.
    • Write tests to confirm correct interaction with the vector database (Qdrant) and Redis.

4. Automate Testing with Continuous Integration (CI)

  • Description: Create a CI pipeline that automatically runs the entire test suite on every code change, providing immediate feedback and preventing faulty code from being merged.
  • Tasks:
    • Create a GitHub Actions workflow file (.github/workflows/ci.yml).
    • Configure the workflow to trigger on every push to feature branches and on every pull_request to main/develop.
    • The CI job must:
      1. Install project dependencies using uv.
      2. Run the complete pytest suite for all services.
      3. Calculate and report code coverage using pytest-cov.
    • Implement a branch protection rule that requires the CI checks to pass before a Pull Request can be merged.

Definition of Done

  • The core testing infrastructure is fully configured and documented.
  • Overall project test coverage exceeds 85%.
  • All critical business logic modules are covered by unit tests at >95%.
  • All API endpoints are covered by integration tests.
  • A green CI pipeline is successfully running and required for all Pull Requests.
  • The README is updated with instructions on how to run the test suite locally.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    Status

    In progress

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions