Repository navigation
Test coverage: UI touch/pen commands + pointer support (issue #630) - #672
Alexandre Zollinger Chohfi (azchohfi) merged 3 commits into
Conversation
#630) Bucket 3 (issue #630) touch/pen coverage top-up. Adds meaningful, deterministic use-case tests driving UiTouchCommand / UiPenCommand through the command handler with the fake IPointerInput, asserting exit codes, that no injection occurs on rejected/aborted paths, and the human error/success/warning messages routed to stderr / the ambient console. Per-file line coverage (scoped MTP run): - Helpers/PointerCommandSupport.cs: 100% (was 85.9%) - Commands/UiTouchCommand.cs: 100% (was 85.3%) - Commands/UiPenCommand.cs: 100% (was 87.4%) - Helpers/PointerInput.cs: 63.1% (was 61.7%) - native ceiling - Helpers/RealPointerInput.cs: 0/2 - native adapter ceiling New tests (30): - UiCommandTests.Touch.cs (+16): arg-validation branches (fingers<1, invalid --direction value, malformed --at/--to-point, no-target, pinch-without-distance, swipe-without-endpoint), missing-app, selector not-found / zero-size / vanished-before-injection, non-JSON local + remote render paths, COMException->stale, generic->internal_error. - UiCommandTests.Pen.cs (+12): analogous coverage (negative duration, tilt out-of-range, malformed --path/--at, no-target, missing-app, selector not-found, non-JSON local + remote, COM + generic catch). - PointerInputFrameTests.cs (+2): best-effort finally lift that SUCCEEDS after a mid-stroke glide throw (complements the swallowed-failure case), and Interpolate's single-waypoint fast path via a mixed-waypoint stroke. Native SendInput/OS injection paths in PointerInput.cs and the RealPointerInput adapter require a live, unlocked interactive desktop and are genuinely un-coverable in the shared CI/test run; each is documented as a per-method coverage ceiling via <remarks> referencing issue #630. The frame-planning logic feeding them is covered through the injectable TouchSender / PenFrameSender seams. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…le capture pr-review (Bucket 3, touch/pen) flagged two MEDIUM issues on this branch. Finding 1 (no coverage gaming): PointerInput.Pen() mapped pen pressure inline, after the native CreateSyntheticPointerDevice call, hiding the pure float->uint arithmetic behind the native ceiling so the frame tests never exercised it. Extract it into a pure internal helper MapPenPressure(float) (behavior- preserving: identical clamp + round + non-zero bump), replace the two inline lines with a call, and add PointerInputPressureTests covering both branches of the ==0 guard and both clamp bounds with exact values. Narrow the Pen() <remarks> #630 ceiling to the OS injection calls only. PointerInput.cs line coverage rises 63.1% -> 64.2%. Finding 2 (DRY): the ambient-console swap harness was copy-pasted across four non-JSON touch/pen tests. Extract one shared BaseCommandTests helper, InvokeWithAmbientConsoleCaptureAsync, that always restores the previous ambient console in a finally so global state cannot leak across tests, and replace the four duplicated blocks with calls to it. Behavior is identical. Builds: Debug solution 0W/0E; Release WinApp.Cli and WinApp.Cli.Tests each 0W/0E. Scoped coverage: PointerCommandSupport / UiTouchCommand / UiPenCommand stay 100%; the new MapPenPressure lines are covered. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Improves deterministic coverage for UI touch/pen commands and pointer logic while documenting native-injection coverage limits.
Changes:
- Adds touch/pen validation, error-path, output, and frame tests.
- Extracts and tests pen-pressure mapping.
- Adds reusable ambient-console capture and native coverage remarks.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
Helpers/RealPointerInput.cs |
Documents native coverage limits. |
Helpers/PointerInput.cs |
Extracts pressure mapping and documents native boundaries. |
UiCommandTests.Touch.cs |
Expands touch command coverage. |
UiCommandTests.Pen.cs |
Expands pen command coverage. |
PointerInputPressureTests.cs |
Tests pressure mapping. |
PointerInputFrameTests.cs |
Covers residual touch-frame branches. |
BaseCommandTests.cs |
Adds shared ambient-console capture. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| Assert.AreEqual(1, exitCode); | ||
| Assert.AreEqual(0, _fakePointer.TouchCalls.Count); | ||
| StringAssert.Contains(ConsoleStdErr.ToString(), "no longer accessible"); |
There was a problem hiding this comment.
Fixed in d215a9e. Root cause: UiErrors.StaleElement/GenericError emitted the --json envelope to the raw Console.Error instead of the command's configured InvocationConfiguration.Error (unlike the sibling AppNotFound/InvalidOperation catches), so it never reached the test's capturing writer. Threaded an errorOut writer through those two helpers and pass parseResult.InvocationConfiguration.Error at the touch/pen catch sites (behavior-preserving — in production that writer is Console.Error). The test now asserts the structured code via AssertJsonErrorCode in addition to the human message; UiTouchCommand/UiPenCommand/UiErrors stay 100% covered.
| Assert.AreEqual(1, exitCode); | ||
| Assert.AreEqual(0, _fakePointer.TouchCalls.Count); | ||
| StringAssert.Contains(ConsoleStdErr.ToString(), "boom (test)"); |
There was a problem hiding this comment.
Fixed in d215a9e. Root cause: UiErrors.StaleElement/GenericError emitted the --json envelope to the raw Console.Error instead of the command's configured InvocationConfiguration.Error (unlike the sibling AppNotFound/InvalidOperation catches), so it never reached the test's capturing writer. Threaded an errorOut writer through those two helpers and pass parseResult.InvocationConfiguration.Error at the touch/pen catch sites (behavior-preserving — in production that writer is Console.Error). The test now asserts the structured code via AssertJsonErrorCode in addition to the human message; UiTouchCommand/UiPenCommand/UiErrors stay 100% covered.
| Assert.AreEqual(1, exitCode); | ||
| Assert.AreEqual(0, _fakePointer.PenCalls.Count); | ||
| StringAssert.Contains(ConsoleStdErr.ToString(), "no longer accessible"); |
There was a problem hiding this comment.
Fixed in d215a9e. Root cause: UiErrors.StaleElement/GenericError emitted the --json envelope to the raw Console.Error instead of the command's configured InvocationConfiguration.Error (unlike the sibling AppNotFound/InvalidOperation catches), so it never reached the test's capturing writer. Threaded an errorOut writer through those two helpers and pass parseResult.InvocationConfiguration.Error at the touch/pen catch sites (behavior-preserving — in production that writer is Console.Error). The test now asserts the structured code via AssertJsonErrorCode in addition to the human message; UiTouchCommand/UiPenCommand/UiErrors stay 100% covered.
| Assert.AreEqual(1, exitCode); | ||
| Assert.AreEqual(0, _fakePointer.PenCalls.Count); | ||
| StringAssert.Contains(ConsoleStdErr.ToString(), "boom (test)"); |
There was a problem hiding this comment.
Fixed in d215a9e. Root cause: UiErrors.StaleElement/GenericError emitted the --json envelope to the raw Console.Error instead of the command's configured InvocationConfiguration.Error (unlike the sibling AppNotFound/InvalidOperation catches), so it never reached the test's capturing writer. Threaded an errorOut writer through those two helpers and pass parseResult.InvocationConfiguration.Error at the touch/pen catch sites (behavior-preserving — in production that writer is Console.Error). The test now asserts the structured code via AssertJsonErrorCode in addition to the human message; UiTouchCommand/UiPenCommand/UiErrors stay 100% covered.
Build Metrics ReportBinary Sizes
Test Results✅ 3473 passed, 4 skipped out of 3477 tests in 593.9s (+39 tests, +65.9s vs. baseline) Test Coverage✅ 94.2% line coverage, 88.7% branch coverage · ✅ +0.4% vs. baseline CLI Startup Time42ms median (x64, Updated 2026-07-17 02:51:39 UTC · commit |
…iter Copilot review flagged that the touch/pen COMException (stale_element) and generic (internal_error) tests asserted only the human message, so a JSON error-code regression would pass. The structured envelope from UiErrors. StaleElement/GenericError was emitted to the raw Console.Error instead of the command's configured InvocationConfiguration.Error, unlike the sibling AppNotFound/InvalidOperation catches in the same commands. Thread an optional errorOut writer through UiErrors.StaleElement/GenericError and pass parseResult.InvocationConfiguration.Error at the touch/pen catch sites (behavior-preserving: in production InvocationConfiguration.Error is Console.Error). Strengthen the four tests with AssertJsonErrorCode to pin the stale_element / internal_error codes. UiTouchCommand/UiPenCommand/UiErrors all remain 100% covered. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
aa67d14
into
main
What
Raises per-file test coverage to 100% for the UI touch/pen command logic and pointer support (issue #630):
Commands/UiTouchCommand.csCommands/UiPenCommand.csHelpers/PointerCommandSupport.csHelpers/PointerInput.csHelpers/RealPointerInput.csPointerInput.cs/RealPointerInput.csremain below 95% by design: theirCreateSyntheticPointerDevice/InjectSyntheticPointerInput/InjectTouchInputcalls require a touch/pen-capable, unlocked interactive desktop and cannot run in the shared CI lane. The frame-planning and ordering logic that feeds them is covered deterministically via the injectableTouchSender/PenFrameSenderseams; the native boundaries carry in-source<remarks>ceilings referencing #630. No[ExcludeFromCodeCoverage], nocoverage.runsettingsedits.Product changes (minimal, behavior-preserving)
PointerInput.MapPenPressure(float)— the pure0..1 → Win32 1..1024pressure mapping — out ofPointerInput.Pen()so the arithmetic (linear scale, nearest-integer rounding, clamping, and the non-zero-pressure guarantee that keeps in-contact frames in contact) is unit-testable without the native synthetic-pointer device.Pen()now calls it; logic is byte-for-byte identical. ThePen()ceiling<remarks>was narrowed accordingly.Tests
PointerInputPressureTests— data-driven coverage ofMapPenPressure: interior linear values, both clamp bounds, round-not-truncate, and the==0 → 1in-contact guarantee.UiCommandTests.Touch/.Pen— argument validation, injection-count assertions via the pointer fake, human error/success/warning strings, JSON envelopes, remote-session advisory warning, and out-of-window rejection.BaseCommandTests.InvokeWithAmbientConsoleCaptureAsynchelper replaces a 4×-duplicated ambient-AnsiConsoleswap harness with onetry/finally-guarded method (callers stay[DoNotParallelize]).Validation
WinApp.CliandWinApp.Cli.Tests, warnings-as-errors): 0 W / 0 E each.WINAPP_UI_INJECTION_LIVElive-injection andWINAPP_RECORD_INTERACTIVE_TESTSgated tests, not relied on in the default lane).pr-reviewskill (7 specialists + a GPT multi-model cross-check) before opening; the two accepted MEDIUM findings (pressure-mapping hidden behind the native ceiling; the copy-pasted console-swap harness) are fixed in this branch. New tests assert stable observable behavior (exit codes, injection counts, message substrings), so they are unaffected by the pending out-of-window reject→warn change in the open pointer PRs.