Skip to content

chore: simplify mouse input simulation support - #1646

Merged
hatayama merged 2 commits into
v3-betafrom
refactor/hatayama/evaluate-mouse-input-use-case
Jul 9, 2026
Merged

hatayama merged 2 commits into
v3-betafrom
refactor/hatayama/evaluate-mouse-input-use-case

Conversation

@hatayama

@hatayama hatayama commented Jul 9, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • Isolate mouse input response construction and main-thread cleanup from action execution.
  • Keep mouse input simulation behavior, messages, timing, and wire responses unchanged.

User Impact

  • No user-visible behavior change is intended.
  • Click, long-press, movement, scroll, timeout cleanup, and Pause Point reporting retain their existing behavior.

Changes

  • Move interrupted and timed-out response projection to MouseInputSimulationResponseFactory.
  • Add focused characterization coverage for timeout fields and multiple Pause Point hit projection.
  • Move button release, delta reset, overlay cleanup, and deferred timeout recovery to stateless MouseInputMainThreadCleanup.
  • Extend the async CancellationToken source guard to the new cleanup owner.
  • Reduce SimulateMouseInputUseCase from 770 to 580 lines; action execution remains in the use case for the next R2-42 stages.

Refactor Safety

  • The PR contains two commits so response and cleanup moves can be reviewed independently.
  • Statement order, ConfigureAwait(false), CancellationToken.None cleanup semantics, fire-and-forget scheduling, response strings and fields, overlay mutations, and Pause Point projection are preserved.
  • Moved helpers have no instance or mutable static fields and do not depend back on SimulateMouseInputUseCase.
  • No schema, public API, wire shape, or protocol declaration changed.

Verification

  • Baseline SimulateMouseInputTests: 12/12 passed.
  • Red: the two factory characterization tests produced two expected missing-type compile errors before extraction.
  • Response factory tests plus existing mouse input PlayMode tests: 14/14 passed.
  • Assembly dependency, PlayMode preflight, and static source guard fixtures: 111/111 passed.
  • Unity compile: 0 errors, 0 warnings.
  • git diff --check: passed.

Follow-up

  • R2-42 Stage 2 will move click and long-press execution to a press action executor.
  • R2-42 Stage 3 will move delta, scroll, and smooth-delta execution and leave the use case as the tool-level orchestrator.

Review in cubic

hatayama added 2 commits July 9, 2026 09:20
Move interrupted and timed-out response projection behind a focused
factory so action executors no longer own wire response assembly. Add
characterization coverage for timeout fields and multiple pause hits.
Move device release, delta reset, and timeout recovery behind one
stateless owner so action execution no longer carries cleanup policy.
Keep the async cancellation-token guard tracking the moved methods.
@coderabbitai

coderabbitai Bot commented Jul 9, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 253e4a80-23d2-4387-ab4f-c0ca2831188a

📥 Commits

Reviewing files that changed from the base of the PR and between 5eed29b and 8750f65.

⛔ Files ignored due to path filters (3)
  • Assets/Tests/PlayMode/MouseInputSimulationResponseFactoryTests.cs.meta is excluded by none and included by none
  • Packages/src/Editor/FirstPartyTools/SimulateMouseInput/MouseInputMainThreadCleanup.cs.meta is excluded by none and included by none
  • Packages/src/Editor/FirstPartyTools/SimulateMouseInput/MouseInputSimulationResponseFactory.cs.meta is excluded by none and included by none
📒 Files selected for processing (5)
  • Assets/Tests/Editor/StaticFacadeStateGuardTests.cs
  • Assets/Tests/PlayMode/MouseInputSimulationResponseFactoryTests.cs
  • Packages/src/Editor/FirstPartyTools/SimulateMouseInput/MouseInputMainThreadCleanup.cs
  • Packages/src/Editor/FirstPartyTools/SimulateMouseInput/MouseInputSimulationResponseFactory.cs
  • Packages/src/Editor/FirstPartyTools/SimulateMouseInput/SimulateMouseInputUseCase.cs

📝 Walkthrough

Walkthrough

Response construction and cleanup logic previously embedded in SimulateMouseInputUseCase are extracted into two new classes: MouseInputSimulationResponseFactory (builds interrupted/timed-out responses with pause-point metadata) and MouseInputMainThreadCleanup (handles main-thread button/overlay/delta cleanup). The use case is updated to call these, PlayMode tests are added for the factory, and the async guard test's allowlist is extended.

Changes

Mouse Input Response/Cleanup Extraction

Layer / File(s) Summary
Response factory for simulation results
Packages/src/Editor/FirstPartyTools/SimulateMouseInput/MouseInputSimulationResponseFactory.cs
Adds a factory building interrupted/timed-out SimulateMouseInputResponse objects and attaching pause-point hit metadata from the pause-point registry.
Main-thread cleanup helper
Packages/src/Editor/FirstPartyTools/SimulateMouseInput/MouseInputMainThreadCleanup.cs
Adds a helper for releasing mouse buttons, resetting delta, and scheduling timed-out cleanup on Unity's main thread, gated by mouse-injection availability and pause state.
Use case rewiring
Packages/src/Editor/FirstPartyTools/SimulateMouseInput/SimulateMouseInputUseCase.cs
Click, LongPress, MoveDelta, Scroll, and SmoothDelta execution paths now call the new factory and cleanup helper instead of removed inline helper methods.
Tests and guard allowlist
Assets/Tests/PlayMode/MouseInputSimulationResponseFactoryTests.cs, Assets/Tests/Editor/StaticFacadeStateGuardTests.cs
New PlayMode tests verify factory behavior for pause-point interruption and timeout cases; the async cancellation-token guard test's scanned file allowlist is extended to include the new cleanup file.

Estimated code review effort: 3 (Moderate) | ~30 minutes

Sequence Diagram(s)

sequenceDiagram
  participant UseCase as SimulateMouseInputUseCase
  participant Factory as MouseInputSimulationResponseFactory
  participant Cleanup as MouseInputMainThreadCleanup
  participant Registry as PausePointRegistry
  participant Mouse

  UseCase->>UseCase: detect timeout or pause interruption
  alt interrupted by pause point
    UseCase->>Factory: InterruptedButtonResult/InterruptedActionResult(...)
    Factory->>Registry: query latest pause-point snapshot
    Registry-->>Factory: snapshot/hits
    Factory-->>UseCase: response with PausePointId, hits
  else timed out
    UseCase->>Cleanup: ScheduleTimedOutButtonCleanup/OverlayCleanup/DeltaCleanup
    Cleanup->>Mouse: release button / reset delta / clear overlay
    UseCase->>Factory: TimedOutButtonResult/TimedOutActionResult(...)
    Factory-->>UseCase: failure response
  end
  UseCase-->>UseCase: return SimulateMouseInputResponse
Loading

Possibly related PRs

  • hatayama/unity-cli-loop#1214: Both PRs modify the mouse input simulation execution flow in SimulateMouseInputUseCase.cs, with this PR refactoring interruption/timeout results and cleanup via factories/schedulers.
  • hatayama/unity-cli-loop#1516: Both PRs modify SimulateMouseInputUseCase's interruption/timeout handling and cleanup call sites for the same core mouse-simulation code paths.
  • hatayama/unity-cli-loop#1594: Both PRs modify the mouse input cleanup flow in SimulateMouseInputUseCase.cs, overlapping at the button-release/cleanup code paths.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately reflects the mouse input simulation refactor.
Description check ✅ Passed The description clearly matches the refactor, tests, and unchanged-behavior goals in the changeset.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/hatayama/evaluate-mouse-input-use-case

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@hatayama
hatayama merged commit 041dd24 into v3-beta Jul 9, 2026
10 checks passed
@hatayama
hatayama deleted the refactor/hatayama/evaluate-mouse-input-use-case branch July 9, 2026 00:42
RyanXie123 pushed a commit to RyanXie123/unity-cli-loop that referenced this pull request Sep 22, 2026
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