Skip to content
Closed
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
11 changes: 11 additions & 0 deletions tests/rig/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -1238,6 +1238,17 @@ def _node_command(
)
return ["sh", "-c", "exit 5"]

if group.optional and not (group.absolute_workdir() / "node_modules").is_dir():
# An optional suite nobody installed (CI never installs `ui`) would
# otherwise make `npx --no-install` abort and read as an error on every
# run. Required groups fall through, so a missing install stays red.
print(
f"[rig] {group.workdir}/node_modules not found; skipping optional "
f"{group.name} (runner={group.runner})",
file=sys.stderr,
)
return ["sh", "-c", "exit 5"]

if group.runner == "vitest":
cmd = [
"npx",
Expand Down
51 changes: 51 additions & 0 deletions tests/rig/tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -916,6 +916,57 @@ def test_node_command_without_npx_collects_nothing(
]


def _node_group(workdir: Path, *, optional: bool):
from tests.rig.groups import GroupDefinition

return GroupDefinition(
name="ui", tier="e2e", paths=(".",), runner="playwright",
workdir=str(workdir), optional=optional,
)


def test_node_command_optional_group_without_node_modules_collects_nothing(
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
) -> None:
"""CI has npx but never installs an optional suite's packages, so
`npx --no-install` aborts and the group reads as an error on every run.
An optional group must skip instead, as `groups.yaml` documents.
"""
import tests.rig.cli as cli_mod

monkeypatch.setattr(cli_mod.shutil, "which", lambda _: "/usr/bin/npx")
group = _node_group(tmp_path, optional=True)
assert cli_mod._node_command(group, junit=tmp_path / "junit.xml") == [
"sh", "-c", "exit 5",
]


def test_node_command_required_group_without_node_modules_still_runs(
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
) -> None:
"""A required group (e.g. `frontend`) whose install step went missing must
stay red, not skip quietly.
"""
import tests.rig.cli as cli_mod

monkeypatch.setattr(cli_mod.shutil, "which", lambda _: "/usr/bin/npx")
group = _node_group(tmp_path, optional=False)
cmd = cli_mod._node_command(group, junit=tmp_path / "junit.xml")
assert cmd[:4] == ["npx", "--no-install", "playwright", "test"]


def test_node_command_optional_group_with_node_modules_runs(
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
) -> None:
import tests.rig.cli as cli_mod

monkeypatch.setattr(cli_mod.shutil, "which", lambda _: "/usr/bin/npx")
(tmp_path / "node_modules").mkdir()
group = _node_group(tmp_path, optional=True)
cmd = cli_mod._node_command(group, junit=tmp_path / "junit.xml")
assert cmd[:4] == ["npx", "--no-install", "playwright", "test"]


def _make_group(name: str, workdir: str):
from tests.rig.groups import GroupDefinition

Expand Down
Loading