fix(p0): #1922 from-assets 空 templateId 双斜杠 404 兜底 #1926

Merged
auto-approve-bot merged 2 commits from fix/p0-from-assets-default-template-fallback-v2 into develop 2026-09-15 11:54:06 +08:00
Owner

P0 Bug 修复

关联 Issue: #1922

根因

双 Bug 链:

  1. PR#1918 清理模板管理 API 时误删 GET /templates 自动创建默认模板的兜底逻辑;
  2. 前端 PR#1913 去掉空 tid 拦截后,新用户首次进入生成页 templateId='',拼出 URL /templates//editor/clips/from-assets(双斜杠)→ FastAPI 404,完全阻断首次生成流程。

修复方案(三层后端兜底 + 独立端点)

文件 改动 作用
app/api/routes/_default_template.py 🆕 共享 get_or_create_default_template_id():查有效模板 → 无则 CreateTemplateUseCase 创建默认 voice_over 模板 → 创建异常回滚后重查(防并发唯一键冲突)
app/api/routes/templates.py 修改 GET /templates 列表查询前调用兜底,确保生成页首次拉模板列表时一定有数据
app/api/routes/clips_standalone.py 🆕 独立端点 POST /api/v1/clips/from-assets(tags=[Clips]),template_id 从 body 传入可选,为空时后端自动兜底,彻底消除双斜杠路径问题
app/api/routes/templates_editor/dependencies.py 修改 抽出纯函数 resolve_draft_plan_id()(支持 auto_create_default=True 空 tid 兜底),原 get_draft_plan_id Depends 改为薄封装
app/api/routes/templates_editor/__init__.py 修改 导出 resolve_draft_plan_id
app/api/router.py 修改 注册 clips_standalone_router
tests/unit/test_default_template_fallback_p0.py 🆕 16 个单元测试,覆盖兜底函数/resolve/list端点/standalone端点/路由注册

前端配套

前端 useStep2Materials 需改为调用新端点 POST /api/v1/clips/from-assets,templateId 作为 body 字段传入(为空不拼路径,后端自动兜底)。

验证方式

  • CI 全绿(含 unit tests + diff coverage ≥ 40%)
  • staging E2E:新用户首次访问生成页 → GET /templates 返回默认模板 → 点击「智能选片」→ POST /api/v1/clips/from-assets 正常创建片段,不再 404

备注

旧 PR #1921 因分支基于过期 develop(未合入 #1919/#1920/#1924),本次重建分支基于最新 develop 重提。

## P0 Bug 修复 关联 Issue: #1922 ### 根因 双 Bug 链: 1. **PR#1918 清理模板管理 API 时误删** GET /templates 自动创建默认模板的兜底逻辑; 2. **前端 PR#1913 去掉空 tid 拦截**后,新用户首次进入生成页 `templateId=''`,拼出 URL `/templates//editor/clips/from-assets`(双斜杠)→ FastAPI 404,完全阻断首次生成流程。 ### 修复方案(三层后端兜底 + 独立端点) | 文件 | 改动 | 作用 | |---|---|---| | `app/api/routes/_default_template.py` | 🆕 | 共享 `get_or_create_default_template_id()`:查有效模板 → 无则 CreateTemplateUseCase 创建默认 voice_over 模板 → 创建异常回滚后重查(防并发唯一键冲突)| | `app/api/routes/templates.py` | 修改 | GET /templates 列表查询前调用兜底,确保生成页首次拉模板列表时一定有数据 | | `app/api/routes/clips_standalone.py` | 🆕 | 独立端点 `POST /api/v1/clips/from-assets`(tags=[Clips]),`template_id` 从 body 传入可选,为空时后端自动兜底,**彻底消除双斜杠路径问题** | | `app/api/routes/templates_editor/dependencies.py` | 修改 | 抽出纯函数 `resolve_draft_plan_id()`(支持 auto_create_default=True 空 tid 兜底),原 `get_draft_plan_id` Depends 改为薄封装 | | `app/api/routes/templates_editor/__init__.py` | 修改 | 导出 `resolve_draft_plan_id` | | `app/api/router.py` | 修改 | 注册 `clips_standalone_router` | | `tests/unit/test_default_template_fallback_p0.py` | 🆕 | 16 个单元测试,覆盖兜底函数/resolve/list端点/standalone端点/路由注册 | ### 前端配套 前端 `useStep2Materials` 需改为调用新端点 `POST /api/v1/clips/from-assets`,`templateId` 作为 body 字段传入(为空不拼路径,后端自动兜底)。 ### 验证方式 - CI 全绿(含 unit tests + diff coverage ≥ 40%) - staging E2E:新用户首次访问生成页 → GET /templates 返回默认模板 → 点击「智能选片」→ POST /api/v1/clips/from-assets 正常创建片段,不再 404 ### 备注 旧 PR #1921 因分支基于过期 develop(未合入 #1919/#1920/#1924),本次重建分支基于最新 develop 重提。
xiaoxia added 1 commit 2026-09-15 11:37:43 +08:00
fix(p0): #1922 from-assets 空 templateId 双斜杠 404 兜底
CI/CD Pipeline / Dedup Check - skip PR tests when covered by push pipeline (pull_request) Successful in 1s
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 2s
Preview Deploy / Deploy Preview Environment (pull_request) Successful in 1m52s
CI/CD Pipeline / PR Build API Image (pull_request) Successful in 2m29s
PR Automation / Auto Approve on CI Green (pull_request) Successful in 3m5s
CI/CD Pipeline / PR Build Worker Image (pull_request) Successful in 3m18s
CI/CD Pipeline / Integration Tests (pull_request) Successful in 3m49s
CI/CD Pipeline / Unit Tests (pull_request) Successful in 4m7s
CI/CD Pipeline / Validate - Style (pull_request) Has been cancelled
CI/CD Pipeline / Validate - Security (pull_request) Has been cancelled
CI/CD Pipeline / Validate - Python (mypy + alembic) (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 Merge on CI Green + Approved (pull_request) Has been cancelled
CI/CD Pipeline / Staging API Integration Tests (pull_request) Failing after 27h45m43s
CI/CD Pipeline / Retag skipped Staging API Image (pull_request) Failing after 27h45m52s
CI/CD Pipeline / PR Build Web Image (pull_request) Failing after 27h45m55s
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Failing after 27h45m9s
CI/CD Pipeline / Retag skipped Staging Web Image (pull_request) Failing after 27h45m11s
CI/CD Pipeline / Build Staging Worker Image (pull_request) Failing after 27h45m16s
CI/CD Pipeline / Build Staging Web Image (pull_request) Failing after 27h45m17s
CI/CD Pipeline / Build Staging API Image (pull_request) Failing after 27h45m17s
CI/CD Pipeline / Check push changed paths (pull_request) Failing after 27h45m24s
CI/CD Pipeline / ACR Image Cleanup (pull_request) Failing after 27h45m5s
CI/CD Pipeline / Retag skipped Staging Worker Image (pull_request) Failing after 27h45m11s
CI/CD Pipeline / Staging E2E Tests (pull_request) Failing after 27h45m5s
CI/CD Pipeline / Frontend Unit Tests (pull_request) Failing after 27h45m18s
CI/CD Pipeline / Frontend Lint (pull_request) Failing after 27h45m19s
f10106bc51
根因:
1. PR#1918 清理模板管理 API 时误删了 GET /templates 自动创建默认模板兜底逻辑;
2. 前端 PR#1913 去掉空 tid 拦截后,新用户首次进入生成页 templateId='',
   拼出 URL /templates//editor/clips/from-assets(双斜杠)→ FastAPI 404,
   阻断首次生成流程。

修复(三层兜底):
- 新增 _default_template.py,提供共享函数 get_or_create_default_template_id:
  查有效模板 → 无则 CreateTemplateUseCase 创建默认 voice_over 模板 →
  创建异常回滚后重查(防并发唯一键冲突)。
- GET /templates 列表查询前调用兜底,确保生成页首次拉模板列表时一定有数据。
- 新增独立端点 POST /api/v1/clips/from-assets(tags=[Clips]),template_id 从
  body 传入(可选),为空时后端自动兜底,彻底消除双斜杠路径问题。
- dependencies.py 抽出纯函数 resolve_draft_plan_id(支持 auto_create_default),
  原 get_draft_plan_id Depends 改为薄封装。
- router.py 注册 clips_standalone_router。

配套:16 个单元测试覆盖兜底函数/resolve/list端点/standalone端点/路由注册,
保证 diff coverage ≥ 40% 过 CI 门禁。

🚀 预览环境已部署

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

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

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

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

🚀 **预览环境已部署** | 项目 | 详情 | |------|------| | PR号 | #1926 | | 预览链接 | [https://pr-1926.preview.xiaoxiajianji.com](https://pr-1926.preview.xiaoxiajianji.com) | | API环境 | staging | > 💡 预览环境使用 staging API 数据,请勿在预览环境中操作重要数据。 > > 🔄 每次提交新代码后预览环境会自动更新。 > > 🗑️ PR 关闭或合并后,预览环境会自动清理。
auto-approve-bot added 1 commit 2026-09-15 11:42:43 +08:00
style: auto-format with black + isort + ruff + prettier [skip ci-format-check]
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 3s
CI/CD Pipeline / Dedup Check - skip PR tests when covered by push pipeline (pull_request) Successful in 3s
CI/CD Pipeline / PR Build Worker Image (pull_request) Successful in 39s
Preview Deploy / Deploy Preview Environment (pull_request) Successful in 1m46s
CI/CD Pipeline / PR Build API Image (pull_request) Successful in 1m43s
CI/CD Pipeline / Integration Tests (pull_request) Successful in 2m43s
PR Automation / Auto Approve on CI Green (pull_request) Successful in 3m5s
CI/CD Pipeline / Validate - Style (pull_request) Successful in 4m17s
CI/CD Pipeline / Unit Tests (pull_request) Successful in 4m19s
CI/CD Pipeline / Validate - Python (mypy + alembic) (pull_request) Successful in 4m39s
AI Code Review / AI Code Review (pull_request) Successful in 6m36s
CI/CD Pipeline / Validate - Security (pull_request) Successful in 10m33s
CI/CD Pipeline / CI Gate (pull_request) Successful in 1s
CI/CD Pipeline / Production Browser E2E (pull_request) Has been skipped
PR Automation / Auto Merge on CI Green + Approved (pull_request) Successful in 8m10s
ACR Cleanup / ACR Image Cleanup (pull_request_target) Successful in 23s
Preview Cleanup / Cleanup Preview Environment (pull_request) Successful in 47s
CI/CD Pipeline / Deploy Production (pull_request) Failing after 27h30m15s
CI/CD Pipeline / Build Production API Image (pull_request) Failing after 27h30m17s
CI/CD Pipeline / PR Build Web Image (pull_request) Failing after 27h40m51s
CI/CD Pipeline / Build Staging Worker Image (pull_request) Failing after 27h40m55s
CI/CD Pipeline / Retag skipped Staging Worker Image (pull_request) Failing after 27h40m12s
CI/CD Pipeline / Retag skipped Staging API Image (pull_request) Failing after 27h40m12s
CI/CD Pipeline / Build Staging Web Image (pull_request) Failing after 27h40m18s
CI/CD Pipeline / Build Staging API Image (pull_request) Failing after 27h40m18s
CI/CD Pipeline / Check push changed paths (pull_request) Failing after 27h40m20s
CI/CD Pipeline / Build Production Web Image (pull_request) Failing after 27h29m39s
CI/CD Pipeline / Staging E2E Tests (pull_request) Failing after 27h40m9s
CI/CD Pipeline / ACR Image Cleanup (pull_request) Failing after 27h40m7s
CI/CD Pipeline / Build Production Worker Image (pull_request) Failing after 27h29m39s
CI/CD Pipeline / Staging API Integration Tests (pull_request) Failing after 27h40m7s
CI/CD Pipeline / Retag skipped Staging Web Image (pull_request) Failing after 27h40m12s
CI/CD Pipeline / Frontend Unit Tests (pull_request) Failing after 27h40m13s
CI/CD Pipeline / Canary Release to Production (pull_request) Failing after 27h29m38s
CI/CD Pipeline / Frontend Lint (pull_request) Failing after 27h40m13s
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Failing after 28h15m46s
d0937a6f29
auto-approve-bot merged commit 352221f199 into develop 2026-09-15 11:54:06 +08:00
auto-approve-bot deleted branch fix/p0-from-assets-default-template-fallback-v2 2026-09-15 11:54:06 +08:00

🗑️ 预览环境已清理

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

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

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