fix: #1294 预览视频未使用用户选择的配音 #1295

Merged
xiaoxia merged 4 commits from bugfix/1294-preview-voice-injection into develop 2026-08-08 12:21:24 +08:00
Owner

问题

用户在智能剪辑流程中选择了配音音色,但生成的预览视频完全没有配音。

根因

Worker 端三层断裂:

  1. _load_task_info 未加载 voice_ids 字段
  2. _render_video 未接收 voice_ids 参数
  3. plan.config 中未注入 voice_id,导致渲染引擎 _maybe_add_voiceover_layer 读不到 voice_id 直接跳过配音生成

修复

  1. _load_task_info:增加 voice_ids 字段加载
  2. _render_video:新增 voice_ids 参数,在构建 virtual_plan 后注入 voice_id 到 config,并设置 subtitle.auto_generated=True 启用 ASR 字幕对齐配音模式
  3. generate_video:将 task_info 中的 voice_ids 传递给 _render_video

测试

  • 新增 5 个单元测试,覆盖 voice_ids 加载、参数签名、传递链路
  • 全量单元测试通过
## 问题 用户在智能剪辑流程中选择了配音音色,但生成的预览视频完全没有配音。 ## 根因 Worker 端三层断裂: 1. `_load_task_info` 未加载 `voice_ids` 字段 2. `_render_video` 未接收 `voice_ids` 参数 3. `plan.config` 中未注入 `voice_id`,导致渲染引擎 `_maybe_add_voiceover_layer` 读不到 `voice_id` 直接跳过配音生成 ## 修复 1. **`_load_task_info`**:增加 `voice_ids` 字段加载 2. **`_render_video`**:新增 `voice_ids` 参数,在构建 `virtual_plan` 后注入 `voice_id` 到 config,并设置 `subtitle.auto_generated=True` 启用 ASR 字幕对齐配音模式 3. **`generate_video`**:将 `task_info` 中的 `voice_ids` 传递给 `_render_video` ## 测试 - 新增 5 个单元测试,覆盖 voice_ids 加载、参数签名、传递链路 - 全量单元测试通过

🚀 预览环境已部署

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

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

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

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

🚀 **预览环境已部署** | 项目 | 详情 | |------|------| | PR号 | #1295 | | 预览链接 | [https://pr-1295.preview.xiaoxiajianji.com](https://pr-1295.preview.xiaoxiajianji.com) | | API环境 | staging | > 💡 预览环境使用 staging API 数据,请勿在预览环境中操作重要数据。 > > 🔄 每次提交新代码后预览环境会自动更新。 > > 🗑️ PR 关闭或合并后,预览环境会自动清理。
xiaoxia force-pushed bugfix/1294-preview-voice-injection from 80882cd472 to 9e8732eb9e 2026-08-08 11:20:41 +08:00 Compare
xiaoxia added 2 commits 2026-08-08 11:42:55 +08:00
根因:Worker 端三层断裂——
1. _load_task_info 未加载 voice_ids
2. _render_video 未接收 voice_ids 参数
3. plan config 未注入 voice_id,导致 _maybe_add_voiceover_layer 跳过配音

修复:
- _load_task_info 增加 voice_ids 字段加载
- _render_video 新增 voice_ids 参数,注入 voice_id + subtitle.auto_generated=True
- generate_video 将 task_info 中的 voice_ids 传递给 _render_video
- 新增 5 个单元测试覆盖修复逻辑
style: auto-format with black + isort + prettier [skip ci-format-check]
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 / Check if frontend-only change (pull_request) Successful in 39s
CI/CD Pipeline / Validate - Type Check (mypy) (pull_request) Successful in 1m4s
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Has been skipped
CI/CD Pipeline / Frontend Lint (pull_request) Has been skipped
CI/CD Pipeline / Frontend Unit Tests (pull_request) Has been skipped
CI/CD Pipeline / Validate - Migration (alembic) (pull_request) Successful in 1m5s
CI/CD Pipeline / PR Build Web Image (pull_request) Has been skipped
PR Automation / Auto Merge on CI Green + Approved (pull_request) Successful in 2m0s
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
Preview Deploy / Deploy Preview Environment (pull_request) Successful in 1m47s
CI/CD Pipeline / Validate - Code Quality (pull_request) Successful in 3m5s
CI/CD Pipeline / Unit Tests (pull_request) Failing after 2m43s
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 / Production Browser E2E (pull_request) Has been skipped
CI/CD Pipeline / Canary Release to Production (pull_request) Has been skipped
PR Automation / Auto Approve on CI Green (pull_request) Successful in 4m13s
AI Code Review / AI Code Review (pull_request) Successful in 4m30s
CI/CD Pipeline / PR Build API Image (pull_request) Successful in 3m37s
CI/CD Pipeline / PR Build Worker Image (pull_request) Successful in 3m36s
CI/CD Pipeline / Integration Tests (pull_request) Successful in 2m16s
CI/CD Pipeline / CI Gate (pull_request) Failing after 14s
d7315544d3
xiaoxia force-pushed bugfix/1294-preview-voice-injection from 9e8732eb9e to d7315544d3 2026-08-08 11:42:55 +08:00 Compare
xiaoxia added 1 commit 2026-08-08 12:10:21 +08:00
test: 补充 _render_video 配音注入实际执行测试,覆盖 diff-cover 新增行
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 / ACR Image Cleanup (pull_request) Has been skipped
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 44s
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 / Validate - Migration (alembic) (pull_request) Successful in 1m3s
CI/CD Pipeline / Validate - Type Check (mypy) (pull_request) Successful in 1m5s
Preview Deploy / Deploy Preview Environment (pull_request) Successful in 1m29s
PR Automation / Auto Merge on CI Green + Approved (pull_request) Successful in 1m44s
AI Code Review / AI Code Review (pull_request) Successful in 2m25s
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 / PR Build API Image (pull_request) Has been cancelled
CI/CD Pipeline / PR Build Worker Image (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 / Canary Release to Production (pull_request) Has been cancelled
CI/CD Pipeline / CI Gate (pull_request) Has been cancelled
PR Automation / Auto Approve on CI Green (pull_request) Has been cancelled
09ac626505
原测试仅检查函数签名和源码文本,未实际执行配音注入代码路径,
导致 diff-cover 检测到 generation.py lines 1181-1188 覆盖率为 0%。

新增 test_voice_ids_injected_into_plan_config:
- Mock _build_plan_and_clips_from_task / _load_template_plan_config / RenderAdapter / SessionLocal
- 实际调用 _render_video(voice_ids=['voice_abc'])
- 验证 plan.config['voice_id'] == 'voice_abc' 且 subtitle.auto_generated == True

新增 test_voice_ids_empty_skips_injection:
- 验证 voice_ids 为空时不注入 voice_id
auto-approve-bot added 1 commit 2026-08-08 12:13:02 +08:00
style: auto-format with black + isort + prettier [skip ci-format-check]
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 / ACR Image Cleanup (pull_request) Has been skipped
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 40s
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 / Validate - Type Check (mypy) (pull_request) Successful in 57s
CI/CD Pipeline / Validate - Migration (alembic) (pull_request) Successful in 57s
Preview Deploy / Deploy Preview Environment (pull_request) Successful in 1m24s
PR Automation / Auto Merge on CI Green + Approved (pull_request) Successful in 1m41s
AI Code Review / AI Code Review (pull_request) Failing after 2m20s
CI/CD Pipeline / PR Build API Image (pull_request) Successful in 1m50s
CI/CD Pipeline / PR Build Worker Image (pull_request) Successful in 1m52s
CI/CD Pipeline / Unit Tests (pull_request) Successful in 2m3s
CI/CD Pipeline / Validate - Code Quality (pull_request) Successful in 3m9s
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
PR Automation / Auto Approve on CI Green (pull_request) Successful in 3m27s
CI/CD Pipeline / Integration Tests (pull_request) Successful in 1m16s
CI/CD Pipeline / CI Gate (pull_request) Successful in 6s
ACR Cleanup / ACR Image Cleanup (pull_request_target) Successful in 54s
Preview Cleanup / Cleanup Preview Environment (pull_request) Successful in 1m5s
a3cc325bd8
Collaborator

【阻塞级判定】

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

📊 审查概览

  • 整体评价:需修改
  • 建议级问题数量:2 个

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

  1. [apps/worker/worker_app/tasks/generation.py: 1182] 参数命名与实现逻辑不符
    • 问题类型:逻辑bug
    • 问题描述:函数参数定义为 voice_ids(复数形式,类型为 list[str]),但在实现中仅使用了 voice_ids[0]。如果传入的列表包含多个 ID,后续的 ID 会被静默忽略。这会导致功能不完整或行为不符合预期(用户误以为支持多个配音注入)。
    • 修改建议:如果业务逻辑仅支持单个配音注入,建议将参数名改为 voice_id(单数),类型改为 str | None,并修改调用处的逻辑;如果确实需要支持多个,则应修改注入逻辑以遍历列表或抛出明确的异常。

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

  1. [tests/unit/test_1294_preview_voice_injection.py: 244] 测试方法过于脆弱

    • 具体内容:test_generate_video_passes_voice_ids 方法通过读取源码文件并检查字符串字面量来验证参数传递。这种“白盒”字符串检查测试非常脆弱,一旦代码格式化或重构(例如参数换行),测试就会失败。建议使用 unittest.mock.patch 来 mock _render_video 函数,然后调用 generate_video,验证 _render_video 是否被正确的参数调用。
  2. [apps/worker/worker_app/tasks/generation.py: 1180] 边界条件校验可加强

    • 具体内容:当前逻辑 if voice_ids: 仅判断列表非空。如果列表中包含空字符串(如 [""]),条件依然成立,导致 plan_cfg["voice_id"] 被设置为空字符串,这可能引发下游错误。建议增加对首个元素非空的校验:if voice_ids and voice_ids[0]:

良好实践

  • _load_task_info 中使用 list(getattr(..., []) or []) 确保了返回值的类型安全,有效避免了 NoneType 错误。
  • 新增的单元测试覆盖了主要逻辑路径(空列表、非空列表),且使用了 dataclass 构造 Mock 对象,测试代码结构清晰。
  • _render_video 中重新获取 virtual_plan.config 进行修改,确保了不会意外覆盖之前代码块(如 export 配置)设置的属性,逻辑处理得当。

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


🤖 由 AI 代码审查机器人自动生成 | 2026-08-08 04:15:22 | 模型:

### 【阻塞级判定】 - 是否存在阻塞级问题:是 - 阻塞级问题数量:1 个 ### 📊 审查概览 - 整体评价:需修改 - 建议级问题数量:2 个 ### 🔴 阻塞级问题(必须修复) 1. **[apps/worker/worker_app/tasks/generation.py: 1182] 参数命名与实现逻辑不符** - 问题类型:逻辑bug - 问题描述:函数参数定义为 `voice_ids`(复数形式,类型为 `list[str]`),但在实现中仅使用了 `voice_ids[0]`。如果传入的列表包含多个 ID,后续的 ID 会被静默忽略。这会导致功能不完整或行为不符合预期(用户误以为支持多个配音注入)。 - 修改建议:如果业务逻辑仅支持单个配音注入,建议将参数名改为 `voice_id`(单数),类型改为 `str | None`,并修改调用处的逻辑;如果确实需要支持多个,则应修改注入逻辑以遍历列表或抛出明确的异常。 ### 💡 改进建议(不阻塞合并) 1. **[tests/unit/test_1294_preview_voice_injection.py: 244] 测试方法过于脆弱** - 具体内容:`test_generate_video_passes_voice_ids` 方法通过读取源码文件并检查字符串字面量来验证参数传递。这种“白盒”字符串检查测试非常脆弱,一旦代码格式化或重构(例如参数换行),测试就会失败。建议使用 `unittest.mock.patch` 来 mock `_render_video` 函数,然后调用 `generate_video`,验证 `_render_video` 是否被正确的参数调用。 2. **[apps/worker/worker_app/tasks/generation.py: 1180] 边界条件校验可加强** - 具体内容:当前逻辑 `if voice_ids:` 仅判断列表非空。如果列表中包含空字符串(如 `[""]`),条件依然成立,导致 `plan_cfg["voice_id"]` 被设置为空字符串,这可能引发下游错误。建议增加对首个元素非空的校验:`if voice_ids and voice_ids[0]:`。 ### ✅ 良好实践 - 在 `_load_task_info` 中使用 `list(getattr(..., []) or [])` 确保了返回值的类型安全,有效避免了 NoneType 错误。 - 新增的单元测试覆盖了主要逻辑路径(空列表、非空列表),且使用了 dataclass 构造 Mock 对象,测试代码结构清晰。 - 在 `_render_video` 中重新获取 `virtual_plan.config` 进行修改,确保了不会意外覆盖之前代码块(如 export 配置)设置的属性,逻辑处理得当。 --- ✅ 格式检查通过 | ❌ 逻辑审查需修改 | ✅ 性能良好 --- <sub>🤖 由 AI 代码审查机器人自动生成 | 2026-08-08 04:15:22 | 模型: </sub> <!-- AI_CODE_REVIEW_AUTO_COMMENT -->
xiaoxia merged commit 975a094a0c into develop 2026-08-08 12:21:24 +08:00

🗑️ 预览环境已清理

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

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

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