tests — tools

Module: tests-tools Cohesion: 0.80 Members: 0

tests — tools

This document provides an overview of the tests/tools module, which contains the unit and integration tests for the various tools available in the src/tools directory. Its primary purpose is to ensure the correctness, reliability, and security of these tools, which are critical components for the agent's interaction with the environment.

While this documentation focuses on the tests, it implicitly describes the expected behavior and functionality of the tools themselves.

Module Purpose

The tests/tools module is dedicated to validating the functionality and robustness of the agent's toolset. Each test file corresponds to a specific tool or a set of related tool utilities, ensuring that:

  1. Core functionality works as expected: Tools perform their intended operations correctly.
  2. Edge cases are handled gracefully: Unexpected inputs or environmental conditions do not cause crashes or incorrect behavior.
  3. Security measures are effective: Dangerous commands or operations are blocked, especially for tools interacting with the operating system or sensitive data.
  4. Integration with core services is sound: Tools correctly interact with components like the Virtual File System (VFS), Confirmation Service, and Sandbox Manager.
  5. Performance and resource management: Streaming, timeouts, and session management are tested for efficiency and stability.

General Testing Principles

The tests in this module employ several common strategies to achieve comprehensive coverage:

Overview of Tool Tests

The following sections detail the specific aspects covered by the tests for each tool.

AudioTool Tests (audio-tool.test.ts)

These tests validate the AudioTool's ability to interact with audio files via the Virtual File System (VFS).

BashTool Tests (bash-tool.test.ts, bash-streaming.test.ts, bash.test.ts)

The BashTool is one of the most critical and security-sensitive tools, reflected in its extensive test suite across multiple files.

ComputerControlTool Browser Ref Handling Tests (computer-control-browser-refs.test.ts)

These tests focus on a specific security and usability aspect of the ComputerControlTool: preventing it from interacting with browser elements that lack valid screen coordinates.

DiagramTool Tests (diagram-tool.test.ts)

These tests validate the DiagramTool's ability to generate various diagrams using Mermaid syntax.

FirecrawlTool Tests (firecrawl-tool.test.ts)

These tests validate the integration with the Firecrawl API for web scraping and searching.

GitTool Tests (git-tool.test.ts)

The GitTool tests are robust integration tests that operate on a real temporary Git repository, providing high confidence in its functionality.

Lessons Tools Tests (lessons-tools.test.ts)

These tests validate the tools for managing a knowledge base of "lessons" or insights. They use a real file system in a temporary directory, mocking os.homedir to ensure isolation.

Tool Hooks & Session Management Tests (result-sanitizer.test.ts, session-lanes.test.ts, tool-hooks.test.ts)

These tests cover the infrastructure for managing tool call lifecycles, output sanitization, and concurrent execution.

ResultSanitizer Tests

SessionLanesManager Tests

ToolHooksManager Tests

Architecture Diagram

The tests/tools module primarily interacts with the src/tools modules, often relying on mocked or controlled versions of core dependencies to isolate and validate tool behavior.

graph TD
    subgraph "Test Modules (tests/tools)"
        A[audio-tool.test.ts]
        B[bash-tool.test.ts]
        C[computer-control.test.ts]
        D[diagram-tool.test.ts]
        E[firecrawl.test.ts]
        F[git-tool.test.ts]
        G[lessons-tools.test.ts]
        H[tool-hooks.test.ts]
        I[result-sanitizer.test.ts]
        J[session-lanes.test.ts]
    end

    subgraph "Production Modules (src/tools)"
        TA[AudioTool]
        TB[BashTool]
        TC[ComputerControlTool]
        TD[DiagramTool]
        TE[Firecrawl functions]
        TF[GitTool]
        TG[Lessons Tools]
        TH[ToolHooksManager]
        TI[ResultSanitizer]
        TJ[SessionLanesManager]
    end

    subgraph "Key Dependencies (Mocked/Controlled)"
        M1[Virtual File System (VFS)]
        M2[Child Process Execution]
        M3[Security Sandbox]
        M4[Confirmation Service]
        M5[Temporary File System]
        M6[External APIs (e.g., Firecrawl)]
        M7[Desktop Automation]
    end

    A --> TA
    B --> TB
    C --> TC
    D --> TD
    E --> TE
    F --> TF
    G --> TG
    H --> TH
    I --> TI
    J --> TJ

    A,D -- uses --> M1
    B,D -- uses --> M2
    B -- uses --> M3, M4
    C -- uses --> M7
    E -- uses --> M6
    F,G -- uses --> M5

Contributing to Tool Tests

When contributing to the src/tools directory, developers should: