feat: improve OpenAI messages compatibility for Claude Code

This commit is contained in:
lyen1688
2026-05-05 19:32:41 +08:00
parent 94e494319a
commit 0584305e5a
21 changed files with 2525 additions and 136 deletions

View File

@@ -44,6 +44,39 @@ func TestApplyCodexOAuthTransform_ToolContinuationPreservesInput(t *testing.T) {
require.Equal(t, "fc1", second["call_id"])
}
func TestApplyCodexOAuthTransform_MessagesBridgePromptCacheKeyIsHeaderOnly(t *testing.T) {
reqBody := map[string]any{
"model": "gpt-5.5",
"prompt_cache_key": "anthropic-metadata-session-1",
"input": []any{
map[string]any{
"type": "message",
"role": "developer",
"content": []any{
map[string]any{
"type": "input_text",
"text": openAICompatClaudeCodeTodoGuardMarker,
},
},
},
map[string]any{
"type": "message",
"role": "user",
"content": "hello",
},
},
}
result := applyCodexOAuthTransformWithOptions(reqBody, codexOAuthTransformOptions{
SkipDefaultInstructions: true,
PreserveToolCallIDs: true,
})
require.Equal(t, "anthropic-metadata-session-1", result.PromptCacheKey)
require.True(t, result.Modified)
require.NotContains(t, reqBody, "prompt_cache_key")
}
func TestApplyCodexOAuthTransform_ToolContinuationPreservesNativeMessageAndReasoningIDs(t *testing.T) {
reqBody := map[string]any{
"model": "gpt-5.2",