test(wave93): 43 unit tests for duplication domain models #956

Closed
xiaoxia wants to merge 0 commits from test/wave93-duplication-domain into develop
Owner

变更内容

  • 新增 43 个单元测试,完整覆盖 duplication 领域模型纯逻辑
  • 覆盖 DuplicateSegment.create 校验(边界值/异常路径)
  • 覆盖 DuplicationRecord.create 校验(空值/空格/负数/唯一ID)
  • 覆盖 mark_processing / mark_completed / mark_failed 状态流转
  • 覆盖 can_retry 状态判断 + reset_for_retry 重置逻辑

测试结果

本地 43 passed

## 变更内容 - 新增 43 个单元测试,完整覆盖 duplication 领域模型纯逻辑 - 覆盖 DuplicateSegment.create 校验(边界值/异常路径) - 覆盖 DuplicationRecord.create 校验(空值/空格/负数/唯一ID) - 覆盖 mark_processing / mark_completed / mark_failed 状态流转 - 覆盖 can_retry 状态判断 + reset_for_retry 重置逻辑 ## 测试结果 本地 43 passed
Collaborator

代码审查结果 - PR #956

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

  1. apps/api/app/services/smart_asset_selector.py 第48-51行__init__ 方法默认参数使用了硬编码的魔法数字(30.0, 1920, 1080),而文件顶部已经从 packages.domain.asset_scoring 导入了对应的常量(_MIN_QUALITY_SCORE, _TARGET_WIDTH 等)。

    • 后果:导致顶部导入的常量成为死代码。如果 asset_scoring.py 中的配置常量更新,SmartAssetSelector 的默认行为不会同步,造成配置不一致的隐患。
    • 建议:将默认参数修改为使用导入的常量,例如 min_quality_score: float = _MIN_QUALITY_SCORE
  2. packages/domain/asset_scoring.py 第102行score_resolution 函数中存在除零风险。

    • 后果:代码中计算 ratio = actual_pixels / target_pixels,虽然函数有默认参数,但如果调用方显式传入 target_width=0target_height=0,将触发 ZeroDivisionError 导致程序崩溃。作为被抽离的纯逻辑层,应对无效输入做防御性检查。
    • 建议:在函数开头增加参数校验,若 target_width <= 0target_height <= 0,应抛出 ValueError 或返回安全的默认评分(如 0.0)。

💡 建议(1个可选)

  1. apps/api/app/services/smart_asset_selector.py:向后兼容方法(_score_resolution, _score_duration, _score_bitrate)内部使用了局部导入(from packages.domain.asset_scoring import ...)。
    • 说明:虽然 Python 模块机制会缓存导入,不会造成严重的性能损耗,但在函数内部进行导入不符合 Python 最佳实践(PEP 8),且降低了代码可读性。建议将这些依赖移至文件顶部统一导入。

良好实践

  • 逻辑抽离:成功将复杂的评分和选择逻辑从服务层抽离到领域层(packages.domain),降低了耦合度,便于单独测试和维护。
  • 测试路径修复tests/unit/test_agent_docs.py 中使用 Path(__file__).parent.parent.parent 构建路径,比相对路径更健壮,避免了因运行目录不同导致的测试失败。

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


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

## 代码审查结果 - PR #956 ### ⚠️ 问题(2个需要修改) 1. **apps/api/app/services/smart_asset_selector.py 第48-51行**:`__init__` 方法默认参数使用了硬编码的魔法数字(`30.0`, `1920`, `1080`),而文件顶部已经从 `packages.domain.asset_scoring` 导入了对应的常量(`_MIN_QUALITY_SCORE`, `_TARGET_WIDTH` 等)。 - **后果**:导致顶部导入的常量成为死代码。如果 `asset_scoring.py` 中的配置常量更新,`SmartAssetSelector` 的默认行为不会同步,造成配置不一致的隐患。 - **建议**:将默认参数修改为使用导入的常量,例如 `min_quality_score: float = _MIN_QUALITY_SCORE`。 2. **packages/domain/asset_scoring.py 第102行**:`score_resolution` 函数中存在除零风险。 - **后果**:代码中计算 `ratio =` `actual_pixels / target_pixels`,虽然函数有默认参数,但如果调用方显式传入 `target_width=0` 或 `target_height=0`,将触发 `ZeroDivisionError` 导致程序崩溃。作为被抽离的纯逻辑层,应对无效输入做防御性检查。 - **建议**:在函数开头增加参数校验,若 `target_width <= 0` 或 `target_height <= 0`,应抛出 `ValueError` 或返回安全的默认评分(如 0.0)。 ### 💡 建议(1个可选) 1. **apps/api/app/services/smart_asset_selector.py**:向后兼容方法(`_score_resolution`, `_score_duration`, `_score_bitrate`)内部使用了局部导入(`from packages.domain.asset_scoring import ...`)。 - **说明**:虽然 Python 模块机制会缓存导入,不会造成严重的性能损耗,但在函数内部进行导入不符合 Python 最佳实践(PEP 8),且降低了代码可读性。建议将这些依赖移至文件顶部统一导入。 ### ✅ 良好实践 - **逻辑抽离**:成功将复杂的评分和选择逻辑从服务层抽离到领域层(`packages.domain`),降低了耦合度,便于单独测试和维护。 - **测试路径修复**:`tests/unit/test_agent_docs.py` 中使用 `Path(__file__).parent.parent.parent` 构建路径,比相对路径更健壮,避免了因运行目录不同导致的测试失败。 --- ✅ 格式检查通过 | ❌ 逻辑审查需修改 | ✅ 性能无问题 --- <sub>🤖 由 AI 代码审查机器人自动生成 | 2026-07-26 17:16:11 | 模型: </sub> <!-- AI_CODE_REVIEW_AUTO_COMMENT -->
xiaoxia force-pushed test/wave93-duplication-domain from 5ee69a0046 to 5289e427e2 2026-07-27 18:53:56 +08:00 Compare
xiaoxia closed this pull request 2026-07-27 19:48:59 +08:00

🚀 预览环境已部署

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

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

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

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

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

🗑️ 预览环境已清理

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

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

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