Files
magpie/internal/gateway/search_models_test.go
T
yetone 76f802d37d gateway: Command Code's Provider API searches by itself for the 12 models that do, and the rest keep magpie's searcher (#1590, M3chD09)
Command Code's Provider API passes a provider-defined web_search on to the
model's vendor, and only some models search: M3chD09 ran all 87 and 12
did (claude-sonnet-5-5 and claude-haiku-5-5 on Messages; gpt-6-luna,
gpt-5.6-sol, gpt-5.6-luna, meta/muse-spark-1.2/1.3 and their -contributor
ids, xai/grok-4.5/4.6/4.7 on Responses). magpie took the whole provider
as one that doesn't search, so each of those searches went to the
searcher instead. Marking the provider as searching (Searches, or its
host in searchHosts) would have sent the tool to the other 75, which take
it and don't search.

searchModels now lists, per provider and API, the models that search by
themselves; modelSearches reads it for a keyed provider made from the
"commandcode" preset or at api.commandcode.ai, and none count when the
provider is sent Command Code's x-cmd-zdr header, under which it refuses
every built-in tool (cmd_zdr_unsupported_tool, from the report). It is
read in searchesModel, so the relay/translate choice and the tool swap
both follow it, and in webSearchOf, so a remote magpie's list says
"native" for those models too. Sign-ins (the Command Code Plan, its
plugin) are not changed.

Verified:
- TestCommandCodeSearchesForSomeModels: gpt-6-luna and xai/grok-4.7 on
  Responses and claude-sonnet-5-5 on Messages are sent the agent's own
  web search tool; deepseek-v4-pro and claude-opus-5-5 aren't; with
  x-cmd-zdr: 1 none is. Without the searchesModel change it fails for the
  three searching models.
- go test -run Search ./internal/gateway, gofmt -l.
- Not tried against the real Command Code API (no key for it here); the
  list is the reporter's run of 2026-10-11.
2026-10-11 21:00:29 +08:00

67 lines
2.8 KiB
Go

package gateway
import (
"strings"
"testing"
"github.com/yetone/magpie/internal/provider"
)
// Command Code's Provider API searches the web by itself for some of its
// models only (#1590, M3chD09: 12 of 87, its GPT, Grok and Muse models on
// Responses, its Claude ones on Messages). Those are sent the agent's own
// web search tool; the rest keep magpie's searcher, and so does every
// model when the provider is sent Command Code's zero-data-retention
// header, under which it refuses every built-in tool.
func TestCommandCodeSearchesForSomeModels(t *testing.T) {
srv, seen := relayOfEvery(t)
fresh(t)
save := func(h map[string]string) {
t.Helper()
if err := provider.Save(provider.Provider{ID: "commandcode", Name: "Command Code", Key: "k", Preset: "commandcode",
Chat: srv.URL + "/v1", Responses: srv.URL + "/v1", Anthropic: srv.URL, Headers: h,
Models: []string{"gpt-6-luna", "xai/grok-4.7", "deepseek/deepseek-v4-pro", "claude-sonnet-5-5", "claude-opus-5-5"}}); err != nil {
t.Fatal(err)
}
}
codex := func(model string) string {
return `{"model":"commandcode/` + model + `","stream":true,"store":false,"input":[{"type":"message","role":"user","content":[{"type":"input_text","text":"news?"}]}],
"tools":[{"type":"function","name":"shell","description":"run","parameters":{"type":"object","properties":{}}},{"type":"web_search","external_web_access":true}]}`
}
claude := func(model string) string {
return `{"model":"commandcode/` + model + `","max_tokens":100,"stream":true,"messages":[{"role":"user","content":"news?"}],
"tools":[{"name":"Read","description":"read","input_schema":{"type":"object"}},{"type":"web_search_20250305","name":"web_search","max_uses":8}]}`
}
cases := []struct {
name, path, body, want string
native bool
}{
{"gpt-6-luna", "/v1/responses", codex("gpt-6-luna"), "/v1/responses", true},
{"xai/grok-4.7", "/v1/responses", codex("xai/grok-4.7"), "/v1/responses", true},
{"deepseek-v4-pro", "/v1/responses", codex("deepseek/deepseek-v4-pro"), "/v1/responses", false},
{"claude-sonnet-5-5", "/v1/messages", claude("claude-sonnet-5-5"), "/v1/messages", true},
{"claude-opus-5-5", "/v1/messages", claude("claude-opus-5-5"), "/v1/messages", false},
}
run := func(zdr bool) {
for _, r := range cases {
seen()
if code, b := post(t, r.path, r.body); code != 200 {
t.Fatalf("%s: %d %s", r.name, code, b)
}
paths, bodies := seen()
if len(paths) != 1 || paths[0] != r.want {
t.Errorf("%s (zdr %v) went to %v, want %s", r.name, zdr, paths, r.want)
continue
}
got := strings.Contains(bodies[0], `"type":"web_search`)
if want := r.native && !zdr; got != want {
t.Errorf("%s (zdr %v): the vendor's own search tool sent = %v, want %v: %s", r.name, zdr, got, want, bodies[0])
}
}
}
save(nil)
run(false)
save(map[string]string{"x-cmd-zdr": "1"})
run(true)
}