Use random commit id when migrating to add morph types#2344
Conversation
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
📝 WalkthroughWalkthroughThis PR fixes a regression where projects downloaded from Lexbox fail with commit ID conflicts. The fix separates morphtype seeding into deterministic (project creation) and non-deterministic (migration) paths, updates test infrastructure to support fixed project IDs for regression testing, and adds debug utilities for CRDT project creation. ChangesMorphtype Seeding Determinism Fix
Debug Utilities Enhancement
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
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 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 |
C# FwHeadless Unit Tests48 tests 48 ✅ 17s ⏱️ Results for commit 8de8c07. ♻️ This comment has been updated with latest results. |
UI unit Tests 1 files 62 suites 30s ⏱️ Results for commit 8de8c07. ♻️ 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.
Actionable comments posted: 4
🤖 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.
Inline comments:
In `@backend/FwLite/LcmCrdt.Tests/Data/DownloadProjectTests.cs`:
- Around line 12-13: The test currently syncs remote state into an empty local
DB because MiniLcmApiFixture.InitializeAsync() no longer seeds morph types;
update the test to seed the local side before calling SyncWith(remoteModel) by
invoking the same creation/download path the app uses or explicitly creating the
deterministic morph-type seed commit on the fixture (e.g., call the project
creation/download helper or a new
MiniLcmApiFixture.SeedDeterministicMorphTypes()/CreateDeterministicMorphTypeSeedCommit()
helper) so the local project contains the deterministic seed commit prior to
synchronization.
In `@backend/FwLite/LcmCrdt.Tests/Data/RegressionTestHelper.cs`:
- Around line 41-42: The helper currently calls
projectsService.SetupProjectContext(crdtProject) reusing the same Project.DbPath
so CurrentProjectService's static MigrationTasks (keyed by Project.DbPath) skips
migrations; fix by ensuring each test initialization uses a unique sqlite path
or clears the memoized entry before setup: either generate a unique db file name
for crdtProject (e.g., append a GUID/timestamp) so SetupProjectContext runs
migrations/seeding against a fresh path, or explicitly remove the MigrationTasks
entry keyed by crdtProject.DbPath from CurrentProjectService before calling
SetupProjectContext so migrations are not skipped.
In `@backend/FwLite/LcmDebugger/FakeSyncSource.cs`:
- Line 53: The File.OpenRead(path) stream passed into JsonSerializer.Deserialize
in FakeSyncSource.cs is never disposed (variable changes), which can leak file
handles; fix by creating and disposing the stream explicitly (e.g., using/using
var for the File.OpenRead(path) stream) before calling
JsonSerializer.Deserialize, or alternatively read the file into a string with
File.ReadAllText and deserialize that, ensuring the stream is closed; update the
code around the changes assignment in the FakeSyncSource class to use one of
these approaches.
In `@backend/FwLite/LcmDebugger/Utils.cs`:
- Around line 55-56: The code returns crdtMiniLcmApi even when
DataModel.SyncWith may fail; update the caller to verify sync success before
returning by either awaiting SyncWith and checking its boolean/result (if it
returns a status) or wrapping the await in a try/catch and rethrowing or
returning a failure indicator when sync fails; specifically modify the block
that calls services.GetRequiredService<DataModel>().SyncWith(syncable) so that
DataModel.SyncWith failures are detected and handled (e.g., throw a descriptive
InvalidOperationException or return null/error) and only return crdtMiniLcmApi
when the sync completed successfully.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 9b3d23df-6ea7-4a46-8a8c-5af05f4d7b58
📒 Files selected for processing (9)
backend/FwLite/LcmCrdt.Tests/Data/DownloadProjectTests.csbackend/FwLite/LcmCrdt.Tests/Data/RegressionTestHelper.csbackend/FwLite/LcmCrdt.Tests/MiniLcmApiFixture.csbackend/FwLite/LcmCrdt/Changes/CreateMorphTypeChange.csbackend/FwLite/LcmCrdt/CrdtProjectsService.csbackend/FwLite/LcmCrdt/CurrentProjectService.csbackend/FwLite/LcmCrdt/Objects/PreDefinedData.csbackend/FwLite/LcmDebugger/FakeSyncSource.csbackend/FwLite/LcmDebugger/Utils.cs
…t time of project creation
…n seeding. Modify CreateMorphTypeChange to handle creating the same morph type multiple times due to migrations.
b334094 to
d4db943
Compare
|
I thought this PR would start actually just importing morph-types from fwdata, but I confused some of our fwheadless import code with our client-side "import local FieldWorks classic project" code. It would be non-trivial to stop seeding the predefined morph-types commit in fw-headless, because fw-headless uses our standard "open/migrate project" code. I think we should leave that until we pull out the morph-types data migration. Then we could/should easily standardize the morph-type import code to use the same pattern as other entities (instead of I've created the follow up clean-up issue: #2350 and added code comments referencing that issue. |
Fixes #2343
Using deterministic commit IDs during migrations causes problems resulting in commits not ending up in the same order between clients after a sync. This PR changes how we generate commit IDs for the migration which adds morph types, and fixes the CreateMorphTypeChange to be fine with attempting to create an morph type which already exists.