diff --git a/skills/last30days/scripts/last30days.py b/skills/last30days/scripts/last30days.py index 960cb2d..6a82454 100644 --- a/skills/last30days/scripts/last30days.py +++ b/skills/last30days/scripts/last30days.py @@ -195,9 +195,9 @@ def compute_save_path_display(save_dir: str, topic: str, suffix: str, emit: str) try: home = _Path.home().resolve() relative = raw.relative_to(home) - return f"~/{relative}" + return f"~/{relative.as_posix()}" except ValueError: - return str(raw) + return raw.as_posix() def read_synthesis_file(path: str) -> str: diff --git a/tests/test_cli_v3.py b/tests/test_cli_v3.py index 48f2dd1..23e5dc2 100644 --- a/tests/test_cli_v3.py +++ b/tests/test_cli_v3.py @@ -1,6 +1,7 @@ # ruff: noqa: E402 import json import io +import shutil import tempfile import subprocess import sys @@ -143,6 +144,30 @@ class CliV3Tests(unittest.TestCase): _, kwargs = write_text.call_args self.assertEqual("utf-8", kwargs.get("encoding")) + def test_compute_save_path_display_uses_posix_slashes_under_home(self): + # Regression: f"~/{relative}" stringified pathlib.Path with the + # OS-native separator, producing "~/Documents\\Last30Days\\..." on + # Windows that no shell or File Explorer could open. The fix is + # f"~/{relative.as_posix()}" which forces forward slashes regardless + # of host OS. On POSIX hosts this asserts the contract for + # cross-platform safety; on Windows hosts it would fail without the fix. + real_home = Path.home() + tmp_under_home = Path(tempfile.mkdtemp(prefix="l30d_save_path_", dir=str(real_home))) + try: + save_dir = tmp_under_home / "Documents" / "Last30Days" + save_dir.mkdir(parents=True, exist_ok=True) + display = cli.compute_save_path_display( + str(save_dir), "british airways middle east", "v3", "compact" + ) + self.assertTrue(display.startswith("~/"), f"Expected '~/' prefix, got: {display}") + self.assertNotIn("\\", display, f"Backslash leaked into display: {display}") + self.assertTrue( + display.endswith("british-airways-middle-east-raw-v3.md"), + f"Expected slug+suffix at end, got: {display}", + ) + finally: + shutil.rmtree(tmp_under_home, ignore_errors=True) + def test_persist_report_updates_run_status_on_success_and_failure(self): report = self.make_report()