Files
Alby96andClaude Opus 5.5 efa87f68ce
CI / Build and test (push) Failing after 3m1s
CI / PostgreSQL 16 integration (push) Skipped
CI / PostgreSQL 17 integration (push) Skipped
CI / Docker image (push) Skipped
CI / Windows tests and installer (push) Skipped
CI / YAML check (push) Successful in 10s
Release / Build, test and publish (push) Successful in 15m31s
Release / Server image (push) Successful in 1m13s
feat: owner review 2 phase 4b: mass conversion after import (#13)
Convert photos already in the archive to JPEG, TIFF-16 or Linear DNG, from the panel's Library and the desktop's Archive and Library. Each run asks Replace (same frames, originals to the trash, recoverable) or New sequence. A dry run lists what converts, what is skipped and why, size before and after, and free space; the job converts exactly the confirmed photos, resumes, and commits all or nothing per sequence. A conversion never changes what Chronos reads from a photo. Replaced originals are erased only on the archive's own word that their conversion is gone. Desktop TIFFs that WIC showed black or as noise now go to the managed reader; the Edit picker no longer spins a core.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Alberto Balbo <alberto.balbo.96@gmail.com>
2026-11-03 10:41:50 +01:00

163 lines
10 KiB
C#

using Chronos.Core.Imaging;
using Chronos.Core.Model;
using Chronos.Data.Repositories;
using Chronos.Data.Tests.Infrastructure;
using Chronos.Testing;
namespace Chronos.Data.Tests.Repositories;
/// <summary>
/// The stamps of what a Reorganize and a conversion plan from in an archive's index (<see cref="SequenceRepository.GetStampAsync"/>,
/// <see cref="SequenceRepository.GetConvertStampAsync"/>) on both dialects: the server makes a kept plan again once its
/// stamp is another one, and only then (owner review 2, R7).
/// </summary>
public abstract class SequenceStampTests(TestContext context) : RepositoryTest(context)
{
[Test]
public async Task TheStampFollowsWhatAReorganizePlansFromAndNothingElse()
{
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 roof = TestData.Sequence(archive.Id, new DateTime(2026, 9, 28, 18, 0, 0), "Roof");
var inner = TestData.Sequence(archive.Id, null, "Inner") with { Folder = roof.Folder + "/inner" };
var ridge = TestData.Sequence(archive.Id, new DateTime(2026, 9, 29, 7, 0, 0), "Ridge");
IReadOnlyList<Guid> planned = [roof.Id];
var empty = await db.Sequences.GetStampAsync(archive.Id, planned, Ct);
foreach (var sequence in new[] { roof, inner, ridge }) await db.Sequences.UpsertAsync(sequence, Ct);
var stamp = await db.Sequences.GetStampAsync(archive.Id, planned, Ct);
Assert.NotEqual(empty, stamp);
Assert.Equal(stamp, await db.Sequences.GetStampAsync(archive.Id, planned, Ct));
Assert.NotEqual(stamp, await db.Sequences.GetStampAsync(archive.Id, null, Ct));
// What the plan does not read: another archive, and the writes of every upload, verify, tag or status change elsewhere.
await db.Sequences.UpsertAsync(TestData.Sequence(other.Id), Ct);
await VerifyAsync(db, await PhotoAsync(db, ridge, 0, hashed: false));
await VerifyAsync(db, await PhotoAsync(db, inner, 0, hashed: false));
Assert.Equal(SequenceEditOutcome.Updated, (await db.Sequences.EditAsync(ridge.Id, new SequenceEdit { Title = "Ridge at dawn", Notes = "cold" }, null, Ct)).Outcome);
foreach (var id in new[] { roof.Id, ridge.Id })
{
Assert.True(await db.Sequences.SetTagsAsync(id, ["sky"], Ct));
Assert.True(await db.Sequences.UpdateStatusAsync(id, SequenceStatus.ProxiesBuilt, SequenceStatus.None, Ct));
Assert.True(await db.Sequences.RecordVerifiedAsync(id, SequenceStatus.None, SequenceStatus.None, TestData.Now, Ct));
}
Assert.Equal(stamp, await db.Sequences.GetStampAsync(archive.Id, planned, Ct));
// What it reads gives one never seen before: the sequences planned, the titles inside their folders, every folder.
var seen = new HashSet<string>(StringComparer.Ordinal) { empty, stamp };
async Task ChangedAsync(string what) => Assert.True(seen.Add(await db.Sequences.GetStampAsync(archive.Id, planned, Ct)), what);
Assert.Equal(SequenceEditOutcome.Updated, (await db.Sequences.EditAsync(roof.Id, new SequenceEdit { Title = "Roof at noon" }, null, Ct)).Outcome);
await ChangedAsync("title");
var scanned = await PhotoAsync(db, roof, 0, hashed: false);
await ChangedAsync("photos");
await VerifyAsync(db, scanned);
await ChangedAsync("photos hashed by a verify, which a file template renames");
Assert.Equal(SequenceEditOutcome.Updated, (await db.Sequences.EditAsync(inner.Id, new SequenceEdit { Title = "Inner court" }, null, Ct)).Outcome);
await ChangedAsync("title of a sequence a moving folder would carry");
Assert.True(await db.Sequences.RelocateAsync(ridge.Id, "2026/ridge", null, Ct));
await ChangedAsync("folder of a sequence not planned");
Assert.True(await db.Sequences.RelocateAsync(roof.Id, "2026/moved", null, Ct));
await ChangedAsync("folder");
var added = TestData.Sequence(archive.Id);
await db.Sequences.UpsertAsync(added, Ct);
await ChangedAsync("a sequence added");
Assert.True(await db.Sequences.DeleteAsync(added.Id, Ct));
Assert.Contains(await db.Sequences.GetStampAsync(archive.Id, planned, Ct), seen);
// With every sequence planned, a photo anywhere changes the plan read, and so does a verify that hashes one; a verify
// that hashes none still does not.
var all = await db.Sequences.GetStampAsync(archive.Id, null, Ct);
Assert.True(await db.Sequences.RecordVerifiedAsync(ridge.Id, SequenceStatus.None, SequenceStatus.None, TestData.Now.AddDays(1), Ct));
Assert.Equal(all, await db.Sequences.GetStampAsync(archive.Id, null, Ct));
var photo = await PhotoAsync(db, ridge, 1, hashed: false);
var uploaded = await db.Sequences.GetStampAsync(archive.Id, null, Ct);
Assert.NotEqual(all, uploaded);
await VerifyAsync(db, photo);
var verified = await db.Sequences.GetStampAsync(archive.Id, null, Ct);
Assert.False(verified == all || verified == uploaded, "a photo hashed");
}
[Test]
public async Task TheConvertStampFollowsThePhotosAConversionPlansFrom()
{
var db = await OpenChronosAsync();
var archive = TestData.Archive();
await db.Archives.UpsertAsync(archive, Ct);
var roof = TestData.Sequence(archive.Id, new DateTime(2026, 9, 28, 18, 0, 0), "Roof");
var ridge = TestData.Sequence(archive.Id, new DateTime(2026, 9, 29, 7, 0, 0), "Ridge");
foreach (var sequence in new[] { roof, ridge }) await db.Sequences.UpsertAsync(sequence, Ct);
var photo = await PhotoAsync(db, roof, 0);
var elsewhere = await PhotoAsync(db, ridge, 0);
IReadOnlyList<Guid> planned = [roof.Id];
var stamp = await db.Sequences.GetConvertStampAsync(archive.Id, planned, Ct);
Assert.Equal(stamp, await db.Sequences.GetConvertStampAsync(archive.Id, planned, Ct));
Assert.Equal(stamp, await db.Sequences.GetConvertStampAsync(archive.Id, [roof.Id, roof.Id], Ct));
Assert.NotEqual(stamp, await db.Sequences.GetConvertStampAsync(archive.Id, null, Ct));
// What a conversion does not read: the photos of a sequence not planned, light statistics, tags, a verify time.
Assert.Equal(1, await db.Frames.UpdateFlagsAsync([elsewhere.Id], FrameFlags.Missing, FrameFlags.None, Ct));
Assert.Equal(1, await db.Frames.UpdateLightStatsAsync([new FrameLightStats(photo.Id, -2.5, 0.01, 0.02)], Ct));
Assert.True(await db.Sequences.SetTagsAsync(roof.Id, ["sky"], Ct));
Assert.True(await db.Sequences.RecordVerifiedAsync(roof.Id, SequenceStatus.Verified, SequenceStatus.None, TestData.Now, Ct));
Assert.Equal(stamp, await db.Sequences.GetConvertStampAsync(archive.Id, planned, Ct));
// What it reads, without another frames version: each flag that keeps a photo as it is (a scan's, a verify's, a
// decode's), the format a decode records, the hash a verify records. Cleared again, the stamp is the one before.
var seen = new HashSet<string>(StringComparer.Ordinal) { stamp };
foreach (var flag in new[] { FrameFlags.Missing, FrameFlags.Corrupt, FrameFlags.PreviewOnly, FrameFlags.Undecodable })
{
Assert.Equal(1, await db.Frames.UpdateFlagsAsync([photo.Id], flag, FrameFlags.None, Ct));
Assert.True(seen.Add(await db.Sequences.GetConvertStampAsync(archive.Id, planned, Ct)), flag.ToString());
Assert.Equal(1, await db.Frames.UpdateFlagsAsync([photo.Id], FrameFlags.None, flag, Ct));
Assert.Equal(stamp, await db.Sequences.GetConvertStampAsync(archive.Id, planned, Ct));
}
Assert.Equal(1, await db.Frames.UpdateTiersAsync([new FrameTierFields(photo.Id, FrameFlags.None, 0, 0, ImageFileFormat.Dng)], Ct));
Assert.True(seen.Add(await db.Sequences.GetConvertStampAsync(archive.Id, planned, Ct)), "format");
var unhashed = await PhotoAsync(db, roof, 1, hashed: false);
Assert.True(seen.Add(await db.Sequences.GetConvertStampAsync(archive.Id, planned, Ct)), "a photo added");
await VerifyAsync(db, unhashed);
Assert.True(seen.Add(await db.Sequences.GetConvertStampAsync(archive.Id, planned, Ct)), "hashed by a verify");
// With every sequence planned, a flag on any photo changes it.
var all = await db.Sequences.GetConvertStampAsync(archive.Id, null, Ct);
Assert.Equal(1, await db.Frames.UpdateFlagsAsync([elsewhere.Id], FrameFlags.None, FrameFlags.Missing, Ct));
Assert.NotEqual(all, await db.Sequences.GetConvertStampAsync(archive.Id, null, Ct));
}
/// <summary>
/// A photo indexed into a sequence, as an upload does, or without its hash, as a scan does: the frame, then the row's
/// counts and frames version.
/// </summary>
private async Task<Frame> PhotoAsync(ChronosDatabase db, Sequence sequence, int index, bool hashed = true)
{
var frame = TestData.Frame(sequence.Id, index);
frame = frame with { RelativePath = $"{sequence.Folder}/originals/{frame.FileName}", Sha256 = hashed ? frame.Sha256 : null };
await db.Frames.BulkInsertAsync([frame], Ct);
Assert.NotNull(await db.Sequences.RefreshStatsAsync(sequence.Id, Ct));
return frame;
}
/// <summary>What a verify writes once it hashed a photo never hashed: the hash, then the sequence's verify time, and not another frames version.</summary>
private async Task VerifyAsync(ChronosDatabase db, Frame frame)
{
var version = (await db.Sequences.GetAsync(frame.SequenceId, Ct))!.FramesVersion;
var sha256 = TestData.Frame(frame.SequenceId, frame.Index).Sha256;
Assert.Equal(1, await db.Frames.UpdateIntegrityAsync([new FrameIntegrity(frame.Id, FrameFlags.None, sha256)], Ct));
Assert.True(await db.Sequences.RecordVerifiedAsync(frame.SequenceId, SequenceStatus.Verified, SequenceStatus.None, TestData.Now, Ct));
Assert.Equal(version, (await db.Sequences.GetAsync(frame.SequenceId, Ct))!.FramesVersion);
}
}
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;
}