diff --git a/backend/internal/handler/gateway_handler_warmup_intercept_unit_test.go b/backend/internal/handler/gateway_handler_warmup_intercept_unit_test.go index daf15f640a..0c94d50b76 100644 --- a/backend/internal/handler/gateway_handler_warmup_intercept_unit_test.go +++ b/backend/internal/handler/gateway_handler_warmup_intercept_unit_test.go @@ -127,7 +127,7 @@ func (f *fakeConcurrencyCache) GetAccountConcurrencyBatch(_ context.Context, acc return result, nil } func (f *fakeConcurrencyCache) CleanupExpiredAccountSlots(context.Context, int64) error { return nil } -func (f *fakeConcurrencyCache) CleanupStaleProcessSlots(context.Context, string) error { return nil } +func (f *fakeConcurrencyCache) CleanupStaleProcessSlots(context.Context, string) error { return nil } func newTestGatewayHandler(t *testing.T, group *service.Group, accounts []*service.Account) (*GatewayHandler, func()) { t.Helper() diff --git a/backend/internal/handler/sora_client_handler_test.go b/backend/internal/handler/sora_client_handler_test.go index ad92016221..87009882d6 100644 --- a/backend/internal/handler/sora_client_handler_test.go +++ b/backend/internal/handler/sora_client_handler_test.go @@ -1808,7 +1808,7 @@ func TestStoreMediaWithDegradation_S3FailsFallbackToLocal(t *testing.T) { mediaStorage := service.NewSoraMediaStorage(cfg) h := &SoraClientHandler{ objectStorage: s3Storage, - mediaStorage: mediaStorage, + mediaStorage: mediaStorage, } _, _, storageType, _, _ := h.storeMediaWithDegradation( diff --git a/backend/internal/repository/concurrency_cache.go b/backend/internal/repository/concurrency_cache.go index f5e3ac1e6a..8488f93962 100644 --- a/backend/internal/repository/concurrency_cache.go +++ b/backend/internal/repository/concurrency_cache.go @@ -147,7 +147,6 @@ var ( return 1 `) - // cleanupExpiredSlotsScript 清理单个账号/用户有序集合中过期槽位 // KEYS[1] = 有序集合键 // ARGV[1] = TTL(秒) @@ -215,8 +214,7 @@ var ( return removed `) - ) - +) type concurrencyCache struct { rdb *redis.Client @@ -516,7 +514,6 @@ func (c *concurrencyCache) GetUsersLoadBatch(ctx context.Context, users []servic return loadMap, nil } - func (c *concurrencyCache) CleanupExpiredAccountSlots(ctx context.Context, accountID int64) error { key := accountSlotKey(accountID) _, err := cleanupExpiredSlotsScript.Run(ctx, c.rdb, []string{key}, c.slotTTLSeconds).Result() diff --git a/backend/internal/repository/concurrency_cache_integration_test.go b/backend/internal/repository/concurrency_cache_integration_test.go index efebc81ca6..5da94fc258 100644 --- a/backend/internal/repository/concurrency_cache_integration_test.go +++ b/backend/internal/repository/concurrency_cache_integration_test.go @@ -288,7 +288,6 @@ func (s *ConcurrencyCacheSuite) TestCleanupStaleProcessSlots() { require.True(s.T(), errors.Is(err, redis.Nil)) } - func (s *ConcurrencyCacheSuite) TestGetAccountConcurrency_Missing() { // When no slots exist, GetAccountConcurrency should return 0 cur, err := s.cache.GetAccountConcurrency(s.ctx, 999) @@ -486,4 +485,3 @@ func (s *ConcurrencyCacheSuite) TestCleanupStaleProcessSlots_DeletesEmptySlotKey require.NoError(s.T(), err) require.EqualValues(s.T(), 0, exists) } - diff --git a/backend/internal/repository/gateway_cache.go b/backend/internal/repository/gateway_cache.go index a3cef7f092..ec4bf40e3e 100644 --- a/backend/internal/repository/gateway_cache.go +++ b/backend/internal/repository/gateway_cache.go @@ -31,12 +31,12 @@ var ( //go:embed lua/clear_account_affinity.lua clearAccountAffinityLua string - getAffinityScript = redis.NewScript(getAffinityLua) - updateAffinityScript = redis.NewScript(updateAffinityLua) - getAffinityCountScript = redis.NewScript(getAffinityCountLua) - getAffinityClientsScript = redis.NewScript(getAffinityClientsLua) + getAffinityScript = redis.NewScript(getAffinityLua) + updateAffinityScript = redis.NewScript(updateAffinityLua) + getAffinityCountScript = redis.NewScript(getAffinityCountLua) + getAffinityClientsScript = redis.NewScript(getAffinityClientsLua) getAffinityClientsWithScoresScript = redis.NewScript(getAffinityClientsWithScoresLua) - clearAccountAffinityScript = redis.NewScript(clearAccountAffinityLua) + clearAccountAffinityScript = redis.NewScript(clearAccountAffinityLua) ) type gatewayCache struct { diff --git a/backend/internal/service/admin_service_apikey_test.go b/backend/internal/service/admin_service_apikey_test.go index a6d12f9739..5c18a438fa 100644 --- a/backend/internal/service/admin_service_apikey_test.go +++ b/backend/internal/service/admin_service_apikey_test.go @@ -32,28 +32,44 @@ func (s *userRepoStubForGroupUpdate) AddGroupToAllowedGroups(_ context.Context, return s.addGroupErr } -func (s *userRepoStubForGroupUpdate) Create(context.Context, *User) error { panic("unexpected") } -func (s *userRepoStubForGroupUpdate) GetByID(context.Context, int64) (*User, error) { panic("unexpected") } -func (s *userRepoStubForGroupUpdate) GetByEmail(context.Context, string) (*User, error) { panic("unexpected") } -func (s *userRepoStubForGroupUpdate) GetFirstAdmin(context.Context) (*User, error) { panic("unexpected") } -func (s *userRepoStubForGroupUpdate) Update(context.Context, *User) error { panic("unexpected") } -func (s *userRepoStubForGroupUpdate) Delete(context.Context, int64) error { panic("unexpected") } +func (s *userRepoStubForGroupUpdate) Create(context.Context, *User) error { panic("unexpected") } +func (s *userRepoStubForGroupUpdate) GetByID(context.Context, int64) (*User, error) { + panic("unexpected") +} +func (s *userRepoStubForGroupUpdate) GetByEmail(context.Context, string) (*User, error) { + panic("unexpected") +} +func (s *userRepoStubForGroupUpdate) GetFirstAdmin(context.Context) (*User, error) { + panic("unexpected") +} +func (s *userRepoStubForGroupUpdate) Update(context.Context, *User) error { panic("unexpected") } +func (s *userRepoStubForGroupUpdate) Delete(context.Context, int64) error { panic("unexpected") } func (s *userRepoStubForGroupUpdate) List(context.Context, pagination.PaginationParams) ([]User, *pagination.PaginationResult, error) { panic("unexpected") } func (s *userRepoStubForGroupUpdate) ListWithFilters(context.Context, pagination.PaginationParams, UserListFilters) ([]User, *pagination.PaginationResult, error) { panic("unexpected") } -func (s *userRepoStubForGroupUpdate) UpdateBalance(context.Context, int64, float64) error { panic("unexpected") } -func (s *userRepoStubForGroupUpdate) DeductBalance(context.Context, int64, float64) error { panic("unexpected") } -func (s *userRepoStubForGroupUpdate) UpdateConcurrency(context.Context, int64, int) error { panic("unexpected") } -func (s *userRepoStubForGroupUpdate) ExistsByEmail(context.Context, string) (bool, error) { panic("unexpected") } +func (s *userRepoStubForGroupUpdate) UpdateBalance(context.Context, int64, float64) error { + panic("unexpected") +} +func (s *userRepoStubForGroupUpdate) DeductBalance(context.Context, int64, float64) error { + panic("unexpected") +} +func (s *userRepoStubForGroupUpdate) UpdateConcurrency(context.Context, int64, int) error { + panic("unexpected") +} +func (s *userRepoStubForGroupUpdate) ExistsByEmail(context.Context, string) (bool, error) { + panic("unexpected") +} func (s *userRepoStubForGroupUpdate) RemoveGroupFromAllowedGroups(context.Context, int64) (int64, error) { panic("unexpected") } -func (s *userRepoStubForGroupUpdate) UpdateTotpSecret(context.Context, int64, *string) error { panic("unexpected") } -func (s *userRepoStubForGroupUpdate) EnableTotp(context.Context, int64) error { panic("unexpected") } -func (s *userRepoStubForGroupUpdate) DisableTotp(context.Context, int64) error { panic("unexpected") } +func (s *userRepoStubForGroupUpdate) UpdateTotpSecret(context.Context, int64, *string) error { + panic("unexpected") +} +func (s *userRepoStubForGroupUpdate) EnableTotp(context.Context, int64) error { panic("unexpected") } +func (s *userRepoStubForGroupUpdate) DisableTotp(context.Context, int64) error { panic("unexpected") } // apiKeyRepoStubForGroupUpdate implements APIKeyRepository for AdminUpdateAPIKeyGroupID tests. type apiKeyRepoStubForGroupUpdate struct { diff --git a/backend/internal/service/gateway_affinity_scheduling_test.go b/backend/internal/service/gateway_affinity_scheduling_test.go index 0ad7bfb466..0650081195 100644 --- a/backend/internal/service/gateway_affinity_scheduling_test.go +++ b/backend/internal/service/gateway_affinity_scheduling_test.go @@ -20,7 +20,7 @@ import ( // mockAffinityCache 为亲和调度测试提供可控的 GatewayCache mock。 // 通过 getCountBatchFunc 可以自定义 GetAccountAffinityCountBatch 的行为。 type mockAffinityCache struct { - getCountBatchFunc func(ctx context.Context, groupID int64, accountIDs []int64, ttl time.Duration) (map[int64]int64, error) + getCountBatchFunc func(ctx context.Context, groupID int64, accountIDs []int64, ttl time.Duration) (map[int64]int64, error) getCountBatchCalls int // 记录 GetAccountAffinityCountBatch 被调用次数 } @@ -728,9 +728,9 @@ func TestClassifyByAffinityZone(t *testing.T) { t.Run("greens preferred over yellows", func(t *testing.T) { accs := []accountWithLoad{ - makeAWL(1, 5, 3, 3), // green (3 ≤ 5) - makeAWL(2, 5, 3, 7), // yellow (5 < 7 ≤ 8) - makeAWL(3, 5, 3, 2), // green (2 ≤ 5) + makeAWL(1, 5, 3, 3), // green (3 ≤ 5) + makeAWL(2, 5, 3, 7), // yellow (5 < 7 ≤ 8) + makeAWL(3, 5, 3, 2), // green (2 ≤ 5) } result := classifyByAffinityZone(accs) require.Len(t, result, 2) diff --git a/backend/internal/service/sora_task_worker.go b/backend/internal/service/sora_task_worker.go index b29083e009..059b671031 100644 --- a/backend/internal/service/sora_task_worker.go +++ b/backend/internal/service/sora_task_worker.go @@ -11,15 +11,15 @@ import ( // SoraTaskWorker polls unfinished Sora tasks in the background. // When a task completes, it downloads media to configured storage if available. type SoraTaskWorker struct { - taskService *SoraTaskService - accountRepo AccountRepository + taskService *SoraTaskService + accountRepo AccountRepository objectStorage SoraObjectStorage - mediaStorage *SoraMediaStorage - interval time.Duration - pollTimeout time.Duration - stopCh chan struct{} - stopOnce sync.Once - wg sync.WaitGroup + mediaStorage *SoraMediaStorage + interval time.Duration + pollTimeout time.Duration + stopCh chan struct{} + stopOnce sync.Once + wg sync.WaitGroup } func NewSoraTaskWorker( @@ -33,13 +33,13 @@ func NewSoraTaskWorker( interval = 60 * time.Second } return &SoraTaskWorker{ - taskService: taskService, - accountRepo: accountRepo, + taskService: taskService, + accountRepo: accountRepo, objectStorage: objectStorage, - mediaStorage: mediaStorage, - interval: interval, - pollTimeout: 30 * time.Second, - stopCh: make(chan struct{}), + mediaStorage: mediaStorage, + interval: interval, + pollTimeout: 30 * time.Second, + stopCh: make(chan struct{}), } } diff --git a/backend/internal/service/token_refresh_service_test.go b/backend/internal/service/token_refresh_service_test.go index bdef0ed747..4b74395033 100644 --- a/backend/internal/service/token_refresh_service_test.go +++ b/backend/internal/service/token_refresh_service_test.go @@ -386,7 +386,7 @@ func TestTokenRefreshService_RefreshWithRetry_ClearsTempUnschedulable(t *testing err := service.refreshWithRetry(context.Background(), account, refresher) require.NoError(t, err) require.Equal(t, 1, repo.updateCalls) - require.Equal(t, 1, repo.clearTempCalls) // DB 清除 + require.Equal(t, 1, repo.clearTempCalls) // DB 清除 require.Equal(t, 1, tempCache.deleteCalls) // Redis 缓存也应清除 } diff --git a/backend/internal/service/user_service_test.go b/backend/internal/service/user_service_test.go index 05fe50560b..7f6c748fa6 100644 --- a/backend/internal/service/user_service_test.go +++ b/backend/internal/service/user_service_test.go @@ -47,8 +47,8 @@ func (m *mockUserRepo) RemoveGroupFromAllowedGroups(context.Context, int64) (int } func (m *mockUserRepo) AddGroupToAllowedGroups(context.Context, int64, int64) error { return nil } func (m *mockUserRepo) UpdateTotpSecret(context.Context, int64, *string) error { return nil } -func (m *mockUserRepo) EnableTotp(context.Context, int64) error { return nil } -func (m *mockUserRepo) DisableTotp(context.Context, int64) error { return nil } +func (m *mockUserRepo) EnableTotp(context.Context, int64) error { return nil } +func (m *mockUserRepo) DisableTotp(context.Context, int64) error { return nil } // --- mock: APIKeyAuthCacheInvalidator ---