Running the suite on GitHub-hosted runners for the first time exposed two
latent test-portability failures; neither is a production bug.
tests/test_containment.py: on windows-latest (symlink-capable, unlike most
local Windows setups) the escaping-symlink test ran and failed because the
resolver's stdout is a POSIX-style Git Bash path (/tmp is the mounted user
temp dir), while the assertion canonicalized it with os.path.realpath, which
reads it as C:\tmp. The resolver rejected the escape correctly. Map the
sh-emitted path back to its host form with cygpath before comparing, same
comparison-side normalization as the Hermes adapter test fix in 0d028d4.
tests/test_path_fix.py: the two Windows-shaped vectors fail on any POSIX
host because Path.resolve() treats C:/Users/... as a relative path and
prepends the CWD. In production the sanitizer only ever receives real POSIX
paths on POSIX hosts, so the branch under test is Windows-only; restrict the
two tests to Windows, mirroring the existing skipIf on the Unix vector.
52 lines
2.4 KiB
Python
52 lines
2.4 KiB
Python
"""Test the path sanitization in scripts/session-catchup.py.
|
|
|
|
Loads the real module via importlib (the filename has a hyphen, so it can't
|
|
be `import`-ed normally) and exercises its actual get_project_dir_claude,
|
|
instead of reimplementing the logic here. An earlier version of this file
|
|
reimplemented a fixed sanitizer for testing "to avoid import issues" — that
|
|
reimplementation was correct, but it meant the suite stayed green while the
|
|
shipped session-catchup.py (which it never touched) was still broken on
|
|
Windows. See CHANGELOG for the fix this guards.
|
|
"""
|
|
import importlib.util
|
|
import os
|
|
import sys
|
|
import unittest
|
|
from pathlib import Path
|
|
|
|
REPO_ROOT = Path(__file__).resolve().parent.parent
|
|
MODULE_PATH = REPO_ROOT / "scripts" / "session-catchup.py"
|
|
|
|
spec = importlib.util.spec_from_file_location("session_catchup", MODULE_PATH)
|
|
assert spec is not None and spec.loader is not None
|
|
session_catchup = importlib.util.module_from_spec(spec)
|
|
sys.modules["session_catchup"] = session_catchup
|
|
spec.loader.exec_module(session_catchup)
|
|
|
|
|
|
class SessionCatchupPathSanitizeTests(unittest.TestCase):
|
|
def _sanitized_name(self, project_path: str) -> str:
|
|
project_dir = session_catchup.get_project_dir_claude(project_path)
|
|
return project_dir.name
|
|
|
|
@unittest.skipUnless(os.name == "nt", "Windows-shaped input; on POSIX Path.resolve() treats C:/... as relative and prepends the CWD")
|
|
def test_windows_native_path(self) -> None:
|
|
result = self._sanitized_name("C:/Users/oasrvadmin/Documents/planning-with-files-repo")
|
|
self.assertEqual(result, "C--Users-oasrvadmin-Documents-planning-with-files-repo")
|
|
|
|
@unittest.skipUnless(os.name == "nt", "Windows-shaped input; on POSIX Path.resolve() treats C:/... as relative and prepends the CWD")
|
|
def test_git_bash_path(self) -> None:
|
|
result = self._sanitized_name("/c/Users/oasrvadmin/Documents/planning-with-files-repo")
|
|
self.assertEqual(result, "C--Users-oasrvadmin-Documents-planning-with-files-repo")
|
|
|
|
@unittest.skipIf(os.name == "nt", "exercises the real-Unix-path branch, not meaningful on Windows")
|
|
def test_unix_absolute_path_unchanged(self) -> None:
|
|
# Real Unix paths never contain ':' or '\\', so this must take the
|
|
# legacy branch untouched by the Windows fix (regression guard).
|
|
result = self._sanitized_name("/home/user/project")
|
|
self.assertEqual(result, "-home-user-project")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|