E2E Mock Testing Architecture
To ensure the reliability of theinternal/proxy layer, ONR uses a robust E2E Mock testing system. This system validates the end-to-end transformation behavior, including req_map, routing, resp_map, and sse_parse, without actually hitting real upstream providers (saving costs and avoiding flaky tests).
Scope and Goals
- Test Entry Point:
open-next-router/internal/proxy/e2e_mock_test.go - Key Validations:
- Are requests correctly rewritten and routed to the target upstream paths?
- Are responses accurately transformed back into the OpenAI-compatible format?
- Are SSE termination events (
data: [DONE]) ordered correctly and unique?
How It Works
-
Downstream Request Simulation
- We use
gin.CreateTestContextandhttptest.NewRecorderto simulate a client requesting ONR. - The test directly enters the proxy chain via
Client.ProxyJSON(...)without spinning up a fullonrprocess.
- We use
-
Upstream Service Mocking
httptest.Serversimulates the upstream provider APIs.- It returns JSON or SSE text based on the test scenario.
- The handler asserts the upstream path, query parameters, and critical request fields to ensure the DSL rewrite worked.
-
DSL Configuration Isolation
- Tests construct minimal provider DSL strings inline (
providerConf*). - These are dynamically written to
t.TempDir()and loaded usingdslconfig.Registry.ReloadFromDir(). - Each test only loads the provider needed for that scenario, preventing pollution from global configurations.
- Tests construct minimal provider DSL strings inline (
Directory Structure & Conventions
Test data is organized underopen-next-router/internal/proxy/testdata/:
fixtures/: Contains downstream request bodies (Input samples).mock_upstream/: Contains upstream response bodies (Original JSON/SSE).- Naming Convention: Files are organized by
provider/scenario_namefor easy scaling.
Currently Supported Scenarios
- Anthropic
/v1/messages(Non-streaming)- Translates OpenAI chat request -> Anthropic messages request.
- Translates Anthropic JSON -> OpenAI chat completion JSON.
- Anthropic
/v1/messages(Streaming tool_use)- Translates Anthropic SSE
tool_useevents -> OpenAItool_callschunks. - Validates
finish_reason=tool_callsand a single[DONE].
- Translates Anthropic SSE
- Gemini (Streaming)
- Translates OpenAI chat request -> Gemini
:streamGenerateContent?alt=sse. - Validates Gemini SSE -> OpenAI chat chunks (including the usage chunk).
- Translates OpenAI chat request -> Gemini
- Azure Responses (Streaming)
- Translates OpenAI chat request ->
/openai/responses?api-version=2025-04-01-preview. - Validates
[DONE]does not arrive earlier than subsequent tokens.
- Translates OpenAI chat request ->
Running the Tests
To run the mock E2E tests, navigate to theopen-next-router directory and execute:
Golden Baselines
E2E test cases perform both critical field assertions and full Golden output comparisons. Golden files are located at:open-next-router/internal/proxy/testdata/golden/
To avoid false positives caused by timestamps or random IDs, the test standardizes dynamic fields (like created, chatcmpl_*) before comparing.
Updating Golden Files:
Only do this when you intentionally change the transformation behavior.