Skip to content

chore: Separate editor settings storage from domain values - #1581

Merged
hatayama merged 1 commit into
v3-betafrom
chore/c5-3-editor-settings-vo
Jul 7, 2026
Merged

hatayama merged 1 commit into
v3-betafrom
chore/c5-3-editor-settings-vo

Conversation

@hatayama

@hatayama hatayama commented Jul 7, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • Keep editor settings behavior and JSON storage shape unchanged while making the domain settings record immutable after construction.
  • Move Unity JsonUtility storage concerns into an infrastructure DTO.

User Impact

  • Existing UserSettings JSON remains compatible, including field names, order, and defaults.
  • No CLI or Unity Editor behavior changes are intended.

Changes

  • Convert UnityCliLoopEditorSettingsData from mutable serialized fields to lowercase init-only domain properties and remove [Serializable] from the domain value.
  • Add UnityCliLoopEditorSettingsJsonData in Infrastructure with the existing JSON fields, declaration order, and defaults, plus DTO/domain conversion methods.
  • Add an internal Domain IsExternalInit marker because Unity .NET profile does not provide the type required by init accessors.
  • Update recovery tests to serialize through the infrastructure DTO and pin JsonUtility explicit-null string materialization as string.Empty.

Review Notes

  • IUnityCliLoopEditorSettingsPort signatures are unchanged because the public type name and member names are preserved.
  • DTO-to-domain conversion does not normalize string values; observed string.Empty for explicit JSON null comes from Unity JsonUtility materialization.

Verification

  • dist/darwin-arm64/uloop compile --project-path "$(git rev-parse --show-toplevel)"
  • dist/darwin-arm64/uloop run-tests --project-path "$(git rev-parse --show-toplevel)" --test-mode EditMode --filter-type exact --filter-value "io.github.hatayama.UnityCliLoop.Tests.Editor.UnityCliLoopEditorSettingsRecoveryTests"
  • dist/darwin-arm64/uloop run-tests --project-path "$(git rev-parse --show-toplevel)" --test-mode EditMode --filter-type exact --filter-value "io.github.hatayama.UnityCliLoop.Tests.Editor.UnityCliLoopPackageRemovalSettingsResetterTests"
  • dist/darwin-arm64/uloop run-tests --project-path "$(git rev-parse --show-toplevel)" --test-mode EditMode --filter-type exact --filter-value "io.github.hatayama.UnityCliLoop.Tests.Editor.SetupWizardWindowTests"
  • dist/darwin-arm64/uloop run-tests --project-path "$(git rev-parse --show-toplevel)" --test-mode EditMode --filter-type exact --filter-value "io.github.hatayama.UnityCliLoop.Tests.Editor.OnionAssemblyDependencyTests"
  • dist/darwin-arm64/uloop run-tests --project-path "$(git rev-parse --show-toplevel)" --test-mode EditMode --filter-type exact --filter-value "io.github.hatayama.UnityCliLoop.Tests.Editor.UnityCliLoopSettingsWindowCliActionTests"

Review in cubic

Keep editor settings behavior and JSON shape unchanged while moving JsonUtility storage into an infrastructure DTO and making the domain settings record init-only.

Add the Unity IsExternalInit marker needed for init accessors in the Domain assembly.
@coderabbitai

coderabbitai Bot commented Jul 7, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Introduces a JSON DTO (UnityCliLoopEditorSettingsJsonData) to mediate between domain settings and serialized JSON, converts UnityCliLoopEditorSettingsData fields to init-only properties, adds an IsExternalInit compatibility shim, rewires the settings repository to use the DTO, and updates tests accordingly.

Changes

Settings JSON DTO Introduction

Layer / File(s) Summary
Init accessor support and domain model properties
Packages/src/Editor/Domain/IsExternalInit.cs, Packages/src/Editor/Domain/UnityCliLoopEditorSettingsData.cs
Adds an internal IsExternalInit marker class and converts UnityCliLoopEditorSettingsData fields to init-only properties, removing [Serializable].
JSON DTO and domain conversion
Packages/src/Editor/Infrastructure/Settings/UnityCliLoopEditorSettingsJsonData.cs
Adds UnityCliLoopEditorSettingsJsonData with ToDomain()/FromDomain(...) conversion methods, including a null guard throwing ArgumentNullException.
Repository wiring to use JSON DTO
Packages/src/Editor/Infrastructure/Settings/UnityCliLoopEditorSettingsRepository.cs
SaveSettings and LoadSettings now convert domain data through the new JSON DTO instead of serializing domain objects directly.
Assembly boundary test update
Assets/Tests/Editor/OnionAssemblyDependencyTests.cs
Renames and extends the onion architecture test to verify UnityCliLoopEditorSettingsJsonData belongs to the Infrastructure assembly.
Recovery/migration test updates via serialization helpers
Assets/Tests/Editor/UnityCliLoopEditorSettingsRecoveryTests.cs
Recovery and migration tests now write/read settings via new SerializeSettingsData/DeserializeSettingsJson helpers, and a null-field materialization test is added.

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

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant Repository as UnityCliLoopEditorSettingsRepository
  participant Dto as UnityCliLoopEditorSettingsJsonData
  participant JsonUtility

  Client->>Repository: SaveSettings(domainData)
  Repository->>Dto: FromDomain(domainData)
  Repository->>JsonUtility: ToJson(dto)
  Repository-->>Client: file written

  Client->>Repository: LoadSettings()
  Repository->>JsonUtility: FromJson<JsonData>(json)
  Repository->>Dto: ToDomain()
  Repository-->>Client: domainData
Loading

Possibly related PRs

  • hatayama/unity-cli-loop#1531: Shares the same editor-settings port/service test surface, touching UnityCliLoopEditorSettingsRecoveryTests and related assembly-dependency checks around settings persistence.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: separating editor settings storage from domain values.
Description check ✅ Passed The description matches the changeset and accurately describes the storage/domain split and test updates.
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 chore/c5-3-editor-settings-vo

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
Packages/src/Editor/Domain/IsExternalInit.cs (1)

1-7: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Standard init-accessor shim — LGTM.

This is the well-known workaround for init accessors on runtimes lacking the built-in IsExternalInit marker; declaring it internal in this assembly is sufficient for the Domain assembly's own use.

One thing worth keeping in mind going forward: because this type is internal, it is only visible within this assembly. If another assembly (e.g. Infrastructure or Application) later wants its own record/init properties, it will need its own copy of this shim (or a shared, referenced one) since internal types don't cross assembly boundaries.

🤖 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/IsExternalInit.cs` around lines 1 - 7, The
IsExternalInit shim is declared internal in the Domain assembly, so it will not
be available to other assemblies that may later use record or init accessors. If
cross-assembly support is intended, add the same shim to each consuming assembly
or move it into a shared referenced assembly; otherwise keep it as-is and ensure
only the Domain assembly relies on it. Reference the IsExternalInit type in
System.Runtime.CompilerServices when making the decision.
🤖 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/IsExternalInit.cs`:
- Around line 1-7: The IsExternalInit shim is declared internal in the Domain
assembly, so it will not be available to other assemblies that may later use
record or init accessors. If cross-assembly support is intended, add the same
shim to each consuming assembly or move it into a shared referenced assembly;
otherwise keep it as-is and ensure only the Domain assembly relies on it.
Reference the IsExternalInit type in System.Runtime.CompilerServices when making
the decision.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 66980509-da4c-40be-a05c-bcc0c30ca14f

📥 Commits

Reviewing files that changed from the base of the PR and between 97c3c78 and f38c027.

⛔ Files ignored due to path filters (2)
  • Packages/src/Editor/Domain/IsExternalInit.cs.meta is excluded by none and included by none
  • Packages/src/Editor/Infrastructure/Settings/UnityCliLoopEditorSettingsJsonData.cs.meta is excluded by none and included by none
📒 Files selected for processing (6)
  • Assets/Tests/Editor/OnionAssemblyDependencyTests.cs
  • Assets/Tests/Editor/UnityCliLoopEditorSettingsRecoveryTests.cs
  • Packages/src/Editor/Domain/IsExternalInit.cs
  • Packages/src/Editor/Domain/UnityCliLoopEditorSettingsData.cs
  • Packages/src/Editor/Infrastructure/Settings/UnityCliLoopEditorSettingsJsonData.cs
  • Packages/src/Editor/Infrastructure/Settings/UnityCliLoopEditorSettingsRepository.cs

@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.

1 issue found across 8 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="Packages/src/Editor/Infrastructure/Settings/UnityCliLoopEditorSettingsJsonData.cs">

<violation number="1" location="Packages/src/Editor/Infrastructure/Settings/UnityCliLoopEditorSettingsJsonData.cs:38">
P3: FromDomain is an internal method, so the ArgumentNullException throw after the Debug.Assert is redundant and adds unnecessary exception surface. The project convention for internal APIs is to enforce preconditions with Debug.Assert alone. Remove the `if (settings == null)` guard and let the assert serve as the contract check.</violation>
</file>

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

Re-trigger cubic

};
}

internal static UnityCliLoopEditorSettingsJsonData FromDomain(UnityCliLoopEditorSettingsData settings)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P3: FromDomain is an internal method, so the ArgumentNullException throw after the Debug.Assert is redundant and adds unnecessary exception surface. The project convention for internal APIs is to enforce preconditions with Debug.Assert alone. Remove the if (settings == null) guard and let the assert serve as the contract check.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At Packages/src/Editor/Infrastructure/Settings/UnityCliLoopEditorSettingsJsonData.cs, line 38:

<comment>FromDomain is an internal method, so the ArgumentNullException throw after the Debug.Assert is redundant and adds unnecessary exception surface. The project convention for internal APIs is to enforce preconditions with Debug.Assert alone. Remove the `if (settings == null)` guard and let the assert serve as the contract check.</comment>

<file context>
@@ -0,0 +1,60 @@
+            };
+        }
+
+        internal static UnityCliLoopEditorSettingsJsonData FromDomain(UnityCliLoopEditorSettingsData settings)
+        {
+            Debug.Assert(settings != null, "settings must not be null");
</file context>

@hatayama
hatayama merged commit b7e7970 into v3-beta Jul 7, 2026
10 checks passed
@hatayama
hatayama deleted the chore/c5-3-editor-settings-vo branch July 7, 2026 02:51
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