chore: Compile session state now flows from a single composition-root instance#1512
Conversation
Four production sites rebuilt UnityCliLoopEditorSessionStateService with a fresh UnityCliLoopEditorSessionStateRepository, bypassing the CompositionRoot -owned shared instance. Introduce UnityCliLoopEditorSessionStateFacade in the Domain layer as the read seam that CompositionRoot registers once, and thread the shared service through the compile pipeline via constructor injection. CompileTool (built by Activator.CreateInstance in the tool registry) and CompileStatusBridgeCommand (a static bridge dispatched by the IPC router) both lack an injection seam, so they read from the facade. The pipeline below CompileTool (CompileUseCase -> CompilationExecutionService -> CompileController) now takes the service via ctor. Drop the deprecated parameterless convenience ctors on DomainReloadDetectionFileService, UnityCliLoopBridgeServer, and UnityCliLoopBridgeServerInstanceFactory, since they only existed to hide the same ad hoc construction and have no callers now that CompositionRoot uses the injected paths. The dev editor window and example add a Domain asmdef reference so they can obtain the shared service through the facade for local compile checks. Verification: - dist/darwin-arm64/uloop compile --project-path <repo> -> Success, 0 errors, 0 warnings. - dist/darwin-arm64/uloop run-tests --filter-type regex --filter-value "(CompileSessionResultService|CompileStatusBridgeCommand| DomainReloadDetectionService|DomainReloadRecoveryUseCase| UnityCliLoopServerControllerStartupLock|UnityCliLoopServerStartupProtection| StaticFacadeStateGuard|OnionAssemblyDependency)" -> 122 tests: 119 pass, 3 baseline failures unrelated to this refactor (MigratedFacadeFiles_WhenScanned_DoNotOwnMutableStaticState references a stale MainThreadSwitcher path, EditorUiFiles_WhenLoaded_DoNotReferenceFacadeInternalsDirectly flags pre-existing Presentation references to CliVersionComparer, and SimulateMouseUiUseCase_WhenReturningAfterTimeout_UsesCapturedUnityObjectState checks unrelated content). All three fail on origin/v3-beta with these changes stashed.
📝 WalkthroughWalkthroughA new static ChangesSession State Dependency Injection
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant Registration as UnityCliLoopApplicationRegistration
participant Facade as UnityCliLoopEditorSessionStateFacade
participant Tool as CompileTool
participant UseCase as CompileUseCase
participant ExecService as CompilationExecutionService
participant Controller as CompileController
Registration->>Facade: RegisterService(sessionStateService)
Tool->>Facade: Service
Facade-->>Tool: sessionStateService
Tool->>UseCase: new CompileUseCase(sessionStateService)
UseCase->>ExecService: new CompilationExecutionService(_sessionStateService)
ExecService->>Controller: new CompileController(_sessionStateService)
Controller->>Controller: RecordCompileResultIfNeeded(_sessionStateService)
Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
Packages/src/Editor/Domain/UnityCliLoopEditorSessionStateFacade.cs (1)
15-15: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueNaming inconsistent with codebase convention.
ServiceValueis a private static field but doesn't follow the_camelCaseconvention used for backing fields elsewhere (_sessionStateServiceinCompileController,CompileUseCase,CompilationExecutionService).✏️ Suggested rename
- private static UnityCliLoopEditorSessionStateService ServiceValue; + private static UnityCliLoopEditorSessionStateService s_service;(and update the two references below)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@Packages/src/Editor/Domain/UnityCliLoopEditorSessionStateFacade.cs` at line 15, Rename the private static backing field ServiceValue to follow the codebase’s _camelCase convention, matching patterns used in CompileController, CompileUseCase, and CompilationExecutionService. Update all references in UnityCliLoopEditorSessionStateFacade accordingly so the field declaration and its two usages stay consistent.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@Packages/src/Editor/Domain/UnityCliLoopEditorSessionStateFacade.cs`:
- Line 15: Rename the private static backing field ServiceValue to follow the
codebase’s _camelCase convention, matching patterns used in CompileController,
CompileUseCase, and CompilationExecutionService. Update all references in
UnityCliLoopEditorSessionStateFacade accordingly so the field declaration and
its two usages stay consistent.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 087b9a04-bfca-49ad-8c3d-5fa18ab51020
⛔ Files ignored due to path filters (2)
Assets/Editor/UnityCLILoop.Dev.asmdefis excluded by none and included by nonePackages/src/Editor/Domain/UnityCliLoopEditorSessionStateFacade.cs.metais excluded by none and included by none
📒 Files selected for processing (11)
Assets/Editor/CompileCheckWindow/CompileCheckerExample.csAssets/Editor/CompileCheckWindow/CompileEditorWindow.csPackages/src/Editor/CompositionRoot/UnityCliLoopApplicationRegistration.csPackages/src/Editor/Domain/UnityCliLoopEditorSessionStateFacade.csPackages/src/Editor/FirstPartyTools/Compile/CompilationExecutionService.csPackages/src/Editor/FirstPartyTools/Compile/CompileController.csPackages/src/Editor/FirstPartyTools/Compile/CompileTool.csPackages/src/Editor/FirstPartyTools/Compile/CompileUseCase.csPackages/src/Editor/Infrastructure/Api/CompileStatusBridgeCommand.csPackages/src/Editor/Infrastructure/Server/DomainReloadDetectionFileService.csPackages/src/Editor/Infrastructure/UnityCliLoopBridgeServer.cs
💤 Files with no reviewable changes (2)
- Packages/src/Editor/Infrastructure/Server/DomainReloadDetectionFileService.cs
- Packages/src/Editor/Infrastructure/UnityCliLoopBridgeServer.cs
|
Re: the |
Summary
User Impact
SessionState, so all instances always read the same data). The gain is structural: session state now has one owner, so future changes to its wiring happen in one place instead of five.Changes
UnityCliLoopEditorSessionStateFacade(Domain): exposes the composition-root-owned service to call sites that have no injection seam — static IPC bridge command handlers and tools instantiated viaActivator.CreateInstance. Follows the existing facade pattern (RegisterService+ServiceValue+ throw-if-unregistered accessor) enforced byStaticFacadeStateGuardTests. Placed in Domain because the compile tool and Infrastructure assemblies reference Domain but not Application.CompileTool→CompileUseCase→CompilationExecutionService→CompileController): the tool reads the facade once and threads the service down through constructors; the ad hoc constructions insideCompileUseCaseandCompileControllerare gone.CompileStatusBridgeCommand.Execute: reads the facade instead of newing a service per request.DomainReloadDetectionFileService,UnityCliLoopBridgeServer, andUnityCliLoopBridgeServerInstanceFactory(grep confirmed no callers; the composition root always used the injected overloads).Assets/Editornow pass the facade service explicitly (Dev asmdef gains a Domain reference).Verification
dist/darwin-arm64/uloop compile→ Success, 0 errors / 0 warningsuloop run-testsover compile/session-state/server-startup/facade-guard/onion-dependency suites → 122 tests, 119 passed; the 3 failures (MigratedFacadeFiles_WhenScanned_DoNotOwnMutableStaticState,EditorUiFiles_WhenLoaded_DoNotReferenceFacadeInternalsDirectly,SimulateMouseUiUseCase_WhenReturningAfterTimeout_UsesCapturedUnityObjectState) reproduce identically on a cleanorigin/v3-betacheckout and are unrelated to this changenew UnityCliLoopEditorSessionStateService(remains inPackages/srcoutside the composition root