Add a regression test for foreign platform absolute key detection
Covers the review finding directly: a Windows drive letter key, a
UNC key, and a POSIX absolute key must all be recognized as already
absolute regardless of which platform the test runs on, and must not
be joined onto the scan root. Confirmed against pre fix code via git
stash, the test fails there since the recognizing helper does not
exist yet.
(cherry picked from commit 33b3a7a00a)
This commit is contained in:
1 parent
007844e0c8
commit
c973b90dea
1 file changed
+25
@@ -2586,6 +2586,31 @@ def test_load_manifest_collapses_a_relative_key_with_a_dot_dot_segment(tmp_path)
|
||||
assert loaded[abs_key]["ast_hash"] == "fresh"
|
||||
|
||||
|
||||
def test_to_absolute_from_storage_recognizes_a_foreign_platform_absolute_key(tmp_path):
|
||||
"""Review finding on #1964: Path.is_absolute() only recognizes the
|
||||
CURRENT platform's own syntax, so a manifest genuinely moved between
|
||||
platforms (this module's own stated scope) could carry a key like
|
||||
'C:/Users/x/foo.py' or '\\\\server\\share\\foo.py' loaded on POSIX, or
|
||||
'/abs/path' loaded on Windows. Pre-fix, such a key was wrongly judged
|
||||
relative and joined onto root, producing a nonsense path like
|
||||
'<root>/C:/Users/x/foo.py' instead of being left alone."""
|
||||
from graphify.detect import _looks_absolute, _to_absolute_from_storage
|
||||
|
||||
for foreign_key in (
|
||||
"C:/Users/x/foo.py",
|
||||
"C:\\Users\\x\\foo.py",
|
||||
"\\\\server\\share\\foo.py",
|
||||
"/abs/path/foo.py",
|
||||
):
|
||||
assert _looks_absolute(foreign_key), foreign_key
|
||||
|
||||
result = _to_absolute_from_storage("C:/Users/x/foo.py", tmp_path)
|
||||
assert str(tmp_path) not in result, (
|
||||
f"a foreign-platform absolute key must not be joined onto root, got {result!r}"
|
||||
)
|
||||
assert _looks_absolute("src/foo.py") is False
|
||||
|
||||
|
||||
def test_save_manifest_relativize_step_collapses_seeded_duplicates(tmp_path):
|
||||
"""#1964: the same collapse must happen on the WRITE side too. If the
|
||||
existing on-disk manifest already has both an absolute and a relative
|
||||
|
||||
Reference in new issue
Block a user