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
34 changes: 24 additions & 10 deletions src/opcli/core/spread.py
Original file line number Diff line number Diff line change
Expand Up @@ -560,17 +560,13 @@ def _resolve_effective_discover_path(
return discover_path.rstrip("/")


def _build_suite_entry(
suite_path: str,
suite_cfg_raw: object,
root: Path,
) -> tuple[str, dict[str, object]]:
"""Build a single expanded suite entry from an integration-suites config."""
_validate_safe_path(suite_path, "integration-suites key")

suite_cfg: dict[str, object] = dict(suite_cfg_raw) if isinstance(suite_cfg_raw, dict) else {}
def _pop_opcli_keys(
suite_cfg: dict[str, object],
) -> tuple[bool, str, str | None, str]:
"""Pop all opcli-only keys from *suite_cfg* and return their typed values.

# Extract opcli-only keys
Returns (auto_discover, discover_pattern, discover_path, working_dir).
"""
auto_discover = suite_cfg.pop("auto-discover", True)
if not isinstance(auto_discover, bool):
auto_discover = True
Expand All @@ -584,6 +580,24 @@ def _build_suite_entry(
if not isinstance(discover_pattern, str):
discover_pattern = "test_*.py"
discover_path: str | None = discover_path_raw if isinstance(discover_path_raw, str) else None
return auto_discover, discover_pattern, discover_path, working_dir


def _build_suite_entry(
suite_path: str,
suite_cfg_raw: object,
root: Path,
) -> tuple[str, dict[str, object]]:
"""Build a single expanded suite entry from an integration-suites config."""
_validate_safe_path(suite_path, "integration-suites key")

suite_cfg: dict[str, object] = dict(suite_cfg_raw) if isinstance(suite_cfg_raw, dict) else {}

if "cwd" in suite_cfg:
msg = f"Suite '{suite_path}': 'cwd' is no longer supported. Use 'working-dir' instead."
raise ConfigurationError(msg)

auto_discover, discover_pattern, discover_path, working_dir = _pop_opcli_keys(suite_cfg)

_validate_safe_path(working_dir, "working-dir")
effective_discover = _resolve_effective_discover_path(suite_path, discover_path, auto_discover)
Expand Down
21 changes: 21 additions & 0 deletions tests/unit/test_spread.py
Original file line number Diff line number Diff line change
Expand Up @@ -2189,3 +2189,24 @@ def test_path_traversal_in_suite_path_raises(self, tmp_path: Path) -> None:

with pytest.raises(ConfigurationError, match="Path traversal"):
spread_expand(tmp_path, ci=False)

def test_cwd_key_raises_configuration_error(self, tmp_path: Path) -> None:
"""The old 'cwd' key raises a clear error directing users to 'working-dir'."""
spread = """\
project: test-project
path: /home/ubuntu/proj
backends:
integration-test:
type: integration-test
systems:
- ubuntu-24.04
integration-suites:
tests/integration/:
cwd: k8s-charm/
backends:
- integration-test
"""
write_file(tmp_path / "spread.yaml", spread)

with pytest.raises(ConfigurationError, match=r"'cwd' is no longer supported.*working-dir"):
spread_expand(tmp_path, ci=False)
Loading