test(translation): table-driven tests for Anthropic <-> OpenAI <-> Responses translation#334
Merged
Merged
Conversation
…sponses translation Pin the wire format of the three translation paths exercised at every PR: * canonical (Anthropic-shape) -> OpenAI Chat Completions request * OpenAI Chat Completions response -> canonical * canonical -> Responses API (Codex CLI) The audit logged 18 touches in src/server/openai_compat, src/server/responses_compat and src/providers/openai/transform.rs over 3 months with no dedicated tests; this file is the regression ratchet that catches structural drift before it reaches a release. Streaming is intentionally out of scope here (separate PR). * 29 tests in tests/enterprise/translation_test.rs covering the matrix from the audit (12 anthropic-to-openai request, 5 response, 3 inbound to canonical, 1 canonical-to-openai-response, 3 anthropic-to-responses, 5 edge cases including 10MB / unicode / null content / nested input) * Expose a `pub mod test_api` shim in src/providers/openai/mod.rs that re-emits the otherwise pub(crate) `transform_request`, `transform_response`, and `transform_to_responses_request` as JSON-returning helpers, so the integration suite under tests/ can reach them without enabling extra cargo features. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
tests/enterprise/translation_test.rscovering the Anthropic Messages <-> OpenAI Chat Completions <-> Responses API (Codex CLI) translation paths. Pins the wire format of the three transformers that account for the bulk of inbound and outbound format work.pub mod test_apishim insrc/providers/openai/mod.rsthat re-emits the otherwisepub(crate)transform_request,transform_response, andtransform_to_responses_requestas JSON-returning helpers, so thetests/integration suite can reach them without enabling extra cargo features.src/server/openai_compat/,src/server/responses_compat/, andsrc/providers/openai/transform.rsover 3 months with no dedicated tests. This file is the regression ratchet that catches structural drift before release. Streaming is intentionally out of scope here (parallel PR).Test matrix
Anthropic Messages -> OpenAI Chat Completions (request direction):
anthropic_to_openai_simple_user_messageanthropic_to_openai_with_system_prompt_hoisted_to_first_messageanthropic_to_openai_strips_duplicate_system_role_from_messagesanthropic_to_openai_with_assistant_message_after_useranthropic_to_openai_tool_use_block_to_tool_callsanthropic_to_openai_tool_result_block_to_tool_role_messageanthropic_to_openai_image_input_urlanthropic_to_openai_image_input_base64anthropic_to_openai_thinking_block_dropped_when_target_is_chat_completionsanthropic_to_openai_cache_control_dropped_when_target_lacks_cacheanthropic_to_openai_with_max_tokens_and_stop_sequencesanthropic_to_openai_temperature_and_top_p_passthroughOpenAI Chat Completions -> Anthropic (response direction):
openai_response_finish_reason_stop_to_anthropic_end_turnopenai_response_finish_reason_length_to_anthropic_max_tokensopenai_response_finish_reason_tool_calls_to_anthropic_tool_use_blockopenai_response_usage_to_anthropic_usage_input_outputopenai_response_with_no_content_to_anthropic_with_empty_text_blockInbound OpenAI request -> Canonical (server compat layer):
openai_request_to_canonical_simple_user_messageopenai_request_to_canonical_with_image_url_partopenai_request_to_canonical_tool_call_followed_by_tool_resultCanonical response -> OpenAI response:
canonical_response_to_openai_finish_reason_stopAnthropic Messages -> Responses API (Codex CLI):
anthropic_to_responses_input_array_formatanthropic_to_responses_with_tools_arrayanthropic_to_responses_streaming_event_types_match_spec(static type-tag pin only; streaming codepath untouched)Edge cases:
transform_returns_error_on_unserializable_tool_inputtransform_handles_empty_messages_array_gracefullytransform_handles_unicode_in_message_contenttransform_handles_very_long_messages_no_panic(10MB string)transform_preserves_request_id_in_response_metadataTest plan
cargo check --testspassescargo fmt --all -- --checkpassescargo clippy --tests -- -D warningspassescargo nextest run --test lib enterprise::translation_testpasses (29/29)🤖 Generated with Claude Code