Skip to content

test: characterize the hidpp v20 matcher and cover the CLI#406

Merged
AprilNEA merged 4 commits into
masterfrom
test/cli-hidpp-v20
Jul 18, 2026
Merged

test: characterize the hidpp v20 matcher and cover the CLI#406
AprilNEA merged 4 commits into
masterfrom
test/cli-hidpp-v20

Conversation

@AprilNEA

Copy link
Copy Markdown
Owner

Summary

Closes the two long-standing test gaps flagged in the engineering audit: the HID++ 2.0 send/response-matcher path in the vendored hidpp fork had no characterization tests, and openlogi-cli had 2 tests for ~965 lines. All changes are purely additive #[cfg(test)] modules — zero production lines modified.

Changes

  • hidpp: characterization tests for the v20 correlation layer (protocol/v20.rs::send_v20 over the predicate-based HidppChannel::send), reusing the existing MockRawHidChannel harness: header-field correlation against interleaved decoys, broadcast events not consuming pending requests, 0xFF error-frame decoding (mapped code → Hidpp20Error::Feature, unmapped code → UnsupportedResponse), and the width-agnostic matching quirk (a Long reply to a Short request is accepted) pinned as current behavior.
  • cli: 30 tests covering clap parsing (debug_assert, arg conflicts, NonZeroU8 bounds, value-enum mapping), diag message selection, DPI list-vs-range summarization, lighting color validation (rejects before any device I/O), optional-asset classification incl. two pinned quirks, and list output formatting. Pure dispatch glue and hardware-seam functions were deliberately left untested (tautological or requiring prod changes).

Found while writing tests, recorded here rather than fixed (test-only PR): the unreachable map_err in diag/lighting.rs color parsing, and is_optional_asset's loose front_ext* prefix match.

Testing

  • cargo test -p openlogi-hidpp -p openlogi-cli — 157 + 30 passed, 0 failed
  • cargo clippy -p openlogi-cli --all-targets -- -D warnings — clean
  • Not runtime-tested on hardware (all tests run against mocks or pre-I/O validation paths).

@greptile-apps

greptile-apps Bot commented Jul 18, 2026

Copy link
Copy Markdown

Greptile Summary

This PR is purely additive test coverage — zero production lines are modified. It adds characterization tests for the HID++ 2.0 send/response matcher in openlogi-hidpp and ~30 new tests for the CLI layer covering Clap parsing, diagnostic message selection, DPI range summarization, color validation, optional-asset classification, and list output formatting.

  • crates/openlogi-hidpp/src/channel.rs: 5 new #[cfg(test)] tests for send_v20, exercising header-field correlation against decoys, broadcast-event pass-through, width-agnostic matching, and 0xFF error-frame decoding.
  • crates/openlogi-cli/src/**: 30 tests across lib.rs, diag/, assets/sync.rs, and cmd/list.rs. Known quirks are explicitly called out as pinned-current-behaviour.

Confidence Score: 5/5

All changes are additive test-only code; no production lines are touched, so there is no risk of regression.

The PR adds only #[cfg(test)] modules. The one gap identified — a missing function_id decoy in a characterization test — does not affect production behaviour in any way.

crates/openlogi-hidpp/src/channel.rs — the decoy set in send_v20_matches_response_by_header_ignoring_unrelated_messages does not cover all four header fields.

Important Files Changed

Filename Overview
crates/openlogi-hidpp/src/channel.rs Adds 5 characterization tests for the v20 send/matcher path; one test's comment claims all four header fields are covered by decoys but the function_id field has no corresponding decoy.
crates/openlogi-cli/src/lib.rs Adds 7 Clap parsing tests: structural validation, bare invocation, conflict detection, NonZeroU8 rejection, value-enum mapping and flag round-trips.
crates/openlogi-cli/src/cmd/assets/sync.rs Adds 6 tests for is_optional_asset, including two explicitly-pinned quirk tests.
crates/openlogi-cli/src/cmd/diag/dpi.rs Adds 2 tests pinning the list-vs-range boundary in summarize_dpi at exactly 12 values.
crates/openlogi-cli/src/cmd/diag/lighting.rs Adds 2 async tests exercising pre-I/O color validation.
crates/openlogi-cli/src/cmd/diag/mod.rs Adds 4 tests for the no_match_err error-message builder, covering all four branches.
crates/openlogi-cli/src/cmd/list.rs Adds 7 tests for format_device, format_battery, and format_model.

Sequence Diagram

%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
    participant Test
    participant HidppChannel
    participant ReadThread
    participant Listener

    Test->>HidppChannel: send_v20(request)
    Note over HidppChannel: registers oneshot waiter
    HidppChannel-->>ReadThread: (background loop)

    Test->>ReadThread: feed decoys (wrong_device / wrong_feature / wrong_sw_id)
    ReadThread->>ReadThread: predicate false - skip waiter
    ReadThread->>Listener: "notify(decoy, matched=false)"

    Test->>ReadThread: feed response (header matches)
    ReadThread->>HidppChannel: resolve oneshot
    ReadThread->>Listener: "notify(response, matched=true)"

    Note over Test: wait_for_event_count before asserting listener events
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
sequenceDiagram
    participant Test
    participant HidppChannel
    participant ReadThread
    participant Listener

    Test->>HidppChannel: send_v20(request)
    Note over HidppChannel: registers oneshot waiter
    HidppChannel-->>ReadThread: (background loop)

    Test->>ReadThread: feed decoys (wrong_device / wrong_feature / wrong_sw_id)
    ReadThread->>ReadThread: predicate false - skip waiter
    ReadThread->>Listener: "notify(decoy, matched=false)"

    Test->>ReadThread: feed response (header matches)
    ReadThread->>HidppChannel: resolve oneshot
    ReadThread->>Listener: "notify(response, matched=true)"

    Note over Test: wait_for_event_count before asserting listener events
Loading

Reviews (2): Last reviewed commit: "test(hidpp): wait for listener delivery ..." | Re-trigger Greptile

Comment thread crates/openlogi-hidpp/src/channel.rs
@AprilNEA
AprilNEA merged commit da6949b into master Jul 18, 2026
10 checks passed
@AprilNEA
AprilNEA deleted the test/cli-hidpp-v20 branch July 18, 2026 07:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant