mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-12-05 16:07:33 +00:00
解决与 #7618 的 51 个文件冲突,并把 ollama_cloud 接入平台清单与 provider profile: - domain/platforms.go 登记 ollama_cloud(OpenAI 网关,LiteLLMProvider 留空); provider_profile.go 登记 by_inbound profile(legacy/credits 两模式共用端点), 新增 ProviderProfile.DefaultAPIProtocol 表达未配置时默认 adaptive。 - 删除 #7114 手写的约 30 处平台清单/switch,改用清单派生(AllowedQuotaPlatforms、 binding 校验、调度快照、组合分组、路由 dispatcher、前端平台选项/配色/配额等)。 - 迁移 242_ollama_cloud_platform 改为 243_ollama_cloud_channel_monitor_provider: 只放宽渠道监控 provider CHECK,不再重建 #7618 删除的两个平台 CHECK(否则 command_code/cline 写入失败)。 - compositeOwnershipQueryPlatforms 改为平台清单派生,修复 command_code/cline 账号在组合分组归属扫描中被漏掉。 - 连接测试:ollama_cloud 专属路径先于按入站协议分流的通用分支。 - nativeAnthropicMessagesURL:版本感知拼接对 ollama_cloud 生效,国产厂商保持朴素拼接。 - GetOpenAIBaseURL 保留多协议账号不回落 api.openai.com 的护栏。 - 前端:ollama_cloud 保留专属表单(双额度模式 + 月度信用额度),从通用表单与 通用平台按钮中排除;端点常量改读平台清单;配额弹窗/设置页保留未知平台行护栏。 - 重新生成 platformCatalog.builtin.json;同步相关测试基准。
89 lines
3.1 KiB
Go
89 lines
3.1 KiB
Go
//go:build unit
|
|
|
|
package admin
|
|
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
"net/http/httptest"
|
|
"testing"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
// 回归分组平台枚举:kimi/zhipu/deepseek/opencode_go/ollama_cloud 必须能通过
|
|
// Create/Update 的 binding 校验(历史 bug:调度/路由链路已支持这些平台,但 oneof
|
|
// 白名单漏加,导致平台分组无法创建、账号"无可用分组");非法值仍须被拒。
|
|
func bindGroupPlatformJSON(t *testing.T, target any, body string) error {
|
|
t.Helper()
|
|
gin.SetMode(gin.TestMode)
|
|
c, _ := gin.CreateTestContext(httptest.NewRecorder())
|
|
c.Request = httptest.NewRequest("POST", "/", bytes.NewBufferString(body))
|
|
c.Request.Header.Set("Content-Type", "application/json")
|
|
return c.ShouldBindJSON(target)
|
|
}
|
|
|
|
func TestGroupPlatformBinding_AllowedPlatforms(t *testing.T) {
|
|
allowed := []string{
|
|
"anthropic", "openai", "gemini", "antigravity", "grok",
|
|
"kimi", "zhipu", "deepseek", "minimax", "opencode_go", "composite",
|
|
"typesafe",
|
|
"command_code", "cline", "ollama_cloud",
|
|
}
|
|
for _, platform := range allowed {
|
|
t.Run("create_"+platform, func(t *testing.T) {
|
|
var req CreateGroupRequest
|
|
body := fmt.Sprintf(`{"name":"g","platform":%q}`, platform)
|
|
require.NoError(t, bindGroupPlatformJSON(t, &req, body),
|
|
"platform %q 应通过 CreateGroupRequest 校验", platform)
|
|
require.Equal(t, platform, req.Platform)
|
|
})
|
|
t.Run("update_"+platform, func(t *testing.T) {
|
|
var req UpdateGroupRequest
|
|
body := fmt.Sprintf(`{"platform":%q}`, platform)
|
|
require.NoError(t, bindGroupPlatformJSON(t, &req, body),
|
|
"platform %q 应通过 UpdateGroupRequest 校验", platform)
|
|
require.Equal(t, platform, req.Platform)
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestGroupPlatformBinding_RejectsInvalidPlatforms(t *testing.T) {
|
|
invalid := []string{
|
|
"moonshot", // 厂商别名,不是平台标识
|
|
"Kimi", // 大小写敏感
|
|
"openai ", // 尾随空格
|
|
"glm",
|
|
"bogus",
|
|
}
|
|
for _, platform := range invalid {
|
|
t.Run("create_"+platform, func(t *testing.T) {
|
|
var req CreateGroupRequest
|
|
body := fmt.Sprintf(`{"name":"g","platform":%q}`, platform)
|
|
require.Error(t, bindGroupPlatformJSON(t, &req, body),
|
|
"platform %q 应被 CreateGroupRequest 拒绝", platform)
|
|
})
|
|
t.Run("update_"+platform, func(t *testing.T) {
|
|
var req UpdateGroupRequest
|
|
body := fmt.Sprintf(`{"platform":%q}`, platform)
|
|
require.Error(t, bindGroupPlatformJSON(t, &req, body),
|
|
"platform %q 应被 UpdateGroupRequest 拒绝", platform)
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestCompositeRouteTargetPlatform_AllowsConcreteProviders(t *testing.T) {
|
|
for _, platform := range []string{"kimi", "zhipu", "deepseek", "minimax", "opencode_go", "typesafe", "command_code", "cline", "ollama_cloud"} {
|
|
var req CompositeRouteRequest
|
|
body := fmt.Sprintf(`{"public_model":"m","target_platform":%q}`, platform)
|
|
require.NoError(t, bindGroupPlatformJSON(t, &req, body))
|
|
require.Equal(t, platform, req.TargetPlatform)
|
|
}
|
|
}
|
|
|
|
func TestCompositeRouteTargetPlatform_RejectsComposite(t *testing.T) {
|
|
var req CompositeRouteRequest
|
|
require.Error(t, bindGroupPlatformJSON(t, &req, `{"public_model":"m","target_platform":"composite"}`))
|
|
}
|