File size: 2,956 Bytes
434c049
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
"""Basic tests for the AI Creative Studio & Moldovan AI Media Studio.

These tests verify:
- app.py and studio_server.py can be compiled and parsed syntactically.
- The FastAPI endpoints exist and audio synthesizer functions properly.
"""

import os
import sys
import py_compile
import pytest
from pathlib import Path

PROJECT_ROOT = Path(__file__).resolve().parent.parent
sys.path.insert(0, str(PROJECT_ROOT))
sys.path.insert(0, str(PROJECT_ROOT / "moldovan-qwen"))


def test_app_imports():
    """Verify the app module can be parsed syntactically without errors."""
    result = py_compile.compile(str(PROJECT_ROOT / "app.py"), doraise=True)
    assert result is not None and os.path.exists(result), f"app.py has syntax errors: {result}"


def test_studio_server_imports():
    """Verify the moldovan studio server can be parsed syntactically."""
    server_path = PROJECT_ROOT / "moldovan-qwen" / "studio_server.py"
    result = py_compile.compile(str(server_path), doraise=True)
    assert result is not None and os.path.exists(result), f"studio_server.py syntax error: {result}"


def test_audio_synthesizer_imports():
    """Verify audio synthesizer module compiles."""
    synth_path = PROJECT_ROOT / "moldovan-qwen" / "engine" / "audio_synthesizer.py"
    result = py_compile.compile(str(synth_path), doraise=True)
    assert result is not None and os.path.exists(result), f"audio_synthesizer.py syntax error: {result}"


def test_native_audio_wav_generation(tmp_path):
    """Verify that native PCM WAV audio files are generated correctly."""
    from engine.audio_synthesizer import MoldovanAudioSynthesizer
    synth = MoldovanAudioSynthesizer(output_dir=str(tmp_path))
    res = synth.generate_track_audio("Test Beat", genre="Chișinău 808 Trap", bpm=140, bars=2)
    assert res["success"] is True
    assert os.path.exists(res["file_path"])
    assert os.path.getsize(res["file_path"]) > 10000


def test_environment():
    """Verify HF_TOKEN is set in environment (skip in CI/dev)."""
    token = os.getenv("HF_TOKEN")
    if token is None:
        pytest.skip("HF_TOKEN not set — skip in CI/dev environments")
    assert token is not None, "HF_TOKEN must be set"


def test_api_endpoints_exist():
    """Verify the API endpoints are defined in the module."""
    app_source = (PROJECT_ROOT / "app.py").read_text()
    assert "/v1/health" in app_source, "Health endpoint not found in app.py"
    assert "/v1/gpu/status" in app_source, "GPU status endpoint not found in app.py"
    assert "/v1/chat/completions" in app_source, "Chat completions endpoint not found in app.py"


def test_model_paths_exist():
    """Verify model files exist on disk (HF Space mount)."""
    model_path = Path("/data/gemma-4-26B-A4B-it-ultra-uncensored-heretic.i1-Q4_K_M.gguf")
    if not model_path.exists():
        pytest.skip(f"Model not found at {model_path} — expected on HF Spaces")
    assert model_path.exists(), f"Model not found at {model_path}"