test(wave91): add 59 unit tests for generation_plan_builder + extract from generation.py #945

Closed
xiaoxia wants to merge 0 commits from test/wave91-generation-plan-builder into develop
Owner

第91波单测+重构专项

generation.py 1678行巨无霸中抽出纯逻辑模块 generation_plan_builder.py

重构

新模块 apps/worker/worker_app/tasks/generation_plan_builder.py(327行):

  • VirtualPlan / VirtualClip: 内存中的虚拟计划/片段数据类
  • extract_intro_outro_from_clip_configs: 从模板clip_config提取片头片尾配置
  • apply_template_clip_effects: 将模板效果层映射到素材clips(转场/滤镜/调速)
  • build_clips_by_mode: 4种模式构建clip列表(one_take/pip/voice_over/voice_pip)
  • build_error_info: 结构化错误信息构建(堆栈截断)

瘦身效果

  • 原文件:1678行 → 1508行(-170行,-10%)
  • 清理无用导入:dataclass/field

单测覆盖(59个)

模块 数量
VirtualPlan / VirtualClip 6
extract_intro_outro 13
apply_template_clip_effects 19
build_clips_by_mode 15
build_error_info 6

本地验证

  • 59 passed in 1.57s
  • black formatted
  • 向后兼容:_VirtualPlan/_VirtualClip/_build_error_info 等别名保留
  • generation.py 语法正确
## 第91波单测+重构专项 从 `generation.py` 1678行巨无霸中抽出纯逻辑模块 `generation_plan_builder.py`。 ### 重构 新模块 `apps/worker/worker_app/tasks/generation_plan_builder.py`(327行): - `VirtualPlan` / `VirtualClip`: 内存中的虚拟计划/片段数据类 - `extract_intro_outro_from_clip_configs`: 从模板clip_config提取片头片尾配置 - `apply_template_clip_effects`: 将模板效果层映射到素材clips(转场/滤镜/调速) - `build_clips_by_mode`: 4种模式构建clip列表(one_take/pip/voice_over/voice_pip) - `build_error_info`: 结构化错误信息构建(堆栈截断) ### 瘦身效果 - 原文件:1678行 → 1508行(-170行,-10%) - 清理无用导入:dataclass/field ### 单测覆盖(59个) | 模块 | 数量 | |------|------| | VirtualPlan / VirtualClip | 6 | | extract_intro_outro | 13 | | apply_template_clip_effects | 19 | | build_clips_by_mode | 15 | | build_error_info | 6 | ### 本地验证 - ✅ 59 passed in 1.57s - ✅ black formatted - ✅ 向后兼容:_VirtualPlan/_VirtualClip/_build_error_info 等别名保留 - ✅ generation.py 语法正确
Collaborator

代码审查结果 - PR #945

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

  1. apps/worker/worker_app/tasks/generation_plan_builder.py 第52-55行_transition_value 函数对 None 值的处理存在逻辑错误,会导致行为变更。

    • 问题描述:当输入 tNone 时,函数返回字符串 "None"。在 apply_template_clip_effects 的调用处,判断条件为 if transition and transition != "cut"。字符串 "None" 为真值,会导致原本应该跳过的逻辑(当 transition_effect 为 None 或空时)错误地执行,将 clip.transition_effect 设置为字符串 "None",可能引起渲染引擎报错或行为异常。
    • 修改建议:在函数开头增加对 None 的判断,返回空字符串。例如:if t is None: return ""
  2. apps/worker/worker_app/tasks/generation_plan_builder.py 第115行apply_template_clip_effects 函数存在未使用的参数和未使用的常量,逻辑意图不明确。

    • 问题描述:函数定义了参数 mode,且模块内定义了常量 _EFFECT_TARGET_TYPES(包含不同模式对应的 clip_type 映射),但在函数体中完全没有使用。函数仅依赖 _SKIP_TYPES 进行黑名单过滤。虽然目前的黑名单逻辑(排除 corner_voice)恰好覆盖了 build_clips_by_mode 生成的类型,但未使用的参数和常量暗示了重构不完整或逻辑遗漏。如果未来引入新的 clip_type,可能会导致错误的效果应用。
    • 修改建议:要么实现基于 mode_EFFECT_TARGET_TYPES 的白名单过滤逻辑,要么移除未使用的参数 mode 和常量 _EFFECT_TARGET_TYPES,以明确代码意图。

💡 建议(1个可选)

  1. apps/worker/worker_app/tasks/generation_plan_builder.py 第312行build_error_info 函数依赖隐式上下文获取堆栈信息。
    • 建议描述:当前使用 traceback.format_exc() 获取堆栈,这依赖于当前线程的异常上下文。如果在非异常处理上下文中调用该函数,或者 error 对象是从其他地方传递过来的,获取的堆栈可能不准确。建议使用 traceback.format_exception(type(error), error, error.__traceback__) 来显式获取该异常对象的堆栈。

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


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

## 代码审查结果 - PR #945 ### ⚠️ 问题(2个需要修改) 1. **apps/worker/worker_app/tasks/generation_plan_builder.py 第52-55行**:`_transition_value` 函数对 `None` 值的处理存在逻辑错误,会导致行为变更。 - **问题描述**:当输入 `t` 为 `None` 时,函数返回字符串 `"None"`。在 `apply_template_clip_effects` 的调用处,判断条件为 `if transition and transition != "cut"`。字符串 `"None"` 为真值,会导致原本应该跳过的逻辑(当 transition_effect 为 None 或空时)错误地执行,将 `clip.transition_effect` 设置为字符串 `"None"`,可能引起渲染引擎报错或行为异常。 - **修改建议**:在函数开头增加对 `None` 的判断,返回空字符串。例如:`if t is None: return ""`。 2. **apps/worker/worker_app/tasks/generation_plan_builder.py 第115行**:`apply_template_clip_effects` 函数存在未使用的参数和未使用的常量,逻辑意图不明确。 - **问题描述**:函数定义了参数 `mode`,且模块内定义了常量 `_EFFECT_TARGET_TYPES`(包含不同模式对应的 clip_type 映射),但在函数体中完全没有使用。函数仅依赖 `_SKIP_TYPES` 进行黑名单过滤。虽然目前的黑名单逻辑(排除 `corner_voice`)恰好覆盖了 `build_clips_by_mode` 生成的类型,但未使用的参数和常量暗示了重构不完整或逻辑遗漏。如果未来引入新的 clip_type,可能会导致错误的效果应用。 - **修改建议**:要么实现基于 `mode` 和 `_EFFECT_TARGET_TYPES` 的白名单过滤逻辑,要么移除未使用的参数 `mode` 和常量 `_EFFECT_TARGET_TYPES`,以明确代码意图。 ### 💡 建议(1个可选) 1. **apps/worker/worker_app/tasks/generation_plan_builder.py 第312行**:`build_error_info` 函数依赖隐式上下文获取堆栈信息。 - **建议描述**:当前使用 `traceback.format_exc()` 获取堆栈,这依赖于当前线程的异常上下文。如果在非异常处理上下文中调用该函数,或者 `error` 对象是从其他地方传递过来的,获取的堆栈可能不准确。建议使用 `traceback.format_exception(type(error), error, error.__traceback__)` 来显式获取该异常对象的堆栈。 --- ✅ 格式检查通过 | ❌ 逻辑审查需修改 | ✅ 性能无明显问题 --- <sub>🤖 由 AI 代码审查机器人自动生成 | 2026-07-26 17:07:00 | 模型: </sub> <!-- AI_CODE_REVIEW_AUTO_COMMENT -->
xiaoxia force-pushed test/wave91-generation-plan-builder from b12bcbcc76 to 5289e427e2 2026-07-27 18:50:20 +08:00 Compare
xiaoxia closed this pull request 2026-07-27 19:48:58 +08:00

🚀 预览环境已部署

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

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

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

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

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

🗑️ 预览环境已清理

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

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

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