feat(copies): matches between this PC and the server, Integrate and merge (owner review 6, v1.2.0) (#74)
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
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>
This commit was merged in pull request #74.
This commit is contained in:
1 parent
43719bb5c5
commit
f33bcac32e
586 files changed
+41546
-280
No files matched your search
@@ -0,0 +1,228 @@
|
||||
using Chronos.Core.Project;
|
||||
using Chronos.Data.Sync;
|
||||
using Chronos.Protocol;
|
||||
using Chronos.Testing;
|
||||
|
||||
namespace Chronos.Data.Tests.Sync;
|
||||
|
||||
/// <summary>The photo-by-photo comparison of two copies (owner review 6, #73; design §4.1).</summary>
|
||||
[Category("sync")]
|
||||
public sealed class CopyComparisonTests
|
||||
{
|
||||
private static readonly DateTime Start = new(2026, 9, 28, 18, 0, 0, 250);
|
||||
|
||||
private static string Sha(int n) => Convert.ToHexStringLower(BitConverter.GetBytes((long)n)).PadLeft(64, 'a');
|
||||
|
||||
/// <summary>Photo n: its own SHA-256, size and a sub-second capture time 5 s after the one before.</summary>
|
||||
private static CopyPhotoInput Photo(int n, int index = -1, bool hashed = true, bool unusable = false, string? name = null, DateTime? at = null, long? size = null) =>
|
||||
new(Guid.NewGuid(), index < 0 ? n : index, name ?? $"IMG_{n:0000}.JPG", hashed ? Sha(n) : null, size ?? 1000 + n, at ?? Start.AddSeconds(5 * n), unusable);
|
||||
|
||||
private static CopySideInput Side(params CopyPhotoInput[] photos) => new(photos, []);
|
||||
|
||||
private static CopySideInput Side(IEnumerable<CopyPhotoInput> photos, params RemovedPhotoDto[] removed) => new([.. photos], removed);
|
||||
|
||||
private static RemovedPhotoDto Deleted(int n) => new(Sha(n), null, "deleted", DateTimeOffset.UnixEpoch);
|
||||
|
||||
private static RemovedPhotoDto Replaced(int n, int by) => new(Sha(n), Sha(by), "replaced", DateTimeOffset.UnixEpoch);
|
||||
|
||||
private static int Count(CopyComparisonResult result, PhotoClass c) => result.Of(c).Count();
|
||||
|
||||
[Test]
|
||||
public void IdenticalCopiesAreAllSame()
|
||||
{
|
||||
var result = CopyComparer.Compare(Side(Photo(1), Photo(2), Photo(3)), Side(Photo(1), Photo(2), Photo(3)));
|
||||
Assert.Equal(3, Count(result, PhotoClass.Same));
|
||||
Assert.Equal((3, 0, 0, 1000, 1000), (result.Score.Shared, result.Score.OnlyHere, result.Score.OnlyThere, result.Score.Containment, result.Score.Overlap));
|
||||
Assert.True(result.Score.Identical);
|
||||
Assert.True(result.Score.ByHash);
|
||||
Assert.Count(9, result.Totals);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ASubsetReadsFullyContainedAndASupersetToo()
|
||||
{
|
||||
// The Uploader sent part of the card: the server holds a subset.
|
||||
var all = Enumerable.Range(1, 10).Select(n => Photo(n)).ToArray();
|
||||
var part = Enumerable.Range(1, 4).Select(n => Photo(n)).ToArray();
|
||||
var subset = CopyComparer.Compare(Side(all), Side(part));
|
||||
Assert.Equal((4, 6, 0, 1000, 400), (subset.Score.Shared, subset.Score.OnlyHere, subset.Score.OnlyThere, subset.Score.Containment, subset.Score.Overlap));
|
||||
Assert.False(subset.Score.Identical);
|
||||
var superset = CopyComparer.Compare(Side(part), Side(all));
|
||||
Assert.Equal((4, 0, 6, 1000), (superset.Score.Shared, superset.Score.OnlyHere, superset.Score.OnlyThere, superset.Score.Containment));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AConvertedPhotoIsConvertedNotOnlyOnOneSide()
|
||||
{
|
||||
// This PC replaced photo 2 by a converted file (photo 50's content); the server still holds the original.
|
||||
var here = Side([Photo(1), Photo(50, index: 1, at: Start.AddSeconds(10))], Replaced(2, 50));
|
||||
var result = CopyComparer.Compare(here, Side(Photo(1), Photo(2)));
|
||||
var converted = Assert.Contains(result.Photos, p => p.Class == PhotoClass.Converted);
|
||||
Assert.Equal((Sha(50), Sha(2)), (converted.Here!.Sha256, converted.There!.Sha256));
|
||||
Assert.Equal((2, 0, 0), (result.Score.Shared, result.Score.OnlyHere, result.Score.OnlyThere));
|
||||
Assert.True(result.Score.Identical);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ATombstonedPhotoIsDeletedOnThatSideNotOnlyOnTheOther()
|
||||
{
|
||||
var result = CopyComparer.Compare(Side([Photo(1), Photo(2)], Deleted(3)), Side([Photo(1), Photo(3)], Deleted(2)));
|
||||
Assert.Equal(Sha(2), Assert.Contains(result.Photos, p => p.Class == PhotoClass.DeletedThere).Key);
|
||||
Assert.Equal(Sha(3), Assert.Contains(result.Photos, p => p.Class == PhotoClass.DeletedHere).Key);
|
||||
Assert.Equal((0, 0, 1, 1, 2), (result.Score.OnlyHere, result.Score.OnlyThere, result.Score.DeletedHere, result.Score.DeletedThere, result.Score.SharedRemoved));
|
||||
Assert.False(result.Score.Identical);
|
||||
Assert.Equal(1000, result.Score.Containment);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CopiesOfOnePhotoInsideASideCountOnce()
|
||||
{
|
||||
var copy = Photo(2) with { FrameId = Guid.NewGuid(), Index = 5, FileName = "IMG_0002 (1).JPG" };
|
||||
var result = CopyComparer.Compare(Side(Photo(1), Photo(2), copy), Side(Photo(1), Photo(2)));
|
||||
Assert.Equal((2, 2, 2), (result.Score.Shared, result.Score.LocalPhotos, result.Score.OtherPhotos));
|
||||
var same = Assert.Contains(result.Photos, p => p.Key == Sha(2));
|
||||
Assert.Equal((2, 1), (same.HereOccurrences, same.ThereOccurrences));
|
||||
Assert.True(result.Score.Identical);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AnUnhashedPhotoMatchesBySizeAndMillisecond()
|
||||
{
|
||||
var result = CopyComparer.Compare(Side(Photo(1), Photo(2, hashed: false)), Side(Photo(1), Photo(2)));
|
||||
var unhashed = Assert.Contains(result.Photos, p => p.Class == PhotoClass.SameUnhashed);
|
||||
Assert.Equal(Sha(2), unhashed.Key);
|
||||
Assert.Equal((1, 1), (result.Score.Shared, result.Score.SharedUnhashed));
|
||||
Assert.True(result.Score.Identical);
|
||||
Assert.False(result.Score.ByHash);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void UnhashedLeftoversStayOnTheirSide()
|
||||
{
|
||||
// Another size at the same time is another photo: unlike CompareOriginals, nothing is assumed to match.
|
||||
var result = CopyComparer.Compare(Side(Photo(1), Photo(2, hashed: false, size: 7)), Side(Photo(1), Photo(3, hashed: false)));
|
||||
Assert.Equal((1, 0, 1, 1), (result.Score.Shared, result.Score.SharedUnhashed, result.Score.OnlyHere, result.Score.OnlyThere));
|
||||
Assert.True(Assert.Contains(result.Photos, p => p.Class == PhotoClass.OnlyHere).Key.StartsWith("u:7:", StringComparison.Ordinal));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DiffersPairsOnePhotoPerSideWithTheSameNameAndSubSecondInstant()
|
||||
{
|
||||
// Photo 2 edited on one side: another SHA-256, same name, same sub-second capture time.
|
||||
var edited = Photo(2) with { Sha256 = Sha(99), Size = 4242 };
|
||||
var result = CopyComparer.Compare(Side(Photo(1), Photo(2)), Side(Photo(1), edited));
|
||||
var differs = Assert.Contains(result.Photos, p => p.Class == PhotoClass.Differs);
|
||||
Assert.Equal((Sha(2), Sha(99), 1002L), (differs.Here!.Sha256, differs.There!.Sha256, differs.Bytes));
|
||||
Assert.Equal((1, 0, 0), (result.Score.Differs, result.Score.OnlyHere, result.Score.OnlyThere));
|
||||
Assert.False(result.Score.Identical);
|
||||
var total = Assert.Contains(result.Totals, t => t.Class == PhotoClass.Differs);
|
||||
Assert.Equal((1002L, 4242L), (total.HereBytes, total.ThereBytes));
|
||||
|
||||
// Another name, or another millisecond, is no pair.
|
||||
Assert.Equal(0, CopyComparer.Compare(Side(Photo(2)), Side(edited with { FileName = "DSC_0002.JPG" })).Score.Differs);
|
||||
Assert.Equal(0, CopyComparer.Compare(Side(Photo(2)), Side(edited with { CapturedAt = edited.CapturedAt!.Value.AddMilliseconds(1) })).Score.Differs);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WholeSecondCaptureTimesNeverPairAsDiffers()
|
||||
{
|
||||
// A camera that records whole seconds: two different photos at one second with one name are not one photo edited.
|
||||
var at = new DateTime(2026, 9, 28, 18, 0, 0);
|
||||
var result = CopyComparer.Compare(Side(Photo(1, at: at, name: "IMG_0001.JPG")), Side(Photo(2, at: at, name: "IMG_0001.JPG")));
|
||||
Assert.Equal((0, 1, 1), (result.Score.Differs, result.Score.OnlyHere, result.Score.OnlyThere));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BurstsNeverPairAsDiffers()
|
||||
{
|
||||
// Two photos of a burst at one instant on each side: which is which cannot be told, so nothing pairs.
|
||||
var at = Start.AddMilliseconds(130);
|
||||
var result = CopyComparer.Compare(
|
||||
Side(Photo(1, at: at, name: "IMG_0001.JPG"), Photo(2, at: at, name: "IMG_0001.JPG")),
|
||||
Side(Photo(3, at: at, name: "IMG_0001.JPG"), Photo(4, at: at, name: "IMG_0001.JPG")));
|
||||
Assert.Equal((0, 2, 2), (result.Score.Differs, result.Score.OnlyHere, result.Score.OnlyThere));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TwoVersionsAfterAKeepBothAreVersions()
|
||||
{
|
||||
// A Union keep-both left both versions of photo 2 on both sides, at its one capture instant.
|
||||
var version = Photo(2) with { FrameId = Guid.NewGuid(), Index = 3, Sha256 = Sha(99), Size = 4242 };
|
||||
var result = CopyComparer.Compare(Side(Photo(1), Photo(2), version), Side(Photo(1), Photo(2), version with { FrameId = Guid.NewGuid() }));
|
||||
Assert.Equal(2, Count(result, PhotoClass.Versions));
|
||||
Assert.Equal((3, 2), (result.Score.Shared, result.Score.Versions));
|
||||
Assert.True(result.Score.Identical);
|
||||
|
||||
// At a whole second they stay Same.
|
||||
var at = new DateTime(2026, 9, 28, 18, 0, 10);
|
||||
var whole = CopyComparer.Compare(Side(Photo(2, at: at), version with { CapturedAt = at }), Side(Photo(2, at: at), version with { CapturedAt = at }));
|
||||
Assert.Equal((2, 0), (Count(whole, PhotoClass.Same), whole.Score.Versions));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AnUnusableFrameHoldsNothingAndMarksTheRepair()
|
||||
{
|
||||
var result = CopyComparer.Compare(Side(Photo(1), Photo(2, unusable: true)), Side(Photo(1), Photo(2), Photo(3, unusable: true)));
|
||||
var brought = Assert.Contains(result.Photos, p => p.Key == Sha(2));
|
||||
Assert.Equal((PhotoClass.OnlyThere, true, false), (brought.Class, brought.RepairsHere, brought.RepairsThere));
|
||||
Assert.DoesNotContain(Sha(3), result.Photos.Select(p => p.Key));
|
||||
Assert.Equal((1, 2), (result.Score.LocalPhotos, result.Score.OtherPhotos));
|
||||
|
||||
// A Missing or Corrupt frame there is repaired by this PC's copy.
|
||||
var other = CopyComparer.Compare(Side(Photo(1), Photo(2)), Side(Photo(1), Photo(2, unusable: true)));
|
||||
var sent = Assert.Contains(other.Photos, p => p.Key == Sha(2));
|
||||
Assert.Equal((PhotoClass.OnlyHere, true), (sent.Class, sent.RepairsThere));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BytesArePerClassAndSide()
|
||||
{
|
||||
var result = CopyComparer.Compare(Side(Photo(1), Photo(2)), Side(Photo(1), Photo(3)));
|
||||
Assert.Equal((1001L, 1001L), Totals(PhotoClass.Same));
|
||||
Assert.Equal((1002L, 0L), Totals(PhotoClass.OnlyHere));
|
||||
Assert.Equal((0L, 1003L), Totals(PhotoClass.OnlyThere));
|
||||
Assert.Equal(1003L, Assert.Contains(result.Photos, p => p.Class == PhotoClass.OnlyThere).Bytes);
|
||||
|
||||
(long, long) Totals(PhotoClass c)
|
||||
{
|
||||
var total = result.Totals.Single(t => t.Class == c);
|
||||
return (total.HereBytes, total.ThereBytes);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TheResultDoesNotDependOnTheOrderOfTheInputs()
|
||||
{
|
||||
var edited = Photo(7) with { Sha256 = Sha(97) };
|
||||
CopyPhotoInput[] here = [Photo(1), Photo(2), Photo(3, hashed: false), Photo(4), Photo(5), Photo(6), Photo(7), Photo(8, unusable: true)];
|
||||
CopyPhotoInput[] there = [Photo(1), Photo(3), Photo(4, hashed: false), Photo(6), edited, Photo(8), Photo(9)];
|
||||
var removedHere = new[] { Deleted(9) };
|
||||
var removedThere = new[] { Deleted(5) };
|
||||
var a = CopyComparer.Compare(Side(here, removedHere), Side(there, removedThere));
|
||||
var b = CopyComparer.Compare(Side(Enumerable.Reverse(here), removedHere), Side(Enumerable.Reverse(there), removedThere));
|
||||
Assert.Equal(a.Score, b.Score);
|
||||
Assert.SequenceEqual(a.Photos.Select(p => (p.Class, p.Key, p.Here?.FrameId, p.There?.FrameId)), b.Photos.Select(p => (p.Class, p.Key, p.Here?.FrameId, p.There?.FrameId)));
|
||||
Assert.Equal((2, 2, 1, 1, 1, 1, 1), (a.Score.Shared, a.Score.SharedUnhashed, a.Score.Differs, a.Score.DeletedHere, a.Score.DeletedThere, a.Score.OnlyHere, a.Score.OnlyThere));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DeletionsCountWhatTheOtherSideTombstonedAndNoLongerHolds()
|
||||
{
|
||||
var tombstones = SyncTombstones.FromDtos([Deleted(3)], [Deleted(2), Deleted(1)]);
|
||||
FramePhoto[] here = [new(Sha(1), 1, null), new(Sha(2), 2, null), new(Sha(2), 2, null)];
|
||||
FramePhoto[] there = [new(Sha(1), 1, null), new(Sha(3), 3, null)];
|
||||
Assert.Equal((1, 1), CopyComparer.Deletions(here, there, tombstones));
|
||||
Assert.Equal((0, 0), CopyComparer.Deletions(here, there, SyncTombstones.None));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TombstonesFromDtosReadBothSides()
|
||||
{
|
||||
var tombstones = SyncTombstones.FromDtos([Replaced(2, 50), Deleted(4)], [Deleted(5)]);
|
||||
Assert.Equal(tombstones.Canonical(Sha(50)), tombstones.Canonical(Sha(2)));
|
||||
Assert.True(tombstones.DeletedLocally(Sha(4)));
|
||||
Assert.False(tombstones.DeletedLocally(Sha(2)));
|
||||
Assert.True(tombstones.DeletedRemotely(Sha(5)));
|
||||
Assert.True(SyncTombstones.FromDtos([], null).IsEmpty);
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,8 @@ internal sealed class FakeSyncRemote : ISyncRemote
|
||||
private readonly Channel<ServerEvent> _events = Channel.CreateUnbounded<ServerEvent>();
|
||||
private readonly Dictionary<string, FakeSequence> _sessions = [];
|
||||
|
||||
public string Server => "https://nas.test:8443";
|
||||
/// <summary>The server's key: an address key unless a test names one by id (<c>id:<N></c>).</summary>
|
||||
public string Server { get; init; } = "https://nas.test:8443";
|
||||
|
||||
public Dictionary<Guid, FakeSequence> Sequences { get; } = [];
|
||||
|
||||
@@ -59,6 +60,155 @@ internal sealed class FakeSyncRemote : ISyncRemote
|
||||
|
||||
public Task<int> SettingsFormatAsync(CancellationToken cancellationToken) => Task.FromResult(SettingsFormat);
|
||||
|
||||
/// <summary>
|
||||
/// The capabilities the server announces (<see cref="ServerCapabilities"/>): none by default, an older server's path
|
||||
/// (owner review 6, #73); tests of the lookup and of uploads into a target opt in.
|
||||
/// </summary>
|
||||
public HashSet<string> Capabilities { get; } = new(StringComparer.Ordinal);
|
||||
|
||||
public Task<IReadOnlySet<string>> CapabilitiesAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
lock (_gate) return Task.FromResult<IReadOnlySet<string>>(new HashSet<string>(Capabilities, StringComparer.Ordinal));
|
||||
}
|
||||
|
||||
/// <summary>Lookup requests so far, as received.</summary>
|
||||
public List<PhotoLookupRequest> Lookups { get; } = [];
|
||||
|
||||
/// <summary>Uploads into a target so far (<see cref="UploadFileIntoAsync"/>), and how many the server filed from a copy it held elsewhere.</summary>
|
||||
public int IntoUploads { get; private set; }
|
||||
|
||||
public int CopiedInto { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Uploads into a target refused with 403, as for an account with Read and Upload but not Edit that does not own the
|
||||
/// target; <see cref="RefusedInto"/> counts them.
|
||||
/// </summary>
|
||||
public bool ForbidInto { get; set; }
|
||||
|
||||
public int RefusedInto { get; private set; }
|
||||
|
||||
/// <summary>Runs once, before the next frame deletion is answered (the server sequence changing meanwhile).</summary>
|
||||
public Action? OnceBeforeDelete { get; set; }
|
||||
|
||||
/// <summary>Frame deletions refused with 403, as for an account that is neither the owner nor an admin.</summary>
|
||||
public bool ForbidFrameDeletes { get; set; }
|
||||
|
||||
/// <summary>Frames moved to the server's trash so far, by sequence.</summary>
|
||||
public List<(Guid SequenceId, FakeFrame Frame)> Trashed { get; } = [];
|
||||
|
||||
/// <summary>Files <paramref name="sequence"/> under <paramref name="sessionKey"/>, as an upload with that key would.</summary>
|
||||
public void FileUnder(string sessionKey, FakeSequence sequence)
|
||||
{
|
||||
lock (_gate) _sessions[sessionKey] = sequence;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Like the server (owner review 6, #73): per probe, the sequences holding its hashes in a frame (a sequence it never
|
||||
/// hashed lists none), tombstoning them (by the photo's or its replacement's SHA-256), holding a frame of its unhashed keys
|
||||
/// by size and capture millisecond, or filed under its session key. 404 without <see cref="ServerCapabilities.PhotoLookup"/>,
|
||||
/// 413 beyond the limits.
|
||||
/// </summary>
|
||||
public Task<PhotoLookupResponse> LookupPhotosAsync(PhotoLookupRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
lock (_gate)
|
||||
{
|
||||
if (!Capabilities.Contains(ServerCapabilities.PhotoLookup)) throw new ChronosApiException(HttpStatusCode.NotFound, new ApiError("not_found", "route"));
|
||||
if (request.Probes.Count > PhotoLookupRequest.MaxProbes || request.CountItems() > PhotoLookupRequest.MaxItems)
|
||||
throw new ChronosApiException(HttpStatusCode.RequestEntityTooLarge, new ApiError("too_many", "probes"));
|
||||
Lookups.Add(request);
|
||||
var results = new List<ProbeResult>();
|
||||
foreach (var probe in request.Probes)
|
||||
{
|
||||
var hashes = probe.Sha256.Select(h => h.ToLowerInvariant()).ToHashSet(StringComparer.Ordinal);
|
||||
var keys = (probe.Unhashed ?? []).Select(k => (k.Size, Ms(k.CapturedAt))).ToHashSet();
|
||||
var filed = probe.SessionKey is { } key && _sessions.TryGetValue(key, out var held) ? held : null;
|
||||
var hits = new List<PhotoLookupHit>();
|
||||
foreach (var sequence in Sequences.Values)
|
||||
{
|
||||
var inFrames = sequence.Unhashed ? 0 : sequence.Frames.Select(f => f.Sha256).Where(hashes.Contains).Distinct(StringComparer.Ordinal).Count();
|
||||
var removed = hashes.Count(h => sequence.Removed.Any(r => r.Sha256 == h || r.Replacement == h));
|
||||
var unhashed = keys.Count(k => sequence.Frames.Any(f => f.CapturedAt is { } at && f.Bytes.Length == k.Size && Ms(at) == k.Item2));
|
||||
var session = ReferenceEquals(filed, sequence);
|
||||
if (inFrames + removed + unhashed > 0 || session) hits.Add(new PhotoLookupHit(sequence.Id, inFrames, removed, unhashed, session));
|
||||
}
|
||||
results.Add(new ProbeResult(probe.Key, hits));
|
||||
}
|
||||
return Task.FromResult(new PhotoLookupResponse(results));
|
||||
}
|
||||
|
||||
static long Ms(DateTime at) => at.Ticks / TimeSpan.TicksPerMillisecond;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Like the server with <see cref="ServerCapabilities.UploadInto"/>: the photo is filed into the target even when another
|
||||
/// sequence holds it (a server-side copy, counted in <see cref="CopiedInto"/>); one the target holds answers its frame, one
|
||||
/// it tombstoned answers none. Without the capability the server ignores the flag: an upload as before.
|
||||
/// </summary>
|
||||
public async Task<CompleteUploadResponse?> UploadFileIntoAsync(string path, Guid sequenceId, string sha256, DateTime? capturedAt,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
bool capable;
|
||||
lock (_gate) capable = Capabilities.Contains(ServerCapabilities.UploadInto);
|
||||
if (!capable) return await UploadFileAsync(path, sequenceId, null, sha256, capturedAt, cancellationToken);
|
||||
if (ForbidInto)
|
||||
{
|
||||
lock (_gate) RefusedInto++;
|
||||
throw new ChronosApiException(HttpStatusCode.Forbidden, new ApiError("forbidden", "into"));
|
||||
}
|
||||
var bytes = await File.ReadAllBytesAsync(path, cancellationToken);
|
||||
if (Convert.ToHexStringLower(SHA256.HashData(bytes)) != sha256)
|
||||
throw new ChronosApiException(HttpStatusCode.BadRequest, new ApiError("hash_mismatch", "hash"));
|
||||
lock (_gate)
|
||||
{
|
||||
IntoUploads++;
|
||||
var target = Find(sequenceId);
|
||||
if (target.Removed.Any(r => r.Sha256 == sha256)) return null;
|
||||
var index = target.Frames.FindIndex(f => f.Sha256 == sha256);
|
||||
if (index >= 0) return new CompleteUploadResponse(target.Frames[index].Id, target.Id, index);
|
||||
if (Sequences.Values.Where(s => !s.Unhashed && s != target).SelectMany(s => s.Frames).Any(f => f.Sha256 == sha256)) CopiedInto++;
|
||||
var frame = target.AddFrame(bytes, Path.GetFileName(path), capturedAt);
|
||||
return new CompleteUploadResponse(frame.Id, target.Id, target.Frames.IndexOf(frame));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Like the server's <c>frames/delete</c>: 404 for an unknown sequence, 403 with <see cref="ForbidFrameDeletes"/>, 409
|
||||
/// <c>frames_conflict</c> when a frame is not there or the frames version moved, 409 <c>would_empty</c>; a dry run answers
|
||||
/// the plan; else the frames go to the trash, each leaving a tombstone, and the frames version moves.
|
||||
/// </summary>
|
||||
public Task<FrameDeleteResultDto> DeleteFramesAsync(Guid sequenceId, FrameDeleteRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
if (OnceBeforeDelete is { } before)
|
||||
{
|
||||
OnceBeforeDelete = null;
|
||||
before();
|
||||
}
|
||||
lock (_gate)
|
||||
{
|
||||
var sequence = Find(sequenceId);
|
||||
if (ForbidFrameDeletes) throw new ChronosApiException(HttpStatusCode.Forbidden, new ApiError("forbidden", "delete"));
|
||||
var wanted = request.FrameIds.ToHashSet();
|
||||
var frames = sequence.Frames.Where(f => wanted.Contains(f.Id)).ToList();
|
||||
if (frames.Count != wanted.Count || (request.ExpectedFramesVersion is { } expected && expected != sequence.FramesVersion))
|
||||
throw new ChronosApiException(HttpStatusCode.Conflict, new ApiError("frames_conflict", "changed"));
|
||||
if (frames.Count == sequence.Frames.Count) throw new ChronosApiException(HttpStatusCode.Conflict, new ApiError("would_empty", "empty"));
|
||||
var bytes = frames.Sum(f => (long)f.Bytes.Length);
|
||||
if (request.DryRun)
|
||||
return Task.FromResult(new FrameDeleteResultDto(sequenceId, frames.Count, bytes, sequence.FramesVersion, sequence.Frames.Count, null, true));
|
||||
var at = DateTimeOffset.UtcNow;
|
||||
foreach (var frame in frames)
|
||||
{
|
||||
sequence.Frames.Remove(frame);
|
||||
Trashed.Add((sequenceId, frame));
|
||||
if (!sequence.Removed.Any(r => r.Sha256 == frame.Sha256)) sequence.Removed.Add(new RemovedPhotoDto(frame.Sha256, null, "deleted", at));
|
||||
}
|
||||
sequence.FramesVersion++;
|
||||
sequence.UpdatedAt = at;
|
||||
return Task.FromResult(new FrameDeleteResultDto(sequenceId, frames.Count, bytes, sequence.FramesVersion, sequence.Frames.Count,
|
||||
$"trash/photos-{Guid.NewGuid():N}", false));
|
||||
}
|
||||
}
|
||||
|
||||
public FakeSequence Add(string? title, IEnumerable<byte[]> originals, string? settingsJson = null,
|
||||
SequenceStatus status = SequenceStatus.ProxiesBuilt | SequenceStatus.ThumbsBuilt)
|
||||
{
|
||||
@@ -68,6 +218,12 @@ internal sealed class FakeSyncRemote : ISyncRemote
|
||||
return sequence;
|
||||
}
|
||||
|
||||
/// <summary>Someone deletes the sequence on the server: every later call for it answers 404.</summary>
|
||||
public void Drop(Guid id)
|
||||
{
|
||||
lock (_gate) Sequences.Remove(id);
|
||||
}
|
||||
|
||||
/// <summary>Someone else edits the settings on the server.</summary>
|
||||
public void EditSettings(Guid id, string settingsJson)
|
||||
{
|
||||
@@ -357,7 +513,10 @@ internal sealed class FakeSequence
|
||||
}
|
||||
|
||||
public SequenceDto Dto() => new(Id, Title, Title ?? "Untitled", "2026/" + Id.ToString("N"), "Canon", CameraModel, null, FirstCapture, null, Frames.Count, 10,
|
||||
Frames.Sum(f => (long)f.Bytes.Length), (long)Status, Renders.Count, null, Tags, Rating, Notes, SettingsVersion, FramesVersion, 0, null, UpdatedAt);
|
||||
Frames.Sum(f => (long)f.Bytes.Length), (long)Status, Renders.Count, null, Tags, Rating, Notes, SettingsVersion, FramesVersion, 0, OwnerUserId, UpdatedAt);
|
||||
|
||||
/// <summary>The server account that owns the sequence (none by default).</summary>
|
||||
public Guid? OwnerUserId { get; set; }
|
||||
|
||||
public SequenceManifest Manifest(Func<Guid, bool> proxySent) => new(Id, FramesVersion, SettingsVersion, SettingsJson, Tags,
|
||||
[.. Frames.Select((f, i) => new ManifestFrame(f.Id, i, f.FileName, f.Bytes.Length, Unhashed ? string.Empty : f.Sha256,
|
||||
|
||||
@@ -0,0 +1,146 @@
|
||||
using Chronos.Core.IO;
|
||||
using Chronos.Core.Model;
|
||||
using Chronos.Data.Copies;
|
||||
using Chronos.Data.Jobs;
|
||||
using Chronos.Data.Sync;
|
||||
using Chronos.Testing;
|
||||
|
||||
namespace Chronos.Data.Tests.Sync;
|
||||
|
||||
/// <summary>
|
||||
/// The new photos of a pair integrated with automatic photos (owner review 6, #73; design §7.3): after a comparison the
|
||||
/// agent queues them both ways in the background; never for a pair only linked or integrated without automatic photos; a
|
||||
/// failed transfer counts, waits for its backoff, and three in a row are told.
|
||||
/// </summary>
|
||||
[Category("sync")]
|
||||
public sealed class SyncAgentCopyTests(TestContext context)
|
||||
{
|
||||
private static readonly SyncAgentOptions Quick = new()
|
||||
{
|
||||
RefreshInterval = TimeSpan.FromHours(1),
|
||||
EventDelay = TimeSpan.FromMilliseconds(20),
|
||||
MinBackoff = TimeSpan.FromMilliseconds(20),
|
||||
MaxBackoff = TimeSpan.FromMilliseconds(200),
|
||||
};
|
||||
|
||||
/// <summary>An engine that queues but never runs, so the queued jobs can be read and settled by the test.</summary>
|
||||
private static JobEngine Queue(SyncFixture f) => new(f.Db, [.. f.Sync.CreateJobHandlers(new SyncFixture.Connector(f.Remote))],
|
||||
new JobEngineOptions { Workers = 1, WorkerId = "test", PollInterval = TimeSpan.FromMilliseconds(50) });
|
||||
|
||||
/// <summary>A local sequence and a server sequence sharing two photos, each with one the other lacks, linked, in <paramref name="state"/>.</summary>
|
||||
private static async Task<(Sequence Local, FakeSequence Remote)> PairAsync(SyncFixture f, string title, CopyState state, bool autoPhotos)
|
||||
{
|
||||
var photos = f.NewPhotos(4);
|
||||
var local = await f.LocalAsync(title, photos.Take(3).ToList());
|
||||
var remote = f.Remote.Add(title + " NAS", [photos[0], photos[1], photos[3]]);
|
||||
await f.Sync.LinkAsync(f.Server, remote.Id, local.Id, f.Ct);
|
||||
var row = await f.Sync.Copies.EnsureLinkedAsync(f.Server, remote.Id, local.Id, f.Ct);
|
||||
if (state != CopyState.Linked)
|
||||
Assert.True(await f.Sync.Copies.SetStateAsync(row.Id, null, state, new CopyAnswer(null, null, null, autoPhotos, DateTimeOffset.UtcNow), f.Ct));
|
||||
return (local, remote);
|
||||
}
|
||||
|
||||
private static async Task<List<Job>> QueuedAsync(SyncFixture f, JobKind kind) =>
|
||||
[.. (await f.Db.Jobs.ListAsync(JobState.Queued, kind, 50, cancellationToken: f.Ct)).Items];
|
||||
|
||||
[Test]
|
||||
public async Task AnIntegratedPairWithAutomaticPhotosQueuesBothWaysInTheBackground()
|
||||
{
|
||||
await using var f = await SyncFixture.CreateAsync(context);
|
||||
var (local, remote) = await PairAsync(f, "Comet", CopyState.Integrated, autoPhotos: true);
|
||||
await using var engine = Queue(f);
|
||||
await using var agent = new SyncAgent(f.Sync, f.Remote, () => new SyncPolicy(), engine, Quick);
|
||||
|
||||
await agent.RefreshAsync(f.Ct);
|
||||
await agent.RefreshAsync(f.Ct);
|
||||
|
||||
var upload = (await QueuedAsync(f, JobKind.UploadCommit)).Single();
|
||||
var download = (await QueuedAsync(f, JobKind.Download)).Single();
|
||||
Assert.Equal((local.Id, JobPriority.Background), (upload.TargetIds.Single(), upload.Priority));
|
||||
Assert.Equal((remote.Id, JobPriority.Background), (download.TargetIds.Single(), download.Priority));
|
||||
Assert.Contains(local.ArchiveId.ToString(), download.ParametersJson ?? string.Empty);
|
||||
Assert.Count(0, agent.PhotoFailures);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task APairOnlyLinkedOrWithoutAutomaticPhotosQueuesNothing()
|
||||
{
|
||||
await using var f = await SyncFixture.CreateAsync(context);
|
||||
await PairAsync(f, "Linked", CopyState.Linked, autoPhotos: false);
|
||||
await PairAsync(f, "Manual", CopyState.Integrated, autoPhotos: false);
|
||||
await using var engine = Queue(f);
|
||||
await using var agent = new SyncAgent(f.Sync, f.Remote, () => new SyncPolicy(), engine, Quick);
|
||||
|
||||
await agent.RefreshAsync(f.Ct);
|
||||
|
||||
Assert.Count(0, await QueuedAsync(f, JobKind.UploadCommit));
|
||||
Assert.Count(0, await QueuedAsync(f, JobKind.Download));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task APairWhoseServerCopyIsGoneQueuesNoAutomaticPhotos()
|
||||
{
|
||||
await using var f = await SyncFixture.CreateAsync(context);
|
||||
// A server keyed by its id, so a 404 counts against the pair (design §7.5).
|
||||
var nas = new FakeSyncRemote { Server = HomeFolders.IdKey(Guid.NewGuid()) };
|
||||
var photos = f.NewPhotos(3);
|
||||
var local = await f.LocalAsync("Comet", photos);
|
||||
var remote = nas.Add("Comet NAS", photos.Take(2));
|
||||
await f.Sync.LinkAsync(nas.Server, remote.Id, local.Id, f.Ct);
|
||||
var row = await f.Sync.Copies.EnsureLinkedAsync(nas.Server, remote.Id, local.Id, f.Ct);
|
||||
Assert.True(await f.Sync.Copies.SetStateAsync(row.Id, null, CopyState.Integrated,
|
||||
new CopyAnswer(null, null, null, true, DateTimeOffset.UtcNow), f.Ct));
|
||||
nas.Drop(remote.Id);
|
||||
await using var engine = new JobEngine(f.Db, [.. f.Sync.CreateJobHandlers(new SyncFixture.Connector(nas))],
|
||||
new JobEngineOptions { Workers = 1, WorkerId = "test", PollInterval = TimeSpan.FromMilliseconds(50) });
|
||||
await using var agent = new SyncAgent(f.Sync, nas, () => new SyncPolicy(), engine, Quick);
|
||||
|
||||
await agent.RefreshAsync(f.Ct);
|
||||
await using (var session = await f.Db.Database.OpenAsync(f.Ct))
|
||||
await session.ExecuteAsync("UPDATE found_copies SET remote_gone_at = $1 WHERE id = $2", [DateTimeOffset.UtcNow.AddMinutes(-11), row.Id], f.Ct);
|
||||
await agent.RefreshAsync(f.Ct);
|
||||
|
||||
var pair = (await f.Sync.Copies.GetAsync(row.Id, f.Ct))!;
|
||||
Assert.True(pair.RemoteGoneHits > 0);
|
||||
Assert.Equal((CopyState.Integrated, true), (pair.State, pair.AutoPhotos));
|
||||
Assert.Count(0, await QueuedAsync(f, JobKind.UploadCommit));
|
||||
Assert.Count(0, await QueuedAsync(f, JobKind.Download));
|
||||
Assert.Count(0, agent.PhotoFailures);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task FailedTransfersCountWaitForTheirBackoffAndThreeInARowAreTold()
|
||||
{
|
||||
await using var f = await SyncFixture.CreateAsync(context);
|
||||
var photos = f.NewPhotos(3);
|
||||
var local = await f.LocalAsync("Comet", photos);
|
||||
var remote = f.Remote.Add("Comet NAS", photos.Take(2));
|
||||
await f.Sync.LinkAsync(f.Server, remote.Id, local.Id, f.Ct);
|
||||
var row = await f.Sync.Copies.EnsureLinkedAsync(f.Server, remote.Id, local.Id, f.Ct);
|
||||
await f.Sync.Copies.SetStateAsync(row.Id, null, CopyState.Integrated, new CopyAnswer(null, null, null, true, DateTimeOffset.UtcNow), f.Ct);
|
||||
await using var engine = Queue(f);
|
||||
await using var agent = new SyncAgent(f.Sync, f.Remote, () => new SyncPolicy(), engine, Quick);
|
||||
var told = new List<(Guid, AutoPhotoFailure)>();
|
||||
agent.PhotosNotSent += (id, failure) => told.Add((id, failure));
|
||||
|
||||
for (var attempt = 1; attempt <= SyncAgent.NotSentAfter; attempt++)
|
||||
{
|
||||
await agent.RefreshAsync(f.Ct);
|
||||
var upload = (await QueuedAsync(f, JobKind.UploadCommit)).Single();
|
||||
await f.Db.Jobs.SetStateAsync(upload.Id, JobState.Failed, "Quota reached", f.Ct);
|
||||
|
||||
await agent.RefreshAsync(f.Ct);
|
||||
Assert.Equal(new AutoPhotoFailure(attempt, "Quota reached"), agent.PhotoFailures[local.Id]);
|
||||
// Within its backoff nothing new is queued.
|
||||
Assert.Count(0, await QueuedAsync(f, JobKind.UploadCommit));
|
||||
await Task.Delay(Quick.MaxBackoff + TimeSpan.FromMilliseconds(50), f.Ct);
|
||||
}
|
||||
Assert.Equal((local.Id, SyncAgent.NotSentAfter), (told.Single().Item1, told.Single().Item2.Count));
|
||||
|
||||
await agent.RefreshAsync(f.Ct);
|
||||
var last = (await QueuedAsync(f, JobKind.UploadCommit)).Single();
|
||||
await f.Db.Jobs.SetStateAsync(last.Id, JobState.Done, null, f.Ct);
|
||||
await agent.RefreshAsync(f.Ct);
|
||||
Assert.Count(0, agent.PhotoFailures);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -54,8 +56,11 @@ internal sealed class SyncFixture : IAsyncDisposable
|
||||
return photos;
|
||||
}
|
||||
|
||||
/// <summary>A local sequence made through the archive ingest (hashed frames, a real sidecar).</summary>
|
||||
public async Task<Sequence> LocalAsync(string title, IReadOnlyList<byte[]> originals, string? settingsJson = null)
|
||||
/// <summary>
|
||||
/// A local sequence made through the archive ingest (hashed frames, a real sidecar), each frame captured 10 s after the
|
||||
/// one before from <see cref="ArchiveFixture.Start"/>, or at <paramref name="capturedAt"/>.
|
||||
/// </summary>
|
||||
public async Task<Sequence> LocalAsync(string title, IReadOnlyList<byte[]> originals, string? settingsJson = null, IReadOnlyList<DateTime>? capturedAt = null)
|
||||
{
|
||||
Guid? id = null;
|
||||
var staging = Path.Combine(Archive.Paths.StagingDirectory, "test");
|
||||
@@ -66,7 +71,7 @@ internal sealed class SyncFixture : IAsyncDisposable
|
||||
await File.WriteAllBytesAsync(path, originals[i], Ct);
|
||||
var sha = Convert.ToHexStringLower(System.Security.Cryptography.SHA256.HashData(originals[i]));
|
||||
var result = await Archive.Service.Ingest.CommitAsync(new IngestRequest(Archive.Archive.Id, id, id is null ? title : null, null, path,
|
||||
$"IMG_{i + 1:0000}.JPG", originals[i].Length, sha, ArchiveFixture.Start.AddSeconds(10 * i), null), Ct);
|
||||
$"IMG_{i + 1:0000}.JPG", originals[i].Length, sha, capturedAt?[i] ?? ArchiveFixture.Start.AddSeconds(10 * i), null), Ct);
|
||||
id = result.SequenceId;
|
||||
}
|
||||
var sequence = (await Db.Sequences.GetAsync(id!.Value, Ct))!;
|
||||
|
||||
@@ -0,0 +1,535 @@
|
||||
using Chronos.Core.IO;
|
||||
using Chronos.Core.Model;
|
||||
using Chronos.Core.Project;
|
||||
using Chronos.Data.Copies;
|
||||
using Chronos.Data.Jobs;
|
||||
using Chronos.Data.Sync;
|
||||
using Chronos.Protocol;
|
||||
using Chronos.Testing;
|
||||
|
||||
namespace Chronos.Data.Tests.Sync;
|
||||
|
||||
/// <summary>
|
||||
/// Sync with found copies (owner review 6, #73): no silent link, links by setting outside the gate, unlink, 404 marks,
|
||||
/// deletion counts and the agreed details of an Integrate.
|
||||
/// </summary>
|
||||
[Category("sync")]
|
||||
public sealed class SyncServiceCopyTests(TestContext context)
|
||||
{
|
||||
[Test]
|
||||
public async Task ARefreshLinksNothingByDefaultAndAsks()
|
||||
{
|
||||
await using var f = await SyncFixture.CreateAsync(context);
|
||||
var photos = f.NewPhotos(3);
|
||||
var local = await f.LocalAsync("Comet", photos);
|
||||
var remote = f.Remote.Add("2026-09-28 Canon", photos);
|
||||
remote.FirstCapture = local.FirstCapture;
|
||||
remote.CameraModel = local.CameraModel;
|
||||
var raised = new List<CopyFindResult>();
|
||||
f.Sync.CopiesFound += (_, result) => raised.Add(result);
|
||||
|
||||
await f.RefreshAsync();
|
||||
|
||||
Assert.Null((await f.EntryAsync("Comet")).Link);
|
||||
var pair = (await f.Sync.Copies.ListByServerAsync(f.Server, f.Ct)).Single();
|
||||
Assert.Equal(CopyState.Candidate, pair.State);
|
||||
Assert.Equal((local.Id, remote.Id), (pair.LocalId, pair.RemoteId!.Value));
|
||||
Assert.Equal(CopyEvidence.Hashes, pair.Evidence);
|
||||
Assert.Equal(3, pair.Score.Shared);
|
||||
Assert.Equal(pair.Id, raised.Single().New.Single().Id);
|
||||
Assert.Empty(raised.Single().AutoLinked);
|
||||
|
||||
// Nothing moved: nothing is compared or announced again.
|
||||
var manifests = f.Remote.ManifestCalls;
|
||||
await f.RefreshAsync();
|
||||
Assert.Equal(manifests, f.Remote.ManifestCalls);
|
||||
Assert.Count(1, raised);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task IdenticalCopiesAreLinkedByThemselvesWhenTheSettingSaysSo()
|
||||
{
|
||||
await using var f = await SyncFixture.CreateAsync(context);
|
||||
f.Remote.Capabilities.Add(ServerCapabilities.PhotoLookup);
|
||||
var photos = f.NewPhotos(3);
|
||||
var local = await f.LocalAsync("Comet", photos);
|
||||
var remote = f.Remote.Add("Comet", photos);
|
||||
var raised = new List<CopyFindResult>();
|
||||
f.Sync.CopiesFound += (_, result) => raised.Add(result);
|
||||
|
||||
await f.RefreshAsync(new SyncPolicy { Linking = CopyLinking.WhenIdentical });
|
||||
|
||||
var entry = await f.EntryAsync("Comet");
|
||||
Assert.Equal(remote.Id, entry.Link?.RemoteId);
|
||||
Assert.Equal(SyncStatus.InSync, entry.Status);
|
||||
var pair = (await f.Sync.Copies.ListByServerAsync(f.Server, f.Ct)).Single();
|
||||
Assert.Equal(CopyState.Linked, pair.State);
|
||||
Assert.Equal(pair.Id, raised.Single().AutoLinked.Single().Id);
|
||||
Assert.Equal(local.Id, pair.LocalId);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AKeepApartAnsweredMeanwhileWinsOverTheLink()
|
||||
{
|
||||
await using var f = await SyncFixture.CreateAsync(context);
|
||||
var photos = f.NewPhotos(2);
|
||||
var local = await f.LocalAsync("Comet", photos);
|
||||
var remote = f.Remote.Add("Comet", photos);
|
||||
remote.FirstCapture = local.FirstCapture;
|
||||
remote.CameraModel = local.CameraModel;
|
||||
await f.RefreshAsync();
|
||||
var pair = (await f.Sync.Copies.ListByServerAsync(f.Server, f.Ct)).Single();
|
||||
Assert.True(await f.Sync.Copies.SetStateAsync(pair.Id, CopyState.Candidate, CopyState.KeptApart,
|
||||
new CopyAnswer(pair.Fingerprint, pair.Score.Shared, null, false, DateTimeOffset.UtcNow), f.Ct));
|
||||
|
||||
var linked = await f.Sync.AutoLinkAsync(f.Remote, new SyncPolicy { Linking = CopyLinking.WhenIdentical }, pair, remote.Dto(), local, null, f.Ct);
|
||||
|
||||
Assert.False(linked);
|
||||
Assert.Null(await f.Sync.LinkOfAsync(f.Server, local.Id, f.Ct));
|
||||
Assert.Equal(CopyState.KeptApart, (await f.Sync.Copies.GetAsync(pair.Id, f.Ct))!.State);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task EveryLinkHasItsPair()
|
||||
{
|
||||
await using var f = await SyncFixture.CreateAsync(context);
|
||||
var local = await f.LocalAsync("Comet", f.NewPhotos(2));
|
||||
var remote = f.Remote.Add("Harbour", f.NewPhotos(1));
|
||||
|
||||
await f.Sync.LinkAsync(f.Server, remote.Id, local.Id, f.Ct);
|
||||
|
||||
var pair = (await f.Sync.Copies.ListByServerAsync(f.Server, f.Ct)).Single();
|
||||
Assert.Equal((CopyEvidence.Link, CopyState.Linked), (pair.Evidence, pair.State));
|
||||
Assert.Equal((local.Id, remote.Id), (pair.LocalId, pair.RemoteId!.Value));
|
||||
Assert.False(pair.IsListed);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AnUploadForAnIntegratedPairCanWaitInTheBackground()
|
||||
{
|
||||
await using var f = await SyncFixture.CreateAsync(context);
|
||||
var local = await f.LocalAsync("Comet", f.NewPhotos(1));
|
||||
await using var engine = new JobEngine(f.Db, f.Sync.CreateJobHandlers(new SyncFixture.Connector(f.Remote)));
|
||||
|
||||
var background = await f.Sync.EnqueueUploadAsync(engine, f.Server, local, JobPriority.Background, f.Ct);
|
||||
Assert.Equal(JobPriority.Background, background.Priority);
|
||||
Assert.Equal(SyncTransferKind.Upload, SyncService.TransferKind(background));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task UnlinkKeepsTheServerSequenceAndKeepsThePairApart()
|
||||
{
|
||||
await using var f = await SyncFixture.CreateAsync(context);
|
||||
var photos = f.NewPhotos(2);
|
||||
var local = await f.LocalAsync("Comet", photos);
|
||||
var remote = f.Remote.Add("Comet", photos);
|
||||
await f.Sync.LinkAsync(f.Server, remote.Id, local.Id, f.Ct);
|
||||
await f.RefreshAsync();
|
||||
Assert.Equal(SyncStatus.InSync, (await f.EntryAsync("Comet")).Status);
|
||||
|
||||
await f.Sync.UnlinkAsync(f.Server, remote.Id, local.Id, f.Ct);
|
||||
|
||||
var link = await f.Sync.Links.GetAsync(f.Server, remote.Id, f.Ct);
|
||||
Assert.NotNull(link);
|
||||
Assert.Null(link.LocalId);
|
||||
Assert.Null(await f.Sync.LinkOfAsync(f.Server, local.Id, f.Ct));
|
||||
Assert.Equal(SyncState.LocalOnly, (await f.Db.Sequences.GetAsync(local.Id, f.Ct))!.SyncState);
|
||||
var pair = (await f.Sync.Copies.ListByServerAsync(f.Server, f.Ct)).Single();
|
||||
Assert.Equal(CopyState.KeptApart, pair.State);
|
||||
Assert.Equal(2, pair.AnsweredShared);
|
||||
|
||||
// Asked again only by a large later change: the next refresh leaves the two apart.
|
||||
await f.RefreshAsync(new SyncPolicy { Linking = CopyLinking.WhenHalfShared });
|
||||
Assert.Null((await f.Sync.ListAsync(f.Server, f.Ct)).Single(e => e.Local?.Id == local.Id).Link);
|
||||
Assert.Equal(CopyState.KeptApart, (await f.Sync.Copies.GetAsync(pair.Id, f.Ct))!.State);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task A404IsCountedOncePerRefreshAndTwiceReadsDeleted()
|
||||
{
|
||||
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);
|
||||
nas.Sequences.Remove(remote.Id);
|
||||
|
||||
await f.Sync.RefreshAsync(nas, new SyncPolicy(), f.Ct);
|
||||
|
||||
Assert.Null(await f.Sync.LinkOfAsync(nas.Server, local.Id, f.Ct));
|
||||
var pair = (await f.Sync.Copies.ListByServerAsync(nas.Server, f.Ct)).Single();
|
||||
Assert.Equal(1, pair.RemoteGoneHits);
|
||||
Assert.False(pair.RemoteGone);
|
||||
|
||||
// Asked again no sooner than ten minutes after the first 404.
|
||||
await f.Sync.RefreshAsync(nas, new SyncPolicy(), f.Ct);
|
||||
Assert.Equal(1, (await f.Sync.Copies.GetAsync(pair.Id, f.Ct))!.RemoteGoneHits);
|
||||
await using (var session = await f.Db.Database.OpenAsync(f.Ct))
|
||||
await session.ExecuteAsync("UPDATE found_copies SET remote_gone_at = $1 WHERE id = $2", [DateTimeOffset.UtcNow.AddMinutes(-11), pair.Id], f.Ct);
|
||||
|
||||
await f.Sync.RefreshAsync(nas, new SyncPolicy(), f.Ct);
|
||||
|
||||
pair = (await f.Sync.Copies.GetAsync(pair.Id, f.Ct))!;
|
||||
Assert.Equal(2, pair.RemoteGoneHits);
|
||||
Assert.True(pair.RemoteGone);
|
||||
Assert.True(pair.NeedsAttention);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AMatchWhoseServerSequenceIsDeletedIsGoneAfterTheRefreshAndUploadAllSendsTheLocalOne()
|
||||
{
|
||||
await using var f = await SyncFixture.CreateAsync(context);
|
||||
var nas = new FakeSyncRemote { Server = HomeFolders.IdKey(Guid.NewGuid()) };
|
||||
var photos = f.NewPhotos(3);
|
||||
var local = await f.LocalAsync("Comet", photos);
|
||||
var remote = nas.Add("2026-09-28 Canon", photos);
|
||||
remote.FirstCapture = local.FirstCapture;
|
||||
remote.CameraModel = local.CameraModel;
|
||||
await f.Sync.RefreshAsync(nas, new SyncPolicy(), f.Ct);
|
||||
var pair = (await f.Sync.Copies.ListByServerAsync(nas.Server, f.Ct)).Single();
|
||||
Assert.Equal((CopyState.Candidate, local.Id), (pair.State, pair.LocalId));
|
||||
Assert.Null((await f.Sync.Links.GetAsync(nas.Server, remote.Id, f.Ct))!.LocalId);
|
||||
|
||||
// Deleted on the server: no longer listed, and a 404 when asked for.
|
||||
nas.Sequences.Remove(remote.Id);
|
||||
await f.Sync.RefreshAsync(nas, new SyncPolicy(), f.Ct);
|
||||
|
||||
Assert.Null(await f.Sync.Copies.GetAsync(pair.Id, f.Ct));
|
||||
var entries = (await f.Sync.ListAsync(nas.Server, f.Ct)).Where(e => e.Local?.Id == local.Id).ToList();
|
||||
var (upload, skipped) = UploadAllRule.Select(entries, await f.Sync.Copies.ListAsync(f.Ct), new HashSet<Guid>(), new HashSet<Guid>());
|
||||
Assert.Empty(skipped);
|
||||
Assert.Equal(local.Id, upload.Single().Local!.Id);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AKeptApartServerSequenceAnswering404OnceKeepsTheAnswerAndIsNeverLinkedByItself()
|
||||
{
|
||||
await using var f = await SyncFixture.CreateAsync(context);
|
||||
var nas = new FakeSyncRemote { Server = HomeFolders.IdKey(Guid.NewGuid()) };
|
||||
var photos = f.NewPhotos(3);
|
||||
var local = await f.LocalAsync("Comet", photos);
|
||||
var remote = nas.Add("2026-09-28 Canon", photos);
|
||||
remote.FirstCapture = local.FirstCapture;
|
||||
remote.CameraModel = local.CameraModel;
|
||||
await f.Sync.RefreshAsync(nas, new SyncPolicy(), f.Ct);
|
||||
var pair = (await f.Sync.Copies.ListByServerAsync(nas.Server, f.Ct)).Single();
|
||||
Assert.True(await f.Sync.Copies.SetStateAsync(pair.Id, CopyState.Candidate, CopyState.KeptApart,
|
||||
new CopyAnswer(pair.Fingerprint, pair.Score.Shared, null, false, DateTimeOffset.UtcNow), f.Ct));
|
||||
|
||||
// Moved to the server's trash and restored: one refresh gets a 404, the next lists it again.
|
||||
nas.Sequences.Remove(remote.Id);
|
||||
await f.Sync.RefreshAsync(nas, new SyncPolicy(), f.Ct);
|
||||
Assert.Equal((CopyState.KeptApart, 1), ((await f.Sync.Copies.GetAsync(pair.Id, f.Ct))!.State, (await f.Sync.Copies.GetAsync(pair.Id, f.Ct))!.RemoteGoneHits));
|
||||
nas.Sequences[remote.Id] = remote;
|
||||
await f.Sync.RefreshAsync(nas, new SyncPolicy { Linking = CopyLinking.WhenIdentical }, f.Ct);
|
||||
|
||||
// Keep separate is remembered (owner Q1): not asked again, and not linked although the photos are identical.
|
||||
var after = (await f.Sync.Copies.ListByServerAsync(nas.Server, f.Ct)).Single();
|
||||
Assert.Equal((pair.Id, CopyState.KeptApart, 0), (after.Id, after.State, after.RemoteGoneHits));
|
||||
Assert.Null(await f.Sync.LinkOfAsync(nas.Server, local.Id, f.Ct));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ASequenceReadAsDeletedOnTheServerIsClearedWhenItIsListedAgainOrLinkedAgain()
|
||||
{
|
||||
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);
|
||||
nas.Sequences.Remove(remote.Id);
|
||||
await f.Sync.RefreshAsync(nas, new SyncPolicy(), f.Ct);
|
||||
var pair = (await f.Sync.Copies.ListByServerAsync(nas.Server, f.Ct)).Single();
|
||||
await using (var session = await f.Db.Database.OpenAsync(f.Ct))
|
||||
await session.ExecuteAsync("UPDATE found_copies SET remote_gone_at = $1 WHERE id = $2", [DateTimeOffset.UtcNow.AddMinutes(-11), pair.Id], f.Ct);
|
||||
await f.Sync.RefreshAsync(nas, new SyncPolicy(), f.Ct);
|
||||
Assert.True((await f.Sync.Copies.GetAsync(pair.Id, f.Ct))!.RemoteGone);
|
||||
|
||||
// Restored from the server's trash: listed again, it no longer reads "deleted on server".
|
||||
nas.Sequences[remote.Id] = remote;
|
||||
await f.Sync.RefreshAsync(nas, new SyncPolicy(), f.Ct);
|
||||
pair = (await f.Sync.Copies.GetAsync(pair.Id, f.Ct))!;
|
||||
Assert.Equal((0, (DateTimeOffset?)null, false), (pair.RemoteGoneHits, pair.RemoteGoneAt, pair.RemoteGone));
|
||||
Assert.Equal(CopyState.Candidate, pair.State);
|
||||
|
||||
// A pair still marked (the listing missed it) is cleared by a link to that very sequence: automatic photos may move again.
|
||||
await using (var session = await f.Db.Database.OpenAsync(f.Ct))
|
||||
await session.ExecuteAsync("UPDATE found_copies SET remote_gone_hits = 2, remote_gone_at = $1 WHERE id = $2", [DateTimeOffset.UtcNow, pair.Id], f.Ct);
|
||||
await f.Sync.LinkAsync(nas.Server, remote.Id, local.Id, f.Ct);
|
||||
pair = (await f.Sync.Copies.GetAsync(pair.Id, f.Ct))!;
|
||||
Assert.Equal((0, false, CopyState.Linked), (pair.RemoteGoneHits, pair.RemoteGone, pair.State));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ASequenceBackOnTheServerIsAskedAboutAgain()
|
||||
{
|
||||
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);
|
||||
nas.Unlisted.Add(remote.Id);
|
||||
nas.Sequences.Remove(remote.Id);
|
||||
await f.Sync.RefreshAsync(nas, new SyncPolicy(), f.Ct);
|
||||
Assert.Equal(1, (await f.Sync.Copies.ListByServerAsync(nas.Server, f.Ct)).Single().RemoteGoneHits);
|
||||
|
||||
nas.Sequences[remote.Id] = remote;
|
||||
nas.Unlisted.Remove(remote.Id);
|
||||
await f.Sync.RefreshAsync(nas, new SyncPolicy(), f.Ct);
|
||||
|
||||
var pair = (await f.Sync.Copies.ListByServerAsync(nas.Server, f.Ct)).Single();
|
||||
Assert.Equal(0, pair.RemoteGoneHits);
|
||||
Assert.Null(pair.RemoteGoneAt);
|
||||
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()
|
||||
{
|
||||
await using var f = await SyncFixture.CreateAsync(context);
|
||||
var nas = new FakeSyncRemote { Server = HomeFolders.IdKey(Guid.NewGuid()) };
|
||||
var remotes = new List<FakeSequence>();
|
||||
for (var i = 0; i < 5; i++)
|
||||
{
|
||||
var photos = f.NewPhotos(1);
|
||||
var local = await f.LocalAsync($"Card {i}", photos);
|
||||
var remote = nas.Add($"Card {i}", photos);
|
||||
await f.Sync.LinkAsync(nas.Server, remote.Id, local.Id, f.Ct);
|
||||
remotes.Add(remote);
|
||||
}
|
||||
foreach (var remote in remotes) nas.Sequences.Remove(remote.Id);
|
||||
|
||||
await f.Sync.RefreshAsync(nas, new SyncPolicy(), f.Ct);
|
||||
|
||||
Assert.Empty(await f.Sync.Links.ListAsync(nas.Server, f.Ct));
|
||||
Assert.True((await f.Sync.Copies.ListByServerAsync(nas.Server, f.Ct)).All(p => p.RemoteGoneHits == 0));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ASweepOf404sConfirmsNoEarlierHitEither()
|
||||
{
|
||||
await using var f = await SyncFixture.CreateAsync(context);
|
||||
var nas = new FakeSyncRemote { Server = HomeFolders.IdKey(Guid.NewGuid()) };
|
||||
// One pair with a 404 counted more than ten minutes ago (its link already forgotten).
|
||||
var first = f.NewPhotos(2);
|
||||
var gone = await f.LocalAsync("Comet", first);
|
||||
var goneRemote = nas.Add("Comet", first);
|
||||
await f.Sync.LinkAsync(nas.Server, goneRemote.Id, gone.Id, f.Ct);
|
||||
await f.Sync.RefreshAsync(nas, new SyncPolicy(), f.Ct);
|
||||
nas.Sequences.Remove(goneRemote.Id);
|
||||
await f.Sync.RefreshAsync(nas, new SyncPolicy(), f.Ct);
|
||||
var pair = (await f.Sync.Copies.ListByServerAsync(nas.Server, f.Ct)).Single(p => p.LocalId == gone.Id);
|
||||
Assert.Equal(1, pair.RemoteGoneHits);
|
||||
await using (var session = await f.Db.Database.OpenAsync(f.Ct))
|
||||
await session.ExecuteAsync("UPDATE found_copies SET remote_gone_at = $1 WHERE id = $2", [DateTimeOffset.UtcNow.AddMinutes(-11), pair.Id], f.Ct);
|
||||
|
||||
// Then the server serves something else: every linked sequence answers 404 at once.
|
||||
var remotes = new List<FakeSequence>();
|
||||
for (var i = 0; i < 5; i++)
|
||||
{
|
||||
var photos = f.NewPhotos(1);
|
||||
var local = await f.LocalAsync($"Card {i}", photos);
|
||||
var remote = nas.Add($"Card {i}", photos);
|
||||
await f.Sync.LinkAsync(nas.Server, remote.Id, local.Id, f.Ct);
|
||||
remotes.Add(remote);
|
||||
}
|
||||
foreach (var remote in remotes) nas.Sequences.Remove(remote.Id);
|
||||
|
||||
await f.Sync.RefreshAsync(nas, new SyncPolicy(), f.Ct);
|
||||
|
||||
pair = (await f.Sync.Copies.GetAsync(pair.Id, f.Ct))!;
|
||||
Assert.Equal(1, pair.RemoteGoneHits);
|
||||
Assert.False(pair.RemoteGone);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AServerKnownOnlyByItsAddressMarksNothing()
|
||||
{
|
||||
await using var f = await SyncFixture.CreateAsync(context);
|
||||
var photos = f.NewPhotos(2);
|
||||
var local = await f.LocalAsync("Comet", photos);
|
||||
var remote = f.Remote.Add("Comet", photos);
|
||||
await f.Sync.LinkAsync(f.Server, remote.Id, local.Id, f.Ct);
|
||||
f.Remote.Sequences.Remove(remote.Id);
|
||||
|
||||
await f.RefreshAsync();
|
||||
|
||||
Assert.Null(await f.Sync.LinkOfAsync(f.Server, local.Id, f.Ct));
|
||||
Assert.True((await f.Sync.Copies.ListByServerAsync(f.Server, f.Ct)).All(p => p.RemoteGoneHits == 0));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ASequenceForgottenOnAServerKnownByItsAddressIsFoundAgainWhenItIsBack()
|
||||
{
|
||||
await using var f = await SyncFixture.CreateAsync(context);
|
||||
f.Remote.Capabilities.Add(ServerCapabilities.PhotoLookup);
|
||||
var photos = f.NewPhotos(2);
|
||||
var local = await f.LocalAsync("Comet", photos);
|
||||
var remote = f.Remote.Add("Comet", photos);
|
||||
await f.Sync.LinkAsync(f.Server, remote.Id, local.Id, f.Ct);
|
||||
await f.RefreshAsync();
|
||||
f.Remote.Sequences.Remove(remote.Id);
|
||||
await f.RefreshAsync();
|
||||
Assert.Null(await f.Sync.LinkOfAsync(f.Server, local.Id, f.Ct));
|
||||
|
||||
// Back on the server: nothing remembers the forgotten link, so the two are found and asked about again.
|
||||
f.Remote.Sequences[remote.Id] = remote;
|
||||
await f.RefreshAsync();
|
||||
|
||||
var pair = (await f.Sync.Copies.ListByServerAsync(f.Server, f.Ct)).Single();
|
||||
Assert.Equal((local.Id, remote.Id, CopyState.Candidate), (pair.LocalId, pair.RemoteId!.Value, pair.State));
|
||||
Assert.Null(await f.Sync.LinkOfAsync(f.Server, local.Id, f.Ct));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ALinkedPairWhoseLinkIsGoneIsAskedAboutAgain()
|
||||
{
|
||||
await using var f = await SyncFixture.CreateAsync(context);
|
||||
f.Remote.Capabilities.Add(ServerCapabilities.PhotoLookup);
|
||||
var photos = f.NewPhotos(2);
|
||||
var local = await f.LocalAsync("Comet", photos);
|
||||
var remote = f.Remote.Add("Comet", photos);
|
||||
await f.Sync.LinkAsync(f.Server, remote.Id, local.Id, f.Ct);
|
||||
await f.RefreshAsync();
|
||||
// The link removed by another hand, the pair's row left as it was.
|
||||
await f.Sync.Links.DeleteAsync(f.Server, remote.Id, f.Ct);
|
||||
var raised = new List<CopyFindResult>();
|
||||
f.Sync.CopiesFound += (_, result) => raised.Add(result);
|
||||
|
||||
await f.RefreshAsync();
|
||||
|
||||
var pair = (await f.Sync.Copies.ListByServerAsync(f.Server, f.Ct)).Single();
|
||||
Assert.Equal((CopyState.Candidate, false), (pair.State, pair.AutoPhotos));
|
||||
Assert.Contains(pair.Id, raised.SelectMany(r => r.New).Select(p => p.Id));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task DeletionCountsFollowEachComparison()
|
||||
{
|
||||
await using var f = await SyncFixture.CreateAsync(context);
|
||||
var photos = f.NewPhotos(3);
|
||||
var local = await f.LocalAsync("Comet", photos);
|
||||
var remote = f.Remote.Add("Comet", photos);
|
||||
await f.Sync.LinkAsync(f.Server, remote.Id, local.Id, f.Ct);
|
||||
await f.RefreshAsync();
|
||||
var pair = (await f.Sync.Copies.ListByServerAsync(f.Server, f.Ct)).Single();
|
||||
Assert.Equal((3, 0, 0), (pair.Score.Shared, pair.Score.DeletedHere, pair.Score.DeletedThere));
|
||||
|
||||
// The server deletes a photo this PC still holds.
|
||||
var gone = remote.Frames[1];
|
||||
remote.Frames.Remove(gone);
|
||||
remote.FramesVersion++;
|
||||
remote.Removed.Add(new RemovedPhotoDto(gone.Sha256, null, "deleted", DateTimeOffset.UtcNow));
|
||||
await f.RefreshAsync();
|
||||
|
||||
pair = (await f.Sync.Copies.GetAsync(pair.Id, f.Ct))!;
|
||||
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]
|
||||
public async Task AgreedDetailsTakeTheServersOwnChangeSinceThePlan()
|
||||
{
|
||||
await using var f = await SyncFixture.CreateAsync(context);
|
||||
var (local, remote, planLocal, planRemote) = await PlannedAsync(f);
|
||||
var final = planLocal with { Title = "Comet agreed" };
|
||||
// The server's light analysis of the photos just filed changes its settings after the plan.
|
||||
f.Remote.EditSettings(remote.Id, SyncFixture.Window41);
|
||||
|
||||
var (applied, updated) = await f.Sync.ApplyAgreedAsync(f.Remote, remote.Id, final, planLocal, planRemote, local.SettingsVersion, f.Ct);
|
||||
|
||||
Assert.Equal("Comet agreed", remote.Title);
|
||||
Assert.True(SyncRules.SameSettings(SyncFixture.Window41, remote.SettingsJson));
|
||||
var stored = (await f.Db.Sequences.GetAsync(local.Id, f.Ct))!;
|
||||
Assert.Equal("Comet agreed", stored.Title);
|
||||
Assert.True(SyncRules.SameSettings(SyncFixture.Window41, stored.SettingsJson));
|
||||
Assert.Equal((stored.SettingsVersion, remote.SettingsVersion), (applied.SettingsVersion, updated.SettingsVersion));
|
||||
var link = (await f.Sync.Links.GetAsync(f.Server, remote.Id, f.Ct))!;
|
||||
Assert.Equal((stored.SettingsVersion, remote.SettingsVersion), (link.BaseLocalSettings, link.BaseRemoteSettings));
|
||||
Assert.Count(1, f.Remote.Updates);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AgreedDetailsAreSentAgainAfterARefusedEdit()
|
||||
{
|
||||
await using var f = await SyncFixture.CreateAsync(context);
|
||||
var (local, remote, planLocal, planRemote) = await PlannedAsync(f);
|
||||
var final = planLocal with { Title = "Comet agreed" };
|
||||
// Unhashed on the server: its frames are read after the manifest, and the server changes right then.
|
||||
remote.Unhashed = true;
|
||||
f.Remote.OnceBeforeFrames = () =>
|
||||
{
|
||||
f.Remote.EditSettings(remote.Id, SyncFixture.Window41);
|
||||
return Task.CompletedTask;
|
||||
};
|
||||
|
||||
await f.Sync.ApplyAgreedAsync(f.Remote, remote.Id, final, planLocal, planRemote, local.SettingsVersion, f.Ct);
|
||||
|
||||
Assert.Equal("Comet agreed", remote.Title);
|
||||
Assert.True(SyncRules.SameSettings(SyncFixture.Window41, remote.SettingsJson));
|
||||
Assert.Equal("Comet agreed", (await f.Db.Sequences.GetAsync(local.Id, f.Ct))!.Title);
|
||||
Assert.Count(1, f.Remote.Updates);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AgreedDetailsAreRefusedAfterAnEditOnThisPc()
|
||||
{
|
||||
await using var f = await SyncFixture.CreateAsync(context);
|
||||
var (local, remote, planLocal, planRemote) = await PlannedAsync(f);
|
||||
var final = planLocal with { Title = "Comet agreed" };
|
||||
var edited = await f.EditLocalSettingsAsync(local.Id, SyncFixture.Window41);
|
||||
|
||||
await Assert.ThrowsAsync<SyncConflictChangedException>(() =>
|
||||
f.Sync.ApplyAgreedAsync(f.Remote, remote.Id, final, planLocal, planRemote, local.SettingsVersion, f.Ct));
|
||||
// Shown at the new version, the content still moved since the plan.
|
||||
await Assert.ThrowsAsync<SyncConflictChangedException>(() =>
|
||||
f.Sync.ApplyAgreedAsync(f.Remote, remote.Id, final, planLocal, planRemote, edited.SettingsVersion, f.Ct));
|
||||
|
||||
Assert.Empty(f.Remote.Updates);
|
||||
Assert.Equal("Comet", remote.Title);
|
||||
Assert.True(SyncRules.SameSettings(SyncFixture.Window41, (await f.Db.Sequences.GetAsync(local.Id, f.Ct))!.SettingsJson));
|
||||
}
|
||||
|
||||
/// <summary>A linked pair with the same settings on both sides, and each side's portable payload as an Integrate's plan reads it.</summary>
|
||||
private static async Task<(Sequence Local, FakeSequence Remote, SyncPayload PlanLocal, SyncPayload PlanRemote)> PlannedAsync(SyncFixture f)
|
||||
{
|
||||
var photos = f.NewPhotos(2);
|
||||
var local = await f.LocalAsync("Comet", photos, SyncFixture.Window33);
|
||||
var remote = f.Remote.Add("Comet", photos, SyncFixture.Window33);
|
||||
await f.Sync.LinkAsync(f.Server, remote.Id, local.Id, f.Ct);
|
||||
local = (await f.Db.Sequences.GetAsync(local.Id, f.Ct))!;
|
||||
var none = new FramePhotos([]);
|
||||
return (local, remote, CopyPayload.Portable(SyncPayload.Of(local), none), CopyPayload.Portable(SyncPayload.Of(remote.Dto(), remote.SettingsJson), none));
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ using Chronos.Core.Localization;
|
||||
using Chronos.Core.Model;
|
||||
using Chronos.Core.Project;
|
||||
using Chronos.Data.Archiving;
|
||||
using Chronos.Data.Copies;
|
||||
using Chronos.Data.Sync;
|
||||
using Chronos.Data.Tests.Archiving;
|
||||
using Chronos.Protocol;
|
||||
@@ -763,14 +764,14 @@ public sealed class SyncServiceTests(TestContext context)
|
||||
other.FirstCapture = local.FirstCapture;
|
||||
other.CameraModel = local.CameraModel;
|
||||
|
||||
await f.RefreshAsync();
|
||||
await f.RefreshAsync(new SyncPolicy { Linking = CopyLinking.WhenHalfShared });
|
||||
|
||||
var entry = await f.EntryAsync("Comet");
|
||||
Assert.Equal(remote.Id, entry.Link?.RemoteId);
|
||||
Assert.Equal((0, 0), (entry.Link!.MissingRemote, entry.Link.MissingLocal));
|
||||
Assert.Null((await f.EntryAsync("Other card")).Local);
|
||||
var manifests = f.Remote.ManifestCalls;
|
||||
await f.RefreshAsync();
|
||||
await f.RefreshAsync(new SyncPolicy { Linking = CopyLinking.WhenHalfShared });
|
||||
Assert.Equal(manifests, f.Remote.ManifestCalls);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,555 @@
|
||||
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;
|
||||
|
||||
namespace Chronos.Data.Tests.Sync;
|
||||
|
||||
/// <summary>
|
||||
/// The filtered transfers an Integrate runs (owner review 6, #73; design §5c): only the photos asked for, each once even
|
||||
/// when resumed, a server sequence gone marks the pair, and a linked upload files into its target when the server can.
|
||||
/// </summary>
|
||||
[Category("sync")]
|
||||
public sealed class SyncTransferCopyTests(TestContext context)
|
||||
{
|
||||
private static string Sha(byte[] bytes) => Convert.ToHexStringLower(SHA256.HashData(bytes));
|
||||
|
||||
private static async Task<JobContext> ContextAsync(SyncFixture f)
|
||||
{
|
||||
var engine = new JobEngine(f.Db, [], new JobEngineOptions { WorkerId = "t" });
|
||||
await f.Db.Jobs.EnqueueAsync(new Job { Id = Guid.CreateVersion7(), Kind = JobKind.Verify, State = JobState.Queued, Created = DateTimeOffset.UtcNow }, f.Ct);
|
||||
var claimed = Assert.NotNull(await f.Db.Jobs.ClaimNextAsync("t", [JobKind.Verify], f.Ct));
|
||||
return new JobContext(engine, claimed, f.Ct);
|
||||
}
|
||||
|
||||
private static async Task<HashSet<string>> LocalHashesAsync(SyncFixture f, Guid id) =>
|
||||
(await f.Db.Frames.ListBySequenceAsync(id, cancellationToken: f.Ct)).Select(fr => fr.Sha256!).ToHashSet(StringComparer.Ordinal);
|
||||
|
||||
private static SyncFixture Capable(SyncFixture f)
|
||||
{
|
||||
f.Remote.Capabilities.Add(ServerCapabilities.UploadInto);
|
||||
f.Remote.Capabilities.Add(ServerCapabilities.PhotoLookup);
|
||||
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()
|
||||
{
|
||||
await using var f = Capable(await SyncFixture.CreateAsync(context));
|
||||
var photos = f.NewPhotos(5);
|
||||
var local = await f.LocalAsync("Comet", [photos[0], photos[1], photos[2]]);
|
||||
var remote = f.Remote.Add("Comet", [photos[0], photos[3], photos[4]]);
|
||||
var job = await ContextAsync(f);
|
||||
var transfers = new SyncTransfers(f.Sync);
|
||||
|
||||
Assert.Equal(1, await transfers.SendPhotosAsync(job, f.Remote, local.Id, remote.Id, [Sha(photos[1])]));
|
||||
Assert.Equal(1, await transfers.FetchPhotosAsync(job, f.Remote, remote.Id, local.Id, [Sha(photos[3])]));
|
||||
|
||||
Assert.True(remote.Frames.Select(fr => fr.Sha256).ToHashSet().SetEquals([Sha(photos[0]), Sha(photos[1]), Sha(photos[3]), Sha(photos[4])]));
|
||||
Assert.True((await LocalHashesAsync(f, local.Id)).SetEquals([Sha(photos[0]), Sha(photos[1]), Sha(photos[2]), Sha(photos[3])]));
|
||||
Assert.Equal(1, f.Remote.IntoUploads);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ARunAgainSendsAndFetchesNothingTwice()
|
||||
{
|
||||
await using var f = Capable(await SyncFixture.CreateAsync(context));
|
||||
var photos = f.NewPhotos(4);
|
||||
var local = await f.LocalAsync("Comet", [photos[0], photos[1]]);
|
||||
var remote = f.Remote.Add("Comet", [photos[2], photos[3]]);
|
||||
var job = await ContextAsync(f);
|
||||
var transfers = new SyncTransfers(f.Sync);
|
||||
var sent = new List<string>();
|
||||
var fetched = new List<string>();
|
||||
string[] send = [Sha(photos[0]), Sha(photos[1])], fetch = [Sha(photos[2]), Sha(photos[3])];
|
||||
|
||||
Assert.Equal(2, await transfers.SendPhotosAsync(job, f.Remote, local.Id, remote.Id, send, k => { sent.Add(k); return ValueTask.CompletedTask; }));
|
||||
Assert.Equal(2, await transfers.FetchPhotosAsync(job, f.Remote, remote.Id, local.Id, fetch, k => { fetched.Add(k); return ValueTask.CompletedTask; }));
|
||||
var uploads = f.Remote.IntoUploads;
|
||||
|
||||
Assert.Equal(0, await transfers.SendPhotosAsync(job, f.Remote, local.Id, remote.Id, send, k => { sent.Add(k); return ValueTask.CompletedTask; }));
|
||||
Assert.Equal(0, await transfers.FetchPhotosAsync(job, f.Remote, remote.Id, local.Id, fetch, k => { fetched.Add(k); return ValueTask.CompletedTask; }));
|
||||
|
||||
Assert.Equal(uploads, f.Remote.IntoUploads);
|
||||
Assert.Count(4, remote.Frames);
|
||||
Assert.Count(4, await f.Db.Frames.ListBySequenceAsync(local.Id, cancellationToken: f.Ct));
|
||||
// Every key is reported done, the second time without moving a file.
|
||||
Assert.SequenceEqual([.. send, .. send], sent);
|
||||
Assert.SequenceEqual([.. fetch, .. fetch], fetched);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AServerSequenceGoneMarksThePairAndSendsNowhereElse()
|
||||
{
|
||||
await using var f = await SyncFixture.CreateAsync(context);
|
||||
// A server known by its id: a 404 there is that server's word (an address may name another server tomorrow).
|
||||
var nas = new FakeSyncRemote { Server = ServerIdentity.IdKey(Guid.NewGuid()) };
|
||||
nas.Capabilities.Add(ServerCapabilities.UploadInto);
|
||||
nas.Capabilities.Add(ServerCapabilities.PhotoLookup);
|
||||
var photos = f.NewPhotos(2);
|
||||
var local = await f.LocalAsync("Comet", photos);
|
||||
var remote = nas.Add("Comet", [photos[0]]);
|
||||
var pair = await PairAsync(f, nas.Server, local.Id, remote.Id);
|
||||
nas.Sequences.Remove(remote.Id);
|
||||
var job = await ContextAsync(f);
|
||||
var transfers = new SyncTransfers(f.Sync);
|
||||
|
||||
await Assert.ThrowsAsync<RemoteGoneException>(() => transfers.SendPhotosAsync(job, nas, local.Id, remote.Id, [Sha(photos[1])]));
|
||||
await Assert.ThrowsAsync<RemoteGoneException>(() => transfers.FetchPhotosAsync(job, nas, remote.Id, local.Id, [Sha(photos[0])]));
|
||||
|
||||
Assert.Empty(nas.Sequences);
|
||||
Assert.Equal(0, nas.IntoUploads);
|
||||
Assert.Equal(1, (await f.Sync.Copies.GetAsync(pair.Id, f.Ct))!.RemoteGoneHits);
|
||||
|
||||
// A refresh right after asks again but does not count a second 404 within the recheck interval.
|
||||
await f.Sync.RefreshAsync(nas, new SyncPolicy(), f.Ct);
|
||||
Assert.Equal(1, (await f.Sync.Copies.GetAsync(pair.Id, f.Ct))!.RemoteGoneHits);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AGoneAnswerFromAServerKnownByItsAddressMarksNothing()
|
||||
{
|
||||
await using var f = Capable(await SyncFixture.CreateAsync(context));
|
||||
var photos = f.NewPhotos(2);
|
||||
var local = await f.LocalAsync("Comet", photos);
|
||||
var remote = f.Remote.Add("Comet", [photos[0]]);
|
||||
var pair = await PairAsync(f, f.Server, local.Id, remote.Id);
|
||||
f.Remote.Sequences.Remove(remote.Id);
|
||||
var job = await ContextAsync(f);
|
||||
|
||||
await Assert.ThrowsAsync<RemoteGoneException>(() => new SyncTransfers(f.Sync).SendPhotosAsync(job, f.Remote, local.Id, remote.Id, [Sha(photos[1])]));
|
||||
|
||||
Assert.Equal(0, (await f.Sync.Copies.GetAsync(pair.Id, f.Ct))!.RemoteGoneHits);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AFirstUploadWhoseFirstPhotoTheServerHoldsElsewhereEndsWithEveryPhotoInTheNewSequence()
|
||||
{
|
||||
await using var f = Capable(await SyncFixture.CreateAsync(context));
|
||||
var photos = f.NewPhotos(3);
|
||||
var local = await f.LocalAsync("Comet", photos);
|
||||
// The first photo is already on the server, in another sequence.
|
||||
f.Remote.Add("Elsewhere", [photos[0]]);
|
||||
var engine = await f.StartEngineAsync();
|
||||
|
||||
var job = await f.Sync.EnqueueUploadAsync(engine, f.Server, local);
|
||||
await f.Archive.WaitForAsync(job.Id, JobState.Done);
|
||||
|
||||
var link = Assert.NotNull(await f.Sync.Links.FindByLocalAsync(f.Server, local.Id, f.Ct));
|
||||
var target = f.Remote.Sequences[link.RemoteId];
|
||||
Assert.True(target.Frames.Select(fr => fr.Sha256).ToHashSet().SetEquals(photos.Select(Sha)));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AnUploadOfASequenceKeptApartMakesANewServerSequenceAndLeavesTheOtherAlone()
|
||||
{
|
||||
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 first = Assert.NotNull(await f.Sync.Links.FindByLocalAsync(f.Server, local.Id, f.Ct)).RemoteId;
|
||||
// Unlinked ("Stop syncing these sequences"): the pair is kept apart.
|
||||
await f.Sync.UnlinkAsync(f.Server, first, local.Id, f.Ct);
|
||||
var pair = (await f.Sync.Copies.ListByServerAsync(f.Server, f.Ct)).Single(c => c.RemoteId == first);
|
||||
Assert.Equal(CopyState.KeptApart, pair.State);
|
||||
|
||||
// A new photo, then a plain Upload.
|
||||
await f.AddLocalAsync(local.Id, photos[2]);
|
||||
job = await f.Sync.EnqueueUploadAsync(engine, f.Server, (await f.Db.Sequences.GetAsync(local.Id, f.Ct))!);
|
||||
await f.Archive.WaitForAsync(job.Id, JobState.Done);
|
||||
|
||||
// The sequence kept apart gets nothing, and stays apart and unlinked; a new one holds every photo.
|
||||
Assert.True(f.Remote.Sequences[first].Frames.Select(fr => fr.Sha256).ToHashSet().SetEquals([Sha(photos[0]), Sha(photos[1])]));
|
||||
Assert.Equal(CopyState.KeptApart, (await f.Sync.Copies.GetAsync(pair.Id, f.Ct))!.State);
|
||||
Assert.Null((await f.Sync.Links.GetAsync(f.Server, first, f.Ct))!.LocalId);
|
||||
var link = Assert.NotNull(await f.Sync.Links.FindByLocalAsync(f.Server, local.Id, f.Ct));
|
||||
Assert.NotEqual(first, link.RemoteId);
|
||||
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 DownloadingAgainAServerSequenceWhoseLinkA404ForgotRefillsAndLinksItsOwnLocalCopy()
|
||||
{
|
||||
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);
|
||||
|
||||
// A refresh's 404 forgot the link (the archive was briefly offline); listed again, the pair is asked about again.
|
||||
await f.Sync.Links.DeleteAsync(f.Server, remote.Id, f.Ct);
|
||||
var pair = (await f.Sync.Copies.ListByServerAsync(f.Server, f.Ct)).Single(c => c.RemoteId == remote.Id && c.LocalId == local);
|
||||
Assert.True(await f.Sync.Copies.SetStateAsync(pair.Id, pair.State, CopyState.Candidate, null, f.Ct));
|
||||
|
||||
// Download originals of the server-only sequence: it goes back into its own local copy, linked again.
|
||||
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);
|
||||
|
||||
Assert.Equal(local, Assert.NotNull(await f.Sync.Links.GetAsync(f.Server, remote.Id, f.Ct)).LocalId);
|
||||
Assert.Count(3, await f.Db.Frames.ListBySequenceAsync(local, cancellationToken: f.Ct));
|
||||
Assert.True((await LocalHashesAsync(f, local)).SetEquals(photos.Select(Sha)));
|
||||
var keys = await f.Db.Sequences.ListSessionKeysAsync(f.Archive.Archive.Id, SyncService.SessionKey(remote.Id) + "%", f.Ct);
|
||||
Assert.True(keys.All(k => k.SequenceId == local), "no second local sequence holds a key of the server sequence");
|
||||
Assert.Equal(1, (await f.Db.Sequences.ListAsync(new SequenceQuery(), f.Ct)).Items.Count);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task DownloadingAgainIntoTheOwnLocalCopyOfAPairAskedAgainKeepsItsDeletionsAndDetails()
|
||||
{
|
||||
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);
|
||||
|
||||
// While linked: one photo deleted here (the server keeps it, owner Q6) and the title edited; then unlinked and
|
||||
// asked about again (Ask again, or a Keep apart undone).
|
||||
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.True(await f.Sync.Copies.SetStateAsync(pair.Id, CopyState.KeptApart, CopyState.Candidate, null, f.Ct));
|
||||
|
||||
// Download originals of the server sequence: it refills its own local copy, as a linked 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 photo deleted here stays deleted, and the title is not overwritten by the server's.
|
||||
Assert.Equal(local, Assert.NotNull(await f.Sync.Links.GetAsync(f.Server, remote.Id, f.Ct)).LocalId);
|
||||
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("Mine", (await f.Db.Sequences.GetAsync(local, f.Ct))!.Title);
|
||||
Assert.Equal("Comet", remote.Title);
|
||||
Assert.Equal(1, (await f.Db.Sequences.ListAsync(new SequenceQuery(), f.Ct)).Items.Count);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AnUploadOfASequenceAskedAboutAgainMakesANewServerSequenceAndLeavesTheOtherAlone()
|
||||
{
|
||||
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 first = Assert.NotNull(await f.Sync.Links.FindByLocalAsync(f.Server, local.Id, f.Ct)).RemoteId;
|
||||
// Unlinked, then asked about again: the pair is a Candidate and nothing links the two.
|
||||
await f.Sync.UnlinkAsync(f.Server, first, local.Id, f.Ct);
|
||||
var pair = (await f.Sync.Copies.ListByServerAsync(f.Server, f.Ct)).Single(c => c.RemoteId == first);
|
||||
Assert.True(await f.Sync.Copies.SetStateAsync(pair.Id, CopyState.KeptApart, CopyState.Candidate, null, f.Ct));
|
||||
// Renamed on the server (the web, another desktop); a new photo here.
|
||||
var server = f.Remote.Sequences[first];
|
||||
server.Title = "Comet NAS";
|
||||
server.SettingsVersion++;
|
||||
server.UpdatedAt = DateTimeOffset.UtcNow;
|
||||
await f.AddLocalAsync(local.Id, photos[2]);
|
||||
|
||||
job = await f.Sync.EnqueueUploadAsync(engine, f.Server, (await f.Db.Sequences.GetAsync(local.Id, f.Ct))!);
|
||||
await f.Archive.WaitForAsync(job.Id, JobState.Done);
|
||||
|
||||
// The other is not joined through the key, linked unasked or overwritten: a new server sequence holds every photo.
|
||||
Assert.Equal("Comet NAS", server.Title);
|
||||
Assert.True(server.Frames.Select(fr => fr.Sha256).ToHashSet().SetEquals([Sha(photos[0]), Sha(photos[1])]));
|
||||
Assert.Equal(CopyState.Candidate, (await f.Sync.Copies.GetAsync(pair.Id, f.Ct))!.State);
|
||||
Assert.Null((await f.Sync.Links.GetAsync(f.Server, first, f.Ct))!.LocalId);
|
||||
var link = Assert.NotNull(await f.Sync.Links.FindByLocalAsync(f.Server, local.Id, f.Ct));
|
||||
Assert.NotEqual(first, link.RemoteId);
|
||||
Assert.True(f.Remote.Sequences[link.RemoteId].Frames.Select(fr => fr.Sha256).ToHashSet().SetEquals(photos.Select(Sha)));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AnUploadThatJoinsAServerSequenceItKnowsAlreadyComparesItsDetailsInsteadOfOverwritingThem()
|
||||
{
|
||||
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 first = Assert.NotNull(await f.Sync.Links.FindByLocalAsync(f.Server, local.Id, f.Ct)).RemoteId;
|
||||
// The link and its pair were forgotten (a sweep of 404s: the server served another archive for a while); the
|
||||
// server sequence is listed again, as an observation.
|
||||
var observed = Assert.NotNull(await f.Sync.Links.GetAsync(f.Server, first, f.Ct)) with { LocalId = null };
|
||||
await f.Sync.Links.UpsertAsync(observed, f.Ct);
|
||||
await using (var session = await f.Db.Database.OpenAsync(f.Ct))
|
||||
await session.ExecuteAsync("DELETE FROM found_copies WHERE remote_id = $1", [first], f.Ct);
|
||||
var server = f.Remote.Sequences[first];
|
||||
server.Title = "Comet NAS";
|
||||
server.SettingsVersion++;
|
||||
server.UpdatedAt = DateTimeOffset.UtcNow;
|
||||
await f.AddLocalAsync(local.Id, photos[2]);
|
||||
|
||||
job = await f.Sync.EnqueueUploadAsync(engine, f.Server, (await f.Db.Sequences.GetAsync(local.Id, f.Ct))!);
|
||||
await f.Archive.WaitForAsync(job.Id, JobState.Done);
|
||||
|
||||
// Joined through this sequence's key, not made by this upload: the server's title is not overwritten unseen.
|
||||
Assert.Equal(first, Assert.NotNull(await f.Sync.Links.FindByLocalAsync(f.Server, local.Id, f.Ct)).RemoteId);
|
||||
Assert.True(server.Frames.Select(fr => fr.Sha256).ToHashSet().SetEquals(photos.Select(Sha)));
|
||||
Assert.Equal("Comet NAS", server.Title);
|
||||
Assert.Equal("Comet", (await f.Db.Sequences.GetAsync(local.Id, f.Ct))!.Title);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ARetriedUploadThatJoinedAServerSequenceItKnewStillComparesItsDetails()
|
||||
{
|
||||
await using var f = Capable(await SyncFixture.CreateAsync(context));
|
||||
var photos = f.NewPhotos(4);
|
||||
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 first = Assert.NotNull(await f.Sync.Links.FindByLocalAsync(f.Server, local.Id, f.Ct)).RemoteId;
|
||||
// The link and its pair were forgotten; the server sequence is listed again and renamed there.
|
||||
var observed = Assert.NotNull(await f.Sync.Links.GetAsync(f.Server, first, f.Ct)) with { LocalId = null };
|
||||
await f.Sync.Links.UpsertAsync(observed, f.Ct);
|
||||
await using (var session = await f.Db.Database.OpenAsync(f.Ct))
|
||||
await session.ExecuteAsync("DELETE FROM found_copies WHERE remote_id = $1", [first], f.Ct);
|
||||
var server = f.Remote.Sequences[first];
|
||||
server.Title = "Comet NAS";
|
||||
server.SettingsVersion++;
|
||||
server.UpdatedAt = DateTimeOffset.UtcNow;
|
||||
await f.AddLocalAsync(local.Id, photos[2]);
|
||||
await f.AddLocalAsync(local.Id, photos[3]);
|
||||
// One original unreadable for the first attempt: it fails after joining the known sequence.
|
||||
var damaged = (await f.Db.Frames.ListBySequenceAsync(local.Id, cancellationToken: f.Ct)).Single(fr => fr.Sha256 == Sha(photos[3]));
|
||||
var path = f.Archive.Paths.FromRelative(damaged.RelativePath);
|
||||
var bytes = await File.ReadAllBytesAsync(path, f.Ct);
|
||||
var broken = bytes.ToArray();
|
||||
broken[^3] ^= 0xFF;
|
||||
await File.WriteAllBytesAsync(path, broken, f.Ct);
|
||||
|
||||
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,
|
||||
};
|
||||
await f.Db.Jobs.EnqueueAsync(row, f.Ct);
|
||||
var jobs = new JobEngine(f.Db, [], new JobEngineOptions { WorkerId = "t" });
|
||||
var attempt = new JobContext(jobs, row, f.Ct);
|
||||
await Assert.ThrowsAsync<InvalidDataException>(() => new SyncTransfers(f.Sync).UploadAsync(attempt, f.Remote, local.Id));
|
||||
Assert.Equal(first, Assert.NotNull(await f.Sync.Links.FindByLocalAsync(f.Server, local.Id, f.Ct)).RemoteId);
|
||||
|
||||
// Retried from that attempt's checkpoint, the original readable again.
|
||||
await File.WriteAllBytesAsync(path, bytes, f.Ct);
|
||||
var retry = new JobContext(jobs, row with { Checkpoint = attempt.Checkpoint }, f.Ct);
|
||||
await new SyncTransfers(f.Sync).UploadAsync(retry, f.Remote, local.Id);
|
||||
|
||||
// Still joined, not made by this upload: the server's title is not overwritten unseen.
|
||||
Assert.True(server.Frames.Select(fr => fr.Sha256).ToHashSet().SetEquals(photos.Select(Sha)));
|
||||
Assert.Equal("Comet NAS", server.Title);
|
||||
Assert.Equal("Comet", (await f.Db.Sequences.GetAsync(local.Id, f.Ct))!.Title);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AnAutomaticUploadAfterTheServerCopyIsGoneFailsAndCreatesNothing()
|
||||
{
|
||||
await using var f = Capable(await SyncFixture.CreateAsync(context));
|
||||
var photos = f.NewPhotos(2);
|
||||
var local = await f.LocalAsync("Comet", photos);
|
||||
var remote = f.Remote.Add("Comet", [photos[0]]);
|
||||
await f.Sync.LinkAsync(f.Server, remote.Id, local.Id, f.Ct);
|
||||
var pair = await PairAsync(f, f.Server, local.Id, remote.Id);
|
||||
Assert.True(await f.Sync.Copies.SetStateAsync(pair.Id, null, CopyState.Integrated, new CopyAnswer(null, null, null, true, DateTimeOffset.UtcNow), f.Ct));
|
||||
f.Remote.Sequences.Remove(remote.Id);
|
||||
var engine = await f.StartEngineAsync();
|
||||
|
||||
var job = await f.Sync.EnqueueAutomaticUploadAsync(engine, f.Server, local, f.Ct);
|
||||
await f.Archive.WaitForAsync(job.Id, JobState.Failed);
|
||||
|
||||
// Never a new server sequence: the automatic photos move only between the two the pair joins.
|
||||
Assert.Empty(f.Remote.Sequences);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AnAutomaticUploadOfAPairNoLongerIntegratedSendsNothing()
|
||||
{
|
||||
await using var f = Capable(await SyncFixture.CreateAsync(context));
|
||||
var photos = f.NewPhotos(2);
|
||||
var local = await f.LocalAsync("Comet", photos);
|
||||
var remote = f.Remote.Add("Comet", [photos[0]]);
|
||||
await f.Sync.LinkAsync(f.Server, remote.Id, local.Id, f.Ct);
|
||||
await PairAsync(f, f.Server, local.Id, remote.Id, CopyState.Linked);
|
||||
var engine = await f.StartEngineAsync();
|
||||
|
||||
var job = await f.Sync.EnqueueAutomaticUploadAsync(engine, f.Server, local, f.Ct);
|
||||
await f.Archive.WaitForAsync(job.Id, JobState.Failed);
|
||||
|
||||
Assert.Count(1, remote.Frames);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AnAutomaticDownloadWithoutTheLocalCopyFailsAndCreatesNoSequence()
|
||||
{
|
||||
await using var f = Capable(await SyncFixture.CreateAsync(context));
|
||||
var remote = f.Remote.Add("Comet", f.NewPhotos(2));
|
||||
var engine = await f.StartEngineAsync();
|
||||
|
||||
var job = await f.Sync.EnqueueAutomaticDownloadAsync(engine, f.Server, remote.Id, "Comet", f.Archive.Archive.Id, f.Ct);
|
||||
await f.Archive.WaitForAsync(job.Id, JobState.Failed);
|
||||
|
||||
Assert.Equal(0, await f.Db.Sequences.CountAsync(new() { ArchiveId = f.Archive.Archive.Id }, f.Ct));
|
||||
}
|
||||
|
||||
private static Task<FoundCopy> PairAsync(SyncFixture f, string server, Guid localId, Guid remoteId, CopyState state = CopyState.Candidate) =>
|
||||
f.Sync.Copies.UpsertFoundAsync(new FoundCopy
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
Kind = CopyKind.LocalServer,
|
||||
LocalId = localId,
|
||||
Server = server,
|
||||
RemoteId = remoteId,
|
||||
Evidence = CopyEvidence.Hashes,
|
||||
Fingerprint = "f",
|
||||
State = state,
|
||||
}, f.Ct);
|
||||
|
||||
[Test]
|
||||
public async Task ALinkedUploadFilesIntoItsTargetWhenTheServerCan()
|
||||
{
|
||||
await using var f = Capable(await SyncFixture.CreateAsync(context));
|
||||
var photos = f.NewPhotos(2);
|
||||
var local = await f.LocalAsync("Comet", photos);
|
||||
var remote = f.Remote.Add("Comet", [photos[0]]);
|
||||
// The server holds the second photo in another sequence: filed into the target all the same.
|
||||
f.Remote.Add("Elsewhere", [photos[1]]);
|
||||
await f.Sync.LinkAsync(f.Server, remote.Id, local.Id, f.Ct);
|
||||
var engine = await f.StartEngineAsync();
|
||||
|
||||
var job = await f.Sync.EnqueueUploadAsync(engine, f.Server, local);
|
||||
await f.Archive.WaitForAsync(job.Id, JobState.Done);
|
||||
|
||||
Assert.True(remote.Frames.Select(fr => fr.Sha256).ToHashSet().SetEquals(photos.Select(Sha)));
|
||||
Assert.Equal((1, 1), (f.Remote.IntoUploads, f.Remote.CopiedInto));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ALinkedUploadTheServerRefusesIntoItsTargetStillFilesEveryOriginal()
|
||||
{
|
||||
await using var f = Capable(await SyncFixture.CreateAsync(context));
|
||||
// An account with Read and Upload but not Edit, whose local sequence is linked to another account's: 403 for "into".
|
||||
f.Remote.ForbidInto = true;
|
||||
var photos = f.NewPhotos(4);
|
||||
var local = await f.LocalAsync("Comet", photos);
|
||||
var remote = f.Remote.Add("Comet", [photos[0]]);
|
||||
await f.Sync.LinkAsync(f.Server, remote.Id, local.Id, f.Ct);
|
||||
var engine = await f.StartEngineAsync();
|
||||
|
||||
var job = await f.Sync.EnqueueUploadAsync(engine, f.Server, local);
|
||||
await f.Archive.WaitForAsync(job.Id, JobState.Done);
|
||||
|
||||
// The refusal falls back to the upload as before the server could file into a target: every original is there.
|
||||
Assert.True(remote.Frames.Select(fr => fr.Sha256).ToHashSet().SetEquals(photos.Select(Sha)));
|
||||
Assert.True(f.Remote.RefusedInto >= 1);
|
||||
Assert.Equal(0, f.Remote.IntoUploads);
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ using Chronos.Core.Model;
|
||||
using Chronos.Core.Project;
|
||||
using Chronos.Core.Render;
|
||||
using Chronos.Data.Archiving;
|
||||
using Chronos.Data.Copies;
|
||||
using Chronos.Data.Sync;
|
||||
using Chronos.Data.Tests.Archiving;
|
||||
using Chronos.Protocol;
|
||||
@@ -879,7 +880,7 @@ public sealed class SyncTransferTests(TestContext context)
|
||||
theirs.FirstCapture = mine.FirstCapture;
|
||||
theirs.CameraModel = mine.CameraModel;
|
||||
|
||||
await f.RefreshAsync();
|
||||
await f.RefreshAsync(new SyncPolicy { Linking = CopyLinking.WhenHalfShared });
|
||||
|
||||
var comet = await f.EntryAsync("Comet");
|
||||
Assert.Equal(remote.Id, comet.Link?.RemoteId);
|
||||
|
||||
Reference in new issue
Block a user