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>
104 lines
5.8 KiB
C#
104 lines
5.8 KiB
C#
using Chronos.Data.Migrations;
|
|
using Chronos.Data.Tests.Infrastructure;
|
|
using Chronos.Testing;
|
|
|
|
namespace Chronos.Data.Tests.Migrations;
|
|
|
|
/// <summary>Migration 0012 (owner review 6, #73): found copies beside the links, every existing link a linked pair.</summary>
|
|
public abstract class FoundCopiesMigrationTests(TestContext context) : RepositoryTest(context)
|
|
{
|
|
[Test]
|
|
public async Task EveryLinkWithALocalSequenceBecomesOneLinkedPair()
|
|
{
|
|
var chronos = await OpenChronosAsync();
|
|
var database = chronos.Database;
|
|
var all = MigrationRunner.Load(Dialect);
|
|
Assert.Equal(12, all.Single(m => m.Name == "found_copies").Version);
|
|
|
|
var archive = TestData.Archive();
|
|
await chronos.Archives.UpsertAsync(archive, Ct);
|
|
var first = TestData.Sequence(archive.Id);
|
|
var second = TestData.Sequence(archive.Id);
|
|
await chronos.Sequences.UpsertAsync(first, Ct);
|
|
await chronos.Sequences.UpsertAsync(second, Ct);
|
|
var (r1, r2, r3) = (Guid.CreateVersion7(), Guid.CreateVersion7(), Guid.CreateVersion7());
|
|
await using (var session = await database.OpenAsync(Ct))
|
|
{
|
|
// Back to an index of 1.1 (schema 11) holding these links, then migrated again.
|
|
await session.ExecuteAsync("DROP TABLE copy_probes", [], Ct);
|
|
await session.ExecuteAsync("DROP TABLE found_copies", [], Ct);
|
|
await session.ExecuteAsync("DELETE FROM schema_migrations WHERE version = 12", [], Ct);
|
|
await Link(session, "https://nas.test:8443", r1, first.Id);
|
|
await Link(session, "id:server-b", r2, second.Id);
|
|
// An observation-only link (a server sequence this PC does not hold) is no pair.
|
|
await Link(session, "https://nas.test:8443", r3, null);
|
|
}
|
|
|
|
Assert.Equal(all[^1].Version, await MigrationRunner.MigrateAsync(database, Ct));
|
|
await using var after = await database.OpenAsync(Ct);
|
|
var rows = await after.QueryListAsync(
|
|
"SELECT id, kind, local_id, server, remote_id, other_id, evidence, state, fingerprint, auto_photos, remote_gone_hits, found_at FROM found_copies ORDER BY server",
|
|
[], r => r, Ct);
|
|
Assert.Equal(2, rows.Count);
|
|
Assert.Equal(2, rows.Select(r => r.GetGuid(0)).Distinct().Count());
|
|
foreach (var row in rows)
|
|
{
|
|
Assert.NotEqual(Guid.Empty, row.GetGuid(0));
|
|
Assert.Equal(0, row.GetInt32(1));
|
|
Assert.True(row.IsNull(5));
|
|
Assert.Equal(0, row.GetInt32(6));
|
|
Assert.Equal(2, row.GetInt32(7));
|
|
Assert.Equal("link", row.GetString(8));
|
|
Assert.False(row.GetBool(9));
|
|
Assert.Equal(0, row.GetInt32(10));
|
|
Assert.True(row.GetDateTimeOffset(11) > DateTimeOffset.UtcNow.AddMinutes(-5));
|
|
}
|
|
var pairs = rows.Select(r => (r.GetString(3), r.GetGuid(4), r.GetGuid(2))).ToHashSet();
|
|
Assert.Contains(("https://nas.test:8443", r1, first.Id), pairs);
|
|
Assert.Contains(("id:server-b", r2, second.Id), pairs);
|
|
// The ids are random version 4 UUIDs, in the form the binding writes.
|
|
foreach (var row in rows) Assert.Equal(4, row.GetGuid(0).Version);
|
|
// No change to the links.
|
|
Assert.Equal(3L, await after.ScalarAsync<long>("SELECT count(*) FROM sync_links", [], Ct));
|
|
}
|
|
|
|
[Test]
|
|
public async Task TheCheckRefusesAServerPairWithoutServerAndALocalPairOfOneSequence()
|
|
{
|
|
var chronos = await OpenChronosAsync();
|
|
var archive = TestData.Archive();
|
|
await chronos.Archives.UpsertAsync(archive, Ct);
|
|
var sequence = TestData.Sequence(archive.Id);
|
|
await chronos.Sequences.UpsertAsync(sequence, Ct);
|
|
await using var session = await chronos.Database.OpenAsync(Ct);
|
|
const string insert = "INSERT INTO found_copies (id, kind, local_id, server, remote_id, other_id, evidence, fingerprint, found_at, updated_at) " +
|
|
"VALUES ($1, $2, $3, $4, $5, $6, 2, 'f', $7, $7)";
|
|
await Assert.ThrowsAsync<DatabaseException>(() => session.ExecuteAsync(insert,
|
|
[Guid.NewGuid(), 0, sequence.Id, DbParam.Text(null), Guid.CreateVersion7(), (Guid?)null, TestData.Now], Ct));
|
|
await Assert.ThrowsAsync<DatabaseException>(() => session.ExecuteAsync(insert,
|
|
[Guid.NewGuid(), 1, sequence.Id, DbParam.Text(null), (Guid?)null, sequence.Id, TestData.Now], Ct));
|
|
await Assert.ThrowsAsync<DatabaseException>(() => session.ExecuteAsync(insert,
|
|
[Guid.NewGuid(), 1, sequence.Id, "https://nas.test:8443", (Guid?)null, Guid.CreateVersion7(), TestData.Now], Ct));
|
|
// A pair names existing sequences: a found copy goes with its sequence.
|
|
await Assert.ThrowsAsync<DatabaseException>(() => session.ExecuteAsync(insert,
|
|
[Guid.NewGuid(), 0, Guid.CreateVersion7(), "https://nas.test:8443", Guid.CreateVersion7(), (Guid?)null, TestData.Now], Ct));
|
|
await session.ExecuteAsync(insert, [Guid.NewGuid(), 0, sequence.Id, "https://nas.test:8443", Guid.CreateVersion7(), (Guid?)null, TestData.Now], Ct);
|
|
Assert.Equal(1L, await session.ScalarAsync<long>("SELECT count(*) FROM found_copies", [], Ct));
|
|
}
|
|
|
|
private static Task<int> Link(IDbSession session, string server, Guid remoteId, Guid? localId) =>
|
|
session.ExecuteAsync("INSERT INTO sync_links (server, remote_id, local_id, title, remote_updated_at) VALUES ($1, $2, $3, $4, $5)",
|
|
[server, remoteId, localId, "Remote", TestData.Now], CancellationToken.None);
|
|
}
|
|
|
|
public sealed class SqliteFoundCopiesMigrationTests(TestContext context) : FoundCopiesMigrationTests(context)
|
|
{
|
|
protected override Backend Backend => Backend.SqliteMemory;
|
|
}
|
|
|
|
[RequiresEnvironment(PgTestServer.Variable)]
|
|
public sealed class PostgresFoundCopiesMigrationTests(TestContext context) : FoundCopiesMigrationTests(context)
|
|
{
|
|
protected override Backend Backend => Backend.Postgres;
|
|
}
|