Copilot answers 400 "invalid request body" to every Gemini turn whose tools have a schema with a required entry naming no property (common in MCP tools), or two tools of one name. Probed live on a real Copilot account with gemini-3.8-flash: required-missing, nested required-missing, required without properties, and duplicate names were each 400; the same request with the entry or the second tool gone was 200. Claude Code, Codex and OpenCode bodies without those were 200. Now such required entries are dropped and the first of same-named tools kept, for Copilot's Gemini on chat only; a clean tools array goes byte for byte as it came. Run: new TestCopilotGeminiTakesToolsFit and the TestCopilotGemini* set (Linux, wsl-run); red with the call removed by hand (400 back). vet on darwin, linux, windows and the gateway and gui tests on mote. Not tried: Gemini tool names with a space, a leading digit or a slash are also 400 on Copilot (probed); a rename needs the reply mapped back, so it is left. items given as an array and boolean schemas are 400 too, left.
46 lines
1.8 KiB
Go
46 lines
1.8 KiB
Go
package gateway
|
|
|
|
import (
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"strings"
|
|
"sync"
|
|
"testing"
|
|
)
|
|
|
|
// Copilot's Gemini answers 400 "invalid request body" to a tool schema whose
|
|
// required names a property it lacks, and to two tools of one name
|
|
// (yuushabu_buyinn on X). The fake refuses exactly those; the turn must
|
|
// reach it fit, and a clean tool must go as it came.
|
|
func TestCopilotGeminiTakesToolsFit(t *testing.T) {
|
|
var mu sync.Mutex
|
|
var sent []string
|
|
copilotTurnFake(t, map[string]string{
|
|
"gemini-3.8-flash": `["/chat/completions"]`,
|
|
}, nil, func(m string, b []byte) bool {
|
|
s := string(b)
|
|
return strings.Contains(s, `"required":["ghost"`) || strings.Contains(s, `"required":["deep"]`) ||
|
|
strings.Count(s, `"name":"dup"`) > 1
|
|
}, "invalid request body", http.StatusBadRequest, &sent)
|
|
|
|
req := `{"model":"copilot/gemini-3.8-flash","stream":false,
|
|
"messages":[{"role":"user","content":"hi"}],
|
|
"tools":[
|
|
{"type":"function","function":{"name":"dup","parameters":{"type":"object","properties":{"a":{"type":"string"}},"required":["ghost","a"]}}},
|
|
{"type":"function","function":{"name":"dup","parameters":{"type":"object","properties":{}}}},
|
|
{"type":"function","function":{"name":"nest","parameters":{"type":"object","properties":{"o":{"type":"object","properties":{"x":{"type":"string"}},"required":["deep"]}},"required":["o"]}}}]}`
|
|
rec := httptest.NewRecorder()
|
|
New().Handler().ServeHTTP(rec, httptest.NewRequest("POST", "/v1/chat/completions", strings.NewReader(req)))
|
|
if rec.Code != 200 {
|
|
t.Fatalf("%d %s", rec.Code, rec.Body.String())
|
|
}
|
|
mu.Lock()
|
|
defer mu.Unlock()
|
|
if len(sent) != 1 {
|
|
t.Fatalf("Copilot was asked %d times", len(sent))
|
|
}
|
|
if !strings.Contains(sent[0], `"required":["a"]`) || !strings.Contains(sent[0], `"required":["o"]`) {
|
|
t.Errorf("the real required entries were lost: %s", sent[0])
|
|
}
|
|
}
|