mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-06-14 12:25:18 +08:00
feat(executor): refine session and conversation header handling for Codex
- Updated session handling to replace `Session_id` and `Conversation_id` headers with new logic ensuring consistent use of `Cache.ID` and prompt keys. - Restored `Session_id` as a priority extraction source for `ExtractSessionID`. - Added tests to validate case-sensitive and case-insensitive headers, canonical account header usage, and session key preservation. - Removed legacy support for deprecated `Conversation_id` header to clean up API.
This commit is contained in:
@@ -47,8 +47,8 @@ func TestCodexExecutorCacheHelper_OpenAIChatCompletions_StablePromptCacheKeyFrom
|
||||
if gotConversation := httpReq.Header.Get("Conversation_id"); gotConversation != "" {
|
||||
t.Fatalf("Conversation_id = %q, want empty", gotConversation)
|
||||
}
|
||||
if gotSession := httpReq.Header.Get("Session_id"); gotSession != "" {
|
||||
t.Fatalf("Session_id = %q, want empty", gotSession)
|
||||
if gotSession := httpReq.Header.Get("Session_id"); gotSession != expectedKey {
|
||||
t.Fatalf("Session_id = %q, want %q", gotSession, expectedKey)
|
||||
}
|
||||
|
||||
httpReq2, _, _, err := executor.cacheHelper(ctx, sdktranslator.FromString("openai"), url, nil, req, req.Payload, rawJSON)
|
||||
@@ -119,8 +119,8 @@ func TestCodexExecutorCacheHelper_IdentityConfuseRemapsBodyAndHeaders(t *testing
|
||||
t.Fatalf("%s = %q, want %q", headerName, gotHeader, expectedPromptCacheKey)
|
||||
}
|
||||
}
|
||||
if gotSession := httpReq.Header.Get("Session_id"); gotSession != "" {
|
||||
t.Fatalf("Session_id = %q, want empty", gotSession)
|
||||
if gotSession := httpReq.Header.Get("Session_id"); gotSession != expectedPromptCacheKey {
|
||||
t.Fatalf("Session_id = %q, want %q", gotSession, expectedPromptCacheKey)
|
||||
}
|
||||
if gotWindow := httpReq.Header.Get("X-Codex-Window-Id"); gotWindow != expectedPromptCacheKey+":0" {
|
||||
t.Fatalf("X-Codex-Window-Id = %q, want %q", gotWindow, expectedPromptCacheKey+":0")
|
||||
@@ -137,6 +137,20 @@ func TestCodexExecutorCacheHelper_IdentityConfuseRemapsBodyAndHeaders(t *testing
|
||||
}
|
||||
}
|
||||
|
||||
func TestApplyCodexHeadersUsesAccountHeaderForOAuth(t *testing.T) {
|
||||
httpReq := httptest.NewRequest("POST", "https://example.com/responses", nil)
|
||||
auth := &cliproxyauth.Auth{
|
||||
Provider: "codex",
|
||||
Metadata: map[string]any{"account_id": "acct-1"},
|
||||
}
|
||||
|
||||
applyCodexHeaders(httpReq, auth, "oauth-token", true, nil)
|
||||
|
||||
if got := httpReq.Header.Get("Chatgpt-Account-Id"); got != "acct-1" {
|
||||
t.Fatalf("Chatgpt-Account-Id = %q, want acct-1", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCodexIdentityConfuseKeepsClientBodySeparateFromUpstreamBody(t *testing.T) {
|
||||
cfg := &config.Config{
|
||||
Routing: config.RoutingConfig{Strategy: "fill-first"},
|
||||
|
||||
Reference in New Issue
Block a user