Skip to content

Conversation

EItanya
Copy link
Contributor

@EItanya EItanya commented Sep 16, 2025

No description provided.

Signed-off-by: Eitan Yarmush <eitan.yarmush@solo.io>
Signed-off-by: Eitan Yarmush <eitan.yarmush@solo.io>
@EItanya EItanya changed the title Eitanya/mock llm tests Feat: Mock LLM servers for test Sep 16, 2025
Signed-off-by: Eitan Yarmush <eitan.yarmush@solo.io>
@EItanya EItanya marked this pull request as ready for review September 17, 2025 14:36
@Copilot Copilot AI review requested due to automatic review settings September 17, 2025 14:36
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces a comprehensive mock LLM server framework for testing AI agent interactions in end-to-end tests. The mock server simulates OpenAI and Anthropic LLM APIs, enabling deterministic testing without external API dependencies.

  • Implements a configurable mock server supporting both OpenAI and Anthropic APIs with streaming capabilities
  • Provides type-safe configuration using official SDK types for request/response mocking
  • Updates existing E2E tests to use the mock server instead of real external LLM services

Reviewed Changes

Copilot reviewed 16 out of 17 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
go/test/mockllm/types.go Defines core types and configuration structures for mock LLM server
go/test/mockllm/server.go Implements HTTP server with health checks and routing for mock endpoints
go/test/mockllm/openai.go OpenAI provider implementation with request matching and response handling
go/test/mockllm/anthropic.go Anthropic provider implementation with header validation and streaming support
go/test/mockllm/server_test.go Comprehensive test suite for both OpenAI and Anthropic mock functionality
go/test/e2e/invoke_api_test.go Updated E2E tests to use mock server with dynamic configuration
go/test/mockllm/DESIGN.md Technical design documentation for the mock server architecture
go/go.mod Added dependencies for OpenAI and Anthropic SDK integration

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Signed-off-by: Eitan Yarmush <eitan.yarmush@solo.io>
Signed-off-by: Eitan Yarmush <eitan.yarmush@solo.io>
Signed-off-by: Eitan Yarmush <eitan.yarmush@solo.io>
splitted := strings.Split(baseURL, ":")
port := splitted[len(splitted)-1]

localHost := "172.17.0.1"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you want to do if linux/mac here? i think this only works on linux

Copy link
Contributor

@inFocus7 inFocus7 Sep 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^ +1. we probably should
i tried 127.0.0.1 on mac and hit an issue where i got a timeout in the test. host.docker.internal work, since this url used so the agent within the cluster communicates with the locally-running mock llm.

},
{
"name": "k8s_get_resources_response",
"match": {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this a type of assertion? or scenario matching logic? maybe explain in readme?

### Configuration
Two ways to configure scenarios:
1) In-code builder (for brevity in tests):
- Fluent API: `NewScenario("name").Expect(OpenAI()).WithModel("gpt-4o").WithMessages(...).Then().RespondWithText("hello").AsStream(...).Build()`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

??

Signed-off-by: Eitan Yarmush <eitan.yarmush@solo.io>
Signed-off-by: Eitan Yarmush <eitan.yarmush@solo.io>
Comment on lines +124 to +134
modelCfg := generateModelCfg(baseURL + "/v1")
err = cli.Create(t.Context(), modelCfg)
require.NoError(t, err)
agent := generateAgent()
err = cli.Create(t.Context(), agent)
require.NoError(t, err)

defer func() {
cli.Delete(t.Context(), modelCfg) //nolint:errcheck
cli.Delete(t.Context(), agent) //nolint:errcheck
}()
Copy link
Contributor

@inFocus7 inFocus7 Sep 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: having the defer down here would mean if the agent failed to be created, we'll fail and end the test before deleting the model config.

super nit: I believe go tests are safer using t.Cleanup() for post-test cleanups, at least true for parallel testing. We're not doing parallel tests here so nbd, but may be worth using it to err on the safer side of things.

Signed-off-by: Eitan Yarmush <eitan.yarmush@solo.io>
Signed-off-by: Eitan Yarmush <eitan.yarmush@solo.io>
@EItanya EItanya merged commit 2056a7b into main Sep 23, 2025
16 checks passed
@EItanya EItanya deleted the eitanya/mock-llm-tests branch September 23, 2025 17:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants