Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 113 additions & 0 deletions selftests/test_workbench_runtime_versions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
"""Tests for Workbench runtime version verification feature."""

from __future__ import annotations

import textwrap

import pytest

from vip.config import RuntimesConfig, VIPConfig, load_config
from vip_tests.workbench.pages.homepage import NewSessionDialog


class TestRuntimesConfigExcluded:
def test_defaults_to_empty_excluded_lists(self):
rc = RuntimesConfig()
assert rc.r_excluded_versions == []
assert rc.python_excluded_versions == []

def test_accepts_excluded_versions(self):
rc = RuntimesConfig(
r_versions=["4.3.1", "4.4.0"],
python_versions=["3.11.0"],
r_excluded_versions=["3.6.3"],
python_excluded_versions=["2.7.18"],
)
assert rc.r_excluded_versions == ["3.6.3"]
assert rc.python_excluded_versions == ["2.7.18"]

def test_load_config_reads_excluded_versions(self, tmp_path):
cfg_file = tmp_path / "vip.toml"
cfg_file.write_text(
textwrap.dedent("""\
[runtimes]
r_versions = ["4.3.1", "4.4.0"]
python_versions = ["3.11.0"]
r_excluded_versions = ["3.6.3", "3.5.0"]
python_excluded_versions = ["2.7.18"]
""")
)
config = load_config(cfg_file)
assert config.runtimes.r_versions == ["4.3.1", "4.4.0"]
assert config.runtimes.python_versions == ["3.11.0"]
assert config.runtimes.r_excluded_versions == ["3.6.3", "3.5.0"]
assert config.runtimes.python_excluded_versions == ["2.7.18"]

def test_load_config_excluded_default_empty(self, tmp_path):
cfg_file = tmp_path / "vip.toml"
cfg_file.write_text(
textwrap.dedent("""\
[runtimes]
r_versions = ["4.3.1"]
""")
)
config = load_config(cfg_file)
assert config.runtimes.r_excluded_versions == []
assert config.runtimes.python_excluded_versions == []

def test_vip_config_default_runtimes_excluded_empty(self):
config = VIPConfig()
assert config.runtimes.r_excluded_versions == []
assert config.runtimes.python_excluded_versions == []


class TestNewSessionDialogVersionSelectors:
def test_r_version_dropdown_selector_defined(self):
assert hasattr(NewSessionDialog, "R_VERSION_DROPDOWN")
assert NewSessionDialog.R_VERSION_DROPDOWN

def test_python_version_dropdown_selector_defined(self):
assert hasattr(NewSessionDialog, "PYTHON_VERSION_DROPDOWN")
assert NewSessionDialog.PYTHON_VERSION_DROPDOWN

def test_r_version_selector_is_css_id(self):
assert NewSessionDialog.R_VERSION_DROPDOWN.startswith("#")

def test_python_version_selector_is_css_id(self):
assert NewSessionDialog.PYTHON_VERSION_DROPDOWN.startswith("#")


class TestRuntimeVersionsFeatureFile:
@pytest.fixture
def feature_path(self):
from pathlib import Path

return (
Path(__file__).parent.parent
/ "src"
/ "vip_tests"
/ "workbench"
/ "test_runtime_versions.feature"
)

def test_feature_file_exists(self, feature_path):
assert feature_path.exists(), f"Feature file not found: {feature_path}"

def test_feature_has_workbench_tag(self, feature_path):
content = feature_path.read_text()
assert "@workbench" in content

def test_feature_has_three_scenarios(self, feature_path):
from vip.gherkin import parse_feature_file

result = parse_feature_file(feature_path)
assert len(result["scenarios"]) == 3

def test_feature_scenarios_cover_r_python_and_session(self, feature_path):
from vip.gherkin import parse_feature_file

result = parse_feature_file(feature_path)
titles = [s["title"] for s in result["scenarios"]]
assert any("R version" in t for t in titles)
assert any("Python version" in t for t in titles)
assert any("RStudio" in t or "session" in t.lower() for t in titles)
4 changes: 4 additions & 0 deletions src/vip/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,8 @@ class RuntimesConfig:

r_versions: list[str] = field(default_factory=list)
python_versions: list[str] = field(default_factory=list)
r_excluded_versions: list[str] = field(default_factory=list)
python_excluded_versions: list[str] = field(default_factory=list)


@dataclass
Expand Down Expand Up @@ -495,6 +497,8 @@ def load_config(path: str | Path | None = None) -> VIPConfig:
runtimes=RuntimesConfig(
r_versions=runtimes_raw.get("r_versions", []),
python_versions=runtimes_raw.get("python_versions", []),
r_excluded_versions=runtimes_raw.get("r_excluded_versions", []),
python_excluded_versions=runtimes_raw.get("python_excluded_versions", []),
),
performance=PerformanceConfig.from_dict(performance_raw),
data_sources=data_sources,
Expand Down
4 changes: 4 additions & 0 deletions src/vip_tests/workbench/pages/homepage.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ class NewSessionDialog:
IMAGE_DROPDOWN = "#rstudio_label_image"
IMAGE_EDIT_BUTTON = "#rstudio_group_image button"

# Runtime version selectors
R_VERSION_DROPDOWN = "#rstudio_label_r_version"
PYTHON_VERSION_DROPDOWN = "#rstudio_label_python_version"

# IDE icons (legacy modal)
RSTUDIO_PRO_ICON = "[id*=trigger-RStudio]"
VSCODE_ICON = ".rstudio-modal [title='New VS Code session']"
Expand Down
27 changes: 27 additions & 0 deletions src/vip_tests/workbench/test_runtime_versions.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
@workbench
Feature: Workbench R and Python versions
As a Posit Team administrator
I want to verify that the expected R and Python versions are available
So that users can start sessions with the correct runtime

Scenario: Expected R versions are available in Workbench session dialog
Given the user is logged in to Workbench
And expected R versions are specified in vip.toml
When I check the available R versions in the New Session dialog
Then all expected R versions are present in the R version selector
And no excluded R versions are present in the R version selector

Scenario: Expected Python versions are available in Workbench session dialog
Given the user is logged in to Workbench
And expected Python versions are specified in vip.toml
When I check the available Python versions in the New Session dialog
Then all expected Python versions are present in the Python version selector
And no excluded Python versions are present in the Python version selector

Scenario: Launched RStudio session uses expected R version
Given the user is logged in to Workbench
And expected R versions are specified in vip.toml
When the user starts a new RStudio session with the first expected R version
Then the session transitions to Active state
And the RStudio console reports the expected R version
And the session is cleaned up
Loading
Loading