feat: sync deployed v1.0.0-rc.38-custom.42
Sync production source including routing, billing, Astra detection and public uptime. Update custom build instructions and license packaging.
This commit is contained in:
1 parent
aa6c3f50f4
commit
ceddfd3d6b
828 files changed
+122253
-13702
No files matched your search
@@ -1,6 +1,7 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/QuantumNous/new-api/common"
|
||||
@@ -8,6 +9,23 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestTokenAstraCacheUpgradePreservesLiveQuota(t *testing.T) {
|
||||
useUserCacheMiniRedis(t)
|
||||
ctx := context.Background()
|
||||
token := Token{Id: 43, UserId: 7, Key: "legacy-astra-cache", AstraAutoSwitch: true, RemainQuota: 100}
|
||||
require.NoError(t, cacheSetTokenForTest(token))
|
||||
key := getTokenCacheKey(token.Key)
|
||||
require.NoError(t, common.RDB.HDel(ctx, key, "AstraAutoSwitch").Err())
|
||||
require.NoError(t, common.RDB.HSet(ctx, key, "RemainQuota", 70).Err())
|
||||
_, err := cacheGetTokenByKey(token.Key)
|
||||
require.Error(t, err, "legacy cache must fetch the migrated value from the database")
|
||||
require.NoError(t, cacheSetTokenForTest(token))
|
||||
cached, err := cacheGetTokenByKey(token.Key)
|
||||
require.NoError(t, err)
|
||||
require.True(t, cached.AstraAutoSwitch)
|
||||
require.Equal(t, 70, cached.RemainQuota, "metadata hydration must not overwrite concurrent quota consumption")
|
||||
}
|
||||
|
||||
func TestTokenAutoGroupsRoundTripThroughRedisHashCache(t *testing.T) {
|
||||
useUserCacheMiniRedis(t)
|
||||
token := Token{
|
||||
@@ -41,6 +59,7 @@ func TestTokenUpdateSynchronouslyNarrowsPreheatedAutoGroupsCache(t *testing.T) {
|
||||
Group: "auto",
|
||||
CrossGroupRetry: true,
|
||||
AutoGroups: `["default","vip"]`,
|
||||
AstraAutoSwitch: true,
|
||||
}
|
||||
require.NoError(t, token.Insert())
|
||||
require.NoError(t, cacheSetTokenForTest(token))
|
||||
@@ -50,6 +69,7 @@ func TestTokenUpdateSynchronouslyNarrowsPreheatedAutoGroupsCache(t *testing.T) {
|
||||
assert.JSONEq(t, `["default","vip"]`, preheated.AutoGroups)
|
||||
|
||||
require.NoError(t, token.SetAutoGroups([]string{"vip"}))
|
||||
token.AstraAutoSwitch = false
|
||||
require.NoError(t, token.Update())
|
||||
// Update 是限制性变更:写库前删除缓存并设置 fence。缓存不再提供旧的
|
||||
// 宽分组值,下一次读取必须看到收紧后的分组。
|
||||
@@ -58,6 +78,7 @@ func TestTokenUpdateSynchronouslyNarrowsPreheatedAutoGroupsCache(t *testing.T) {
|
||||
reloaded, err := GetTokenByKey(token.Key, false)
|
||||
require.NoError(t, err)
|
||||
assert.JSONEq(t, `["vip"]`, reloaded.AutoGroups)
|
||||
assert.False(t, reloaded.AstraAutoSwitch)
|
||||
}
|
||||
|
||||
// cacheSetTokenForTest 以测试身份写入完整 token 缓存(含额度字段),
|
||||
|
||||
Reference in new issue
Block a user