fix(sync): download and match originals the server has not hashed
A folder the server adopted and never verified lists no SHA-256. A
download of such a sequence failed ("did not arrive intact") because
every unhashed frame collapsed into one wanted entry and the empty hash
was refused, and desktops never sent the proxies the server asked for
those frames (V-9).
- Each unhashed server original is fetched by frame id into staging,
accepted on its size (two attempts, resumed with Range) and hashed
here; the archive ingest files it by that hash like any other.
- Server frames without a hash are matched to this PC's originals by
size and capture time: they are not downloaded twice, not uploaded
again, counted right in the comparison (each frame on its own), and
their wanted proxies are counted and sent from the matching original.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
5 files changed
+318
-59
No files matched your search
@@ -265,6 +265,81 @@ public sealed class SyncTransferTests(TestContext context)
|
||||
Assert.Equal(SyncStatus.InSync, (await f.EntryAsync("Harbour")).Status);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task OriginalsTheServerHasNotHashedAreDownloadedAndHashedHere()
|
||||
{
|
||||
await using var f = await SyncFixture.CreateAsync(context);
|
||||
var photos = f.NewPhotos(3);
|
||||
// A folder the server adopted and never verified: its manifest lists no SHA-256.
|
||||
var remote = f.Remote.Add("Adopted on the server", photos);
|
||||
remote.Unhashed = true;
|
||||
await f.RefreshAsync();
|
||||
var engine = await f.StartEngineAsync();
|
||||
|
||||
var job = await f.Sync.EnqueueDownloadAsync(engine, f.Server, remote.Id, "Adopted on the server", SyncDownloadMode.Originals, f.Archive.Archive.Id);
|
||||
await f.Archive.WaitForAsync(job.Id, JobState.Done);
|
||||
|
||||
var entry = await f.EntryAsync("Adopted on the server");
|
||||
var frames = await f.Db.Frames.ListBySequenceAsync(entry.Local!.Id, cancellationToken: f.Ct);
|
||||
Assert.True(frames.Select(r => r.Sha256).ToHashSet().SetEquals(photos.Select(Sha)), "every original arrived, hashed here");
|
||||
// Matched by size and capture time, the copies are the server's originals.
|
||||
Assert.Equal((SyncStatus.InSync, 0, 0), (entry.Status, entry.Link!.MissingRemote, entry.Link.MissingLocal));
|
||||
|
||||
// One more photo adopted there: only that one travels.
|
||||
remote.AddFrame(f.NewPhotos(1)[0]);
|
||||
await f.RefreshAsync();
|
||||
Assert.Equal(1, (await f.EntryAsync("Adopted on the server")).Link!.MissingLocal);
|
||||
job = await f.Sync.EnqueueDownloadAsync(engine, f.Server, remote.Id, "Adopted on the server", SyncDownloadMode.Originals, null);
|
||||
await f.Archive.WaitForAsync(job.Id, JobState.Done);
|
||||
Assert.Equal(4, (await f.Db.Frames.ListBySequenceAsync(entry.Local.Id, cancellationToken: f.Ct)).Count);
|
||||
Assert.Equal(SyncStatus.InSync, (await f.EntryAsync("Adopted on the server")).Status);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AnUploadDoesNotSendAgainWhatTheServerHoldsWithoutAHash()
|
||||
{
|
||||
await using var f = await SyncFixture.CreateAsync(context);
|
||||
var photos = f.NewPhotos(4);
|
||||
var local = await f.LocalAsync("Harbour", photos);
|
||||
// The server adopted the first three photos and never verified them: it cannot recognise them by content.
|
||||
var remote = f.Remote.Add("Harbour", photos[..3]);
|
||||
remote.Unhashed = true;
|
||||
await f.Sync.LinkAsync(f.Server, remote.Id, local.Id, f.Ct);
|
||||
await f.RefreshAsync();
|
||||
var ahead = (await f.EntryAsync("Harbour")).Link!;
|
||||
Assert.Equal((1, 0), (ahead.MissingRemote, ahead.MissingLocal));
|
||||
var engine = await f.StartEngineAsync();
|
||||
|
||||
var job = await f.Sync.EnqueueUploadAsync(engine, f.Server, local);
|
||||
var done = await f.Archive.WaitForAsync(job.Id, JobState.Done);
|
||||
|
||||
Assert.Equal((4L, 4L), (done.ProgressDone, done.ProgressTotal));
|
||||
Assert.SequenceEqual(photos.Select(Sha), remote.Frames.Select(r => r.Sha256));
|
||||
Assert.Equal(SyncStatus.InSync, (await f.EntryAsync("Harbour")).Status);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ProxiesOfFramesTheServerHasNotHashedAreSentToo()
|
||||
{
|
||||
await using var f = await SyncFixture.CreateAsync(context);
|
||||
var photos = f.NewPhotos(3);
|
||||
var local = await f.LocalAsync("Holy grail", photos);
|
||||
// The server adopted the same originals, cannot decode them and has not hashed them.
|
||||
var remote = f.Remote.Add("Holy grail", photos);
|
||||
remote.Undecodable = true;
|
||||
remote.Unhashed = true;
|
||||
await f.Sync.LinkAsync(f.Server, remote.Id, local.Id, f.Ct);
|
||||
await f.RefreshAsync();
|
||||
Assert.Equal(3, (await f.EntryAsync("Holy grail")).Link!.MissingRemote);
|
||||
var engine = await f.StartEngineAsync();
|
||||
|
||||
var job = await f.Sync.EnqueueUploadAsync(engine, f.Server, local);
|
||||
await f.Archive.WaitForAsync(job.Id, JobState.Done);
|
||||
|
||||
Assert.True(f.Remote.SentProxies.Keys.ToHashSet().SetEquals(remote.Frames.Select(r => r.Id)), "a proxy of every frame");
|
||||
Assert.Equal((SyncStatus.InSync, 0), ((await f.EntryAsync("Holy grail")).Status, (await f.EntryAsync("Holy grail")).Link!.MissingRemote));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task PositionsTakenFromTheServerStayOnTheirPhotosWhenTheOriginalsArrive()
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user