CI / Build and test (push) Successful in 13m44s
CI / Windows tests and installer (push) Skipped
CI / YAML check (push) Successful in 16s
Release / Build, test and publish (push) Successful in 26m34s
CI / PostgreSQL 16 integration (push) Failing after 17m36s
CI / PostgreSQL 17 integration (push) Failing after 15m36s
CI / Docker image (push) Successful in 1m12s
Release / Server image (push) Failing after 15s
The same time-lapse on a server and on this PC under different ids, or twice on this PC, is recognised, compared and settled as the owner asked in owner review 6. Matches are found after each sync refresh, through the server's new photo lookup, and after the jobs that change photos. The default is to ask every time. Server › Matches offers: - Keep apart, which is remembered; - Link only and Unlink; - the Compare dialog: photos, details line by line, projects and the plan. Integrate completes both sides. Photos default to Union, projects are copied across, and a losing version goes to the trash only after a hash check. Afterwards new photos move by themselves, and deletions wait for the user. A merge of two local sequences verifies every photo before the other sequence goes to its archive's trash. Upload all local skips suspected matches and flags them. Migration 0012 adds the found_copies and copy_probes tables. Jobs 25 (Integrate) and 26 (MergeSequences) are new, and so are the server capabilities photo-lookup and upload-into. Refs #73 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Alberto Balbo <alberto.balbo.96@gmail.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));
|
|
}
|
|
}
|