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.
This commit is contained in:
Igor Lins e Silva
2026-04-25 01:18:31 -03:00
parent 8faf0042b5
commit c4eeec8642
2 changed files with 15 additions and 5 deletions
+10 -4
View File
@@ -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
+5 -1
View File
@@ -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):