Skip to content

Test: LLM adapter integration tests (Anthropic, OpenAI, Gemini, Copilot) #54

@JackChen-me

Description

@JackChen-me

Context

PR #53 brought overall src/ coverage from 37% to 71%. The remaining low-coverage modules are the LLM adapter chat() and stream() implementations:

Module Current Coverage
src/llm/anthropic.ts 6%
src/llm/openai.ts 9%
src/llm/gemini.ts 6%
src/llm/copilot.ts 0%

What needs to be done

Mock the underlying SDK HTTP clients to test the adapter chat() and stream() methods without making real API calls:

  1. Anthropic adapter — mock Anthropic.messages.create() and messages.stream(), verify toAnthropicMessages() / fromAnthropicContentBlock() round-trip
  2. OpenAI adapter — mock OpenAI.chat.completions.create() for both stream: false and stream: true paths
  3. Gemini adapter — mock GoogleGenerativeAI client
  4. Copilot adapter — mock OAuth device flow + chat completions

Approach

Use vi.mock() or vi.spyOn() to intercept SDK client methods. Each test should verify:

  • Correct wire-format conversion (framework types → SDK types → framework types)
  • Token usage extraction
  • Tool call handling (including streaming tool call assembly)
  • Error propagation (API errors, malformed responses)
  • Abort signal forwarding

Priority

P2 — the conversion helpers (openai-common.ts) are already at 100% coverage. The untested code is mostly SDK call wrappers. Most likely to break on SDK version bumps, not on framework changes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Community contributions welcome — good first issuesenhancementNew feature or requestsource:ownerSource: owner initiative

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions