test(wave95): 82 unit tests for domain entities #958

Closed
xiaoxia wants to merge 0 commits from test/wave95-domain-entities into develop
Owner

变更内容

  • 新增 82 个单元测试,完整覆盖 domain/entities.py 所有业务逻辑
  • 覆盖 Project / AssetLibrary / AssetStatus / Asset / IngestJob / User 6 个实体

测试分布

  • Project (13 tests): create 校验 + 名称清理 + 权限判断(is_owner / is_shared_with / can_access)
  • AssetLibrary (6 tests): create 校验 + 3 种素材库类型
  • AssetStatus (26 tests): 枚举值 + missing 向后兼容(uploaded/success/fail/err 等 20+ 别名映射)
  • Asset (23 tests): create 校验 + file_type 属性 + 标签增删去重幂等
  • IngestJob (11 tests): create 校验 + 字段 strip
  • User (3 tests): 默认值 + 管理员 + 订阅

测试结果

本地 82 passed

## 变更内容 - 新增 82 个单元测试,完整覆盖 domain/entities.py 所有业务逻辑 - 覆盖 Project / AssetLibrary / AssetStatus / Asset / IngestJob / User 6 个实体 ## 测试分布 - **Project (13 tests)**: create 校验 + 名称清理 + 权限判断(is_owner / is_shared_with / can_access) - **AssetLibrary (6 tests)**: create 校验 + 3 种素材库类型 - **AssetStatus (26 tests)**: 枚举值 + _missing_ 向后兼容(uploaded/success/fail/err 等 20+ 别名映射) - **Asset (23 tests)**: create 校验 + file_type 属性 + 标签增删去重幂等 - **IngestJob (11 tests)**: create 校验 + 字段 strip - **User (3 tests)**: 默认值 + 管理员 + 订阅 ## 测试结果 本地 82 passed
xiaoxia force-pushed test/wave95-domain-entities from e31e9c2883 to 0482e62c59 2026-07-26 20:11:29 +08:00 Compare

🚀 预览环境已部署

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

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

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

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

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

代码审查结果 - PR #958

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

  1. packages/domain/media_validation.py 第107行:丢失了非白名单视频编码的日志记录,导致可观测性下降。
    • 原代码在检测到非白名单编码时会记录 logger.info,便于排查问题。新代码虽然注释提到“调用方负责日志”,但实际调用方 ingest.py 只是调用了 _is_valid_media,并未进行额外的编解码器检查,导致该日志信息彻底丢失。
  2. packages/domain/media_validation.py 第75行safe_parse_fps 函数未处理 NaNInfinity 边界情况。
    • 当输入字符串为 "nan""inf" 等特殊值时,Python 的 float() 转换不会抛出 ValueError,而是返回 naninf。这会导致后续计算(如 duration * fps)产生错误结果或异常,而当前的 try-except 块无法捕获这种情况。

💡 建议(1个可选)

  1. packages/domain/media_validation.py 第93-105行is_valid_media 函数对元数据值的类型转换缺乏容错性。
    • 代码直接使用 int()float() 强转 metadata 中的值。如果上游 ffprobe 返回的数据格式异常(如字符串 "N/A"),会导致 ValueError 崩溃。建议增加类型检查或使用辅助函数进行安全转换,确保领域模块的健壮性。

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


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

## 代码审查结果 - PR #958 ### ⚠️ 问题(2个需要修改) 1. **packages/domain/media_validation.py 第107行**:丢失了非白名单视频编码的日志记录,导致可观测性下降。 - 原代码在检测到非白名单编码时会记录 `logger.info`,便于排查问题。新代码虽然注释提到“调用方负责日志”,但实际调用方 `ingest.py` 只是调用了 `_is_valid_media`,并未进行额外的编解码器检查,导致该日志信息彻底丢失。 2. **packages/domain/media_validation.py 第75行**:`safe_parse_fps` 函数未处理 `NaN` 和 `Infinity` 边界情况。 - 当输入字符串为 `"nan"`、`"inf"` 等特殊值时,Python 的 `float()` 转换不会抛出 `ValueError`,而是返回 `nan` 或 `inf`。这会导致后续计算(如 `duration * fps`)产生错误结果或异常,而当前的 `try-except` 块无法捕获这种情况。 ### 💡 建议(1个可选) 1. **packages/domain/media_validation.py 第93-105行**:`is_valid_media` 函数对元数据值的类型转换缺乏容错性。 - 代码直接使用 `int()` 和 `float()` 强转 `metadata` 中的值。如果上游 `ffprobe` 返回的数据格式异常(如字符串 `"N/A"`),会导致 `ValueError` 崩溃。建议增加类型检查或使用辅助函数进行安全转换,确保领域模块的健壮性。 --- ✅ 格式检查通过 | ❌ 逻辑审查需修改 | ✅ 性能无明显问题 --- <sub>🤖 由 AI 代码审查机器人自动生成 | 2026-07-26 17:23:06 | 模型: </sub> <!-- AI_CODE_REVIEW_AUTO_COMMENT -->
xiaoxia force-pushed test/wave95-domain-entities from d619204d87 to 5289e427e2 2026-07-27 18:57:12 +08:00 Compare
xiaoxia closed this pull request 2026-07-27 19:49:01 +08:00

🗑️ 预览环境已清理

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

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

🗑️ **预览环境已清理** PR #958 已关闭或合并,对应的预览环境已被清理。 > 如有需要,可以重新打开 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.