Skip to content

Decompose SimulatorManager responsibilities into lifecycle, app, UI, and device catalog modules #708

@shaun0927

Description

@shaun0927

Tracked by #713.

Background

src/simulator/manager.ts mixes device discovery, boot/shutdown, screenshots, app lifecycle, UI appearance/rotation, cloning, and errors. Parallel simulator automation benefits from clearer boundaries.

Objective

Split SimulatorManager responsibilities into focused modules without changing public tool behavior.

Scope

  • Extract device catalog/discovery.
  • Extract lifecycle operations.
  • Extract app management operations.
  • Extract UI controls and screenshots.
  • Move simulator errors into a dedicated module.

Target files and paths

  • src/simulator/manager.ts
  • new src/simulator/device-catalog.ts
  • new src/simulator/lifecycle.ts
  • new src/simulator/app-manager.ts
  • new src/simulator/ui-controller.ts
  • new src/simulator/errors.ts
  • tests/unit/*simulator*.test.ts

Implementation steps

  1. Move error classes first.
  2. Extract pure discovery/catalog functions.
  3. Extract boot/shutdown lifecycle logic with tests.
  4. Extract app lifecycle methods.
  5. Extract screenshot, appearance, rotation, and status bar operations.
  6. Keep SimulatorManager facade until callers migrate.

Acceptance criteria

  • Existing simulator tools keep the same behavior and parameters.
  • Each new module has focused unit coverage or preserved existing coverage.
  • Lifecycle timeout behavior is explicit and tested.
  • No forced destructive behavior is introduced without an explicit option.

Verification

  • npm run lint -- --quiet
  • Targeted simulator manager tests
  • Manual macOS smoke: list, boot, screenshot, rotate, shutdown.

Dependencies / recommended order

Run after lifecycle polling optimization if both touch boot/shutdown. This is a staged refactor, not a single broad rewrite.

Risks and cautions

  • Avoid combining refactor with semantic changes.
  • Keep destructive operations explicit and tested.
  • Preserve Xcode version compatibility.

Non-goals

  • Do not redesign device presets.
  • Do not change CLI command names.
  • Do not migrate pool orchestration in the first PR.

Ambiguity reducers

  • “Facade” means current callers can continue constructing SimulatorManager.
  • “Lifecycle” includes boot, shutdown, erase/delete only when already present.
  • Screenshot belongs to UI controller unless a stronger module boundary is documented in the PR.

Validity review

Proceed after higher-priority speed/security work. It is valid for long-term maintainability of multi-device automation.

Implementation detail refinements

  • Move error classes first to reduce import churn.
  • Add deprecation comments only if public imports move.
  • Use dependency injection for Simctl to keep tests fast.

Verification checklist reinforcement

  • Existing simulator tests pass.
  • New module boundaries are reflected in imports.
  • Manual simulator smoke passes.
  • No public tool schema changes occur.

Metadata

Metadata

Assignees

No one assigned

    Labels

    architectureArchitecture changes and improvementsautomation-roadmapOpenSafari automation roadmap work itemstech-debtTechnical debt and maintainability

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions