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
@@ -1,5 +1,6 @@
|
||||
using Chronos.Core.IO;
|
||||
using Chronos.Core.Project;
|
||||
using Chronos.Data.Copies;
|
||||
using Chronos.Data.Homes;
|
||||
using Chronos.Data.Projects;
|
||||
using Chronos.Data.Sync;
|
||||
@@ -202,6 +203,105 @@ public abstract class HomeRekeyLinkTests(TestContext context) : RepositoryTest(c
|
||||
Assert.Count(1, await store.ListAsync(HomeFixtures.Other, Ct));
|
||||
Assert.Empty(await store.ListAsync(HomeFixtures.Nas, Ct));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TheMatchesAndProbesOfAnAliasMoveWithItsLinks()
|
||||
{
|
||||
var db = await OpenChronosAsync();
|
||||
var (linked, found) = await TwoSequencesAsync(db);
|
||||
var store = new SyncLinkStore(db);
|
||||
var copies = new FoundCopyStore(db);
|
||||
var (r1, r2) = (Guid.CreateVersion7(), Guid.CreateVersion7());
|
||||
await store.UpsertAsync(Link(HomeFixtures.Nas, r1, linked, TestData.Now), Ct);
|
||||
await copies.EnsureLinkedAsync(HomeFixtures.Nas, r1, linked, Ct);
|
||||
await copies.UpsertFoundAsync(Candidate(HomeFixtures.Nas, r2, found), Ct);
|
||||
await copies.SetProbeAsync(new CopyProbe(found, HomeFixtures.Nas, 3, 3, TestData.Now), Ct);
|
||||
|
||||
var migration = new HomeLayoutMigration(new HomeLayoutOptions { DataDirectory = Context.CreateTempDirectory("data"), Database = db });
|
||||
var result = await migration.RekeyAsync(Id, [HomeFixtures.Nas, HomeFixtures.NasByIp], Ct);
|
||||
|
||||
Assert.Equal((1, 0), (result.LinksMoved, result.LinksDropped));
|
||||
var key = ServerIdentity.IdKey(Id);
|
||||
Assert.Empty(await copies.ListByServerAsync(HomeFixtures.Nas, Ct));
|
||||
var moved = await copies.ListByServerAsync(key, Ct);
|
||||
Assert.Count(2, moved);
|
||||
Assert.Equal(CopyState.Linked, moved.Single(c => c.RemoteId == r1).State);
|
||||
Assert.Equal(CopyState.Candidate, moved.Single(c => c.RemoteId == r2).State);
|
||||
Assert.Null(await copies.GetProbeAsync(found, HomeFixtures.Nas, Ct));
|
||||
Assert.Equal(3, (await copies.GetProbeAsync(found, key, Ct))!.FramesVersion);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task OnAClashThePairOfTheSurvivingLinkWinsElseTheHigherState()
|
||||
{
|
||||
var db = await OpenChronosAsync();
|
||||
var (linked, found) = await TwoSequencesAsync(db);
|
||||
var key = ServerIdentity.IdKey(Id);
|
||||
var store = new SyncLinkStore(db);
|
||||
var copies = new FoundCopyStore(db);
|
||||
var (r1, r2) = (Guid.CreateVersion7(), Guid.CreateVersion7());
|
||||
// The same link under both keys: the one compared last (the alias's) survives, and so does its pair, though the pair
|
||||
// under the id is further on.
|
||||
await store.UpsertAsync(Link(HomeFixtures.Nas, r1, linked, TestData.Now), Ct);
|
||||
await store.UpsertAsync(Link(key, r1, linked, TestData.Now.AddHours(-1)), Ct);
|
||||
var aliasPair = await copies.EnsureLinkedAsync(HomeFixtures.Nas, r1, linked, Ct);
|
||||
var idPair = await copies.EnsureLinkedAsync(key, r1, linked, Ct);
|
||||
Assert.True(await copies.SetStateAsync(idPair.Id, CopyState.Linked, CopyState.Integrated, new CopyAnswer(null, null, null, true, TestData.Now), Ct));
|
||||
// A match without a link under both keys: the answered one wins over the newer candidate.
|
||||
var keptApart = await copies.UpsertFoundAsync(Candidate(HomeFixtures.Nas, r2, found), Ct);
|
||||
Assert.True(await copies.SetStateAsync(keptApart.Id, CopyState.Candidate, CopyState.KeptApart, new CopyAnswer("f", 4, null, null, TestData.Now), Ct));
|
||||
var candidate = await copies.UpsertFoundAsync(Candidate(key, r2, found), Ct);
|
||||
await copies.SetProbeAsync(new CopyProbe(found, HomeFixtures.Nas, 1, 1, TestData.Now), Ct);
|
||||
await copies.SetProbeAsync(new CopyProbe(found, key, 2, 2, TestData.Now), Ct);
|
||||
|
||||
var (moved, dropped) = await store.RekeyAsync(HomeFixtures.Nas, key, Ct);
|
||||
|
||||
Assert.Equal((1, 1), (moved, dropped));
|
||||
var rows = await copies.ListByServerAsync(key, Ct);
|
||||
Assert.Count(2, rows);
|
||||
var pair = rows.Single(c => c.RemoteId == r1);
|
||||
Assert.Equal(aliasPair.Id, pair.Id);
|
||||
Assert.Equal(CopyState.Linked, pair.State);
|
||||
var match = rows.Single(c => c.RemoteId == r2);
|
||||
Assert.Equal(keptApart.Id, match.Id);
|
||||
Assert.NotEqual(candidate.Id, match.Id);
|
||||
Assert.Equal(CopyState.KeptApart, match.State);
|
||||
Assert.Empty(await copies.ListByServerAsync(HomeFixtures.Nas, Ct));
|
||||
Assert.Equal(2, (await copies.GetProbeAsync(found, key, Ct))!.FramesVersion);
|
||||
Assert.Null(await copies.GetProbeAsync(found, HomeFixtures.Nas, Ct));
|
||||
}
|
||||
|
||||
private async Task<(Guid Linked, Guid Found)> TwoSequencesAsync(ChronosDatabase db)
|
||||
{
|
||||
var archive = TestData.Archive();
|
||||
await db.Archives.UpsertAsync(archive, Ct);
|
||||
var linked = TestData.Sequence(archive.Id);
|
||||
var found = TestData.Sequence(archive.Id);
|
||||
await db.Sequences.UpsertAsync(linked, Ct);
|
||||
await db.Sequences.UpsertAsync(found, Ct);
|
||||
return (linked.Id, found.Id);
|
||||
}
|
||||
|
||||
private static SyncLink Link(string server, Guid remoteId, Guid localId, DateTimeOffset synced) => new()
|
||||
{
|
||||
Server = server,
|
||||
RemoteId = remoteId,
|
||||
LocalId = localId,
|
||||
Title = "Harbour",
|
||||
RemoteUpdatedAt = TestData.Now,
|
||||
SyncedAt = synced,
|
||||
};
|
||||
|
||||
private static FoundCopy Candidate(string server, Guid remoteId, Guid localId) => new()
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
Kind = CopyKind.LocalServer,
|
||||
LocalId = localId,
|
||||
Server = server,
|
||||
RemoteId = remoteId,
|
||||
Evidence = CopyEvidence.Hashes,
|
||||
Fingerprint = "f",
|
||||
};
|
||||
}
|
||||
|
||||
public sealed class SqliteHomeRekeyLinkTests(TestContext context) : HomeRekeyLinkTests(context)
|
||||
|
||||
Reference in new issue
Block a user