test: add direct unit tests for WindowsUsbPortDescriptorProvider - #572
Conversation
…ovider WindowsUsbPortDescriptorProvider had no direct tests — unlike its Linux and macOS siblings, it read straight from the shared WindowsPnpPortMap.Shared singleton with no injectable seam, so its lookup logic was only reachable through the platform factory or WMI itself. Extracted an internal static Resolve(string, WindowsPnpPortMap) method, mirroring the Resolve/Parse seam already used by LinuxUsbPortDescriptorProvider and MacOsUsbPortDescriptorProvider, so the lookup can be driven against a fake map (WindowsPnpPortMap already takes an injected query function) on any OS. GetDescriptor now just adds the Windows platform gate and supplies the real shared map. Added WindowsUsbPortDescriptorProviderTests covering: a port with a USB entity, a port the map doesn't list, a port claimed only by a non-USB entity, a port claimed by both (skips to the USB one), and a WMI failure surfacing from the map (returns null instead of propagating). Part of #464 (slice 3: discovery descriptor providers). dotnet test full suite green on net9.0 and net10.0 (3713 passed, 2 skipped, 0 failed both times). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
|
/agentic_review |
PR Summary by QodoAdd unit tests for WindowsUsbPortDescriptorProvider via injectable Resolve seam
AI Description
Diagram
High-Level Assessment
Files changed (2)
|
Code Review by Qodo
1.
|
…r tests
- Resolve now throws ArgumentNullException for a null map instead of
letting the catch-all swallow the resulting NullReferenceException into
an indistinguishable "no descriptor" answer.
- Moved [SupportedOSPlatform("windows")] from the class down to just
GetDescriptor (the only member that reaches WMI); Resolve is pure and
carries no platform attribute, so tests no longer need a blanket CA1416
suppression to call it — only the two GetDescriptor call sites do, each
scoped narrowly. Updated UsbPortDescriptorProviderFactory's now-stale
suppression comment/pragma to match (the constructor is unannotated).
- Replaced the vacuous off-Windows test (asserted nothing when run on
Windows) with the LinuxUsbPortDescriptorProviderTests convention: an
unconditional GetDescriptor call whose answer is the same on both sides
of the gate, plus one explicitly guarded to the platform where the gate
itself has to produce the answer.
dotnet test full suite green on net9.0 and net10.0 (3715 passed, 2
skipped, 0 failed both times).
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
|
/agentic_review |
|
Code review by qodo was updated up to the latest commit 4eb9e7b |
…r tests - Removed GetDescriptor_PortNoEntityClaims_ReturnsNull: on Windows it reached WindowsPnpPortMap.Shared, whose first lookup can rebuild the map and run a real WMI query, making the test slow and potentially flaky. The Windows-side lookup logic it duplicated is already fully covered by the Resolve tests against a fake map. - Corrected Resolve's doc comment, which claimed it "never touches WMI" — true only because it never calls System.Management directly; whether a WMI query happens depends on which WindowsPnpPortMap is passed in. dotnet test full suite green on net9.0 and net10.0 (3714 passed, 2 skipped, 0 failed both times). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
|
/agentic_review |
|
Code review by qodo was updated up to the latest commit 30ee80b |
|
Qodo-clean, CI green — ready for review. |
What was wrong
WindowsUsbPortDescriptorProvider— the collaborator that resolves a serial port's USB vendor/product ID on Windows via the shared PnP entity map — had no tests, unlike its Linux and macOS siblings. It read directly from theWindowsPnpPortMap.Sharedsingleton with no seam to inject a fake, so its lookup logic (which entity wins when a port is claimed by more than one, what happens on a WMI failure) was only reachable through the platform factory or real WMI.How it was fixed
Pulled the lookup out into an internal static
Resolve(string, WindowsPnpPortMap), the same shapeLinuxUsbPortDescriptorProvider.ResolveandMacOsUsbPortDescriptorProvider.Parsealready use.WindowsPnpPortMapalready takes an injected query function, soResolvecan be driven against a fake map on any OS.GetDescriptoris now just the Windows platform gate plus the real shared map.Added
WindowsUsbPortDescriptorProviderTestscovering: a port with a USB entity, a port the map doesn't list, a port claimed only by a non-USB entity, a port claimed by both a non-USB and a USB entity (picks the USB one), and a WMI failure surfacing from the map (returns null rather than propagating).Verification
dotnet testfull suite green on net9.0 and net10.0 (3713 passed, 2 skipped, 0 failed both times). Test-only change plus an internal refactor (no public API surface touched) — no bench validation needed.Part of #464 (slice 3: discovery descriptor providers). Not merging — for review.