test(shared): wave198 ai_service 单测 +41 #1164

Merged
xiaoxia merged 2 commits from test/wave198-shared-ai-service into develop 2026-07-30 00:25:25 +08:00
Owner

变更说明

  • 为 shared.ai_service 添加 41 个单元测试(纯逻辑部分)

覆盖内容

  1. _parse_recommend_response (27测)

    • 基础解析:空输入/无效JSON/非dict
    • clips处理:空列表/非列表/排序/重编号/跳过非法条目
    • 字段校验:duration钳制(1~30)/start_time钳制/asset_id白名单/默认值
    • Markdown代码块JSON解析
    • confidence钳制(0~1)及默认值
    • config深拷贝/title设置
    • total_duration计算
  2. _fallback_recommend_clips (10测)

    • 结构完整性、intro/outro存在性
    • showcase数量匹配素材数、无素材降级
    • 素材分配、confidence范围、title格式、顺序连续
  3. _call_ai_cover_service (4测)

    • upload/manual/ai_frame/ai_regenerate 四种类型
    • frame_time 范围校验

测试统计

  • 新增测试:41
  • 全部通过
## 变更说明 - 为 shared.ai_service 添加 41 个单元测试(纯逻辑部分) ### 覆盖内容 1. **_parse_recommend_response** (27测) - 基础解析:空输入/无效JSON/非dict - clips处理:空列表/非列表/排序/重编号/跳过非法条目 - 字段校验:duration钳制(1~30)/start_time钳制/asset_id白名单/默认值 - Markdown代码块JSON解析 - confidence钳制(0~1)及默认值 - config深拷贝/title设置 - total_duration计算 2. **_fallback_recommend_clips** (10测) - 结构完整性、intro/outro存在性 - showcase数量匹配素材数、无素材降级 - 素材分配、confidence范围、title格式、顺序连续 3. **_call_ai_cover_service** (4测) - upload/manual/ai_frame/ai_regenerate 四种类型 - frame_time 范围校验 ## 测试统计 - 新增测试:41 - 全部通过 ✅
xiaoxia added 1 commit 2026-07-29 22:05:59 +08:00
test(shared): add wave198 ai_service unit tests (+41)
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 12s
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 / Validate - Migration (alembic) (pull_request) Successful in 1m55s
CI/CD Pipeline / Validate - Type Check (mypy) (pull_request) Successful in 1m58s
CI/CD Pipeline / Validate - Code Quality (pull_request) Has been cancelled
CI/CD Pipeline / Unit Tests (pull_request) Has been cancelled
CI/CD Pipeline / Integration Tests (pull_request) Has been cancelled
CI/CD Pipeline / Frontend Lint (pull_request) Has been cancelled
CI/CD Pipeline / Frontend Unit Tests (pull_request) Has been cancelled
CI/CD Pipeline / PR Build API Image (pull_request) Has been cancelled
CI/CD Pipeline / PR Build Web Image (pull_request) Has been cancelled
CI/CD Pipeline / PR Build Worker Image (pull_request) Has been cancelled
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Has been cancelled
CI/CD Pipeline / Staging E2E Tests (pull_request) Has been cancelled
CI/CD Pipeline / Staging API Integration Tests (pull_request) Has been cancelled
CI/CD Pipeline / Build Production API Image (pull_request) Has been cancelled
CI/CD Pipeline / Build Production Web Image (pull_request) Has been cancelled
CI/CD Pipeline / Build Production Worker Image (pull_request) Has been cancelled
CI/CD Pipeline / Deploy Production (pull_request) Has been cancelled
CI/CD Pipeline / Production Browser E2E (pull_request) Has been cancelled
CI/CD Pipeline / ACR Image Cleanup (pull_request) Has been cancelled
CI/CD Pipeline / Canary Release to Production (pull_request) Has been cancelled
CI/CD Pipeline / CI Gate (pull_request) Has been cancelled
AI Code Review / AI Code Review (pull_request) Has been cancelled
PR Automation / Auto Approve on CI Green (pull_request) Has been cancelled
PR Automation / Auto Merge on CI Green + Approved (pull_request) Has been cancelled
Preview Deploy / Deploy Preview Environment (pull_request) Has been cancelled
cb85b33ee9
Add comprehensive unit tests for shared.ai_service pure logic:
- _parse_recommend_response (27 tests): basic parsing, clips handling,
  field validation/boundaries, markdown code blocks, confidence clamping,
  config deep copy, total duration calculation
- _fallback_recommend_clips (10 tests): structure, intro/outro,
  showcase count, no assets, asset assignment, title/duration/order
- _call_ai_cover_service (4 tests): upload/manual/ai_frame types,
  frame_time range validation
auto-approve-bot added 1 commit 2026-07-29 22:15:15 +08:00
style: auto-format with black + isort + prettier [skip ci-format-check]
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 46s
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 / Validate - Type Check (mypy) (pull_request) Successful in 1m44s
CI/CD Pipeline / Validate - Migration (alembic) (pull_request) Successful in 1m46s
CI/CD Pipeline / Frontend Lint (pull_request) Has been skipped
CI/CD Pipeline / Frontend Unit Tests (pull_request) Has been skipped
CI/CD Pipeline / PR Build Web Image (pull_request) Has been skipped
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Has been skipped
Preview Deploy / Deploy Preview Environment (pull_request) Successful in 47s
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 / ACR Image Cleanup (pull_request) Has been skipped
PR Automation / Auto Merge on CI Green + Approved (pull_request) Successful in 1m14s
CI/CD Pipeline / PR Build API Image (pull_request) Successful in 2m16s
CI/CD Pipeline / PR Build Worker Image (pull_request) Successful in 2m17s
PR Automation / Auto Approve on CI Green (pull_request) Successful in 3m29s
AI Code Review / AI Code Review (pull_request) Successful in 3m57s
CI/CD Pipeline / Validate - Code Quality (pull_request) Successful in 6m2s
CI/CD Pipeline / Unit Tests (pull_request) Successful in 5m36s
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 / Canary Release to Production (pull_request) Has been skipped
CI/CD Pipeline / Production Browser E2E (pull_request) Has been skipped
CI/CD Pipeline / Integration Tests (pull_request) Successful in 3m14s
CI/CD Pipeline / CI Gate (pull_request) Successful in 10s
ACR Cleanup / ACR Image Cleanup (pull_request_target) Has been cancelled
Preview Cleanup / Cleanup Preview Environment (pull_request) Successful in 56s
4951fd6e77

🚀 预览环境已部署

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

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

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

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

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

【阻塞级判定】

  • 是否存在阻塞级问题:否
  • 阻塞级问题数量:0 个

📊 审查概览

  • 整体评价:通过
  • 建议级问题数量:0 个

🔴 阻塞级问题(必须修复)

💡 改进建议(不阻塞合并)

良好实践

  1. 边界条件覆盖全面:测试用例详细覆盖了 None、空字符串、纯空格、无效 JSON、Markdown 包裹的 JSON 等多种边界情况,确保了解析函数的健壮性。
  2. Mock 使用得当:在测试 _fallback_recommend_clips_call_ai_cover_service 时,正确使用了 patch 来 mock time.sleeprandom.uniform,避免了测试中的不必要等待和随机性,提高了测试效率和稳定性。
  3. 浮点数断言精确:在 test_parse_total_duration_sum 中使用了 pytest.approx 进行浮点数比较,避免了精度问题导致的测试失败。
  4. 关注数据隔离test_parse_config_is_deep_copy 专门测试了返回结果的深拷贝特性,防止了潜在的副作用污染,这是一个容易被忽视但非常重要的测试点。
  5. 测试结构清晰:使用了清晰的类结构(如 TestParseRecommendResponseBasic, TestParseRecommendResponseClips)对测试用例进行分组,可读性极佳。

格式检查通过 | 逻辑审查通过 | 性能良好


🤖 由 AI 代码审查机器人自动生成 | 2026-07-29 14:21:09 | 模型:

### 【阻塞级判定】 - 是否存在阻塞级问题:否 - 阻塞级问题数量:0 个 ### 📊 审查概览 - 整体评价:通过 - 建议级问题数量:0 个 ### 🔴 阻塞级问题(必须修复) 无 ### 💡 改进建议(不阻塞合并) 无 ### ✅ 良好实践 1. **边界条件覆盖全面**:测试用例详细覆盖了 None、空字符串、纯空格、无效 JSON、Markdown 包裹的 JSON 等多种边界情况,确保了解析函数的健壮性。 2. **Mock 使用得当**:在测试 `_fallback_recommend_clips` 和 `_call_ai_cover_service` 时,正确使用了 `patch` 来 mock `time.sleep` 和 `random.uniform`,避免了测试中的不必要等待和随机性,提高了测试效率和稳定性。 3. **浮点数断言精确**:在 `test_parse_total_duration_sum` 中使用了 `pytest.approx` 进行浮点数比较,避免了精度问题导致的测试失败。 4. **关注数据隔离**:`test_parse_config_is_deep_copy` 专门测试了返回结果的深拷贝特性,防止了潜在的副作用污染,这是一个容易被忽视但非常重要的测试点。 5. **测试结构清晰**:使用了清晰的类结构(如 `TestParseRecommendResponseBasic`, `TestParseRecommendResponseClips`)对测试用例进行分组,可读性极佳。 --- ✅ 格式检查通过 | ✅ 逻辑审查通过 | ✅ 性能良好 --- <sub>🤖 由 AI 代码审查机器人自动生成 | 2026-07-29 14:21:09 | 模型: </sub> <!-- AI_CODE_REVIEW_AUTO_COMMENT -->
xiaoxia merged commit 028c6613ce into develop 2026-07-30 00:25:25 +08:00

🗑️ 预览环境已清理

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

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

🗑️ **预览环境已清理** PR #1164 已关闭或合并,对应的预览环境已被清理。 > 如有需要,可以重新打开 PR 来重新生成预览环境。
Sign in to join this conversation.