Spaces:
Sleeping
Sleeping
| """ | |
| Verifies app.py imports cleanly under file-layout problems that have actually | |
| broken this Space: | |
| A integrations/ folder missing entirely (HF web uploader skips folders) | |
| B integrations/ present but without __init__.py | |
| C integrations/ complete | |
| D app started from a different working directory | |
| Uses the REAL gradio (a verified dependency) and stubs only model loading, so | |
| nothing downloads. Never launches a server — that is test_app.py's job. | |
| """ | |
| import os | |
| import shutil | |
| import subprocess | |
| import sys | |
| import tempfile | |
| SRC = os.path.dirname(os.path.abspath(__file__)) | |
| GREEN, RED, OFF = "\033[92m", "\033[91m", "\033[0m" | |
| HARNESS = ''' | |
| import sys | |
| sys.path.insert(0, sys.argv[2]) | |
| import pipeline as _pl | |
| _pl.HausaVoiceAIPipeline._load_asr = lambda self: None | |
| _pl.HausaVoiceAIPipeline._load_asr_fast = lambda self: None | |
| _pl.HausaVoiceAIPipeline._load_nllb = lambda self: None | |
| _pl.HausaVoiceAIPipeline._load_tts = lambda self: None | |
| import runpy | |
| runpy.run_path(sys.argv[1], run_name="__not_main__") | |
| print("IMPORT_OK") | |
| ''' | |
| def scenario(name, setup, cwd=None): | |
| tmp = tempfile.mkdtemp() | |
| for f in os.listdir(SRC): | |
| if f.endswith(".py"): | |
| shutil.copy(os.path.join(SRC, f), tmp) | |
| setup(tmp) | |
| harness = os.path.join(tmp, "_h.py") | |
| with open(harness, "w") as fh: | |
| fh.write(HARNESS) | |
| r = subprocess.run( | |
| [sys.executable, harness, os.path.join(tmp, "app.py"), tmp], | |
| capture_output=True, text=True, cwd=cwd or tmp) | |
| ok = "IMPORT_OK" in r.stdout | |
| tag = f"{GREEN}BOOTS{OFF}" if ok else f"{RED}CRASH{OFF}" | |
| print(f" [{tag}] {name}") | |
| if not ok: | |
| tail = (r.stderr or r.stdout).strip().splitlines() | |
| print(" " + (tail[-1] if tail else "no output")) | |
| shutil.rmtree(tmp, ignore_errors=True) | |
| return ok | |
| def none(tmp): | |
| pass | |
| def no_init(tmp): | |
| d = os.path.join(tmp, "integrations") | |
| os.makedirs(d, exist_ok=True) | |
| for f in ("crm.py", "sip.py", "whatsapp.py"): | |
| shutil.copy(os.path.join(SRC, "integrations", f), d) | |
| def full(tmp): | |
| d = os.path.join(tmp, "integrations") | |
| os.makedirs(d, exist_ok=True) | |
| for f in os.listdir(os.path.join(SRC, "integrations")): | |
| if f.endswith(".py"): | |
| shutil.copy(os.path.join(SRC, "integrations", f), d) | |
| print("\n== Space startup scenarios ==") | |
| res = [ | |
| scenario("A: integrations/ missing entirely", none), | |
| scenario("B: integrations/ without __init__.py", no_init), | |
| scenario("C: integrations/ complete", full), | |
| scenario("D: different working directory", full, cwd="/"), | |
| ] | |
| print(f"\n {sum(res)}/{len(res)} scenarios boot cleanly") | |
| sys.exit(0 if all(res) else 1) | |