Some checks are pending
build-images / api (push) Waiting to run
build-images / worker-gpu (push) Waiting to run
build-images / web (push) Waiting to run
codeql / Analyze (javascript-typescript) (push) Waiting to run
codeql / Analyze (python) (push) Waiting to run
perf / API hot-path micro-smoke (budgeted) (push) Waiting to run
perf / Desktop engine crates (release build check) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (comfy-workflow-schema) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (effects-core) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (eventbus-types) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (growth-analytics) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (trends-schema) (push) Waiting to run
vision2026-ci / API phase modules (ruff + pytest) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (provider-adapter-kit) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (publishing-connectors) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (render-core) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (shot-template-schema) (push) Waiting to run
vision2026-ci / Python SDK resource tests (push) Waiting to run
vision2026-ci / Desktop engine crates (test + clippy + fmt) (push) Waiting to run
vision2026-ci / Alembic upgrade + drift check (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (caption-engine) (push) Waiting to run
Paid, hosted product at menivor.com, now retired as a company project. Fresh squashed history of the cleaned working tree (secret-scanned, no .env, no customer data, no outreach logs). Built on MoneyPrinterTurbo (MIT, harry0703) — see NOTICE.
167 lines
5.5 KiB
Python
167 lines
5.5 KiB
Python
import ast
|
|
import os
|
|
import re
|
|
from collections.abc import Mapping
|
|
from pathlib import Path
|
|
|
|
|
|
ROOT_DIR = Path(__file__).parent.parent.parent
|
|
WEBUI_MAIN = ROOT_DIR / "webui" / "Main.py"
|
|
TASK_HISTORY_HELPERS = {
|
|
"_find_final_task_video",
|
|
"_build_video_download_name",
|
|
"_build_restore_upload_requirements",
|
|
"_get_unmet_restore_upload_requirements",
|
|
}
|
|
TASK_HISTORY_CONSTANTS = {
|
|
"_FINAL_VIDEO_PATTERN",
|
|
"_DOWNLOAD_FILENAME_INVALID_PATTERN",
|
|
"VOICE_MODE_TTS",
|
|
"VOICE_MODE_UPLOAD",
|
|
"VOICE_MODE_NONE",
|
|
}
|
|
|
|
|
|
def _load_task_history_helpers():
|
|
"""
|
|
从 WebUI 入口中隔离加载不依赖 Streamlit 的任务历史纯函数。
|
|
|
|
直接导入 Main.py 会执行整套页面渲染。测试只编译目标常量和函数,既验证
|
|
合并后的真实实现,也避免为了单元测试重新拆出一个只有少量函数的生产模块。
|
|
"""
|
|
tree = ast.parse(WEBUI_MAIN.read_text(encoding="utf-8"))
|
|
selected_nodes = []
|
|
for node in tree.body:
|
|
if isinstance(node, ast.Assign) and any(
|
|
isinstance(target, ast.Name) and target.id in TASK_HISTORY_CONSTANTS
|
|
for target in node.targets
|
|
):
|
|
selected_nodes.append(node)
|
|
elif isinstance(node, ast.FunctionDef) and node.name in TASK_HISTORY_HELPERS:
|
|
selected_nodes.append(node)
|
|
|
|
namespace = {"os": os, "re": re, "Mapping": Mapping}
|
|
module = ast.fix_missing_locations(ast.Module(body=selected_nodes, type_ignores=[]))
|
|
exec(compile(module, str(WEBUI_MAIN), "exec"), namespace)
|
|
return namespace
|
|
|
|
|
|
TASK_HISTORY_NAMESPACE = _load_task_history_helpers()
|
|
find_final_task_video = TASK_HISTORY_NAMESPACE["_find_final_task_video"]
|
|
build_video_download_name = TASK_HISTORY_NAMESPACE["_build_video_download_name"]
|
|
build_restore_upload_requirements = TASK_HISTORY_NAMESPACE[
|
|
"_build_restore_upload_requirements"
|
|
]
|
|
get_unmet_restore_upload_requirements = TASK_HISTORY_NAMESPACE[
|
|
"_get_unmet_restore_upload_requirements"
|
|
]
|
|
|
|
|
|
def test_find_final_task_video_ignores_intermediate_files(tmp_path):
|
|
"""任务历史只能把 final 成片识别为完成,不能使用合成中间文件。"""
|
|
for file_name in (
|
|
"combined-1.mp4",
|
|
"temp-clip-1.mp4",
|
|
"final-1TEMP_MPY_wvf_snd.mp4",
|
|
):
|
|
(tmp_path / file_name).touch()
|
|
|
|
assert find_final_task_video(str(tmp_path)) == ""
|
|
|
|
|
|
def test_find_final_task_video_returns_first_numbered_output(tmp_path):
|
|
"""多成片任务与运行时结果保持一致,默认播放序号最小的最终视频。"""
|
|
(tmp_path / "final-10.mp4").touch()
|
|
(tmp_path / "final-2.mp4").touch()
|
|
(tmp_path / "final-1.mp4").touch()
|
|
|
|
assert find_final_task_video(str(tmp_path)) == str(tmp_path / "final-1.mp4")
|
|
|
|
|
|
def test_build_video_download_name_uses_subject_and_output_index():
|
|
assert (
|
|
build_video_download_name("A day: in / Shanghai?", 2, 3)
|
|
== "A day in Shanghai-2.mp4"
|
|
)
|
|
|
|
|
|
def test_build_video_download_name_handles_empty_and_long_subjects():
|
|
assert build_video_download_name(" ... ", 1, 1) == "video.mp4"
|
|
assert len(build_video_download_name("a" * 100, 1, 1)) == 84
|
|
|
|
|
|
def test_restore_requirements_block_missing_uploaded_files():
|
|
params = {
|
|
"video_source": "local",
|
|
"custom_audio_file": "/old-task/custom-audio.wav",
|
|
"voice_name": "zh-CN-XiaoxiaoNeural-Female",
|
|
}
|
|
requirements = build_restore_upload_requirements(params)
|
|
|
|
assert get_unmet_restore_upload_requirements(
|
|
requirements,
|
|
video_source="local",
|
|
voice_name=params["voice_name"],
|
|
has_local_materials=False,
|
|
has_custom_audio=False,
|
|
) == {"local_materials", "custom_audio"}
|
|
|
|
|
|
def test_restore_requirements_allow_explicit_replacements():
|
|
requirements = build_restore_upload_requirements(
|
|
{
|
|
"video_source": "local",
|
|
"custom_audio_file": "/old-task/custom-audio.wav",
|
|
"voice_name": "zh-CN-XiaoxiaoNeural-Female",
|
|
}
|
|
)
|
|
|
|
assert not get_unmet_restore_upload_requirements(
|
|
requirements,
|
|
video_source="pexels",
|
|
voice_name="en-US-JennyNeural-Female",
|
|
has_local_materials=False,
|
|
has_custom_audio=False,
|
|
)
|
|
|
|
|
|
def test_restore_requirements_require_file_in_upload_voice_mode():
|
|
"""恢复上传配音任务时,继续使用上传模式必须重新选择音频文件。"""
|
|
requirements = build_restore_upload_requirements(
|
|
{
|
|
"video_source": "pexels",
|
|
"custom_audio_file": "/old-task/custom-audio.wav",
|
|
"voice_name": "zh-CN-XiaoxiaoNeural-Female",
|
|
}
|
|
)
|
|
|
|
assert get_unmet_restore_upload_requirements(
|
|
requirements,
|
|
video_source="pexels",
|
|
voice_name="zh-CN-XiaoxiaoNeural-Female",
|
|
has_local_materials=False,
|
|
has_custom_audio=False,
|
|
voice_mode="upload",
|
|
) == {"custom_audio"}
|
|
|
|
|
|
def test_restore_requirements_allow_replacing_upload_with_other_voice_modes():
|
|
"""用户主动切换到自动配音或无配音时,不再强制恢复历史上传文件。"""
|
|
requirements = build_restore_upload_requirements(
|
|
{
|
|
"video_source": "pexels",
|
|
"custom_audio_file": "/old-task/custom-audio.wav",
|
|
"voice_name": "zh-CN-XiaoxiaoNeural-Female",
|
|
}
|
|
)
|
|
|
|
for voice_mode in ("tts", "none"):
|
|
assert not get_unmet_restore_upload_requirements(
|
|
requirements,
|
|
video_source="pexels",
|
|
voice_name="zh-CN-XiaoxiaoNeural-Female",
|
|
has_local_materials=False,
|
|
has_custom_audio=False,
|
|
voice_mode=voice_mode,
|
|
)
|