fix(copies): close the owner review 6 verification findings
A merge could still trash photos it never verified, resume against a pair the user had answered meanwhile, and take different unhashed photos for copies; the dialog and the lists worded several facts wrongly or lost them on refresh. - Merge: a retry resumes only while the pair is still the job's; Verify requires the other archive online and its folder in place, stops on an unreadable photo, files a differing unhashed photo as a second version and must cover every frame before Trash; the plan hashes unmatched unhashed photos first, lists "Deleted in the other" and names the relinked servers; second versions stay discoverable (CopySides.VersionsAsync). - Integrate: a retry after a failure before the journal runs again. - Sync: a sequence back after a 404 stays Linked while its link holds; a local cull no longer asks for attention. - Block lines of both planners name the right sequence, archive, server and space through one formatter. - Compare dialog: one Details row per setting with worded values, Projects headings, Choose focuses the kept-sequence radios, the photo selection reaches rows outside the viewport, the Replace confirmation lists the losers per side, plan lines read as queued. - Matches and Library: counts first and grouped, integrating shown as a share, local matches name the other archive, the Library keeps its match and "deleted on server" statuses across a refresh. Refs #73 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
d10577b175
commit
b34b6b6fe0
41 files changed
+1046
-193
No files matched your search
@@ -269,7 +269,7 @@ public abstract class SequenceMergerTests(TestContext context) : DatabaseTest(co
|
||||
var keep = await SequenceAsync(fx, "keep", [(1, 0, "IMG_0001.JPG")]);
|
||||
var drop = await SequenceAsync(fx, "drop", [(1, 0, "IMG_0001.JPG")]);
|
||||
var copy = await PairAsync(fx, keep.Id, drop.Id);
|
||||
var merger = Merger(fx);
|
||||
var merger = new SequenceMerger(fx.Db, fx.Service, new CopySides(fx.Db)) { ServerNames = key => key == Nas ? "Studio NAS" : null };
|
||||
var choices = await ChoicesAsync(fx, keep.Id, drop.Id, CopyPhotoPolicy.Union);
|
||||
|
||||
var render = await RunningAsync(fx, JobKind.Render, keep.Id);
|
||||
@@ -281,7 +281,12 @@ public abstract class SequenceMergerTests(TestContext context) : DatabaseTest(co
|
||||
var links = new SyncLinkStore(fx.Db);
|
||||
await links.UpsertAsync(new SyncLink { Server = Nas, RemoteId = Guid.CreateVersion7(), LocalId = keep.Id, Title = "k" }, Ct);
|
||||
await links.UpsertAsync(new SyncLink { Server = Nas, RemoteId = Guid.CreateVersion7(), LocalId = drop.Id, Title = "d" }, Ct);
|
||||
Assert.Contains(CopyBlock.BothLinked, (await merger.PlanAsync(copy.Id, keep.Id, drop.Id, choices, NoContext, Ct)).Blocks);
|
||||
var both = await merger.PlanAsync(copy.Id, keep.Id, drop.Id, choices, NoContext, Ct);
|
||||
Assert.Contains(CopyBlock.BothLinked, both.Blocks);
|
||||
// Named by the server's name, never its key.
|
||||
Assert.Equal("Studio NAS", both.BothLinkedServer);
|
||||
Assert.SequenceEqual(["Studio NAS"], both.LinkNames);
|
||||
Assert.Equal(Chronos.Core.Localization.Loc.L("Errors.Copies.BothLinked", "Studio NAS"), await merger.BlockMessageAsync(both with { Blocks = [CopyBlock.BothLinked] }, Ct));
|
||||
|
||||
var unsent = PlanContext() with { UnsentWorkspaceSequences = new HashSet<Guid> { drop.Id } };
|
||||
Assert.Contains(CopyBlock.UnsentWorkspace, (await merger.PlanAsync(copy.Id, keep.Id, drop.Id, choices, unsent, Ct)).Blocks);
|
||||
@@ -542,6 +547,163 @@ public abstract class SequenceMergerTests(TestContext context) : DatabaseTest(co
|
||||
Assert.Null(await fx.Db.Sequences.GetAsync(drop.Id));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AUnionMergeLeavesItsSecondVersionsListedInTheKeptOne()
|
||||
{
|
||||
var fx = await FixtureAsync();
|
||||
var keep = await SequenceAsync(fx, "keep", [(1, 0, "IMG_0001.JPG"), (2, 10_000, "IMG_0002.JPG"), (4, 30_250, "IMG_0004.JPG")]);
|
||||
var drop = await SequenceAsync(fx, "drop", [(1, 0, "IMG_0001.JPG"), (5, 30_250, "IMG_0004.JPG")]);
|
||||
// The other deleted photo 2, which the kept one still holds.
|
||||
await fx.Db.FrameRemovals.SyncSequenceAsync(drop.Id, [new FrameRemoval(drop.Id, Sha(2, 10_000), null, RemovalReason.Deleted, DateTimeOffset.UtcNow)], Ct);
|
||||
var copy = await PairAsync(fx, keep.Id, drop.Id);
|
||||
var merger = Merger(fx);
|
||||
var (engine, _) = Engine(fx, merger, new FakeProjects(), new FakeWorkspace());
|
||||
await engine.StartAsync(Ct);
|
||||
var plan = await merger.PlanAsync(copy.Id, keep.Id, drop.Id, await ChoicesAsync(fx, keep.Id, drop.Id, CopyPhotoPolicy.Union), NoContext, Ct);
|
||||
Assert.Equal(1, plan.DeletedInOther);
|
||||
Assert.Empty(await new CopySides(fx.Db).VersionsAsync(keep.Id, Ct));
|
||||
|
||||
var job = await merger.EnqueueAsync(engine, new FoundCopyStore(fx.Db), plan, keep.DisplayTitle, Ct);
|
||||
await fx.WaitForAsync(job.Id, JobState.Done);
|
||||
|
||||
// The pair is gone with the other; the kept one still lists the photo it holds in two versions.
|
||||
Assert.Null(await new FoundCopyStore(fx.Db).GetAsync(copy.Id, Ct));
|
||||
var versions = (await new CopySides(fx.Db).VersionsAsync(keep.Id, Ct)).Single();
|
||||
Assert.True(new[] { versions.FirstSha256, versions.SecondSha256 }.ToHashSet().SetEquals([Sha(4, 30_250), Sha(5, 30_250)]));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ARetryAfterKeepApartRefusesAndTrashesNothing()
|
||||
{
|
||||
var fx = await FixtureAsync();
|
||||
var keep = await SequenceAsync(fx, "keep", [(1, 0, "IMG_0001.JPG")]);
|
||||
var drop = await SequenceAsync(fx, "drop", [(1, 0, "IMG_0001.JPG"), (2, 10_000, "IMG_0002.JPG")]);
|
||||
var copy = await PairAsync(fx, keep.Id, drop.Id);
|
||||
var merger = Merger(fx);
|
||||
var workspace = new FakeWorkspace();
|
||||
var (engine, handler) = Engine(fx, merger, new FakeProjects(), workspace);
|
||||
await engine.StartAsync(Ct);
|
||||
// The trash stage stops on unsent workspace work: the pair is still the failed job's.
|
||||
handler.BeforeStage = stage =>
|
||||
{
|
||||
if (stage == MergeStage.Trash) workspace.Unsent.Add(drop.Id);
|
||||
return Task.CompletedTask;
|
||||
};
|
||||
var store = new FoundCopyStore(fx.Db);
|
||||
var plan = await merger.PlanAsync(copy.Id, keep.Id, drop.Id, await ChoicesAsync(fx, keep.Id, drop.Id, CopyPhotoPolicy.Union), NoContext, Ct);
|
||||
var job = await merger.EnqueueAsync(engine, store, plan, keep.DisplayTitle, Ct);
|
||||
await fx.WaitForAsync(job.Id, JobState.Failed);
|
||||
|
||||
// Kept apart, the work sent, then Retry: the journal is stale, the other stays where it is.
|
||||
Assert.True(await store.SetStateAsync(copy.Id, null, CopyState.KeptApart, new CopyAnswer("f", 1, null, null, DateTimeOffset.UtcNow), Ct));
|
||||
handler.BeforeStage = null;
|
||||
workspace.Unsent.Clear();
|
||||
await engine.ResumeAsync(job.Id, Ct);
|
||||
var failed = await fx.WaitForAsync(job.Id, JobState.Failed);
|
||||
|
||||
Assert.Equal(Chronos.Core.Localization.Loc.L("Errors.Copies.StalePlan"), failed.Error);
|
||||
var still = await fx.Db.Sequences.GetAsync(drop.Id);
|
||||
Assert.NotNull(still);
|
||||
Assert.True(File.Exists(fx.Paths.Sequence(still!.Folder).ManifestPath));
|
||||
Assert.False(File.Exists(MergeJournal.PathFor(fx.Paths, job.Id)));
|
||||
Assert.Equal(CopyState.KeptApart, (await store.GetAsync(copy.Id, Ct))!.State);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ARetryAfterAnotherMergeOfThePairRefusesAndTrashesNothing()
|
||||
{
|
||||
var fx = await FixtureAsync();
|
||||
var keep = await SequenceAsync(fx, "keep", [(1, 0, "IMG_0001.JPG")]);
|
||||
var drop = await SequenceAsync(fx, "drop", [(1, 0, "IMG_0001.JPG"), (2, 10_000, "IMG_0002.JPG")]);
|
||||
var copy = await PairAsync(fx, keep.Id, drop.Id);
|
||||
var merger = Merger(fx);
|
||||
var (engine, handler) = Engine(fx, merger, new FakeProjects(), new FakeWorkspace());
|
||||
await engine.StartAsync(Ct);
|
||||
handler.BeforeStage = stage => stage == MergeStage.Verify ? throw new IOException("crash before Verify") : Task.CompletedTask;
|
||||
var store = new FoundCopyStore(fx.Db);
|
||||
var plan = await merger.PlanAsync(copy.Id, keep.Id, drop.Id, await ChoicesAsync(fx, keep.Id, drop.Id, CopyPhotoPolicy.Union), NoContext, Ct);
|
||||
var job = await merger.EnqueueAsync(engine, store, plan, keep.DisplayTitle, Ct);
|
||||
await fx.WaitForAsync(job.Id, JobState.Failed);
|
||||
|
||||
// A new merge keeping the other one takes the pair (and stops before its own trash).
|
||||
handler.BeforeStage = stage => stage == MergeStage.Copy ? throw new IOException("crash before Copy") : Task.CompletedTask;
|
||||
var swapped = await merger.PlanAsync(copy.Id, drop.Id, keep.Id, await ChoicesAsync(fx, drop.Id, keep.Id, CopyPhotoPolicy.Union), NoContext, Ct);
|
||||
var second = await merger.EnqueueAsync(engine, store, swapped, drop.DisplayTitle, Ct);
|
||||
await fx.WaitForAsync(second.Id, JobState.Failed);
|
||||
|
||||
handler.BeforeStage = null;
|
||||
await engine.ResumeAsync(job.Id, Ct);
|
||||
var failed = await fx.WaitForAsync(job.Id, JobState.Failed);
|
||||
|
||||
Assert.Equal(Chronos.Core.Localization.Loc.L("Errors.Copies.StalePlan"), failed.Error);
|
||||
Assert.NotNull(await fx.Db.Sequences.GetAsync(drop.Id));
|
||||
Assert.NotNull(await fx.Db.Sequences.GetAsync(keep.Id));
|
||||
Assert.False(File.Exists(MergeJournal.PathFor(fx.Paths, job.Id)));
|
||||
// The other merge's journal is untouched.
|
||||
Assert.True(File.Exists(MergeJournal.PathFor(fx.Paths, second.Id)));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AVerifyThatCannotReadTheOtherStopsAndTheRetryVerifiesEverything()
|
||||
{
|
||||
var fx = await FixtureAsync();
|
||||
var keep = await SequenceAsync(fx, "keep", [(1, 0, "IMG_0001.JPG")]);
|
||||
var drop = await SequenceAsync(fx, "drop", [(2, 0, "IMG_0001.JPG")]);
|
||||
// Neither hashed, the same size and time: compared as the same photo, only the verify tells them apart.
|
||||
await new DbAccess(fx.Db.Database).ExecuteAsync("UPDATE frames SET sha256 = NULL, size = 1000 WHERE sequence_id = $1 OR sequence_id = $2",
|
||||
[keep.Id, drop.Id], Ct);
|
||||
var copy = await PairAsync(fx, keep.Id, drop.Id);
|
||||
var merger = Merger(fx);
|
||||
var (engine, handler) = Engine(fx, merger, new FakeProjects(), new FakeWorkspace());
|
||||
await engine.StartAsync(Ct);
|
||||
var folder = fx.Paths.Sequence(drop.Folder).Folder;
|
||||
var aside = folder + "-away";
|
||||
handler.BeforeStage = stage =>
|
||||
{
|
||||
if (stage == MergeStage.Verify && Directory.Exists(folder)) Directory.Move(folder, aside);
|
||||
return Task.CompletedTask;
|
||||
};
|
||||
var plan = await merger.PlanAsync(copy.Id, keep.Id, drop.Id, await ChoicesAsync(fx, keep.Id, drop.Id, CopyPhotoPolicy.Union), NoContext, Ct);
|
||||
var job = await merger.EnqueueAsync(engine, new FoundCopyStore(fx.Db), plan, keep.DisplayTitle, Ct);
|
||||
await fx.WaitForAsync(job.Id, JobState.Failed);
|
||||
Assert.NotNull(await fx.Db.Sequences.GetAsync(drop.Id));
|
||||
Assert.Count(1, await fx.Db.Frames.ListBySequenceAsync(keep.Id));
|
||||
|
||||
handler.BeforeStage = null;
|
||||
Directory.Move(aside, folder);
|
||||
await engine.ResumeAsync(job.Id, Ct);
|
||||
await fx.WaitForAsync(job.Id, JobState.Done);
|
||||
|
||||
// The other photo was read and filed as a second version before the other went to the trash.
|
||||
Assert.Contains(Sha(2, 0), (await fx.Db.Frames.ListBySequenceAsync(keep.Id)).Select(f => f.Sha256));
|
||||
Assert.Null(await fx.Db.Sequences.GetAsync(drop.Id));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AnUnhashedPhotoTheKeptOneDeletedIsALastCopyNotACopy()
|
||||
{
|
||||
var fx = await FixtureAsync();
|
||||
var keep = await SequenceAsync(fx, "keep", [(1, 0, "IMG_0001.JPG")]);
|
||||
var drop = await SequenceAsync(fx, "drop", [(1, 0, "IMG_0001.JPG"), (2, 10_000, "IMG_0002.JPG")]);
|
||||
var gone = Sha(2, 10_000);
|
||||
await fx.Db.FrameRemovals.SyncSequenceAsync(keep.Id, [new FrameRemoval(keep.Id, gone, null, RemovalReason.Deleted, DateTimeOffset.UtcNow)], Ct);
|
||||
await new DbAccess(fx.Db.Database).ExecuteAsync("UPDATE frames SET sha256 = NULL WHERE sequence_id = $1 AND file_name = $2", [drop.Id, "IMG_0002.JPG"], Ct);
|
||||
var copy = await PairAsync(fx, keep.Id, drop.Id);
|
||||
var merger = Merger(fx);
|
||||
var (engine, _) = Engine(fx, merger, new FakeProjects(), new FakeWorkspace());
|
||||
await engine.StartAsync(Ct);
|
||||
|
||||
var plan = await merger.PlanAsync(copy.Id, keep.Id, drop.Id, await ChoicesAsync(fx, keep.Id, drop.Id, CopyPhotoPolicy.Union), NoContext, Ct);
|
||||
Assert.Empty(plan.Photos);
|
||||
Assert.SequenceEqual([(CopySide.Other, gone)], plan.LastCopies.Select(l => (l.Side, l.Key)));
|
||||
|
||||
// Confirmed as a last copy: the merge goes through and does not file it in the kept one.
|
||||
var job = await merger.EnqueueAsync(engine, new FoundCopyStore(fx.Db), plan, keep.DisplayTitle, Ct);
|
||||
await fx.WaitForAsync(job.Id, JobState.Done);
|
||||
Assert.DoesNotContain(gone, await HashesAsync(fx, keep.Id));
|
||||
Assert.Null(await fx.Db.Sequences.GetAsync(drop.Id));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ACancelReturnsThePairToItsStateAndLeavesTheOtherAlone()
|
||||
{
|
||||
|
||||
@@ -326,4 +326,38 @@ public sealed class CopyEngineTests(TestContext context)
|
||||
await Assert.ThrowsAsync<StaleCopyPlanException>(() => engine.TrashThereAsync(plan, f.Remote, f.Ct));
|
||||
Assert.Count(0, f.Remote.Trashed);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TwinsNameTheProjectsOfBothHomesOfALinkedPairEvenUnderTheServersIdKey()
|
||||
{
|
||||
// Owner Q5's alternative: projects left where they are; Edit's picker marks the two homes' projects as twins. The
|
||||
// server home is keyed by the server's id while the pair still carries the address key it was found under.
|
||||
var serverId = Guid.NewGuid();
|
||||
var address = string.Empty;
|
||||
await using var f = await SyncFixture.CreateAsync(context, () => new ServerIdentity([new KnownServerKey(serverId, [address])]));
|
||||
address = f.Server;
|
||||
var photos = f.NewPhotos(2);
|
||||
var linked = await f.LocalAsync("Comet", photos);
|
||||
var apart = await f.LocalAsync("Lighthouse", f.NewPhotos(2));
|
||||
var linkedRemote = f.Remote.Add("Comet NAS", photos);
|
||||
var apartRemote = f.Remote.Add("Lighthouse NAS", photos);
|
||||
var pair = await PairAsync(f, linked.Id, linkedRemote.Id);
|
||||
Assert.True(await f.Sync.Copies.SetStateAsync(pair.Id, CopyState.Candidate, CopyState.Linked, null, f.Ct));
|
||||
await PairAsync(f, apart.Id, apartRemote.Id);
|
||||
var sides = new CopySides(f.Db);
|
||||
IReadOnlyList<(Chronos.Core.Project.BundleHome Home, string Name)> projects =
|
||||
[
|
||||
(new(Chronos.Core.Project.BundleHome.ArchiveKind, linked.Id), "Grade"),
|
||||
(new(Chronos.Core.Project.BundleHome.ServerKind, linkedRemote.Id, Server: ServerIdentity.IdKey(serverId)), "Grade NAS"),
|
||||
(new(Chronos.Core.Project.BundleHome.ArchiveKind, apart.Id), "Unpaired"),
|
||||
];
|
||||
using var engine = new CopyEngine(f.Sync, f.Archive.Service, new IntegratePlanner(f.Sync, sides, f.Archive.Service.Projects),
|
||||
new SequenceMerger(f.Db, f.Archive.Service, sides), new CopyReviewBuilder(f.Db, f.Archive.Service.Projects, sides), _ => Context,
|
||||
workspaceProjects: _ => Task.FromResult(projects));
|
||||
|
||||
var twin = (await engine.TwinsAsync(f.Ct)).Single();
|
||||
|
||||
Assert.Equal((pair.Id, linked.Id, "Grade", linkedRemote.Id, "Grade NAS"), (twin.CopyId, twin.LocalId, twin.LocalProject, twin.RemoteId, twin.ServerProject));
|
||||
Assert.Equal(f.Server, twin.Server);
|
||||
}
|
||||
}
|
||||
@@ -558,6 +558,62 @@ public sealed class IntegrateTests(TestContext context)
|
||||
Assert.False(File.Exists(IntegrateJournal.PathFor(f.Archive.Paths, job.Id)));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ARetryAfterAFailureBeforeTheJournalRunsTheIntegrate()
|
||||
{
|
||||
await using var f = await FixtureAsync(context);
|
||||
var (engine, _) = Engine(f);
|
||||
await using var _ = engine;
|
||||
var (local, remote, pair) = await ScenarioAsync(f);
|
||||
var plan = await Planner(f).PlanAsync(f.Remote, pair, await ChoicesAsync(f, local.Id, remote.Id, CopyPhotoPolicy.Union), PlanContext(), f.Ct);
|
||||
var job = await CopyJobs.EnqueueIntegrateAsync(engine, f.Sync.Copies, plan, local.DisplayTitle, f.Ct);
|
||||
// The plan made again is blocked: the job fails before it writes its journal.
|
||||
f.Remote.Capabilities.Remove(ServerCapabilities.UploadInto);
|
||||
await engine.StartAsync(f.Ct);
|
||||
await f.Archive.WaitForAsync(job.Id, JobState.Failed);
|
||||
Assert.False(File.Exists(IntegrateJournal.PathFor(f.Archive.Paths, job.Id)));
|
||||
Assert.Equal(CopyState.Candidate, (await f.Sync.Copies.GetAsync(pair.Id, f.Ct))!.State);
|
||||
|
||||
f.Remote.Capabilities.Add(ServerCapabilities.UploadInto);
|
||||
await engine.ResumeAsync(job.Id, f.Ct);
|
||||
await f.Archive.WaitForAsync(job.Id, JobState.Done);
|
||||
|
||||
Assert.Equal(CopyState.Integrated, (await f.Sync.Copies.GetAsync(pair.Id, f.Ct))!.State);
|
||||
Assert.Contains(Sha(3, 20_000), await LocalHashesAsync(f, local.Id));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ProjectsAreLeftWhereTheyAreWhenTheChoiceSaysSo()
|
||||
{
|
||||
await using var f = await FixtureAsync(context);
|
||||
f.Remote.Capabilities.Add(ServerCapabilities.Projects);
|
||||
var (local, remote, pair) = await ScenarioAsync(f);
|
||||
var standIn = await LocalAsync(f, "Stand-in", [(50, 0, "IMG_0050.JPG")]);
|
||||
var projects = f.Archive.Service.Projects;
|
||||
var serverHome = new ArchiveProjectHome(f.Db, projects, standIn.Id);
|
||||
await projects.CreateAsync(local.Id, "Vertical", cancellationToken: f.Ct);
|
||||
await projects.CreateAsync(standIn.Id, "Wide", cancellationToken: f.Ct);
|
||||
var planner = new IntegratePlanner(f.Sync, new CopySides(f.Db), projects, (_, _) => serverHome);
|
||||
var choices = await ChoicesAsync(f, local.Id, remote.Id, CopyPhotoPolicy.Union) with { Projects = CopyProjects.Leave };
|
||||
|
||||
// Even where the user keeps projects, Leave plans no project step.
|
||||
var plan = await planner.PlanAsync(f.Remote, pair, choices, PlanContext(keepsProjects: true), f.Ct);
|
||||
Assert.True(plan.CanApply);
|
||||
Assert.Empty(plan.Projects);
|
||||
|
||||
var connector = new SyncFixture.Connector(f.Remote);
|
||||
var handler = new IntegrateJobHandler(f.Sync, planner, new ProjectTransplant(), connector, f.Sync.Copies, f.Archive.Service);
|
||||
await using var engine = new JobEngine(f.Db, [.. f.Archive.Service.CreateJobHandlers(), .. f.Sync.CreateJobHandlers(connector), handler],
|
||||
new JobEngineOptions { Workers = 1, WorkerId = "test", PollInterval = TimeSpan.FromMilliseconds(50), CheckpointInterval = TimeSpan.FromMilliseconds(50) });
|
||||
await engine.StartAsync(f.Ct);
|
||||
var job = await CopyJobs.EnqueueIntegrateAsync(engine, f.Sync.Copies, plan, local.DisplayTitle, f.Ct);
|
||||
await f.Archive.WaitForAsync(job.Id, JobState.Done);
|
||||
|
||||
static List<string> Names(IEnumerable<SequenceProject> list) => [.. list.Where(p => !p.IsMain).Select(p => p.Name).Order(StringComparer.Ordinal)];
|
||||
Assert.SequenceEqual(["Vertical"], Names(await projects.ListAsync(local.Id, f.Ct)));
|
||||
Assert.SequenceEqual(["Wide"], Names(await projects.ListAsync(standIn.Id, f.Ct)));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ACancelAfterTheLinkLeavesThePairLinkedAndFreeOfTheJob()
|
||||
{
|
||||
|
||||
@@ -30,13 +30,15 @@ internal sealed class SyncFixture : IAsyncDisposable
|
||||
public string Server => Remote.Server;
|
||||
public CancellationToken Ct => Archive.Ct;
|
||||
|
||||
public static async Task<SyncFixture> CreateAsync(TestContext context)
|
||||
/// <param name="identity">The servers known by id and the address keys they were reached under (default: none).</param>
|
||||
public static async Task<SyncFixture> CreateAsync(TestContext context, Func<ServerIdentity>? identity = null)
|
||||
{
|
||||
var archive = await ArchiveFixture.CreateAsync(context);
|
||||
var sync = new SyncService(archive.Db, archive.Service, new SyncOptions
|
||||
{
|
||||
Archive = new ArchiveServiceOptions { Owner = "test", LeaseWait = TimeSpan.FromSeconds(20) },
|
||||
ProxyCacheDirectory = context.CreateTempDirectory("proxies"),
|
||||
Identity = identity,
|
||||
});
|
||||
return new SyncFixture(archive, sync);
|
||||
}
|
||||
|
||||
@@ -201,6 +201,27 @@ public sealed class SyncServiceCopyTests(TestContext context)
|
||||
Assert.Equal(CopyState.Candidate, pair.State);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ASequenceBackAfterAJobs404StaysLinked()
|
||||
{
|
||||
await using var f = await SyncFixture.CreateAsync(context);
|
||||
var nas = new FakeSyncRemote { Server = HomeFolders.IdKey(Guid.NewGuid()) };
|
||||
var photos = f.NewPhotos(2);
|
||||
var local = await f.LocalAsync("Comet", photos);
|
||||
var remote = nas.Add("Comet", photos);
|
||||
await f.Sync.LinkAsync(nas.Server, remote.Id, local.Id, f.Ct);
|
||||
await f.Sync.RefreshAsync(nas, new SyncPolicy(), f.Ct);
|
||||
// A transfer's 404: the pair is marked once, the link stays.
|
||||
await f.Sync.Copies.MarkRemoteGoneAsync(nas.Server, remote.Id, local.Id, Guid.NewGuid(), DateTimeOffset.UtcNow, f.Ct);
|
||||
Assert.Equal(1, (await f.Sync.Copies.ListByServerAsync(nas.Server, f.Ct)).Single().RemoteGoneHits);
|
||||
|
||||
await f.Sync.RefreshAsync(nas, new SyncPolicy(), f.Ct);
|
||||
|
||||
var pair = (await f.Sync.Copies.ListByServerAsync(nas.Server, f.Ct)).Single();
|
||||
Assert.Equal((0, CopyState.Linked), (pair.RemoteGoneHits, pair.State));
|
||||
Assert.Equal(local.Id, (await f.Sync.LinkOfAsync(nas.Server, local.Id, f.Ct))?.LocalId);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task EveryLinkAnswering404AtOnceMarksNothing()
|
||||
{
|
||||
@@ -307,6 +328,10 @@ public sealed class SyncServiceCopyTests(TestContext context)
|
||||
Assert.Equal((0, 1), (pair.Score.DeletedHere, pair.Score.DeletedThere));
|
||||
Assert.True(pair.IsListed);
|
||||
Assert.True(pair.NeedsAttention);
|
||||
|
||||
// A photo deleted on this PC only: counted, never a warning (the user's own cull).
|
||||
var culled = pair with { Score = pair.Score with { DeletedHere = 2, DeletedThere = 0 } };
|
||||
Assert.False(culled.NeedsAttention);
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
||||
Reference in new issue
Block a user