fix(sync): finish stuck downloads and keep edits saved during a comparison
A download whose .part already held the whole original (the job stopped while hashing it) or more asked the server to resume past the end, got 416 and failed on every retry; such a part is now hashed again, and one the server cannot resume starts over (CD-1). Auto-sync pulled the server's settings with the copy of the sequence read when the comparison began, so an edit saved on this PC meanwhile was overwritten unseen. The payload is now applied in one step under the sequence lease and only while the local settings version is the one read; otherwise nothing is written and the change is settled as a conflict (CD-3). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
4 files changed
+137
-27
No files matched your search
@@ -94,6 +94,31 @@ public sealed class SyncServiceTests(TestContext context)
|
||||
Assert.Equal(SyncStatus.InSync, (await f.EntryAsync("Harbour")).Status);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AnEditSavedHereDuringTheComparisonIsNotReplacedByTheServers()
|
||||
{
|
||||
await using var f = await SyncFixture.CreateAsync(context);
|
||||
var photos = f.NewPhotos(1);
|
||||
var local = await f.LocalAsync("Harbour", photos);
|
||||
var remote = f.Remote.Add("Harbour", photos);
|
||||
await f.Sync.LinkAsync(f.Server, remote.Id, local.Id, f.Ct);
|
||||
await f.RefreshAsync();
|
||||
|
||||
// The server's copy changes; the editor saves this PC's edit after the comparison read the local copy, before it
|
||||
// takes the server's version.
|
||||
f.Remote.EditSettings(remote.Id, SyncFixture.Window33);
|
||||
var racing = new RacingRemote(f.Remote, () => f.EditLocalSettingsAsync(local.Id, SyncFixture.Window41).GetAwaiter().GetResult(),
|
||||
beforeManifest: true);
|
||||
await f.Sync.RefreshAsync(racing, new SyncPolicy(), f.Ct);
|
||||
|
||||
var entry = await f.EntryAsync("Harbour");
|
||||
Assert.Equal(SyncStatus.Conflict, entry.Status);
|
||||
Assert.True(SyncRules.SameSettings(SyncFixture.Window41, entry.Local!.SettingsJson), "this PC's edit is kept");
|
||||
Assert.True(SyncRules.SameSettings(SyncFixture.Window41, await File.ReadAllTextAsync(f.Archive.Paths.Sequence(entry.Local.Folder).ProjectPath, f.Ct)));
|
||||
Assert.True(SyncRules.SameSettings(SyncFixture.Window33, entry.Link!.ConflictRemote!.SettingsJson), "the user picks");
|
||||
Assert.True(SyncRules.SameSettings(SyncFixture.Window33, remote.SettingsJson));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task WithoutAutomaticSyncAnEditWaitsForTheUser()
|
||||
{
|
||||
@@ -432,8 +457,11 @@ public sealed class SyncServiceTests(TestContext context)
|
||||
return (local, remote);
|
||||
}
|
||||
|
||||
/// <summary>A remote where someone else edits the settings right after the first read of a sequence, or right before the first edit.</summary>
|
||||
private sealed class RacingRemote(FakeSyncRemote inner, Action race, bool beforeUpdate = false) : ISyncRemote
|
||||
/// <summary>
|
||||
/// A remote where someone edits right after the first read of a sequence, right before the first edit, or right
|
||||
/// before the first manifest is read.
|
||||
/// </summary>
|
||||
private sealed class RacingRemote(FakeSyncRemote inner, Action race, bool beforeUpdate = false, bool beforeManifest = false) : ISyncRemote
|
||||
{
|
||||
private Action? _race = race;
|
||||
|
||||
@@ -442,12 +470,17 @@ public sealed class SyncServiceTests(TestContext context)
|
||||
public async Task<SequenceDto> GetSequenceAsync(Guid id, CancellationToken cancellationToken)
|
||||
{
|
||||
var dto = await inner.GetSequenceAsync(id, cancellationToken);
|
||||
if (!beforeUpdate) Interlocked.Exchange(ref _race, null)?.Invoke();
|
||||
if (!beforeUpdate && !beforeManifest) Interlocked.Exchange(ref _race, null)?.Invoke();
|
||||
return dto;
|
||||
}
|
||||
|
||||
public Task<IReadOnlyList<SequenceDto>> ListSequencesAsync(CancellationToken cancellationToken) => inner.ListSequencesAsync(cancellationToken);
|
||||
public Task<SequenceManifest> GetManifestAsync(Guid id, CancellationToken cancellationToken) => inner.GetManifestAsync(id, cancellationToken);
|
||||
public Task<SequenceManifest> GetManifestAsync(Guid id, CancellationToken cancellationToken)
|
||||
{
|
||||
if (beforeManifest) Interlocked.Exchange(ref _race, null)?.Invoke();
|
||||
return inner.GetManifestAsync(id, cancellationToken);
|
||||
}
|
||||
|
||||
public Task<IReadOnlyList<FrameDto>> ListFramesAsync(Guid sequenceId, CancellationToken cancellationToken) => inner.ListFramesAsync(sequenceId, cancellationToken);
|
||||
public Task<SequenceDto> UpdateSequenceAsync(Guid id, UpdateSequenceRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user