Discover Copy()-test types by reflection instead of CRDT registration#2326
Discover Copy()-test types by reflection instead of CRDT registration#2326myieye wants to merge 2 commits into
Conversation
EntityCopyMethodTests drove its theory from crdtConfig.ObjectTypes, the CRDT sync registration. That lists only root entities, so owned types that define their own Copy() (Translation, ViewField, ViewWritingSystem, RichString, RichMultiString, RichSpan) never appeared as direct rows — they were only covered transitively via their owners, and a new model could be forgotten entirely. Enumerate every concrete type in the MiniLcm assembly that declares a parameterless Copy() instead, so coverage tracks the Copy() contract itself and can't drift from a hand-maintained list. Drops the RemoteResource exclusion (it's in the SIL.Harmony assembly, so scanning the MiniLcm assembly excludes it naturally). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
📝 WalkthroughWalkthroughThis PR refactors entity copy validation testing in ChangesEntity Copy Method Test Refactoring
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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 |
UI unit Tests 1 files 59 suites 30s ⏱️ Results for commit 985d58a. ♻️ This comment has been updated with latest results. |
|
The latest updates on your projects. Learn more about Argos notifications ↗︎
|
There was a problem hiding this comment.
🧹 Nitpick comments (1)
backend/FwLite/LcmCrdt.Tests/EntityCopyMethodTests.cs (1)
19-26: ⚡ Quick winTighten discovery to declared
Copy()implementations.Line 20 / Line 26 currently match any visible public parameterless
Copy, including inherited methods. That makes the test set broader than the stated "types that declare their ownCopy()" contract and can pull in future classes whoseCopy()is inherited or shaped differently.Suggested change
public static IEnumerable<object[]> GetEntityTypes() { return typeof(IObjectWithId).Assembly.GetTypes() .Where(t => t is { IsClass: true, IsAbstract: false } && CopyMethod(t) is not null) .Select(t => new object[] { t }); } private static MethodInfo? CopyMethod(Type type) { - return type.GetMethod("Copy", BindingFlags.Public | BindingFlags.Instance, binder: null, Type.EmptyTypes, modifiers: null); + var method = type.GetMethod( + "Copy", + BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly, + binder: null, + Type.EmptyTypes, + modifiers: null); + + return method?.ReturnType == type ? method : null; }🤖 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 `@backend/FwLite/LcmCrdt.Tests/EntityCopyMethodTests.cs` around lines 19 - 26, The discovery currently picks up inherited public parameterless Copy() methods; update the CopyMethod(Type type) so it only returns a Copy declared on the type itself (e.g., use BindingFlags.DeclaredOnly together with BindingFlags.Public | BindingFlags.Instance when calling GetMethod, or alternatively locate parameterless methods named "Copy" and ensure method.DeclaringType == type) so only types that declare their own Copy() are included by the test.
🤖 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 `@backend/FwLite/LcmCrdt.Tests/EntityCopyMethodTests.cs`:
- Around line 19-26: The discovery currently picks up inherited public
parameterless Copy() methods; update the CopyMethod(Type type) so it only
returns a Copy declared on the type itself (e.g., use BindingFlags.DeclaredOnly
together with BindingFlags.Public | BindingFlags.Instance when calling
GetMethod, or alternatively locate parameterless methods named "Copy" and ensure
method.DeclaringType == type) so only types that declare their own Copy() are
included by the test.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 9edc9692-a92e-48e3-9af2-bb33e80412e5
📒 Files selected for processing (1)
backend/FwLite/LcmCrdt.Tests/EntityCopyMethodTests.cs
Without BindingFlags.DeclaredOnly the reflection scan also matched types that only inherit Copy(), notably the private RichStringPrimitive helper nested in RichString's JSON converter, which AutoFaker can't construct. DeclaredOnly keeps the 17 types that define their own Copy() and drops inherit-only subclasses. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
Closing — this adds no real coverage over develop's existing test.
The reflection-based discovery here only converts transitive coverage into direct rows, at the cost of extra machinery and a |
EntityCopyMethodTestsdrove its theory fromcrdtConfig.ObjectTypes(the CRDT sync registration), which lists only root entities. Owned types that define their ownCopy()—Translation,ViewField,ViewWritingSystem,MultiString,RichMultiString,RichString,RichSpan— were therefore only covered transitively (via their owners), and a brand-new model could be left off entirely.This switches discovery to reflection over the MiniLcm assembly for any concrete type that declares a parameterless
Copy()(DeclaredOnly, so inherit-only subclasses such as the privateRichStringPrimitiveJSON-converter helper are excluded). Coverage now tracks theCopy()contract itself rather than a registration list that can drift. The row count goes 11 → 18, with the owned types now verified as direct, named cases.Split out of #2322, whose doc comment already points at this test.
🤖 Generated with Claude Code