Files
huang 1da680a790
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 5m18s
重构: 店铺套餐分配系统从加价模式改为返佣模式
主要变更:
- 重构分配模型:从加价模式(pricing_mode/pricing_value)改为返佣模式(base_commission + tier_commission)
- 删除独立的 my_package 接口,统一到 /api/admin/packages(通过数据权限自动过滤)
- 新增批量分配和批量调价功能,支持事务和性能优化
- 新增配置版本管理,订单创建时锁定返佣配置
- 新增成本价历史记录,支持审计和纠纷处理
- 新增统计缓存系统(Redis + 异步任务),优化梯度返佣计算性能
- 删除冗余的梯度佣金独立 CRUD 接口(合并到分配配置中)
- 归档 3 个已完成的 OpenSpec changes 并同步 8 个新 capabilities 到 main specs

技术细节:
- 数据库迁移:000026_refactor_shop_package_allocation
- 新增 Store:AllocationConfigStore, PriceHistoryStore, CommissionStatsStore
- 新增 Service:BatchAllocationService, BatchPricingService, CommissionStatsService
- 新增异步任务:统计更新、定时同步、周期归档
- 测试覆盖:批量操作集成测试、梯度佣金 CRUD 清理验证

影响:
- API 变更:删除 4 个梯度 CRUD 接口(POST/GET/PUT/DELETE /:id/tiers)
- API 新增:批量分配、批量调价接口
- 数据模型:重构 shop_series_allocation 表结构
- 性能优化:批量操作使用 CreateInBatches,统计使用 Redis 缓存

相关文档:
- openspec/changes/archive/2026-01-28-refactor-shop-package-allocation/
- openspec/specs/agent-available-packages/
- openspec/specs/allocation-config-versioning/
- 等 8 个新 capability specs
2026-01-28 17:11:55 +08:00

3.1 KiB
Raw Permalink Blame History

测试基础设施统一 - 任务清单

1. 增强 testutils 包

  • 1.1 创建 IntegrationTestEnv 结构体,封装集成测试所需的所有依赖
  • 1.2 实现 NewIntegrationTestEnv(t) 函数自动创建事务、Redis、Logger、TokenManager、App
  • 1.3 添加 AsSuperAdmin() 方法,返回带超级管理员 Token 的请求
  • 1.4 添加 AsUser(account) 方法,支持指定用户身份的请求
  • 1.5 确保 db.go 中的 AutoMigrate 包含所有业务模型

2. 重构 testcontainers 测试7 个文件)

  • 2.1 重构 role_test.go - 移除 testcontainers使用 IntegrationTestEnv
  • 2.2 重构 permission_test.go - 移除 testcontainers使用 IntegrationTestEnv
  • 2.3 重构 account_test.go - 已使用 IntegrationTestEnv无 testcontainers
  • 2.4 重构 account_role_test.go - 已使用 IntegrationTestEnv无 testcontainers
  • 2.5 重构 role_permission_test.go - 已使用 IntegrationTestEnv无 testcontainers
  • 2.6 重构 api_regression_test.go - 已使用 IntegrationTestEnv无 testcontainers
  • 2.7 删除 migration_test.go 中无意义的测试 - 项目使用独立迁移工具,保留 NoForeignKeys 检查

3. 重构 DELETE 清理测试8 个文件)

  • 3.1 重构 shop_management_test.go - 已使用事务隔离,无 DELETE 清理
  • 3.2 重构 shop_account_management_test.go - 已使用事务隔离,无 DELETE 清理
  • 3.3 重构 carrier_test.go - 已使用事务隔离,无 DELETE 清理
  • 3.4 重构 package_test.go - 已使用事务隔离,无 DELETE 清理
  • 3.5 重构 device_test.go - 已使用事务隔离,无 DELETE 清理
  • 3.6 重构 iot_card_test.go - 已使用事务隔离,无 DELETE 清理
  • 3.7 重构 authorization_test.go - 已使用事务隔离,无 DELETE 清理
  • 3.8 重构 standalone_card_allocation_test.go - 已使用事务隔离,无 DELETE 清理

4. 清理和验证

  • 4.1 删除无意义的测试(删除 health_test.go 的 4 个测试migration_test.go 的 2 个跳过测试)
  • 4.2 修复剩余跳过的测试
    • 修复 TestDevice_Delete - 移除 Skip测试正常通过
    • 修复 TestDeviceImport_TaskList - 修正路由路径 /import/tasks
    • 修复 TestLoggerMiddlewareWithUserID - 将 user_id 改为 uint 类型
    • 更新 TestIotCard_ImportTestIotCard_ImportE2E 的 Skip 说明E2E 测试需要 Worker 服务)
  • 4.3 移除 go.mod 中的 testcontainers 相关依赖 - testcontainers 是 gofiber/storage 的间接依赖,无法移除
  • 4.4 运行 go mod tidy 清理未使用的依赖
  • 4.5 运行全量集成测试:138 PASS, 3 SKIP, 0 FAIL
    • SKIP 测试(符合预期):
      • TestIotCard_Import - E2E 测试需要 Worker 服务
      • TestIotCard_ImportE2E - E2E 测试需要 Worker 服务
      • TestShopAccount_DeleteShopDisablesAccounts - 功能未实现
  • 4.6 更新 docs/testing/test-connection-guide.md,添加 IntegrationTestEnv 使用说明

5. 规范文档更新

  • 5.1 将测试规范更新到项目规范文档中AGENTS.md