Spaces:
Sleeping
Sleeping
Test: key and progress survive a server restart
Browse files19 unmodified lines2021222324252627282930313233343557 unmodified lines93949596979819 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:for _ in range(60):try:urllib.request.urlopen(URL, timeout=1)breakexcept Exception:time.sleep(0.5)else:raise SystemExit("server did not start:\n" + srv.stdout.read().decode())with sync_playwright() as pw:exe = CHROMIUM if os.path.exists(CHROMIUM) else None57 unmodified linesexpect(page.get_by_label("OpenRouter API key")).to_have_value("sk-or-UITESTKEY")print("ok progress and key persist across reload")# 8. model list refresh via the fake serverpage.get_by_role("button", name="Load current OpenRouter model list").click()expect(page.get_by_text("2 models loaded")).to_be_visible(timeout=10000)19 unmodified lines20212223242526272829303132333435363738394057 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)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)return procexcept Exception:time.sleep(0.5)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 linesexpect(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 serverpage.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