fix: 预览分辨率自动从模板mode推断(Fix3补充) #1230

Merged
xiaoxia merged 7 commits from fix/preview-resolution-auto-infer into develop 2026-08-04 01:08:23 +08:00
Owner

问题

PR #1229 的 Fix3 修复了 worker 端的渲染分辨率逻辑(尊重传入的 resolution 参数),但 API 层创建预览任务时,_calc_preview_resolution(request.video_ratio) 在前端未传 video_ratio 时默认返回 854x480(横屏),导致竖屏模板(mode=pip)仍被渲染为横屏。

修复

  • 新增 _infer_video_ratio_from_template() 函数:当前端未传 video_ratio 时,从模板 mode 字段推断视频比例
    • pip9:16480x854
    • standard16:9854x480
    • square1:1480x480
  • 路由函数新增 db: Session 依赖,用于查询模板
  • 推断失败时安全降级,不影响原有逻辑

测试

  • TestInferVideoRatioFromTemplate: 6 个测试(pip/standard/unknown/不存在/空ID/DB异常)
  • TestPreviewRouteAutoInfersVideoRatio: 集成测试验证路由自动推断
  • 所有现有路由测试更新增加 db mock
## 问题 PR #1229 的 Fix3 修复了 worker 端的渲染分辨率逻辑(尊重传入的 resolution 参数),但 API 层创建预览任务时,`_calc_preview_resolution(request.video_ratio)` 在前端未传 `video_ratio` 时默认返回 `854x480`(横屏),导致竖屏模板(mode=pip)仍被渲染为横屏。 ## 修复 - 新增 `_infer_video_ratio_from_template()` 函数:当前端未传 `video_ratio` 时,从模板 `mode` 字段推断视频比例 - `pip` → `9:16` → `480x854` - `standard` → `16:9` → `854x480` - `square` → `1:1` → `480x480` - 路由函数新增 `db: Session` 依赖,用于查询模板 - 推断失败时安全降级,不影响原有逻辑 ## 测试 - `TestInferVideoRatioFromTemplate`: 6 个测试(pip/standard/unknown/不存在/空ID/DB异常) - `TestPreviewRouteAutoInfersVideoRatio`: 集成测试验证路由自动推断 - 所有现有路由测试更新增加 db mock
xiaoxia added 2 commits 2026-08-04 00:45:48 +08:00
When frontend doesn't pass video_ratio, backend infers from template.mode:
- pip → 9:16 → 480x854
- standard → 16:9 → 854x480
test: add template mode inference tests
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 36s
CI/CD Pipeline / Frontend Unit Tests (pull_request) Has been skipped
CI/CD Pipeline / Frontend Lint (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 51s
CI/CD Pipeline / Validate - Migration (alembic) (pull_request) Successful in 1m0s
Preview Deploy / Deploy Preview Environment (pull_request) Successful in 1m23s
PR Automation / Auto Merge on CI Green + Approved (pull_request) Successful in 1m54s
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
AI Code Review / AI Code Review (pull_request) Has been cancelled
PR Automation / Auto Approve on CI Green (pull_request) Has been cancelled
1d973554c8
- TestInferVideoRatioFromTemplate: 6 tests
- TestPreviewRouteAutoInfersVideoRatio: integration test
- Update existing route tests with db mock

🚀 预览环境已部署

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

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

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

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

🚀 **预览环境已部署** | 项目 | 详情 | |------|------| | PR号 | #1230 | | 预览链接 | [https://pr-1230.preview.xiaoxiajianji.com](https://pr-1230.preview.xiaoxiajianji.com) | | API环境 | staging | > 💡 预览环境使用 staging API 数据,请勿在预览环境中操作重要数据。 > > 🔄 每次提交新代码后预览环境会自动更新。 > > 🗑️ PR 关闭或合并后,预览环境会自动清理。
auto-approve-bot added 1 commit 2026-08-04 00:47:52 +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 API Integration Tests (pull_request) Has been skipped
CI/CD Pipeline / Staging E2E 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 42s
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 48s
CI/CD Pipeline / Validate - Migration (alembic) (pull_request) Successful in 49s
CI/CD Pipeline / Validate - Code Quality (pull_request) Failing after 1m2s
Preview Deploy / Deploy Preview Environment (pull_request) Successful in 1m28s
PR Automation / Auto Merge on CI Green + Approved (pull_request) Successful in 1m47s
CI/CD Pipeline / Unit Tests (pull_request) Failing after 1m40s
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 / PR Build API Image (pull_request) Successful in 1m54s
CI/CD Pipeline / PR Build Worker Image (pull_request) Successful in 1m55s
CI/CD Pipeline / Integration Tests (pull_request) Successful in 1m40s
CI/CD Pipeline / CI Gate (pull_request) Failing after 7s
PR Automation / Auto Approve on CI Green (pull_request) Successful in 3m28s
AI Code Review / AI Code Review (pull_request) Successful in 6m50s
9ceb545f07
xiaoxia added 1 commit 2026-08-04 00:54:48 +08:00
xiaoxia added 1 commit 2026-08-04 00:54:48 +08:00
fix: only add db mock to create_preview calls, not get_preview + add inference tests
CI/CD Pipeline / Build Staging Web Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging API 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 / ACR Image Cleanup (pull_request) Has been skipped
CI/CD Pipeline / Staging API Integration Tests (pull_request) Has been skipped
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 32s
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 54s
CI/CD Pipeline / Validate - Type Check (mypy) (pull_request) Successful in 1m1s
Preview Deploy / Deploy Preview Environment (pull_request) Successful in 1m26s
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
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
57996909f8
auto-approve-bot added 1 commit 2026-08-04 00:56:39 +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 / Validate - Migration (alembic) (pull_request) Successful in 40s
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 47s
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 - Code Quality (pull_request) Failing after 1m0s
Preview Deploy / Deploy Preview Environment (pull_request) Successful in 1m22s
AI Code Review / AI Code Review (pull_request) Successful in 1m43s
PR Automation / Auto Merge on CI Green + Approved (pull_request) Successful in 1m44s
CI/CD Pipeline / Unit Tests (pull_request) Successful in 1m39s
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 1m31s
PR Automation / Auto Approve on CI Green (pull_request) Successful in 3m30s
CI/CD Pipeline / PR Build API Image (pull_request) Successful in 3m36s
CI/CD Pipeline / PR Build Worker Image (pull_request) Successful in 3m37s
CI/CD Pipeline / CI Gate (pull_request) Failing after 7s
b7c6e4e142
xiaoxia added 1 commit 2026-08-04 01:01:56 +08:00
fix: remove unused variable 'e' from GlobalQueueFull except block
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 / ACR Image Cleanup (pull_request) Has been skipped
CI/CD Pipeline / Staging API Integration Tests (pull_request) Has been skipped
CI/CD Pipeline / Validate - Migration (alembic) (pull_request) Successful in 36s
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 37s
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 56s
Preview Deploy / Deploy Preview Environment (pull_request) Successful in 1m15s
PR Automation / Auto Merge on CI Green + Approved (pull_request) Successful in 1m37s
AI Code Review / AI Code Review (pull_request) Successful in 1m52s
CI/CD Pipeline / PR Build API Image (pull_request) Successful in 1m46s
CI/CD Pipeline / PR Build Worker Image (pull_request) Successful in 1m47s
CI/CD Pipeline / Validate - Code Quality (pull_request) Successful in 3m29s
CI/CD Pipeline / Unit Tests (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
CI/CD Pipeline / Integration Tests (pull_request) Successful in 2m1s
CI/CD Pipeline / CI Gate (pull_request) Successful in 5s
ACR Cleanup / ACR Image Cleanup (pull_request_target) Successful in 39s
Preview Cleanup / Cleanup Preview Environment (pull_request) Successful in 47s
PR Automation / Auto Approve on CI Green (pull_request) Failing after 13m31s
f04943b352
Collaborator

【阻塞级判定】

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

📊 审查概览

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

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

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

  1. [apps/api/app/api/routes/generation_preview.py: 28] 依赖注入解耦

    • 具体内容:在路由函数中直接导入并实例化 SQLAlchemyTemplateRepository (from packages.adapters...) 增加了 API 层与具体数据库适配器的耦合度。建议在 app.dependencies 中创建 get_template_repository 依赖工厂函数,遵循依赖倒置原则,便于后续测试或替换存储实现。
  2. [apps/api/app/api/routes/generation_preview.py: 76] 异常捕获范围

    • 具体内容:_infer_video_ratio_from_template 函数中使用了裸 except Exception:。虽然这里作为辅助函数且返回空字符串作为降级处理是合理的,但捕获过于宽泛。建议捕获具体的数据库异常(如 SQLAlchemyError),避免掩盖非预期的系统级错误(如内存错误等),虽然在此处概率极低,但更严谨的做法是只捕获预期的异常。

良好实践

  • 降级策略设计:在无法从模板推断 video_ratio 时(如模板不存在或查询异常),代码优雅地降级为空字符串,交由后续逻辑使用默认分辨率,保证了核心流程不中断。
  • 测试覆盖充分:新增的单元测试覆盖了正常模式、未知模式、模板不存在、DB异常等多种边界情况,且集成测试验证了端到端的逻辑,质量较高。
  • 错误信息优化:将 UserPendingLimitExceeded 的错误信息从笼统的提示改为包含具体数量({e.pending_count - 1}/{e.limit}),提升了用户体验。

格式检查通过 | 逻辑审查通过 | 性能无需关注


🤖 由 AI 代码审查机器人自动生成 | 2026-08-03 17:03:49 | 模型:

### 【阻塞级判定】 - 是否存在阻塞级问题:否 - 阻塞级问题数量:0 个 ### 📊 审查概览 - 整体评价:通过 - 建议级问题数量:2 个 ### 🔴 阻塞级问题(必须修复) 无 ### 💡 改进建议(不阻塞合并) 1. **[apps/api/app/api/routes/generation_preview.py: 28] 依赖注入解耦** - 具体内容:在路由函数中直接导入并实例化 `SQLAlchemyTemplateRepository` (`from packages.adapters...`) 增加了 API 层与具体数据库适配器的耦合度。建议在 `app.dependencies` 中创建 `get_template_repository` 依赖工厂函数,遵循依赖倒置原则,便于后续测试或替换存储实现。 2. **[apps/api/app/api/routes/generation_preview.py: 76] 异常捕获范围** - 具体内容:`_infer_video_ratio_from_template` 函数中使用了裸 `except Exception:`。虽然这里作为辅助函数且返回空字符串作为降级处理是合理的,但捕获过于宽泛。建议捕获具体的数据库异常(如 `SQLAlchemyError`),避免掩盖非预期的系统级错误(如内存错误等),虽然在此处概率极低,但更严谨的做法是只捕获预期的异常。 ### ✅ 良好实践 - **降级策略设计**:在无法从模板推断 `video_ratio` 时(如模板不存在或查询异常),代码优雅地降级为空字符串,交由后续逻辑使用默认分辨率,保证了核心流程不中断。 - **测试覆盖充分**:新增的单元测试覆盖了正常模式、未知模式、模板不存在、DB异常等多种边界情况,且集成测试验证了端到端的逻辑,质量较高。 - **错误信息优化**:将 `UserPendingLimitExceeded` 的错误信息从笼统的提示改为包含具体数量(`{e.pending_count - 1}/{e.limit}`),提升了用户体验。 --- ✅ 格式检查通过 | ✅ 逻辑审查通过 | ✅ 性能无需关注 --- <sub>🤖 由 AI 代码审查机器人自动生成 | 2026-08-03 17:03:49 | 模型: </sub> <!-- AI_CODE_REVIEW_AUTO_COMMENT -->
xiaoxia merged commit 405bce6e1b into develop 2026-08-04 01:08:23 +08:00
xiaoxia deleted branch fix/preview-resolution-auto-infer 2026-08-04 01:08:23 +08:00

🗑️ 预览环境已清理

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

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

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