From 9058cf061d481fb0ca9678c3777555d495115597 Mon Sep 17 00:00:00 2001 From: Robert Wojciechowski Date: Sat, 28 Feb 2026 00:02:31 +0000 Subject: [PATCH] fix: sync audio media refs for worker prompt validation --- api/orchestration/media_sync.py | 15 ++++++++------- tests/api/test_media_sync.py | 14 +++++++++++++- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/api/orchestration/media_sync.py b/api/orchestration/media_sync.py index 24223e1..877d4ed 100644 --- a/api/orchestration/media_sync.py +++ b/api/orchestration/media_sync.py @@ -12,12 +12,13 @@ from ...utils.trace_logger import trace_debug, trace_info LIKELY_FILENAME_RE = re.compile( - r"\.(ckpt|safetensors|pt|pth|bin|yaml|json|png|jpg|jpeg|webp|gif|bmp|latent|txt|vae|lora|embedding)" + r"\.(ckpt|safetensors|pt|pth|bin|yaml|json|png|jpg|jpeg|webp|gif|bmp|mp4|avi|mov|mkv|webm|" + r"wav|mp3|flac|m4a|aac|ogg|opus|aiff|aif|wma|latent|txt|vae|lora|embedding)" r"(\s*\[\w+\])?$", re.IGNORECASE, ) -IMAGE_OR_VIDEO_RE = re.compile( - r"\.(png|jpg|jpeg|webp|gif|bmp|mp4|avi|mov|mkv|webm)(\s*\[\w+\])?$", +MEDIA_FILE_RE = re.compile( + r"\.(png|jpg|jpeg|webp|gif|bmp|mp4|avi|mov|mkv|webm|wav|mp3|flac|m4a|aac|ogg|opus|aiff|aif|wma)(\s*\[\w+\])?$", re.IGNORECASE, ) @@ -39,7 +40,7 @@ def convert_paths_for_platform(obj, target_separator): return trimmed # Keep relative media-style paths in forward-slash form (Comfy-style annotated paths). - if not has_drive and not is_absolute and not has_protocol and IMAGE_OR_VIDEO_RE.search(trimmed): + if not has_drive and not is_absolute and not has_protocol and MEDIA_FILE_RE.search(trimmed): return re.sub(r"[\\]+", "/", trimmed) if target_separator == "\\": @@ -56,17 +57,17 @@ def convert_paths_for_platform(obj, target_separator): def _find_media_references(prompt_obj): - """Find media file references in image/video inputs used by worker prompts.""" + """Find media file references in image/video/audio inputs used by worker prompts.""" media_refs = set() for node in prompt_obj.values(): if not isinstance(node, dict): continue inputs = node.get("inputs", {}) - for key in ("image", "video"): + for key in ("image", "video", "audio"): value = inputs.get(key) if isinstance(value, str): cleaned = re.sub(r"\s*\[\w+\]$", "", value).strip().replace("\\", "/") - if IMAGE_OR_VIDEO_RE.search(cleaned): + if MEDIA_FILE_RE.search(cleaned): media_refs.add(cleaned) return sorted(media_refs) diff --git a/tests/api/test_media_sync.py b/tests/api/test_media_sync.py index f402f37..99cabf1 100644 --- a/tests/api/test_media_sync.py +++ b/tests/api/test_media_sync.py @@ -99,11 +99,16 @@ class ConvertPathsForPlatformTests(unittest.TestCase): self.assertNotIn("/", result["ckpt_name"]) def test_relative_media_paths_always_stay_forward_slash(self): - """Relative image/video paths (Comfy annotated style) must not be backslash-ified.""" + """Relative image/video/audio paths (Comfy annotated style) must not be backslash-ified.""" obj = {"image": "subfolder/my_photo.png"} result = ms.convert_paths_for_platform(obj, "\\") self.assertEqual(result["image"], "subfolder/my_photo.png") + def test_relative_audio_paths_stay_forward_slash(self): + obj = {"audio": "subfolder/my_track.wav"} + result = ms.convert_paths_for_platform(obj, "\\") + self.assertEqual(result["audio"], "subfolder/my_track.wav") + def test_annotated_relative_media_path_stays_forward_slash(self): obj = {"image": "input/frame.jpg [abc123]"} result = ms.convert_paths_for_platform(obj, "\\") @@ -169,6 +174,11 @@ class FindMediaReferencesTests(unittest.TestCase): refs = ms._find_media_references(prompt) self.assertIn("clip.mp4", refs) + def test_finds_audio_input(self): + prompt = {"1": {"class_type": "LoadAudio", "inputs": {"audio": "track.wav"}}} + refs = ms._find_media_references(prompt) + self.assertIn("track.wav", refs) + def test_strips_annotation_suffix(self): prompt = {"1": {"class_type": "LoadImage", "inputs": {"image": "photo.jpg [abc123]"}}} refs = ms._find_media_references(prompt) @@ -219,10 +229,12 @@ class FindMediaReferencesTests(unittest.TestCase): prompt = { "1": {"class_type": "LoadImage", "inputs": {"image": "frame.png"}}, "2": {"class_type": "LoadVideo", "inputs": {"video": "clip.mp4"}}, + "3": {"class_type": "LoadAudio", "inputs": {"audio": "track.wav"}}, } refs = ms._find_media_references(prompt) self.assertIn("frame.png", refs) self.assertIn("clip.mp4", refs) + self.assertIn("track.wav", refs) if __name__ == "__main__":