chore(backend): repair test suite and bring ruff to green

The suite hadn't run green since the routes refactor:
- test_profile_duplicate_names.py imported the pre-refactor module
  layout and broke collection; now imports backend.services.profiles
- tests/conftest.py puts the repo root and backend dir on sys.path so
  files collect standalone instead of depending on run order
- test_cors.py tested a hand-copied mirror of the origin list that had
  drifted from app.py (missing http://tauri.localhost); it now builds
  the app via the real create_app() factory
- test_progress.py simulated a 1KB download, below the tracker's 1MB
  reporting threshold; simulation raised to 5MB
- slow/timeout markers registered in pyproject

Ruff: ~900 violations auto-fixed (typing modernization, import
sorting, unused imports, whitespace). The remaining rules are baselined
in pyproject.toml with per-rule counts to burn down, plus per-file
carve-outs for deliberate env-before-import ordering. ruff check is
now clean; suite is 134 passed, 2 skipped.
This commit is contained in:
Jamie Pine
2026-07-26 23:16:09 -07:00
parent 766c51a8a1
commit b434db22f6
82 changed files with 970 additions and 999 deletions
+16 -16
View File
@@ -2,10 +2,10 @@
Audio processing utilities.
"""
import librosa
import numpy as np
import soundfile as sf
import librosa
from typing import Tuple, Optional
def normalize_audio(
@@ -15,32 +15,32 @@ def normalize_audio(
) -> np.ndarray:
"""
Normalize audio to target loudness with peak limiting.
Args:
audio: Input audio array
target_db: Target RMS level in dB
peak_limit: Peak limit (0.0-1.0)
Returns:
Normalized audio array
"""
# Convert to float32
audio = audio.astype(np.float32)
# Calculate current RMS
rms = np.sqrt(np.mean(audio**2))
# Calculate target RMS
target_rms = 10**(target_db / 20)
# Apply gain
if rms > 0:
gain = target_rms / rms
audio = audio * gain
# Peak limiting
audio = np.clip(audio, -peak_limit, peak_limit)
return audio
@@ -48,15 +48,15 @@ def load_audio(
path: str,
sample_rate: int = 24000,
mono: bool = True,
) -> Tuple[np.ndarray, int]:
) -> tuple[np.ndarray, int]:
"""
Load audio file with normalization.
Args:
path: Path to audio file
sample_rate: Target sample rate
mono: Convert to mono
Returns:
Tuple of (audio_array, sample_rate)
"""
@@ -84,8 +84,8 @@ def save_audio(
Raises:
OSError: If file cannot be written
"""
from pathlib import Path
import os
from pathlib import Path
temp_path = f"{path}.tmp"
try:
@@ -264,7 +264,7 @@ def validate_reference_audio(
min_duration: float = 2.0,
max_duration: float = 30.0,
min_rms: float = 0.01,
) -> Tuple[bool, Optional[str]]:
) -> tuple[bool, str | None]:
"""
Validate reference audio for voice cloning.
@@ -288,7 +288,7 @@ def validate_and_load_reference_audio(
min_duration: float = 2.0,
max_duration: float = 30.0,
min_rms: float = 0.01,
) -> Tuple[bool, Optional[str], Optional[np.ndarray], Optional[int]]:
) -> tuple[bool, str | None, np.ndarray | None, int | None]:
"""
Validate and load reference audio in a single pass.
@@ -315,4 +315,4 @@ def validate_and_load_reference_audio(
return True, None, audio, sr
except Exception as e:
return False, f"Error validating audio: {str(e)}", None, None
return False, f"Error validating audio: {e!s}", None, None