Skip to content

feat: add agent loop integration tests with mocked Claude API #55

@nickmeinhold

Description

@nickmeinhold

Problem or Motivation

Current tests cover utilities (sprint, timezone, mentions) and DB queries, but nothing tests the core agent loop pipeline: message in → Claude API call → tool execution → response out. This is where breakage is most likely and most painful.

Proposed Solution

Add integration tests for the agent loop that mock the Anthropic SDK and MCP tool layer:

  1. Mock @anthropic-ai/sdk — return canned Claude responses (text-only, with tool calls, multi-round)
  2. Mock tool-registry — return canned tool results without real MCP servers
  3. Mock grammy Api — capture typing indicators and verify they're sent

Test Scenarios

  • Simple text response (no tools)
  • Single tool call round (Claude calls a tool, gets result, responds)
  • Multi-round tool calls (2-3 rounds of tool usage)
  • Tool execution error handling (tool throws, agent recovers)
  • Auth failure handling (401 from Claude API)
  • Max tool rounds exceeded (10 rounds hit)
  • System-initiated messages (no tools available)
  • Image attachment handling

Acceptance Criteria

  • Integration test file at src/agent/agent-loop.integration.test.ts
  • All 8 scenarios above covered
  • Tests run in CI without any API keys or external services
  • Tests complete in <5 seconds

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions