fix(sync): send wanted proxies of unverified originals and recount them
Wanted proxies were matched to this PC's originals by SHA-256 only, and frames adopted from a folder stay unhashed until verified. A desktop that uploaded an adopted HEIC folder counted none of the proxies the server asked for, showed the link in sync and sent none of them. The upload now keeps the hash it computes for each original the index has none for and makes the proxies from those too; the comparison counts a wanted frame no hash matched against an unhashed original this PC reads by size (the server names its copy by its own template, so not by name). The wanted count was recomputed only when frame or render counters moved, so proxies a render node sent left the row "Local ahead" with an upload that sent nothing, and proxies the server started asking for later were never counted. A link whose copy may make proxies for the server now keeps the server's update time of the last comparison (sync_links.diff_remote_updated_at, migration 0006) and is compared again when it moved. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
9 files changed
+198
-18
No files matched your search
@@ -62,6 +62,59 @@ public sealed class SyncTransferTests(TestContext context)
|
||||
Assert.Equal(SyncStatus.InSync, (await f.EntryAsync("Holy grail")).Status);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AnUploadOfAnUnverifiedCopySendsTheProxiesTheServerAsksFor()
|
||||
{
|
||||
await using var f = await SyncFixture.CreateAsync(context);
|
||||
var photos = f.NewPhotos(3);
|
||||
// An adopted folder (never verified, so its frames have no hash here) whose originals the server already holds
|
||||
// under the names it gave them, and cannot decode (HEIF, BRIEF §2.3).
|
||||
var folder = Path.Combine(f.Archive.Paths.Root, "Adopted");
|
||||
Directory.CreateDirectory(folder);
|
||||
for (var i = 0; i < 3; i++) await File.WriteAllBytesAsync(Path.Combine(folder, $"DSC_{i + 1:0000}.JPG"), photos[i], f.Ct);
|
||||
await f.Archive.ScanAsync();
|
||||
var local = Assert.Contains((await f.Db.Sequences.ListAsync(new Titano.Data.Repositories.SequenceQuery(), f.Ct)).Items, s => s.Folder == "Adopted");
|
||||
Assert.True((await f.Db.Frames.ListBySequenceAsync(local.Id, cancellationToken: f.Ct)).All(fr => fr.Sha256 is null), "adopted frames are unhashed");
|
||||
var remote = f.Remote.Add("Adopted", photos);
|
||||
remote.Undecodable = true;
|
||||
await f.Sync.LinkAsync(f.Server, remote.Id, local.Id, f.Ct);
|
||||
await f.RefreshAsync();
|
||||
var ahead = await f.EntryAsync(local.DisplayTitle);
|
||||
Assert.Equal((SyncStatus.LocalAhead, 3), (ahead.Status, ahead.Link!.MissingRemote));
|
||||
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.True(f.Remote.SentProxies.Keys.ToHashSet().SetEquals(remote.Frames.Select(r => r.Id)), "a proxy of every frame");
|
||||
Assert.Contains(Loc.L("Archive.Log.ProxiesSent", 3, 0), done.LogTail);
|
||||
Assert.Equal(SyncStatus.InSync, (await f.EntryAsync(local.DisplayTitle)).Status);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ProxiesSentFromElsewhereAreNoLongerCountedHere()
|
||||
{
|
||||
await using var f = await SyncFixture.CreateAsync(context);
|
||||
var photos = f.NewPhotos(2);
|
||||
var local = await f.LocalAsync("Holy grail", photos);
|
||||
var remote = f.Remote.Add("Holy grail", photos);
|
||||
remote.Undecodable = true;
|
||||
await f.Sync.LinkAsync(f.Server, remote.Id, local.Id, f.Ct);
|
||||
await f.RefreshAsync();
|
||||
Assert.Equal(2, (await f.EntryAsync("Holy grail")).Link!.MissingRemote);
|
||||
var calls = f.Remote.ManifestCalls;
|
||||
await f.RefreshAsync();
|
||||
Assert.Equal(calls, f.Remote.ManifestCalls);
|
||||
|
||||
// A render node sends them after a job: the server's frame counters stand still, its sequence changes.
|
||||
foreach (var frame in remote.Frames) f.Remote.SentProxies[frame.Id] = frame.Proxy;
|
||||
remote.UpdatedAt = remote.UpdatedAt.AddSeconds(1);
|
||||
await f.RefreshAsync();
|
||||
|
||||
var entry = await f.EntryAsync("Holy grail");
|
||||
Assert.Equal((SyncStatus.InSync, 0), (entry.Status, entry.Link!.MissingRemote));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AResumedUploadSendsOnlyWhatTheServerLacks()
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user