Spaces:
Sleeping
Sleeping
Test: key and progress survive a server restart
Browse files- tests/test_ui.py +23 -5
tests/test_ui.py
CHANGED
|
@@ -20,16 +20,21 @@ CHROMIUM = os.environ.get("CHROMIUM_PATH") or "/opt/pw-browsers/chromium-1194/ch
|
|
| 20 |
fake = Fake()
|
| 21 |
env = dict(os.environ, OPENROUTER_BASE_URL=fake.url, GRADIO_SERVER_PORT=str(PORT), NO_PROXY="127.0.0.1,localhost", no_proxy="127.0.0.1,localhost")
|
| 22 |
env.pop("SPACE_ID", None)
|
| 23 |
-
|
| 24 |
-
|
|
|
|
|
|
|
| 25 |
for _ in range(60):
|
| 26 |
try:
|
| 27 |
urllib.request.urlopen(URL, timeout=1)
|
| 28 |
-
|
| 29 |
except Exception:
|
| 30 |
time.sleep(0.5)
|
| 31 |
-
|
| 32 |
-
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
with sync_playwright() as pw:
|
| 35 |
exe = CHROMIUM if os.path.exists(CHROMIUM) else None
|
|
@@ -93,6 +98,19 @@ try:
|
|
| 93 |
expect(page.get_by_label("OpenRouter API key")).to_have_value("sk-or-UITESTKEY")
|
| 94 |
print("ok progress and key persist across reload")
|
| 95 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
# 8. model list refresh via the fake server
|
| 97 |
page.get_by_role("button", name="Load current OpenRouter model list").click()
|
| 98 |
expect(page.get_by_text("2 models loaded")).to_be_visible(timeout=10000)
|
|
|
|
| 20 |
fake = Fake()
|
| 21 |
env = dict(os.environ, OPENROUTER_BASE_URL=fake.url, GRADIO_SERVER_PORT=str(PORT), NO_PROXY="127.0.0.1,localhost", no_proxy="127.0.0.1,localhost")
|
| 22 |
env.pop("SPACE_ID", None)
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
def start_server():
|
| 26 |
+
proc = subprocess.Popen([sys.executable, "app.py"], cwd=ROOT, env=env, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
| 27 |
for _ in range(60):
|
| 28 |
try:
|
| 29 |
urllib.request.urlopen(URL, timeout=1)
|
| 30 |
+
return proc
|
| 31 |
except Exception:
|
| 32 |
time.sleep(0.5)
|
| 33 |
+
raise SystemExit("server did not start:\n" + proc.stdout.read().decode())
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
srv = start_server()
|
| 37 |
+
try:
|
| 38 |
|
| 39 |
with sync_playwright() as pw:
|
| 40 |
exe = CHROMIUM if os.path.exists(CHROMIUM) else None
|
|
|
|
| 98 |
expect(page.get_by_label("OpenRouter API key")).to_have_value("sk-or-UITESTKEY")
|
| 99 |
print("ok progress and key persist across reload")
|
| 100 |
|
| 101 |
+
# 7b. persistence across a SERVER RESTART (a Space sleeping or rebuilding).
|
| 102 |
+
# BrowserState encrypts with a per-process random secret unless one is set,
|
| 103 |
+
# which silently drops the saved key and progress after a restart.
|
| 104 |
+
srv.terminate()
|
| 105 |
+
srv.wait()
|
| 106 |
+
srv = start_server()
|
| 107 |
+
page.reload()
|
| 108 |
+
page.get_by_role("tab", name="Progress").click()
|
| 109 |
+
expect(page.get_by_text("1 drills")).to_be_visible(timeout=20000)
|
| 110 |
+
page.get_by_role("tab", name="Settings").click()
|
| 111 |
+
expect(page.get_by_label("OpenRouter API key")).to_have_value("sk-or-UITESTKEY")
|
| 112 |
+
print("ok key and progress survive a server restart")
|
| 113 |
+
|
| 114 |
# 8. model list refresh via the fake server
|
| 115 |
page.get_by_role("button", name="Load current OpenRouter model list").click()
|
| 116 |
expect(page.get_by_text("2 models loaded")).to_be_visible(timeout=10000)
|