The Providers page asks tencentPlanRegion and openCodeGateway of every
provider on each list. Both url.Parse'd every base, a heap profile of 40
/api/providers asks put 3MB of url.Parse there (2.5MB Tencent, 0.5MB
OpenCode). Every host either takes holds "tencentmaas.com" or
"opencode.ai", so a base without it (case folded; ToLower copies nothing
for an already lower-case base) returns at once.
TestOtherVendorsBasesAreNotParsed: 0 allocations for another vendor's
provider and base, and mixed-case Tencent and OpenCode Go bases still
resolve (ap-guangzhou, go). Red on the old code (3 and 1 allocations).
Run on mote at 682a1e392: go test ./internal/provider ./internal/gui ok;
vet provider for darwin, linux and windows ok.
24 lines
1.1 KiB
Go
24 lines
1.1 KiB
Go
package provider
|
|
|
|
import "testing"
|
|
|
|
// The Providers page asks every provider whether it is a Tencent Token
|
|
// Plan or OpenCode's gateway; a base of another vendor's is told apart
|
|
// without parsing it.
|
|
func TestOtherVendorsBasesAreNotParsed(t *testing.T) {
|
|
p := Provider{ID: "x", Chat: "https://api.example.com/v1", Responses: "https://api.example.com/v1", Anthropic: "https://api.example.com/anthropic"}
|
|
if n := testing.AllocsPerRun(50, func() { tencentPlanRegion(p) }); n != 0 {
|
|
t.Errorf("tencentPlanRegion of another vendor's provider allocated %v times a call", n)
|
|
}
|
|
if n := testing.AllocsPerRun(50, func() { openCodeGateway(p.Chat) }); n != 0 {
|
|
t.Errorf("openCodeGateway of another vendor's base allocated %v times a call", n)
|
|
}
|
|
// and still what they are about, whatever its case
|
|
if r, ok := tencentPlanRegion(Provider{Chat: "https://TokenHub.TencentMaaS.com/plan/v3"}); !ok || r != "ap-guangzhou" {
|
|
t.Errorf("Tencent's plan base: %q %v", r, ok)
|
|
}
|
|
if g := openCodeGateway("https://OpenCode.ai/zen/go/v1"); g != "go" {
|
|
t.Errorf("OpenCode Go's base: %q", g)
|
|
}
|
|
}
|