Skip to content

test(translation): table-driven tests for Anthropic <-> OpenAI <-> Responses translation#334

Merged
Destynova2 merged 1 commit into
mainfrom
test/translation-layer
Apr 28, 2026
Merged

test(translation): table-driven tests for Anthropic <-> OpenAI <-> Responses translation#334
Destynova2 merged 1 commit into
mainfrom
test/translation-layer

Conversation

@Destynova2
Copy link
Copy Markdown
Contributor

Summary

  • Add 29 dedicated tests in tests/enterprise/translation_test.rs covering 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.
  • 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 tests/ integration suite can reach them without enabling extra cargo features.
  • Audit context: 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 release. Streaming is intentionally out of scope here (parallel PR).

Test matrix

Anthropic Messages -> OpenAI Chat Completions (request direction):

  • anthropic_to_openai_simple_user_message
  • anthropic_to_openai_with_system_prompt_hoisted_to_first_message
  • anthropic_to_openai_strips_duplicate_system_role_from_messages
  • anthropic_to_openai_with_assistant_message_after_user
  • anthropic_to_openai_tool_use_block_to_tool_calls
  • anthropic_to_openai_tool_result_block_to_tool_role_message
  • anthropic_to_openai_image_input_url
  • anthropic_to_openai_image_input_base64
  • anthropic_to_openai_thinking_block_dropped_when_target_is_chat_completions
  • anthropic_to_openai_cache_control_dropped_when_target_lacks_cache
  • anthropic_to_openai_with_max_tokens_and_stop_sequences
  • anthropic_to_openai_temperature_and_top_p_passthrough

OpenAI Chat Completions -> Anthropic (response direction):

  • openai_response_finish_reason_stop_to_anthropic_end_turn
  • openai_response_finish_reason_length_to_anthropic_max_tokens
  • openai_response_finish_reason_tool_calls_to_anthropic_tool_use_block
  • openai_response_usage_to_anthropic_usage_input_output
  • openai_response_with_no_content_to_anthropic_with_empty_text_block

Inbound OpenAI request -> Canonical (server compat layer):

  • openai_request_to_canonical_simple_user_message
  • openai_request_to_canonical_with_image_url_part
  • openai_request_to_canonical_tool_call_followed_by_tool_result

Canonical response -> OpenAI response:

  • canonical_response_to_openai_finish_reason_stop

Anthropic Messages -> Responses API (Codex CLI):

  • anthropic_to_responses_input_array_format
  • anthropic_to_responses_with_tools_array
  • anthropic_to_responses_streaming_event_types_match_spec (static type-tag pin only; streaming codepath untouched)

Edge cases:

  • transform_returns_error_on_unserializable_tool_input
  • transform_handles_empty_messages_array_gracefully
  • transform_handles_unicode_in_message_content
  • transform_handles_very_long_messages_no_panic (10MB string)
  • transform_preserves_request_id_in_response_metadata

Test plan

  • cargo check --tests passes
  • cargo fmt --all -- --check passes
  • cargo clippy --tests -- -D warnings passes
  • cargo nextest run --test lib enterprise::translation_test passes (29/29)
  • Full lib suite still green (246/246)
  • All pre-push hooks pass locally (gitleaks, fmt, clippy, deny, machete, doc-coverage, audit, sweep)

🤖 Generated with Claude Code

…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>
@Destynova2 Destynova2 enabled auto-merge (squash) April 28, 2026 21:30
@Destynova2 Destynova2 merged commit 12331e7 into main Apr 28, 2026
43 checks passed
@Destynova2 Destynova2 deleted the test/translation-layer branch April 28, 2026 21:49
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.

1 participant