test(wave137): pip_engine 纯逻辑抽离 + 96 单测 #1052

Closed
xiaoxia wants to merge 2 commits from test/wave137-pip-engine-pure into develop
Owner

变更内容

pip_engine.py 抽离纯逻辑到 pip_engine_pure.py,0 FFmpeg 依赖,可完全单测。原模块完全不变,向后兼容。

抽离的纯函数

  • compute_pip_size — 尺寸计算(像素/百分比,自动等比,边界钳制)
  • compute_pip_position — 位置计算(9宫格 + custom,边界钳制)
  • build_pip_pre_filter — 预处理滤镜链(scale / 圆角 / 边框 / 透明度 / fade动画)
  • build_animation_filters — fade 类入场出场动画滤镜
  • build_overlay_expr — overlay x/y 表达式(支持4方向滑动动画)
  • build_enable_expr — enable 时间控制表达式
  • build_pip_filters — 完整 PiP 滤镜链编排(多图层叠加)
  • validate_pip_layer — 图层配置合法性校验(15+ 检查项)
  • count_visible_layers / sort_layers_by_z_index — 辅助函数

测试覆盖(96 个)

类别 数量
尺寸计算 6
位置计算 10
预处理滤镜 14
动画滤镜 8
overlay 表达式 14
enable 表达式 7
完整滤镜链 8
配置验证 16
可见统计/排序 7

验证

  • pytest: 122 passed(96 新增 + 26 原有,0 回退)
  • black 格式化通过
## 变更内容 从 `pip_engine.py` 抽离纯逻辑到 `pip_engine_pure.py`,0 FFmpeg 依赖,可完全单测。原模块完全不变,向后兼容。 ### 抽离的纯函数 - **compute_pip_size** — 尺寸计算(像素/百分比,自动等比,边界钳制) - **compute_pip_position** — 位置计算(9宫格 + custom,边界钳制) - **build_pip_pre_filter** — 预处理滤镜链(scale / 圆角 / 边框 / 透明度 / fade动画) - **build_animation_filters** — fade 类入场出场动画滤镜 - **build_overlay_expr** — overlay x/y 表达式(支持4方向滑动动画) - **build_enable_expr** — enable 时间控制表达式 - **build_pip_filters** — 完整 PiP 滤镜链编排(多图层叠加) - **validate_pip_layer** — 图层配置合法性校验(15+ 检查项) - **count_visible_layers / sort_layers_by_z_index** — 辅助函数 ### 测试覆盖(96 个) | 类别 | 数量 | |------|------| | 尺寸计算 | 6 | | 位置计算 | 10 | | 预处理滤镜 | 14 | | 动画滤镜 | 8 | | overlay 表达式 | 14 | | enable 表达式 | 7 | | 完整滤镜链 | 8 | | 配置验证 | 16 | | 可见统计/排序 | 7 | ### 验证 - pytest: 122 passed(96 新增 + 26 原有,0 回退) - black 格式化通过
xiaoxia added 1 commit 2026-07-28 10:00:25 +08:00
test(wave137): pip_engine 纯逻辑抽离 + 96 单测
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 59s
CI/CD Pipeline / PR Build Web Image (pull_request) Successful in 54s
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 2m13s
CI/CD Pipeline / Validate - Migration (alembic) (pull_request) Successful in 2m40s
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 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
Preview Deploy / Deploy Preview Environment (pull_request) Has been cancelled
PR Automation / Auto Merge on CI Green + Approved (pull_request) Successful in 1m33s
PR Automation / Auto Approve on CI Green (pull_request) Successful in 4m42s
3d849467a0
抽离 pip_engine_pure.py 纯函数模块,0 FFmpeg 依赖:
- compute_pip_size / compute_pip_position: 尺寸与位置计算
- build_pip_pre_filter: 预处理滤镜链(scale/圆角/边框/透明度/动画)
- build_animation_filters: fade 类动画滤镜
- build_overlay_expr: overlay x/y 表达式(支持滑动动画)
- build_enable_expr: enable 时间控制表达式
- build_pip_filters: 完整 PiP 滤镜链编排
- validate_pip_layer: 配置合法性校验
- count_visible_layers / sort_layers_by_z_index: 辅助函数

原 pip_engine.py 完全不变,向后兼容。
新增 96 个单测,0 FFmpeg 依赖。
auto-approve-bot added 1 commit 2026-07-28 10:03:34 +08:00
style: auto-format with black + isort + prettier [skip ci-format-check]
PR Automation / Auto Approve on CI Green (pull_request) Successful in 4m43s
PR Automation / Auto Merge on CI Green + Approved (pull_request) Successful in 18m36s
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 18s
CI/CD Pipeline / Frontend Lint (pull_request) Successful in 49s
CI/CD Pipeline / Validate - Type Check (mypy) (pull_request) Successful in 1m15s
CI/CD Pipeline / Validate - Code Quality (pull_request) Failing after 1m29s
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 1m17s
Preview Deploy / Deploy Preview Environment (pull_request) Successful in 1m23s
CI/CD Pipeline / PR Build Web Image (pull_request) Successful in 2m7s
CI/CD Pipeline / PR Build Worker Image (pull_request) Successful in 1m54s
AI Code Review / AI Code Review (pull_request) Failing after 4m29s
CI/CD Pipeline / PR Build API Image (pull_request) Successful in 8m34s
CI/CD Pipeline / Frontend Unit 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 Staging (Watchtower auto-deploy) (pull_request) Has been skipped
CI/CD Pipeline / Integration Tests (pull_request) Successful in 3m48s
CI/CD Pipeline / Unit Tests (pull_request) Successful in 5m41s
CI/CD Pipeline / Deploy Production (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 / Canary Release to Production (pull_request) Has been cancelled
CI/CD Pipeline / CI Gate (pull_request) Successful in 29s
CI/CD Pipeline / Production Browser E2E (pull_request) Has been skipped
ACR Cleanup / ACR Image Cleanup (pull_request_target) Has been cancelled
Preview Cleanup / Cleanup Preview Environment (pull_request) Successful in 30s
c93e79f947

🚀 预览环境已部署

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

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

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

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

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

🗑️ 预览环境已清理

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

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

🗑️ **预览环境已清理** PR #1052 已关闭或合并,对应的预览环境已被清理。 > 如有需要,可以重新打开 PR 来重新生成预览环境。
xiaoxia reopened this pull request 2026-07-28 12:18:39 +08:00
Collaborator

【阻塞级判定】

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

📊 审查概览

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

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

  1. [apps/worker/video_processing/pip_engine_pure.py:379] build_pip_filters 参数默认值逻辑错误

    • 问题类型:逻辑bug
    • 问题描述:函数 build_pip_filters 的参数 base_input_idx 默认值为 0。通常情况下,base_label(底层视频)是 [0:v],此时 PiP 素材的输入索引应从 1 开始。如果使用默认值 0,生成的滤镜链会将 [0:v](底层视频)作为 PiP 的源输入,而实际添加的 PiP 文件将变成输入索引 1 且未被引用。这会导致 PiP 效果失效(变成底层视频覆盖自身),或者如果底层视频不是输入 0,则会引用错误的视频流。
    • 修改建议:将 base_input_idx 的默认值修改为 1,或者移除默认值强制调用者显式传入,以避免索引冲突。
  2. [apps/worker/video_processing/pip_engine_pure.py:438] validate_pip_layer 缺少对 border_color 的校验

    • 问题类型:逻辑bug / 数据损坏风险
    • 问题描述:在 validate_pip_layer 函数中,虽然检查了 border_width,但没有检查 border_color。如果配置中 border_width > 0border_colorNone 或空字符串,build_pip_pre_filter 生成的 FFmpeg pad 滤镜参数将格式错误(如 pad=...:None),导致 FFmpeg 执行失败。
    • 修改建议:在 validate_pip_layer 中增加校验逻辑:当 layer.border_width > 0 时,layer.border_color 必须为非空字符串。
  3. [apps/worker/video_processing/pip_engine_pure.py:438] validate_pip_layer 缺少对自定义坐标的校验

    • 问题类型:逻辑bug
    • 问题描述:当 position"custom" 时,依赖 xy 坐标。validate_pip_layer 没有检查这两个字段是否存在或类型是否正确。如果它们缺失,calculate_pip_position 可能会返回 None,导致 compute_pip_position 中的 max(0, min(x, ...)) 抛出 TypeError
    • 修改建议:当 layer.position == "custom" 时,校验 layer.xlayer.y 不为 None 且为数值类型。

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

  1. [apps/worker/video_processing/pip_engine_pure.py:1] 未使用的导入
    • 具体内容:代码中导入了 from typing import Any,但在全文中未使用 Any 类型。建议删除该导入以保持代码整洁。

良好实践

  • 代码结构清晰,将纯逻辑抽离非常利于单元测试。
  • 使用了类型提示(Type Hints),提高了代码可读性和 IDE 支持。
  • compute_pip_sizecompute_pip_position 中包含了边界钳制(clamp)逻辑,防止了数值溢出导致的错误。
  • 使用列表收集滤镜片段并在最后通过 join 拼接,避免了循环中低效的字符串拼接。

🤖 由 AI 代码审查机器人自动生成 | 2026-07-28 04:40:58 | 模型:

### 【阻塞级判定】 - 是否存在阻塞级问题:是 - 阻塞级问题数量:3 个 ### 📊 审查概览 - 整体评价:需修改 - 建议级问题数量:1 个 ### 🔴 阻塞级问题(必须修复) 1. **[apps/worker/video_processing/pip_engine_pure.py:379] build_pip_filters 参数默认值逻辑错误** - 问题类型:逻辑bug - 问题描述:函数 `build_pip_filters` 的参数 `base_input_idx` 默认值为 `0`。通常情况下,`base_label`(底层视频)是 `[0:v]`,此时 PiP 素材的输入索引应从 `1` 开始。如果使用默认值 `0`,生成的滤镜链会将 `[0:v]`(底层视频)作为 PiP 的源输入,而实际添加的 PiP 文件将变成输入索引 `1` 且未被引用。这会导致 PiP 效果失效(变成底层视频覆盖自身),或者如果底层视频不是输入 0,则会引用错误的视频流。 - 修改建议:将 `base_input_idx` 的默认值修改为 `1`,或者移除默认值强制调用者显式传入,以避免索引冲突。 2. **[apps/worker/video_processing/pip_engine_pure.py:438] validate_pip_layer 缺少对 border_color 的校验** - 问题类型:逻辑bug / 数据损坏风险 - 问题描述:在 `validate_pip_layer` 函数中,虽然检查了 `border_width`,但没有检查 `border_color`。如果配置中 `border_width > 0` 但 `border_color` 为 `None` 或空字符串,`build_pip_pre_filter` 生成的 FFmpeg `pad` 滤镜参数将格式错误(如 `pad=...:None`),导致 FFmpeg 执行失败。 - 修改建议:在 `validate_pip_layer` 中增加校验逻辑:当 `layer.border_width > 0` 时,`layer.border_color` 必须为非空字符串。 3. **[apps/worker/video_processing/pip_engine_pure.py:438] validate_pip_layer 缺少对自定义坐标的校验** - 问题类型:逻辑bug - 问题描述:当 `position` 为 `"custom"` 时,依赖 `x` 和 `y` 坐标。`validate_pip_layer` 没有检查这两个字段是否存在或类型是否正确。如果它们缺失,`calculate_pip_position` 可能会返回 `None`,导致 `compute_pip_position` 中的 `max(0, min(x, ...))` 抛出 `TypeError`。 - 修改建议:当 `layer.position == "custom"` 时,校验 `layer.x` 和 `layer.y` 不为 `None` 且为数值类型。 ### 💡 改进建议(不阻塞合并) 1. **[apps/worker/video_processing/pip_engine_pure.py:1] 未使用的导入** - 具体内容:代码中导入了 `from typing import Any`,但在全文中未使用 `Any` 类型。建议删除该导入以保持代码整洁。 ### ✅ 良好实践 - 代码结构清晰,将纯逻辑抽离非常利于单元测试。 - 使用了类型提示(Type Hints),提高了代码可读性和 IDE 支持。 - `compute_pip_size` 和 `compute_pip_position` 中包含了边界钳制(clamp)逻辑,防止了数值溢出导致的错误。 - 使用列表收集滤镜片段并在最后通过 `join` 拼接,避免了循环中低效的字符串拼接。 --- <sub>🤖 由 AI 代码审查机器人自动生成 | 2026-07-28 04:40:58 | 模型: </sub> <!-- AI_CODE_REVIEW_AUTO_COMMENT -->
xiaoxia closed this pull request 2026-07-28 13:10:07 +08:00

🗑️ 预览环境已清理

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

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

🗑️ **预览环境已清理** PR #1052 已关闭或合并,对应的预览环境已被清理。 > 如有需要,可以重新打开 PR 来重新生成预览环境。
Some required checks failed
PR Automation / Auto Approve on CI Green (pull_request) Successful in 4m43s
PR Automation / Auto Merge on CI Green + Approved (pull_request) Successful in 18m36s
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 18s
CI/CD Pipeline / Frontend Lint (pull_request) Successful in 49s
CI/CD Pipeline / Validate - Type Check (mypy) (pull_request) Successful in 1m15s
CI/CD Pipeline / Validate - Code Quality (pull_request) Failing after 1m29s
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 1m17s
Preview Deploy / Deploy Preview Environment (pull_request) Successful in 1m23s
CI/CD Pipeline / PR Build Web Image (pull_request) Successful in 2m7s
CI/CD Pipeline / PR Build Worker Image (pull_request) Successful in 1m54s
AI Code Review / AI Code Review (pull_request) Failing after 4m29s
Required
Details
CI/CD Pipeline / PR Build API Image (pull_request) Successful in 8m34s
CI/CD Pipeline / Frontend Unit 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 Staging (Watchtower auto-deploy) (pull_request) Has been skipped
CI/CD Pipeline / Integration Tests (pull_request) Successful in 3m48s
CI/CD Pipeline / Unit Tests (pull_request) Successful in 5m41s
CI/CD Pipeline / Deploy Production (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 / Canary Release to Production (pull_request) Has been cancelled
CI/CD Pipeline / CI Gate (pull_request) Successful in 29s
Required
Details
CI/CD Pipeline / Production Browser E2E (pull_request) Has been skipped
ACR Cleanup / ACR Image Cleanup (pull_request_target) Has been cancelled
Preview Cleanup / Cleanup Preview Environment (pull_request) Successful in 30s

Pull request closed

Sign in to join this conversation.