pull_staging.py
python
sha256:7d6dd8f4a89e2d1fef2d84f6e65feaff51385d382f466766b7f690a22ec18e32
fix: fall back to DB ancestry check when mpack-only fast-fo…
Sonnet 4.6
patch
7 days ago
| 1 | """Pull verb atomic tests against staging.musehub.ai. |
| 2 | |
| 3 | Builds a source repo with real muse commits, pushes to gabriel/timing-test, |
| 4 | then exercises clone + incremental pull roundtrips. |
| 5 | |
| 6 | Tests: |
| 7 | PL0: clone-equivalent — pull 100 commits into an empty local repo |
| 8 | PL1: +1 commit incremental |
| 9 | PL2: +10 commits incremental |
| 10 | PL3: +100 commits incremental |
| 11 | |
| 12 | Usage: |
| 13 | python3 scripts/pull_staging.py |
| 14 | """ |
| 15 | from __future__ import annotations |
| 16 | |
| 17 | import json |
| 18 | import os |
| 19 | import shutil |
| 20 | import subprocess |
| 21 | import sys |
| 22 | import time |
| 23 | |
| 24 | MUSE = "muse" |
| 25 | HUB = "https://staging.musehub.ai" |
| 26 | TIMING_REPO_URL = f"{HUB}/gabriel/timing-test" |
| 27 | |
| 28 | |
| 29 | def run(cmd: list[str], cwd: str | None = None, check: bool = True) -> subprocess.CompletedProcess: |
| 30 | return subprocess.run(cmd, cwd=cwd, capture_output=True, text=True, check=check) |
| 31 | |
| 32 | |
| 33 | def m(args: list[str], cwd: str, check: bool = True) -> subprocess.CompletedProcess: |
| 34 | return run([MUSE] + args, cwd=cwd, check=check) |
| 35 | |
| 36 | |
| 37 | def mj(args: list[str], cwd: str) -> dict: |
| 38 | r = m(args + ["--json"], cwd=cwd) |
| 39 | return json.loads(r.stdout) |
| 40 | |
| 41 | |
| 42 | def fresh_pull_target(path: str) -> str: |
| 43 | if os.path.exists(path): |
| 44 | shutil.rmtree(path) |
| 45 | os.makedirs(path) |
| 46 | m(["init"], cwd=path) |
| 47 | r = run([MUSE, "remote", "add", "staging", TIMING_REPO_URL], cwd=path, check=False) |
| 48 | if r.returncode != 0: |
| 49 | run([MUSE, "remote", "set-url", "staging", TIMING_REPO_URL], cwd=path, check=False) |
| 50 | return path |
| 51 | |
| 52 | |
| 53 | def local_commit_count(repo: str) -> int: |
| 54 | try: |
| 55 | return len(mj(["log"], cwd=repo).get("commits", [])) |
| 56 | except Exception: |
| 57 | return -1 |
| 58 | |
| 59 | |
| 60 | def timed_pull(repo: str, branch: str = "main") -> dict: |
| 61 | t0 = time.perf_counter() |
| 62 | r = run([MUSE, "pull", "staging", branch], cwd=repo, check=False) |
| 63 | elapsed = round((time.perf_counter() - t0) * 1000, 1) |
| 64 | ok = r.returncode == 0 |
| 65 | err = None |
| 66 | if not ok: |
| 67 | output = r.stdout + r.stderr |
| 68 | for line in output.splitlines(): |
| 69 | if "❌" in line or "Error" in line or "failed" in line.lower(): |
| 70 | err = line.strip() |
| 71 | break |
| 72 | if not err: |
| 73 | err = (r.stdout + r.stderr).strip()[:200] |
| 74 | return {"ok": ok, "t_total": elapsed, "error": err} |
| 75 | |
| 76 | |
| 77 | def fmt(label: str, r: dict, extra: str = "") -> str: |
| 78 | ok = "✅" if r["ok"] else "❌" |
| 79 | err = f" ERROR: {r['error']}" if r.get("error") else "" |
| 80 | return ( |
| 81 | f" {label:42s}" |
| 82 | f" total={str(r['t_total']):>8}ms" |
| 83 | f" {ok}{extra}{err}" |
| 84 | ) |
| 85 | |
| 86 | |
| 87 | def _add_commits(src: str, n: int) -> bool: |
| 88 | existing = local_commit_count(src) |
| 89 | for i in range(n): |
| 90 | idx = existing + i |
| 91 | obj_file = os.path.join(src, f"obj_{idx:04d}.dat") |
| 92 | with open(obj_file, "wb") as f: |
| 93 | f.write(os.urandom(512)) |
| 94 | m(["code", "add", f"obj_{idx:04d}.dat"], cwd=src) |
| 95 | m(["commit", "-m", f"pull test commit {idx}", |
| 96 | "--agent-id", "wire-test", "--model-id", "n/a"], cwd=src) |
| 97 | r = run([MUSE, "push", "staging", "main", "--force"], cwd=src, check=False) |
| 98 | return r.returncode == 0 |
| 99 | |
| 100 | |
| 101 | def build_source_repo(path: str, n_commits: int) -> bool: |
| 102 | if os.path.exists(path): |
| 103 | shutil.rmtree(path) |
| 104 | os.makedirs(path) |
| 105 | m(["init"], cwd=path) |
| 106 | r = run([MUSE, "remote", "add", "staging", TIMING_REPO_URL], cwd=path, check=False) |
| 107 | if r.returncode != 0: |
| 108 | run([MUSE, "remote", "set-url", "staging", TIMING_REPO_URL], cwd=path, check=False) |
| 109 | |
| 110 | for i in range(n_commits): |
| 111 | obj_file = os.path.join(path, f"obj_{i:04d}.dat") |
| 112 | with open(obj_file, "wb") as f: |
| 113 | f.write(os.urandom(512)) |
| 114 | m(["code", "add", f"obj_{i:04d}.dat"], cwd=path) |
| 115 | m(["commit", "-m", f"pull test commit {i}", |
| 116 | "--agent-id", "wire-test", "--model-id", "n/a"], cwd=path) |
| 117 | |
| 118 | r = run([MUSE, "push", "staging", "main", "--force"], cwd=path, check=False) |
| 119 | return r.returncode == 0 |
| 120 | |
| 121 | |
| 122 | def main() -> None: |
| 123 | print(f"\n── Pull atomic tests → {HUB} ──") |
| 124 | print(f" {'label':42s} {'total':>12} status") |
| 125 | print(" " + "-" * 85) |
| 126 | |
| 127 | src = "/tmp/pull-staging-src" |
| 128 | print(f" building source repo (100 commits)… ", end="", flush=True) |
| 129 | ok_build = build_source_repo(src, 100) |
| 130 | print("done" if ok_build else "FAILED") |
| 131 | if not ok_build: |
| 132 | print("❌ source repo push failed — stopping.") |
| 133 | return |
| 134 | |
| 135 | target = "/tmp/pull-staging-target" |
| 136 | fresh_pull_target(target) |
| 137 | |
| 138 | r0 = timed_pull(target) |
| 139 | n0 = local_commit_count(target) |
| 140 | print(fmt("PL0: empty→100c+100o (M clone)", r0, f" [{n0}c local]")) |
| 141 | sys.stdout.flush() |
| 142 | if not r0["ok"]: |
| 143 | print(f"\n❌ PL0 failed — stopping.\n {r0['error']}") |
| 144 | return |
| 145 | |
| 146 | _add_commits(src, 1) |
| 147 | r1 = timed_pull(target) |
| 148 | print(fmt("PL1: +1c+1o incremental (XS)", r1, f" [{local_commit_count(target)}c local]")) |
| 149 | sys.stdout.flush() |
| 150 | |
| 151 | _add_commits(src, 10) |
| 152 | r2 = timed_pull(target) |
| 153 | print(fmt("PL2: +10c+10o incremental (XS→S)", r2, f" [{local_commit_count(target)}c local]")) |
| 154 | sys.stdout.flush() |
| 155 | |
| 156 | _add_commits(src, 100) |
| 157 | r3 = timed_pull(target) |
| 158 | print(fmt("PL3: +100c+100o incremental (M)", r3, f" [{local_commit_count(target)}c local]")) |
| 159 | sys.stdout.flush() |
| 160 | |
| 161 | print() |
| 162 | |
| 163 | |
| 164 | if __name__ == "__main__": |
| 165 | main() |
File History
1 commit
sha256:7d6dd8f4a89e2d1fef2d84f6e65feaff51385d382f466766b7f690a22ec18e32
fix: fall back to DB ancestry check when mpack-only fast-fo…
Sonnet 4.6
patch
7 days ago