diff --git a/src/opcli/core/spread.py b/src/opcli/core/spread.py index 77c0a16..c4cbd6a 100644 --- a/src/opcli/core/spread.py +++ b/src/opcli/core/spread.py @@ -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 @@ -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) diff --git a/tests/unit/test_spread.py b/tests/unit/test_spread.py index 514d3a2..f902cd0 100644 --- a/tests/unit/test_spread.py +++ b/tests/unit/test_spread.py @@ -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)