Skip to content

Add backend unit tests for LangGraph agent #164

@dokterbob

Description

@dokterbob

Title: Add backend unit tests for LangGraph agent

Description:

The backend currently has no automated tests. We need comprehensive unit tests to verify the LangGraph agent behaves correctly.

Requirements:

  1. Test infrastructure setup

    • Add pytest with async support for testing async agent operations
    • Add respx for mocking HTTP requests to OpenAI-compatible APIs
    • Add a moon backend:test task to run tests
  2. Test scenarios to cover

    • Basic conversation: Agent receives a user message and returns an AI response
    • State maintenance: Conversation history is preserved across multiple invocations within the same thread
    • Tool invocation: Agent recognizes when to call the get_weather tool, executes it, and incorporates the result into its response
    • Tool output verification: The tool returns the expected format and content
  3. Test parametrization

    • Tests should run against multiple OpenAI-compatible base URLs (OpenAI default, OpenRouter, Ollama) to ensure provider flexibility
    • Tests should run with different model names to ensure model configuration works correctly
  4. Determinism requirements

    • The get_weather tool has random sleep for realism in production, but tests must be fast and deterministic
    • Mock the tool to return immediately with predictable output

Acceptance criteria:

  • moon backend:test passes
  • Tests cover all four scenarios above
  • Tests are parametrized across providers and models
  • No flaky tests due to randomness or timing

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions