()
| 50 | |
| 51 | |
| 52 | def main() -> int: |
| 53 | env = os.environ.copy() |
| 54 | env.setdefault("PYTHONUTF8", "1") |
| 55 | env.setdefault("TESTING", "true") |
| 56 | |
| 57 | smoke_root = Path(tempfile.mkdtemp(prefix="astrbot-smoke-root-")) |
| 58 | env["ASTRBOT_ROOT"] = str(smoke_root) |
| 59 | log_path = smoke_root / "smoke.log" |
| 60 | webui_dir = smoke_root / "webui" |
| 61 | webui_dir.mkdir() |
| 62 | (webui_dir / "index.html").write_text( |
| 63 | "<!doctype html><title>AstrBot</title>", |
| 64 | encoding="utf-8", |
| 65 | ) |
| 66 | |
| 67 | with log_path.open("wb") as log_file: |
| 68 | proc = subprocess.Popen( |
| 69 | [ |
| 70 | sys.executable, |
| 71 | str(REPO_ROOT / "main.py"), |
| 72 | "--webui-dir", |
| 73 | str(webui_dir), |
| 74 | ], |
| 75 | cwd=REPO_ROOT, |
| 76 | stdout=log_file, |
| 77 | stderr=subprocess.STDOUT, |
| 78 | env=env, |
| 79 | ) |
| 80 | |
| 81 | print(f"Starting smoke test on {HEALTH_URL}") |
| 82 | deadline = time.monotonic() + STARTUP_TIMEOUT_SECONDS |
| 83 | try: |
| 84 | while time.monotonic() < deadline: |
| 85 | if _is_ready(): |
| 86 | print("Smoke test passed") |
| 87 | return 0 |
| 88 | |
| 89 | return_code = proc.poll() |
| 90 | if return_code is not None: |
| 91 | print( |
| 92 | f"AstrBot exited before becoming healthy. Exit code: {return_code}", |
| 93 | file=sys.stderr, |
| 94 | ) |
| 95 | print(_tail(log_path), file=sys.stderr) |
| 96 | return 1 |
| 97 | |
| 98 | time.sleep(1) |
| 99 | |
| 100 | print( |
| 101 | "Smoke test failed: health endpoint did not become ready in time.", |
| 102 | file=sys.stderr, |
| 103 | ) |
| 104 | print(_tail(log_path), file=sys.stderr) |
| 105 | return 1 |
| 106 | finally: |
| 107 | _stop_process(proc) |
| 108 | try: |
| 109 | log_path.unlink() |
no test coverage detected