Skip to content

refactor(input): consolidate sim-hid + pointer-service + flutter-vm backends (#707 b)#733

Merged
shaun0927 merged 2 commits into
refactor/707a-input-resolverfrom
refactor/707b-consolidate
May 8, 2026
Merged

refactor(input): consolidate sim-hid + pointer-service + flutter-vm backends (#707 b)#733
shaun0927 merged 2 commits into
refactor/707a-input-resolverfrom
refactor/707b-consolidate

Conversation

@shaun0927
Copy link
Copy Markdown
Owner

Stacked on PR #731 (base = refactor/707a-input-resolver). Will retarget to develop after #731 merges.

Implements the #707 follow-up deferred from PR #731. Behavior-preserving moves + import path updates only. Closes #707 when combined with #707a (PR #731).

What changed

Three backend files are relocated from src/tools/ into src/input/ to be consistent with the modules already split there by #707a:

Old path New canonical path
src/tools/sim-hid-input-backend.ts src/input/sim-hid-backend.ts
src/tools/pointer-service-input-backend.ts src/input/pointer-service-backend.ts
src/tools/flutter-vm-input-backend.ts src/input/flutter-vm-backend.ts

The old src/tools/ paths become thin re-export shims so all existing external callers (tests, integration suites, any downstream consumers) continue to work without modification.

Internal callers that live inside src/ are updated to import from the new canonical paths directly:

  • src/input/backend-resolver.ts — previously crossed the src/input/src/tools/ boundary; now imports within src/input/
  • src/tools/diagnose.ts and src/tools/pasteboard-input.ts — both imported from ./sim-hid-input-backend; updated to ../input/sim-hid-backend

src/metrics/input-telemetry.ts and src/metrics/input-telemetry-rollup.ts already imported from ../input/backend directly — no change needed.

Decision: pointer-service and flutter-vm

Both moves are purely mechanical (file relocation + import-path updates, zero logic change), so they are included here per the task spec. No behaviour changes, no promotion of experimental status, no schema changes.

Validation

  • npx tsc --noEmit — 0 errors
  • npm run build — clean
  • npx jest (5 input unit test suites, 175 tests) — all pass
  • npx jest (2 telemetry suites, 28 tests) — all pass
  • npm run lint -- --quiet — clean
  • git diff --check — clean

Diff is ~60 net new lines (shims + updated imports) on top of ~1200 lines moved.

Move sim-hid, pointer-service, and flutter-vm backends from src/tools/
into src/input/ for consistency with the #707a split. The old paths are
kept as thin re-export shims so all existing callers (tests, tools,
integration suites) continue to work without modification.

Internal callers that were already inside src/ are updated to import
directly from the new canonical paths:
  - src/input/backend-resolver.ts  → ./sim-hid-backend, ./pointer-service-backend, ./flutter-vm-backend
  - src/tools/diagnose.ts          → ../input/sim-hid-backend
  - src/tools/pasteboard-input.ts  → ../input/sim-hid-backend

src/metrics/input-telemetry.ts and src/metrics/input-telemetry-rollup.ts
already imported from ../input/backend directly (no change needed).

Behavior is strictly unchanged: no fallback semantics, no public API, no
tool schemas were altered.

Decision on pointer-service and flutter-vm: both moves are mechanical
(relocation + import-path update, zero logic change), so they are included
here per the task spec.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@qodo-code-review
Copy link
Copy Markdown

ⓘ You've reached your Qodo monthly free-tier limit. Reviews pause until next month — upgrade your plan to continue now, or link your paid account if you already have one.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the codebase by consolidating input backend tools into the src/input/ directory while maintaining backward compatibility via re-export shims in src/tools/. The reviewer suggests optimizing runTapPs by moving dynamic imports to the top level for better performance and updating tryCreateSimulatorKitHIDBackend to return null instead of throwing an error when the bridge is missing, ensuring consistency with its documentation and other factory methods.

Comment thread src/input/pointer-service-backend.ts Outdated
Comment on lines +140 to +142
const { execFile } = await import('child_process');
const { promisify } = await import('util');
const execFileAsync = promisify(execFile);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The dynamic imports for child_process and util inside runTapPs are executed on every tap call. Since these are standard Node.js modules and are already used by the delegate backend, they should be imported at the top level of the file to avoid unnecessary overhead and improve performance.

Comment on lines +464 to +469
const searched = candidates.map((c) => ` - ${c}`).join('\n');
throw new InputBackendError(
`sim-hid-bridge not found. Searched:\n${searched}\n` +
'Run npm run build or set OPENSAFARI_ALLOW_SWIFT_INTERPRETER=1 for dev mode.',
'HID_BRIDGE_MISSING',
);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The implementation of tryCreateSimulatorKitHIDBackend throws an InputBackendError when the bridge is not found, which contradicts its docstring (line 430) stating it returns null. It is also inconsistent with tryCreatePointerServiceBackend in pointer-service-backend.ts. To align with the documentation and provide a consistent API for the resolver, this should return null instead of throwing.

Suggested change
const searched = candidates.map((c) => ` - ${c}`).join('\n');
throw new InputBackendError(
`sim-hid-bridge not found. Searched:\n${searched}\n` +
'Run npm run build or set OPENSAFARI_ALLOW_SWIFT_INTERPRETER=1 for dev mode.',
'HID_BRIDGE_MISSING',
);
return null;

- Hoist runTapPs's child_process / util imports to module scope so each
  tap call no longer re-resolves them. Matches sim-hid-backend.ts which
  already imports execFile/promisify at the top.
- Document tryCreateSimulatorKitHIDBackend's actual contract: returns a
  backend or throws InputBackendError(HID_BRIDGE_MISSING). The previous
  docstring said it returns null on missing bridge, which has never been
  the case (see tests/unit/sim-hid-input-backend.test.ts). Aligning the
  contract to null is a behavior change and is intentionally deferred so
  this PR remains a behavior-preserving file relocation.
@shaun0927
Copy link
Copy Markdown
Owner Author

Re: gemini's suggestion to change tryCreateSimulatorKitHIDBackend to return null on missing bridge:

This PR is intentionally a behavior-preserving file relocation (per the PR description). The throw vs null decision is unchanged from before #707b — and the throw is currently asserted by tests/unit/sim-hid-input-backend.test.ts:521,529, so flipping it to null would be a real behavior change plus test churn that goes beyond the consolidation scope.

What I did instead in 40e6c04: fixed the docstring to match actual behavior (returns a backend or throws InputBackendError(HID_BRIDGE_MISSING)). That resolves the contract inconsistency gemini flagged without altering runtime behavior. Aligning the implementation to null (matching tryCreatePointerServiceBackend) can be tracked as a separate PR if/when we want that contract change.

@shaun0927
Copy link
Copy Markdown
Owner Author

/gemini review

@shaun0927
Copy link
Copy Markdown
Owner Author

@codex review

@gemini-code-assist
Copy link
Copy Markdown

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 👍

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@shaun0927 shaun0927 merged commit ca984fa into refactor/707a-input-resolver May 8, 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