Spaces:
Sleeping
Sleeping
Test: key and progress survive a server restart
Browse files19 unmodified lines202122232423242526272829283031323132333435363738394057 unmodified lines989910010110210310410510610710810911011111211311411511619 unmodified linesfake = Fake()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")env.pop("SPACE_ID", None)srv = subprocess.Popen([sys.executable, "app.py"], cwd=ROOT, env=env, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)try:
def start_server(): proc = subprocess.Popen([sys.executable, "app.py"], cwd=ROOT, env=env, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) for _ in range(60): try: urllib.request.urlopen(URL, timeout=1) break return proc except Exception: time.sleep(0.5) else: raise SystemExit("server did not start:\n" + srv.stdout.read().decode()) raise SystemExit("server did not start:\n" + proc.stdout.read().decode())
srv = start_server()try:
with sync_playwright() as pw: exe = CHROMIUM if os.path.exists(CHROMIUM) else None57 unmodified lines expect(page.get_by_label("OpenRouter API key")).to_have_value("sk-or-UITESTKEY") print("ok progress and key persist across reload")
# 7b. persistence across a SERVER RESTART (a Space sleeping or rebuilding). # BrowserState encrypts with a per-process random secret unless one is set, # which silently drops the saved key and progress after a restart. srv.terminate() srv.wait() srv = start_server() page.reload() page.get_by_role("tab", name="Progress").click() expect(page.get_by_text("1 drills")).to_be_visible(timeout=20000) page.get_by_role("tab", name="Settings").click() expect(page.get_by_label("OpenRouter API key")).to_have_value("sk-or-UITESTKEY") print("ok key and progress survive a server restart")
# 8. model list refresh via the fake server page.get_by_role("button", name="Load current OpenRouter model list").click() expect(page.get_by_text("2 models loaded")).to_be_visible(timeout=10000)tests/test_ui.py+23-5