src — testing

Module: src-testing Cohesion: 0.80 Members: 0

src — testing

The src/testing module provides a comprehensive suite of tools for integrating testing and quality assurance directly into the development workflow, particularly when working with AI agents. It encompasses AI integration tests, automated linting, automated code testing, code coverage management, and a structured Test-Driven Development (TDD) mode.

The primary goal of this module is to enable AI agents to autonomously verify their code generation, adhere to coding standards, and follow development methodologies like TDD, thereby improving code quality and reducing iteration cycles.

Core Components

The src/testing module is composed of several distinct but interconnected sub-modules:

  1. AI Integration Tests (ai-integration-tests.ts): Validates the capabilities of the configured AI provider.
  2. Auto-Lint Integration (auto-lint.ts): Automatically runs linters and formats code.
  3. Auto-Test Integration (auto-test.ts): Automatically runs tests using various frameworks.
  4. Coverage Targets (coverage-targets.ts): Manages and compares code coverage thresholds.
  5. TDD Mode (tdd-mode.ts): Orchestrates a Test-Driven Development workflow.

1. AI Integration Tests (ai-integration-tests.ts)

This module is responsible for verifying the functionality and reliability of the currently configured AI provider by making real API calls. It covers essential AI capabilities such as basic completion, streaming responses, tool calling, and error handling.

AITestRunner Class

The AITestRunner is the central class for executing AI integration tests. It extends EventEmitter to provide real-time feedback on test progress.


2. Auto-Lint Integration (auto-lint.ts)

This module provides automated linting capabilities, detecting and optionally fixing code style and quality issues. It supports a range of languages and linters by abstracting their execution and output parsing.

AutoLintManager Class

The AutoLintManager is responsible for detecting available linters in a project, running them on specified files, and formatting their output. It also extends EventEmitter.


3. Auto-Test Integration (auto-test.ts)

This module automates the execution of tests, providing structured results and supporting various testing frameworks. It's designed to integrate Test-Driven Development (TDD) workflows and provide immediate feedback on code changes.

AutoTestManager Class

The AutoTestManager detects the project's testing framework, runs tests, and processes their output. It also extends EventEmitter.


4. Coverage Targets (coverage-targets.ts)

This utility module helps in defining and comparing code coverage thresholds, typically read from project configuration files.

Key Functions


5. TDD Mode (tdd-mode.ts)

This module implements a structured Test-Driven Development (TDD) workflow, guiding an AI agent through the "red-green-refactor" cycle. It aims to improve code quality by ensuring tests are written before implementation.

TDDModeManager Class

The TDDModeManager orchestrates the TDD cycle, managing its state, generating prompts for the LLM, and processing test results. It extends EventEmitter.


Module Architecture

The src/testing module is designed with a clear separation of concerns, with each manager (AITestRunner, AutoLintManager, AutoTestManager, TDDModeManager) handling a specific aspect of testing.

graph TD
    subgraph Testing Module
        A[AITestRunner] --> CB(CodeBuddyClient)
        AL[AutoLintManager] --> CP(Child Process)
        AT[AutoTestManager] --> CP
        TDD[TDDModeManager] --> AT
        CT[Coverage Targets]
    end

    commands[Commands/Handlers] --> A
    commands --> AL
    commands --> AT
    commands --> TDD
    commands --> CT

    style A fill:#e0f7fa,stroke:#00796b,stroke-width:2px
    style AL fill:#e0f7fa,stroke:#00796b,stroke-width:2px
    style AT fill:#e0f7fa,stroke:#00796b,stroke-width:2px
    style TDD fill:#e0f7fa,stroke:#00796b,stroke-width:2px
    style CT fill:#e0f7fa,stroke:#00796b,stroke-width:2px
    style CB fill:#fff3e0,stroke:#e65100,stroke-width:1px
    style CP fill:#fff3e0,stroke:#e65100,stroke-width:1px
    style commands fill:#f3e5f5,stroke:#8e24aa,stroke-width:1px

Key Architectural Patterns:

Contributing to the Module

When contributing to the src/testing module, consider the following: