Skip to content

利用 AI 大模型和自动化工作流,根据主题或关键词一键生成高清短视频。Generate HD short videos from a topic or keyword with an automated AI workflow.

fix(cli): validate only files consumed by the requested stage

Rudy Celekli6edaf7373c19
diff --git a/cli.py b/cli.py
index fc9cc6a0..e8ecef62 100644
--- a/cli.py
+++ b/cli.py
@@ -1489,7 +1489,7 @@ def _validate_cli_files(
".flv",
}
- if params.custom_audio_file:
+ if params.custom_audio_file and stop_at not in {"script", "terms"}:
params.custom_audio_file = _resolve_cli_file(
params.custom_audio_file,
description="custom audio",
@@ -1502,7 +1502,7 @@ def _validate_cli_files(
f"allowed extensions: {allowed}"
)
- if params.bgm_type == "custom":
+ if params.bgm_type == "custom" and stop_at == "video":
if not bgm_service.should_use_bgm(params.bgm_type, params.bgm_volume):
# 0 音量时下游会统一跳过所有 BGM。这里同时清空文件参数,避免
# CLI 为一个不会被读取的文件执行路径解析、存在性检查或格式
diff --git a/test/services/test_cli.py b/test/services/test_cli.py
index 6d79746c..ac1e7c33 100644
--- a/test/services/test_cli.py
+++ b/test/services/test_cli.py
@@ -859,7 +859,7 @@ class TestCli(unittest.TestCase):
"--bgm-type",
"custom",
"--stop-at",
- "script",
+ "video",
]
)
@@ -893,13 +893,14 @@ class TestCli(unittest.TestCase):
]
)
params = cli.build_video_params(args)
+ params.subtitle_enabled = False
with patch(
"app.services.bgm.resolve_bgm_file",
side_effect=AssertionError(
"zero-volume BGM must not resolve a file"
),
) as resolver:
- cli.prepare_cli_files(params, stop_at="script")
+ cli.prepare_cli_files(params, stop_at="video")
resolver.assert_not_called()
self.assertEqual(params.bgm_file, "")
@@ -923,12 +924,13 @@ class TestCli(unittest.TestCase):
]
)
params = cli.build_video_params(args)
+ params.subtitle_enabled = False
with patch.object(
bgm_service,
"resolve_bgm_file",
return_value=resolved_path,
) as resolver:
- cli.prepare_cli_files(params, stop_at="script")
+ cli.prepare_cli_files(params, stop_at="video")
resolver.assert_called_once_with(filename)
self.assertEqual(params.bgm_file, resolved_path)
@@ -948,6 +950,7 @@ class TestCli(unittest.TestCase):
]
)
params = cli.build_video_params(args)
+ params.subtitle_enabled = False
with (
patch.object(
bgm_service,
@@ -956,7 +959,7 @@ class TestCli(unittest.TestCase):
),
self.assertRaisesRegex(ValueError, "storage/bgm or resource/songs"),
):
- cli.prepare_cli_files(params, stop_at="script")
+ cli.prepare_cli_files(params, stop_at="video")
def test_invalid_aspect_and_non_finite_numbers_are_argument_errors(self):
invalid_argvs = [
diff --git a/test/services/test_cli_stage_files.py b/test/services/test_cli_stage_files.py
new file mode 100644
index 00000000..1a80b500
--- /dev/null
+++ b/test/services/test_cli_stage_files.py
@@ -0,0 +1,52 @@
+from unittest.mock import patch
+import pytest
+import cli
+from app.models.schema import VideoParams
+
+
[email protected]("stage", ["script", "terms"])
+def test_text_only_stage_ignores_unused_custom_audio_and_bgm_paths(stage):
+ params = VideoParams(
+ video_subject="Coffee",
+ custom_audio_file="missing.wav",
+ bgm_type="custom",
+ bgm_file="missing.mp3",
+ )
+ with (
+ patch.object(
+ cli,
+ "_resolve_cli_file",
+ side_effect=AssertionError("unused audio was opened"),
+ ),
+ patch(
+ "app.services.bgm.resolve_bgm_file",
+ side_effect=AssertionError("unused music was opened"),
+ ),
+ ):
+ assert cli._validate_cli_files(params, stage) == ("", [])
+
+
[email protected]("stage", ["audio", "subtitle", "materials"])
+def test_non_video_stage_does_not_require_unused_background_music(stage):
+ params = VideoParams(
+ video_subject="Coffee", bgm_type="custom", bgm_file="missing.mp3"
+ )
+ with patch(
+ "app.services.bgm.resolve_bgm_file",
+ side_effect=AssertionError("unused music was opened"),
+ ):
+ assert cli._validate_cli_files(params, stage) == ("", [])
+
+
+def test_video_stage_still_validates_background_music():
+ params = VideoParams(
+ video_subject="Coffee",
+ bgm_type="custom",
+ bgm_file="missing.mp3",
+ subtitle_enabled=False,
+ )
+ with patch(
+ "app.services.bgm.resolve_bgm_file", side_effect=ValueError("missing music")
+ ):
+ with pytest.raises(ValueError, match="background music"):
+ cli._validate_cli_files(params, "video")