Skip to content

Commit b66e33b

Browse files
myieyermunn
authored andcommitted
Remove CreateMorphType and DeleteMorphType from MiniLcm API (#2221)
1 parent 4a19f9a commit b66e33b

12 files changed

Lines changed: 42 additions & 142 deletions

File tree

backend/FwLite/FwDataMiniLcmBridge/Api/FwDataMiniLcmApi.cs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -581,12 +581,6 @@ internal MorphType FromLcmMorphType(IMoMorphType morphType)
581581
};
582582
}
583583

584-
public Task<MorphType> CreateMorphType(MorphType morphType)
585-
{
586-
// Creating new morph types not allowed in FwData projects, so silently ignore operation
587-
return Task.FromResult(morphType);
588-
}
589-
590584
public Task<MorphType> UpdateMorphType(Guid id, UpdateObjectInput<MorphType> update)
591585
{
592586
var lcmMorphType = MorphTypeRepository.GetObject(id);
@@ -608,12 +602,6 @@ public async Task<MorphType> UpdateMorphType(MorphType before, MorphType after,
608602
return await GetMorphType(after.Id) ?? throw new NullReferenceException("unable to find morph type with id " + after.Id);
609603
}
610604

611-
public Task DeleteMorphType(Guid id)
612-
{
613-
// Deleting morph types not allowed in FwData projects, so silently ignore operation
614-
return Task.CompletedTask;
615-
}
616-
617605
public IAsyncEnumerable<VariantType> GetVariantTypes()
618606
{
619607
return VariantTypes.PossibilitiesOS

backend/FwLite/FwLiteProjectSync.Tests/Import/ResumableTests.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -189,11 +189,6 @@ Task<ComplexFormType> IMiniLcmWriteApi.CreateComplexFormType(ComplexFormType com
189189
ResumableTests.MaybeThrowRandom(random, 0.2);
190190
return _api.CreateComplexFormType(complexFormType);
191191
}
192-
Task<MorphType> IMiniLcmWriteApi.CreateMorphType(MorphType morphType)
193-
{
194-
ResumableTests.MaybeThrowRandom(random, 0.02);
195-
return _api.CreateMorphType(morphType);
196-
}
197192
Task<SemanticDomain> IMiniLcmWriteApi.CreateSemanticDomain(SemanticDomain semanticDomain)
198193
{
199194
ResumableTests.MaybeThrowRandom(random, 0.2);

backend/FwLite/FwLiteProjectSync.Tests/SyncTestHelpers.cs

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,9 @@
1-
using FwDataMiniLcmBridge.Api;
21
using MiniLcm.Models;
32

43
namespace FwLiteProjectSync.Tests;
54

65
public static class SyncTestHelpers
76
{
8-
public static MorphType CreateMorphType(MorphTypeKind kind, string? prefix = null, string? postfix = null, int secondaryOrder = 0)
9-
{
10-
var guid = LcmHelpers.ToLcmMorphTypeId(kind) ?? Guid.NewGuid();
11-
var name = $"Test {kind}";
12-
var abbr = $"Tst {kind}";
13-
var desc = $"Test morph type {kind}";
14-
return new MorphType
15-
{
16-
Id = guid,
17-
Kind = kind,
18-
Name = new MultiString() { { "en", name } },
19-
Abbreviation = new MultiString() { { "en", abbr } },
20-
Description = new RichMultiString() { { "en", new RichString(desc) } },
21-
Prefix = prefix,
22-
Postfix = postfix,
23-
SecondaryOrder = secondaryOrder,
24-
};
25-
}
26-
277
public static MorphType UpdateMorphType(MorphType orig, string? newName = null, string? newAbbreviation = null)
288
{
299
var newby = orig.Copy();

backend/FwLite/FwLiteProjectSync.Tests/SyncTests.cs

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -505,51 +505,6 @@ public async Task MorphTypeUpdatesSyncBothWays()
505505
fwdataStemAfterSync.Abbreviation["en"].Should().Be(newAbbr);
506506
}
507507

508-
[Fact]
509-
[Trait("Category", "Integration")]
510-
public async Task MorphTypeCreationDoesNotSyncCrdtToFw()
511-
{
512-
// FwDataMiniLcmApi.CreateMorphType is a no-op because FLEx forbids morph type creation or deletion
513-
var crdtApi = _fixture.CrdtApi;
514-
var fwdataApi = _fixture.FwDataApi;
515-
await _syncService.Import(crdtApi, fwdataApi);
516-
var projectSnapshot = await _fixture.RegenerateAndGetSnapshot();
517-
518-
var newMorphType = SyncTestHelpers.CreateMorphType(MorphTypeKind.Unknown, prefix: "!", postfix: "!");
519-
await crdtApi.CreateMorphType(newMorphType);
520-
var syncResult = await _syncService.Sync(crdtApi, fwdataApi, projectSnapshot);
521-
522-
var fwdataMorphTypes = await fwdataApi.GetMorphTypes().ToArrayAsync();
523-
var crdtMorphTypes = await crdtApi.GetMorphTypes().ToArrayAsync();
524-
crdtMorphTypes.Should().ContainEquivalentOf(newMorphType);
525-
fwdataMorphTypes.Should().NotContainEquivalentOf(newMorphType);
526-
crdtMorphTypes.Length.Should().Be(fwdataMorphTypes.Length + 1);
527-
crdtMorphTypes.Where(m => m.Kind != MorphTypeKind.Unknown).Should().BeEquivalentTo(fwdataMorphTypes);
528-
}
529-
530-
[Fact]
531-
[Trait("Category", "Integration")]
532-
public async Task MorphTypeDeletionDoesNotSyncCrdtToFw()
533-
{
534-
// FwDataMiniLcmApi.DeleteMorphType is a no-op because FLEx forbids morph type creation or deletion
535-
var crdtApi = _fixture.CrdtApi;
536-
var fwdataApi = _fixture.FwDataApi;
537-
await _syncService.Import(crdtApi, fwdataApi);
538-
var projectSnapshot = await _fixture.RegenerateAndGetSnapshot();
539-
540-
var prefixingInterfix = await crdtApi.GetMorphType(MorphTypeKind.PrefixingInterfix);
541-
prefixingInterfix.Should().NotBeNull();
542-
await crdtApi.DeleteMorphType(prefixingInterfix.Id);
543-
var syncResult = await _syncService.Sync(crdtApi, fwdataApi, projectSnapshot);
544-
545-
var fwdataMorphTypes = await fwdataApi.GetMorphTypes().ToArrayAsync();
546-
var crdtMorphTypes = await crdtApi.GetMorphTypes().ToArrayAsync();
547-
fwdataMorphTypes.Should().ContainEquivalentOf(prefixingInterfix);
548-
crdtMorphTypes.Should().NotContainEquivalentOf(prefixingInterfix);
549-
crdtMorphTypes.Length.Should().Be(fwdataMorphTypes.Length - 1);
550-
crdtMorphTypes.Should().BeEquivalentTo(fwdataMorphTypes.Where(m => m.Kind != MorphTypeKind.PrefixingInterfix));
551-
}
552-
553508
[Fact]
554509
[Trait("Category", "Integration")]
555510
public async Task UpdatingAnEntryInEachProjectSyncsAcrossBoth()

backend/FwLite/FwLiteProjectSync/DryRunMiniLcmApi.cs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,6 @@ public Task DeleteComplexFormType(Guid id)
126126
return Task.CompletedTask;
127127
}
128128

129-
public Task<MorphType> CreateMorphType(MorphType morphType)
130-
{
131-
DryRunRecords.Add(new DryRunRecord(nameof(CreateMorphType),
132-
$"Create morph type {morphType.Name}"));
133-
return Task.FromResult(morphType);
134-
}
135-
136129
public async Task<MorphType> UpdateMorphType(Guid id, UpdateObjectInput<MorphType> update)
137130
{
138131
DryRunRecords.Add(new DryRunRecord(nameof(UpdateMorphType), $"Update morph type {id}"));
@@ -145,12 +138,6 @@ public Task<MorphType> UpdateMorphType(MorphType before, MorphType after, IMiniL
145138
return Task.FromResult(after);
146139
}
147140

148-
public Task DeleteMorphType(Guid id)
149-
{
150-
DryRunRecords.Add(new DryRunRecord(nameof(DeleteMorphType), $"Delete morph type {id}"));
151-
return Task.CompletedTask;
152-
}
153-
154141
public Task<Entry> CreateEntry(Entry entry, CreateEntryOptions? options)
155142
{
156143
options ??= new CreateEntryOptions();

backend/FwLite/FwLiteProjectSync/Import/ResumableImportApi.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,6 @@ async Task<ComplexFormType> IMiniLcmWriteApi.CreateComplexFormType(ComplexFormTy
5858
{
5959
return await HasCreated(complexFormType, _api.GetComplexFormTypes(), () => _api.CreateComplexFormType(complexFormType));
6060
}
61-
async Task<MorphType> IMiniLcmWriteApi.CreateMorphType(MorphType morphType)
62-
{
63-
return await HasCreated(morphType, _api.GetMorphTypes(), () => _api.CreateMorphType(morphType), m => m.Kind.ToString());
64-
}
6561
async Task<SemanticDomain> IMiniLcmWriteApi.CreateSemanticDomain(SemanticDomain semanticDomain)
6662
{
6763
return await HasCreated(semanticDomain, _api.GetSemanticDomains(), () => _api.CreateSemanticDomain(semanticDomain));

backend/FwLite/FwLiteWeb/Hubs/CrdtMiniLcmApiHub.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,6 @@ public override IAsyncEnumerable<Entry> SearchEntries(string query, QueryOptions
9999
return base.SearchEntries(query, options);
100100
}
101101

102-
public override async Task<MorphType> CreateMorphType(MorphType morphType)
103-
{
104-
var newMorphType = await base.CreateMorphType(morphType);
105-
TriggerSync();
106-
return newMorphType;
107-
}
108-
109102
public override async Task<MorphType> UpdateMorphType(Guid id, JsonPatchDocument<MorphType> update)
110103
{
111104
var updatedMorphType = await base.UpdateMorphType(id, update);

backend/FwLite/FwLiteWeb/Hubs/MiniLcmApiHubBase.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,6 @@ public IAsyncEnumerable<ComplexFormType> GetComplexFormTypes()
4747
return _miniLcmApi.GetComplexFormTypes();
4848
}
4949

50-
public virtual async Task<MorphType> CreateMorphType(MorphType morphType)
51-
{
52-
var newMorphType = await _miniLcmApi.CreateMorphType(morphType);
53-
return newMorphType;
54-
}
55-
5650
public virtual async Task<MorphType> UpdateMorphType(Guid id, JsonPatchDocument<MorphType> update)
5751
{
5852
var updatedMorphType = await _miniLcmApi.UpdateMorphType(id, new UpdateObjectInput<MorphType>(update));

backend/FwLite/LcmCrdt/CrdtMiniLcmApi.cs

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -370,23 +370,6 @@ public async IAsyncEnumerable<MorphType> GetMorphTypes()
370370
return await repo.MorphTypes.SingleOrDefaultAsync(m => m.Kind == kind);
371371
}
372372

373-
public async Task<MorphType> CreateMorphType(MorphType morphType)
374-
{
375-
await using var repo = await repoFactory.CreateRepoAsync();
376-
377-
// Duplicate MorphTypes (by kind) are not allowed
378-
// Note: can't put this in validation wrapper since we need a repo
379-
var exists = await repo.MorphTypes.AnyAsync(m => m.Kind == morphType.Kind);
380-
if (exists) throw new DuplicateObjectException($"Morph type {morphType.Kind} already exists");
381-
382-
await AddChange(new CreateMorphTypeChange(morphType));
383-
// MorphTypeKind value must be unique in DB, so return by MorphType rather than Id in case a race condition
384-
// ended up causing two CreateMorphType calls to happen at the same time. It's possible that the other
385-
// call went through, creating a MorphType entry with a different GUID but the same Kind (which would
386-
// violate the constraint). So we fetch by Kind rather than by Id here to mitigate that rare case.
387-
return await repo.MorphTypes.SingleAsync(c => c.Kind == morphType.Kind);
388-
}
389-
390373
public async Task<MorphType> UpdateMorphType(Guid id, UpdateObjectInput<MorphType> update)
391374
{
392375
await AddChange(new JsonPatchChange<MorphType>(id, update.Patch));
@@ -399,11 +382,6 @@ public async Task<MorphType> UpdateMorphType(MorphType before, MorphType after,
399382
return await GetMorphType(after.Id) ?? throw NotFoundException.ForType<MorphType>(after.Id);
400383
}
401384

402-
public async Task DeleteMorphType(Guid id)
403-
{
404-
await AddChange(new DeleteChange<MorphType>(id));
405-
}
406-
407385
public async Task<int> CountEntries(string? query = null, FilterQueryOptions? options = null)
408386
{
409387
await using var repo = await repoFactory.CreateRepoAsync();
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using MiniLcm.SyncHelpers;
2+
3+
namespace MiniLcm.Tests;
4+
5+
public class MorphTypeSyncTests
6+
{
7+
[Fact]
8+
public async Task Sync_ThrowsOnAdd_WhenAfterContainsExtraMorphType()
9+
{
10+
var before = CanonicalMorphTypes.All.Values.ToArray();
11+
var extraMorphType = new MorphType
12+
{
13+
Id = Guid.NewGuid(),
14+
Kind = MorphTypeKind.Unknown,
15+
Name = new MultiString { { "en", "bogus" } },
16+
};
17+
var after = before.Append(extraMorphType).ToArray();
18+
19+
var act = () => MorphTypeSync.Sync(before, after, null!);
20+
21+
await act.Should().ThrowAsync<InvalidOperationException>()
22+
.WithMessage("*cannot be created*");
23+
}
24+
25+
[Fact]
26+
public async Task Sync_ThrowsOnRemove_WhenAfterIsMissingMorphType()
27+
{
28+
var before = CanonicalMorphTypes.All.Values.ToArray();
29+
var after = before.Skip(1).ToArray(); // drop one
30+
31+
var act = () => MorphTypeSync.Sync(before, after, null!);
32+
33+
await act.Should().ThrowAsync<InvalidOperationException>()
34+
.WithMessage("*cannot be deleted*");
35+
}
36+
}

0 commit comments

Comments
 (0)