From 5817ef83876b909ad44f776c11ee527fda9e696a Mon Sep 17 00:00:00 2001 From: Daniel Zivkovic Date: Sat, 2 May 2026 18:56:29 -0400 Subject: [PATCH] test(cli): regression test for Windows save-path display Asserts compute_save_path_display() never returns a backslash when the save_dir is under the user's home directory, regardless of host OS. Reproduces the original bug on Windows (failed message before the fix: AssertionError: '\' unexpectedly found in '~/l30d_save_path__luu2g76\Documents\Last30Days\british-airways-middle-east-raw-v3.md' ) and locks in the contract on POSIX hosts (passes trivially today; would fail if anyone removes .as_posix() in the future). Verified by temporarily reverting the fix and confirming RED, then re-applying the fix and confirming GREEN. All 13 CliV3Tests pass. --- tests/test_cli_v3.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tests/test_cli_v3.py b/tests/test_cli_v3.py index 48f2dd1..feba03d 100644 --- a/tests/test_cli_v3.py +++ b/tests/test_cli_v3.py @@ -143,6 +143,31 @@ 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. + import shutil + 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()