fix(copies): close the eighth verification round of owner review 6
- A merge's Renders stage never deletes what sits at a journaled render target: a file or folder it did not copy there (a render of the kept sequence made after a failed run), or a path another render of the kept sequence names, makes the copy take a new free name instead. - A merge's Verify stage records the hash it read for each kept frame the index had none for, the Details stage leaves the versions the verify filed out of Main, and Two versions also lists a whole-second instant holding two frames of one size and other content (owner Q3). - The Integrate journal keeps the losers the plan listed as last copies; a loser that became the only copy while the job ran is never trashed: the journal goes and the job fails as a stale plan. - Download originals of a server sequence whose earlier download was unlinked or kept apart makes a new local sequence under a key of the job, instead of filling the old one, re-linking it and overwriting its details. - An upload never links again from its checkpoint a server sequence the user kept apart since the attempt that made it. Refs #73 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
123ceba845
commit
aad8ae46dd
11 files changed
+536
-36
No files matched your search
@@ -2,6 +2,7 @@ using System.Security.Cryptography;
|
||||
using Chronos.Core.Model;
|
||||
using Chronos.Data.Copies;
|
||||
using Chronos.Data.Jobs;
|
||||
using Chronos.Data.Repositories;
|
||||
using Chronos.Data.Sync;
|
||||
using Chronos.Protocol;
|
||||
using Chronos.Testing;
|
||||
@@ -35,6 +36,19 @@ public sealed class SyncTransferCopyTests(TestContext context)
|
||||
return f;
|
||||
}
|
||||
|
||||
/// <summary>Waits until no pass a download queued works on <paramref name="sequenceId"/>.</summary>
|
||||
private static async Task WaitIdleAsync(SyncFixture f, Guid sequenceId)
|
||||
{
|
||||
var until = DateTime.UtcNow.AddSeconds(30);
|
||||
while (DateTime.UtcNow < until)
|
||||
{
|
||||
var held = await f.Db.Jobs.ListPendingTargetsAsync(JobKind.Thumbs, f.Ct);
|
||||
held.UnionWith(await f.Db.Jobs.ListPendingTargetsAsync(JobKind.LightAnalyse, f.Ct));
|
||||
if (!held.Contains(sequenceId)) return;
|
||||
await Task.Delay(20, f.Ct);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task OnlyThePhotosAskedForGoEachWay()
|
||||
{
|
||||
@@ -172,6 +186,83 @@ public sealed class SyncTransferCopyTests(TestContext context)
|
||||
Assert.True(f.Remote.Sequences[link.RemoteId].Frames.Select(fr => fr.Sha256).ToHashSet().SetEquals(photos.Select(Sha)));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ARetriedUploadNeverLinksAgainTheServerSequenceItsFirstAttemptMadeAndTheUserKeptApart()
|
||||
{
|
||||
await using var f = Capable(await SyncFixture.CreateAsync(context));
|
||||
var photos = f.NewPhotos(3);
|
||||
var local = await f.LocalAsync("Comet", [photos[0], photos[1]]);
|
||||
var engine = await f.StartEngineAsync();
|
||||
var job = await f.Sync.EnqueueUploadAsync(engine, f.Server, local);
|
||||
await f.Archive.WaitForAsync(job.Id, JobState.Done);
|
||||
var started = Assert.NotNull(await f.Sync.Links.FindByLocalAsync(f.Server, local.Id, f.Ct)).RemoteId;
|
||||
// The user keeps the pair apart while a run of the upload that made it is still to be retried.
|
||||
await f.Sync.UnlinkAsync(f.Server, started, local.Id, f.Ct);
|
||||
var pair = (await f.Sync.Copies.ListByServerAsync(f.Server, f.Ct)).Single(c => c.RemoteId == started);
|
||||
await f.AddLocalAsync(local.Id, photos[2]);
|
||||
|
||||
// The retry resumes from the checkpoint naming the sequence that run made.
|
||||
var row = new Job
|
||||
{
|
||||
Id = Guid.CreateVersion7(),
|
||||
Kind = JobKind.UploadCommit,
|
||||
TargetIds = [local.Id],
|
||||
State = JobState.Running,
|
||||
NodeId = "t#0",
|
||||
Created = DateTimeOffset.UtcNow,
|
||||
Started = DateTimeOffset.UtcNow,
|
||||
Checkpoint = started.ToString(),
|
||||
};
|
||||
await f.Db.Jobs.EnqueueAsync(row, f.Ct);
|
||||
var retry = new JobContext(new JobEngine(f.Db, [], new JobEngineOptions { WorkerId = "t" }), row, f.Ct);
|
||||
await new SyncTransfers(f.Sync).UploadAsync(retry, f.Remote, local.Id);
|
||||
|
||||
// The sequence kept apart stays apart, unlinked and as it was; a new one holds every photo.
|
||||
Assert.Equal(CopyState.KeptApart, (await f.Sync.Copies.GetAsync(pair.Id, f.Ct))!.State);
|
||||
Assert.Null((await f.Sync.Links.GetAsync(f.Server, started, f.Ct))!.LocalId);
|
||||
Assert.True(f.Remote.Sequences[started].Frames.Select(fr => fr.Sha256).ToHashSet().SetEquals([Sha(photos[0]), Sha(photos[1])]));
|
||||
var link = Assert.NotNull(await f.Sync.Links.FindByLocalAsync(f.Server, local.Id, f.Ct));
|
||||
Assert.NotEqual(started, link.RemoteId);
|
||||
Assert.True(f.Remote.Sequences[link.RemoteId].Frames.Select(fr => fr.Sha256).ToHashSet().SetEquals(photos.Select(Sha)));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task DownloadingAgainAServerSequenceUnlinkedFromItsDownloadMakesANewLocalSequence()
|
||||
{
|
||||
await using var f = Capable(await SyncFixture.CreateAsync(context));
|
||||
var photos = f.NewPhotos(3);
|
||||
var remote = f.Remote.Add("Comet", photos);
|
||||
var engine = await f.StartEngineAsync();
|
||||
var job = await f.Sync.EnqueueDownloadAsync(engine, f.Server, remote.Id, "Comet", SyncDownloadMode.Originals, f.Archive.Archive.Id);
|
||||
await f.Archive.WaitForAsync(job.Id, JobState.Done);
|
||||
var local = Assert.NotNull(Assert.NotNull(await f.Sync.Links.GetAsync(f.Server, remote.Id, f.Ct)).LocalId);
|
||||
await WaitIdleAsync(f, local);
|
||||
|
||||
// Here: one photo deleted, the title edited; then the pair is unlinked (kept apart).
|
||||
var sequence = (await f.Db.Sequences.GetAsync(local, f.Ct))!;
|
||||
var gone = (await f.Db.Frames.ListBySequenceAsync(local, cancellationToken: f.Ct))[0];
|
||||
var delete = await f.Archive.Service.FrameTrash.PlanDeleteAsync(local, [gone.Id], sequence.FramesVersion, f.Ct);
|
||||
await f.Archive.Service.FrameTrash.DeleteAsync(delete, cancellationToken: f.Ct);
|
||||
await f.Db.Sequences.EditAsync(local, new SequenceEdit { Title = "Mine" }, null, f.Ct);
|
||||
await f.Sync.UnlinkAsync(f.Server, remote.Id, local, f.Ct);
|
||||
var pair = (await f.Sync.Copies.ListByServerAsync(f.Server, f.Ct)).Single(c => c.RemoteId == remote.Id && c.LocalId == local);
|
||||
Assert.Equal(CopyState.KeptApart, pair.State);
|
||||
|
||||
// Download originals again: a separate local copy.
|
||||
job = await f.Sync.EnqueueDownloadAsync(engine, f.Server, remote.Id, "Comet", SyncDownloadMode.Originals, f.Archive.Archive.Id);
|
||||
await f.Archive.WaitForAsync(job.Id, JobState.Done);
|
||||
|
||||
// The sequence kept apart is as the user left it: its photos, its deletion, its title, its pair.
|
||||
var after = (await f.Db.Sequences.GetAsync(local, f.Ct))!;
|
||||
Assert.Equal("Mine", after.Title);
|
||||
Assert.Count(2, await f.Db.Frames.ListBySequenceAsync(local, cancellationToken: f.Ct));
|
||||
Assert.Contains(gone.Sha256, (await f.Db.FrameRemovals.ListBySequenceAsync(local, f.Ct)).Select(r => r.Sha256));
|
||||
Assert.Equal(CopyState.KeptApart, (await f.Sync.Copies.GetAsync(pair.Id, f.Ct))!.State);
|
||||
var copy = Assert.NotNull(Assert.NotNull(await f.Sync.Links.GetAsync(f.Server, remote.Id, f.Ct)).LocalId);
|
||||
Assert.NotEqual(local, copy);
|
||||
Assert.True((await LocalHashesAsync(f, copy)).SetEquals(photos.Select(Sha)));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AnAutomaticUploadAfterTheServerCopyIsGoneFailsAndCreatesNothing()
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user