fix(archive): scans leave sequences waiting for a folder alone and build server images

A sequence created through POST /api/v1/sequences keeps an empty folder until its
first frame. Scans no longer adopt loose photos at the archive root under its id,
and a rebuild, the orphans report and fix, verify and the scan follow-ups no longer
treat it as the root sequence, as missing or as a sequence to analyse. All of them
use ArchiveIngest.AwaitsFolder.

On the server (ArchiveServiceOptions.ImagesAfterScan), a scan that indexes sequences
without thumbnails or proxies queues background Thumbs and Proxies passes for them,
as an upload does. A scan that finds photos added or removed clears ThumbsBuilt and
ProxiesBuilt together with AnalyzedLight.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
Claude committed 2026-10-12 15:58:37 +00:00
1 parent 32a0e9bbc1
commit fba05c2840
10 files changed
+290 -29

No files matched your search

@@ -17,6 +17,24 @@ public sealed class ArchiveIngestTests(TestContext context)
Guid? sequenceId = null, string? title = null, string name = "IMG_0001.JPG") =>
new(fx.Archive.Id, sequenceId, title, sequenceId is null && title is null ? sessionKey : null, staged.Path, name, staged.Size, staged.Sha256, null, null);
/// <summary>A sequence as <c>POST /api/v1/sequences</c> creates it: a row without a folder or frames.</summary>
private static async Task<Sequence> CreateWithoutPhotosAsync(ArchiveFixture fx, string title)
{
var created = new Sequence
{
Id = Guid.CreateVersion7(),
ArchiveId = fx.Archive.Id,
Title = title,
Folder = string.Empty,
Rating = 4,
Origin = SequenceOrigin.Server,
OwnerUserId = Guid.CreateVersion7(),
UpdatedAt = DateTimeOffset.UtcNow,
};
await fx.Db.Sequences.UpsertAsync(created, fx.Ct);
return created;
}
[Test]
public async Task ASessionKeyCreatesOneSequenceNamedByTheTemplates()
{
@@ -242,6 +260,80 @@ public sealed class ArchiveIngestTests(TestContext context)
Assert.FileExists(staged.Path);
}
[Test]
public async Task ASequenceWaitingForItsFirstFrameNeverLendsItsIdToTheArchiveRoot()
{
await using var fx = await CreateAsync(context);
var waiting = await CreateWithoutPhotosAsync(fx, "Harbour sunset");
// Loose photos at the root, which a scan adopts in place.
Photos.WriteSeries(fx.Archive.RootPath, Start.AddDays(-1), 2);
await fx.ScanAsync();
var root = ManifestStore.ReadSequence(fx.Paths.Sequence(string.Empty).ManifestPath);
Assert.NotEqual(waiting.Id, root.Id);
var rootRow = (await fx.Db.Sequences.GetAsync(root.Id))!;
Assert.Equal((string.Empty, 2), (rootRow.Folder, rootRow.FrameCount));
var row = (await fx.Db.Sequences.GetAsync(waiting.Id))!;
Assert.Equal((string.Empty, 0, "Harbour sunset"), (row.Folder, row.FrameCount, row.Title));
// Its first frame still gets a folder of its own, and the root keeps its photos.
var first = await fx.Service.Ingest.CommitAsync(Request(fx, fx.Stage(Start, 1), sequenceId: waiting.Id), fx.Ct);
Assert.Equal(waiting.Id, first.SequenceId);
var placed = (await fx.Db.Sequences.GetAsync(waiting.Id))!;
Assert.Equal(("2026/2026-09-28 Canon EOS R5", 1), (placed.Folder, placed.FrameCount));
Assert.Equal(root.Id, ManifestStore.ReadSequence(fx.Paths.Sequence(string.Empty).ManifestPath).Id);
Assert.Equal(2, (await fx.Db.Sequences.GetAsync(root.Id))!.FrameCount);
}
[Test]
public async Task ARootSequenceWhoseSidecarIsGoneIsAdoptedAgainUnderItsOwnId()
{
await using var fx = await CreateAsync(context);
Photos.WriteSeries(fx.Archive.RootPath, Start, 2);
await fx.ScanAsync();
var adopted = Assert.NotNull((await fx.Db.Sequences.ListLocationsAsync(fx.Archive.Id, fx.Ct)).SingleOrDefault());
// Created later, so its id sorts after the root sequence's.
var waiting = await CreateWithoutPhotosAsync(fx, "Harbour sunset");
File.Delete(fx.Paths.Sequence(string.Empty).ManifestPath);
await fx.ScanAsync();
Assert.Equal(adopted.Id, ManifestStore.ReadSequence(fx.Paths.Sequence(string.Empty).ManifestPath).Id);
Assert.Equal(2, (await fx.Db.Sequences.GetAsync(adopted.Id))!.FrameCount);
var row = (await fx.Db.Sequences.GetAsync(waiting.Id))!;
Assert.Equal((string.Empty, 0), (row.Folder, row.FrameCount));
}
[Test]
public async Task RebuildOrphansAndVerifyLeaveASequenceWaitingForItsFirstFrame()
{
await using var fx = await CreateAsync(context);
Photos.WriteSeries(Path.Combine(fx.Archive.RootPath, "Trips", "Comet"), Start, 2);
await fx.ScanAsync();
var waiting = await CreateWithoutPhotosAsync(fx, "Harbour sunset");
// It has no sidecar yet, which is no reason to drop it.
var rebuilt = await fx.ScanAsync(ScanMode.Rebuild);
Assert.Equal(0, rebuilt.Removed);
var orphans = await fx.Service.FindOrphansAsync(fx.Archive.Id, fx.Ct);
Assert.Empty(orphans.MissingSequences);
Assert.Empty(orphans.UnindexedFolders);
Assert.Equal(0, await fx.Service.RemoveMissingSequencesAsync(fx.Archive.Id, [waiting.Id], fx.Ct));
var report = await fx.Service.Verifier.VerifyAsync(fx.Archive, null, default, (_, _, _) => ValueTask.CompletedTask, null, fx.Ct);
Assert.Equal((1, 2L), (report.Sequences, report.Checked));
var kept = Assert.NotNull(await fx.Db.Sequences.GetAsync(waiting.Id));
Assert.Equal(("Harbour sunset", 4), (kept.Title, kept.Rating));
// The archive root is not its folder: loose photos there are a folder the index does not know yet.
Photos.WriteSeries(fx.Archive.RootPath, Start.AddDays(-1), 1, firstSeed: 50);
Assert.SequenceEqual([string.Empty], (await fx.Service.FindOrphansAsync(fx.Archive.Id, fx.Ct)).UnindexedFolders);
var first = await fx.Service.Ingest.CommitAsync(Request(fx, fx.Stage(Start.AddDays(1), 1), sequenceId: waiting.Id), fx.Ct);
Assert.Equal(waiting.Id, first.SequenceId);
Assert.Equal("2026/2026-09-29 Canon EOS R5", (await fx.Db.Sequences.GetAsync(waiting.Id))!.Folder);
}
[Test]
public async Task FramesInsertedBeforeOthersTakeTheProjectPositionsAlong()
{