Skip to content

chore: Application layer no longer reads Unity editor state directly#1528

Merged
hatayama merged 1 commit into
v3-betafrom
refactor/c4-editor-runtime-state-port
Jul 5, 2026
Merged

chore: Application layer no longer reads Unity editor state directly#1528
hatayama merged 1 commit into
v3-betafrom
refactor/c4-editor-runtime-state-port

Conversation

@hatayama

@hatayama hatayama commented Jul 5, 2026

Copy link
Copy Markdown
Owner

Summary

User Impact

  • No runtime behavior change. Busy/guard error messages, state-refresh timing, and domain-reload subscription behavior are unchanged; only where the values are read from moved.

Changes

  • New IEditorRuntimeStatePort (Application) + EditorRuntimeStateService (Infrastructure) reading EditorApplication state.
  • The EditorApplication.update/playModeStateChanged subscription moved from the Application-side snapshot into an Infrastructure subscriber, initialized at the same bootstrap position.
  • UnityCliLoopEditorStateGuard.ValidateForState now receives all four state booleans explicitly (named arguments at every call site) instead of reading two of them from EditorApplication inside its throw branches.
  • UnityCliLoopToolExecutionService takes the port via constructor injection from the composition root.
  • New source-scan guard test ApplicationSources_WhenLoaded_DoNotReferenceUnityEditor pins the Application layer as UnityEditor-free (no compiler-level gate exists for UnityEditor usage).

Verification

  • dist/darwin-arm64/uloop compile: 0 errors, 0 warnings
  • uloop run-tests (state guard, tool execution service, onion dependency, JSON-RPC version gate, tool registry, tool settings suites): 135/135 passed
  • grep -rn "UnityEditor" Packages/src/Editor/Application/: zero matches

Review in cubic

Application code read EditorApplication directly in three places: the
editor state snapshot subscription, the execution state guard, and
busy-exception construction. Introduce IEditorRuntimeStatePort in
Application with an Infrastructure implementation, move the
EditorApplication.update/playModeStateChanged subscription behind the
boundary, and add a source-scan guard test that keeps the Application
layer free of UnityEditor references.
@coderabbitai

coderabbitai Bot commented Jul 5, 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: 2e8eacc5-77cb-49d4-96ff-332bd494bba4

📥 Commits

Reviewing files that changed from the base of the PR and between 3cd2604 and 7f95133.

⛔ Files ignored due to path filters (5)
  • Assets/Tests/Editor/NoOpEditorRuntimeStatePort.cs.meta is excluded by none and included by none
  • Packages/src/Editor/Application/EditorRuntimeStatePort.cs.meta is excluded by none and included by none
  • Packages/src/Editor/Infrastructure/EditorState.meta is excluded by none and included by none
  • Packages/src/Editor/Infrastructure/EditorState/EditorRuntimeStateService.cs.meta is excluded by none and included by none
  • Packages/src/Editor/Infrastructure/EditorState/EditorRuntimeStateSnapshotSubscriber.cs.meta is excluded by none and included by none
📒 Files selected for processing (17)
  • Assets/Tests/Editor/DynamicCodeToolTests/ExecuteDynamicCodeParameterValidationTests.cs
  • Assets/Tests/Editor/JsonRpcProcessorCliVersionGateTests.cs
  • Assets/Tests/Editor/NoOpEditorRuntimeStatePort.cs
  • Assets/Tests/Editor/OnionAssemblyDependencyTests.cs
  • Assets/Tests/Editor/ToolSettingsUseCaseTests.cs
  • Assets/Tests/Editor/UnityCliLoopEditorStateGuardTests.cs
  • Assets/Tests/Editor/UnityCliLoopToolExecutionServiceTests.cs
  • Assets/Tests/Editor/UnityCliLoopToolRegistryTests.cs
  • Packages/src/Editor/Application/ApplicationEditorStartup.cs
  • Packages/src/Editor/Application/EditorRuntimeStatePort.cs
  • Packages/src/Editor/Application/UnityCliLoopEditorStateGuard.cs
  • Packages/src/Editor/Application/UnityCliLoopEditorStateSnapshot.cs
  • Packages/src/Editor/Application/UnityCliLoopToolExecutionService.cs
  • Packages/src/Editor/CompositionRoot/UnityCliLoopApplicationRegistration.cs
  • Packages/src/Editor/CompositionRoot/UnityCliLoopEditorBootstrapper.cs
  • Packages/src/Editor/Infrastructure/EditorState/EditorRuntimeStateService.cs
  • Packages/src/Editor/Infrastructure/EditorState/EditorRuntimeStateSnapshotSubscriber.cs
💤 Files with no reviewable changes (1)
  • Packages/src/Editor/Application/ApplicationEditorStartup.cs

📝 Walkthrough

Walkthrough

Introduces IEditorRuntimeStatePort abstraction to decouple UnityCliLoopEditorStateGuard, UnityCliLoopToolExecutionService, and UnityCliLoopEditorStateSnapshot from direct UnityEditor.EditorApplication access. Adds EditorRuntimeStateService (production) and NoOpEditorRuntimeStatePort (test) implementations, plus EditorRuntimeStateSnapshotSubscriber to update the snapshot from Editor events, wired into composition root and bootstrapper. Updates existing tests and adds an assembly-boundary test asserting application sources don't reference UnityEditor.

Changes

IEditorRuntimeStatePort introduction

Layer / File(s) Summary
Port interface and implementations
Packages/src/Editor/Application/EditorRuntimeStatePort.cs, Packages/src/Editor/Infrastructure/EditorState/EditorRuntimeStateService.cs, Packages/src/Editor/Infrastructure/EditorState/EditorRuntimeStateSnapshotSubscriber.cs, Assets/Tests/Editor/NoOpEditorRuntimeStatePort.cs
New IEditorRuntimeStatePort interface exposing IsCompiling, IsUpdating, IsPlaying, IsPaused; EditorRuntimeStateService maps these to EditorApplication flags; EditorRuntimeStateSnapshotSubscriber subscribes to Editor update/play-mode events and pushes state into the snapshot; NoOpEditorRuntimeStatePort returns false for all flags in tests.
Guard and snapshot decoupling
Packages/src/Editor/Application/UnityCliLoopEditorStateGuard.cs, Packages/src/Editor/Application/UnityCliLoopEditorStateSnapshot.cs
UnityCliLoopEditorStateGuard.Validate now accepts an IEditorRuntimeStatePort and forwards isPlaying/isPaused through ValidateForState and busy-exception construction; UnityEditor import removed. UnityCliLoopEditorStateSnapshot drops its Editor event subscription/initialization and exposes SetPlayState as internal for external callers.
Execution service wiring
Packages/src/Editor/Application/UnityCliLoopToolExecutionService.cs
Constructor now requires IEditorRuntimeStatePort; ExecuteToolAsync and CreateBusyException use the injected port instead of EditorApplication directly; UnityEditor import removed.
Composition root and startup
Packages/src/Editor/CompositionRoot/UnityCliLoopApplicationRegistration.cs, Packages/src/Editor/CompositionRoot/UnityCliLoopEditorBootstrapper.cs, Packages/src/Editor/Application/ApplicationEditorStartup.cs
Registration constructs EditorRuntimeStateService and injects it into UnityCliLoopToolExecutionService; bootstrapper initializes EditorRuntimeStateSnapshotSubscriber; startup no longer calls the removed snapshot initializer.
Test updates and assembly boundary check
Assets/Tests/Editor/*.cs
Existing tests updated to construct UnityCliLoopToolExecutionService with NoOpEditorRuntimeStatePort, pass the port to CreateBusyException, and use named parameters for ValidateForState; new OnionAssemblyDependencyTests case asserts application sources don't reference UnityEditor.

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

Sequence Diagram(s)

sequenceDiagram
  participant EditorApplication
  participant EditorRuntimeStateSnapshotSubscriber
  participant UnityCliLoopEditorStateSnapshot
  participant UnityCliLoopToolExecutionService
  participant UnityCliLoopEditorStateGuard
  participant EditorRuntimeStateService

  EditorApplication->>EditorRuntimeStateSnapshotSubscriber: update / playModeStateChanged
  EditorRuntimeStateSnapshotSubscriber->>UnityCliLoopEditorStateSnapshot: SetPlayState(isPlaying, isPaused)

  UnityCliLoopToolExecutionService->>UnityCliLoopEditorStateGuard: Validate(toolName, editorRuntimeStatePort)
  UnityCliLoopEditorStateGuard->>EditorRuntimeStateService: IsCompiling / IsUpdating / IsPlaying / IsPaused
  EditorRuntimeStateService->>EditorApplication: read live state
  UnityCliLoopEditorStateGuard-->>UnityCliLoopToolExecutionService: throw UnityCliLoopToolBusyException or allow
Loading

Possibly related PRs

  • hatayama/unity-cli-loop#1164: Both PRs touch UnityCliLoopEditorStateGuard/UnityCliLoopToolBusyException busy-state gating logic, with this PR refactoring that guard to use the injected IEditorRuntimeStatePort.
  • hatayama/unity-cli-loop#1283: Shares code-level changes around the same guard/exception/execution-service and editor state snapshot wiring.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the main refactor: moving Unity editor state reads out of the Application layer.
Description check ✅ Passed The description is directly about the same refactor and its tests, so it is clearly relevant.
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/c4-editor-runtime-state-port

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.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

No issues found across 22 files

Re-trigger cubic

@hatayama
hatayama merged commit 6e33518 into v3-beta Jul 5, 2026
10 checks passed
@hatayama
hatayama deleted the refactor/c4-editor-runtime-state-port branch July 5, 2026 17:57
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