fix(archive): erase replaced originals only on the archive's own word

A conversion counted as deleted when no frame of the sidecar held it, no
tombstone ended its chain and every frame was hashed. A sidecar rebuilt by
adoption meets that after a routine verify although it never knew the
conversion, so the originals were erased, the dry run calling them the last
copy, while the damaged conversion was still in the folder. A sequence found
nowhere and missing from this index counted as gone in the same way, even
when the walk had only skipped its folder (photos without a sidecar), and its
live conversion was never hashed.

A conversion is now deleted only on positive evidence: a Deleted tombstone
ending its chain in the sequence's sidecar, the sequence in the trash, or the
trash's record of erasing it (.chronos/trash/.erased/<id>.json, written
before a deleted sequence's folder goes while a replaced entry of it stays,
swept once none does). Anything else keeps the entry, and its job log line
says what settles it: verify the sequence (a frame never hashed), scan the
archive (a sidecar missing or unreadable), rebuild the index (a row the
archive does not bear out), or restore the entry to keep its photos.

Also:
- a dry run or an emptying walks the archive once for every sequence that
  moved, and again only when a folder it found no longer holds it;
- a download queues the passes a frame swap cleared whatever stops the job
  (JobContext.EnqueueFollowUpAsync with a token), as a restore does;
- the confirmation's detail takes Tab and scrolls from the keyboard when it
  is longer than its card.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-11-03 09:36:01 +01:00
1 parent 8ea25228eb
commit 5012c3bbd2
12 files changed
+657 -108

No files matched your search

@@ -439,9 +439,19 @@ public abstract class FrameTrashTests(TestContext context) : DatabaseTest(contex
var (sequence, frames) = await UploadedAsync(fx, 2);
var replacement = frames[1];
var good = WriteReplaced(fx, sequence, "20261027100000", replacement.Sha256!);
// A replacement no frame of the sequence holds any more (its conversion deleted and erased): the dry run says so, and
// the emptying confirmed with it erases the originals (owner review 2, R7).
var gone = WriteReplaced(fx, sequence, "20261027110000", new string('a', 64));
// A replacement no frame of the sequence holds any more, and whose deletion the sidecar records (its conversion deleted
// and erased): the dry run says so, and the emptying confirmed with it erases the originals (owner review 2, R7).
var deleted = new string('a', 64);
var gone = WriteReplaced(fx, sequence, "20261027110000", deleted);
var sidecar = fx.Paths.Sequence(sequence.Folder).ManifestPath;
var manifest = ManifestStore.ReadSequence(sidecar);
ManifestStore.WriteSequence(sidecar, manifest with
{
Removed = [.. (manifest.Removed ?? []), new RemovedPhoto { Sha256 = deleted, Reason = RemovalReason.Deleted, At = DateTimeOffset.UtcNow }],
});
// One that nothing in the archive says was deleted stays: the sidecar holds no frame of it and no tombstone of it, as a
// sidecar rebuilt from the photos shows a conversion it never knew.
var untraced = WriteReplaced(fx, sequence, "20261027113000", new string('b', 64));
var engine = await fx.StartEngineAsync();
var listed = await fx.Service.ListTrashAsync(fx.Archive.Id, fx.Ct);
Assert.True(listed.All(e => e.Kind == TrashKind.Replaced));
@@ -449,9 +459,11 @@ public abstract class FrameTrashTests(TestContext context) : DatabaseTest(contex
var plan = await fx.Service.PlanEmptyTrashAsync(fx.Archive.Id, null, fx.Ct);
Assert.True(plan.Entries.Single(e => e.Name == FrameTrash.EntryPrefix + gone).ConversionDeleted);
Assert.False(plan.Entries.Single(e => e.Name == FrameTrash.EntryPrefix + good).ConversionDeleted);
Assert.False(plan.Entries.Single(e => e.Name == FrameTrash.EntryPrefix + untraced).ConversionDeleted, "the archive does not say it was deleted");
var job = await engine.EnqueueAsync(ArchiveJobs.EmptyTrash(fx.Archive, plan), cancellationToken: fx.Ct);
await fx.WaitForAsync(job.Id, JobState.Done);
Assert.Empty(await fx.Service.ListTrashAsync(fx.Archive.Id, fx.Ct));
var kept = await fx.WaitForAsync(job.Id, JobState.Failed);
Assert.Contains(Chronos.Core.Localization.Loc.L("Archive.Log.TrashKeptUnknown", sequence.DisplayTitle), kept.LogTail);
Assert.Equal(FrameTrash.EntryPrefix + untraced, (await fx.Service.ListTrashAsync(fx.Archive.Id, fx.Ct)).Single().Name, "the others are erased");
// A replacement whose file no longer hashes to it keeps its originals.
var other = WriteReplaced(fx, sequence, "20261027120000", replacement.Sha256!);