test(wave96): 76 unit tests for Job domain model (state machine + lifecycle) #959

Closed
xiaoxia wants to merge 0 commits from test/wave96-job-domain into develop
Owner

变更内容

  • 新增 76 个单元测试,完整覆盖 job.py 领域模型状态机与生命周期
  • 覆盖 JobType/JobStatus 枚举、状态转换、重试机制、进度更新、序列化

测试分布

  • 枚举与常量 (10 tests): JobType + JobStatus + TERMINAL_STATUSES
  • Job.create (17 tests): 字段校验 + 字符串枚举兼容 + strip 处理
  • is_terminal/is_retryable (12 tests): 各状态下属性正确性
  • transition_to 状态机 (16 tests): 所有合法转换 + 非法转换异常 + 时间戳自动设置
  • mark_ 方法 (8 tests)*: running/success/failed/cancelled 便捷方法
  • update_progress (9 tests): 边界值 + 阶段更新 + 时间戳
  • prepare_retry (4 tests): 成功/次数/不可重试场景
  • to_dict (3 tests): 序列化结构 + 不同状态

测试结果

本地 76 passed

## 变更内容 - 新增 76 个单元测试,完整覆盖 job.py 领域模型状态机与生命周期 - 覆盖 JobType/JobStatus 枚举、状态转换、重试机制、进度更新、序列化 ## 测试分布 - **枚举与常量 (10 tests)**: JobType + JobStatus + TERMINAL_STATUSES - **Job.create (17 tests)**: 字段校验 + 字符串枚举兼容 + strip 处理 - **is_terminal/is_retryable (12 tests)**: 各状态下属性正确性 - **transition_to 状态机 (16 tests)**: 所有合法转换 + 非法转换异常 + 时间戳自动设置 - **mark_* 方法 (8 tests)**: running/success/failed/cancelled 便捷方法 - **update_progress (9 tests)**: 边界值 + 阶段更新 + 时间戳 - **prepare_retry (4 tests)**: 成功/次数/不可重试场景 - **to_dict (3 tests)**: 序列化结构 + 不同状态 ## 测试结果 本地 76 passed
xiaoxia force-pushed test/wave96-job-domain from 23acc95d88 to e57ff9f23f 2026-07-26 20:11:46 +08:00 Compare

🚀 预览环境已部署

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

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

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

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

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

📊 审查概览

  • 整体评价:有建议
  • 严重问题数量:0 个
  • 一般建议数量:2 个

需修改的问题(严重)

💡 改进建议(一般)

  1. [packages/domain/media_validation.py: 88-91] 移除无效的代码逻辑

    • 具体内容:在 is_valid_media 函数中,存在一段代码 if codec and codec not in SUPPORTED_VIDEO_CODECS: pass。根据注释说明“调用方负责日志”,此处逻辑实际上不做任何操作。保留一个只包含 pass 的条件判断属于死代码,会降低代码可读性。既然业务逻辑决定“不再做严格的编码拦截”,建议直接删除该 if 判断块,仅保留 return True
  2. [packages/domain/media_validation.py: 77, 80, 95, 96] 增强元数据获取的健壮性

    • 具体内容:代码中使用 int(metadata.get("size_bytes", 0))float(metadata.get("duration", 0)) 进行类型转换。如果 metadata 字典中对应的 key 存在但值为 None(例如上游解析逻辑未正确处理空值),int(None)float(None) 会抛出 TypeError
    • 修改建议:建议使用 or 0 进行兜底,例如:int(metadata.get("size_bytes") or 0),确保在值为 None 或空字符串时也能安全转换为 0。

良好实践

  • 重构清晰:将业务逻辑从 Worker 任务中剥离到 domain 层,符合单一职责原则,便于复用和测试。
  • 类型安全:使用 frozenset 定义 SUPPORTED_VIDEO_CODECS,既保证了性能(O(1) 查找),又防止了运行时被意外修改。
  • 防御性编程safe_parse_fps 函数中对分母为 0 的情况进行了显式检查,避免了除零错误。
  • 测试改进test_agent_docs.py 中使用 Path(__file__).parent.parent.parent 动态计算路径,提高了测试在不同运行环境下的通过率。

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

### 📊 审查概览 - **整体评价**:有建议 - **严重问题数量**:0 个 - **一般建议数量**:2 个 ### ❌ 需修改的问题(严重) 无 ### 💡 改进建议(一般) 1. **[packages/domain/media_validation.py: 88-91] 移除无效的代码逻辑** - **具体内容**:在 `is_valid_media` 函数中,存在一段代码 `if codec and codec not in SUPPORTED_VIDEO_CODECS: pass`。根据注释说明“调用方负责日志”,此处逻辑实际上不做任何操作。保留一个只包含 `pass` 的条件判断属于死代码,会降低代码可读性。既然业务逻辑决定“不再做严格的编码拦截”,建议直接删除该 `if` 判断块,仅保留 `return True`。 2. **[packages/domain/media_validation.py: 77, 80, 95, 96] 增强元数据获取的健壮性** - **具体内容**:代码中使用 `int(metadata.get("size_bytes", 0))` 和 `float(metadata.get("duration", 0))` 进行类型转换。如果 `metadata` 字典中对应的 key 存在但值为 `None`(例如上游解析逻辑未正确处理空值),`int(None)` 或 `float(None)` 会抛出 `TypeError`。 - **修改建议**:建议使用 `or 0` 进行兜底,例如:`int(metadata.get("size_bytes") or 0)`,确保在值为 `None` 或空字符串时也能安全转换为 0。 ### ✅ 良好实践 - **重构清晰**:将业务逻辑从 Worker 任务中剥离到 `domain` 层,符合单一职责原则,便于复用和测试。 - **类型安全**:使用 `frozenset` 定义 `SUPPORTED_VIDEO_CODECS`,既保证了性能(O(1) 查找),又防止了运行时被意外修改。 - **防御性编程**:`safe_parse_fps` 函数中对分母为 0 的情况进行了显式检查,避免了除零错误。 - **测试改进**:`test_agent_docs.py` 中使用 `Path(__file__).parent.parent.parent` 动态计算路径,提高了测试在不同运行环境下的通过率。 --- <sub>🤖 由 AI 代码审查机器人自动生成 | 2026-07-26 17:26:53 | 模型: </sub> <!-- AI_CODE_REVIEW_AUTO_COMMENT -->
xiaoxia force-pushed test/wave96-job-domain from bda1f51c8a to 5289e427e2 2026-07-27 18:58:27 +08:00 Compare
xiaoxia closed this pull request 2026-07-27 19:49:01 +08:00

🗑️ 预览环境已清理

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

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

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