Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions internal/runtime/executor/codex_openai_images.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func (e *CodexExecutor) executeOpenAIImage(ctx context.Context, auth *cliproxyau
if errCache != nil {
return resp, errCache
}
applyCodexHeaders(httpReq, auth, apiKey, true, e.cfg)
applyCodexDirectImageHeaders(httpReq, auth, apiKey, true, e.cfg)
applyCodexIdentityConfuseHeaders(httpReq.Header, &identityState)
recordCodexOpenAIImageRequest(ctx, e.cfg, e.Identifier(), auth, url, httpReq.Header.Clone(), body)

Expand Down Expand Up @@ -208,7 +208,7 @@ func (e *CodexExecutor) executeOpenAIImageStream(ctx context.Context, auth *clip
if errCache != nil {
return nil, errCache
}
applyCodexHeaders(httpReq, auth, apiKey, true, e.cfg)
applyCodexDirectImageHeaders(httpReq, auth, apiKey, true, e.cfg)
applyCodexIdentityConfuseHeaders(httpReq.Header, &identityState)
recordCodexOpenAIImageRequest(ctx, e.cfg, e.Identifier(), auth, url, httpReq.Header.Clone(), body)

Expand Down
32 changes: 32 additions & 0 deletions internal/runtime/executor/codex_openai_images_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,3 +315,35 @@ func TestCodexExecutorDirectOpenAIImageEditUsesImagesEditEndpointForMultipart(t
t.Fatalf("mask.image_url = %q, want mask-data data URL; body=%s", maskURL, string(gotBody))
}
}

func TestCodexExecutorWrappedOpenAIImageDoesNotForwardDownstreamUA(t *testing.T) {
var gotUA string
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
gotUA = r.Header.Get("User-Agent")
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte(`{"id":"resp_1","output":[{"type":"image_generation_call","result":"AA=="}],"usage":{"input_tokens":1,"output_tokens":1}}`))
}))
defer server.Close()

ctx := contextWithGinHeaders(map[string]string{
"User-Agent": "Python-urllib/3.9",
})
executor := NewCodexExecutor(&config.Config{})
// Use a model name that is NOT gpt-image-1.5 / gpt-image-2 so the request
// takes the wrapped (/responses) path instead of the direct (/images/*) path.
_, _ = executor.Execute(ctx, newCodexOpenAIImageTestAuth(server.URL), cliproxyexecutor.Request{
Model: "codex/dall-e-3",
Payload: []byte(`{"model":"codex/dall-e-3","prompt":"A cute otter","stream":false}`),
}, codexOpenAIImageTestOptions(codexImagesGenerationsPath, false))
Comment on lines +335 to +338

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The test currently ignores the error returned by executor.Execute using _, _ =. It is highly recommended to check and assert that err is nil to ensure the execution succeeds and to prevent silent failures or confusing test failures if the setup or request preparation fails.

	_, err := executor.Execute(ctx, newCodexOpenAIImageTestAuth(server.URL), cliproxyexecutor.Request{
		Model:   "codex/dall-e-3",
		Payload: []byte(`{"model":"codex/dall-e-3","prompt":"A cute otter","stream":false}`),
	}, codexOpenAIImageTestOptions(codexImagesGenerationsPath, false))
	if err != nil {
		t.Fatalf("Execute() error = %v", err)
	}


if gotUA == "" {
t.Fatal("upstream request was never made (User-Agent not captured)")
}
if gotUA == "Python-urllib/3.9" {
t.Fatalf("downstream User-Agent leaked to upstream: %q", gotUA)
}
if gotUA != codexUserAgent {
t.Fatalf("User-Agent = %q, want codex default %q", gotUA, codexUserAgent)
}
}
Loading