World's first open-source, agentic video production system. 12 production pipelines, 100+ tools, 700+ agent skill and production-knowledge files. Turn your AI coding assistant into a full video production studio.
Python agentagentic-aiaiclaudecopilotcursorelevenlabsffmpegfluximage-generationopen-sourceopenaipythonremotionstable-diffusiontext-to-speechtext-to-videovideo-generationvideo-production
fix: isolate video trimmer concat temporary workspaces (#719)
Alex5469a4e7a2ba
diff --git a/tests/tools/test_video_trimmer_workspaces.py b/tests/tools/test_video_trimmer_workspaces.pynew file mode 100644index 00000000..6d442b04--- /dev/null+++ b/tests/tools/test_video_trimmer_workspaces.py@@ -0,0 +1,63 @@+"""Concat calls must own their temporary files, including failed partial cuts."""+from pathlib import Path+from unittest.mock import patch++from tools.video.video_trimmer import VideoTrimmer+++def test_nested_concat_keeps_outer_file_list(tmp_path):+ source = tmp_path / "source.mp4"+ source.write_bytes(b"source")+ lists = []+ tool = VideoTrimmer()++ def run(cmd):+ file_list = Path(cmd[cmd.index("-i") + 1])+ lists.append(file_list)+ if len(lists) == 1:+ inner = tool.execute({"operation": "concat", "segments": [{"input_path": str(source)}],+ "output_path": str(tmp_path / "inner.mp4")})+ assert inner.success, inner.error+ assert file_list.exists()+ assert source.resolve().as_posix() in file_list.read_text()++ with patch.object(tool, "run_command", side_effect=run):+ result = tool.execute({"operation": "concat", "segments": [{"input_path": str(source)}],+ "output_path": str(tmp_path / "outer.mp4")})+ assert result.success, result.error+ assert lists[0].parent != lists[1].parent+ assert all(not path.parent.exists() for path in lists)+ assert source.read_bytes() == b"source"+++def test_partial_cut_is_removed_without_masking_error(tmp_path):+ source = tmp_path / "source.mp4"+ source.touch()+ partials = []++ def fail(cmd):+ partial = Path(cmd[-1])+ partial.write_bytes(b"partial")+ partials.append(partial)+ raise RuntimeError("cut failed")++ tool = VideoTrimmer()+ with patch.object(tool, "run_command", side_effect=fail):+ result = tool.execute({"operation": "concat", "segments": [{"input_path": str(source), "start_seconds": 1}],+ "output_path": str(tmp_path / "output.mp4")})+ assert not result.success+ assert result.error == "cut failed"+ assert not partials[0].parent.exists()+++def test_existing_concat_directory_is_not_owned_by_call(tmp_path):+ directory = tmp_path / ".concat_tmp"+ directory.mkdir()+ source = directory / "original.mp4"+ source.write_bytes(b"original")+ tool = VideoTrimmer()+ with patch.object(tool, "run_command"):+ result = tool.execute({"operation": "concat", "segments": [{"input_path": str(source)}],+ "output_path": str(tmp_path / "output.mp4")})+ assert result.success, result.error+ assert source.read_bytes() == b"original"diff --git a/tools/video/video_trimmer.py b/tools/video/video_trimmer.pyindex 65eda5c4..9fdbfe0d 100644--- a/tools/video/video_trimmer.py+++ b/tools/video/video_trimmer.py@@ -9,6 +9,7 @@ from __future__ import annotationsimport jsonimport time+import tempfilefrom pathlib import Pathfrom typing import Any@@ -188,10 +189,9 @@ class VideoTrimmer(BaseTool):# First, cut each segment to a temp file if start/end are specifiedtemp_files: list[Path] = []- temp_dir = output_path.parent / ".concat_tmp"- temp_dir.mkdir(parents=True, exist_ok=True)-- try:+ output_path.parent.mkdir(parents=True, exist_ok=True)+ with tempfile.TemporaryDirectory(prefix=".concat-", dir=output_path.parent) as workspace:+ temp_dir = Path(workspace)for i, seg in enumerate(segments):seg_input = Path(seg["input_path"])if not seg_input.exists():@@ -239,18 +239,6 @@ class VideoTrimmer(BaseTool):},artifacts=[str(output_path)],)- finally:- # Clean up temp segment files (but not the originals)- for tf in temp_files:- if tf.parent == temp_dir and tf.exists():- tf.unlink()- if list_path.exists():- list_path.unlink()- if temp_dir.exists():- try:- temp_dir.rmdir()- except OSError:- pass@staticmethoddef _build_atempo_chain(factor: float) -> str: