Skip to content

test_binary_captures_skip_existing_entries fails on Windows: readlink() returns a \\?\ extended-length path #4435

Closed

Description

@sub4biz

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.

Activity

  1. github-actions commented on Oct 13, 2026

    @github-actions

    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.

  2. ayushcodes10 commented on Oct 16, 2026

    @ayushcodes10
    Contributor

    Already fixed on v8: commit e7772b2 (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.

  3. omsenjalia commented on Oct 18, 2026

    @omsenjalia
    Contributor

    Fixed on v8 by e7772b2: 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.

  4. omsenjalia commented on Oct 18, 2026

    @omsenjalia
    Contributor

    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?

  5. sub4biz commented on Nov 15, 2026

    @sub4biz
    Author

    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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions