tests — acp

Module: tests-acp Cohesion: 0.80 Members: 0

tests — acp

This document describes the tests/acp/protocol.test.ts module, which serves as the comprehensive test suite for the core Agent Communication Protocol (ACP) components, primarily the ACPRouter class, defined in src/acp/protocol.js.

Its purpose is to ensure the robustness, correctness, and expected behavior of the ACPRouter and its interactions with ACPAgents and ACPMessages. Developers contributing to the ACP core should refer to these tests to understand the intended functionality and API contracts.

ACP Core Components Under Test

The tests/acp/protocol.test.ts module validates the following key components from src/acp/protocol.js:

ACPRouter Functionality & API (as demonstrated by tests)

The tests cover the full lifecycle and core operations of the ACPRouter.

1. Agent Lifecycle Management

The ACPRouter acts as a registry for ACPAgents.

2. Message Routing & Action Handling

The ACPRouter is responsible for directing ACPMessages to their intended recipients or handlers.

3. Request/Response Pattern

The ACPRouter facilitates a request-response mechanism using correlationIds.

4. Message Logging

The ACPRouter maintains a log of all messages processed.

5. Resource Management

ACPRouter Architecture Overview

The ACPRouter acts as a central message broker and agent registry.

graph TD
    subgraph ACPRouter
        direction LR
        A[register/unregister] --> B(Agent Registry)
        C[send] --> D(Action Handlers)
        C --> E(Message Log)
        F[request] --> G(Pending Requests)
        G --> C
        D -- handles --> C
    end

    Agent1[ACPAgent 1] -- registers with --> ACPRouter
    Agent2[ACPAgent 2] -- registers with --> ACPRouter
    Agent1 -- sends ACPMessage --> ACPRouter
    ACPRouter -- routes ACPMessage --> Agent2
    ACPRouter -- emits events --> External Listeners

Contributing and Extending

When modifying the ACPRouter class or related ACP primitives in src/acp/protocol.js, it is crucial to:

  1. Consult existing tests: Understand the current expected behavior for each method and interaction.
  2. Add new tests: For any new functionality or edge cases, write corresponding tests in tests/acp/protocol.test.ts.
  3. Ensure all tests pass: Before submitting changes, run the test suite to confirm no regressions have been introduced.

The tests use jest.fn() extensively to mock handlers and spies, allowing for precise verification of function calls and arguments. Asynchronous operations are tested using async/await and setTimeout to simulate real-world delays and ensure correct handling of promises and timeouts.