"""Clone verb atomic tests against staging.musehub.ai. Tests: CL0: clone gabriel/timing-test (~100c+) CL1: clone gabriel/muse (~799c) Usage: python3 scripts/clone_staging.py """ from __future__ import annotations import json import os import shutil import subprocess import sys import time MUSE = "muse" HUB = "https://staging.musehub.ai" OWNER = "gabriel" def run(cmd: list[str], cwd: str | None = None, check: bool = True) -> subprocess.CompletedProcess: return subprocess.run(cmd, cwd=cwd, capture_output=True, text=True, check=check) def timed_clone_url(url: str, dest: str, branch: str = "main") -> dict: if os.path.exists(dest): shutil.rmtree(dest) t0 = time.perf_counter() r = run([MUSE, "clone", url, dest, "--branch", branch], check=False) elapsed = round((time.perf_counter() - t0) * 1000, 1) ok = r.returncode == 0 err = None if not ok: output = r.stdout + r.stderr for line in output.splitlines(): if "❌" in line or "Error" in line or "failed" in line.lower(): err = line.strip() break if not err: err = (r.stdout + r.stderr).strip()[:200] commits_received = None try: d = json.loads(r.stdout) commits_received = d.get("commits_received") except Exception: pass return {"ok": ok, "t_total": elapsed, "error": err, "commits_received": commits_received} def fmt(label: str, r: dict, extra: str = "") -> str: ok = "✅" if r["ok"] else "❌" err = f" ERROR: {r['error']}" if r.get("error") else "" cr = r.get("commits_received") received = f" [{cr}c received]" if cr is not None else "" return ( f" {label:46s}" f" total={str(r['t_total']):>9}ms" f" {ok}{received}{extra}{err}" ) CASES = [ ("CL0", "M", "timing-test", "~100c+"), ("CL1", "L", "muse", "~799c"), ] def main() -> None: print(f"\n── Clone atomic tests → {HUB} ──") print(f" {'label':46s} {'total':>12} status") print(" " + "-" * 90) for tag, scale, repo_slug, size_label in CASES: label = f"{tag}: clone {repo_slug} {size_label} ({scale})" clone_url = f"{HUB}/{OWNER}/{repo_slug}" dest = f"/tmp/clone-staging-{tag.lower()}" r = timed_clone_url(clone_url, dest) print(fmt(label, r)) sys.stdout.flush() if not r["ok"]: print(f"\n❌ {tag} failed — stopping.\n {r['error']}") return print() if __name__ == "__main__": main()