Files
magpie/internal/gateway/plugin_kinds_test.go
T
yetoneandggbdpq 8c63c5b787 provider, plugin: a plugin model that says it gives no text leaves the chat lists (#3279)
A plugin provider's list counted every model it named as a chat model.
XYenon's Google AI Studio plugin put gemini-embedding-001 and its TTS
models in the chat chips, the agents' lists and /v1/models. The plugin
does declare them: the embedding's capabilities.output is
{"text": false} and the TTS's says audio only. But the host's kinds()
kept only the true keys. That made "said it gives nothing" look the same
as "said nothing", and pluginCatalog never read Outputs.

- host.js passes outputsSaid, which is whether capabilities.output says
  yes or no to any kind (kindsSaid). It goes into plugin.Model.OutputsSaid.
- pluginCatalog leaves out a model whose outputs were declared and name
  no text, image or video (pluginTalks). Every chat list is built from
  that list: /v1/models, provider.Catalog (the agents' lists and routing),
  and Available (the editor's chips).
- A plugin that says nothing about outputs keeps every model, whatever
  the id. Image-only and video-only models stay where they are; #2792
  decides where they go.

Ported from ggbdpq's hunt65-c-3279-kinds (7391b0df2), with changes
after review. That patch found the right place (pluginCatalog) and
wrote the provider tests kept here. It judged an embedding by "embed" in
its id, because the host drops the declaration. So an embedding named
otherwise (bge-m3, text:false) stayed in the list. A plugin that says
nothing about outputs lost any model whose id held "embed" or "-tts",
which changes today's behaviour. An image-only model (outputs ["image"])
was dropped, though the patch said it left #2792's models alone. This
version fixes the declaration in the host instead and guesses nothing
from ids. catalog.textModel is unchanged.

Docs: docs/subsystems/provider-plugins.md, "A model that gives no text".

Run (mote, at base 96a703a59; then rebased onto 9f25de56c, which
changed only two mover mins, and ./internal/provider plus the e2e test
run again there: ok):
- TestPluginModelGivingNoTextLeavesTheChatLists (gateway, a real Bun
  host with the fake plugin under FAKE_KINDS, using XYenon's literal
  capabilities) is red on main: the embedding and the TTS are in
  /v1/models, the agents' catalog and Available. It is green with this
  change.
- go test -count=1 -timeout 45m ./internal/plugin ./internal/provider
  ./internal/gateway: ok (plugin 165s, provider
  121s, gateway 759s).
- GOOS=linux and GOOS=windows go vet of the three packages: clean.
  gofmt -l: clean.
Broken by hand:
- host.js without outputsSaid: the e2e test is red (embedding, bge-m3
  and TTS listed; rerun at this base).
- pluginTalks always true: the e2e test and both provider tests are red
  (rerun at this base: embedding, bge-m3 and TTS listed in each).
- ggbdpq's original product change with these tests: the e2e test is red
  on bge-m3. The unit test is red on bge-m3 kept, imagen-4 lost and
  embedder-chat lost.
Not tried: the reporter's real plugin with a Google AI Studio account.
The fixture is the plugin's parseModels output and the report's own
row. A TTS or embedding model still has no route of its own here.
Not run: the full ./... suite, and the GUI suite (no GUI file changed).

Co-authored-by: ggbdpq <ggbdpq@gmail.com>
2026-10-29 18:17:55 +08:00

73 lines
1.9 KiB
Go

package gateway
import (
"encoding/json"
"net/http"
"net/http/httptest"
"strings"
"testing"
"github.com/yetone/magpie/internal/provider"
)
// A plugin model that says it gives no text is no model to talk with: its
// embedding and its TTS leave the chat lists, the gateway's /v1/models,
// the agents' (provider.Catalog) and the provider's own (Available, the
// GUI's chips), as XYenon's Google AI Studio plugin lists them (#3279). A
// model naming text among what it gives stays, speaking or drawing too.
// An embedding is known by what its plugin says, not its id (bge-m3).
func TestPluginModelGivingNoTextLeavesTheChatLists(t *testing.T) {
t.Setenv("FAKE_KINDS", "1")
pid := besideFake(t, "google-ai-studio", &cursorUp{})
gone := []string{"gemini-embedding-001", "bge-m3", "gemini-2.5-flash-preview-tts"}
kept := []string{"fake-1", "gemini-2.5-flash-native-audio", "gemini-2.5-flash-image"}
check := func(where string, got map[string]bool) {
t.Helper()
for _, id := range gone {
if got[id] {
t.Errorf("%s lists %s, which gives no text", where, id)
}
}
for _, id := range kept {
if !got[id] {
t.Errorf("%s lost %s", where, id)
}
}
}
rec := httptest.NewRecorder()
New().Handler().ServeHTTP(rec, httptest.NewRequest(http.MethodGet, "/v1/models", nil))
var list struct {
Data []struct{ ID string } `json:"data"`
}
if err := json.Unmarshal(rec.Body.Bytes(), &list); err != nil {
t.Fatalf("/v1/models: %v\n%s", err, rec.Body.String())
}
got := map[string]bool{}
for _, m := range list.Data {
if id, ok := strings.CutPrefix(m.ID, pid+"/"); ok {
got[id] = true
}
}
check("/v1/models", got)
got = map[string]bool{}
for _, e := range provider.Catalog() {
if e.Provider.ID == pid {
got[e.Model] = true
}
}
check("the agents' catalog", got)
p, err := provider.Find(pid)
if err != nil {
t.Fatal(err)
}
got = map[string]bool{}
for _, m := range p.Available() {
got[m.ID] = true
}
check("Available", got)
}