`test_binary_captures_skip_existing_entries` fails on Windows: `readlink()` returns a `\\?\` extended-length path
Summary
tests/test_ingest_url_type.py::test_binary_captures_skip_existing_entries (added in 750b5642, #4393)
fails on Windows for three parameters: dangling_link-False, dangling_link-True, live_link-True
(3 failed, 37 passed on a clean v0.9.89 checkout, Python 3.13.13, Windows 11).
The fix itself works: all earlier assertions pass (the new capture gets a free numbered name, its bytes are right, the existing symlink is untouched). Only the final symlink check fails:
assert occupied.is_symlink() and occupied.readlink() == sentinel
AssertionError: assert (True and WindowsPath('//?/C:/Users/.../sentinel') == WindowsPath('C:/Users/.../sentinel'))
Cause
On Windows, Path.readlink() returns the target in extended-length form (\\?\C:\..., or
\\?\UNC\server\share\... for a network path), while sentinel is a plain C:\... path.
import pathlib, tempfile
d = pathlib.Path(tempfile.mkdtemp())
s, l = d / "sentinel", d / "l"
l.symlink_to(s)
print(l.readlink()) # \\?\C:\Users\...\sentinel
print(l.readlink() == s) # False
Hosts that cannot create symlinks skip these parameters, so the failure only appears where symlinks work.
Suggested fix
Strip the extended-length prefix before comparing. os.path.samefile is not an option here (the
dangling_link target does not exist), and a bare removeprefix("\\\\?\\") turns the UNC form into
UNC\server\share\..., so that case is handled separately:
def _without_extended_prefix(path) -> str:
text = str(path)
if text.startswith("\\\\?\\UNC\\"):
return "\\\\" + text[len("\\\\?\\UNC\\"):]
return text.removeprefix("\\\\?\\")
assert occupied.is_symlink()
assert _without_extended_prefix(occupied.readlink()) == str(sentinel)
With this, all 40 tests in the file pass on Windows. On POSIX the helper is a no-op.
Thanks for opening this issue, @sub4biz. A maintainer will take a look soon.
If you would like to discuss it in real time, come say hi on our Discord server. For longer-form questions and ideas there is also GitHub Discussions.
To help us triage, please make sure the report includes what you expected, what actually happened, and the steps (and a small sample) to reproduce it.
Already fixed on v8: commit e7772b2d (test(ingest): compare the symlink target against what readlink returned before (#4435)) changed the assertion to compare occupied.readlink() against a link_target captured via readlink() before the ingest runs, rather than against the plain sentinel path, which sidesteps the extended length prefix mismatch entirely. Landed via #4442 (closed, not auto linked since it was cherry picked rather than merged through the PR button, same pattern as #2780/#2779 and #4413/#4414). Might be worth closing this one too.
Fixed on v8 by e7772b2d186b2039c090765b9063cf10d65b0459: the test now compares the link against the target readlink() returned before the capture, so the Windows \\?\ extended-length prefix no longer breaks the check. It was cherry-picked, so the issue didn't close automatically. Safe to close.
This looks fixed on the v8 branch by e7772b2d (test(ingest): compare the symlink target against what readlink returned before (#4435)). Could a maintainer confirm and close?
Retested on clean upstream tag v0.9.109 on Windows 11 with Python 3.13.13, the same platform and Python version as in the original report. All 42 tests in tests/test_ingest_url_type.py passed, including the three previously failing symlink cases; none of those cases was skipped.
The change in e7772b2d resolves the reported test failure. Thanks for the fix and for following up!