From 905571b05d0fd3ead293df38661b8d041bb2aba5 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 12 Jan 2026 15:08:05 +0000 Subject: [PATCH 1/3] Initial plan From 34aca2da6212f9f31a5961a10a23e2114c4254b7 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 12 Jan 2026 15:14:00 +0000 Subject: [PATCH 2/3] fix: align codex health check with responses api Co-authored-by: lwaay2025 <218015601+lwaay2025@users.noreply.github.com> --- services/healthcheckservice.go | 12 +++-- services/healthcheckservice_test.go | 84 +++++++++++++++++++++-------- 2 files changed, 71 insertions(+), 25 deletions(-) diff --git a/services/healthcheckservice.go b/services/healthcheckservice.go index b323274..03789d6 100644 --- a/services/healthcheckservice.go +++ b/services/healthcheckservice.go @@ -746,13 +746,19 @@ func (hcs *HealthCheckService) buildTestRequest(platform, model string) []byte { return data } - // Codex 格式:不支持 max_tokens + // Codex Responses 协议 if platform == "codex" { reqBody := map[string]interface{}{ "model": model, - "messages": []map[string]string{ - {"role": "user", "content": "hi"}, + "input": []map[string]interface{}{ + { + "role": "user", + "content": []map[string]interface{}{ + {"type": "text", "text": "hi"}, + }, + }, }, + "max_output_tokens": 1, } data, _ := json.Marshal(reqBody) return data diff --git a/services/healthcheckservice_test.go b/services/healthcheckservice_test.go index 9a6edf8..2843a99 100644 --- a/services/healthcheckservice_test.go +++ b/services/healthcheckservice_test.go @@ -186,7 +186,9 @@ func TestBuildTestRequest(t *testing.T) { model string expectNonNil bool validateModel bool - expectMax bool + tokensField string + expectInput bool + expectMessage bool }{ { name: "Codex 平台请求", @@ -194,7 +196,9 @@ func TestBuildTestRequest(t *testing.T) { model: "gpt-4o-mini", expectNonNil: true, validateModel: true, - expectMax: false, + tokensField: "max_output_tokens", + expectInput: true, + expectMessage: false, }, { name: "Claude 平台请求", @@ -202,7 +206,9 @@ func TestBuildTestRequest(t *testing.T) { model: "claude-3-5-haiku-20241022", expectNonNil: true, validateModel: true, - expectMax: true, + tokensField: "max_tokens", + expectInput: false, + expectMessage: true, }, { name: "映射后的模型名", @@ -210,7 +216,9 @@ func TestBuildTestRequest(t *testing.T) { model: "openai/gpt-4o-mini", expectNonNil: true, validateModel: true, - expectMax: false, + tokensField: "max_output_tokens", + expectInput: true, + expectMessage: false, }, } @@ -245,12 +253,26 @@ func TestBuildTestRequest(t *testing.T) { t.Errorf("Expected model %s in request body, got %s", tt.model, model) } - _, hasMaxTokens := reqData["max_tokens"] - if tt.expectMax && !hasMaxTokens { - t.Error("Expected max_tokens in request body but not found") + if tt.tokensField != "" { + if _, ok := reqData[tt.tokensField]; !ok { + t.Errorf("Expected %s in request body but not found", tt.tokensField) + } } - if !tt.expectMax && hasMaxTokens { - t.Error("max_tokens should not be included for this platform") + + _, hasMessages := reqData["messages"] + if tt.expectMessage && !hasMessages { + t.Error("Expected messages in request body but not found") + } + if !tt.expectMessage && hasMessages { + t.Error("messages should not be included for this platform") + } + + _, hasInput := reqData["input"] + if tt.expectInput && !hasInput { + t.Error("Expected input in request body but not found") + } + if !tt.expectInput && hasInput { + t.Error("input should not be included for this platform") } } }) @@ -318,23 +340,41 @@ func TestHealthCheck_RequestBodyStructure(t *testing.T) { t.Fatalf("Failed to parse request body: %v", err) } - // 验证必需字段 - requiredFields := []string{"model", "max_tokens", "messages"} - for _, field := range requiredFields { - if _, ok := reqData[field]; !ok { - t.Errorf("Required field %s is missing", field) + if platform == "claude" { + requiredFields := []string{"model", "max_tokens", "messages"} + for _, field := range requiredFields { + if _, ok := reqData[field]; !ok { + t.Errorf("Required field %s is missing", field) + } } - } - // 验证 messages 结构 - messages, ok := reqData["messages"].([]interface{}) - if !ok { - t.Error("messages field is not an array") - return + messages, ok := reqData["messages"].([]interface{}) + if !ok { + t.Error("messages field is not an array") + return + } + if len(messages) == 0 { + t.Error("messages array is empty") + } } - if len(messages) == 0 { - t.Error("messages array is empty") + if platform == "codex" { + requiredFields := []string{"model", "input", "max_output_tokens"} + for _, field := range requiredFields { + if _, ok := reqData[field]; !ok { + t.Errorf("Required field %s is missing", field) + } + } + + inputs, ok := reqData["input"].([]interface{}) + if !ok { + t.Error("input field is not an array") + return + } + if len(inputs) == 0 { + t.Error("input array is empty") + return + } } }) } From 808e26b27704611fede6238940703e1b56703ac0 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 12 Jan 2026 15:15:26 +0000 Subject: [PATCH 3/3] chore: simplify codex responses healthcheck body Co-authored-by: lwaay2025 <218015601+lwaay2025@users.noreply.github.com> --- services/healthcheckservice.go | 11 ++--------- services/healthcheckservice_test.go | 20 ++++++++++++-------- 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/services/healthcheckservice.go b/services/healthcheckservice.go index 03789d6..e3df604 100644 --- a/services/healthcheckservice.go +++ b/services/healthcheckservice.go @@ -749,15 +749,8 @@ func (hcs *HealthCheckService) buildTestRequest(platform, model string) []byte { // Codex Responses 协议 if platform == "codex" { reqBody := map[string]interface{}{ - "model": model, - "input": []map[string]interface{}{ - { - "role": "user", - "content": []map[string]interface{}{ - {"type": "text", "text": "hi"}, - }, - }, - }, + "model": model, + "input": "hi", "max_output_tokens": 1, } data, _ := json.Marshal(reqBody) diff --git a/services/healthcheckservice_test.go b/services/healthcheckservice_test.go index 2843a99..0041181 100644 --- a/services/healthcheckservice_test.go +++ b/services/healthcheckservice_test.go @@ -366,14 +366,18 @@ func TestHealthCheck_RequestBodyStructure(t *testing.T) { } } - inputs, ok := reqData["input"].([]interface{}) - if !ok { - t.Error("input field is not an array") - return - } - if len(inputs) == 0 { - t.Error("input array is empty") - return + switch v := reqData["input"].(type) { + case string: + if strings.TrimSpace(v) == "" { + t.Error("input string should not be empty") + } + case []interface{}: + if len(v) == 0 { + t.Error("input array is empty") + return + } + default: + t.Errorf("unexpected input type %T", v) } } })