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
improvement: check node version (#6130)
Myles Scolnick159c6f92f645
diff --git a/marimo/_server/lsp.py b/marimo/_server/lsp.pyindex 8786268253..9d866b3cf9 100644--- a/marimo/_server/lsp.py+++ b/marimo/_server/lsp.py@@ -142,11 +142,42 @@ class CopilotLspServer(BaseLspServer):id = "copilot"def validate_requirements(self) -> Union[str, Literal[True]]:- if DependencyManager.which("node"):- return True- return (- "node.js binary is missing. Install node at https://nodejs.org/."- )+ if not DependencyManager.which("node"):+ return "node.js binary is missing. Install node at https://nodejs.org/."++ # Check Node.js version+ try:+ result = subprocess.run(+ ["node", "--version"],+ capture_output=True,+ text=True,+ timeout=5,+ )+ if result.returncode == 0:+ version_str = result.stdout.strip()+ if version_str.startswith("v"):+ version_str = version_str[1:] # Remove 'v' prefix++ # Parse major version+ major_version = int(version_str.split(".")[0])+ if major_version < 20:+ return (+ f"Node.js version {version_str} is too old. "+ "GitHub Copilot requires Node.js version 20 or higher. "+ "Please upgrade at https://nodejs.org/."+ )+ else:+ # Fail open: If the node version check fails we don't want to not start the server.+ # If it fails again, the user will be alerted again.+ LOGGER.info(+ "Failed to get Node.js version, stderr: %s", result.stderr+ )+ except Exception as e:+ # Fail open: If the node version check fails we don't want to not start the server.+ # If it fails again, the user will be alerted again.+ LOGGER.info("Failed to check Node.js version: %s", e)++ return Truedef _lsp_dir(self) -> Path:lsp_dir = marimo_package_path() / "_lsp"diff --git a/tests/_server/test_lsp.py b/tests/_server/test_lsp.pyindex 14103ef804..e9504b8700 100644--- a/tests/_server/test_lsp.py+++ b/tests/_server/test_lsp.py@@ -131,6 +131,74 @@ def test_copilot_server():assert "GitHub Copilot" in alert.title+def test_copilot_server_node_version_validation():+ server = CopilotLspServer(port=8000)++ # Test missing node+ with mock.patch(+ "marimo._dependencies.dependencies.DependencyManager.which",+ return_value=None,+ ):+ result = server.validate_requirements()+ assert isinstance(result, str)+ assert "node.js binary is missing" in result++ # Test node version < 20+ with (+ mock.patch(+ "marimo._dependencies.dependencies.DependencyManager.which",+ return_value="/usr/bin/node",+ ),+ mock.patch("subprocess.run") as mock_run,+ ):+ mock_run.return_value = mock.MagicMock(+ returncode=0, stdout="v18.17.0\n"+ )+ result = server.validate_requirements()+ assert isinstance(result, str)+ assert "Node.js version 18.17.0 is too old" in result+ assert "requires Node.js version 20 or higher" in result++ # Test node version >= 20+ with (+ mock.patch(+ "marimo._dependencies.dependencies.DependencyManager.which",+ return_value="/usr/bin/node",+ ),+ mock.patch("subprocess.run") as mock_run,+ ):+ mock_run.return_value = mock.MagicMock(+ returncode=0, stdout="v20.10.0\n"+ )+ result = server.validate_requirements()+ assert result is True++ # Test subprocess failure (fail open)+ with (+ mock.patch(+ "marimo._dependencies.dependencies.DependencyManager.which",+ return_value="/usr/bin/node",+ ),+ mock.patch("subprocess.run") as mock_run,+ ):+ mock_run.return_value = mock.MagicMock(+ returncode=1, stderr="Command failed"+ )+ result = server.validate_requirements()+ assert result is True # Should fail open++ # Test exception during version check (fail open)+ with (+ mock.patch(+ "marimo._dependencies.dependencies.DependencyManager.which",+ return_value="/usr/bin/node",+ ),+ mock.patch("subprocess.run", side_effect=Exception("Network error")),+ ):+ result = server.validate_requirements()+ assert result is True # Should fail open++def test_composite_server():def as_reader(completion_config: CompletionConfig, config: LanguageServersConfig