1. 08 Feb, 2026 1 commit
    • yangjianbo's avatar
      test: 完善自动化测试体系(7个模块,73个任务) · bb5a5dd6
      yangjianbo authored
      
      
      系统性地修复、补充和强化项目的自动化测试能力:
      
      1. 测试基础设施修复
         - 修复 stubConcurrencyCache 缺失方法和构造函数参数不匹配
         - 创建 testutil 共享包(stubs.go, fixtures.go, httptest.go)
         - 为所有 Stub 添加编译期接口断言
      
      2. 中间件测试补充
         - 新增 JWT 认证中间件测试(有效/过期/篡改/缺失 Token)
         - 补充 rate_limiter 和 recovery 中间件测试场景
      
      3. 网关核心路径测试
         - 新增账户选择、等待队列、流式响应、并发控制、计费、Claude Code 检测测试
         - 覆盖负载均衡、粘性会话、SSE 转发、槽位管理等关键逻辑
      
      4. 前端测试体系(11个新测试文件,163个测试用例)
         - Pinia stores: auth, app, subscriptions
         - API client: 请求拦截器、响应拦截器、401 刷新
         - Router guards: 认证重定向、管理员权限、简易模式限制
         - Composables: useForm, useTableLoader, useClipboard
         - Components: LoginForm, ApiKeyCreate, Dashboard
      
      5. CI/CD 流水线重构
         - 重构 backend-ci.yml 为统一的 ci.yml
         - 前后端 4 个并行 Job + Postgres/Redis services
         - Race 检测、覆盖率收集与门禁、Docker 构建验证
      
      6. E2E 自动化测试
         - e2e-test.sh 自动化脚本(Docker 启动→健康检查→测试→清理)
         - 用户注册→登录→API Key→网关调用完整链路测试
         - Mock 模式和 API Key 脱敏支持
      
      7. 修复预存问题
         - tlsfingerprint dialer_test.go 缺失 build tag 导致集成测试编译冲突
      Co-Authored-By: default avatarClaude Opus 4.6 <noreply@anthropic.com>
      bb5a5dd6
  2. 07 Feb, 2026 11 commits
    • yangjianbo's avatar
      test: 为代码审核修复添加详细单元测试(7个测试文件,50+测试用例) · 00caf0bc
      yangjianbo authored
      
      
      新增测试文件:
      - cors_test.go: CORS 条件化头部测试(12个测试,覆盖白名单/黑名单/通配符/凭证/多源/Vary)
      - gateway_helper_backoff_test.go: nextBackoff 退避测试(6个测试+基准,验证指数增长/边界/抖动/收敛)
      - billing_cache_jitter_test.go: jitteredTTL 抖动测试(5个测试+基准,验证范围/上界/方差/均值)
      - subscription_calculate_progress_test.go: calculateProgress 纯函数测试(9个测试,覆盖日/周/月限额/超限截断/过期)
      - openai_gateway_handler_test.go: SSE JSON 转义测试(7个子用例,验证双引号/反斜杠/换行符安全)
      
      更新测试文件:
      - response_transformer_test.go: 增强 generateRandomID 测试(7个测试,含并发/字符集/降级计数器)
      - security_headers_test.go: 适配 GenerateNonce 新签名
      - api_key_auth_test.go: 适配 NewSubscriptionService 新参数
      Co-Authored-By: default avatarClaude Opus 4.6 <noreply@anthropic.com>
      00caf0bc
    • yangjianbo's avatar
      fix: 修复代码审核发现的10个问题(P0安全+P1数据一致性+P2性能优化) · 9634494b
      yangjianbo authored
      
      
      P0: OpenAI SSE 错误消息 JSON 注入 — 使用 json.Marshal 替代 fmt.Sprintf
      P1: subscription 续期包裹 Ent 事务确保原子性
      P1: CSP nonce 生成处理 crypto/rand 错误,失败降级为 unsafe-inline
      P1: singleflight 透传数据库真实错误,不再吞没为 not found
      P1: GetUserSubscriptionsWithProgress 提取 calculateProgress 消除 N+1
      P2: billing_cache/gateway_helper 迁移到 math/rand/v2 消除全局锁争用
      P2: generateRandomID 降级分支增加原子计数器防碰撞
      P2: CORS 非白名单 origin 不再设置 Allow-Headers/Methods/Max-Age
      P2: Turnstile 验证移除 VerifyCode 空值跳过条件防绕过
      P2: Redis Cluster Lua 脚本空 KEYS 添加兼容性警告注释
      Co-Authored-By: default avatarClaude Opus 4.6 <noreply@anthropic.com>
      9634494b
    • yangjianbo's avatar
      fix: 修复批量更新凭证明细与缓存TTL抖动 · 4a20a2a8
      yangjianbo authored
      - BatchUpdateCredentials 返回 success/failed/results 及 success_ids/failed_ids
      
      - billing jitteredTTL 改为只减不增,确保TTL不超上界
      
      - crypto/rand 失败时随机ID降级避免 panic
      
      - OpenAI SelectAccount 失败日志去重并补充字段
      
      - 修复两处类型断言以通过 errcheck
      4a20a2a8
    • yangjianbo's avatar
      fix(audit): 第二批审计修复 — P0 生产 Bug、安全加固、性能优化、缓存一致性、代码质量 · 2588fa6a
      yangjianbo authored
      
      
      基于 backend-code-audit 审计报告,修复剩余 P0/P1/P2 共 34 项问题:
      
      P0 生产 Bug:
      - 修复 time.Since(time.Now()) 计时逻辑错误 (P0-03)
      - generateRandomID 改用 crypto/rand 替代固定索引 (P0-04)
      - IncrementQuotaUsed 重写为 Ent 原子操作消除 TOCTOU 竞态 (P0-05)
      
      安全加固:
      - gateway/openai handler 错误响应替换为泛化消息,防止内部信息泄露 (P1-14)
      - usage_log_repo dateFormat 参数改用白名单映射,防止 SQL 注入 (P1-16)
      - 默认配置安全加固:sslmode=prefer、response_headers=true、mode=release (P1-18/19, P2-15)
      
      性能优化:
      - gateway handler 循环内 defer 替换为显式 releaseWait 闭包 (P1-02)
      - group_repo/promo_code_repo Count 前 Clone 查询避免状态污染 (P1-03)
      - usage_log_repo 四个查询添加 LIMIT 10000 防止 OOM (P1-07)
      - GetBatchUsageStats 添加时间范围参数,默认最近 30 天 (P1-10)
      - ip.go CIDR 预编译为包级变量 (P1-11)
      - BatchUpdateCredentials 重构为先验证后更新 (P1-13)
      
      缓存一致性:
      - billing_cache 添加 jitteredTTL 防止缓存雪崩 (P2-10)
      - DeductUserBalance/UpdateSubscriptionUsage 错误传播修复 (P2-12)
      - UserService.UpdateBalance 成功后异步失效 billingCache (P2-13)
      
      代码质量:
      - search 截断改为按 rune 处理,支持多字节字符 (P2-01)
      - TLS Handshake 改为 HandshakeContext 支持 context 取消 (P2-07)
      - CORS 预检添加 Access-Control-Max-Age: 86400 (P2-16)
      
      测试覆盖:
      - 新增 user_service_test.go(UpdateBalance 缓存失效 6 个用例)
      - 新增 batch_update_credentials_test.go(fail-fast + 类型验证 7 个用例)
      - 新增 response_transformer_test.go、ip_test.go、usage_log_repo_unit_test.go、search_truncate_test.go
      - 集成测试:IncrementQuotaUsed 并发测试、billing_cache 错误传播测试
      - config_test.go 补充 server.mode/sslmode 默认值断言
      Co-Authored-By: default avatarClaude Opus 4.6 <noreply@anthropic.com>
      2588fa6a
    • shaw's avatar
      6aaa4aee
    • yangjianbo's avatar
      fix(security): 修复密码重置链接 Host Header 注入漏洞 (P0-07) · e75d3e35
      yangjianbo authored
      
      
      ForgotPassword 原来从 c.Request.Host 构建重置链接基础 URL,攻击者
      可伪造 Host 头将重置链接指向恶意域名窃取 token。
      
      修复方案:
      - ServerConfig 新增 frontend_url 配置项
      - auth_handler 改为从配置读取前端 URL,未配置时拒绝请求
      - Validate() 校验 frontend_url 必须为绝对 HTTP(S) URL
      - 新增 TestValidateServerFrontendURL 单元测试
      - config.example.yaml 添加配置说明
      Co-Authored-By: default avatarClaude Opus 4.6 <noreply@anthropic.com>
      e75d3e35
    • shaw's avatar
      fix(gateway): harden digest logging and align antigravity ops · 1439eb39
      shaw authored
      - avoid panic by using safe UUID prefix truncation in Gemini digest fallback logs\n- remove unconditional Antigravity 429 full-body debug logs and honor log truncation config\n- align Antigravity quick preset mappings to opus 4.6-thinking targets only\n- restore scope rate-limit aggregation/output in ops availability stats
      1439eb39
    • erio's avatar
      edb09370
    • erio's avatar
      feat(antigravity): comprehensive enhancements - model mapping, rate limiting, scheduling & ops · 5e98445b
      erio authored
      Key changes:
      - Upgrade model mapping: Opus 4.5 → Opus 4.6-thinking with precise matching
      - Unified rate limiting: scope-level → model-level with Redis snapshot sync
      - Load-balanced scheduling by call count with smart retry mechanism
      - Force cache billing support
      - Model identity injection in prompts with leak prevention
      - Thinking mode auto-handling (max_tokens/budget_tokens fix)
      - Frontend: whitelist mode toggle, model mapping validation, status indicators
      - Gemini session fallback with Redis Trie O(L) matching
      - Ops: enhanced concurrency monitoring, account availability, retry logic
      - Migration scripts: 049-051 for model mapping unification
      5e98445b
    • shaw's avatar
    • yangjianbo's avatar
      feat(gateway): 支持强制 Codex CLI 模式并伪装 UA · ce764bf2
      yangjianbo authored
      - Codex CLI 请求仅使用内置 instructions,不再读取 opencode 缓存/回源\n- 新增 gateway.force_codex_cli(环境变量 GATEWAY_FORCE_CODEX_CLI)\n- ForceCodexCLI=true 时转发上游强制 User-Agent=codex_cli_rs/0.0.0\n- 更新 deploy 示例配置
      ce764bf2
  3. 05 Feb, 2026 10 commits
    • shaw's avatar
      feat: 新增全局错误透传规则功能 · 39e05a2d
      shaw authored
      支持管理员配置上游错误如何返回给客户端:
      - 新增 ErrorPassthroughRule 数据模型和 Ent Schema
      - 实现规则的 CRUD API(/admin/error-passthrough-rules)
      - 支持按错误码、关键词匹配,支持 any/all 匹配模式
      - 支持按平台过滤(anthropic/openai/gemini/antigravity)
      - 支持透传或自定义响应状态码和错误消息
      - 实现两级缓存(Redis + 本地内存)和多实例同步
      - 集成到 gateway_handler 的错误处理流程
      - 新增前端管理界面组件
      - 新增单元测试覆盖核心匹配逻辑
      
      优化:
      - 移除 refreshLocalCache 中的冗余排序(数据库已排序)
      - 后端 Validate() 增加匹配条件非空校验
      39e05a2d
    • LLLLLLiulei's avatar
      fix: remove unused listAllAccounts · 029994a8
      LLLLLLiulei authored
      029994a8
    • LLLLLLiulei's avatar
      fix: harden import/export flow · 37047919
      LLLLLLiulei authored
      37047919
    • LLLLLLiulei's avatar
      perf: batch fetch proxies for account export · 0b45d48e
      LLLLLLiulei authored
      0b45d48e
    • LLLLLLiulei's avatar
      feat: refine proxy export and toolbar layout · 0c660f83
      LLLLLLiulei authored
      0c660f83
    • LLLLLLiulei's avatar
      feat: add proxy import flow · ce9a247a
      LLLLLLiulei authored
      ce9a247a
    • LLLLLLiulei's avatar
      feat: add data import/export bundle · b4bd46d0
      LLLLLLiulei authored
      b4bd46d0
    • shaw's avatar
      feat: 支持用户专属分组倍率配置 · 2b192f7d
      shaw authored
      2b192f7d
    • shaw's avatar
      feat(auth): 实现 Refresh Token 机制 · 49a3c437
      shaw authored
      - 新增 Access Token + Refresh Token 双令牌认证
      - 支持 Token 自动刷新和轮转
      - 添加登出和撤销所有会话接口
      - 前端实现无感刷新和主动刷新定时器
      49a3c437
    • JIA-ss's avatar
      feat(gateway): filter /v1/usage stats by API Key instead of UserID · fa3ea5ee
      JIA-ss authored
      
      
      Previously the /v1/usage endpoint aggregated usage stats (today/total
      tokens, cost, RPM/TPM) across all API Keys belonging to the user.
      This made it impossible to distinguish usage from different API Keys
      (e.g. balance vs subscription keys).
      
      Now the usage stats are filtered by the current request's API Key ID,
      so each key only sees its own usage data. The balance/remaining fields
      are unaffected and still reflect the user-level wallet balance.
      
      Changes:
      - Add GetAPIKeyDashboardStats to repository interface and implementation
      - Add getPerformanceStatsByAPIKey helper (also fixes TPM to include
        cache_creation_tokens and cache_read_tokens)
      - Add GetAPIKeyDashboardStats to UsageService
      - Update Usage handler to call GetAPIKeyDashboardStats(apiKey.ID)
      Co-Authored-By: default avatarClaude Opus 4.5 <noreply@anthropic.com>
      fa3ea5ee
  4. 03 Feb, 2026 9 commits
  5. 02 Feb, 2026 9 commits
    • bayma888's avatar
      feat(admin): add user balance/concurrency history modal · 606e29d3
      bayma888 authored
      - Add new API endpoint GET /admin/users/:id/balance-history with pagination and type filter
      - Add SumPositiveBalanceByUser for calculating total recharged amount
      - Create UserBalanceHistoryModal component with:
        - User info header (email, username, created_at, current balance, notes, total recharged)
        - Type filter dropdown (all/balance/admin_balance/concurrency/admin_concurrency/subscription)
        - Quick deposit/withdraw buttons
        - Paginated history list with icons and colored values
      - Add instant tooltip on balance column for better UX
      - Add z-index prop to BaseDialog for modal stacking control
      - Update i18n translations (zh/en)
      606e29d3
    • song's avatar
      chore: apply stashed changes · 3ecadf4a
      song authored
      3ecadf4a
    • song's avatar
      merge upstream main · 0170d19f
      song authored
      0170d19f
    • liuxiongfeng's avatar
      feat(groups): 添加从其他分组复制账号功能 · e1a4a7b8
      liuxiongfeng authored
      - 创建分组时可选择从已有分组复制账号
      - 编辑分组时支持同步账号(全量替换操作)
      - 仅允许选择相同平台的源分组
      - 添加完整的数据校验:去重、自引用检查、平台一致性检查
      - 前端支持多选源分组,带提示说明操作行为
      e1a4a7b8
    • liuxiongfeng's avatar
      feat(billing): 添加 Gemini 200K 长上下文双倍计费功能 · 45e1429a
      liuxiongfeng authored
      - 新增 CalculateCostWithLongContext 方法支持阈值双倍计费
      - 新增 RecordUsageWithLongContext 方法专用于 Gemini 计费
      - Gemini 超过 200K token 的部分按 2 倍费率计算
      - 其他平台(Claude/OpenAI)完全不受影响
      45e1429a
    • Zero Clover's avatar
      feat(ops): 支持过滤无效 API Key 错误,不写入错误日志 · ad1cdba3
      Zero Clover authored
      新增 IgnoreInvalidApiKeyErrors 开关,启用后 INVALID_API_KEY 和
      API_KEY_REQUIRED 错误将被完全跳过,不写入 Ops 错误日志。
      这些错误由用户错误配置导致,与服务质量无关。
      ad1cdba3
    • Zero Clover's avatar
      feat(ops): 将 USER_INACTIVE 错误排除在 SLA 统计之外 · 673caf41
      Zero Clover authored
      将账户停用 (USER_INACTIVE) 导致的请求失败视为业务限制类错误,不计入 SLA 和错误率统计。
      
      账户停用是预期内的业务结果,不应被视为系统错误或服务质量问题。此改动使错误分类更加准确,避免将预期的业务限制误报为系统故障。
      
      修改内容:
      - 在 classifyOpsIsBusinessLimited 函数中添加 USER_INACTIVE 错误码
      - 该类错误不再触发错误率告警
      
      Fixes Wei-Shaw/sub2api#453
      673caf41
    • JIA-ss's avatar
      feat(gateway): 增强 /v1/usage 端点返回完整用量统计 · c441638f
      JIA-ss authored
      
      
      为 CC Switch 集成增强 /v1/usage 网关端点,在保持原有 4 字段
      (isValid, planName, remaining, unit) 向后兼容的基础上,新增:
      
      - usage 对象:今日/累计的请求数、token 用量、费用,以及 RPM/TPM
      - subscription 对象(订阅模式):日/周/月用量和限额、过期时间
      - balance 字段(余额模式):当前钱包余额
      
      用量数据获取采用 best-effort 策略,失败不影响基础响应。
      Co-Authored-By: default avatarClaude Opus 4.5 <noreply@anthropic.com>
      c441638f
    • 小北's avatar
      feat: 向用户显示管理员调整余额的备注 · ae18397c
      小北 authored
      - 为RedeemCode DTO添加notes字段(仅用于admin_balance/admin_concurrency类型)
      - 更新mapper使其有条件地包含备注信息
      - 在用户兑换历史UI中显示备注
      - 备注以斜体显示,悬停时显示完整内容
      
      用户现在可以看到管理员调整其余额的原因说明。
      
      Changes:
      - backend/internal/handler/dto/types.go: RedeemCode添加notes字段
      - backend/internal/handler/dto/mappers.go: 条件性填充notes
      - frontend/src/api/redeem.ts: TypeScript接口添加notes
      - frontend/src/views/user/RedeemView.vue: UI显示备注信息
      ae18397c