Skip to content

Test coverage: UI touch/pen commands + pointer support (issue #630) - #672

Merged
Alexandre Zollinger Chohfi (azchohfi) merged 3 commits into
mainfrom
azchohfi-azchohfi-tests-touch-pen
Jul 17, 2026
Merged

Alexandre Zollinger Chohfi (azchohfi) merged 3 commits into
mainfrom
azchohfi-azchohfi-tests-touch-pen

Conversation

@azchohfi

Copy link
Copy Markdown
Collaborator

What

Raises per-file test coverage to 100% for the UI touch/pen command logic and pointer support (issue #630):

File Before After
Commands/UiTouchCommand.cs 85.3% 100%
Commands/UiPenCommand.cs 87.4% 100%
Helpers/PointerCommandSupport.cs 85.9% 100%
Helpers/PointerInput.cs 61.7% 64.1% (documented native ceiling)
Helpers/RealPointerInput.cs 0% 0% (documented native ceiling)

PointerInput.cs / RealPointerInput.cs remain below 95% by design: their CreateSyntheticPointerDevice / InjectSyntheticPointerInput / InjectTouchInput calls 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 injectable TouchSender / PenFrameSender seams; the native boundaries carry in-source <remarks> ceilings referencing #630. No [ExcludeFromCodeCoverage], no coverage.runsettings edits.

Product changes (minimal, behavior-preserving)

  • Extracted PointerInput.MapPenPressure(float) — the pure 0..1 → Win32 1..1024 pressure mapping — out of PointerInput.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. The Pen() ceiling <remarks> was narrowed accordingly.

Tests

  • PointerInputPressureTests — data-driven coverage of MapPenPressure: interior linear values, both clamp bounds, round-not-truncate, and the ==0 → 1 in-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.
  • New shared BaseCommandTests.InvokeWithAmbientConsoleCaptureAsync helper replaces a 4×-duplicated ambient-AnsiConsole swap harness with one try/finally-guarded method (callers stay [DoNotParallelize]).

Validation

  • Debug solution + Release (both WinApp.Cli and WinApp.Cli.Tests, warnings-as-errors): 0 W / 0 E each.
  • Scoped coverage run: 504 passed / 0 failed / 3 skipped (the skips are the WINAPP_UI_INJECTION_LIVE live-injection and WINAPP_RECORD_INTERACTIVE_TESTS gated tests, not relied on in the default lane).
  • Reviewed with the repo pr-review skill (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.

#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>
Copilot AI review requested due to automatic review settings July 17, 2026 02:29

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +783 to +785
Assert.AreEqual(1, exitCode);
Assert.AreEqual(0, _fakePointer.TouchCalls.Count);
StringAssert.Contains(ConsoleStdErr.ToString(), "no longer accessible");

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +798 to +800
Assert.AreEqual(1, exitCode);
Assert.AreEqual(0, _fakePointer.TouchCalls.Count);
StringAssert.Contains(ConsoleStdErr.ToString(), "boom (test)");

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +592 to +594
Assert.AreEqual(1, exitCode);
Assert.AreEqual(0, _fakePointer.PenCalls.Count);
StringAssert.Contains(ConsoleStdErr.ToString(), "no longer accessible");

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +607 to +609
Assert.AreEqual(1, exitCode);
Assert.AreEqual(0, _fakePointer.PenCalls.Count);
StringAssert.Contains(ConsoleStdErr.ToString(), "boom (test)");

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@github-actions

github-actions Bot commented Jul 17, 2026 •

Copy link
Copy Markdown
Contributor

⏳ Build in progress — metrics below are from a previous commit and will update when the current build finishes.

Build Metrics Report

Binary Sizes

Artifact Baseline Current Delta
CLI (ARM64) 32.40 MB 32.40 MB ✅ 0.0 KB (0.00%)
CLI (x64) 32.70 MB 32.70 MB 📈 +0.5 KB (+0.00%)
MSIX (ARM64) N/A 13.57 MB N/A
MSIX (x64) N/A 14.43 MB N/A
NPM Package N/A 28.32 MB N/A
NuGet Package N/A 28.33 MB N/A

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 Time

42ms median (x64, winapp --version) · ✅ no change vs. baseline


Updated 2026-07-17 02:51:39 UTC · commit 25d06d5 · workflow run

…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>
@azchohfi
Alexandre Zollinger Chohfi (azchohfi) merged commit aa67d14 into main Jul 17, 2026
21 of 22 checks passed
@azchohfi
Alexandre Zollinger Chohfi (azchohfi) deleted the azchohfi-azchohfi-tests-touch-pen branch July 17, 2026 03:26
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.

2 participants