Skip to content

chore: CLI pin reading now goes through an injectable boundary instead of static file IO - #1527

Merged
hatayama merged 2 commits into
v3-betafrom
refactor/c4-port-cli-pin-reader
Jul 5, 2026
Merged

hatayama merged 2 commits into
v3-betafrom
refactor/c4-port-cli-pin-reader

Conversation

@hatayama

@hatayama hatayama commented Jul 5, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • The CLI version pin (project-runner-pin.json) is now read through an ICliPinReader port implemented in Infrastructure, instead of static file IO calls inside the Application layer.

User Impact

  • No behavior change. Setup and installation checks read the same pin file with identical validation and error messages. This removes a hidden file-system dependency from the Application layer and makes pin-dependent flows testable without touching disk.

Changes

  • ICliPinReader declared in Application; CliPinReader static class retains only the pure BuildDispatcherReleaseTag helper
  • New CliPinReaderService in Infrastructure/CLI carries the IO, parsing, and validation logic unchanged
  • CliSetupApplicationService and CliInstallationDetector take the reader via constructor injection, wired in UnityCliLoopApplicationRegistration; CliInstallationDetector still resolves the pin on the caller thread before Task.Run
  • CliPinSynchronizer (the pin writer) is untouched; pin format and protocol version are unaffected

Verification

  • uloop compile: 0 errors, 0 warnings
  • uloop run-tests (CliPinReaderServiceTests, CliSetupApplicationServiceTests, CliInstallationDetectorTests, CliPathSetupFlowTests, OnionAssemblyDependencyTests, StaticFacadeStateGuardTests): 121/121 passed
  • New CliPinReaderServiceTests cover valid pin, missing file, empty file, and each missing-key branch with exact message assertions

Review in cubic

The Application layer performed File.ReadAllText and JObject.Parse
directly through static CliPinReader calls, hiding a file-system
dependency inside setup and installation-detection flows.

- Declare ICliPinReader in Application; the static class keeps only
  the pure BuildDispatcherReleaseTag helper
- Move the IO, parsing, and validation into Infrastructure's
  CliPinReaderService with identical semantics and error messages
- Inject the reader into CliSetupApplicationService and
  CliInstallationDetector, wired once in the composition root; the
  pin is still resolved on the caller thread before Task.Run
- Add CliPinReaderServiceTests covering the valid, missing-file,
  empty-file, and missing-key branches
@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: ef7095f3-6075-421f-8003-b245a8ab65bf

📥 Commits

Reviewing files that changed from the base of the PR and between 4fb966f and 70495e8.

⛔ Files ignored due to path filters (2)
  • Assets/Tests/Editor/CliPinReaderServiceTests.cs.meta is excluded by none and included by none
  • Packages/src/Editor/Infrastructure/CLI/CliPinReaderService.cs.meta is excluded by none and included by none
📒 Files selected for processing (8)
  • Assets/Tests/Editor/CliPathSetupFlowTests.cs
  • Assets/Tests/Editor/CliPinReaderServiceTests.cs
  • Assets/Tests/Editor/CliSetupApplicationServiceTests.cs
  • Packages/src/Editor/Application/CliPinReader.cs
  • Packages/src/Editor/Application/CliSetupApplicationService.cs
  • Packages/src/Editor/CompositionRoot/UnityCliLoopApplicationRegistration.cs
  • Packages/src/Editor/Infrastructure/CLI/CliInstallationDetector.cs
  • Packages/src/Editor/Infrastructure/CLI/CliPinReaderService.cs

📝 Walkthrough

Walkthrough

Introduces an ICliPinReader interface and CliPinReaderService implementation, replacing the static CliPinReader pin-loading logic. CliSetupApplicationService and CliInstallationDetector now receive ICliPinReader via constructor injection, wired through the composition root. Tests updated and new unit tests added for CliPinReaderService.

Changes

ICliPinReader dependency injection

Layer / File(s) Summary
Interface and static class reduction
Packages/src/Editor/Application/CliPinReader.cs
ICliPinReader interface added with LoadPackagePin and LoadMinimumDispatcherVersionOrThrow; CliPinReader reduced to only BuildDispatcherReleaseTag.
CliPinReaderService implementation
Packages/src/Editor/Infrastructure/CLI/CliPinReaderService.cs
New sealed service implements ICliPinReader, computes pin file path, parses/validates JSON, and returns structured success/failure results.
Consumer updates
Packages/src/Editor/Application/CliSetupApplicationService.cs, Packages/src/Editor/Infrastructure/CLI/CliInstallationDetector.cs
Both classes gain constructor parameters for ICliPinReader with null checks and use the injected instance instead of static calls.
Composition root wiring
Packages/src/Editor/CompositionRoot/UnityCliLoopApplicationRegistration.cs
A shared CliPinReaderService instance is constructed and passed into both CliInstallationDetector and CliSetupApplicationService.
Test updates and new tests
Assets/Tests/Editor/CliPathSetupFlowTests.cs, Assets/Tests/Editor/CliSetupApplicationServiceTests.cs, Assets/Tests/Editor/CliPinReaderServiceTests.cs
Existing tests updated to construct services with CliPinReaderService; new test fixture added covering valid, missing, empty, missing-key, and invalid JSON pin scenarios.

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

Sequence Diagram(s)

sequenceDiagram
  participant CliInstallationDetector
  participant CliPinReaderService
  participant FileSystem

  CliInstallationDetector->>CliPinReaderService: LoadMinimumDispatcherVersionOrThrow()
  CliPinReaderService->>FileSystem: read pin file at pinPath
  FileSystem-->>CliPinReaderService: file content
  CliPinReaderService->>CliPinReaderService: parse JSON, validate keys
  CliPinReaderService-->>CliInstallationDetector: minimumDispatcherVersion or throw
Loading

Possibly related PRs

  • hatayama/unity-cli-loop#1131: Both PRs modify CliInstallationDetector's shell-visibility flow and how it loads the minimum dispatcher version.
  • hatayama/unity-cli-loop#1503: Aligns with the new pin schema constrained to projectRunnerVersion and minimumDispatcherVersion.
  • hatayama/unity-cli-loop#1506: Supports the same refactor of sourcing dispatcher/project-runner requirements from the pin JSON via injected services.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main refactor from static pin file IO to an injectable CLI pin reader boundary.
Description check ✅ Passed The description matches the changeset and explains the refactor, wiring, behavior, and verification clearly.
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-port-cli-pin-reader

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.

2 issues found across 10 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread Packages/src/Editor/Infrastructure/CLI/CliPinReaderService.cs Outdated
Comment thread Assets/Tests/Editor/CliPinReaderServiceTests.cs
Address cubic review findings on the pin reader port: a corrupt pin
file now surfaces as a CliPinLoadResult failure instead of an
unhandled JsonReaderException, matching the JsonRpcProcessor pattern,
and test cleanup guards Directory.Delete so setup failures are not
masked by DirectoryNotFoundException. Adds a corrupt-JSON test.
@hatayama
hatayama merged commit 3cd2604 into v3-beta Jul 5, 2026
10 checks passed
@hatayama
hatayama deleted the refactor/c4-port-cli-pin-reader branch July 5, 2026 17:30
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