Skip to content

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

fix(project): validate bounded numbers (#1598)

Rudy Mizrahi Celekli2ffba06797cb
diff --git a/app/services/video_project.py b/app/services/video_project.py
index 533497a6..c83a7f49 100644
--- a/app/services/video_project.py
+++ b/app/services/video_project.py
@@ -138,8 +138,8 @@ class RenderSettings:
if (
isinstance(number, bool)
or not isinstance(number, (int, float))
- or not math.isfinite(number)
or not 0 <= number <= 4
+ or not math.isfinite(number)
):
raise ProjectError(f"{name} must be finite and between 0 and 4")
return result
@@ -323,8 +323,8 @@ class VideoProject:
if (
isinstance(duration, bool)
or not isinstance(duration, (int, float))
- or not math.isfinite(duration)
or not 0 < duration <= 3600
+ or not math.isfinite(duration)
):
raise ProjectError(
"scene duration must be finite and between 0 and 3600 seconds"
diff --git a/test/services/test_video_project.py b/test/services/test_video_project.py
index d29490db..bba413b0 100644
--- a/test/services/test_video_project.py
+++ b/test/services/test_video_project.py
@@ -727,3 +727,133 @@ def test_subtitle_background_retains_color_and_explicit_opacity(color, expected)
assert clip.mask.get_frame(0)[0, 0] == 0
finally:
video.close_clip(clip)
+
+
+ not shutil.which("ffmpeg") or not shutil.which("ffprobe"),
+ reason="native FFmpeg/FFprobe required; no mocked rendering claim",
+)
[email protected]("field", ["narration_volume", "bgm_volume", "duration"])
[email protected]("sign", [-1, 1])
+def test_project_cli_rejects_large_json_numbers_without_traceback(
+ tmp_path, field, sign
+):
+ import sys
+
+ media = tmp_path / "footage.mp4"
+ _media(
+ [
+ "-f",
+ "lavfi",
+ "-i",
+ "color=c=red:s=64x64:r=10:d=0.6",
+ "-c:v",
+ "libx264",
+ "-pix_fmt",
+ "yuv420p",
+ str(media),
+ ]
+ )
+ manifest = tmp_path / "manifest.json"
+ project = tmp_path / "project"
+ request = {
+ "project_id": "numbers",
+ "scenes": [{"id": "opening", "footage": str(media), "duration": 0.6}],
+ }
+ manifest.write_text(json.dumps(request), encoding="utf-8")
+ command = [
+ sys.executable,
+ "-m",
+ "app.services.video_project",
+ "--project",
+ str(project),
+ "revise",
+ str(manifest),
+ ]
+ accepted = subprocess.run(command, text=True, capture_output=True, timeout=20)
+ assert accepted.returncode == 0, accepted.stderr
+ previous = (project / "project.json").read_bytes()
+ if field == "duration":
+ request["scenes"][0][field] = sign * 10**399
+ else:
+ request["settings"] = {field: sign * 10**399}
+ manifest.write_text(json.dumps(request), encoding="utf-8")
+ rejected = subprocess.run(command, text=True, capture_output=True, timeout=20)
+ assert rejected.returncode == 1
+ assert (project / "project.json").read_bytes() == previous
+ assert rejected.stdout == ""
+ assert "Traceback" not in rejected.stderr
+ assert "video project:" in rejected.stderr
+ assert ("scene duration" if field == "duration" else field) in rejected.stderr
+
+
+ not shutil.which("ffmpeg") or not shutil.which("ffprobe"),
+ reason="native FFmpeg/FFprobe required; no mocked rendering claim",
+)
+ "field,number",
+ [
+ ("narration_volume", 4),
+ ("bgm_volume", 4),
+ ("duration", 3600),
+ ("narration_volume", 5),
+ ("bgm_volume", 5),
+ ("duration", 3601),
+ ],
+)
+def test_project_cli_numeric_bounds_controls(tmp_path, field, number):
+ import sys
+
+ media = tmp_path / "footage.mp4"
+ _media(
+ [
+ "-f",
+ "lavfi",
+ "-i",
+ "color=c=red:s=64x64:r=10:d=0.6",
+ "-c:v",
+ "libx264",
+ "-pix_fmt",
+ "yuv420p",
+ str(media),
+ ]
+ )
+ manifest = tmp_path / "manifest.json"
+ project = tmp_path / "project"
+ request = {
+ "project_id": "numbers",
+ "scenes": [{"id": "opening", "footage": str(media), "duration": 0.6}],
+ }
+ if field == "duration":
+ request["scenes"][0][field] = number
+ else:
+ request["settings"] = {field: number}
+ manifest.write_text(json.dumps(request), encoding="utf-8")
+ result = subprocess.run(
+ [
+ sys.executable,
+ "-m",
+ "app.services.video_project",
+ "--project",
+ str(project),
+ "revise",
+ str(manifest),
+ ],
+ text=True,
+ capture_output=True,
+ timeout=20,
+ )
+ if number in (4, 3600):
+ assert result.returncode == 0, result.stderr
+ spec = json.loads(result.stdout)
+ assert (
+ spec["scenes"][0][field] if field == "duration" else spec["settings"][field]
+ ) == number
+ assert project.joinpath("project.json").is_file()
+ else:
+ assert result.returncode == 1
+ assert "Traceback" not in result.stderr
+ assert "video project:" in result.stderr
+ assert ("scene duration" if field == "duration" else field) in result.stderr
+ assert not project.joinpath("project.json").exists()