From c4eeec8642d4a03f42d14f39647c52fa50929f3d Mon Sep 17 00:00:00 2001 From: Igor Lins e Silva <4753812+igorls@users.noreply.github.com> Date: Sat, 25 Apr 2026 01:18:31 -0300 Subject: [PATCH] test: use shlex.quote in resume-hint assertions for Windows The pre-existing test_maybe_run_mine_prompt_declined_prints_hint asserted the bare unquoted form `mempalace mine {tmp_path}`. After the production code switched to shlex.quote on the resume hint, this passed on Linux/macOS (POSIX paths have no characters that trigger quoting) but failed on Windows where backslashes always get wrapped in single quotes. Mirror the production code in the assertion via shlex.quote so it's portable across platforms; do the same for the two new spaces-in-path tests for consistency. --- tests/test_cli.py | 14 ++++++++++---- tests/test_miner.py | 6 +++++- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/tests/test_cli.py b/tests/test_cli.py index b21ed8c..5d36ab7 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -1,6 +1,7 @@ """Tests for mempalace.cli — the main CLI dispatcher.""" import argparse +import shlex import sys from pathlib import Path from unittest.mock import MagicMock, patch @@ -221,7 +222,10 @@ def test_maybe_run_mine_prompt_declined_prints_hint(tmp_path, capsys): _maybe_run_mine_after_init(args, cfg) mock_mine.assert_not_called() out = capsys.readouterr().out - assert f"mempalace mine {tmp_path}" in out + # shlex.quote is a no-op on POSIX-safe paths but wraps Windows paths + # (which contain backslashes) in single quotes, so the assertion has + # to mirror what the production code actually emits. + assert f"mempalace mine {shlex.quote(str(tmp_path))}" in out assert "Skipped" in out @@ -297,9 +301,11 @@ def test_maybe_run_mine_decline_quotes_path_with_spaces(tmp_path, capsys): ): _maybe_run_mine_after_init(args, cfg) out = capsys.readouterr().out - # shlex.quote wraps paths with spaces in single quotes. - assert f"mempalace mine '{spaced_dir}'" in out - # And the bare unquoted form is NOT printed (would break paste). + # shlex.quote wraps paths with spaces (and Windows backslashes) in + # single quotes — the assertion must use the same shlex form so the + # test passes on every platform's tmp_path layout. + assert f"mempalace mine {shlex.quote(str(spaced_dir))}" in out + # Bare unquoted form must NOT appear — that's the bug we're guarding. assert f"mempalace mine {spaced_dir} " not in out assert f"mempalace mine {spaced_dir}`" not in out diff --git a/tests/test_miner.py b/tests/test_miner.py index 2dee259..0619dbb 100644 --- a/tests/test_miner.py +++ b/tests/test_miner.py @@ -1,4 +1,5 @@ import os +import shlex import shutil import tempfile from pathlib import Path @@ -674,7 +675,10 @@ def test_mine_keyboard_interrupt_quotes_path_with_spaces_in_resume_hint(tmp_path mine(str(project_root), str(palace_path)) out = capsys.readouterr().out - assert f"mempalace mine '{project_root}'" in out + # Use shlex.quote so the assertion matches whatever the production + # code emits on this platform (POSIX paths with spaces vs Windows + # paths with backslashes both end up wrapped in single quotes). + assert f"mempalace mine {shlex.quote(str(project_root))}" in out def test_mine_cleans_up_pid_file_on_interrupt(tmp_path):