From c3249874d0c1452b5ebe0e27884af65f2a792a3f Mon Sep 17 00:00:00 2001 From: RMANOV <96174405+RMANOV@users.noreply.github.com> Date: Sat, 25 Apr 2026 11:29:54 +0300 Subject: [PATCH] fix(testing): preserve repo-relative windows paths --- python/tests/test_strix_scenario_contract.py | 10 ++++++++++ scripts/strix_scenario_contract.py | 4 ++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/python/tests/test_strix_scenario_contract.py b/python/tests/test_strix_scenario_contract.py index 78a8b51..8fa1539 100644 --- a/python/tests/test_strix_scenario_contract.py +++ b/python/tests/test_strix_scenario_contract.py @@ -114,6 +114,16 @@ def test_public_exception_message_redacts_windows_paths(): assert "/missing.yaml" in sanitized +def test_public_path_prefers_repo_relative_windows_paths(monkeypatch): + module = _load_module() + root = module.PureWindowsPath("C:/repo") + scenario = module.PureWindowsPath("C:/repo/sim/scenarios/a.yaml") + + monkeypatch.setattr(module, "ROOT", root) + + assert module.public_path(scenario) == "sim\\scenarios\\a.yaml" + + def test_public_scenarios_satisfy_contract(): module = _load_module() scenario_dir = Path(__file__).resolve().parents[2] / "sim" / "scenarios" diff --git a/scripts/strix_scenario_contract.py b/scripts/strix_scenario_contract.py index bbe7cad..191aa8a 100644 --- a/scripts/strix_scenario_contract.py +++ b/scripts/strix_scenario_contract.py @@ -30,11 +30,11 @@ def public_path(path: Path) -> str: """Return a report-safe path without leaking local checkout layout.""" path_str = str(path) + if path.is_relative_to(ROOT): + return str(path.relative_to(ROOT)) if re.match(r"^[A-Za-z]:[\\/]", path_str) or path_str.startswith("\\\\"): name = PureWindowsPath(path_str).name or "." return f"/{name}" - if path.is_relative_to(ROOT): - return str(path.relative_to(ROOT)) if path.is_absolute(): name = path.name or "." return f"/{name}"