A refresh no longer links copies by content behind the user's back. After the gate is released, CopyFinder looks for copies whose ids differ: the server's photo lookup (or 1.1's gate and the hints on an older server), session keys, and an exact comparison by manifest, bounded per refresh and remembered in copy_probes so nothing is compared twice while neither side moves. What a pair becomes is the Link matches setting's call: asked by default, linked by itself only as the setting allows, through a compare-and-set that a Keep apart wins. Local detection finds copies inside this PC's archives and never links them. SyncService gives every link its pair, adds Unlink (kept apart, observation kept), marks pairs whose server sequence answers 404 (once per refresh, twice reads deleted, never on an address key or in a 404 sweep), keeps deletion counts current at each comparison, writes an Integrate's agreed details to both sides by content (ApplyAgreedAsync) and queues uploads at a given priority. CopyReviewBuilder assembles what the Compare dialog shows. Refs #73 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
112 lines
5.1 KiB
C#
112 lines
5.1 KiB
C#
using Chronos.Data.Copies;
|
|
using Chronos.Data.Sync;
|
|
using Chronos.Data.Tests.Sync;
|
|
using Chronos.Protocol;
|
|
using Chronos.Testing;
|
|
|
|
namespace Chronos.Data.Tests.Copies;
|
|
|
|
/// <summary>What the Compare dialog shows of a pair (owner review 6, #73; design §4.4): facts, photos, details and what can be done.</summary>
|
|
[Category("sync")]
|
|
public sealed class CopyReviewBuilderTests(TestContext context)
|
|
{
|
|
private static CopyPlanContext Context(bool canUpload = true, bool canDelete = false) =>
|
|
new("PC", "NAS", canUpload, true, true, canDelete, canDelete, false, null, new HashSet<Guid>(), new HashSet<Guid>());
|
|
|
|
private static CopyReviewBuilder Builder(SyncFixture f) => new(f.Db, f.Archive.Service.Projects, new CopySides(f.Db));
|
|
|
|
/// <summary>A local copy and a server copy sharing two photos, each holding one more, with different settings; asked about.</summary>
|
|
private static async Task<(FoundCopy Pair, Guid LocalId, FakeSequence Remote)> AskedAsync(SyncFixture f)
|
|
{
|
|
var photos = f.NewPhotos(4);
|
|
var local = await f.LocalAsync("Comet", photos.Take(3).ToList(), SyncFixture.Window33);
|
|
var remote = f.Remote.Add("Comet", [photos[0], photos[1], photos[3]], SyncFixture.Window41);
|
|
await f.RefreshAsync();
|
|
return ((await f.Sync.Copies.ListByServerAsync(f.Server, f.Ct)).Single(), local.Id, remote);
|
|
}
|
|
|
|
[Test]
|
|
public async Task AServerPairShowsBothSidesAndCanBeIntegrated()
|
|
{
|
|
await using var f = await SyncFixture.CreateAsync(context);
|
|
f.Remote.Capabilities.Add(ServerCapabilities.PhotoLookup);
|
|
f.Remote.Capabilities.Add(ServerCapabilities.UploadInto);
|
|
var (pair, localId, remote) = await AskedAsync(f);
|
|
|
|
var review = await Builder(f).BuildAsync(pair, f.Remote, Context(), f.Ct);
|
|
|
|
Assert.Equal(("Comet", f.Archive.Archive.Id, 3, 3), (review.Here.Title, review.Here.ArchiveId, review.Here.Photos, review.Here.Hashed));
|
|
Assert.Equal((3, (Guid?)null), (review.There.Photos, review.There.ArchiveId));
|
|
Assert.Equal((2, 1, 1), (review.Photos.Score.Shared, review.Photos.Score.OnlyHere, review.Photos.Score.OnlyThere));
|
|
Assert.True(review.Details.Any(d => d.Path.StartsWith("exposure", StringComparison.Ordinal)));
|
|
Assert.Empty(review.Can.Blocks);
|
|
Assert.True(review.Can.Integrate);
|
|
Assert.True(review.Can.LinkOnly);
|
|
Assert.False(review.Can.DeleteThere);
|
|
Assert.Equal(pair.Id, review.Copy.Id);
|
|
Assert.Equal(localId, review.Copy.LocalId);
|
|
Assert.Equal(remote.Id, review.Copy.RemoteId);
|
|
}
|
|
|
|
[Test]
|
|
public async Task AnOlderServerOrMissingRightsBlockIntegrateButNotLinkOnly()
|
|
{
|
|
await using var f = await SyncFixture.CreateAsync(context);
|
|
var (pair, _, _) = await AskedAsync(f);
|
|
|
|
var review = await Builder(f).BuildAsync(pair, f.Remote, Context(canUpload: false, canDelete: true), f.Ct);
|
|
|
|
Assert.SequenceEqual([CopyBlock.NeedsNewerServer, CopyBlock.NoUploadRight], review.Can.Blocks);
|
|
Assert.False(review.Can.Integrate);
|
|
Assert.True(review.Can.LinkOnly);
|
|
Assert.True(review.Can.DeleteThere);
|
|
}
|
|
|
|
[Test]
|
|
public async Task ALinkToAnotherCopyIsTaken()
|
|
{
|
|
await using var f = await SyncFixture.CreateAsync(context);
|
|
f.Remote.Capabilities.Add(ServerCapabilities.PhotoLookup);
|
|
f.Remote.Capabilities.Add(ServerCapabilities.UploadInto);
|
|
var (pair, localId, _) = await AskedAsync(f);
|
|
var other = f.Remote.Add("Harbour", f.NewPhotos(1));
|
|
await f.Sync.LinkAsync(f.Server, other.Id, localId, f.Ct);
|
|
|
|
var review = await Builder(f).BuildAsync(pair, f.Remote, Context(), f.Ct);
|
|
|
|
Assert.Contains(CopyBlock.LinkTaken, review.Can.Blocks);
|
|
Assert.False(review.Can.Integrate);
|
|
Assert.False(review.Can.LinkOnly);
|
|
}
|
|
|
|
[Test]
|
|
public async Task TwoLocalCopiesCanBeMergedNeverLinked()
|
|
{
|
|
await using var f = await SyncFixture.CreateAsync(context);
|
|
var photos = f.NewPhotos(3);
|
|
await f.LocalAsync("Comet", photos);
|
|
await f.LocalAsync("Comet (card)", photos.Take(2).ToList(), SyncFixture.Window41);
|
|
var pair = (await f.Sync.Finder.FindLocalAsync(f.Ct)).New.Single();
|
|
|
|
var review = await Builder(f).BuildAsync(pair, null, Context(), f.Ct);
|
|
|
|
Assert.Equal((2, 1, 0), (review.Photos.Score.Shared, review.Photos.Score.OnlyHere + review.Photos.Score.OnlyThere, review.Photos.Score.Differs));
|
|
Assert.Equal(f.Archive.Archive.Id, review.There.ArchiveId);
|
|
Assert.NotEmpty(review.Details);
|
|
Assert.True(review.Can.Integrate);
|
|
Assert.False(review.Can.LinkOnly);
|
|
Assert.False(review.Can.DeleteThere);
|
|
}
|
|
|
|
[Test]
|
|
public async Task AServerPairNeedsItsServer()
|
|
{
|
|
await using var f = await SyncFixture.CreateAsync(context);
|
|
var (pair, _, _) = await AskedAsync(f);
|
|
|
|
await Assert.ThrowsAsync<ArgumentException>(() => Builder(f).BuildAsync(pair, null, Context(), f.Ct));
|
|
await Assert.ThrowsAsync<ArgumentException>(() =>
|
|
Builder(f).BuildAsync(pair, new FakeSyncRemote { Server = "https://other.test:8443" }, Context(), f.Ct));
|
|
}
|
|
}
|