test(wave97): 53 unit tests for quota domain system #960

Closed
xiaoxia wants to merge 0 commits from test/wave97-quota-domain into develop
Owner

变更内容

  • 新增 53 个单元测试,完整覆盖 quota.py 配额系统纯逻辑
  • 覆盖配额维度枚举、套餐等级、配额检查器、告警级别、注册表模式

测试分布

  • QuotaDimension (3 tests): 核心维度 + 扩展维度 + 类型验证
  • QuotaTier (6 tests): get_limit / is_unlimited / 边界情况
  • QUOTA_TIERS (4 tests): 三套餐数值校验 + 单调性验证
  • QuotaCheckResult (6 tests): usage_percent 各种边界(零/超限/不限量)
  • QuotaRegistry (9 tests): 初始化 + 注册新维度 + 幂等 + 部分设置
  • QuotaChecker (18 tests): 配额检查 + 批量检查 + 4 级告警阈值边界
  • 便捷函数 + 单例 (6 tests): get_warning_level + 全局实例

测试结果

本地 53 passed

## 变更内容 - 新增 53 个单元测试,完整覆盖 quota.py 配额系统纯逻辑 - 覆盖配额维度枚举、套餐等级、配额检查器、告警级别、注册表模式 ## 测试分布 - **QuotaDimension (3 tests)**: 核心维度 + 扩展维度 + 类型验证 - **QuotaTier (6 tests)**: get_limit / is_unlimited / 边界情况 - **QUOTA_TIERS (4 tests)**: 三套餐数值校验 + 单调性验证 - **QuotaCheckResult (6 tests)**: usage_percent 各种边界(零/超限/不限量) - **QuotaRegistry (9 tests)**: 初始化 + 注册新维度 + 幂等 + 部分设置 - **QuotaChecker (18 tests)**: 配额检查 + 批量检查 + 4 级告警阈值边界 - **便捷函数 + 单例 (6 tests)**: get_warning_level + 全局实例 ## 测试结果 本地 53 passed
xiaoxia force-pushed test/wave97-quota-domain from a58bc773fd to d984d53c07 2026-07-26 20:11:59 +08:00 Compare

🚀 预览环境已部署

项目 详情
PR号 #960
预览链接 https://pr-960.preview.xiaoxiajianji.com
API环境 staging

💡 预览环境使用 staging API 数据,请勿在预览环境中操作重要数据。

🔄 每次提交新代码后预览环境会自动更新。

🗑️ PR 关闭或合并后,预览环境会自动清理。

🚀 **预览环境已部署** | 项目 | 详情 | |------|------| | PR号 | #960 | | 预览链接 | [https://pr-960.preview.xiaoxiajianji.com](https://pr-960.preview.xiaoxiajianji.com) | | API环境 | staging | > 💡 预览环境使用 staging API 数据,请勿在预览环境中操作重要数据。 > > 🔄 每次提交新代码后预览环境会自动更新。 > > 🗑️ PR 关闭或合并后,预览环境会自动清理。
Collaborator

代码审查结果 - PR #960

⚠️ 问题(2个需要修改)

  1. packages/domain/media_validation.py 第68行safe_parse_fps 函数在输入为 None 或非字符串时会抛出 TypeError

    • 原因:代码中 if "/" in fps_str: 会直接调用 __contains__ 方法。如果 fps_strNone(这在元数据缺失时很常见),Python 会抛出 TypeError: argument of type 'NoneType' is not iterable。当前的 try...except 只捕获了 ValueErrorZeroDivisionError,无法捕获此错误。
    • 后果:当处理缺少帧率信息的媒体文件时,Worker 任务会意外崩溃,而不是返回默认值 0.0。
    • 修改建议:在函数开头增加类型检查,或捕获 TypeError。例如:if not isinstance(fps_str, str): return 0.0
  2. packages/domain/media_validation.py 第102行:移除了对非白名单视频编码的日志记录,导致可观测性降低。

    • 原因:原代码在 ingest.py 中检测到非白名单编码时会记录 logger.info,这对于排查转码问题非常有用。重构时代码被移动到 media_validation.py,虽然注释说“调用方负责日志”,但实际调用方 ingest.py 中并未补充相应的日志逻辑。
    • 后果:系统将不再记录非标准编码格式的媒体摄入情况,增加了后续排查渲染转码问题的难度。
    • 修改建议:在 media_validation.py 中引入 logger 并恢复日志记录,或者确保 ingest.py 中调用该函数后补充了日志判断逻辑。

💡 建议(1个可选)

  1. packages/domain/media_validation.py 第88行is_valid_media 中对 metadata 字典值的类型转换缺乏容错性。
    • 具体内容:代码直接使用 int(metadata.get("size_bytes", 0)),如果元数据中 size_bytes 的值是 None 或无法转换的字符串,会抛出异常。建议使用辅助函数或更安全的转换方式(如 try-except 包裹)来处理可能存在的脏数据。

格式检查通过 | 逻辑审查需修改 | 性能无明显问题


🤖 由 AI 代码审查机器人自动生成 | 2026-07-26 17:32:58 | 模型:

## 代码审查结果 - PR #960 ### ⚠️ 问题(2个需要修改) 1. **packages/domain/media_validation.py 第68行**:`safe_parse_fps` 函数在输入为 `None` 或非字符串时会抛出 `TypeError`。 - **原因**:代码中 `if "/" in fps_str:` 会直接调用 `__contains__` 方法。如果 `fps_str` 为 `None`(这在元数据缺失时很常见),Python 会抛出 `TypeError: argument of type 'NoneType' is not iterable`。当前的 `try...except` 只捕获了 `ValueError` 和 `ZeroDivisionError`,无法捕获此错误。 - **后果**:当处理缺少帧率信息的媒体文件时,Worker 任务会意外崩溃,而不是返回默认值 0.0。 - **修改建议**:在函数开头增加类型检查,或捕获 `TypeError`。例如:`if not isinstance(fps_str, str): return 0.0`。 2. **packages/domain/media_validation.py 第102行**:移除了对非白名单视频编码的日志记录,导致可观测性降低。 - **原因**:原代码在 `ingest.py` 中检测到非白名单编码时会记录 `logger.info`,这对于排查转码问题非常有用。重构时代码被移动到 `media_validation.py`,虽然注释说“调用方负责日志”,但实际调用方 `ingest.py` 中并未补充相应的日志逻辑。 - **后果**:系统将不再记录非标准编码格式的媒体摄入情况,增加了后续排查渲染转码问题的难度。 - **修改建议**:在 `media_validation.py` 中引入 logger 并恢复日志记录,或者确保 `ingest.py` 中调用该函数后补充了日志判断逻辑。 ### 💡 建议(1个可选) 1. **packages/domain/media_validation.py 第88行**:`is_valid_media` 中对 `metadata` 字典值的类型转换缺乏容错性。 - **具体内容**:代码直接使用 `int(metadata.get("size_bytes", 0))`,如果元数据中 `size_bytes` 的值是 `None` 或无法转换的字符串,会抛出异常。建议使用辅助函数或更安全的转换方式(如 `try-except` 包裹)来处理可能存在的脏数据。 --- ✅ 格式检查通过 | ❌ 逻辑审查需修改 | ✅ 性能无明显问题 --- <sub>🤖 由 AI 代码审查机器人自动生成 | 2026-07-26 17:32:58 | 模型: </sub> <!-- AI_CODE_REVIEW_AUTO_COMMENT -->
xiaoxia force-pushed test/wave97-quota-domain from 119f9e8dea to 5289e427e2 2026-07-27 18:59:42 +08:00 Compare
xiaoxia closed this pull request 2026-07-27 19:49:02 +08:00

🗑️ 预览环境已清理

PR #960 已关闭或合并,对应的预览环境已被清理。

如有需要,可以重新打开 PR 来重新生成预览环境。

🗑️ **预览环境已清理** PR #960 已关闭或合并,对应的预览环境已被清理。 > 如有需要,可以重新打开 PR 来重新生成预览环境。
Some checks are pending
CI/CD Pipeline / Check if frontend-only change (push) Has been cancelled
CI/CD Pipeline / Validate - Code Quality (push) Has been cancelled
CI/CD Pipeline / Validate - Type Check (mypy) (push) Has been cancelled
CI/CD Pipeline / Validate - Migration (alembic) (push) Has been cancelled
CI/CD Pipeline / Unit Tests (push) Has been cancelled
CI/CD Pipeline / Integration Tests (push) Has been cancelled
CI/CD Pipeline / Frontend Lint (push) Has been cancelled
CI/CD Pipeline / Frontend Unit Tests (push) Has been cancelled
CI/CD Pipeline / PR Build API Image (push) Has been cancelled
CI/CD Pipeline / PR Build Web Image (push) Has been cancelled
CI/CD Pipeline / PR Build Worker Image (push) Has been cancelled
CI/CD Pipeline / Build Staging API Image (push) Has been cancelled
CI/CD Pipeline / Build Staging Web Image (push) Has been cancelled
CI/CD Pipeline / Build Staging Worker Image (push) Has been cancelled
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (push) Has been cancelled
CI/CD Pipeline / Staging E2E Tests (push) Has been cancelled
CI/CD Pipeline / Staging API Integration Tests (push) Has been cancelled
CI/CD Pipeline / Build Production API Image (push) Has been cancelled
CI/CD Pipeline / Build Production Web Image (push) Has been cancelled
CI/CD Pipeline / Build Production Worker Image (push) Has been cancelled
CI/CD Pipeline / Deploy Production (push) Has been cancelled
CI/CD Pipeline / Production Browser E2E (push) Has been cancelled
CI/CD Pipeline / ACR Image Cleanup (push) Has been cancelled
CI/CD Pipeline / Canary Release to Production (push) Has been cancelled
CI/CD Pipeline / CI Gate (push) Has been cancelled
AI Code Review / AI Code Review (pull_request) Failing after 0s
PR Automation / Auto Approve on CI Green (pull_request) Failing after 0s
PR Automation / Auto Merge on CI Green + Approved (pull_request) Failing after 0s
ACR Cleanup / ACR Image Cleanup (pull_request_target) Failing after 0s
Preview Deploy / Deploy Preview Environment (pull_request) Successful in 1m33s
Preview Cleanup / Cleanup Preview Environment (pull_request) Successful in 48s
CI/CD Pipeline / Production Browser E2E (pull_request) Has been skipped
CI/CD Pipeline / Check if frontend-only change (pull_request) Failing after 1s
CI/CD Pipeline / Validate - Code Quality (pull_request) Failing after 0s
CI/CD Pipeline / Validate - Type Check (mypy) (pull_request) Failing after 1s
CI/CD Pipeline / Validate - Migration (alembic) (pull_request) Failing after 0s
CI/CD Pipeline / Unit Tests (pull_request) Failing after 0s
CI/CD Pipeline / Integration Tests (pull_request) Failing after 0s
CI/CD Pipeline / Frontend Lint (pull_request) Failing after 0s
CI/CD Pipeline / Frontend Unit Tests (pull_request) Failing after 0s
CI/CD Pipeline / PR Build API Image (pull_request) Successful in 10m44s
CI/CD Pipeline / PR Build Web Image (pull_request) Successful in 1m58s
CI/CD Pipeline / PR Build Worker Image (pull_request) Successful in 1m54s
CI/CD Pipeline / Build Staging API Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Web Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Worker Image (pull_request) Has been skipped
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Has been skipped
CI/CD Pipeline / Staging E2E Tests (pull_request) Has been skipped
CI/CD Pipeline / Staging API Integration Tests (pull_request) Has been skipped
CI/CD Pipeline / Build Production API Image (pull_request) Has been skipped
CI/CD Pipeline / Build Production Web Image (pull_request) Has been skipped
CI/CD Pipeline / Build Production Worker Image (pull_request) Has been skipped
CI/CD Pipeline / Deploy Production (pull_request) Has been skipped
CI/CD Pipeline / ACR Image Cleanup (pull_request) Has been skipped
CI/CD Pipeline / Canary Release to Production (pull_request) Has been cancelled
CI/CD Pipeline / CI Gate (pull_request) Failing after 0s

Pull request closed

Sign in to join this conversation.