From 878a8489f0283e53a8b2518bf13cd7d9f6f1bbf7 Mon Sep 17 00:00:00 2001 From: yetone Date: Mon, 5 Oct 2026 03:25:31 +0800 Subject: [PATCH] =?UTF-8?q?gateway:=20a=20plugin's=20model=20that=20writes?= =?UTF-8?q?=20its=20tool=20call=20into=20the=20text=20is=20answered=20as?= =?UTF-8?q?=20a=20built-in's=20is,=20proven=20(#823,=20Dazzle-sys:=20Trae?= =?UTF-8?q?=20CN's=20DeepSeek=20V4.1=20Flash=20in=20a=20group=20ended=20th?= =?UTF-8?q?e=20session=20in=20Pi)=20=E2=80=94=20TestPluginTextWrittenCall?= =?UTF-8?q?=20serves=20a=20plugin=20provider=20(trae-cn)=20whose=20Chat=20?= =?UTF-8?q?stream=20writes=20{"name":"bash",=E2=80=A6}{\"name\":\"bash\",\"arguments\":{\"command\":\"cd /e/Project && echo \\\"### $spec\\\"; done\"}}\n") || + !strings.Contains(body, `"tool_calls"`) || !strings.Contains(body, `"finish_reason":"tool_calls"`) { + t.Fatalf("%d %s", rec.Code, body) + } + var args string + for _, line := range strings.Split(body, "\n") { + var c struct { + Choices []struct { + Delta struct { + ToolCalls []struct { + Function struct{ Name, Arguments string } + } `json:"tool_calls"` + } + } + } + if json.Unmarshal([]byte(strings.TrimPrefix(line, "data: ")), &c) == nil && len(c.Choices) > 0 { + for _, tc := range c.Choices[0].Delta.ToolCalls { + args += tc.Function.Arguments + } + } + } + var a map[string]string + if json.Unmarshal([]byte(args), &a) != nil || a["command"] != `cd /e/Project && echo "### $spec"; done` { + t.Fatalf("arguments %q", args) + } + }) + t.Run("messages", func(t *testing.T) { + req := httptest.NewRequest("POST", "/v1/messages", bytes.NewReader([]byte(`{"model":"`+model+`","stream":true,"max_tokens":100,"tools":[{"name":"bash","input_schema":{"type":"object"}}],"messages":[{"role":"user","content":"go on"}]}`))) + req.Header.Set("x-api-key", "magpie") + rec := httptest.NewRecorder() + h.ServeHTTP(rec, req) + body := rec.Body.String() + if rec.Code != 200 || strings.Contains(body, "DSML") || !strings.Contains(body, `"tool_use"`) { + t.Fatalf("%d %s", rec.Code, body) + } + }) +}