Skip to content

Commit b9b0ff1

Browse files
committed
feat: update cci robot install_playwright to support uv
1 parent 9298ec5 commit b9b0ff1

3 files changed

Lines changed: 56 additions & 11 deletions

File tree

.github/workflows/slow_integration_tests.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,7 @@ jobs:
9191
wget -qO- https://developer.salesforce.com/media/salesforce-cli/sf/channels/stable/sf-linux-x64.tar.xz | tar xJ -C sfdx --strip-components 1
9292
echo $(realpath sfdx/bin) >> $GITHUB_PATH
9393
- name: Initialize Browser/Playwright
94-
run: |
95-
uv pip install robotframework-browser
96-
uv run python -m Browser.entry init
94+
run: uv run cci robot install_playwright
9795
- name: Authenticate Dev Hub
9896
run: |
9997
sf plugins --core

cumulusci/cli/robot.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import importlib.metadata
2+
import shutil
23
import sys
34

45
import click
@@ -37,9 +38,19 @@ def robot_install_playwright(runtime, dry_run):
3738
def robot_uninstall_playwright():
3839
"""Attempt to uninstall playwright"""
3940
p1 = sarge.Command([sys.executable, "-m", "Browser.entry", "clean-node"])
40-
p2 = sarge.Command(
41-
[sys.executable, "-m", "pip", "uninstall", "robotframework-browser", "--yes"]
42-
)
41+
if shutil.which("uv"):
42+
p2 = sarge.Command(["uv", "pip", "uninstall", "robotframework-browser"])
43+
else:
44+
p2 = sarge.Command(
45+
[
46+
sys.executable,
47+
"-m",
48+
"pip",
49+
"uninstall",
50+
"robotframework-browser",
51+
"--yes",
52+
]
53+
)
4354

4455
click.echo("removing node modules...")
4556
click.echo(f"running {' '.join(p1.args)}")
@@ -53,7 +64,11 @@ def robot_uninstall_playwright():
5364

5465

5566
def _install_browser_library(dry_run=False):
56-
pip_cmd = [sys.executable, "-m", "pip", "install", "robotframework-browser"]
67+
if shutil.which("uv"):
68+
pip_cmd = ["uv", "pip", "install", "robotframework-browser"]
69+
else:
70+
pip_cmd = [sys.executable, "-m", "pip", "install", "robotframework-browser"]
71+
5772
click.echo("installing robotframework-browser ...")
5873
if dry_run:
5974
click.echo(f"would run {' '.join(pip_cmd)}")

cumulusci/cli/tests/test_robot.py

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,11 @@ def test_is_package_installed(mock_distribution):
5757
assert result is False
5858

5959

60+
@mock.patch("cumulusci.cli.robot.shutil.which")
6061
@mock.patch("cumulusci.cli.robot.sarge")
61-
def test_happy_path(sarge):
62+
def test_happy_path(sarge, which):
6263
"""Verify the happy path is indeed happy"""
64+
which.return_value = False
6365
sarge.Command.side_effect = mock_Command()
6466
with mock.patch("cumulusci.cli.robot._is_package_installed", return_value=False):
6567
run_cli_command("robot", "install_playwright")
@@ -80,6 +82,30 @@ def test_happy_path(sarge):
8082
assert actual_calls == expected_calls, msg
8183

8284

85+
@mock.patch("cumulusci.cli.robot.shutil.which")
86+
@mock.patch("cumulusci.cli.robot.sarge")
87+
def test_happy_path_uv(sarge, which):
88+
"""Verify the happy path is indeed happy with uv"""
89+
which.return_value = True
90+
sarge.Command.side_effect = mock_Command()
91+
with mock.patch("cumulusci.cli.robot._is_package_installed", return_value=False):
92+
run_cli_command("robot", "install_playwright")
93+
actual_calls = [call.args[0] for call in sarge.Command.mock_calls]
94+
expected_calls = [
95+
"npm --version",
96+
[
97+
"uv",
98+
"pip",
99+
"install",
100+
"robotframework-browser",
101+
],
102+
[sys.executable, "-m", "Browser.entry", "init"],
103+
]
104+
msg = f"\n-- expected --\n{expected_calls}\n\n-- actual --\n{actual_calls}"
105+
106+
assert actual_calls == expected_calls, msg
107+
108+
83109
@mock.patch("sys.exit")
84110
def test_bogus_subcommand(sys_exit):
85111
"""Verify a bogus subcommand returns a UsageError"""
@@ -100,9 +126,11 @@ def test_no_npm(sarge):
100126
assert sarge.Command.mock_calls[0].args[0] == "npm --version"
101127

102128

129+
@mock.patch("cumulusci.cli.robot.shutil.which")
103130
@mock.patch("cumulusci.cli.robot.sarge")
104-
def test_playwright_dry_run(sarge):
131+
def test_playwright_dry_run(sarge, which):
105132
"""Verify the output of a dry run"""
133+
which.return_value = False
106134
sarge.Command.side_effect = mock_Command(returncodes={"npm --version": 0})
107135
with mock.patch("cumulusci.cli.robot._is_package_installed", return_value=False):
108136
result = run_cli_command("robot", "install_playwright", "--dry_run")
@@ -130,9 +158,11 @@ def test_playwright_failure_to_initialize_browser_library(sarge):
130158
run_cli_command("robot", "install_playwright")
131159

132160

161+
@mock.patch("cumulusci.cli.robot.shutil.which")
133162
@mock.patch("cumulusci.cli.robot.sarge")
134-
def test_playwright_failure_to_install_browser_library(sarge):
163+
def test_playwright_failure_to_install_browser_library(sarge, which):
135164
"""Verify we raise an exception if we can't install playwright"""
165+
which.return_value = False
136166
cmd = str([sys.executable, "-m", "pip", "install", "robotframework-browser"])
137167
sarge.Command.side_effect = mock_Command(returncodes={cmd: 1})
138168
with mock.patch("cumulusci.cli.robot._is_package_installed", return_value=False):
@@ -154,9 +184,11 @@ def test_playwright_already_installed(sarge):
154184
)
155185

156186

187+
@mock.patch("cumulusci.cli.robot.shutil.which")
157188
@mock.patch("cumulusci.cli.robot.sarge")
158-
def test_uninstall_playwright(sarge):
189+
def test_uninstall_playwright(sarge, which):
159190
"""Verify calling 'robot uninstall_playwright' calls the right utilities"""
191+
which.return_value = False
160192
sarge.Command.side_effect = mock_Command()
161193
with mock.patch("cumulusci.cli.robot._is_package_installed", return_value=False):
162194
run_cli_command("robot", "uninstall_playwright")

0 commit comments

Comments
 (0)