Public Access
Give the two logs and the buckets a resource type, so a conflict can be written
AadResourceTypes.For maps a syncable type onto the AAD resource type its cache records bind to, and it had no arm for ConnectionLogEntry, ActivityLogEntry or ObjectStore. All three are on both enums, in the reconciler registry and in the cipher pinning; only this switch was missed, and it throws rather than falling back — so a merge conflict on a connection log, an activity log or a bucket raised ArgumentOutOfRangeException on the path that records what the merge discarded. The conflict log is the whole reason the merge is allowed to pick a winner, so the one item kind whose conflicts could not be recorded was a bucket: an editable item two machines can genuinely disagree about. Worth writing down why it lasted two phases. Of the three callers, ItemStore and OutboxStore reach the mapping only when an item carries plaintext fields, and none of these three kinds does — so they never touched the gap. ConflictStore calls it unconditionally, but a test only reaches that by causing a real merge conflict, and every existing one raised its conflict against a Host. Three arms missing, and no path in the suite crossed any of them. So the tests are the point of this commit as much as the arms are. The guard is AadResourceTypeTests.EverySyncableType_HasAnArmInTheStorageMapping: it walks the whole wire enum, and for each type asserts both that there is an arm and that the arm returns the same-named resource type, which is the mistake the file's cipher half already guards against on the server side. Written over the full enum rather than over ItemKinds.SyncedTypes, because that is the stronger claim and the one the switch really makes — the two reserved association types have arms too. Beside it, CacheStoreTests.AConflict_CanBeRecordedForEveryKindOfItem records a conflict per kind and reads the detail back, since an arm returning the wrong resource type seals under one AAD and opens under another, which surfaces as an empty detail rather than as a throw. Both were confirmed to fail with the arms removed: the theory fails on exactly ConnectionLogEntry, ActivityLogEntry and ObjectStore and passes on the other three, and the guard names those three and no others. The note in docs/adding-hosts-on-the-phone.md that recorded this as out of scope is marked fixed, with what let it survive, since that is the part worth knowing next time an item kind is added. 1529 tests pass, seven of them new.
This commit is contained in:
@@ -394,6 +394,49 @@ public sealed class CacheStoreTests : IAsyncLifetime
|
||||
all.Detail.ShouldBe(new byte[] { 1, 2, 3 });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A conflict can be recorded against any kind of item, not only the kinds that were here first.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
/// Every other test in this section uses <see cref="SyncEntityType.Host"/>, and that is how three item
|
||||
/// kinds shipped with no way to record a conflict at all: the two logs and the buckets were added to both
|
||||
/// enums, to the reconciler registry and to the cipher pinning, while <c>AadResourceTypes.For</c> — which
|
||||
/// <c>ConflictStore.RecordAsync</c> calls unconditionally — kept throwing for them. The two other callers
|
||||
/// of that mapping only reach it when an item carries plaintext fields, which none of the three does, so
|
||||
/// nothing else so much as touched the gap.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// A theory over the types rather than one more <c>Host</c> case, because the failure was never about
|
||||
/// conflicts and always about which types the layer below had been taught. Recording is asserted through
|
||||
/// a read-back rather than by "it did not throw": an arm returning the wrong resource type would seal
|
||||
/// under one AAD and open under another, which is a null detail rather than an exception.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
[Theory]
|
||||
[InlineData(SyncEntityType.Host)]
|
||||
[InlineData(SyncEntityType.HostGroup)]
|
||||
[InlineData(SyncEntityType.Snippet)]
|
||||
[InlineData(SyncEntityType.ConnectionLogEntry)]
|
||||
[InlineData(SyncEntityType.ActivityLogEntry)]
|
||||
[InlineData(SyncEntityType.ObjectStore)]
|
||||
public async Task AConflict_CanBeRecordedForEveryKindOfItem(SyncEntityType entityType)
|
||||
{
|
||||
var detail = System.Text.Encoding.UTF8.GetBytes($$"""{"kind":"{{entityType}}"}""");
|
||||
|
||||
var id = await harness.Conflicts.RecordAsync(
|
||||
VaultId, entityType, Guid.CreateVersion7(), ConflictKind.FieldOverridden, detail, Token);
|
||||
|
||||
var listed = (await harness.Conflicts.ListAsync(VaultId, false, Token)).ShouldHaveSingleItem();
|
||||
|
||||
listed.Id.ShouldBe(id);
|
||||
listed.EntityType.ShouldBe(entityType);
|
||||
listed.Detail.ShouldBe(
|
||||
detail,
|
||||
"an empty detail here means the record was sealed under one resource type and opened under "
|
||||
+ "another, which ListAsync reports as nothing rather than as a failure");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task AnUnacknowledgedConflict_CannotBeDiscarded()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user