| 1 | package config |
| 2 | |
| 3 | import ( |
| 4 | "net/url" |
| 5 | "testing" |
| 6 | ) |
| 7 | |
| 8 | func TestDocumentedProtocolEndpoints(t *testing.T) { |
| 9 | for scope, routes := range documentedProtocolEndpoints { |
| 10 | for kind, e := range routes { |
| 11 | if kind != "openai" && kind != "responses" && kind != "anthropic" { |
| 12 | t.Fatalf("unknown kind %s", kind) |
| 13 | } |
| 14 | u, err := url.Parse(e.BaseURL) |
| 15 | if err != nil || u.Host == "" || e.Source == "" || e.CheckedOn == "" { |
| 16 | t.Fatalf("invalid route %s/%s: %+v", scope, kind, e) |
| 17 | } |
| 18 | } |
| 19 | } |
| 20 | cases := []struct{ id, kind, want string }{ |
| 21 | {"deepseek-anthropic", "anthropic", "https://api.deepseek.com/anthropic"}, |
| 22 | {"kimi-coding-plan", "openai", "https://api.kimi.com/coding/v1"}, |
| 23 | {"siliconflow", "anthropic", "https://api.siliconflow.cn"}, |
| 24 | {"ppio", "openai", "https://api.ppio.com/openai"}, |
| 25 | {"amd-gpu-cloud", "openai", "https://developer.amd.com.cn/radeon/api/v1"}, |
| 26 | {"lmstudio", "responses", "http://localhost:1234/v1"}, |
| 27 | {"mimo-api", "responses", "https://api.xiaomimimo.com/v1"}, |
| 28 | } |
| 29 | for _, tc := range cases { |
| 30 | p, ok := CuratedProviderPreset(tc.id) |
| 31 | if !ok { |
| 32 | t.Fatal(tc.id) |
| 33 | } |
| 34 | c := CatalogForProviderPreset(p) |
| 35 | if got := c.Protocols[tc.kind].BaseURL; got != tc.want { |
| 36 | t.Fatalf("%s/%s = %s", tc.id, tc.kind, got) |
| 37 | } |
| 38 | delete(c.Protocols, tc.kind) |
| 39 | if CatalogForProviderPreset(p).Protocols[tc.kind].BaseURL != tc.want { |
| 40 | t.Fatal("catalog shared mutable map") |
| 41 | } |
| 42 | } |
| 43 | p, _ := CuratedProviderPreset("glm-cn") |
| 44 | if _, ok := CatalogForProviderPreset(p).Protocols["responses"]; ok { |
| 45 | t.Fatal("undocumented protocol guessed") |
| 46 | } |
| 47 | p, _ = CuratedProviderPreset("stepfun") |
| 48 | if _, ok := CatalogForProviderPreset(p).Protocols["responses"]; ok { |
| 49 | t.Fatal("payg endpoint leaked into subscription") |
| 50 | } |
| 51 | } |
| 52 |