Spaces:
Running
Running
Add Space runtime smoke check
Browse files- README.md +2 -0
- check_space_runtime.py +55 -0
- frontend/local_server.py +1 -0
README.md
CHANGED
|
@@ -157,6 +157,8 @@ Then open `http://127.0.0.1:7860`.
|
|
| 157 |
Before pushing Space changes, run at least:
|
| 158 |
|
| 159 |
```bash
|
|
|
|
|
|
|
| 160 |
python3 -B - <<'PY'
|
| 161 |
from pathlib import Path
|
| 162 |
import py_compile
|
|
|
|
| 157 |
Before pushing Space changes, run at least:
|
| 158 |
|
| 159 |
```bash
|
| 160 |
+
python3 check_space_runtime.py
|
| 161 |
+
|
| 162 |
python3 -B - <<'PY'
|
| 163 |
from pathlib import Path
|
| 164 |
import py_compile
|
check_space_runtime.py
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import asyncio
|
| 4 |
+
import tempfile
|
| 5 |
+
from pathlib import Path
|
| 6 |
+
|
| 7 |
+
from frontend import local_server
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def main() -> int:
|
| 11 |
+
with tempfile.TemporaryDirectory(prefix="rh_space_check_") as tmp:
|
| 12 |
+
runs_dir = Path(tmp) / "runs"
|
| 13 |
+
local_server.configure_frontend(
|
| 14 |
+
managed_runs_dir=str(runs_dir),
|
| 15 |
+
cleanup_retention_seconds=60,
|
| 16 |
+
cleanup_max_runs=2,
|
| 17 |
+
cleanup_interval_seconds=60,
|
| 18 |
+
collection_enabled=True,
|
| 19 |
+
collection_dataset_repo="CoCoOne/ResearchHarness-Data",
|
| 20 |
+
collection_batch_size=5,
|
| 21 |
+
collection_max_bundle_bytes=1024 * 1024,
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
+
collection_root = local_server._collection_root()
|
| 25 |
+
if collection_root is None or not collection_root.exists():
|
| 26 |
+
raise RuntimeError("collection root was not created")
|
| 27 |
+
|
| 28 |
+
token = local_server._collection_token()
|
| 29 |
+
if token is not None and not isinstance(token, str):
|
| 30 |
+
raise RuntimeError("collection token helper returned a non-string value")
|
| 31 |
+
|
| 32 |
+
loop = asyncio.new_event_loop()
|
| 33 |
+
try:
|
| 34 |
+
bridge = local_server.FrontendRunBridge(loop=loop)
|
| 35 |
+
workspace_root, trace_dir = local_server._create_managed_run(bridge)
|
| 36 |
+
run_root = Path(bridge.managed_run_root)
|
| 37 |
+
(workspace_root / "answer.txt").write_text("ok\n", encoding="utf-8")
|
| 38 |
+
Path(trace_dir, "trace.jsonl").write_text('{"ok": true}\n', encoding="utf-8")
|
| 39 |
+
bundle = local_server._write_collection_bundle(
|
| 40 |
+
run_root,
|
| 41 |
+
{"result_text": "ok", "termination": "result"},
|
| 42 |
+
)
|
| 43 |
+
if bundle is None or not bundle.exists():
|
| 44 |
+
raise RuntimeError("collection bundle was not created")
|
| 45 |
+
local_server._release_managed_run(bridge)
|
| 46 |
+
local_server.cleanup_managed_runs_once()
|
| 47 |
+
finally:
|
| 48 |
+
loop.close()
|
| 49 |
+
|
| 50 |
+
print("space runtime ok")
|
| 51 |
+
return 0
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
if __name__ == "__main__":
|
| 55 |
+
raise SystemExit(main())
|
frontend/local_server.py
CHANGED
|
@@ -4,6 +4,7 @@ import asyncio
|
|
| 4 |
import base64
|
| 5 |
import datetime as _dt
|
| 6 |
import json
|
|
|
|
| 7 |
import re
|
| 8 |
import shutil
|
| 9 |
import threading
|
|
|
|
| 4 |
import base64
|
| 5 |
import datetime as _dt
|
| 6 |
import json
|
| 7 |
+
import os
|
| 8 |
import re
|
| 9 |
import shutil
|
| 10 |
import threading
|