1. 02 Mar, 2026 2 commits
  2. 01 Mar, 2026 1 commit
  3. 28 Feb, 2026 2 commits
    • QTom's avatar
      feat(admin): 完整实现管理员修改用户 API Key 分组的功能 · 9a91815b
      QTom authored
      ## 核心功能
      - 添加 AdminUpdateAPIKeyGroupID 服务方法,支持绑定/解绑/保持不变三态语义
      - 实现 UserRepository.AddGroupToAllowedGroups 接口,自动同步专属分组权限
      - 添加 HTTP PUT /api-keys/:id handler 端点,支持管理员直接修改 API Key 分组
      
      ## 事务一致性
      - 使用 ent Tx 保证专属分组绑定时「添加权限」和「更新 Key」的原子性
      - Repository 方法支持 clientFromContext,兼容事务内调用
      - 事务失败时自动回滚,避免权限孤立
      
      ## 业务逻辑
      - 订阅类型分组阻断,需通过订阅管理流程
      - 非活跃分组拒绝绑定
      - 负 ID 和非法 ID 验证
      - 自动授权响应,告知管理员成功授权的分组
      
      ## 代码质量
      - 16 个单元测试覆盖所有业务路径和边界用例
      - 7 个 handler 集成测试覆盖 HTTP 层
      - GroupRepo stub 返回克隆副本,防止测试间数据泄漏
      - API 类型安全修复(PaginatedResponse<ApiKey>)
      - 前端 ref 回调类型对齐 Vue 规范
      
      ## 国际化支持
      - 中英文提示信息完整
      - 自动授权成功/失败提示
      9a91815b
    • yangjianbo's avatar
      feat(sync): full code sync from release · bb664d9b
      yangjianbo authored
      bb664d9b
  4. 22 Feb, 2026 1 commit
  5. 14 Feb, 2026 3 commits
  6. 13 Feb, 2026 1 commit
    • yangjianbo's avatar
      fix(ops): 修复日志级别过滤并增强OpenAI错误诊断日志 · f96acf6e
      yangjianbo authored
      - 移除 warn 级别下 access info 的强制入库补写,确保运行时日志级别真实生效
      
      - 将 OpenAI fallback matched 与 passthrough 断流提示按需求降级为 info
      
      - 为 codex_cli_only 与 instructions required 场景补充请求诊断字段(含 User-Agent)
      
      - 出于安全考虑移除请求体预览,仅保留 request_body_size 与白名单头信息
      
      - 新增/更新回归测试,覆盖 Forward 入口到日志落库链路
      f96acf6e
  7. 12 Feb, 2026 2 commits
  8. 09 Feb, 2026 1 commit
  9. 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
  10. 07 Feb, 2026 6 commits
    • yangjianbo's avatar
      perf(日志): 降噪优化,将常规成功日志降级为 Debug 级别 · 53e1c8b2
      yangjianbo authored
      
      
      - GIN Logger 中间件跳过 /health 和 /setup/status 的请求日志
      - UsageCleanup 空闲轮询(no_task)日志降级为 slog.Debug
      - Scheduler 常规 rebuild ok 日志降级为 slog.Debug
      - DashboardAggregation 常规聚合完成日志降级为 slog.Debug
      - TokenRefresh 无刷新活动时周期日志降级为 slog.Debug
      
      生产环境(Info 级别)下自动静默,debug 模式下仍可见。
      错误、警告类日志保持原有级别不变。
      Co-Authored-By: default avatarClaude Opus 4.6 <noreply@anthropic.com>
      53e1c8b2
    • 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(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
    • yangjianbo's avatar
      fix(middleware): 管理员JWT增加TokenVersion校验 · 65c0d8b5
      yangjianbo authored
      管理员改密后旧JWT会被拒绝,并补充单元测试覆盖。
      65c0d8b5
    • yangjianbo's avatar
      perf(middleware): 优化订阅模式认证中间件,5次串行调用降至2步同步+1步异步 · 0e514ed8
      yangjianbo authored
      
      
      - 为 GetActiveSubscription 添加 ristretto L1 缓存 + singleflight 防击穿
      - 合并 ValidateSubscription + CheckUsageLimits 为纯内存 ValidateAndCheckLimits
      - 窗口维护操作(激活/重置)异步化,不再阻塞首字节
      - 缓存返回浅拷贝,避免并发 data race 和缓存污染
      - 所有管理操作(分配/续期/撤销/扩展/窗口重置)同步失效 L1 缓存
      - 新增 SubscriptionCacheConfig 可配置 L1 缓存大小/TTL/抖动
      Co-Authored-By: default avatarClaude Opus 4.6 <noreply@anthropic.com>
      0e514ed8
  11. 05 Feb, 2026 1 commit
  12. 04 Feb, 2026 2 commits
  13. 03 Feb, 2026 2 commits
    • bayma888's avatar
      fix(test): add IncrementQuotaUsed to all APIKeyRepository test stubs · e59e3a9f
      bayma888 authored
      Add the missing IncrementQuotaUsed method to:
      - fakeAPIKeyRepo (api_key_auth_google_test.go)
      - stubApiKeyRepo (api_key_auth_test.go)
      - apiKeyRepoStub (api_key_service_delete_test.go)
      - authRepoStub (api_key_service_cache_test.go)
      e59e3a9f
    • bayma888's avatar
      feat(api-key): add independent quota and expiration support · 6146be14
      bayma888 authored
      This feature allows API Keys to have their own quota limits and expiration
      times, independent of the user's balance.
      
      Backend:
      - Add quota, quota_used, expires_at fields to api_key schema
      - Implement IsExpired() and IsQuotaExhausted() checks in middleware
      - Add ResetQuota and ClearExpiration API endpoints
      - Integrate quota billing in gateway handlers (OpenAI, Anthropic, Gemini)
      - Include quota/expiration fields in auth cache for performance
      - Expiration check returns 403, quota exhausted returns 429
      
      Frontend:
      - Add quota and expiration inputs to key create/edit dialog
      - Add quick-select buttons for expiration (+7, +30, +90 days)
      - Add reset quota confirmation dialog
      - Add expires_at column to keys list
      - Add i18n translations for new features (en/zh)
      
      Migration:
      - Add 045_add_api_key_quota.sql for new columns
      6146be14
  14. 02 Feb, 2026 1 commit
  15. 24 Jan, 2026 1 commit
    • shaw's avatar
      feat(subscription): 订阅过期状态自动更新与服务端排序 · b0aa2354
      shaw authored
      - 新增 SubscriptionExpiryService 定时任务,每分钟更新过期订阅状态
      - 订阅列表支持服务端排序(按过期时间、状态、创建时间)
      - 实时显示正确的过期状态,无需等待定时任务
      - 允许对已过期订阅进行续期操作
      - DataTable 组件支持 serverSideSort 模式
      b0aa2354
  16. 16 Jan, 2026 2 commits
  17. 11 Jan, 2026 2 commits
    • IanShaw027's avatar
      fix(lint): 修复所有golangci-lint错误 · 54c5788b
      IanShaw027 authored
      - 修复depguard错误:为ops service文件添加redis导入例外
      - 修复errcheck错误:添加错误检查和类型断言检查
      - 修复gofmt错误:格式化代码
      - 修复ineffassign错误:移除无效的idx++赋值
      - 修复staticcheck错误:合并条件赋值
      - 修复unused错误:移除未使用的字段和函数
        - ops_cleanup_service.go: entryID字段
        - ops_retry.go: status字段
        - ops_upstream_context.go: getOpsUpstreamErrors函数
      54c5788b
    • yangjianbo's avatar
      perf(认证): 引入 API Key 认证缓存与轻量删除查询 · 44a93c19
      yangjianbo authored
      增加 L1/L2 缓存、负缓存与单飞回源
      使用 key+owner 轻量查询替代全量加载并清理旧接口
      补充缓存失效与余额更新测试,修复随机抖动 lint
      
      测试: make test
      44a93c19
  18. 10 Jan, 2026 3 commits
  19. 09 Jan, 2026 6 commits
    • yangjianbo's avatar
      fix(分组): 防止降级环并校验上下文分组 · 2597fe78
      yangjianbo authored
      - 增加降级链路环检测并拦截配置
      
      - 仅复用合法分组上下文并必要时回退查询
      
      - 标注 GetByIDLite 轻量语义并补充测试
      2597fe78
    • IanShaw027's avatar
      feat(运维监控): 增强监控功能和健康评分系统 · 585257d3
      IanShaw027 authored
      后端改进:
      - 新增健康评分计算服务(ops_health_score.go)
      - 添加分布式锁支持(ops_advisory_lock.go)
      - 优化指标采集和聚合逻辑
      - 新增运维指标采集间隔配置(60-3600秒)
      - 移除未使用的WebSocket查询token认证中间件
      - 改进清理服务和告警评估逻辑
      
      前端改进:
      - 简化OpsDashboard组件结构
      - 完善国际化文本(中英文)
      - 新增运维监控相关API类型定义
      - 添加运维指标采集间隔设置界面
      - 优化错误详情模态框
      
      测试:
      - 添加健康评分单元测试
      - 更新API契约测试
      585257d3
    • yangjianbo's avatar
      perf(网关): 复用分组上下文减少热路径查询 · 67554324
      yangjianbo authored
      新增 GetByIDLite 并在网关与 Gemini 选择流程复用上下文 group,避免 COUNT 触发
      更新 API key 中间件注入 group 上下文,减少重复查库
      补充 gateway/gemini 中间件与仓库层回归测试
      
      测试: make test
      67554324
    • Edric.Li's avatar
      feat(api-key): 添加 IP 白名单/黑名单限制功能 (#221) · 0a4641c2
      Edric.Li authored
      * feat(api-key): add IP whitelist/blacklist restriction and usage log IP tracking
      
      - Add IP restriction feature for API keys (whitelist/blacklist with CIDR support)
      - Add IP address logging to usage logs (admin-only visibility)
      - Remove billing_type column from usage logs UI (redundant)
      - Use generic "Access denied" error message for security
      
      Backend:
      - New ip package with IP/CIDR validation and matching utilities
      - Database migrations for ip_whitelist, ip_blacklist (api_keys) and ip_address (usage_logs)
      - Middleware IP restriction check after API key validation
      - Input validation for IP/CIDR patterns on create/update
      
      Frontend:
      - API key form with enable toggle for IP restriction
      - Shield icon indicator in table for keys with IP restriction
      - Removed billing_type filter and column from usage views
      
      * fix: update API contract tests for ip_whitelist/ip_blacklist fields
      
      Add ip_whitelist and ip_blacklist fields to expected JSON responses
      in API contract tests to match the new API key schema.
      0a4641c2
    • Edric Li's avatar
      feat(api-key): add IP whitelist/blacklist restriction and usage log IP tracking · 90798f14
      Edric Li authored
      - Add IP restriction feature for API keys (whitelist/blacklist with CIDR support)
      - Add IP address logging to usage logs (admin-only visibility)
      - Remove billing_type column from usage logs UI (redundant)
      - Use generic "Access denied" error message for security
      
      Backend:
      - New ip package with IP/CIDR validation and matching utilities
      - Database migrations for ip_whitelist, ip_blacklist (api_keys) and ip_address (usage_logs)
      - Middleware IP restriction check after API key validation
      - Input validation for IP/CIDR patterns on create/update
      
      Frontend:
      - API key form with enable toggle for IP restriction
      - Shield icon indicator in table for keys with IP restriction
      - Removed billing_type filter and column from usage views
      90798f14
    • IanShaw027's avatar
      feat(handler): 实现运维监控 API 处理器和中间件 · f3ed95d4
      IanShaw027 authored
      - 新增 ops 错误日志记录器(ops_error_logger.go)
      - 新增 ops 主处理器(ops_handler.go)
      - 新增告警管理处理器(ops_alerts_handler.go)
      - 新增仪表板处理器(ops_dashboard_handler.go)
      - 新增实时监控处理器(ops_realtime_handler.go)
      - 新增配置管理处理器(ops_settings_handler.go)
      - 新增 WebSocket 处理器(ops_ws_handler.go)
      - 扩展设置 DTO 支持 ops 配置
      - 新增客户端请求 ID 中间件(client_request_id.go)
      - 新增 WebSocket 查询令牌认证中间件(ws_query_token_auth.go)
      - 更新管理员认证中间件支持 ops 路由
      - 注册 handler 依赖注入
      f3ed95d4