test(firmware): the WiFi updater's own edge cases had no tests of their own - #522
Conversation
…ir own WifiModuleUpdater is the ~900-line collaborator behind UpdateWifiModuleAsync / CheckWifiFirmwareStatusAsync, and every test that touched it went through the FirmwareUpdateService facade. That covered the happy path and the cancellation points well, but left the parts a facade test cannot reach cleanly untested: the flash-tool/port resolution and argument quoting, each branch of the "why did the flash not report success" verdict, the retry policy's boundaries, the one-shot stdin prompt handshake, and the status probe's behaviour when the mutable options object is changed after the service was constructed. Adds 30 direct tests for exactly those seams — deliberately not a re-run of the facade suite one level down, which would only mean two places to edit. FakeStreamingDevice, FakeFirmwareDownloadService and FakeExternalProcessRunner move out of FirmwareUpdateServiceTests into a shared FirmwareUpdateTestDoubles file so the second caller does not hand-copy ~145 lines of IStreamingDevice surface. The move is verbatim: the facade test file loses 246 lines and gains none, so no existing test body changed. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
/agentic_review |
PR Summary by QodoAdd direct unit tests for WifiModuleUpdater edge cases
AI Description
Diagram
High-Level Assessment
Files changed (3)
|
Code Review by Qodo🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)
Great, no issues found!Qodo reviewed your code and found no material issues that require reviewTip of the day💡 Did you know, you can type 'qodo, fix this' on a finding and the fix lands right on your PR |
|
Qodo-clean, CI green — ready for review. (1 round on head |
What was wrong
WifiModuleUpdateris the ~900-line piece of Core that actually flashes the WiFi module — it finds Microchip's flash tool, builds its command line, answers its interactive prompts, decides whether a failed run is worth retrying, and turns whatever the tool printed into an explanation a caller can act on. None of that had a test of its own. Every test that touched it droveFirmwareUpdateServiceand watched from the outside.That was fine for the happy path, which the facade suite covers well, but it left real behaviour unpinned. Nothing checked that a COM port or firmware path containing a space gets quoted before it becomes a command line. Nothing checked that "the tool couldn't open the port" and "the tool reached the device and the programming failed" produce different messages — the whole point of that code is telling those two apart. Nothing checked that the tool's stdin prompt still gets answered on a second attempt, even though the responder is deliberately one-shot and a spent one would leave the tool blocked forever. A regression in any of these would have shipped.
How it was fixed
30 direct unit tests for
WifiModuleUpdater, covering the seams the facade cannot reach cleanly: flash-tool and port resolution, argument quoting, all five branches of the "why did this flash not report success" verdict, the retry policy's boundaries, the prompt handshake and its per-attempt freshness, the progress band mapping, and the status probe's behaviour when the (mutable) options object is changed after the service was constructed.Deliberately not a re-run of the facade suite one level down.
FirmwareUpdateServiceTestsalready covers the WiFi happy path, the cancellation points and the bridge-exit recovery, and duplicating those here would only mean two places to edit for every change. The file's doc comment says which half lives where.The one thing a reviewer might push back on: this moves three test doubles (
FakeStreamingDevice,FakeFirmwareDownloadService,FakeExternalProcessRunner) out ofFirmwareUpdateServiceTestsinto a sharedFirmwareUpdateTestDoubles.cs, rather than hand-copying ~145 lines ofIStreamingDevicesurface into a second file that would then have to be kept in step by hand. The move is verbatim — same names, same behaviour — so the facade test file loses 246 lines and gains none, and no existing test body changed. The only additions to the doubles are extra observation hooks (every request seen, and the stdin responses produced) that nothing existing reads.Verification
WifiModuleUpdater.csone at a time and each was caught by the test written for it: dropping the stdout scan from the transient-failure classifier (2 tests), removing the attempt-count clamp, removing the argument quoting, removing the prompt responder's one-shot guard, reordering the image-build check behind the device-reached check, reporting raw tool percent instead of the mapped band, caching the chip-info retry budget instead of re-reading it, parsing the minimum version strictly instead of degrading to "no opinion", and waiting out the settle delay after a failed power-on send. Source restored after each.src/Daqifi.Core.Tests/.Part of #464 — slice 1 of the four the issue lists. Deliberately not
closes: the Pic32 collaborators, the discovery descriptor providers andSdCardOperationsare still uncovered, so the issue should stay open until they land.Not merging — for review.