mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-10-16 07:33:06 +08:00
- fetcher:海外/CN coding/CN payg 分派、账号缺失、凭据失效标记、 TTL 命中与失败不缓存、UsageInfo→tiers 全窗口归一、状态推导矩阵 - quota mode:RunCheck 三分派(quota 单行 / quota_probe 仅挂主行 / probe 不变)、配额失败不翻探活状态、校验矩阵、关联账号复核 (quota 报错 probe 自动解绑)、quota→probe 切换强制重填 key、 Duplicate 空明文重加密 - settings:channel_monitor_show_quota 缺省关闭 + 仅 "true" 开启 - 迁移内容断言(仿 176 grok 迁移测试) - repo 集成测试:check_mode/account_id 往返、quota JSONB 回读、 探活旧行 NULL 兼容(testcontainers PG 实跑迁移 226) - 修复 Fetch 在 nil receiver 上的 panic(缓存查询先于原 nil 守卫)
38 lines
1.6 KiB
Go
38 lines
1.6 KiB
Go
package migrations
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestChannelMonitorQuotaModeMigration(t *testing.T) {
|
|
content, err := FS.ReadFile("226_channel_monitor_quota_mode.sql")
|
|
require.NoError(t, err)
|
|
|
|
sql := strings.Join(strings.Fields(string(content)), " ")
|
|
|
|
// provider CHECK 两张表扩到 8 平台,且带幂等守卫(仿 176 grok 迁移)。
|
|
require.Contains(t, sql, "channel_monitors_provider_check")
|
|
require.Contains(t, sql, "channel_monitor_request_templates_provider_check")
|
|
require.Contains(t, sql, "CHECK (provider IN ('openai', 'anthropic', 'gemini', 'grok', 'antigravity', 'kimi', 'zhipu', 'deepseek'))")
|
|
require.Contains(t, sql, "position('kimi' IN monitor_constraint_def) = 0")
|
|
require.Contains(t, sql, "position('kimi' IN template_constraint_def) = 0")
|
|
|
|
// check_mode 三态,默认 probe。
|
|
require.Contains(t, sql, "ADD COLUMN IF NOT EXISTS check_mode VARCHAR(32) NOT NULL DEFAULT 'probe'")
|
|
require.Contains(t, sql, "CHECK (check_mode IN ('probe', 'quota', 'quota_probe'))")
|
|
|
|
// account_id 关联账号,账号删除置空(监控保留,运行时报「账号未关联」)。
|
|
require.Contains(t, sql, "ADD COLUMN IF NOT EXISTS account_id BIGINT REFERENCES accounts(id) ON DELETE SET NULL")
|
|
require.Contains(t, sql, "CREATE INDEX IF NOT EXISTS idx_channel_monitors_account_id ON channel_monitors(account_id)")
|
|
|
|
// 历史表配额快照列。
|
|
require.Contains(t, sql, "ADD COLUMN IF NOT EXISTS quota JSONB")
|
|
|
|
// 公开设置默认关闭。
|
|
require.Contains(t, sql, "VALUES ('channel_monitor_show_quota', 'false')")
|
|
require.Contains(t, sql, "ON CONFLICT (key) DO NOTHING")
|
|
}
|