An all:true dry run reads every sidecar and photo folder of the archive inside the request, and the confirm planned the whole archive again before answering 202. The server now keeps each dry run's plan for five minutes (eight plans at most) by archive, selection, templates and a stamp of the archive's index rows: the same dry run again and its confirmation take the kept plan, and any change the index records (an upload, an edit, a move, a scan, a verify) gives another stamp and a new plan. A change made on disk alone is not in the stamp; the move job still plans again and refuses a plan that no longer matches. Server tests now cover an all:true apply around a sequence already in place, a real plan_changed after an upload, a move job paused between two sequences and resumed, archive_offline, job_unavailable, more than 1,000 ids and the kept plans themselves; a Data test covers the index stamp. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> (cherry picked from commit 71bb53fbf8eb7d0327ea692d046634b12f8d37e9)
64 lines
3.2 KiB
C#
64 lines
3.2 KiB
C#
using Chronos.Core.Model;
|
|
using Chronos.Data.Repositories;
|
|
using Chronos.Data.Tests.Infrastructure;
|
|
using Chronos.Testing;
|
|
|
|
namespace Chronos.Data.Tests.Repositories;
|
|
|
|
/// <summary>
|
|
/// The stamp of an archive's index rows (<see cref="SequenceRepository.GetStampAsync"/>) on both dialects: the server makes
|
|
/// a kept Reorganize plan again once it is another one (owner review 2, R7).
|
|
/// </summary>
|
|
public abstract class SequenceStampTests(TestContext context) : RepositoryTest(context)
|
|
{
|
|
[Test]
|
|
public async Task TheStampFollowsEveryChangeOfTheArchivesSequencesAndNoOtherArchives()
|
|
{
|
|
var db = await OpenChronosAsync();
|
|
var archive = TestData.Archive();
|
|
var other = TestData.Archive("Other");
|
|
await db.Archives.UpsertAsync(archive, Ct);
|
|
await db.Archives.UpsertAsync(other, Ct);
|
|
var empty = await db.Sequences.GetStampAsync(archive.Id, Ct);
|
|
var sequence = TestData.Sequence(archive.Id, new DateTime(2026, 9, 28, 18, 0, 0), "Roof");
|
|
await db.Sequences.UpsertAsync(sequence, Ct);
|
|
var stamp = await db.Sequences.GetStampAsync(archive.Id, Ct);
|
|
Assert.NotEqual(empty, stamp);
|
|
Assert.Equal(stamp, await db.Sequences.GetStampAsync(archive.Id, Ct));
|
|
|
|
// The sequences of another archive are not in it.
|
|
await db.Sequences.UpsertAsync(TestData.Sequence(other.Id), Ct);
|
|
Assert.Equal(stamp, await db.Sequences.GetStampAsync(archive.Id, Ct));
|
|
|
|
// Every change of the row gives one never seen before.
|
|
var seen = new HashSet<string>(StringComparer.Ordinal) { empty, stamp };
|
|
async Task ChangedAsync(string what) => Assert.True(seen.Add(await db.Sequences.GetStampAsync(archive.Id, Ct)), what);
|
|
Assert.Equal(SequenceEditOutcome.Updated, (await db.Sequences.EditAsync(sequence.Id, new SequenceEdit { Title = "Ridge" }, null, Ct)).Outcome);
|
|
await ChangedAsync("title");
|
|
Assert.True(await db.Sequences.RelocateAsync(sequence.Id, "2026/moved", null, Ct));
|
|
await ChangedAsync("folder");
|
|
await db.Frames.BulkInsertAsync([TestData.Frame(sequence.Id, 0)], Ct);
|
|
Assert.NotNull(await db.Sequences.RefreshStatsAsync(sequence.Id, Ct));
|
|
await ChangedAsync("photos");
|
|
// A row indexed again from its sidecar keeps the sidecar's time of change: its folder alone tells.
|
|
var row = Assert.NotNull(await db.Sequences.GetAsync(sequence.Id, Ct));
|
|
await db.Sequences.UpsertAsync(row with { Folder = "2026/elsewhere" }, Ct);
|
|
await ChangedAsync("folder of a row written back");
|
|
Assert.True(await db.Sequences.RecordVerifiedAsync(sequence.Id, SequenceStatus.None, SequenceStatus.None, TestData.Now, Ct));
|
|
await ChangedAsync("verify");
|
|
Assert.True(await db.Sequences.DeleteAsync(sequence.Id, Ct));
|
|
Assert.Equal(empty, await db.Sequences.GetStampAsync(archive.Id, Ct));
|
|
}
|
|
}
|
|
|
|
public sealed class SqliteSequenceStampTests(TestContext context) : SequenceStampTests(context)
|
|
{
|
|
protected override Backend Backend => Backend.SqliteMemory;
|
|
}
|
|
|
|
[RequiresEnvironment(PgTestServer.Variable)]
|
|
public sealed class PostgresSequenceStampTests(TestContext context) : SequenceStampTests(context)
|
|
{
|
|
protected override Backend Backend => Backend.Postgres;
|
|
}
|