dsh's web search is a plugin of its own, web-search-deepseek, which signs each search to DeepSeek's Anthropic API with DEEPSEEK_API_KEY, so a dsh that reaches its models through magpie alone failed every search asking for that key. While dsh starts on a model of magpie's, magpie writes a marked web-search-deepseek entry in each profile: the gateway's /v1 as baseURL, MAGPIE_GATEWAY_KEY as apiKeyEnv and that model. The gateway answers the plugin's web_search_20250305 request as Anthropic does, by the model's own search or magpie's (web_search_tool_result blocks). A row of the user's, or a DEEPSEEK_API_KEY dsh has in .env or its key store, is left as it is. The entry goes with dsh's own model or Disconnect, and moves with the gateway's address. The row's Notice says when magpie has nothing to search with. TestDshSearchThroughGateway is new and fails without the change. Tested end to end in a sandbox (own HOME and DSH_HOME, gateway on 3493, the real DeepSeek account): real dsh 0.2.0-rc.2 headless called web_search, got eight results through magpie, and answered https://golang.google.cn/blog/go1.26; magpie dsh default took the entry out of all three profiles. go vet, go build (darwin, GOOS=linux nogui, GOOS=windows) and go test -tags nogui ./... under a temp HOME pass.
113 lines
3.8 KiB
Go
113 lines
3.8 KiB
Go
package agent
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/yetone/magpie/internal/gateway"
|
|
)
|
|
|
|
// Packing1 on Discord: dsh through magpie alone, every web search failed
|
|
// asking for DEEPSEEK_API_KEY — dsh's web-search-deepseek plugin signs its
|
|
// own requests to DeepSeek. While dsh starts on a model of magpie's, the row
|
|
// points at the gateway with magpie's key and that model; it goes again with
|
|
// magpie's model, and a row or a DeepSeek key of the user's is left as it is.
|
|
func TestDshSearchThroughGateway(t *testing.T) {
|
|
home, dir, web := dshRouteHome(t)
|
|
template := "# Your patch layer for this dsh profile.\n[]\n"
|
|
os.WriteFile(web, []byte(template), 0o644)
|
|
read := func() string { b, _ := os.ReadFile(web); return string(b) }
|
|
a := dsh(home)
|
|
f := a.Field("model")
|
|
|
|
if err := f.Set("magpie/deepseek/pro"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
s := read()
|
|
want := strings.Join(dshSearchLines("deepseek/pro", gateway.URL()), "\n")
|
|
if !strings.Contains(s, want) || strings.Count(s, "id: "+dshSearchRow) != 1 {
|
|
t.Fatalf("search row:\n%s", s)
|
|
}
|
|
for _, w := range []string{"- id: web-search-deepseek # magpie", "apiKeyEnv: " + dshKeyRef, `baseURL: "` + gatewayV1() + `"`, `model: "deepseek/pro"`, `name: "@deepseek-ai/dsh-web-search-deepseek"`} {
|
|
if !strings.Contains(s, w) {
|
|
t.Fatalf("missing %q in\n%s", w, s)
|
|
}
|
|
}
|
|
if a.Check() != "" {
|
|
t.Fatalf("check: %q", a.Check())
|
|
}
|
|
|
|
// another model of magpie's: the search asks it, still one row
|
|
if err := f.Set("magpie/deepseek/flash"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if s = read(); !strings.Contains(s, `model: "deepseek/flash"`) || strings.Count(s, "id: "+dshSearchRow) != 1 {
|
|
t.Fatalf("model moved:\n%s", s)
|
|
}
|
|
|
|
// the gateway's address moved: the round that writes the route again
|
|
// writes the search's too, its model kept
|
|
if _, err := dshRouteAgain(web, magpieModels("dsh"), "http://127.0.0.1:9"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if s = read(); !strings.Contains(s, `baseURL: "http://127.0.0.1:9/v1"`) || !strings.Contains(s, `model: "deepseek/flash"`) {
|
|
t.Fatalf("gateway moved:\n%s", s)
|
|
}
|
|
|
|
// dsh's own model: its own search back, as it ships
|
|
if err := f.Set("deepseek-v4-pro"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if s = read(); strings.Contains(s, dshSearchRow) {
|
|
t.Fatalf("own model kept magpie's search:\n%s", s)
|
|
}
|
|
if err := f.Set("magpie/deepseek/pro"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := f.Set(""); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if s = read(); s != template {
|
|
t.Fatalf("reset:\n%s", s)
|
|
}
|
|
|
|
// a DeepSeek key of dsh's own: its search works as it is
|
|
env := filepath.Join(dir, ".env")
|
|
os.WriteFile(env, []byte("DEEPSEEK_API_KEY=sk-mine\n"), 0o600)
|
|
if err := f.Set("magpie/deepseek/pro"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if s = read(); strings.Contains(s, dshSearchRow) {
|
|
t.Fatalf("own DeepSeek key, search taken:\n%s", s)
|
|
}
|
|
f.Set("")
|
|
os.Remove(env)
|
|
os.WriteFile(filepath.Join(dir, ".credentials.yaml"), []byte("version: 1\nrecords:\n DEEPSEEK_API_KEY:\n kind: secret\n payload:\n value: sk-mine\n"), 0o600)
|
|
if err := f.Set("magpie/deepseek/pro"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if s = read(); strings.Contains(s, dshSearchRow) {
|
|
t.Fatalf("own DeepSeek key in dsh's store, search taken:\n%s", s)
|
|
}
|
|
f.Set("")
|
|
os.Remove(filepath.Join(dir, ".credentials.yaml"))
|
|
|
|
// a row of the user's stays through connect and disconnect
|
|
own := "# Your patch layer for this dsh profile.\n- id: web-search-deepseek\n config:\n apiKeyEnv: MY_KEY\n baseURL: https://search.example/v1\n"
|
|
os.WriteFile(web, []byte(own), 0o644)
|
|
if err := f.Set("magpie/deepseek/pro"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if s = read(); !strings.HasPrefix(s, own) || strings.Count(s, dshSearchRow) != 1 {
|
|
t.Fatalf("user's row:\n%s", s)
|
|
}
|
|
if err := f.Set(""); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if s = read(); s != own {
|
|
t.Fatalf("user's row after reset:\n%s", s)
|
|
}
|
|
}
|