fix(archive): weigh replaced originals against the archive, not this index

Owner review 2, phase 4b, fix round 2 (trash and sync).

- Emptying a Replaced entry decided "conversion deleted" from this host's index
  alone, so a conversion another host made, or one this index had not read yet,
  could be taken for deleted and its originals erased without re-hashing it. The
  survey now reads the archive: the sequence's sidecar where the index or the
  entry says it is, in the trash, or found by walking the archive's folders. Its
  Replaced tombstones are followed and every conversion it holds is re-hashed. A
  conversion counts as deleted only when the sidecar shows it (a Deleted
  tombstone, or the frame gone while every frame is hashed and no photo of the
  folder is unlisted), when the sequence is in the trash, or when no sidecar of it
  exists and this index has no row either. Whatever the archive cannot tell, or a
  converted frame whose file changed since, keeps the entry, and the job log says
  why (changed after the plan, sequence busy, conversion no longer matches,
  conversion not located).
- The erase weighs a Replaced entry under the entry's and the sequence's leases
  and settles the sequence first (an undo waiting for that entry's lease
  completes), so the entry it reads again and fingerprints is the one it erases.
  Read before the settle, a consumed entry's folder vanished under the erase.
- Each sidecar is indexed once per survey: one conversion's entry (every frame it
  swapped) is weighed in one pass, not one pass over the sidecar per photo.
- The desktop Empty confirmation names every entry whose conversion was deleted
  first, with why, wherever the trash lists it; the detail scrolls when long. The
  panel lists them first as well.
- Download originals queues the passes a frame swapped to another encoding
  cleared (light analysis, the deep analysis it had, thumbnails, proxies), as any
  replacement does.
- The job log lines of uploads and downloads are resources (en, it).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 27d9a512183e64da9a3d7fa69a267470ca3ce744)
This commit is contained in:
Alby96 committed 2026-11-02 10:33:34 +01:00
1 parent c669d0504d
commit 48a0ce3e02
15 files changed
+834 -164

No files matched your search

@@ -70,6 +70,38 @@ public sealed class TrashDialogTests(TestContext context)
+ Loc.L("Archive.Trash.ConversionDeleted"), lone.Detail!);
}
[Test]
public void EveryEntryThatMayHoldTheLastCopyIsNamedBeforeTheTypedConfirmation()
{
Loc.SetCulture(CultureInfo.GetCultureInfo("en"));
// The trash lists newest first: ten deletions since two old conversions whose converted photos were deleted.
var newer = Enumerable.Range(1, 10).Select(i => Entry($"Deleted {i}", TrashKind.Photos, 1, 1_000_000)).ToList();
var oldest = new[]
{
Entry("Etna", TrashKind.Replaced, 3, 90_000_000) with { ConversionDeleted = true },
Entry("Stromboli", TrashKind.Replaced, 2, 60_000_000) with { ConversionDeleted = true },
};
var plan = new TrashEmptyPlan(Guid.CreateVersion7(), [.. newer, .. oldest], 160_000_000, "f1", []);
var lines = Assert.NotNull(TrashEmptyPlans.Request(plan)).Detail!.Split(Environment.NewLine);
var why = Loc.Separator + Loc.L("Archive.Trash.ConversionDeleted");
Assert.True(lines[0].Contains("Etna", StringComparison.Ordinal) && lines[0].Contains(why, StringComparison.Ordinal), lines[0]);
Assert.True(lines[1].Contains("Stromboli", StringComparison.Ordinal) && lines[1].Contains(why, StringComparison.Ordinal), lines[1]);
// The other entries fill the lines left, and the rest are counted.
Assert.Equal(DeletePlans.ListedLines + 1, lines.Length);
Assert.Equal(Loc.Plural("Archive.Delete.More", newer.Count - (DeletePlans.ListedLines - oldest.Length)), lines[^1]);
// More of them than lines: every one is named all the same.
var many = Enumerable.Range(1, DeletePlans.ListedLines + 3).Select(i => Entry($"Converted {i}", TrashKind.Replaced, 1, 1_000_000) with { ConversionDeleted = true })
.ToList();
lines = Assert.NotNull(TrashEmptyPlans.Request(plan with { Entries = [.. newer, .. many] })).Detail!.Split(Environment.NewLine);
Assert.Equal(many.Count + 1, lines.Length);
for (var i = 0; i < many.Count; i++)
Assert.True(lines[i].StartsWith(many[i].Title + " ", StringComparison.Ordinal) && lines[i].Contains(why, StringComparison.Ordinal), lines[i]);
Assert.Equal(Loc.Plural("Archive.Delete.More", newer.Count), lines[^1]);
}
[Test]
public async Task EmptyQueuesTheJobOfTheConfirmedPlanOnly()
{
@@ -1,6 +1,7 @@
using System.Security.Cryptography;
using Chronos.Core.Archiving;
using Chronos.Core.Import;
using Chronos.Core.Localization;
using Chronos.Core.Model;
using Chronos.Core.Project;
using Chronos.Data.Archiving;
@@ -45,9 +46,11 @@ public sealed class ReplacedTrashTests(TestContext context)
/// <summary>
/// Replaces the files of the frames at <paramref name="indices"/> (in the sidecar now) with other photos, as a
/// conversion's stage B does (<see cref="FrameTrash.ReplaceAsync"/>); returns the trash entry of the originals.
/// conversion's stage B does (<see cref="FrameTrash.ReplaceAsync"/>), on this host or on <paramref name="by"/> (another
/// host sharing the archive, whose index this one does not read); returns the trash entry of the originals.
/// </summary>
private static async Task<TrashEntry> ReplaceAsync(ArchiveFixture fx, Guid sequenceId, IReadOnlyList<int> indices, int seed, Guid? job = null)
private static async Task<TrashEntry> ReplaceAsync(ArchiveFixture fx, Guid sequenceId, IReadOnlyList<int> indices, int seed, Guid? job = null,
(ArchiveService Service, Archive Archive)? by = null)
{
var sequence = (await fx.Db.Sequences.GetAsync(sequenceId))!;
var manifest = Sidecar(fx, sequence);
@@ -68,10 +71,21 @@ public sealed class ReplacedTrashTests(TestContext context)
Source = new FrameSource { Sha256 = current.Sha256, Format = current.Format, File = current.File, Size = current.Size },
}));
}
var result = Assert.NotNull(await fx.Service.FrameTrash.ReplaceAsync(fx.Archive, sequenceId, null, swaps, null, job, null, null, fx.Ct));
var (service, archive) = by ?? (fx.Service, fx.Archive);
var result = Assert.NotNull(await service.FrameTrash.ReplaceAsync(archive, sequenceId, null, swaps, null, job, null, null, fx.Ct));
return Assert.NotNull(result.Entry);
}
/// <summary>Flips a byte near the end of <paramref name="path"/>; returns its bytes before.</summary>
private static byte[] Damage(string path)
{
var bytes = File.ReadAllBytes(path);
var damaged = (byte[])bytes.Clone();
damaged[^10] ^= 0x01;
File.WriteAllBytes(path, damaged);
return bytes;
}
private static SequenceManifest Sidecar(ArchiveFixture fx, Sequence sequence) => ManifestStore.ReadSequence(fx.Paths.Sequence(sequence.Folder).ManifestPath);
private static string Sha(byte[] bytes) => Convert.ToHexStringLower(SHA256.HashData(bytes));
@@ -279,6 +293,213 @@ public sealed class ReplacedTrashTests(TestContext context)
Assert.Count(2, await fx.Db.Frames.ListBySequenceAsync(id));
}
[Test]
public async Task AConversionAnotherHostMadeIsHashedWhereTheArchiveHoldsIt()
{
await using var fx = await CreateAsync(context);
var (id, photos) = await UploadedAsync(fx, 2);
var engine = await fx.StartEngineAsync();
// A desktop sharing the archive converts the first photo; this index still holds the original there.
var replaced = await ReplaceAsync(fx, id, [0], 500, by: await fx.OtherWriterAsync());
Assert.Equal(Sha(photos[0]), (await fx.Db.Frames.ListBySequenceAsync(id))[0].Sha256);
var sequence = (await fx.Db.Sequences.GetAsync(id))!;
var converted = fx.Paths.Sequence(sequence.Folder).File(Sidecar(fx, sequence).Frames[0].File);
// The conversion is damaged since: the dry run finds it in the sequence, and the emptying keeps the originals.
var bytes = Damage(converted);
var plan = await fx.Service.PlanEmptyTrashAsync(fx.Archive.Id, null, fx.Ct);
Assert.False(plan.Entries.Single().ConversionDeleted, "the archive holds the conversion, whatever this index has");
var kept = await EmptyAsync(fx, engine, plan, JobState.Failed);
Assert.Contains(Loc.L("Archive.Log.TrashKeptMismatch", replaced.Title), kept.LogTail);
Assert.Equal(replaced.Name, (await fx.Service.ListTrashAsync(fx.Archive.Id, fx.Ct)).Single().Name);
// Whole again: the originals go.
File.WriteAllBytes(converted, bytes);
await EmptyAsync(fx, engine, await fx.Service.PlanEmptyTrashAsync(fx.Archive.Id, null, fx.Ct), JobState.Done);
Assert.Empty(await fx.Service.ListTrashAsync(fx.Archive.Id, fx.Ct));
}
[Test]
public async Task AConversionAnotherIndexMovedIsHashedWhereItIsNow()
{
await using var fx = await CreateAsync(context);
var (id, _) = await UploadedAsync(fx, 2);
var engine = await fx.StartEngineAsync();
var replaced = await ReplaceAsync(fx, id, [0], 500);
// Another index moves the sequence into another folder; this one has not scanned since.
var before = (await fx.Db.Sequences.GetAsync(id))!.Folder;
var (other, archive) = await fx.OtherWriterAsync();
await other.ApplyRenameAsync(await other.PlanRenameAsync(archive.Id, [id], "moved/{title}", null, fx.Ct), null, fx.Ct);
Assert.Equal(before, (await fx.Db.Sequences.GetAsync(id))!.Folder);
var folder = ArchiveScanner.FindSequenceFolders(fx.Paths, fx.Ct).Select(s => fx.Paths.Sequence(s.RelativeFolder)).Single(s => s.RelativeFolder != before);
Assert.True(folder.RelativeFolder.StartsWith("moved", StringComparison.Ordinal), folder.RelativeFolder);
var converted = folder.File(ManifestStore.ReadSequence(folder.ManifestPath).Frames[0].File);
var bytes = Damage(converted);
var plan = await fx.Service.PlanEmptyTrashAsync(fx.Archive.Id, null, fx.Ct);
Assert.False(plan.Entries.Single().ConversionDeleted, "found in the folder the sequence is in now");
Assert.Contains(Loc.L("Archive.Log.TrashKeptMismatch", replaced.Title), (await EmptyAsync(fx, engine, plan, JobState.Failed)).LogTail);
File.WriteAllBytes(converted, bytes);
await EmptyAsync(fx, engine, await fx.Service.PlanEmptyTrashAsync(fx.Archive.Id, null, fx.Ct), JobState.Done);
Assert.Empty(await fx.Service.ListTrashAsync(fx.Archive.Id, fx.Ct));
}
[Test]
public async Task OriginalsStayWhileTheArchiveCannotTellWhereTheirConversionIs()
{
await using var fx = await CreateAsync(context);
var (id, _) = await UploadedAsync(fx, 2);
var engine = await fx.StartEngineAsync();
var replaced = await ReplaceAsync(fx, id, [0], 500);
var sequence = (await fx.Db.Sequences.GetAsync(id))!;
var folder = fx.Paths.Sequence(sequence.Folder);
var manifest = Sidecar(fx, sequence);
var unknown = Loc.L("Archive.Log.TrashKeptUnknown", replaced.Title);
// A sidecar rebuilt from the photos, as a scan adopts a folder that lost its own: new frame ids, nothing hashed, no
// tombstones. It no longer says what became of the conversion.
ManifestStore.WriteSequence(folder.ManifestPath, manifest with
{
Frames = [.. manifest.Frames.Select(f => f with { Id = Guid.CreateVersion7(), Sha256 = null })],
Removed = null,
});
var plan = await fx.Service.PlanEmptyTrashAsync(fx.Archive.Id, null, fx.Ct);
Assert.False(plan.Entries.Single().ConversionDeleted);
Assert.Contains(unknown, (await EmptyAsync(fx, engine, plan, JobState.Failed)).LogTail);
// A sidecar that cannot be read.
File.WriteAllText(folder.ManifestPath, "{ \"damaged");
Assert.Contains(unknown, (await EmptyAsync(fx, engine, await fx.Service.PlanEmptyTrashAsync(fx.Archive.Id, null, fx.Ct), JobState.Failed)).LogTail);
// The sequence gone from the archive (deleted and erased by another host) while this index still has it: kept until a
// scan settles the index. Then the dry run says the conversion was deleted, and the emptying confirmed with it erases.
Directory.Delete(folder.Folder, recursive: true);
Assert.Contains(unknown, (await EmptyAsync(fx, engine, await fx.Service.PlanEmptyTrashAsync(fx.Archive.Id, null, fx.Ct), JobState.Failed)).LogTail);
Assert.Equal(replaced.Name, (await fx.Service.ListTrashAsync(fx.Archive.Id, fx.Ct)).Single().Name);
await fx.ScanAsync(ScanMode.Rebuild);
Assert.Null(await fx.Db.Sequences.GetAsync(id));
var gone = await fx.Service.PlanEmptyTrashAsync(fx.Archive.Id, null, fx.Ct);
Assert.True(gone.Entries.Single().ConversionDeleted, "no sequence of that id anywhere");
await EmptyAsync(fx, engine, gone, JobState.Done);
Assert.Empty(await fx.Service.ListTrashAsync(fx.Archive.Id, fx.Ct));
}
[Test]
public async Task OriginalsOfABusySequenceStayInTheTrash()
{
await using var fx = await CreateAsync(context, configure: o => o with { LeaseWait = TimeSpan.FromMilliseconds(300) });
var (id, _) = await UploadedAsync(fx, 2);
var replaced = await ReplaceAsync(fx, id, [0], 500);
var plan = await fx.Service.PlanEmptyTrashAsync(fx.Archive.Id, null, fx.Ct);
var parameters = new EmptyTrashParameters([.. plan.Entries.Select(e => new EmptyTrashItem(e.Name, SequenceTrash.EntryFingerprint(e)))], plan.Fingerprint);
// Another host writes the sequence meanwhile: the conversion is not weighed under it.
using (Assert.NotNull(LeaseFile.TryAcquire(fx.Paths.LocksDirectory, $"seq-{id:N}", "another host")))
{
var busy = await fx.Service.Trash.EmptyAsync(fx.Archive, parameters, 0, (_, _) => ValueTask.CompletedTask, fx.Ct);
Assert.Equal((0, TrashKeptReason.Busy), (busy.Erased, busy.Refused.Single().Reason));
Assert.Equal(Loc.L("Archive.Log.TrashKeptBusy", replaced.Title), busy.Refused.Single().LogLine);
}
Assert.Equal(replaced.Name, (await fx.Service.ListTrashAsync(fx.Archive.Id, fx.Ct)).Single().Name);
var free = await fx.Service.Trash.EmptyAsync(fx.Archive, parameters, 0, (_, _) => ValueTask.CompletedTask, fx.Ct);
Assert.Equal((1, 0), (free.Erased, free.Refused.Count));
}
[Test]
public async Task AConversionAnotherHostDeletedIsReadFromTheArchiveNotThisIndex()
{
await using var fx = await CreateAsync(context);
var (id, _) = await UploadedAsync(fx, 3);
var engine = await fx.StartEngineAsync();
var replaced = await ReplaceAsync(fx, id, [0], 500);
var frames = await fx.Db.Frames.ListBySequenceAsync(id);
// A desktop sharing the archive deletes the converted photo; this index still holds it.
var (other, _) = await fx.OtherWriterAsync();
var deletion = await other.FrameTrash.DeleteAsync(await other.FrameTrash.PlanDeleteAsync(id, [frames[0].Id], null, fx.Ct), null, null, fx.Ct);
Assert.Count(3, await fx.Db.Frames.ListBySequenceAsync(id));
var plan = await fx.Service.PlanEmptyTrashAsync(fx.Archive.Id, null, fx.Ct);
Assert.True(plan.Entries.Single(e => e.Name == replaced.Name).ConversionDeleted, "the sidecar's tombstone says so, whatever this index holds");
Assert.False(plan.Entries.Single(e => e.Name == deletion.Entry.Name).ConversionDeleted);
// The deleted conversion is in the trash, damaged: the originals stay.
var record = Assert.NotNull(FrameTrash.ReadEntry(fx.Paths, deletion.Entry.Name));
var copy = Path.Combine(FrameTrash.Location(fx.Paths, deletion.Entry.Name).Folder, record.Photos[0].Files[0].Path);
var bytes = Damage(copy);
var kept = await EmptyAsync(fx, engine, await fx.Service.PlanEmptyTrashAsync(fx.Archive.Id, [replaced.Name], fx.Ct), JobState.Failed);
Assert.Contains(Loc.L("Archive.Log.TrashKeptMismatch", replaced.Title), kept.LogTail);
// Whole again: the originals go, the deleted conversion stays where it is.
File.WriteAllBytes(copy, bytes);
await EmptyAsync(fx, engine, await fx.Service.PlanEmptyTrashAsync(fx.Archive.Id, [replaced.Name], fx.Ct), JobState.Done);
Assert.Equal(deletion.Entry.Name, (await fx.Service.ListTrashAsync(fx.Archive.Id, fx.Ct)).Single().Name);
}
[Test]
public async Task OriginalsStayWhenTheirConversionChangedSince()
{
await using var fx = await CreateAsync(context);
var (id, _) = await UploadedAsync(fx, 2);
var engine = await fx.StartEngineAsync();
var replaced = await ReplaceAsync(fx, id, [0], 500);
var sequence = (await fx.Db.Sequences.GetAsync(id))!;
var folder = fx.Paths.Sequence(sequence.Folder);
var manifest = Sidecar(fx, sequence);
// The converted file was edited in place and hashed again: its frame holds other content, and nothing says what
// became of the conversion.
var edited = Photos.Jpeg(manifest.Frames[0].CapturedAt, 700);
File.WriteAllBytes(folder.File(manifest.Frames[0].File), edited);
ManifestStore.WriteSequence(folder.ManifestPath, manifest with
{
Frames = [.. manifest.Frames.Select((f, i) => i == 0 ? f with { Sha256 = Sha(edited), Size = edited.Length } : f)],
});
var plan = await fx.Service.PlanEmptyTrashAsync(fx.Archive.Id, null, fx.Ct);
Assert.False(plan.Entries.Single().ConversionDeleted, "the frame is there");
Assert.Contains(Loc.L("Archive.Log.TrashKeptMismatch", replaced.Title), (await EmptyAsync(fx, engine, plan, JobState.Failed)).LogTail);
Assert.Equal(replaced.Name, (await fx.Service.ListTrashAsync(fx.Archive.Id, fx.Ct)).Single().Name);
}
[Test]
public async Task AnEmptyingReadsAnEntryOnlyOnceAnUndoWaitingForItIsSettled()
{
await using var fx = await CreateAsync(context);
var (id, photos) = await UploadedAsync(fx, 2);
var engine = await fx.StartEngineAsync();
var replaced = await ReplaceAsync(fx, id, [0], 500);
var (entryFolder, recordPath) = FrameTrash.Location(fx.Paths, replaced.Name);
var record = await File.ReadAllTextAsync(recordPath, fx.Ct);
// Undone: the original is back in its frame, the conversion in an entry of its own.
await fx.Service.RestoreEntryAsync(fx.Archive.Id, replaced.Name, null, fx.Ct);
var undo = (await fx.Service.ListTrashAsync(fx.Archive.Id, fx.Ct)).Single();
// As a crash right after the undo's sidecar was written leaves it: the entry its original came from still lists it,
// and the undo's completion waits for that entry's lease.
Directory.CreateDirectory(entryFolder);
await File.WriteAllTextAsync(recordPath, record, fx.Ct);
var sequence = (await fx.Db.Sequences.GetAsync(id))!;
var folder = fx.Paths.Sequence(sequence.Folder);
var manifest = Sidecar(fx, sequence);
var (undoFolder, undoRecord) = FrameTrash.Location(fx.Paths, undo.Name);
new FrameReplaceJournal(manifest.Versions.Frames - 1, fx.Paths.ToRelative(undoRecord), fx.Paths.ToRelative(undoFolder), [], [], false,
new ConsumedEntry(fx.Paths.ToRelative(recordPath), fx.Paths.ToRelative(entryFolder), SequenceTrash.EntryLease(replaced.Name), [manifest.Frames[0].Id],
null))
{
Phase = ReplacePhase.Written,
}.Write(folder);
var plan = await fx.Service.PlanEmptyTrashAsync(fx.Archive.Id, [replaced.Name], fx.Ct);
Assert.Equal(replaced.Name, plan.Entries.Single().Name);
// The emptying settles the undo under the entry's lease before it reads the entry again, which takes the photo out of
// it: the entry is not erased as planned, and the sequence keeps its original.
var kept = await EmptyAsync(fx, engine, plan, JobState.Failed);
Assert.Contains(Loc.L("Archive.Log.TrashKept", replaced.Title), kept.LogTail);
Assert.FileMissing(folder.ReplaceJournalPath);
Assert.Equal(undo.Name, (await fx.Service.ListTrashAsync(fx.Archive.Id, fx.Ct)).Single().Name);
Assert.Equal(Sha(photos[0]), Sha(folder.File(Sidecar(fx, sequence).Frames[0].File)));
}
[Test]
public async Task AnEntryNamesTheJobThatReplacedItsPhotos()
{
@@ -5,6 +5,7 @@ using Chronos.Core.Localization;
using Chronos.Core.Model;
using Chronos.Core.Project;
using Chronos.Core.Render;
using Chronos.Data.Archiving;
using Chronos.Data.Sync;
using Chronos.Data.Tests.Archiving;
using Chronos.Protocol;
@@ -180,7 +181,7 @@ public sealed class SyncTransferTests(TestContext context)
var kept = await f.Db.Frames.ListBySequenceAsync(local.Id, cancellationToken: f.Ct);
Assert.True(kept.Select(k => k.Sha256).ToHashSet().SetEquals(photos[1..].Select(Sha)), "the photo deleted here stays deleted");
Assert.True(await f.Db.FrameRemovals.IsRemovedAsync(local.Id, Sha(photos[0])), "and keeps its tombstone");
Assert.Contains("deleted on this PC, not downloaded", done.LogTail);
Assert.Contains(Loc.L("Archive.Log.SyncDeletedHere", remote.Frames.Single(fr => fr.Sha256 == Sha(photos[0])).FileName), done.LogTail);
Assert.False(Directory.Exists(Path.Combine(f.Archive.Paths.StagingDirectory, "sync-" + remote.Id.ToString("N"))), "staging cleaned up");
}
@@ -207,7 +208,7 @@ public sealed class SyncTransferTests(TestContext context)
var done = await f.Archive.WaitForAsync(job.Id, JobState.Done);
Assert.Equal(3, remote.Frames.Count);
Assert.Contains("deleted on the server, not uploaded", done.LogTail);
Assert.Contains(Loc.L("Archive.Log.SyncDeletedThere", "DSC_0004.JPG"), done.LogTail);
// Its hash is in the index now: the comparison leaves it out, so the row settles instead of offering Upload for good.
Assert.True((await f.Db.Frames.ListBySequenceAsync(local.Id, cancellationToken: f.Ct)).All(fr => fr.Sha256 is not null), "hashed by the verify");
var entry = await f.EntryAsync(local.DisplayTitle);
@@ -881,6 +882,36 @@ public sealed class SyncTransferTests(TestContext context)
Assert.Equal(SyncStatus.InSync, (await f.EntryAsync("Harbour")).Status);
}
[Test]
public async Task AFrameThatTookBackItsPhotoInAnotherEncodingIsDrawnAgain()
{
await using var f = await SyncFixture.CreateAsync(context);
var photos = f.NewPhotos(3);
var local = await f.LocalAsync("Harbour", photos);
var engine = await f.StartEngineAsync();
var drawn = await engine.EnqueueAsync(ArchiveJobs.Thumbnails([local.Id], "Harbour"), cancellationToken: f.Ct);
await f.Archive.WaitForAsync(drawn.Id, JobState.Done);
var lost = (await f.Db.Frames.ListBySequenceAsync(local.Id, cancellationToken: f.Ct))[1];
File.Delete(f.Archive.Paths.FromRelative(lost.RelativePath));
await f.Archive.Service.Verifier.VerifyAsync(f.Archive.Archive, [local.Id], default, (_, _, _) => ValueTask.CompletedTask, cancellationToken: f.Ct);
Assert.True(((await f.Db.Sequences.GetAsync(local.Id, f.Ct))!.Status & SequenceStatus.ThumbsBuilt) != 0, "drawn before");
// The server converted that photo.
var converted = f.NewPhotos(1)[0];
var remote = f.Remote.Add("Harbour", [photos[0], converted, photos[2]]);
remote.Removed.Add(new RemovedPhotoDto(Sha(photos[1]), Sha(converted), "replaced", DateTimeOffset.UtcNow));
await f.Sync.LinkAsync(f.Server, remote.Id, local.Id, f.Ct);
await f.RefreshAsync();
var job = await f.Sync.EnqueueDownloadAsync(engine, f.Server, remote.Id, "Harbour", SyncDownloadMode.Originals, null);
await f.Archive.WaitForAsync(job.Id, JobState.Done);
// Nothing was filed, only a frame swapped, which cleared what covered the sequence: the thumbnails it had are drawn again.
Assert.Equal(lost.Id, (await f.Db.Frames.ListBySequenceAsync(local.Id, cancellationToken: f.Ct))[1].Id);
var again = Assert.Contains((await f.Db.Jobs.ListAsync(null, JobKind.Thumbs, 50, null, f.Ct)).Items, j => j.Id != drawn.Id && j.TargetIds.Contains(local.Id));
await f.Archive.WaitForAsync(again.Id, JobState.Done);
Assert.True(((await f.Db.Sequences.GetAsync(local.Id, f.Ct))!.Status & SequenceStatus.ThumbsBuilt) != 0, "drawn again");
}
[Test]
public async Task AFrameTakesBackItsPhotoInAnotherEncodingOnlyWhereTheSequenceIsNow()
{
@@ -629,6 +629,9 @@ public sealed class LibraryTests(TestContext context)
plan = await dry.ReadAsync(ProtocolJson.Default.TrashEmptyPlanDto);
Assert.True(plan.Entries.Single(e => e.Kind == "replaced").ConversionDeleted);
Assert.False(plan.Entries.Single(e => e.Name == photo).ConversionDeleted);
// The panel's confirmation names such entries first, each saying so, wherever the trash lists them.
var page = await server.Client.GetStringAsync("/admin/pages/library/trash.js");
Assert.Contains("list: [...plan.entries.filter((e) => e.conversionDeleted), ...plan.entries.filter((e) => !e.conversionDeleted)]", page);
using (var empty = await admin.PostAsJsonAsync("/api/v1/archive/trash/empty", new TrashEmptyRequest(null, false, plan.Fingerprint),
ProtocolJson.Default.TrashEmptyRequest))
await UntilJobAsync(admin, (await empty.ReadAsync(ProtocolJson.Default.JobDto)).Id, "done");