A refresh no longer links copies by content behind the user's back. After the gate is released, CopyFinder looks for copies whose ids differ: the server's photo lookup (or 1.1's gate and the hints on an older server), session keys, and an exact comparison by manifest, bounded per refresh and remembered in copy_probes so nothing is compared twice while neither side moves. What a pair becomes is the Link matches setting's call: asked by default, linked by itself only as the setting allows, through a compare-and-set that a Keep apart wins. Local detection finds copies inside this PC's archives and never links them. SyncService gives every link its pair, adds Unlink (kept apart, observation kept), marks pairs whose server sequence answers 404 (once per refresh, twice reads deleted, never on an address key or in a 404 sweep), keeps deletion counts current at each comparison, writes an Integrate's agreed details to both sides by content (ApplyAgreedAsync) and queues uploads at a given priority. CopyReviewBuilder assembles what the Compare dialog shows. Refs #73 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
97 lines
4.2 KiB
C#
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));
|
|
}
|
|
}
|