tests — commands

Module: tests-commands Cohesion: 0.80 Members: 0

tests — commands

This document provides an overview of the tests/commands module, which is dedicated to ensuring the correctness and reliability of the application's command-line interface (CLI) and in-chat slash commands.

Module Overview

The tests/commands module contains unit and integration tests for the various command handlers defined in src/commands/handlers and src/commands/cli. Its primary purpose is to validate:

By thoroughly testing these commands, developers can ensure a consistent and predictable user experience, as well as the stability of the core command processing logic.

Testing Strategy

The tests in this module employ a common strategy to achieve isolation and reliability:

  1. Mocking Dependencies: External modules and services (e.g., fs, LLM clients, various managers like LessonsTracker, SkillsHub, AutonomyManager) are extensively mocked using jest.mock or vi.mock. This allows tests to focus solely on the command handler's logic without relying on actual filesystem operations, network calls, or complex state management.
  2. CommandHandlerResult Validation: Many command handlers return a CommandHandlerResult object. Tests frequently assert on the properties of this object, such as:

  1. Spying on Interactions: jest.spyOn or vi.spyOn are used to verify that mocked functions are called with the correct arguments and the expected number of times, ensuring that the command handlers interact with their dependencies as intended.
  2. CLI Program Simulation: For commander.js-based CLI commands, a mock Command program is created, and parseAsync is used to simulate command-line execution, capturing console.log and console.error output for validation.

Example: Mocking for Isolation

The following Mermaid diagram illustrates the general testing approach, using agent-handlers.test.ts as an example:

graph TD
    A[agent-handlers.test.ts] --> B{handleAgent()};
    A --> C{checkAgentTriggers()};
    B -- Calls --> D(getCustomAgentLoader());
    C -- Calls --> D;
    D -- Mocked by --> E[jest.mock('../../src/agent/custom/custom-agent-loader.js')];
    E -- Provides Mocked Methods --> F(listAgents, getAgent, findByTrigger, etc.);
    B -- Returns --> G{CommandHandlerResult};
    C -- Returns --> G;
    A -- Asserts on --> G;
    A -- Asserts on --> F;

Key Test Files and Their Focus

The tests/commands module is organized to mirror the structure of the command handlers, with distinct test files for different command groups.

Slash Command Handlers

These tests validate commands typically invoked within an interactive chat environment (e.g., /command).

CLI Command Handlers

These tests validate commands typically invoked directly from the terminal (e.g., buddy command).

Development Pipelines

Key Interfaces and Utilities Tested

Beyond the command handlers themselves, these tests implicitly or explicitly validate the behavior of several core interfaces and utility functions: