feat: owner review 2 phase 4a: Reorganize sequences after import (#12)
CI / Build and test (push) Successful in 9m15s
CI / Windows tests and installer (push) Skipped
CI / YAML check (push) Successful in 6s
Release / Build, test and publish (push) Successful in 15m35s
CI / PostgreSQL 16 integration (push) Successful in 7m26s
CI / PostgreSQL 17 integration (push) Successful in 6m47s
CI / Docker image (push) Successful in 59s
Release / Server image (push) Successful in 1m24s

- Reorganize… on the web panel and the desktop: folder, file and title templates applied to existing sequences, with a dry run and an explicit Apply that runs as a job.
- One naming rule (FrameNaming) for import, upload and Reorganize.
- Crash-safe plan and file journals, held plans, stale-plan refusal; exports move with their folder.
- Writers refuse a folder another program moved or gave to another sequence.
- Server: POST /api/v1/archive/reorganize with a bounded plan cache; template rules.
- Phase 3 docs and translations merged; strings in all 38 languages.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Alberto Balbo <alberto.balbo.96@gmail.com>
This commit was merged in pull request #12.
This commit is contained in:
Alby96andClaude Opus 5.5 authored and Alby96 committed 2026-10-27 21:58:39 +01:00
1 parent 9aa818ed47
commit 7e4a3b481d
416 files changed
+15304 -1572

No files matched your search

@@ -1127,6 +1127,90 @@ public abstract class FrameTrashTests(TestContext context) : DatabaseTest(contex
Assert.SequenceEqual(frames.Select(f => f.Id), (await fx.Db.Frames.ListBySequenceAsync(sequence.Id)).Select(f => f.Id));
}
/// <summary>The files of a sequence as its sidecar names them, after checking that the index names the same ones and that each holds its photo.</summary>
private static async Task<List<string>> FilesAsync(ArchiveFixture fx, Guid id)
{
var sequence = Assert.NotNull(await fx.Db.Sequences.GetAsync(id));
var folder = fx.Paths.Sequence(sequence.Folder);
var sidecar = ManifestStore.ReadSequence(folder.ManifestPath);
var rows = await fx.Db.Frames.ListBySequenceAsync(id);
Assert.SequenceEqual(sidecar.Frames.Select(f => (f.Id, folder.ArchiveRelative(f.File))), rows.Select(r => (r.Id, r.RelativePath)));
foreach (var frame in sidecar.Frames) Assert.Equal(frame.Sha256, Sha(folder.File(frame.File)));
return [.. sidecar.Frames.Select(f => f.File)];
}
[Test]
public async Task PhotosDeletedBeforeAReorganizeComeBackBesideTheNamesItGave()
{
var fx = await FixtureAsync();
var (sequence, frames) = await UploadedAsync(fx, 4);
var numbered = new RenameTemplates(File: "{n:000}");
await fx.Service.ApplyRenameAsync(await fx.Service.PlanReorganizeAsync(fx.Archive.Id, [sequence.Id], numbered, fx.Ct), null, fx.Ct);
var folder = fx.Paths.Sequence(sequence.Folder);
File.WriteAllText(folder.File("originals/002.xmp"), "second");
await fx.ScanAsync();
// The record keeps the names the photo and its companion had: 002.JPG and 002.xmp.
var deleted = await DeleteAsync(fx, (await fx.Db.Sequences.GetAsync(sequence.Id))!, frames[1]);
Assert.SequenceEqual(["originals/002.JPG", "originals/002.xmp"], FrameTrash.ReadEntry(fx.Paths, deleted.Entry.Name)!.Photos.Single().Files.Select(f => f.From));
// Moved and renamed since: the photos that stay take 001-003, the deleted photo's name included.
var moved = new RenameTemplates(Folder: "moved/{date}", File: "{n:000}");
await fx.Service.ApplyRenameAsync(await fx.Service.PlanReorganizeAsync(fx.Archive.Id, [sequence.Id], moved, fx.Ct), null, fx.Ct);
Assert.SequenceEqual(["originals/001.JPG", "originals/002.JPG", "originals/003.JPG"], await FilesAsync(fx, sequence.Id));
// Restored into the sequence where it is now, under its own name made free: its companion follows that name.
var restored = await fx.Service.RestoreEntryAsync(fx.Archive.Id, deleted.Entry.Name, null, fx.Ct);
Assert.Equal(1, restored.Photos);
var row = (await fx.Db.Sequences.GetAsync(sequence.Id))!;
Assert.Equal("moved/2026-09-28", row.Folder);
Assert.SequenceEqual(["originals/001.JPG", "originals/002_2.JPG", "originals/002.JPG", "originals/003.JPG"], await FilesAsync(fx, sequence.Id));
var now = fx.Paths.Sequence(row.Folder);
Assert.Equal(frames[1].Sha256, Sha(now.File("originals/002_2.JPG")));
Assert.Equal("second", File.ReadAllText(now.File("originals/002_2.xmp")));
Assert.SequenceEqual(frames.Select(f => f.Id), (await fx.Db.Frames.ListBySequenceAsync(sequence.Id)).Select(f => f.Id));
Assert.DoesNotContain(TrashKind.Photos, (await fx.Service.ListTrashAsync(fx.Archive.Id, fx.Ct)).Select(e => e.Kind));
}
[Test]
public async Task AReorganizeWaitsForARestoreItsEntryHoldsThenSettlesItFirst()
{
var fx = await FixtureAsync();
var (sequence, frames) = await UploadedAsync(fx, 3);
var folder = fx.Paths.Sequence(sequence.Folder);
var deleted = await DeleteAsync(fx, sequence, frames[1]);
// A restore died after moving the original back, before the sidecar; the entry is being emptied meanwhile.
var journal = RestoreJournal(fx, deleted.Entry);
journal.Write(folder);
var back = journal.Photos[0].Moves[0];
File.Move(fx.Paths.FromRelative(back.To), folder.File(back.From));
var templates = new RenameTemplates(Folder: "moved/{date}", File: "{n:000}");
var plan = await fx.Service.PlanReorganizeAsync(fx.Archive.Id, [sequence.Id], templates, fx.Ct);
Assert.Equal(2, plan.Steps.Single().FileChanges);
var before = await FilesAsync(fx, sequence.Id);
using (Assert.NotNull(LeaseFile.TryAcquire(fx.Paths.LocksDirectory, SequenceTrash.EntryLease(deleted.Entry.Name), "other")))
{
// Neither the folder nor a file name changes under that restore.
await Assert.ThrowsAsync<LeaseUnavailableException>(() => fx.Service.ApplyRenameAsync(plan, null, fx.Ct));
Assert.Equal(sequence.Folder, (await fx.Db.Sequences.GetAsync(sequence.Id))!.Folder);
Assert.SequenceEqual(before, await FilesAsync(fx, sequence.Id));
Assert.FileExists(folder.RestoreJournalPath);
Assert.FileExists(folder.File(back.From));
}
// Once the entry is free the rename resumes: the restore is settled first (the original goes back into its entry),
// then the folder moves and the files are renamed; the photo then comes back beside them.
Assert.Equal(1, await fx.Service.Renamer.ResumePendingAsync(fx.Archive, fx.Ct));
Assert.Equal(frames[1].Sha256, Sha(fx.Paths.FromRelative(back.To)));
var row = (await fx.Db.Sequences.GetAsync(sequence.Id))!;
Assert.Equal("moved/2026-09-28", row.Folder);
Assert.FileMissing(fx.Paths.Sequence(row.Folder).RestoreJournalPath);
Assert.SequenceEqual(["originals/001.JPG", "originals/002.JPG"], await FilesAsync(fx, sequence.Id));
Assert.Equal(1, (await fx.Service.RestoreEntryAsync(fx.Archive.Id, deleted.Entry.Name, null, fx.Ct)).Photos);
Assert.SequenceEqual(frames.Select(f => f.Id), (await fx.Db.Frames.ListBySequenceAsync(sequence.Id)).Select(f => f.Id));
Assert.Count(3, await FilesAsync(fx, sequence.Id));
}
[Test]
public async Task ARestoreIntoANewSequenceStoppedBetweenPhotosKeepsItsRecordTrue()
{