Owner review 6 asks Chronos to recognise the same time-lapse held under different ids on the server and on this PC, compare the copies, and keep them apart or integrate and sync them. This lays the shared foundation the later parcels build on, without any UI or detection yet. - Migration 0012 adds found_copies (local-server and local-local pairs with evidence, scores, answer, policy and the 404 record) and copy_probes; every existing link with a local sequence becomes a Linked pair, so a server deletion and the per-link policy have a place. - FoundCopyStore keeps the pairs: upserts that never touch the answer, a compare-and-set of the state with an Integrating backstop (a failed or cancelled job reads as the previous state), link promotion and demotion, the once-per-refresh 404 count, the merge's links stage (session keys, links reset, pairs moved, refused when both are linked on one server), the local overlap queries and the probes. SyncLinkStore.RekeyAsync moves pairs and probes with the links in the same transaction. - Contracts for detection, review, plans, the Integrate and MergeSequences jobs (kinds 25/26, High level, new detail steps) and the Upload all rule that keeps suspected, kept-apart, deleted, busy and server-born sequences here. - Wire: POST photos/lookup, uploads into a target (IntoTarget/Copied, trailing and optional), frames/delete on the client, capabilities photo-lookup and upload-into, cached per remote. - The trash plans and deletes accept the job that holds the sequence (its own hold is not Busy) and a frames version checked under the lease; a Background job never interrupts a running one. - Settings for linking, the photo policy and projects; the en and it keys of design section 9. Refs #73 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
92 lines
3.8 KiB
C#
92 lines
3.8 KiB
C#
using Chronos.Core.Model;
|
|
using Chronos.Data.Copies;
|
|
using Chronos.Data.Sync;
|
|
using Chronos.Data.Tests.Infrastructure;
|
|
using Chronos.Testing;
|
|
|
|
namespace Chronos.Data.Tests.Copies;
|
|
|
|
/// <summary>Upload all local (owner review 6, Q8): suspected, kept-apart, deleted, busy and server-born sequences stay here.</summary>
|
|
[Category("sync")]
|
|
public sealed class UploadAllRuleTests
|
|
{
|
|
private const string Nas = "https://nas.test:8443";
|
|
|
|
private static readonly Guid Archive = Guid.CreateVersion7();
|
|
|
|
private static SyncEntry Entry(Guid? archiveId = null) =>
|
|
new(TestData.Sequence(archiveId ?? Archive) with { FrameCount = 3 }, null, SyncStatus.LocalOnly);
|
|
|
|
private static FoundCopy Remote(Guid localId, CopyState state, int goneHits = 0) => new()
|
|
{
|
|
Id = Guid.NewGuid(),
|
|
Kind = CopyKind.LocalServer,
|
|
LocalId = localId,
|
|
Server = Nas,
|
|
RemoteId = Guid.CreateVersion7(),
|
|
Evidence = CopyEvidence.Hashes,
|
|
State = state,
|
|
Fingerprint = "f",
|
|
RemoteGoneHits = goneHits,
|
|
};
|
|
|
|
private static FoundCopy Local(Guid a, Guid b, CopyState state) => new()
|
|
{
|
|
Id = Guid.NewGuid(),
|
|
Kind = CopyKind.LocalLocal,
|
|
LocalId = a,
|
|
OtherId = b,
|
|
Evidence = CopyEvidence.Hashes,
|
|
State = state,
|
|
Fingerprint = "f",
|
|
};
|
|
|
|
[Test]
|
|
public void APlainLocalSequenceUploads()
|
|
{
|
|
var plain = Entry();
|
|
var linked = Entry();
|
|
var (upload, skipped) = UploadAllRule.Select([plain, linked], [Remote(linked.Local!.Id, CopyState.Linked)], new HashSet<Guid>(), new HashSet<Guid>());
|
|
Assert.SequenceEqual([plain.Local!.Id, linked.Local!.Id], upload.Select(e => e.Local!.Id));
|
|
Assert.Empty(skipped);
|
|
}
|
|
|
|
[Test]
|
|
public void EachReasonKeepsTheSequenceHereWithItsReason()
|
|
{
|
|
var (suspected, keptApart, other, gone, busy, integrating, born) = (Entry(), Entry(), Entry(), Entry(), Entry(), Entry(), Entry(Guid.CreateVersion7()));
|
|
FoundCopy[] copies =
|
|
[
|
|
Remote(suspected.Local!.Id, CopyState.Candidate),
|
|
// A local pair names its second sequence too.
|
|
Local(other.Local!.Id, keptApart.Local!.Id, CopyState.KeptApart),
|
|
// One 404 is enough to stay here: it is not uploaded as a new server sequence.
|
|
Remote(gone.Local!.Id, CopyState.Linked, goneHits: 1),
|
|
Remote(integrating.Local!.Id, CopyState.Integrating),
|
|
];
|
|
var (upload, skipped) = UploadAllRule.Select([suspected, keptApart, other, gone, busy, integrating, born], copies,
|
|
new HashSet<Guid> { born.Local!.ArchiveId }, new HashSet<Guid> { busy.Local!.Id });
|
|
|
|
Assert.Empty(upload);
|
|
var why = skipped.ToDictionary(s => s.Entry.Local!.Id, s => s.Why);
|
|
Assert.Equal(UploadSkip.SuspectedCopy, why[suspected.Local.Id]);
|
|
Assert.Equal(UploadSkip.KeptApart, why[keptApart.Local.Id]);
|
|
Assert.Equal(UploadSkip.KeptApart, why[other.Local.Id]);
|
|
Assert.Equal(UploadSkip.DeletedOnServer, why[gone.Local.Id]);
|
|
Assert.Equal(UploadSkip.Busy, why[busy.Local.Id]);
|
|
Assert.Equal(UploadSkip.Busy, why[integrating.Local.Id]);
|
|
Assert.Equal(UploadSkip.ServerOriginals, why[born.Local.Id]);
|
|
}
|
|
|
|
[Test]
|
|
public void BusyComesFirstAndAnEntryWithoutALocalSequenceIsNeither()
|
|
{
|
|
var entry = Entry();
|
|
var serverOnly = new SyncEntry(null, new SyncLink { Server = Nas, RemoteId = Guid.CreateVersion7(), Title = "Harbour" }, SyncStatus.RemoteOnly);
|
|
var (upload, skipped) = UploadAllRule.Select([entry, serverOnly], [Remote(entry.Local!.Id, CopyState.Candidate, goneHits: 2)],
|
|
new HashSet<Guid> { Archive }, new HashSet<Guid> { entry.Local.Id });
|
|
Assert.Empty(upload);
|
|
Assert.Equal((entry.Local.Id, UploadSkip.Busy), (skipped.Single().Entry.Local!.Id, skipped.Single().Why));
|
|
}
|
|
}
|