Unverified Commit 3f8c8d70 authored by Wesley Liddick's avatar Wesley Liddick Committed by GitHub
Browse files

Merge pull request #274 from mt21625457/main

fix(openai): OAuth 请求强制 store=false
parents 55fced39 9c567fad
...@@ -90,17 +90,11 @@ func applyCodexOAuthTransform(reqBody map[string]any) codexTransformResult { ...@@ -90,17 +90,11 @@ func applyCodexOAuthTransform(reqBody map[string]any) codexTransformResult {
result.NormalizedModel = normalizedModel result.NormalizedModel = normalizedModel
} }
// 续链场景强制启用 store;非续链仍按原策略强制关闭存储。 // OAuth 走 ChatGPT internal API 时,store 必须为 false;显式 true 也会强制覆盖。
if needsToolContinuation { // 避免上游返回 "Store must be set to false"。
if v, ok := reqBody["store"].(bool); !ok || !v { if v, ok := reqBody["store"].(bool); !ok || v {
reqBody["store"] = true reqBody["store"] = false
result.Modified = true result.Modified = true
}
} else {
if v, ok := reqBody["store"].(bool); !ok || v {
reqBody["store"] = false
result.Modified = true
}
} }
if v, ok := reqBody["stream"].(bool); !ok || !v { if v, ok := reqBody["stream"].(bool); !ok || !v {
reqBody["stream"] = true reqBody["stream"] = true
......
...@@ -11,7 +11,7 @@ import ( ...@@ -11,7 +11,7 @@ import (
) )
func TestApplyCodexOAuthTransform_ToolContinuationPreservesInput(t *testing.T) { func TestApplyCodexOAuthTransform_ToolContinuationPreservesInput(t *testing.T) {
// 续链场景:保留 item_reference 与 id,并启用 store。 // 续链场景:保留 item_reference 与 id,但不再强制 store=true。
setupCodexCache(t) setupCodexCache(t)
reqBody := map[string]any{ reqBody := map[string]any{
...@@ -25,9 +25,10 @@ func TestApplyCodexOAuthTransform_ToolContinuationPreservesInput(t *testing.T) { ...@@ -25,9 +25,10 @@ func TestApplyCodexOAuthTransform_ToolContinuationPreservesInput(t *testing.T) {
applyCodexOAuthTransform(reqBody) applyCodexOAuthTransform(reqBody)
// 未显式设置 store=true,默认为 false。
store, ok := reqBody["store"].(bool) store, ok := reqBody["store"].(bool)
require.True(t, ok) require.True(t, ok)
require.True(t, store) require.False(t, store)
input, ok := reqBody["input"].([]any) input, ok := reqBody["input"].([]any)
require.True(t, ok) require.True(t, ok)
...@@ -45,8 +46,8 @@ func TestApplyCodexOAuthTransform_ToolContinuationPreservesInput(t *testing.T) { ...@@ -45,8 +46,8 @@ func TestApplyCodexOAuthTransform_ToolContinuationPreservesInput(t *testing.T) {
require.Equal(t, "o1", second["id"]) require.Equal(t, "o1", second["id"])
} }
func TestApplyCodexOAuthTransform_ToolContinuationForcesStoreTrue(t *testing.T) { func TestApplyCodexOAuthTransform_ExplicitStoreFalsePreserved(t *testing.T) {
// 续链场景:显式 store=false 也会被强制为 true。 // 续链场景:显式 store=false 不再强制为 true,保持 false
setupCodexCache(t) setupCodexCache(t)
reqBody := map[string]any{ reqBody := map[string]any{
...@@ -62,16 +63,35 @@ func TestApplyCodexOAuthTransform_ToolContinuationForcesStoreTrue(t *testing.T) ...@@ -62,16 +63,35 @@ func TestApplyCodexOAuthTransform_ToolContinuationForcesStoreTrue(t *testing.T)
store, ok := reqBody["store"].(bool) store, ok := reqBody["store"].(bool)
require.True(t, ok) require.True(t, ok)
require.True(t, store) require.False(t, store)
} }
func TestApplyCodexOAuthTransform_NonContinuationForcesStoreFalseAndStripsIDs(t *testing.T) { func TestApplyCodexOAuthTransform_ExplicitStoreTrueForcedFalse(t *testing.T) {
// 非续链场景:强制 store=false,并移除 input 中的 id // 显式 store=true 也会强制为 false
setupCodexCache(t) setupCodexCache(t)
reqBody := map[string]any{ reqBody := map[string]any{
"model": "gpt-5.1", "model": "gpt-5.1",
"store": true, "store": true,
"input": []any{
map[string]any{"type": "function_call_output", "call_id": "call_1"},
},
"tool_choice": "auto",
}
applyCodexOAuthTransform(reqBody)
store, ok := reqBody["store"].(bool)
require.True(t, ok)
require.False(t, store)
}
func TestApplyCodexOAuthTransform_NonContinuationDefaultsStoreFalseAndStripsIDs(t *testing.T) {
// 非续链场景:未设置 store 时默认 false,并移除 input 中的 id。
setupCodexCache(t)
reqBody := map[string]any{
"model": "gpt-5.1",
"input": []any{ "input": []any{
map[string]any{"type": "text", "id": "t1", "text": "hi"}, map[string]any{"type": "text", "id": "t1", "text": "hi"},
}, },
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment