A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.
Python artificial-intelligencedagdata-sciencedata-visualizationdataflowdeveloper-toolsmachine-learningnotebookspipelinepythonreactivesqlweb-app
Require notebook identity before yielding pair test servers (#11422)
Trevor Manze84c14dbc734
diff --git a/tests/_cli/_pair_server.py b/tests/_cli/_pair_server.pyindex a7482995a5..56a4ff71c7 100644--- a/tests/_cli/_pair_server.py+++ b/tests/_cli/_pair_server.py@@ -26,7 +26,7 @@ class PairTestServer:url: strsession_id: strstable_session_id: str- notebook_id: str | None+ notebook_id: str_process: subprocess.Popen[bytes]_websocket: ClientConnection_stderr_path: Path@@ -141,18 +141,23 @@ def _wait_for_kernel_ready(websocket: ClientConnection,*,timeout: float = 10.0,-) -> None:+) -> str:deadline = time.monotonic() + timeout+ notebook_id: str | None = Nonewhile True:remaining = deadline - time.monotonic()if remaining <= 0:raise TimeoutError("kernel did not become ready")event = json.loads(websocket.recv(timeout=remaining))+ if event["event"] == "notebook":+ notebook_id = event["data"]["notebook"]["id"]if event["event"] != "marimo":continuemessage = event["data"]["marimo"]if message["op"] == "kernel-ready":- return+ # The host publishes notebook identity before kernel-ready.+ assert isinstance(notebook_id, str), "Missing notebook snapshot"+ return notebook_iddef _stop_process(process: subprocess.Popen[bytes]) -> None:@@ -227,19 +232,20 @@ def pair_test_server(if tokenelse {},)- _wait_for_kernel_ready(websocket)+ notebook_id = _wait_for_kernel_ready(websocket)request = urllib.request.Request(f"{url}/api/sessions",headers={"Authorization": f"Bearer {token}"} if token else {},)with urllib.request.urlopen(request, timeout=5) as response:sessions = json.load(response)+ assert sessions[session_id]["notebook_id"] == notebook_idstable_session_id = sessions[session_id]["session_id"]server = PairTestServer(url=url,session_id=session_id,stable_session_id=stable_session_id,- notebook_id=sessions[session_id].get("notebook_id"),+ notebook_id=notebook_id,_process=process,_websocket=websocket,_stderr_path=stderr_path,diff --git a/tests/_cli/test_pair_integration.py b/tests/_cli/test_pair_integration.pyindex a61e401863..31d463cf3e 100644--- a/tests/_cli/test_pair_integration.py+++ b/tests/_cli/test_pair_integration.py@@ -33,7 +33,6 @@ def _command() -> list[str]:target = []if selector == "notebook":- assert server.notebook_id is not Nonetarget = ["--notebook", server.notebook_id]elif selector == "session":target = ["--session", server.stable_session_id]@@ -137,7 +136,6 @@ def test_authenticated_execution_preserves_session_contract() -> None:token_file = tmp_path / "token"token_file.write_text("pair-editor-private-token")- assert editor_server.notebook_id is not Noneresult = _run(editor_server,"--token-file",