Repository navigation
refactor: trim redundant tests and indirection in the HID++ module - #9
Merged
Merged
Conversation
Production code: - Make hidpp a private module of the binary and drop src/lib.rs. Nothing else consumed the library, and with the module private, rustc now flags dead code that `pub` used to hide (e.g. the unused get_feature_index). - Remove the BatteryDevice trait, its HidppTransport impl and the BatterySession wrapper; reading is a free function over RequestIo like the rest of the request path. - Fold ProtocolError (a single variant) into HidppError::ShortResponse and ProbeOutcome into Discovery, which had the same three cases. - Drop the sw_id parameter that every caller set to the same constant, and the per-feature parser wrappers. Tests (54 -> 24 in hidpp, same behaviours covered): - Delete the FakeTransport suite, which re-tested the fallback rules that the scripted battery_recovery tests already cover byte for byte. - Replace the scattered match_report tests with one table test, and drop parser, request_timeout and discover unit tests the scripted tests cover. - Delete tests of the test double itself. - ScriptedIo now checks for unplayed steps on drop, so the per-test assert_finished/writes() bookkeeping and the IoCall log are gone; shared request constants and exchange helpers replace per-module copies. cargo-mutants catches the same mutants as before; the only survivors are hardware glue that needs a real device and two equivalent mutants. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Pu5j1fqQD9iMmDuP3TnJR3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
src/hidpp.rswas ~2,500 lines, ~1,800 of them tests, and many tests checked the same behaviour at two or three levels. This PR removes that duplication and the abstractions that existed only to support it. Runtime behaviour is unchanged.Production code
src/lib.rsand makehidppa private module of the binary. Onlymain.rsused the library. With the module private, rustc now flags dead code thatpubused to hide; the unusedget_feature_indexwas one example.BatteryDevicetrait, itsHidppTransportimpl and theBatterySessionwrapper. Reading the battery is now a free function overRequestIo, like the rest of the request path.ProtocolError(it had a single variant) intoHidppError::ShortResponse. FoldProbeOutcomeintoDiscovery, which had the same three cases.sw_idparameter (every caller passed the same constant) and the two per-feature parser wrappers.Tests (hidpp: 54 → 24; covered behaviour is unchanged)
FakeTransportsuite. It re-tested the unified→legacy fallback rules that the scriptedbattery_recoverytests already cover at the byte level.match_reportunit tests with one table test. Delete the parser,request_timeoutanddiscoverunit tests, which the scripted tests already cover.ScriptedIonow checks on drop that every scripted step was played. This replaces theassert_finished()/writes()calls in each test and theIoCalllog. Shared request constants andexchange/reply/legacy_fallbackhelpers replace the copies in each module.Verification
cargo fmt --check,cargo clippy --all-targets --locked -- -D warningsandcargo test --lockedpass. They were run on Linux with libudev; CI runs them on macOS.cargo-mutants, before and after: the trimmed suite catches every mutant the original suite caught in code that still exists. The only survivors are:candidate_interfaces,probe_device, theHidDeviceimpl,main), which also survived before;|→^on non-overlapping bits,>→>=on a read length).unplayed script steps: …, so the check on drop works.🤖 Generated with Claude Code
https://claude.ai/code/session_01Pu5j1fqQD9iMmDuP3TnJR3
Generated by Claude Code