Merge pull request 'chore: 删除素材选取 random 模式,保持代码干净' (#1542) from chore/remove-random-asset-mode into develop
CI/CD Pipeline / Check push changed paths (push) Successful in 3m58s
CI/CD Pipeline / Validate - Type Check (mypy) (pull_request) Successful in 4m0s
CI/CD Pipeline / Validate - Type Check (mypy) (push) Successful in 4m31s
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 4m40s
CI/CD Pipeline / Validate - Migration (alembic) (push) Successful in 5m38s
CI/CD Pipeline / Validate - Migration (alembic) (pull_request) Successful in 2m55s
CI/CD Pipeline / Build Staging API Image (push) Successful in 1m43s
CI/CD Pipeline / Build Staging Worker Image (push) Successful in 1m26s
Preview Deploy / Deploy Preview Environment (pull_request) Successful in 3m27s
CI/CD Pipeline / PR Build API Image (pull_request) Successful in 55s
CI/CD Pipeline / Validate - Code Quality (push) Successful in 8m32s
CI/CD Pipeline / Retag skipped Staging Web Image (push) Successful in 1m15s
CI/CD Pipeline / PR Build Worker Image (pull_request) Successful in 1m20s
PR Automation / Auto Approve on CI Green (pull_request) Successful in 4m58s
CI/CD Pipeline / Frontend Unit Tests (push) Successful in 9m13s
CI/CD Pipeline / Validate - Code Quality (pull_request) Successful in 9m20s
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (push) Successful in 1m15s
AI Code Review / AI Code Review (pull_request) Successful in 6m33s
CI/CD Pipeline / Integration Tests (push) Successful in 3m48s
CI/CD Pipeline / ACR Image Cleanup (push) Successful in 2m21s
CI/CD Pipeline / Integration Tests (pull_request) Successful in 3m59s
CI/CD Pipeline / Staging API Integration Tests (push) Successful in 4m24s
CI/CD Pipeline / Unit Tests (push) Successful in 16m11s
CI/CD Pipeline / Staging E2E Tests (push) Successful in 6m20s
CI/CD Pipeline / Unit Tests (pull_request) Successful in 12m20s
CI/CD Pipeline / CI Gate (pull_request) Successful in 27s
CI/CD Pipeline / Production Browser E2E (pull_request) Failing after 428h53m19s
CI/CD Pipeline / Canary Release to Production (pull_request) Failing after 428h53m19s
CI/CD Pipeline / Build Production Web Image (pull_request) Failing after 428h53m21s
CI/CD Pipeline / Deploy Production (pull_request) Failing after 428h53m19s
CI/CD Pipeline / Build Production API Image (pull_request) Failing after 428h53m21s
CI/CD Pipeline / Production Browser E2E (push) Failing after 428h54m32s
CI/CD Pipeline / Deploy Production (push) Failing after 428h54m33s
CI/CD Pipeline / Build Production Worker Image (push) Failing after 428h54m34s
CI/CD Pipeline / Build Production API Image (push) Failing after 428h54m35s
CI/CD Pipeline / CI Gate (push) Failing after 428h54m35s
CI/CD Pipeline / Staging API Integration Tests (pull_request) Failing after 429h2m47s
CI/CD Pipeline / Retag skipped Staging Worker Image (push) Failing after 429h2m45s
CI/CD Pipeline / Retag skipped Staging API Image (push) Failing after 429h3m8s
CI/CD Pipeline / Staging E2E Tests (pull_request) Failing after 429h2m49s
CI/CD Pipeline / PR Build Web Image (pull_request) Failing after 429h3m10s
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Failing after 429h3m14s
CI/CD Pipeline / Retag skipped Staging Worker Image (pull_request) Failing after 429h3m16s
CI/CD Pipeline / Build Staging Worker Image (pull_request) Failing after 429h3m23s
CI/CD Pipeline / Retag skipped Staging Web Image (pull_request) Failing after 429h3m18s
CI/CD Pipeline / Build Staging Web Image (pull_request) Failing after 429h3m25s
CI/CD Pipeline / Build Staging Web Image (push) Failing after 429h4m38s
CI/CD Pipeline / Build Staging API Image (pull_request) Failing after 429h3m27s
CI/CD Pipeline / Frontend Unit Tests (pull_request) Failing after 429h4m59s
CI/CD Pipeline / Frontend Lint (pull_request) Failing after 429h5m1s
PR Automation / Auto Merge on CI Green + Approved (pull_request) Failing after 429h6m18s
CI/CD Pipeline / Check push changed paths (pull_request) Failing after 429h6m51s
CI/CD Pipeline / PR Build Worker Image (push) Failing after 429h7m35s
CI/CD Pipeline / PR Build Web Image (push) Failing after 429h7m37s
CI/CD Pipeline / PR Build API Image (push) Failing after 429h7m39s
CI/CD Pipeline / Check if frontend-only change (push) Failing after 429h10m49s
CI/CD Pipeline / Build Production Worker Image (pull_request) Failing after 429h27m24s
CI/CD Pipeline / Canary Release to Production (push) Failing after 429h28m36s
CI/CD Pipeline / Build Production Web Image (push) Failing after 429h28m38s
CI/CD Pipeline / ACR Image Cleanup (pull_request) Failing after 429h37m16s
CI/CD Pipeline / Retag skipped Staging API Image (pull_request) Failing after 429h37m24s
CI/CD Pipeline / Frontend Lint (push) Failing after 429h44m52s

This commit was merged in pull request #1542.
This commit is contained in:
2026-08-29 18:14:50 +08:00
5 changed files with 10 additions and 39 deletions
+4 -11
View File
@@ -1,5 +1,4 @@
import logging
import random
import uuid
from typing import Any
@@ -116,8 +115,8 @@ def _select_assets_from_library(
Args:
assets: 素材库中所有素材(Asset 实体列表)
mode: 选取模式 — all=全部, random=随机, smart=智能匹配(多维度评分+多样性)
count: 选取数量,0 表示全部(仅 random/smart 模式有效)
mode: 选取模式 — all=全部, smart=智能匹配(多维度评分+多样性)
count: 选取数量,0 表示全部(仅 smart 模式有效)
Returns:
选中的素材 ID 列表
@@ -127,12 +126,6 @@ def _select_assets_from_library(
if not ready_video_assets:
return []
if mode == "random":
selected = (
ready_video_assets if count <= 0 else random.sample(ready_video_assets, min(count, len(ready_video_assets)))
)
return [a.id for a in selected]
if mode == "smart":
# 智能匹配:统一使用 packages/domain/smart_match.py 的多维评分+多样性选取
# 评分维度:质量分(40%) + 时长适配(30%) + 新鲜度(20%) + 未使用加分(10%)
@@ -292,8 +285,8 @@ def create_generation_task(
mode=request.asset_select_mode,
count=request.asset_select_count,
)
elif project_id and not resolved_asset_ids and request.asset_select_mode in ("random", "smart"):
# 项目级模式:未指定 asset_ids 且选择了 random/smart 模式时,也自动选取
elif project_id and not resolved_asset_ids and request.asset_select_mode in ("smart",):
# 项目级模式:未指定 asset_ids 且选择了 smart 模式时,也自动选取
assets = asset_repository.find_by_project(project_id)
if assets:
resolved_asset_ids = _select_assets_from_library(
+2 -4
View File
@@ -45,11 +45,9 @@ class CreateGenerationTaskRequest(BaseModel):
# ── 素材库自动匹配 ──
asset_select_mode: str = Field(
default="all",
description="素材选取模式:all=全部ready视频, random=随机选取, smart=智能匹配(按质量/时长评分)",
)
asset_select_count: int = Field(
default=0, ge=0, le=100, description="选取数量,0表示全部(仅 random/smart 模式有效)"
description="素材选取模式:all=全部ready视频, smart=智能匹配(按质量/时长评分)",
)
asset_select_count: int = Field(default=0, ge=0, le=100, description="选取数量,0表示全部(仅 smart 模式有效)")
# ── 自动重试 ──
auto_retry_enabled: bool = Field(
default=False,
+2 -2
View File
@@ -63,7 +63,7 @@ class TestGenerationTaskCreate:
voice_ids=["v1"],
created_by_user_id=" user1 ",
source_edit_plan_id=" plan1 ",
asset_select_mode="random",
asset_select_mode="smart",
batch_id="batch1",
)
assert task.project_id == "proj1"
@@ -76,7 +76,7 @@ class TestGenerationTaskCreate:
assert task.voice_ids == ["v1"]
assert task.created_by_user_id == "user1"
assert task.source_edit_plan_id == "plan1"
assert task.asset_select_mode == "random"
assert task.asset_select_mode == "smart"
assert task.batch_id == "batch1"
def test_create_with_template_instead_of_project(self):
-20
View File
@@ -97,26 +97,6 @@ class TestSelectAssetsAllMode:
assert result == []
class TestSelectAssetsRandomMode:
"""random 模式:随机选取 N 个。"""
def test_random_selects_exact_count(self):
assets = [_asset(f"a{i}", f"v{i}.mp4") for i in range(10)]
result = _select_assets_from_library(assets, mode="random", count=3)
assert len(result) == 3
assert all(rid in [a.id for a in assets] for rid in result)
def test_random_count_zero_returns_all(self):
assets = [_asset(f"a{i}", f"v{i}.mp4") for i in range(5)]
result = _select_assets_from_library(assets, mode="random", count=0)
assert len(result) == 5
def test_random_count_exceeds_total_returns_all(self):
assets = [_asset(f"a{i}", f"v{i}.mp4") for i in range(3)]
result = _select_assets_from_library(assets, mode="random", count=100)
assert len(result) == 3
class TestSelectAssetsSmartMode:
"""smart 模式:使用 smart_match 多维评分(质量40%+时长30%+新鲜度20%+未使用10%)。"""
+2 -2
View File
@@ -116,7 +116,7 @@ class TestGenerationTaskCreate:
voice_ids=["v1"],
created_by_user_id="u1",
source_edit_plan_id="ep1",
asset_select_mode="random",
asset_select_mode="smart",
batch_id="batch_001",
video_title="测试视频",
resolution="1080p",
@@ -132,7 +132,7 @@ class TestGenerationTaskCreate:
assert task.voice_ids == ["v1"]
assert task.created_by_user_id == "u1"
assert task.source_edit_plan_id == "ep1"
assert task.asset_select_mode == "random"
assert task.asset_select_mode == "smart"
assert task.batch_id == "batch_001"
assert task.video_title == "测试视频"
assert task.resolution == "1080p"