Files
Chronos/tests/Chronos.Data.Tests/Copies/CopyFinderLocalTests.cs
T
Alby96andClaude Opus 5.5 f33bcac32e
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
feat(copies): matches between this PC and the server, Integrate and merge (owner review 6, v1.2.0) (#74)
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>
2026-11-18 15:20:29 +01:00

97 lines
4.2 KiB
C#

using Chronos.Core.Model;
using Chronos.Data.Copies;
using Chronos.Data.Tests.Sync;
using Chronos.Testing;
namespace Chronos.Data.Tests.Copies;
/// <summary>Detection on this PC (owner review 6, #73; design §3.4): two local copies are asked about, never linked.</summary>
[Category("sync")]
public sealed class CopyFinderLocalTests(TestContext context)
{
[Test]
public async Task TwoLocalCopiesAreAskedAndNeverLinked()
{
await using var f = await SyncFixture.CreateAsync(context);
var photos = f.NewPhotos(4);
var first = await f.LocalAsync("Comet", photos);
var second = await f.LocalAsync("Comet (card)", photos.Take(3).ToList());
await f.LocalAsync("Harbour", f.NewPhotos(2));
var result = await f.Sync.Finder.FindLocalAsync(f.Ct);
var pair = result.New.Single();
Assert.Equal((CopyKind.LocalLocal, CopyState.Candidate, CopyEvidence.Hashes), (pair.Kind, pair.State, pair.Evidence));
Assert.Equal(FoundCopyStore.Order(first.Id, second.Id), (pair.LocalId, pair.OtherId!.Value));
Assert.Equal(3, pair.Score.Shared);
Assert.Empty(result.AutoLinked);
Assert.Count(1, await f.Sync.Copies.ListAsync(f.Ct));
// Nothing moved: nothing is compared or announced again.
Assert.True((await f.Sync.Finder.FindLocalAsync(f.Ct)).IsEmpty);
}
[Test]
public async Task AnUnhashedCopyIsFoundBySizeAndCaptureTime()
{
await using var f = await SyncFixture.CreateAsync(context);
var photos = f.NewPhotos(3);
await f.LocalAsync("Comet", photos);
var adopted = await f.LocalAsync("Comet (adopted)", photos);
await using (var session = await f.Db.Database.OpenAsync(f.Ct))
await session.ExecuteAsync("UPDATE frames SET sha256 = NULL WHERE sequence_id = $1", [adopted.Id], f.Ct);
var pair = (await f.Sync.Finder.FindLocalAsync(f.Ct)).New.Single();
Assert.Equal(CopyEvidence.SizeAndTime, pair.Evidence);
Assert.Equal(3, pair.Score.SharedUnhashed);
Assert.Equal(CopyState.Candidate, pair.State);
}
[Test]
public async Task AKeptApartPairStaysApartAndAMergeTargetIsLeftAlone()
{
await using var f = await SyncFixture.CreateAsync(context);
var photos = f.NewPhotos(3);
var first = await f.LocalAsync("Comet", photos);
await f.LocalAsync("Comet (card)", photos);
var pair = (await f.Sync.Finder.FindLocalAsync(f.Ct)).New.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));
await f.Sync.Finder.ResetProbesAsync(CopyFinder.LocalScope, f.Ct);
Assert.True((await f.Sync.Finder.FindLocalAsync(f.Ct)).IsEmpty);
Assert.Equal(CopyState.KeptApart, (await f.Sync.Copies.GetAsync(pair.Id, f.Ct))!.State);
// A third copy while a merge waits on the first: the first is left out until the merge ends.
var third = await f.LocalAsync("Comet (again)", photos);
await f.Db.Jobs.EnqueueAsync(new Job
{
Id = Guid.CreateVersion7(),
Kind = JobKind.MergeSequences,
TargetIds = [first.Id],
State = JobState.Queued,
Created = DateTimeOffset.UtcNow,
}, f.Ct);
var result = await f.Sync.Finder.FindLocalAsync(f.Ct);
Assert.False(result.New.Any(p => p.Names(first.Id)));
Assert.True(result.New.Single().Names(third.Id));
}
[Test]
public async Task APairThatSharesNothingAnyMoreIsNoLongerAsked()
{
await using var f = await SyncFixture.CreateAsync(context);
var photos = f.NewPhotos(2);
await f.LocalAsync("Comet", photos);
var second = await f.LocalAsync("Comet (card)", photos);
var pair = (await f.Sync.Finder.FindLocalAsync(f.Ct)).New.Single();
await using (var session = await f.Db.Database.OpenAsync(f.Ct))
await session.ExecuteAsync("UPDATE frames SET sha256 = NULL, captured_at = NULL WHERE sequence_id = $1", [second.Id], f.Ct);
await f.Sync.Finder.FindLocalAsync(f.Ct);
Assert.Null(await f.Sync.Copies.GetAsync(pair.Id, f.Ct));
}
}