Files
magpie/internal/provider/plugin_vendor_test.go
T
yetone 9309e28ced plugins: a plugin's provider in front of a vendor's API is that vendor to the gateway (songlairui on X, #5462, #5464)
A plugin whose provider's `api` is on a vendor's preset host (a Mistral
Vibe plugin's https://api.mistral.ai/v1) got none of what magpie does for
that vendor, since its Host() is the plugin's id. An earlier turn's
thinking went to the plugin's fetch as reasoning_content, and Mistral
turned the whole request away (422 extra_forbidden); the plugin had to
rewrite the body itself.

provider.VendorHost and VendorPreset now resolve a plugin's declared `api`
host to the preset that names it (every Chat, Responses and Anthropic base
of every preset and region; local and remote magpie presets excluded, and
an api on loopback, a private address, .local or .localhost names no
vendor). For every other provider, and a moved subscription, they are
Host() and Preset as before. The gateway's vendor checks read them: 38
p.Host() sites, Mistral's, OpenRouter's, DeepSeek's, Kimi's and
DashScope's preset checks. Host() stays the plugin's id where calls are
kept and shown; requests still go only to the plugin's fetch. Search and
the video plan check are unchanged. No community plugin's api is on a
preset host today (checked at plugins 7b52e3fc), so none changes.

Any plugin gets this with no new field; documented in
docs/subsystems/provider-plugins.md and the plugin docs (en, zh, ja).

Run (mote): go vet ./... darwin, GOOS=linux -tags nogui, GOOS=windows;
go test -count=1 -timeout 45m ./internal/provider ./internal/plugin
./internal/gateway: ok (provider 209s, plugin 182s, gateway 1002s). gofmt -l clean.
Broken by hand: pluginVendor resolving nothing (the old behaviour) turns
TestPluginVendor red, and TestPluginInFrontOfMistralIsMistral red on both
halves: the translated Claude Code turn is answered Mistral's 422
extra_forbidden, and the relayed Chat request carries reasoning_content.
Not tried: a real Mistral Vibe key through the reporter's plugin; Windows
and Linux runs of the tests (no OS-specific code).
2026-11-10 10:01:59 +08:00

54 lines
1.9 KiB
Go

package provider
import (
"testing"
"github.com/yetone/magpie/internal/plugin"
)
// A plugin's provider is the vendor its `api` is on, for the gateway's
// vendor checks (#5464); a provider no plugin gives, a moved subscription,
// and a plugin on no preset's host, this computer or its network keep
// their own host.
func TestPluginVendor(t *testing.T) {
on := func(api string) Provider {
p := PluginForTest("plugin-vibe", "vibe")
p.Account.plugin = &plugin.Provider{ID: "vibe", API: api}
return p
}
for _, c := range []struct {
name, api, preset, host string
}{
{"mistral", "https://api.mistral.ai/v1", "mistral", "api.mistral.ai"},
{"deepseek", "https://api.deepseek.com/v1", "deepseek", "api.deepseek.com"},
{"openrouter", "https://openrouter.ai/api/v1", "openrouter", "openrouter.ai"},
{"unknown host", "https://vibe.example.com/v1", "", ""},
{"no api", "", "", ""},
{"localhost", "http://localhost:11434/v1", "", ""},
{"loopback", "http://127.0.0.1:8080/v1", "", ""},
{"lan", "http://192.168.1.4:8080/v1", "", ""},
{"dot local", "http://box.local:8080/v1", "", ""},
} {
p := on(c.api)
if got := p.VendorPreset(); got != c.preset {
t.Errorf("%s: VendorPreset = %q, want %q", c.name, got, c.preset)
}
want := c.host
if want == "" {
want = p.Host()
}
if got := p.VendorHost(); got != want {
t.Errorf("%s: VendorHost = %q, want %q", c.name, got, want)
}
}
moved := on("https://api.mistral.ai/v1")
moved.Account.moved = true
if moved.VendorPreset() != "" || moved.VendorHost() != moved.Host() {
t.Errorf("a moved subscription is %q at %q, want its own host %q", moved.VendorPreset(), moved.VendorHost(), moved.Host())
}
plain := Provider{ID: "mistral", Preset: "mistral"}
if plain.VendorPreset() != "mistral" || plain.VendorHost() != plain.Host() {
t.Errorf("a preset provider is %q at %q", plain.VendorPreset(), plain.VendorHost())
}
}