105 lines
3.5 KiB
Python
Executable File
105 lines
3.5 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""Deterministic E2E runner for sms-activation-providers.
|
|
|
|
Usage:
|
|
python3 scripts/e2e_ci.py
|
|
"""
|
|
import json
|
|
import shlex
|
|
import subprocess
|
|
import time
|
|
from pathlib import Path
|
|
|
|
BASE = ["python3", "scripts/sms_activation.py"]
|
|
REPORT_JSON = Path("reports/e2e_result.json")
|
|
REPORT_MD = Path("reports/e2e-acceptance.md")
|
|
|
|
|
|
def run(args):
|
|
p = subprocess.run(BASE + args, capture_output=True, text=True)
|
|
item = {
|
|
"cmd": " ".join(shlex.quote(x) for x in BASE + args),
|
|
"rc": p.returncode,
|
|
"stdout": p.stdout.strip(),
|
|
"stderr": p.stderr.strip(),
|
|
}
|
|
try:
|
|
item["json"] = json.loads(p.stdout) if p.stdout.strip() else None
|
|
except Exception:
|
|
item["json"] = None
|
|
return item
|
|
|
|
|
|
def extract_order_id(js):
|
|
if isinstance(js, dict):
|
|
return js.get("activationId") or js.get("id")
|
|
return None
|
|
|
|
|
|
def main():
|
|
Path("reports").mkdir(exist_ok=True)
|
|
out = {"ts": time.strftime("%Y-%m-%d %H:%M:%S"), "runs": []}
|
|
|
|
# Proven combinations from live validation on 2026-05-18
|
|
plans = {
|
|
"smsvn": {"country": "12", "operator": "any", "service": "am", "max_price": "0.2"},
|
|
"5sim": {"country": "usa", "operator": "any", "service": "amazon", "max_price": "0.2"},
|
|
"grizzly": {"country": "187", "service": "tg", "max_price": "2", "force_v1": True},
|
|
}
|
|
|
|
for provider, plan in plans.items():
|
|
out["runs"].append(run(["--provider", provider, "--raw", "balance"]))
|
|
|
|
if provider == "smsvn":
|
|
out["runs"].append(run(["--provider", provider, "--raw", "discover", "--country", plan["country"]]))
|
|
elif provider == "5sim":
|
|
out["runs"].append(run(["--provider", provider, "--raw", "discover", "--country", plan["country"], "--operator", plan["operator"]]))
|
|
else:
|
|
out["runs"].append(run(["--provider", provider, "--raw", "discover"]))
|
|
|
|
buy_args = ["--provider", provider, "--raw", "buy", "--country", plan["country"], "--service", plan["service"], "--max-price", plan["max_price"]]
|
|
if provider in {"smsvn", "5sim"}:
|
|
buy_args += ["--operator", plan["operator"]]
|
|
if plan.get("force_v1"):
|
|
buy_args += ["--v1"]
|
|
buy = run(buy_args)
|
|
out["runs"].append(buy)
|
|
|
|
oid = extract_order_id(buy.get("json"))
|
|
if not oid:
|
|
continue
|
|
|
|
oid = str(oid)
|
|
out["runs"].append(run(["--provider", provider, "--raw", "check", "--order-id", oid]))
|
|
out["runs"].append(run(["--provider", provider, "--raw", "poll", "--order-id", oid, "--attempts", "4", "--interval", "2", "--backoff", "1.05"]))
|
|
|
|
if provider == "5sim":
|
|
out["runs"].append(run(["--provider", provider, "--raw", "finish", "--order-id", oid]))
|
|
else:
|
|
out["runs"].append(run(["--provider", provider, "--raw", "cancel", "--order-id", oid]))
|
|
|
|
REPORT_JSON.write_text(json.dumps(out, ensure_ascii=False, indent=2), encoding="utf-8")
|
|
|
|
lines = [
|
|
"# E2E Acceptance Report",
|
|
"",
|
|
f"Date: {out['ts']}",
|
|
"",
|
|
"Generated by `python3 scripts/e2e_ci.py`.",
|
|
"",
|
|
"## Run Summary",
|
|
"",
|
|
]
|
|
for i, r in enumerate(out["runs"], 1):
|
|
state = "OK" if r["rc"] == 0 else "FAIL"
|
|
lines.append(f"{i}. [{state}] `{r['cmd']}`")
|
|
lines += ["", "Raw details: `reports/e2e_result.json`", ""]
|
|
REPORT_MD.write_text("\n".join(lines), encoding="utf-8")
|
|
|
|
print(f"Wrote {REPORT_JSON}")
|
|
print(f"Wrote {REPORT_MD}")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|