Add more coverage exclusion, with commentary
Marco Ricci

Marco Ricci commited on 2026-01-28 20:48:27
Zeige 3 geänderte Dateien mit 31 Einfügungen und 3 Löschungen.

... ...
@@ -146,7 +146,28 @@ class SSHAgentClient:
146 146
 
147 147
         from derivepassphrase.ssh_agent import socketprovider  # noqa: PLC0415
148 148
 
149
-        if isinstance(socket, _socket.socket):
149
+        # On POSIX, the predominant type of communication channel is the
150
+        # UNIX domain socket, which in Python is represented as
151
+        # a `socket.socket` object.  This is (as of January 2026)
152
+        # unsupported on The Annoying OS: Only in Windows 10 (on some
153
+        # later builds at least) did Microsoft ship a partial
154
+        # implementation of named UNIX domain sockets in stream mode,
155
+        # but because of the limited scope Python does not provide
156
+        # bindings to this functionality.  (The Annoying OS has other
157
+        # predominant communication channels, but these are not
158
+        # represented as `socket.socket` objects.)
159
+        #
160
+        # Thus, for practical purposes, using a `socket.socket` object
161
+        # to interface a running SSH agent is not a valid code path on
162
+        # The Annoying OS.  The code path should therefore be marked as
163
+        # such.
164
+        #
165
+        # https://devblogs.microsoft.com/commandline/af_unix-comes-to-windows/
166
+        # https://github.com/microsoft/WSL/issues/4240
167
+        # https://github.com/python/cpython/issues/77589
168
+        if isinstance(
169
+            socket, _socket.socket
170
+        ):  # pragma: unless posix no cover [external]
150 171
             self._connection = socket
151 172
             # Test whether the socket is connected.
152 173
             self._connection.getpeername()
... ...
@@ -512,7 +512,9 @@ class WindowsNamedPipeHandle:
512 512
                 ctypes.cast(ctypes.byref(write_count), LPDWORD),
513 513
                 ctypes.cast(ctypes.byref(overlapped_struct), LPOVERLAPPED),
514 514
             )
515
-            if not success and GetLastError() == ERROR_IO_PENDING:
515
+            if (
516
+                not success and GetLastError() == ERROR_IO_PENDING
517
+            ):  # pragma: no cover [external]
516 518
                 success = GetOverlappedResult(
517 519
                     self.handle,
518 520
                     ctypes.cast(ctypes.byref(overlapped_struct), LPOVERLAPPED),
... ...
@@ -460,8 +460,13 @@ for key, handler in spawn_handlers.items():
460 460
 Popen = TypeVar("Popen", bound=subprocess.Popen)
461 461
 
462 462
 
463
+# As of v0.6, all SSH agents we interact with on The Annoying OS are
464
+# interfaced, not spawned.  Therefore, this context manager is unused on
465
+# The Annoying OS.
463 466
 @contextlib.contextmanager
464
-def terminate_on_exit(proc: Popen) -> Iterator[Popen]:
467
+def terminate_on_exit(
468
+    proc: Popen,
469
+) -> Iterator[Popen]:  # pragma: unless posix no cover [unused]
465 470
     """Terminate and wait for the subprocess upon exiting the context.
466 471
 
467 472
     Args:
468 473