Skip to content

Add ConfigureJsonOptions and rename CrdtConfig to Harmony#87

Merged
hahn-kev merged 4 commits into
mainfrom
feature/crdt-config-tweaks
Jul 23, 2026
Merged

Add ConfigureJsonOptions and rename CrdtConfig to Harmony#87
hahn-kev merged 4 commits into
mainfrom
feature/crdt-config-tweaks

Conversation

@hahn-kev

@hahn-kev hahn-kev commented Jul 22, 2026

Copy link
Copy Markdown
Collaborator

Now clients don't need to do any weird workarounds to tweak json options. HarmonyConfig now exposes RegisteredChangeType for types so clients can easily get the change discriminator without hacking around using reflection and stuff.

Summary by CodeRabbit

  • New Features
    • Added a formal change-type registration system with string discriminators (including support for deletes).
    • Added ConfigureJsonOptions for polymorphic JSON behavior, with cumulative callbacks and a safe “frozen” enforcement.
    • Introduced object/adapters registration and projected-table adaptation capabilities for custom interfaces.
  • Refactor
    • Consolidated configuration under HarmonyConfig (replacing the prior configuration model) across database, repository, snapshots, and resources.
  • Tests
    • Expanded tests for change-type registration/discriminator expectations and JSON option configuration/freezing behavior.

hahn-kev and others added 3 commits July 22, 2026 16:27
Let clients register JSON customizations before options freeze, and expose change type discriminators alongside CLR types.

Co-authored-by: Cursor <cursoragent@cursor.com>
Replace JsonDerivedType with RegisteredChangeType and expose Types via IReadOnlyList to prevent external mutation.

Co-authored-by: Cursor <cursoragent@cursor.com>
Split builders into separate files under SIL.Harmony.Config and update all references.

Co-authored-by: Cursor <cursoragent@cursor.com>
@coderabbitai

coderabbitai Bot commented Jul 22, 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: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 93d72203-7f25-42ce-b989-3a9398807f86

📥 Commits

Reviewing files that changed from the base of the PR and between 0395eb8 and b5d96be.

📒 Files selected for processing (2)
  • src/SIL.Harmony/Config/ChangeTypeListBuilder.cs
  • src/SIL.Harmony/Config/ObjectTypeListBuilder.cs
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/SIL.Harmony/Config/ObjectTypeListBuilder.cs
  • src/SIL.Harmony/Config/ChangeTypeListBuilder.cs

📝 Walkthrough

Walkthrough

Changes

Harmony configuration modernization

Layer / File(s) Summary
Configuration contracts and frozen builders
src/SIL.Harmony/Config/ChangeTypeListBuilder.cs, src/SIL.Harmony/Config/HarmonyConfig.cs, src/SIL.Harmony/Config/JsonOptionsBuilder.cs
Introduces registered change-type metadata, frozen JSON option configuration, and the HarmonyConfig API.
Object adapter registration and model finalization
src/SIL.Harmony/Config/ObjectTypeListBuilder.cs, src/SIL.Harmony/Adapters/*
Adds frozen object-adapter registration, runtime adaptation, and projected-table model configuration.
Runtime configuration dependency migration
src/SIL.Harmony/CrdtKernel.cs, src/SIL.Harmony/DataModel.cs, src/SIL.Harmony/Db/*, src/SIL.Harmony/ResourceService.cs, src/SIL.Harmony/SnapshotWorker.cs, src/SIL.Harmony/Changes/*, src/SIL.Harmony.Sample/SampleDbContext.cs
Replaces CrdtConfig with HarmonyConfig across DI wiring, persistence, snapshots, resources, changes, and the sample context.
Configuration migration tests and integration updates
src/SIL.Harmony.Tests/ConfigTests.cs, src/SIL.Harmony.Tests/Adapter/CustomObjectAdapterTests.cs, src/SIL.Harmony.Tests/DataModelTestBase.cs, src/SIL.Harmony.Tests/PersistExtraDataTests.cs
Updates test configuration and verifies change registrations and JSON option lifecycle behavior.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Application
  participant CrdtKernel
  participant HarmonyConfig
  participant JsonOptionsBuilder
  participant DataModel
  Application->>CrdtKernel: register Harmony services
  CrdtKernel->>HarmonyConfig: apply configuration delegate
  HarmonyConfig->>JsonOptionsBuilder: queue JSON option callbacks
  CrdtKernel->>DataModel: resolve IOptions<HarmonyConfig>
  JsonOptionsBuilder-->>CrdtKernel: apply options and freeze
Loading
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.69% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly captures the main changes: adding ConfigureJsonOptions and renaming CrdtConfig to HarmonyConfig.
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 feature/crdt-config-tweaks

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)
src/SIL.Harmony/Config/ChangeTypeListBuilder.cs (1)

28-34: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Add validation for duplicate discriminators.

Add<TDerived> only dedupes by Type (Line 31), not by Discriminator. If two different change types resolve to the same TypeName, both get registered, and the collision only surfaces later as a generic Dictionary.Add duplicate-key ArgumentException in HarmonyConfig.BuildChangeDiscriminatorMaps, with no indication of which types collided. The prior explicit discriminator-type validation was reportedly removed in this refactor — worth restoring with a clearer error at registration time.

💡 Proposed fix
 public ChangeTypeListBuilder Add<TDerived>() where TDerived : IChange, IPolyType
 {
     CheckFrozen();
     if (_types.Any(t => t.Type == typeof(TDerived))) return this;
-    _types.Add(new RegisteredChangeType(typeof(TDerived), TDerived.TypeName));
+    var discriminator = TDerived.TypeName;
+    if (_types.Any(t => t.Discriminator == discriminator))
+        throw new InvalidOperationException(
+            $"A change type with discriminator '{discriminator}' has already been registered.");
+    _types.Add(new RegisteredChangeType(typeof(TDerived), discriminator));
     return this;
 }
🤖 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 `@src/SIL.Harmony/Config/ChangeTypeListBuilder.cs` around lines 28 - 34, Update
ChangeTypeListBuilder.Add<TDerived> to validate TDerived.TypeName against
existing RegisteredChangeType entries before adding; retain the existing
type-based deduplication, but throw a clear error identifying both conflicting
change types when a discriminator collision is found, so
HarmonyConfig.BuildChangeDiscriminatorMaps is not reached with duplicate
discriminators.
🤖 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 `@src/SIL.Harmony/Config/ChangeTypeListBuilder.cs`:
- Around line 28-34: Update ChangeTypeListBuilder.Add<TDerived> to validate
TDerived.TypeName against existing RegisteredChangeType entries before adding;
retain the existing type-based deduplication, but throw a clear error
identifying both conflicting change types when a discriminator collision is
found, so HarmonyConfig.BuildChangeDiscriminatorMaps is not reached with
duplicate discriminators.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 4ca1bb35-abbc-48ab-9fb6-91e3b3e80ffc

📥 Commits

Reviewing files that changed from the base of the PR and between aae2ee0 and 0395eb8.

📒 Files selected for processing (20)
  • src/SIL.Harmony.Sample/SampleDbContext.cs
  • src/SIL.Harmony.Tests/Adapter/CustomObjectAdapterTests.cs
  • src/SIL.Harmony.Tests/ConfigTests.cs
  • src/SIL.Harmony.Tests/DataModelTestBase.cs
  • src/SIL.Harmony.Tests/PersistExtraDataTests.cs
  • src/SIL.Harmony/Adapters/CustomAdapterProvider.cs
  • src/SIL.Harmony/Adapters/DefaultAdapterProvider.cs
  • src/SIL.Harmony/Changes/Change.cs
  • src/SIL.Harmony/Changes/ChangeContext.cs
  • src/SIL.Harmony/Changes/PeekThenConcreteChangeConverter.cs
  • src/SIL.Harmony/Config/ChangeTypeListBuilder.cs
  • src/SIL.Harmony/Config/HarmonyConfig.cs
  • src/SIL.Harmony/Config/JsonOptionsBuilder.cs
  • src/SIL.Harmony/Config/ObjectTypeListBuilder.cs
  • src/SIL.Harmony/CrdtKernel.cs
  • src/SIL.Harmony/DataModel.cs
  • src/SIL.Harmony/Db/CrdtDbContextOptionsExtensions.cs
  • src/SIL.Harmony/Db/CrdtRepository.cs
  • src/SIL.Harmony/ResourceService.cs
  • src/SIL.Harmony/SnapshotWorker.cs

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

I think the Freeze methods should both be internal. I didn't check what they were before.
But everything looks good 👍

Comment thread src/SIL.Harmony/Config/ChangeTypeListBuilder.cs Outdated
Comment thread src/SIL.Harmony/Config/ObjectTypeListBuilder.cs Outdated
Co-authored-by: Tim Haasdyk <myieye@gmail.com>
@hahn-kev
hahn-kev merged commit c858cb4 into main Jul 23, 2026
7 checks passed
@hahn-kev
hahn-kev deleted the feature/crdt-config-tweaks branch July 23, 2026 02:10
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.

2 participants