mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-06-23 19:04:08 +08:00
- Updated `ConvertGeminiRequestToClaude`, `ConvertGeminiRequestToCodex`, and their respective response counterparts to include logic for retaining and using tool/call IDs when present from gateway-provided inputs. - Enhanced pairing logic between function calls and responses to handle custom and auto-generated IDs consistently. - Introduced tests validating ID preservation and proper behavior in both streaming and non-streaming flows. Closes: #3878
64 lines
1.5 KiB
Go
64 lines
1.5 KiB
Go
package gemini
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/tidwall/gjson"
|
|
)
|
|
|
|
func TestConvertGeminiRequestToCodex_PreservesCustomCallIDs(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
callField string
|
|
responseField string
|
|
want string
|
|
}{
|
|
{
|
|
name: "id",
|
|
callField: `"id":"call_gateway_id"`,
|
|
responseField: `"id":"call_gateway_id"`,
|
|
want: "call_gateway_id",
|
|
},
|
|
{
|
|
name: "call_id",
|
|
callField: `"call_id":"call_gateway_call_id"`,
|
|
responseField: `"call_id":"call_gateway_call_id"`,
|
|
want: "call_gateway_call_id",
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
raw := []byte(fmt.Sprintf(`{
|
|
"contents": [
|
|
{
|
|
"role": "model",
|
|
"parts": [
|
|
{"functionCall": {"name": "lookup", %s, "args": {"query": "status"}}}
|
|
]
|
|
},
|
|
{
|
|
"role": "user",
|
|
"parts": [
|
|
{"functionResponse": {"name": "lookup", %s, "response": {"result": "ok"}}}
|
|
]
|
|
}
|
|
]
|
|
}`, tt.callField, tt.responseField))
|
|
|
|
out := ConvertGeminiRequestToCodex("gpt-5.1-codex", raw, false)
|
|
|
|
gotCallID := gjson.GetBytes(out, "input.0.call_id").String()
|
|
if gotCallID != tt.want {
|
|
t.Fatalf("expected function_call call_id %q, got %q; output=%s", tt.want, gotCallID, string(out))
|
|
}
|
|
|
|
gotOutputID := gjson.GetBytes(out, "input.1.call_id").String()
|
|
if gotOutputID != tt.want {
|
|
t.Fatalf("expected function_call_output call_id %q, got %q; output=%s", tt.want, gotOutputID, string(out))
|
|
}
|
|
})
|
|
}
|
|
}
|