diff --git a/.gitignore b/.gitignore index fae5801..e313912 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,12 @@ node_modules/ apps/studio/dist/ .DS_Store .cursor/ +# Bytecode / local caches (never commit) +__pycache__/ +*.py[cod] +*.tsbuildinfo +ext_weights/ +.ci-investigate/ *.wav *.mp3 *.mp4 diff --git a/packages/executor/src/groovy/executor/__init__.py b/packages/executor/src/groovy/executor/__init__.py index e603c5f..65dd0df 100644 --- a/packages/executor/src/groovy/executor/__init__.py +++ b/packages/executor/src/groovy/executor/__init__.py @@ -1,5 +1,5 @@ from groovy.executor.audio import AudioBuffer -from groovy.executor.cache import CacheStore +from groovy.executor.cache import CacheStore, safe_cache_id from groovy.executor.engine import ExecutionResult, Executor, JobContext from groovy.executor.signal_integrity import ( ALL_TEMPLATE_INTEGRITY_SPECS, @@ -21,6 +21,7 @@ __all__ = [ "AudioBuffer", "CacheStore", + "safe_cache_id", "ExecutionResult", "Executor", "JobContext", diff --git a/packages/executor/src/groovy/executor/cache.py b/packages/executor/src/groovy/executor/cache.py index 473208b..62c64dd 100644 --- a/packages/executor/src/groovy/executor/cache.py +++ b/packages/executor/src/groovy/executor/cache.py @@ -2,6 +2,7 @@ import hashlib import json +import re from pathlib import Path from typing import Any @@ -17,6 +18,20 @@ from groovy.executor.image import ImageClip from groovy.executor.video import VideoClip +# uuid4, short fixture ids (e.g. left/right), and similar; reject path separators / ``..``. +_SAFE_CACHE_ID = re.compile(r"^[A-Za-z0-9][A-Za-z0-9_-]{0,127}$") + + +def safe_cache_id(cache_id: str) -> str: + """Allowlist cache / report ids used under ``.groovy/cache/`` (path-jail).""" + if not isinstance(cache_id, str) or not cache_id.strip(): + raise ValueError("Invalid cache_id: empty") + if "/" in cache_id or "\\" in cache_id or ".." in cache_id: + raise ValueError(f"Invalid cache_id: {cache_id!r}") + if not _SAFE_CACHE_ID.fullmatch(cache_id): + raise ValueError(f"Invalid cache_id: {cache_id!r}") + return cache_id + class CacheStore: def __init__(self, project_dir: Path) -> None: @@ -26,20 +41,31 @@ def __init__(self, project_dir: Path) -> None: self.cache_dir.mkdir(parents=True, exist_ok=True) self.runs_dir.mkdir(parents=True, exist_ok=True) + def _cache_file(self, cache_id: str, suffix: str) -> Path: + """Return ``cache_dir / {safe_id}{suffix}`` after allowlist + resolve jail.""" + cid = safe_cache_id(cache_id) + if not suffix.startswith("."): + raise ValueError(f"Invalid cache suffix: {suffix!r}") + cache_root = self.cache_dir.resolve() + path = (self.cache_dir / f"{cid}{suffix}").resolve() + if not path.is_relative_to(cache_root): + raise ValueError(f"Invalid cache_id: {cache_id!r}") + return path + def resolve_project_path(self, relative: str) -> Path: candidate = (self.project_dir / relative).resolve() - if not str(candidate).startswith(str(self.project_dir)): + if not candidate.is_relative_to(self.project_dir): raise ValueError(f"Path escapes project directory: {relative}") return candidate def write_audio(self, buffer: AudioBuffer, pcm: np.ndarray) -> AudioBuffer: - f64_path = self.cache_dir / f"{buffer.id}.f64" + f64_path = self._cache_file(buffer.id, ".f64") pcm = np.asarray(pcm, dtype=np.float64) if pcm.ndim == 1: pcm = pcm.reshape(1, -1) pcm.tofile(f64_path) - meta_path = self.cache_dir / f"{buffer.id}.meta.json" + meta_path = self._cache_file(buffer.id, ".meta.json") buffer.path = str(f64_path) meta_path.write_text(json.dumps(buffer.to_meta(), indent=2)) @@ -48,12 +74,12 @@ def write_audio(self, buffer: AudioBuffer, pcm: np.ndarray) -> AudioBuffer: def write_stems(self, stems: StemsBuffer, stem_pcm: dict[str, np.ndarray]) -> StemsBuffer: for name, buffer in stems.stems.items(): self.write_audio(buffer, stem_pcm[name]) - meta_path = self.cache_dir / f"{stems.id}.stems.meta.json" + meta_path = self._cache_file(stems.id, ".stems.meta.json") meta_path.write_text(json.dumps(stems.to_meta(), indent=2)) return stems def load_stems(self, stems_id: str) -> StemsBuffer: - meta_path = self.cache_dir / f"{stems_id}.stems.meta.json" + meta_path = self._cache_file(stems_id, ".stems.meta.json") if not meta_path.exists(): raise FileNotFoundError(f"Stems cache not found: {stems_id}") meta = json.loads(meta_path.read_text()) @@ -70,7 +96,7 @@ def load_stems(self, stems_id: str) -> StemsBuffer: ) def read_meta(self, cache_id: str) -> dict: - meta_path = self.cache_dir / f"{cache_id}.meta.json" + meta_path = self._cache_file(cache_id, ".meta.json") if not meta_path.exists(): raise FileNotFoundError(f"Cache entry not found: {cache_id}") return json.loads(meta_path.read_text()) @@ -89,7 +115,7 @@ def load_audio(self, cache_id: str) -> tuple[AudioBuffer, np.ndarray]: file_format=meta.get("file_format"), file_subtype=meta.get("file_subtype"), spatial_meta=meta.get("spatial_meta", {}), - path=str(self.cache_dir / f"{cache_id}.f64"), + path=str(self._cache_file(cache_id, ".f64")), source_node=meta.get("source_node"), source_node_type=meta.get("source_node_type"), content_hash=meta.get("content_hash"), @@ -98,11 +124,11 @@ def load_audio(self, cache_id: str) -> tuple[AudioBuffer, np.ndarray]: return buffer, pcm def write_provenance(self, cache_id: str, record: dict) -> None: - path = self.cache_dir / f"{cache_id}.provenance.json" + path = self._cache_file(cache_id, ".provenance.json") path.write_text(json.dumps(record, indent=2)) def read_provenance(self, cache_id: str) -> dict | None: - path = self.cache_dir / f"{cache_id}.provenance.json" + path = self._cache_file(cache_id, ".provenance.json") if not path.exists(): return None return json.loads(path.read_text()) @@ -188,19 +214,19 @@ def export_provenance_sidecar( return sidecar def write_midi(self, midi: MidiBuffer, midi_bytes: bytes | None = None) -> MidiBuffer: - mid_path = self.cache_dir / f"{midi.id}.mid" + mid_path = self._cache_file(midi.id, ".mid") if midi_bytes is not None: mid_path.write_bytes(midi_bytes) midi.path = str(mid_path) elif midi.path is None: # Keep intentional empty-string placeholders (optional LoadMIDI) as "". midi.path = str(mid_path) if mid_path.exists() else None - meta_path = self.cache_dir / f"{midi.id}.midi.meta.json" + meta_path = self._cache_file(midi.id, ".midi.meta.json") meta_path.write_text(json.dumps(midi.to_meta(), indent=2)) return midi def load_midi(self, midi_id: str) -> MidiBuffer: - meta_path = self.cache_dir / f"{midi_id}.midi.meta.json" + meta_path = self._cache_file(midi_id, ".midi.meta.json") if not meta_path.exists(): raise FileNotFoundError(f"MIDI cache not found: {midi_id}") meta = json.loads(meta_path.read_text()) @@ -220,7 +246,7 @@ def load_midi(self, midi_id: str) -> MidiBuffer: def midi_roll(self, midi_id: str) -> dict: midi = self.load_midi(midi_id) - mid_path = self.cache_dir / f"{midi_id}.mid" + mid_path = self._cache_file(midi_id, ".mid") duration = midi.frame_count / max(midi.sample_rate, 1) notes: list[dict] = [] # Empty LoadMIDI placeholder — no SMF on disk yet. @@ -265,22 +291,22 @@ def midi_preview_wav_bytes(self, midi_id: str, *, sample_rate: int = 48_000) -> from groovy.executor.midi_synth import synthesize_midi_pcm midi = self.load_midi(midi_id) - mid_path = self.cache_dir / f"{midi_id}.mid" + mid_path = self._cache_file(midi_id, ".mid") pcm = synthesize_midi_pcm(midi, sample_rate=sample_rate, mid_path=mid_path) buf = io.BytesIO() sf.write(buf, pcm.reshape(-1), sample_rate, format="WAV", subtype="FLOAT") return buf.getvalue() def is_midi_cache(self, cache_id: str) -> bool: - return (self.cache_dir / f"{cache_id}.midi.meta.json").exists() + return (self._cache_file(cache_id, ".midi.meta.json")).exists() def write_authenticity(self, report: AuthenticityReport) -> AuthenticityReport: - meta_path = self.cache_dir / f"{report.id}.authenticity.json" + meta_path = self._cache_file(report.id, ".authenticity.json") meta_path.write_text(json.dumps(report.to_meta(), indent=2)) return report def load_authenticity(self, report_id: str) -> AuthenticityReport: - meta_path = self.cache_dir / f"{report_id}.authenticity.json" + meta_path = self._cache_file(report_id, ".authenticity.json") if not meta_path.exists(): raise FileNotFoundError(f"Authenticity report not found: {report_id}") meta = json.loads(meta_path.read_text()) @@ -292,14 +318,14 @@ def write_sample_check(self, report: Any) -> Any: if not isinstance(report, SampleCheckReport): raise TypeError("write_sample_check expects SampleCheckReport") - meta_path = self.cache_dir / f"{report.id}.sample_check.json" + meta_path = self._cache_file(report.id, ".sample_check.json") meta_path.write_text(json.dumps(report.to_meta(), indent=2)) return report def load_sample_check(self, report_id: str) -> Any: from groovy.executor.sample_integrity import SampleCheckReport - meta_path = self.cache_dir / f"{report_id}.sample_check.json" + meta_path = self._cache_file(report_id, ".sample_check.json") if not meta_path.exists(): raise FileNotFoundError(f"Sample check report not found: {report_id}") meta = json.loads(meta_path.read_text()) @@ -311,14 +337,14 @@ def write_generate_log(self, report: Any) -> Any: if not isinstance(report, GenerateLogReport): raise TypeError("write_generate_log expects GenerateLogReport") - meta_path = self.cache_dir / f"{report.id}.generate_log.json" + meta_path = self._cache_file(report.id, ".generate_log.json") meta_path.write_text(json.dumps(report.to_meta(), indent=2)) return report def load_generate_log(self, report_id: str) -> Any: from groovy.executor.generate_log import GenerateLogReport - meta_path = self.cache_dir / f"{report_id}.generate_log.json" + meta_path = self._cache_file(report_id, ".generate_log.json") if not meta_path.exists(): raise FileNotFoundError(f"Generate log not found: {report_id}") meta = json.loads(meta_path.read_text()) @@ -326,25 +352,25 @@ def load_generate_log(self, report_id: str) -> Any: return GenerateLogReport(id=meta["id"], record=record) def write_automation(self, curve: AutomationBuffer) -> AutomationBuffer: - f64_path = self.cache_dir / f"{curve.id}.automation.f64" + f64_path = self._cache_file(curve.id, ".automation.f64") curve.values.astype(np.float64).tofile(f64_path) curve.path = str(f64_path) - meta_path = self.cache_dir / f"{curve.id}.automation.meta.json" + meta_path = self._cache_file(curve.id, ".automation.meta.json") meta_path.write_text(json.dumps(curve.to_meta(), indent=2)) return curve def load_automation(self, automation_id: str) -> AutomationBuffer: - meta_path = self.cache_dir / f"{automation_id}.automation.meta.json" + meta_path = self._cache_file(automation_id, ".automation.meta.json") if not meta_path.exists(): raise FileNotFoundError(f"Automation cache not found: {automation_id}") meta = json.loads(meta_path.read_text()) - values = np.fromfile(self.cache_dir / f"{automation_id}.automation.f64", dtype=np.float64) + values = np.fromfile(self._cache_file(automation_id, ".automation.f64"), dtype=np.float64) return AutomationBuffer( id=meta["id"], sample_rate=meta["sample_rate"], frame_count=meta["frame_count"], values=values, - path=str(self.cache_dir / f"{automation_id}.automation.f64"), + path=str(self._cache_file(automation_id, ".automation.f64")), source_node_type=meta.get("source_node_type"), ) @@ -537,7 +563,7 @@ def spectrogram_tiles( } def write_trajectory(self, trajectory: TrajectoryBuffer) -> TrajectoryBuffer: - points_path = self.cache_dir / f"{trajectory.id}.trajectory.json" + points_path = self._cache_file(trajectory.id, ".trajectory.json") payload = { "points": trajectory.points, "source": trajectory.source, @@ -546,18 +572,18 @@ def write_trajectory(self, trajectory: TrajectoryBuffer) -> TrajectoryBuffer: } points_path.write_text(json.dumps(payload, indent=2)) trajectory.path = str(points_path) - meta_path = self.cache_dir / f"{trajectory.id}.meta.json" + meta_path = self._cache_file(trajectory.id, ".meta.json") meta_path.write_text(json.dumps(trajectory.to_meta(), indent=2)) return trajectory def load_trajectory(self, trajectory_id: str) -> TrajectoryBuffer: - meta_path = self.cache_dir / f"{trajectory_id}.meta.json" + meta_path = self._cache_file(trajectory_id, ".meta.json") if not meta_path.exists(): raise FileNotFoundError(f"Trajectory cache not found: {trajectory_id}") meta = json.loads(meta_path.read_text()) if meta.get("type") != "TRAJECTORY": raise ValueError(f"Cache entry is not a trajectory: {trajectory_id}") - points_path = self.cache_dir / f"{trajectory_id}.trajectory.json" + points_path = self._cache_file(trajectory_id, ".trajectory.json") if not points_path.exists(): raise FileNotFoundError(f"Trajectory points not found: {trajectory_id}") payload = json.loads(points_path.read_text()) @@ -574,13 +600,13 @@ def load_trajectory(self, trajectory_id: str) -> TrajectoryBuffer: ) def write_ambisonics(self, buffer: AmbisonicBuffer, pcm: np.ndarray) -> AmbisonicBuffer: - f64_path = self.cache_dir / f"{buffer.id}.ambi.f64" + f64_path = self._cache_file(buffer.id, ".ambi.f64") pcm = np.asarray(pcm, dtype=np.float64) if pcm.ndim == 1: pcm = pcm.reshape(1, -1) pcm.tofile(f64_path) buffer.path = str(f64_path) - meta_path = self.cache_dir / f"{buffer.id}.meta.json" + meta_path = self._cache_file(buffer.id, ".meta.json") meta_path.write_text(json.dumps(buffer.to_meta(), indent=2)) return buffer @@ -594,7 +620,7 @@ def load_ambisonics(self, ambisonics_id: str) -> tuple[AmbisonicBuffer, np.ndarr frame_count=meta["frame_count"], layout_order=meta.get("layout_order", 1), channels=meta.get("channels", 4), - path=str(self.cache_dir / f"{ambisonics_id}.ambi.f64"), + path=str(self._cache_file(ambisonics_id, ".ambi.f64")), source_node_type=meta.get("source_node_type"), spatial_meta=meta.get("spatial_meta", {}), ) @@ -602,12 +628,12 @@ def load_ambisonics(self, ambisonics_id: str) -> tuple[AmbisonicBuffer, np.ndarr return buffer, pcm def write_object_scene(self, scene: ObjectScene) -> ObjectScene: - meta_path = self.cache_dir / f"{scene.id}.oba.json" + meta_path = self._cache_file(scene.id, ".oba.json") meta_path.write_text(json.dumps(scene.to_meta(), indent=2)) return scene def load_object_scene(self, scene_id: str) -> ObjectScene: - meta_path = self.cache_dir / f"{scene_id}.oba.json" + meta_path = self._cache_file(scene_id, ".oba.json") if not meta_path.exists(): raise FileNotFoundError(f"Object scene not found: {scene_id}") meta = json.loads(meta_path.read_text()) @@ -623,12 +649,12 @@ def load_object_scene(self, scene_id: str) -> ObjectScene: ) def write_osc(self, buffer: OscBuffer) -> OscBuffer: - meta_path = self.cache_dir / f"{buffer.id}.osc.json" + meta_path = self._cache_file(buffer.id, ".osc.json") meta_path.write_text(json.dumps({**buffer.to_meta(), "events": buffer.events}, indent=2)) return buffer def load_osc(self, osc_id: str) -> OscBuffer: - meta_path = self.cache_dir / f"{osc_id}.osc.json" + meta_path = self._cache_file(osc_id, ".osc.json") if not meta_path.exists(): raise FileNotFoundError(f"OSC cache not found: {osc_id}") meta = json.loads(meta_path.read_text()) @@ -641,7 +667,7 @@ def load_osc(self, osc_id: str) -> OscBuffer: ) def write_image(self, clip: ImageClip) -> ImageClip: - meta_path = self.cache_dir / f"{clip.id}.image.json" + meta_path = self._cache_file(clip.id, ".image.json") meta_path.write_text( json.dumps( { @@ -657,7 +683,7 @@ def write_image(self, clip: ImageClip) -> ImageClip: return clip def load_image(self, image_id: str) -> ImageClip: - meta_path = self.cache_dir / f"{image_id}.image.json" + meta_path = self._cache_file(image_id, ".image.json") if not meta_path.exists(): raise FileNotFoundError(f"Image cache not found: {image_id}") meta = json.loads(meta_path.read_text()) @@ -670,7 +696,7 @@ def load_image(self, image_id: str) -> ImageClip: ) def write_video(self, clip: VideoClip) -> VideoClip: - meta_path = self.cache_dir / f"{clip.id}.video.json" + meta_path = self._cache_file(clip.id, ".video.json") meta_path.write_text( json.dumps( { @@ -688,7 +714,7 @@ def write_video(self, clip: VideoClip) -> VideoClip: return clip def load_video(self, video_id: str) -> VideoClip: - meta_path = self.cache_dir / f"{video_id}.video.json" + meta_path = self._cache_file(video_id, ".video.json") if not meta_path.exists(): raise FileNotFoundError(f"Video cache not found: {video_id}") meta = json.loads(meta_path.read_text()) diff --git a/server/src/groovy/server/main.py b/server/src/groovy/server/main.py index 7fa5fdb..6d8401c 100644 --- a/server/src/groovy/server/main.py +++ b/server/src/groovy/server/main.py @@ -1800,7 +1800,10 @@ def workflow_provenance(body: ProvenanceRequest) -> dict[str, Any]: @app.get("/api/cache/{cache_id}/provenance") def cache_provenance(cache_id: str) -> dict[str, Any]: - record = _executor.cache.read_provenance(cache_id) + try: + record = _executor.cache.read_provenance(cache_id) + except ValueError as exc: + raise HTTPException(status_code=400, detail=str(exc)) from exc if not record: raise HTTPException(status_code=404, detail="Provenance not found") return record @@ -1810,6 +1813,8 @@ def cache_provenance(cache_id: str) -> dict[str, Any]: def get_authenticity(report_id: str) -> JSONResponse: try: report = _executor.cache.load_authenticity(report_id) + except ValueError as exc: + raise HTTPException(status_code=400, detail=str(exc)) from exc except FileNotFoundError as exc: raise HTTPException(status_code=404, detail="Authenticity report not found") from exc return JSONResponse(report.record, headers={"Cache-Control": "no-store"}) @@ -1819,6 +1824,8 @@ def get_authenticity(report_id: str) -> JSONResponse: def get_sample_check(report_id: str) -> JSONResponse: try: report = _executor.cache.load_sample_check(report_id) + except ValueError as exc: + raise HTTPException(status_code=400, detail=str(exc)) from exc except FileNotFoundError as exc: raise HTTPException(status_code=404, detail="Sample check report not found") from exc return JSONResponse(report.record, headers={"Cache-Control": "no-store"}) @@ -1986,6 +1993,8 @@ def cache_metrics(cache_id: str) -> dict[str, Any]: try: metrics = measure_clip(_executor.cache, cache_id, label=cache_id) return metrics.to_dict() + except ValueError as exc: + raise HTTPException(status_code=400, detail=str(exc)) from exc except FileNotFoundError as exc: raise HTTPException(status_code=404, detail="Cache not found") from exc @@ -1994,6 +2003,8 @@ def cache_metrics(cache_id: str) -> dict[str, Any]: def cache_meta(cache_id: str) -> dict[str, Any]: try: return _executor.cache.read_meta(cache_id) + except ValueError as exc: + raise HTTPException(status_code=400, detail=str(exc)) from exc except FileNotFoundError as exc: raise HTTPException(status_code=404, detail="Cache not found") from exc @@ -2008,6 +2019,8 @@ def cache_preview(cache_id: str, format: str = "wav") -> Response: data = _executor.cache.preview_wav_bytes(cache_id) return Response(content=data, media_type="audio/wav") raise HTTPException(status_code=400, detail="Unsupported format") + except ValueError as exc: + raise HTTPException(status_code=400, detail=str(exc)) from exc except FileNotFoundError as exc: raise HTTPException(status_code=404, detail="Cache not found") from exc @@ -2016,6 +2029,8 @@ def cache_preview(cache_id: str, format: str = "wav") -> Response: def cache_waveform(cache_id: str, width: int = 512) -> dict[str, Any]: try: return _executor.cache.waveform_peaks(cache_id, width=width) + except ValueError as exc: + raise HTTPException(status_code=400, detail=str(exc)) from exc except FileNotFoundError as exc: raise HTTPException(status_code=404, detail="Cache not found") from exc @@ -2056,6 +2071,8 @@ def cache_trajectory(cache_id: str) -> dict[str, Any]: def cache_midi_roll(cache_id: str) -> dict[str, Any]: try: return _executor.cache.midi_roll(cache_id) + except ValueError as exc: + raise HTTPException(status_code=400, detail=str(exc)) from exc except FileNotFoundError as exc: raise HTTPException(status_code=404, detail="MIDI cache not found") from exc @@ -2076,6 +2093,8 @@ def compare_analyze(body: CompareAnalyzeRequest) -> dict[str, Any]: model_id=body.model_id, question=body.question, ) + except ValueError as exc: + raise HTTPException(status_code=400, detail=str(exc)) from exc except FileNotFoundError as exc: raise HTTPException( status_code=404, diff --git a/server/src/groovy/server/project_assets.py b/server/src/groovy/server/project_assets.py index 278268f..aaded90 100644 --- a/server/src/groovy/server/project_assets.py +++ b/server/src/groovy/server/project_assets.py @@ -5,8 +5,13 @@ import shutil from pathlib import Path +from groovy.executor.project_paths import MEDIA_EXTENSIONS + _SKIP_DIR_NAMES = {".groovy", ".git", "node_modules", ".venv"} +# Hard cap for localhost uploads (video demos can be large; refuse unbounded bodies). +MAX_UPLOAD_BYTES = 512 * 1024 * 1024 + def sidecar_path_for_audio(audio_path: Path) -> Path: return audio_path.with_name(f"{audio_path.stem}.provenance.json") @@ -25,18 +30,41 @@ def iter_project_files_named(project_dir: Path, name: str) -> list[Path]: return matches +def _unique_upload_dest(dest_dir: Path, safe_name: str) -> Path: + """Avoid silent overwrite: first free ``name``, then ``stem-1.ext``, ``stem-2.ext``, …""" + candidate = dest_dir / safe_name + if not candidate.exists(): + return candidate + stem = Path(safe_name).stem + suffix = Path(safe_name).suffix + n = 1 + while True: + candidate = dest_dir / f"{stem}-{n}{suffix}" + if not candidate.exists(): + return candidate + n += 1 + + def resolve_uploaded_audio(project_dir: Path, filename: str, payload: bytes) -> str: """ Store ``payload`` under assets/uploads/, or reuse an existing project file. If exactly one same-name, same-size audio already sits next to a ``*.provenance.json`` sidecar, return that path. Otherwise write to uploads - and copy a uniquely named sidecar if one exists. + (unique basename — never silent overwrite) and copy a uniquely named sidecar + if one exists. """ safe_name = Path(filename).name if not safe_name or safe_name in {".", ".."}: raise ValueError("Missing filename") + suffix = Path(safe_name).suffix.lower() + if suffix not in MEDIA_EXTENSIONS: + raise ValueError(f"Unsupported file type: {suffix or '(none)'}") + + if len(payload) > MAX_UPLOAD_BYTES: + raise ValueError(f"File too large (max {MAX_UPLOAD_BYTES} bytes)") + existing = [ path for path in iter_project_files_named(project_dir, safe_name) @@ -47,14 +75,17 @@ def resolve_uploaded_audio(project_dir: Path, filename: str, payload: bytes) -> dest_dir = project_dir / "assets" / "uploads" dest_dir.mkdir(parents=True, exist_ok=True) - dest = dest_dir / safe_name + dest = _unique_upload_dest(dest_dir, safe_name) dest.write_bytes(payload) - sidecar_name = sidecar_path_for_audio(dest).name dest_sidecar = sidecar_path_for_audio(dest) - candidates = [ - path for path in iter_project_files_named(project_dir, sidecar_name) if path != dest_sidecar - ] + # Prefer a sidecar named for the *original* basename (export reuse), else dest stem. + sidecar_names = {sidecar_path_for_audio(Path(safe_name)).name, dest_sidecar.name} + candidates: list[Path] = [] + for sidecar_name in sidecar_names: + for path in iter_project_files_named(project_dir, sidecar_name): + if path != dest_sidecar and path not in candidates: + candidates.append(path) if len(candidates) == 1: shutil.copy2(candidates[0], dest_sidecar) - return f"assets/uploads/{safe_name}" + return f"assets/uploads/{dest.name}" diff --git a/tests/__pycache__/audio_tolerance.cpython-312-pytest-9.1.1.pyc b/tests/__pycache__/audio_tolerance.cpython-312-pytest-9.1.1.pyc deleted file mode 100644 index 35047bc..0000000 Binary files a/tests/__pycache__/audio_tolerance.cpython-312-pytest-9.1.1.pyc and /dev/null differ diff --git a/tests/__pycache__/audio_tolerance.cpython-312.pyc b/tests/__pycache__/audio_tolerance.cpython-312.pyc deleted file mode 100644 index 3ee2f41..0000000 Binary files a/tests/__pycache__/audio_tolerance.cpython-312.pyc and /dev/null differ diff --git a/tests/__pycache__/template_fixtures.cpython-312.pyc b/tests/__pycache__/template_fixtures.cpython-312.pyc deleted file mode 100644 index 39aa162..0000000 Binary files a/tests/__pycache__/template_fixtures.cpython-312.pyc and /dev/null differ diff --git a/tests/__pycache__/test_ab_compare.cpython-312-pytest-9.1.1.pyc b/tests/__pycache__/test_ab_compare.cpython-312-pytest-9.1.1.pyc deleted file mode 100644 index c5072c3..0000000 Binary files a/tests/__pycache__/test_ab_compare.cpython-312-pytest-9.1.1.pyc and /dev/null differ diff --git a/tests/__pycache__/test_ace_step_runner.cpython-312-pytest-9.1.1.pyc b/tests/__pycache__/test_ace_step_runner.cpython-312-pytest-9.1.1.pyc deleted file mode 100644 index 6b633bf..0000000 Binary files a/tests/__pycache__/test_ace_step_runner.cpython-312-pytest-9.1.1.pyc and /dev/null differ diff --git a/tests/__pycache__/test_ace_step_template.cpython-312-pytest-9.1.1.pyc b/tests/__pycache__/test_ace_step_template.cpython-312-pytest-9.1.1.pyc deleted file mode 100644 index 5f26719..0000000 Binary files a/tests/__pycache__/test_ace_step_template.cpython-312-pytest-9.1.1.pyc and /dev/null differ diff --git a/tests/__pycache__/test_activation_diagnostics.cpython-312-pytest-9.1.1.pyc b/tests/__pycache__/test_activation_diagnostics.cpython-312-pytest-9.1.1.pyc deleted file mode 100644 index 9927d42..0000000 Binary files a/tests/__pycache__/test_activation_diagnostics.cpython-312-pytest-9.1.1.pyc and /dev/null differ diff --git a/tests/__pycache__/test_agent_plan.cpython-312-pytest-9.1.1.pyc b/tests/__pycache__/test_agent_plan.cpython-312-pytest-9.1.1.pyc deleted file mode 100644 index d3f0141..0000000 Binary files a/tests/__pycache__/test_agent_plan.cpython-312-pytest-9.1.1.pyc and /dev/null differ diff --git a/tests/__pycache__/test_ai_worker_stdout.cpython-312-pytest-9.1.1.pyc b/tests/__pycache__/test_ai_worker_stdout.cpython-312-pytest-9.1.1.pyc deleted file mode 100644 index ce96fff..0000000 Binary files a/tests/__pycache__/test_ai_worker_stdout.cpython-312-pytest-9.1.1.pyc and /dev/null differ diff --git a/tests/__pycache__/test_all_templates.cpython-312-pytest-9.1.1.pyc b/tests/__pycache__/test_all_templates.cpython-312-pytest-9.1.1.pyc deleted file mode 100644 index 83c5098..0000000 Binary files a/tests/__pycache__/test_all_templates.cpython-312-pytest-9.1.1.pyc and /dev/null differ diff --git a/tests/__pycache__/test_audio_flamingo_template.cpython-312-pytest-9.1.1.pyc b/tests/__pycache__/test_audio_flamingo_template.cpython-312-pytest-9.1.1.pyc deleted file mode 100644 index e1bb85e..0000000 Binary files a/tests/__pycache__/test_audio_flamingo_template.cpython-312-pytest-9.1.1.pyc and /dev/null differ diff --git a/tests/__pycache__/test_audio_meta.cpython-312-pytest-9.1.1.pyc b/tests/__pycache__/test_audio_meta.cpython-312-pytest-9.1.1.pyc deleted file mode 100644 index 1668386..0000000 Binary files a/tests/__pycache__/test_audio_meta.cpython-312-pytest-9.1.1.pyc and /dev/null differ diff --git a/tests/__pycache__/test_audio_tolerance.cpython-312-pytest-9.1.1.pyc b/tests/__pycache__/test_audio_tolerance.cpython-312-pytest-9.1.1.pyc deleted file mode 100644 index a18182d..0000000 Binary files a/tests/__pycache__/test_audio_tolerance.cpython-312-pytest-9.1.1.pyc and /dev/null differ diff --git a/tests/__pycache__/test_beat_track.cpython-312-pytest-9.1.1.pyc b/tests/__pycache__/test_beat_track.cpython-312-pytest-9.1.1.pyc deleted file mode 100644 index 6ccdfb7..0000000 Binary files a/tests/__pycache__/test_beat_track.cpython-312-pytest-9.1.1.pyc and /dev/null differ diff --git a/tests/__pycache__/test_bundle_install.cpython-312-pytest-9.1.1.pyc b/tests/__pycache__/test_bundle_install.cpython-312-pytest-9.1.1.pyc deleted file mode 100644 index 2f4b401..0000000 Binary files a/tests/__pycache__/test_bundle_install.cpython-312-pytest-9.1.1.pyc and /dev/null differ diff --git a/tests/__pycache__/test_channel_convert.cpython-312-pytest-9.1.1.pyc b/tests/__pycache__/test_channel_convert.cpython-312-pytest-9.1.1.pyc deleted file mode 100644 index 9486486..0000000 Binary files a/tests/__pycache__/test_channel_convert.cpython-312-pytest-9.1.1.pyc and /dev/null differ diff --git a/tests/__pycache__/test_channel_merge.cpython-312-pytest-9.1.1.pyc b/tests/__pycache__/test_channel_merge.cpython-312-pytest-9.1.1.pyc deleted file mode 100644 index 8e8b908..0000000 Binary files a/tests/__pycache__/test_channel_merge.cpython-312-pytest-9.1.1.pyc and /dev/null differ diff --git a/tests/__pycache__/test_cold_machine_hero.cpython-312-pytest-9.1.1.pyc b/tests/__pycache__/test_cold_machine_hero.cpython-312-pytest-9.1.1.pyc deleted file mode 100644 index a6bcd33..0000000 Binary files a/tests/__pycache__/test_cold_machine_hero.cpython-312-pytest-9.1.1.pyc and /dev/null differ diff --git a/tests/__pycache__/test_comfy_import.cpython-312-pytest-9.1.1.pyc b/tests/__pycache__/test_comfy_import.cpython-312-pytest-9.1.1.pyc deleted file mode 100644 index 677d8f7..0000000 Binary files a/tests/__pycache__/test_comfy_import.cpython-312-pytest-9.1.1.pyc and /dev/null differ diff --git a/tests/__pycache__/test_compare_api.cpython-312-pytest-9.1.1.pyc b/tests/__pycache__/test_compare_api.cpython-312-pytest-9.1.1.pyc deleted file mode 100644 index edba053..0000000 Binary files a/tests/__pycache__/test_compare_api.cpython-312-pytest-9.1.1.pyc and /dev/null differ diff --git a/tests/__pycache__/test_compliance.cpython-312-pytest-9.1.1.pyc b/tests/__pycache__/test_compliance.cpython-312-pytest-9.1.1.pyc deleted file mode 100644 index 1931eb8..0000000 Binary files a/tests/__pycache__/test_compliance.cpython-312-pytest-9.1.1.pyc and /dev/null differ diff --git a/tests/__pycache__/test_compliance_report.cpython-312-pytest-9.1.1.pyc b/tests/__pycache__/test_compliance_report.cpython-312-pytest-9.1.1.pyc deleted file mode 100644 index e6c30f7..0000000 Binary files a/tests/__pycache__/test_compliance_report.cpython-312-pytest-9.1.1.pyc and /dev/null differ diff --git a/tests/__pycache__/test_content_credentials.cpython-312-pytest-9.1.1.pyc b/tests/__pycache__/test_content_credentials.cpython-312-pytest-9.1.1.pyc deleted file mode 100644 index f8f6f1c..0000000 Binary files a/tests/__pycache__/test_content_credentials.cpython-312-pytest-9.1.1.pyc and /dev/null differ diff --git a/tests/__pycache__/test_control_curve_points.cpython-312-pytest-9.1.1.pyc b/tests/__pycache__/test_control_curve_points.cpython-312-pytest-9.1.1.pyc deleted file mode 100644 index 86eaa7a..0000000 Binary files a/tests/__pycache__/test_control_curve_points.cpython-312-pytest-9.1.1.pyc and /dev/null differ diff --git a/tests/__pycache__/test_deepfilter_compat.cpython-312-pytest-9.1.1.pyc b/tests/__pycache__/test_deepfilter_compat.cpython-312-pytest-9.1.1.pyc deleted file mode 100644 index a75f7fd..0000000 Binary files a/tests/__pycache__/test_deepfilter_compat.cpython-312-pytest-9.1.1.pyc and /dev/null differ diff --git a/tests/__pycache__/test_desktop_launch.cpython-312-pytest-9.1.1.pyc b/tests/__pycache__/test_desktop_launch.cpython-312-pytest-9.1.1.pyc deleted file mode 100644 index 65c35ba..0000000 Binary files a/tests/__pycache__/test_desktop_launch.cpython-312-pytest-9.1.1.pyc and /dev/null differ diff --git a/tests/__pycache__/test_diarize_transcribe.cpython-312-pytest-9.1.1.pyc b/tests/__pycache__/test_diarize_transcribe.cpython-312-pytest-9.1.1.pyc deleted file mode 100644 index e04d534..0000000 Binary files a/tests/__pycache__/test_diarize_transcribe.cpython-312-pytest-9.1.1.pyc and /dev/null differ diff --git a/tests/__pycache__/test_espeak_compat.cpython-312-pytest-9.1.1.pyc b/tests/__pycache__/test_espeak_compat.cpython-312-pytest-9.1.1.pyc deleted file mode 100644 index f5575b0..0000000 Binary files a/tests/__pycache__/test_espeak_compat.cpython-312-pytest-9.1.1.pyc and /dev/null differ diff --git a/tests/__pycache__/test_featured_real_inference.cpython-312-pytest-9.1.1.pyc b/tests/__pycache__/test_featured_real_inference.cpython-312-pytest-9.1.1.pyc deleted file mode 100644 index 21ff0b3..0000000 Binary files a/tests/__pycache__/test_featured_real_inference.cpython-312-pytest-9.1.1.pyc and /dev/null differ diff --git a/tests/__pycache__/test_generative_prompt_seed.cpython-312-pytest-9.1.1.pyc b/tests/__pycache__/test_generative_prompt_seed.cpython-312-pytest-9.1.1.pyc deleted file mode 100644 index 41bc809..0000000 Binary files a/tests/__pycache__/test_generative_prompt_seed.cpython-312-pytest-9.1.1.pyc and /dev/null differ diff --git a/tests/__pycache__/test_hero_real_inference.cpython-312-pytest-9.1.1.pyc b/tests/__pycache__/test_hero_real_inference.cpython-312-pytest-9.1.1.pyc deleted file mode 100644 index 6d08677..0000000 Binary files a/tests/__pycache__/test_hero_real_inference.cpython-312-pytest-9.1.1.pyc and /dev/null differ diff --git a/tests/__pycache__/test_hf_token_bearer.cpython-312-pytest-9.1.1.pyc b/tests/__pycache__/test_hf_token_bearer.cpython-312-pytest-9.1.1.pyc deleted file mode 100644 index 7ff9a97..0000000 Binary files a/tests/__pycache__/test_hf_token_bearer.cpython-312-pytest-9.1.1.pyc and /dev/null differ diff --git a/tests/__pycache__/test_immersive.cpython-312-pytest-9.1.1.pyc b/tests/__pycache__/test_immersive.cpython-312-pytest-9.1.1.pyc deleted file mode 100644 index 9d8d898..0000000 Binary files a/tests/__pycache__/test_immersive.cpython-312-pytest-9.1.1.pyc and /dev/null differ diff --git a/tests/__pycache__/test_inference_demucs.cpython-312-pytest-9.1.1.pyc b/tests/__pycache__/test_inference_demucs.cpython-312-pytest-9.1.1.pyc deleted file mode 100644 index c32fd35..0000000 Binary files a/tests/__pycache__/test_inference_demucs.cpython-312-pytest-9.1.1.pyc and /dev/null differ diff --git a/tests/__pycache__/test_inference_real.cpython-312-pytest-9.1.1.pyc b/tests/__pycache__/test_inference_real.cpython-312-pytest-9.1.1.pyc deleted file mode 100644 index b3db85b..0000000 Binary files a/tests/__pycache__/test_inference_real.cpython-312-pytest-9.1.1.pyc and /dev/null differ diff --git a/tests/__pycache__/test_install_cancel_and_preflight.cpython-312-pytest-9.1.1.pyc b/tests/__pycache__/test_install_cancel_and_preflight.cpython-312-pytest-9.1.1.pyc deleted file mode 100644 index 339be80..0000000 Binary files a/tests/__pycache__/test_install_cancel_and_preflight.cpython-312-pytest-9.1.1.pyc and /dev/null differ diff --git a/tests/__pycache__/test_install_recovery.cpython-312-pytest-9.1.1.pyc b/tests/__pycache__/test_install_recovery.cpython-312-pytest-9.1.1.pyc deleted file mode 100644 index fca2330..0000000 Binary files a/tests/__pycache__/test_install_recovery.cpython-312-pytest-9.1.1.pyc and /dev/null differ diff --git a/tests/__pycache__/test_job_cancel.cpython-312-pytest-9.1.1.pyc b/tests/__pycache__/test_job_cancel.cpython-312-pytest-9.1.1.pyc deleted file mode 100644 index 72a584f..0000000 Binary files a/tests/__pycache__/test_job_cancel.cpython-312-pytest-9.1.1.pyc and /dev/null differ diff --git a/tests/__pycache__/test_license_scanner.cpython-312-pytest-9.1.1.pyc b/tests/__pycache__/test_license_scanner.cpython-312-pytest-9.1.1.pyc deleted file mode 100644 index a88d9d8..0000000 Binary files a/tests/__pycache__/test_license_scanner.cpython-312-pytest-9.1.1.pyc and /dev/null differ diff --git a/tests/__pycache__/test_live_io.cpython-312-pytest-9.1.1.pyc b/tests/__pycache__/test_live_io.cpython-312-pytest-9.1.1.pyc deleted file mode 100644 index 7d368be..0000000 Binary files a/tests/__pycache__/test_live_io.cpython-312-pytest-9.1.1.pyc and /dev/null differ diff --git a/tests/__pycache__/test_load_audio_multichannel_outlets.cpython-312-pytest-9.1.1.pyc b/tests/__pycache__/test_load_audio_multichannel_outlets.cpython-312-pytest-9.1.1.pyc deleted file mode 100644 index a4950b8..0000000 Binary files a/tests/__pycache__/test_load_audio_multichannel_outlets.cpython-312-pytest-9.1.1.pyc and /dev/null differ diff --git a/tests/__pycache__/test_localize_dialogue_template.cpython-312-pytest-9.1.1.pyc b/tests/__pycache__/test_localize_dialogue_template.cpython-312-pytest-9.1.1.pyc deleted file mode 100644 index 3c0fe09..0000000 Binary files a/tests/__pycache__/test_localize_dialogue_template.cpython-312-pytest-9.1.1.pyc and /dev/null differ diff --git a/tests/__pycache__/test_meter_node.cpython-312-pytest-9.1.1.pyc b/tests/__pycache__/test_meter_node.cpython-312-pytest-9.1.1.pyc deleted file mode 100644 index 91efc00..0000000 Binary files a/tests/__pycache__/test_meter_node.cpython-312-pytest-9.1.1.pyc and /dev/null differ diff --git a/tests/__pycache__/test_midi_roll.cpython-312-pytest-9.1.1.pyc b/tests/__pycache__/test_midi_roll.cpython-312-pytest-9.1.1.pyc deleted file mode 100644 index f03af9d..0000000 Binary files a/tests/__pycache__/test_midi_roll.cpython-312-pytest-9.1.1.pyc and /dev/null differ diff --git a/tests/__pycache__/test_midi_smf_events.cpython-312-pytest-9.1.1.pyc b/tests/__pycache__/test_midi_smf_events.cpython-312-pytest-9.1.1.pyc deleted file mode 100644 index c7caebc..0000000 Binary files a/tests/__pycache__/test_midi_smf_events.cpython-312-pytest-9.1.1.pyc and /dev/null differ diff --git a/tests/__pycache__/test_model_browser_integrations.cpython-312-pytest-9.1.1.pyc b/tests/__pycache__/test_model_browser_integrations.cpython-312-pytest-9.1.1.pyc deleted file mode 100644 index 5b9dca7..0000000 Binary files a/tests/__pycache__/test_model_browser_integrations.cpython-312-pytest-9.1.1.pyc and /dev/null differ diff --git a/tests/__pycache__/test_model_browser_runtime.cpython-312-pytest-9.1.1.pyc b/tests/__pycache__/test_model_browser_runtime.cpython-312-pytest-9.1.1.pyc deleted file mode 100644 index 2683278..0000000 Binary files a/tests/__pycache__/test_model_browser_runtime.cpython-312-pytest-9.1.1.pyc and /dev/null differ diff --git a/tests/__pycache__/test_model_discover.cpython-312-pytest-9.1.1.pyc b/tests/__pycache__/test_model_discover.cpython-312-pytest-9.1.1.pyc deleted file mode 100644 index fe5675b..0000000 Binary files a/tests/__pycache__/test_model_discover.cpython-312-pytest-9.1.1.pyc and /dev/null differ diff --git a/tests/__pycache__/test_model_download.cpython-312-pytest-9.1.1.pyc b/tests/__pycache__/test_model_download.cpython-312-pytest-9.1.1.pyc deleted file mode 100644 index c895155..0000000 Binary files a/tests/__pycache__/test_model_download.cpython-312-pytest-9.1.1.pyc and /dev/null differ diff --git a/tests/__pycache__/test_model_params.cpython-312-pytest-9.1.1.pyc b/tests/__pycache__/test_model_params.cpython-312-pytest-9.1.1.pyc deleted file mode 100644 index dd47686..0000000 Binary files a/tests/__pycache__/test_model_params.cpython-312-pytest-9.1.1.pyc and /dev/null differ diff --git a/tests/__pycache__/test_model_registry.cpython-312-pytest-9.1.1.pyc b/tests/__pycache__/test_model_registry.cpython-312-pytest-9.1.1.pyc deleted file mode 100644 index 8246302..0000000 Binary files a/tests/__pycache__/test_model_registry.cpython-312-pytest-9.1.1.pyc and /dev/null differ diff --git a/tests/__pycache__/test_modular_synth.cpython-312-pytest-9.1.1.pyc b/tests/__pycache__/test_modular_synth.cpython-312-pytest-9.1.1.pyc deleted file mode 100644 index 7406b72..0000000 Binary files a/tests/__pycache__/test_modular_synth.cpython-312-pytest-9.1.1.pyc and /dev/null differ diff --git a/tests/__pycache__/test_module_io.cpython-312-pytest-9.1.1.pyc b/tests/__pycache__/test_module_io.cpython-312-pytest-9.1.1.pyc deleted file mode 100644 index 54ef0f1..0000000 Binary files a/tests/__pycache__/test_module_io.cpython-312-pytest-9.1.1.pyc and /dev/null differ diff --git a/tests/__pycache__/test_mp4_media_io.cpython-312-pytest-9.1.1.pyc b/tests/__pycache__/test_mp4_media_io.cpython-312-pytest-9.1.1.pyc deleted file mode 100644 index f098781..0000000 Binary files a/tests/__pycache__/test_mp4_media_io.cpython-312-pytest-9.1.1.pyc and /dev/null differ diff --git a/tests/__pycache__/test_musicgen_melody_conditioning.cpython-312-pytest-9.1.1.pyc b/tests/__pycache__/test_musicgen_melody_conditioning.cpython-312-pytest-9.1.1.pyc deleted file mode 100644 index 1d521cb..0000000 Binary files a/tests/__pycache__/test_musicgen_melody_conditioning.cpython-312-pytest-9.1.1.pyc and /dev/null differ diff --git a/tests/__pycache__/test_node_cache.cpython-312-pytest-9.1.1.pyc b/tests/__pycache__/test_node_cache.cpython-312-pytest-9.1.1.pyc deleted file mode 100644 index fd7b0fc..0000000 Binary files a/tests/__pycache__/test_node_cache.cpython-312-pytest-9.1.1.pyc and /dev/null differ diff --git a/tests/__pycache__/test_node_enricher.cpython-312-pytest-9.1.1.pyc b/tests/__pycache__/test_node_enricher.cpython-312-pytest-9.1.1.pyc deleted file mode 100644 index 3736bd9..0000000 Binary files a/tests/__pycache__/test_node_enricher.cpython-312-pytest-9.1.1.pyc and /dev/null differ diff --git a/tests/__pycache__/test_note_node.cpython-312-pytest-9.1.1.pyc b/tests/__pycache__/test_note_node.cpython-312-pytest-9.1.1.pyc deleted file mode 100644 index 603d597..0000000 Binary files a/tests/__pycache__/test_note_node.cpython-312-pytest-9.1.1.pyc and /dev/null differ diff --git a/tests/__pycache__/test_oba_phase21.cpython-312-pytest-9.1.1.pyc b/tests/__pycache__/test_oba_phase21.cpython-312-pytest-9.1.1.pyc deleted file mode 100644 index 831f828..0000000 Binary files a/tests/__pycache__/test_oba_phase21.cpython-312-pytest-9.1.1.pyc and /dev/null differ diff --git a/tests/__pycache__/test_pan_node.cpython-312-pytest-9.1.1.pyc b/tests/__pycache__/test_pan_node.cpython-312-pytest-9.1.1.pyc deleted file mode 100644 index 3a097e9..0000000 Binary files a/tests/__pycache__/test_pan_node.cpython-312-pytest-9.1.1.pyc and /dev/null differ diff --git a/tests/__pycache__/test_phase2_closeout.cpython-312-pytest-9.1.1.pyc b/tests/__pycache__/test_phase2_closeout.cpython-312-pytest-9.1.1.pyc deleted file mode 100644 index 5f6829b..0000000 Binary files a/tests/__pycache__/test_phase2_closeout.cpython-312-pytest-9.1.1.pyc and /dev/null differ diff --git a/tests/__pycache__/test_portable_paths.cpython-312-pytest-9.1.1.pyc b/tests/__pycache__/test_portable_paths.cpython-312-pytest-9.1.1.pyc deleted file mode 100644 index ad43e08..0000000 Binary files a/tests/__pycache__/test_portable_paths.cpython-312-pytest-9.1.1.pyc and /dev/null differ diff --git a/tests/__pycache__/test_preview_text.cpython-312-pytest-9.1.1.pyc b/tests/__pycache__/test_preview_text.cpython-312-pytest-9.1.1.pyc deleted file mode 100644 index 44782f4..0000000 Binary files a/tests/__pycache__/test_preview_text.cpython-312-pytest-9.1.1.pyc and /dev/null differ diff --git a/tests/__pycache__/test_preview_wav.cpython-312-pytest-9.1.1.pyc b/tests/__pycache__/test_preview_wav.cpython-312-pytest-9.1.1.pyc deleted file mode 100644 index e4846b5..0000000 Binary files a/tests/__pycache__/test_preview_wav.cpython-312-pytest-9.1.1.pyc and /dev/null differ diff --git a/tests/__pycache__/test_product_license.cpython-312-pytest-9.1.1.pyc b/tests/__pycache__/test_product_license.cpython-312-pytest-9.1.1.pyc deleted file mode 100644 index bcf4e1a..0000000 Binary files a/tests/__pycache__/test_product_license.cpython-312-pytest-9.1.1.pyc and /dev/null differ diff --git a/tests/__pycache__/test_project_bootstrap.cpython-312-pytest-9.1.1.pyc b/tests/__pycache__/test_project_bootstrap.cpython-312-pytest-9.1.1.pyc deleted file mode 100644 index 73a5a65..0000000 Binary files a/tests/__pycache__/test_project_bootstrap.cpython-312-pytest-9.1.1.pyc and /dev/null differ diff --git a/tests/__pycache__/test_project_paths.cpython-312-pytest-9.1.1.pyc b/tests/__pycache__/test_project_paths.cpython-312-pytest-9.1.1.pyc deleted file mode 100644 index 4007448..0000000 Binary files a/tests/__pycache__/test_project_paths.cpython-312-pytest-9.1.1.pyc and /dev/null differ diff --git a/tests/__pycache__/test_project_reveal.cpython-312-pytest-9.1.1.pyc b/tests/__pycache__/test_project_reveal.cpython-312-pytest-9.1.1.pyc deleted file mode 100644 index 43560f9..0000000 Binary files a/tests/__pycache__/test_project_reveal.cpython-312-pytest-9.1.1.pyc and /dev/null differ diff --git a/tests/__pycache__/test_project_upload.cpython-312-pytest-9.1.1.pyc b/tests/__pycache__/test_project_upload.cpython-312-pytest-9.1.1.pyc deleted file mode 100644 index 7c06334..0000000 Binary files a/tests/__pycache__/test_project_upload.cpython-312-pytest-9.1.1.pyc and /dev/null differ diff --git a/tests/__pycache__/test_provenance.cpython-312-pytest-9.1.1.pyc b/tests/__pycache__/test_provenance.cpython-312-pytest-9.1.1.pyc deleted file mode 100644 index ebf60f0..0000000 Binary files a/tests/__pycache__/test_provenance.cpython-312-pytest-9.1.1.pyc and /dev/null differ diff --git a/tests/__pycache__/test_rave_inference.cpython-312-pytest-9.1.1.pyc b/tests/__pycache__/test_rave_inference.cpython-312-pytest-9.1.1.pyc deleted file mode 100644 index 08966ed..0000000 Binary files a/tests/__pycache__/test_rave_inference.cpython-312-pytest-9.1.1.pyc and /dev/null differ diff --git a/tests/__pycache__/test_recommender.cpython-312-pytest-9.1.1.pyc b/tests/__pycache__/test_recommender.cpython-312-pytest-9.1.1.pyc deleted file mode 100644 index 9749dd0..0000000 Binary files a/tests/__pycache__/test_recommender.cpython-312-pytest-9.1.1.pyc and /dev/null differ diff --git a/tests/__pycache__/test_registry_curator.cpython-312-pytest-9.1.1.pyc b/tests/__pycache__/test_registry_curator.cpython-312-pytest-9.1.1.pyc deleted file mode 100644 index 1a59498..0000000 Binary files a/tests/__pycache__/test_registry_curator.cpython-312-pytest-9.1.1.pyc and /dev/null differ diff --git a/tests/__pycache__/test_sample_accuracy_claim.cpython-312-pytest-9.1.1.pyc b/tests/__pycache__/test_sample_accuracy_claim.cpython-312-pytest-9.1.1.pyc deleted file mode 100644 index 6d4b304..0000000 Binary files a/tests/__pycache__/test_sample_accuracy_claim.cpython-312-pytest-9.1.1.pyc and /dev/null differ diff --git a/tests/__pycache__/test_save_audio.cpython-312-pytest-9.1.1.pyc b/tests/__pycache__/test_save_audio.cpython-312-pytest-9.1.1.pyc deleted file mode 100644 index 15e486b..0000000 Binary files a/tests/__pycache__/test_save_audio.cpython-312-pytest-9.1.1.pyc and /dev/null differ diff --git a/tests/__pycache__/test_seed_catalog_quality.cpython-312-pytest-9.1.1.pyc b/tests/__pycache__/test_seed_catalog_quality.cpython-312-pytest-9.1.1.pyc deleted file mode 100644 index 5f33b4f..0000000 Binary files a/tests/__pycache__/test_seed_catalog_quality.cpython-312-pytest-9.1.1.pyc and /dev/null differ diff --git a/tests/__pycache__/test_self_playing_neural_rack.cpython-312-pytest-9.1.1.pyc b/tests/__pycache__/test_self_playing_neural_rack.cpython-312-pytest-9.1.1.pyc deleted file mode 100644 index 7ef4992..0000000 Binary files a/tests/__pycache__/test_self_playing_neural_rack.cpython-312-pytest-9.1.1.pyc and /dev/null differ diff --git a/tests/__pycache__/test_signal_generator.cpython-312-pytest-9.1.1.pyc b/tests/__pycache__/test_signal_generator.cpython-312-pytest-9.1.1.pyc deleted file mode 100644 index 4fc1f62..0000000 Binary files a/tests/__pycache__/test_signal_generator.cpython-312-pytest-9.1.1.pyc and /dev/null differ diff --git a/tests/__pycache__/test_signal_integrity.cpython-312-pytest-9.1.1.pyc b/tests/__pycache__/test_signal_integrity.cpython-312-pytest-9.1.1.pyc deleted file mode 100644 index 45b5100..0000000 Binary files a/tests/__pycache__/test_signal_integrity.cpython-312-pytest-9.1.1.pyc and /dev/null differ diff --git a/tests/__pycache__/test_spatial_upmix_nodes.cpython-312-pytest-9.1.1.pyc b/tests/__pycache__/test_spatial_upmix_nodes.cpython-312-pytest-9.1.1.pyc deleted file mode 100644 index 2aa515e..0000000 Binary files a/tests/__pycache__/test_spatial_upmix_nodes.cpython-312-pytest-9.1.1.pyc and /dev/null differ diff --git a/tests/__pycache__/test_spectrogram.cpython-312-pytest-9.1.1.pyc b/tests/__pycache__/test_spectrogram.cpython-312-pytest-9.1.1.pyc deleted file mode 100644 index 5dcb455..0000000 Binary files a/tests/__pycache__/test_spectrogram.cpython-312-pytest-9.1.1.pyc and /dev/null differ diff --git a/tests/__pycache__/test_stable_audio_template.cpython-312-pytest-9.1.1.pyc b/tests/__pycache__/test_stable_audio_template.cpython-312-pytest-9.1.1.pyc deleted file mode 100644 index b310ef9..0000000 Binary files a/tests/__pycache__/test_stable_audio_template.cpython-312-pytest-9.1.1.pyc and /dev/null differ diff --git a/tests/__pycache__/test_studio_settings_api.cpython-312-pytest-9.1.1.pyc b/tests/__pycache__/test_studio_settings_api.cpython-312-pytest-9.1.1.pyc deleted file mode 100644 index c783fa5..0000000 Binary files a/tests/__pycache__/test_studio_settings_api.cpython-312-pytest-9.1.1.pyc and /dev/null differ diff --git a/tests/__pycache__/test_template_sample_accuracy.cpython-312-pytest-9.1.1.pyc b/tests/__pycache__/test_template_sample_accuracy.cpython-312-pytest-9.1.1.pyc deleted file mode 100644 index 72509da..0000000 Binary files a/tests/__pycache__/test_template_sample_accuracy.cpython-312-pytest-9.1.1.pyc and /dev/null differ diff --git a/tests/__pycache__/test_template_signal_integrity.cpython-312-pytest-9.1.1.pyc b/tests/__pycache__/test_template_signal_integrity.cpython-312-pytest-9.1.1.pyc deleted file mode 100644 index ed1e026..0000000 Binary files a/tests/__pycache__/test_template_signal_integrity.cpython-312-pytest-9.1.1.pyc and /dev/null differ diff --git a/tests/__pycache__/test_templates_api.cpython-312-pytest-9.1.1.pyc b/tests/__pycache__/test_templates_api.cpython-312-pytest-9.1.1.pyc deleted file mode 100644 index ca56a50..0000000 Binary files a/tests/__pycache__/test_templates_api.cpython-312-pytest-9.1.1.pyc and /dev/null differ diff --git a/tests/__pycache__/test_verify_provenance_sidecar.cpython-312-pytest-9.1.1.pyc b/tests/__pycache__/test_verify_provenance_sidecar.cpython-312-pytest-9.1.1.pyc deleted file mode 100644 index 3f591b8..0000000 Binary files a/tests/__pycache__/test_verify_provenance_sidecar.cpython-312-pytest-9.1.1.pyc and /dev/null differ diff --git a/tests/__pycache__/test_verify_samples.cpython-312-pytest-9.1.1.pyc b/tests/__pycache__/test_verify_samples.cpython-312-pytest-9.1.1.pyc deleted file mode 100644 index a59a7f7..0000000 Binary files a/tests/__pycache__/test_verify_samples.cpython-312-pytest-9.1.1.pyc and /dev/null differ diff --git a/tests/__pycache__/test_voice_cloning_template.cpython-312-pytest-9.1.1.pyc b/tests/__pycache__/test_voice_cloning_template.cpython-312-pytest-9.1.1.pyc deleted file mode 100644 index d7dcb5b..0000000 Binary files a/tests/__pycache__/test_voice_cloning_template.cpython-312-pytest-9.1.1.pyc and /dev/null differ diff --git a/tests/__pycache__/test_watermark_audioseal.cpython-312-pytest-9.1.1.pyc b/tests/__pycache__/test_watermark_audioseal.cpython-312-pytest-9.1.1.pyc deleted file mode 100644 index 8a90a9c..0000000 Binary files a/tests/__pycache__/test_watermark_audioseal.cpython-312-pytest-9.1.1.pyc and /dev/null differ diff --git a/tests/__pycache__/test_wavegan_generate.cpython-312-pytest-9.1.1.pyc b/tests/__pycache__/test_wavegan_generate.cpython-312-pytest-9.1.1.pyc deleted file mode 100644 index 4246926..0000000 Binary files a/tests/__pycache__/test_wavegan_generate.cpython-312-pytest-9.1.1.pyc and /dev/null differ diff --git a/tests/__pycache__/test_whisper_resample.cpython-312-pytest-9.1.1.pyc b/tests/__pycache__/test_whisper_resample.cpython-312-pytest-9.1.1.pyc deleted file mode 100644 index 9143b4c..0000000 Binary files a/tests/__pycache__/test_whisper_resample.cpython-312-pytest-9.1.1.pyc and /dev/null differ diff --git a/tests/__pycache__/test_workflow_suggester.cpython-312-pytest-9.1.1.pyc b/tests/__pycache__/test_workflow_suggester.cpython-312-pytest-9.1.1.pyc deleted file mode 100644 index cb344ce..0000000 Binary files a/tests/__pycache__/test_workflow_suggester.cpython-312-pytest-9.1.1.pyc and /dev/null differ diff --git a/tests/golden/__pycache__/test_ab_compare_demo.cpython-312-pytest-9.1.1.pyc b/tests/golden/__pycache__/test_ab_compare_demo.cpython-312-pytest-9.1.1.pyc deleted file mode 100644 index b008f48..0000000 Binary files a/tests/golden/__pycache__/test_ab_compare_demo.cpython-312-pytest-9.1.1.pyc and /dev/null differ diff --git a/tests/golden/__pycache__/test_ambisonic_trajectory_demo.cpython-312-pytest-9.1.1.pyc b/tests/golden/__pycache__/test_ambisonic_trajectory_demo.cpython-312-pytest-9.1.1.pyc deleted file mode 100644 index 3876cf9..0000000 Binary files a/tests/golden/__pycache__/test_ambisonic_trajectory_demo.cpython-312-pytest-9.1.1.pyc and /dev/null differ diff --git a/tests/golden/__pycache__/test_authenticity_check.cpython-312-pytest-9.1.1.pyc b/tests/golden/__pycache__/test_authenticity_check.cpython-312-pytest-9.1.1.pyc deleted file mode 100644 index 73095f5..0000000 Binary files a/tests/golden/__pycache__/test_authenticity_check.cpython-312-pytest-9.1.1.pyc and /dev/null differ diff --git a/tests/golden/__pycache__/test_hello_groovy.cpython-312-pytest-9.1.1.pyc b/tests/golden/__pycache__/test_hello_groovy.cpython-312-pytest-9.1.1.pyc deleted file mode 100644 index 488b7dd..0000000 Binary files a/tests/golden/__pycache__/test_hello_groovy.cpython-312-pytest-9.1.1.pyc and /dev/null differ diff --git a/tests/golden/__pycache__/test_midi_automation_demo.cpython-312-pytest-9.1.1.pyc b/tests/golden/__pycache__/test_midi_automation_demo.cpython-312-pytest-9.1.1.pyc deleted file mode 100644 index 3db2240..0000000 Binary files a/tests/golden/__pycache__/test_midi_automation_demo.cpython-312-pytest-9.1.1.pyc and /dev/null differ diff --git a/tests/golden/__pycache__/test_podcast_denoise.cpython-312-pytest-9.1.1.pyc b/tests/golden/__pycache__/test_podcast_denoise.cpython-312-pytest-9.1.1.pyc deleted file mode 100644 index 1df4e2e..0000000 Binary files a/tests/golden/__pycache__/test_podcast_denoise.cpython-312-pytest-9.1.1.pyc and /dev/null differ diff --git a/tests/golden/__pycache__/test_reproducibility.cpython-312-pytest-9.1.1.pyc b/tests/golden/__pycache__/test_reproducibility.cpython-312-pytest-9.1.1.pyc deleted file mode 100644 index 77b9d82..0000000 Binary files a/tests/golden/__pycache__/test_reproducibility.cpython-312-pytest-9.1.1.pyc and /dev/null differ diff --git a/tests/golden/__pycache__/test_reproducibility.cpython-312.pyc b/tests/golden/__pycache__/test_reproducibility.cpython-312.pyc deleted file mode 100644 index ec0fdc2..0000000 Binary files a/tests/golden/__pycache__/test_reproducibility.cpython-312.pyc and /dev/null differ diff --git a/tests/golden/__pycache__/test_sing_from_midi.cpython-312-pytest-9.1.1.pyc b/tests/golden/__pycache__/test_sing_from_midi.cpython-312-pytest-9.1.1.pyc deleted file mode 100644 index afaab98..0000000 Binary files a/tests/golden/__pycache__/test_sing_from_midi.cpython-312-pytest-9.1.1.pyc and /dev/null differ diff --git a/tests/golden/__pycache__/test_stem_split.cpython-312-pytest-9.1.1.pyc b/tests/golden/__pycache__/test_stem_split.cpython-312-pytest-9.1.1.pyc deleted file mode 100644 index 7d3a6f0..0000000 Binary files a/tests/golden/__pycache__/test_stem_split.cpython-312-pytest-9.1.1.pyc and /dev/null differ diff --git a/tests/golden/__pycache__/test_stem_to_remix.cpython-312-pytest-9.1.1.pyc b/tests/golden/__pycache__/test_stem_to_remix.cpython-312-pytest-9.1.1.pyc deleted file mode 100644 index c980c85..0000000 Binary files a/tests/golden/__pycache__/test_stem_to_remix.cpython-312-pytest-9.1.1.pyc and /dev/null differ diff --git a/tests/golden/__pycache__/test_stems_to_spatial.cpython-312-pytest-9.1.1.pyc b/tests/golden/__pycache__/test_stems_to_spatial.cpython-312-pytest-9.1.1.pyc deleted file mode 100644 index 9797e05..0000000 Binary files a/tests/golden/__pycache__/test_stems_to_spatial.cpython-312-pytest-9.1.1.pyc and /dev/null differ diff --git a/tests/golden/__pycache__/test_surround_downmix.cpython-312-pytest-9.1.1.pyc b/tests/golden/__pycache__/test_surround_downmix.cpython-312-pytest-9.1.1.pyc deleted file mode 100644 index 744cf3d..0000000 Binary files a/tests/golden/__pycache__/test_surround_downmix.cpython-312-pytest-9.1.1.pyc and /dev/null differ diff --git a/tests/golden/__pycache__/test_text_to_music.cpython-312-pytest-9.1.1.pyc b/tests/golden/__pycache__/test_text_to_music.cpython-312-pytest-9.1.1.pyc deleted file mode 100644 index 39266a1..0000000 Binary files a/tests/golden/__pycache__/test_text_to_music.cpython-312-pytest-9.1.1.pyc and /dev/null differ diff --git a/tests/golden/__pycache__/test_transcribe_and_regenerate.cpython-312-pytest-9.1.1.pyc b/tests/golden/__pycache__/test_transcribe_and_regenerate.cpython-312-pytest-9.1.1.pyc deleted file mode 100644 index 8ee4c19..0000000 Binary files a/tests/golden/__pycache__/test_transcribe_and_regenerate.cpython-312-pytest-9.1.1.pyc and /dev/null differ diff --git a/tests/golden/__pycache__/test_transcribe_to_midi.cpython-312-pytest-9.1.1.pyc b/tests/golden/__pycache__/test_transcribe_to_midi.cpython-312-pytest-9.1.1.pyc deleted file mode 100644 index f038497..0000000 Binary files a/tests/golden/__pycache__/test_transcribe_to_midi.cpython-312-pytest-9.1.1.pyc and /dev/null differ diff --git a/tests/test_project_upload.py b/tests/test_project_upload.py index ebe5694..85c4725 100644 --- a/tests/test_project_upload.py +++ b/tests/test_project_upload.py @@ -2,6 +2,8 @@ from pathlib import Path +import pytest + from groovy.server.project_assets import resolve_uploaded_audio @@ -29,3 +31,27 @@ def test_upload_copies_sidecar_into_uploads_when_no_matching_export(tmp_path: Pa sidecar = tmp_path / "assets" / "uploads" / "take.provenance.json" assert sidecar.is_file() assert sidecar.read_text() == '{"ok": true}' + + +def test_upload_rejects_unsupported_extension(tmp_path: Path) -> None: + with pytest.raises(ValueError, match="Unsupported file type"): + resolve_uploaded_audio(tmp_path, "payload.exe", b"MZ") + + +def test_upload_rejects_oversized_payload(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None: + import groovy.server.project_assets as assets + + monkeypatch.setattr(assets, "MAX_UPLOAD_BYTES", 16) + with pytest.raises(ValueError, match="File too large"): + resolve_uploaded_audio(tmp_path, "big.wav", b"x" * 17) + + +def test_upload_does_not_silently_overwrite(tmp_path: Path) -> None: + dest_dir = tmp_path / "assets" / "uploads" + dest_dir.mkdir(parents=True) + (dest_dir / "take.wav").write_bytes(b"first") + + path = resolve_uploaded_audio(tmp_path, "take.wav", b"second") + assert path == "assets/uploads/take-1.wav" + assert (dest_dir / "take.wav").read_bytes() == b"first" + assert (dest_dir / "take-1.wav").read_bytes() == b"second" diff --git a/tests/test_safe_cache_id.py b/tests/test_safe_cache_id.py new file mode 100644 index 0000000..a7566bb --- /dev/null +++ b/tests/test_safe_cache_id.py @@ -0,0 +1,61 @@ +from __future__ import annotations + +import uuid +from pathlib import Path + +import numpy as np +import pytest + +from groovy.executor.audio import AudioBuffer +from groovy.executor.cache import CacheStore, safe_cache_id + + +def test_safe_cache_id_accepts_uuid4() -> None: + cid = str(uuid.uuid4()) + assert safe_cache_id(cid) == cid + + +@pytest.mark.parametrize("ok", ["left", "right", "a", "mix-1", "n2"]) +def test_safe_cache_id_accepts_short_fixture_ids(ok: str) -> None: + assert safe_cache_id(ok) == ok + + +@pytest.mark.parametrize( + "bad", + [ + "", + "../etc/passwd", + "abc/../def", + "foo/bar", + r"foo\bar", + "..", + "has space-xxxxxxxx", + "-leading-hyphen", + ], +) +def test_safe_cache_id_rejects_traversal(bad: str) -> None: + with pytest.raises(ValueError): + safe_cache_id(bad) + + +def test_cache_store_read_meta_rejects_traversal(tmp_path: Path) -> None: + store = CacheStore(tmp_path) + with pytest.raises(ValueError, match="Invalid cache_id"): + store.read_meta("../secret") + + +def test_cache_store_roundtrip_uuid(tmp_path: Path) -> None: + store = CacheStore(tmp_path) + pcm = np.zeros((1, 8), dtype=np.float64) + buf = AudioBuffer.from_planar(pcm, sample_rate=48_000) + store.write_audio(buf, pcm) + meta = store.read_meta(buf.id) + assert meta["id"] == buf.id + _, loaded = store.load_audio(buf.id) + assert loaded.shape == pcm.shape + + +def test_cache_store_provenance_rejects_encoded_traversal(tmp_path: Path) -> None: + store = CacheStore(tmp_path) + with pytest.raises(ValueError, match="Invalid cache_id"): + store.read_provenance("..%2fetc%2fpasswd")