fix: full verification against the brief — 137 confirmed findings fixed over six passes #4

Merged
Alby96 merged 169 commits from claude/keen-knuth-uhxv8w into main 2026-10-13 12:10:04 +02:00
4 changed files with 57 additions and 11 deletions
Showing only changes of commit b76b745d7d - Show all commits

No files matched your search

+2 -2
View File
@@ -1002,8 +1002,8 @@ public sealed class ArchiveViewModel : SectionViewModel
{
case OrphanKind.UnlistedFiles or OrphanKind.MissingFiles when row.SequenceId is { } id:
// The photos it indexes are analysed in the background, as after a scan.
var followUps = Services.Engine;
await Task.Run(() => archives.ReconcileAsync(id, followUps));
var (followUps, deep) = (Services.Engine, Services.Settings.DeepAnalysisAfterScan);
await Task.Run(() => archives.ReconcileAsync(id, followUps, deep));
break;
case OrphanKind.MissingSequence when row.SequenceId is { } id:
var confirmed = Services.Dialogs.Confirm(new ConfirmRequest
+11 -5
View File
@@ -288,15 +288,18 @@ public sealed class ArchiveService : IJobHandlerProvider
/// <summary>
/// Orphans fix: index the unlisted photos of a sequence and flag its missing files. Photos added, gone or back clear
/// what covered the frames, as a scan's reconcile does (<see cref="ArchiveIndexer.ReconcileAsync"/>), and what a scan's
/// follow-ups would make again is queued on <paramref name="followUps"/> (null: nothing): the light analysis and, on a
/// server (<see cref="ArchiveServiceOptions.ImagesAfterScan"/>), the thumbnails and proxies. A kind the engine does
/// not run, or already queued for the sequence, is left out.
/// follow-ups would make again is queued on <paramref name="followUps"/> (null: nothing): the light analysis, a
/// background deep analysis when <paramref name="deepAnalysis"/> asks (as <see cref="ScanParameters.DeepAnalysis"/>
/// does for a scan) and, on a server (<see cref="ArchiveServiceOptions.ImagesAfterScan"/>), the thumbnails and proxies.
/// A kind the engine does not run, or one a queued job of that kind already covers for the sequence, is left out.
/// </summary>
public async Task ReconcileAsync(Guid sequenceId, JobEngine? followUps, CancellationToken cancellationToken = default)
public async Task ReconcileAsync(Guid sequenceId, JobEngine? followUps, bool deepAnalysis, CancellationToken cancellationToken = default)
{
var (archive, sequence) = await LoadSequenceAsync(sequenceId, cancellationToken).ConfigureAwait(false);
if (!await Indexer.ReconcileAsync(archive, sequence, cancellationToken).ConfigureAwait(false) || followUps is null) return;
List<ArchiveJobRequest> requests = [ProcessingJobs.LightAnalysis([sequenceId], sequence.DisplayTitle)];
// BRIEF §10.2: background, low priority.
if (deepAnalysis) requests.Add(ProcessingJobs.DeepAnalysis([sequenceId], sequence.DisplayTitle) with { Priority = JobPriority.Background });
if (_writer.Options.ImagesAfterScan)
{
requests.Add(ArchiveJobs.Thumbnails([sequenceId], sequence.DisplayTitle));
@@ -305,7 +308,10 @@ public sealed class ArchiveService : IJobHandlerProvider
}
foreach (var request in requests)
{
if (!followUps.Runs(request.Kind) || await _db.Jobs.IsQueuedAsync(request.Kind, sequenceId, cancellationToken).ConfigureAwait(false)) continue;
if (!followUps.Runs(request.Kind)) continue;
// A queued job runs after the fix, on the frames as they are then, whatever else it targets (a scan's follow-ups).
var queued = await _db.Jobs.ListQueuedAsync(request.Kind, 1000, cancellationToken).ConfigureAwait(false);
if (queued.Any(j => j.TargetIds.Contains(sequenceId))) continue;
await followUps.EnqueueAsync(request, cancellationToken: cancellationToken).ConfigureAwait(false);
}
}
@@ -113,7 +113,7 @@ public sealed class ArchiveIntegrityTests(TestContext context)
Assert.Equal(manifest.Frames[0].Id, orphans.MissingFiles.Single().Id);
Assert.SequenceEqual(["New folder"], report.UnindexedFolders);
await fx.Service.ReconcileAsync(id, null, fx.Ct);
await fx.Service.ReconcileAsync(id, null, deepAnalysis: false, fx.Ct);
var frames = await fx.Db.Frames.ListBySequenceAsync(id);
Assert.Equal(4, frames.Count);
Assert.Equal(FrameFlags.Missing, frames[0].Flags);
@@ -136,9 +136,10 @@ public sealed class ArchiveIntegrityTests(TestContext context)
var folder = fx.Paths.Sequence((await fx.Db.Sequences.GetAsync(id, fx.Ct))!.Folder);
File.WriteAllBytes(Path.Combine(folder.Originals, "dropped.JPG"), Photos.Jpeg(Start.AddMinutes(5), 50));
// The fix indexes the photo copied in by hand, and queues the thumbnails and proxies of the frames as they are now.
// The fix indexes the photo copied in by hand, and queues the thumbnails and proxies of the frames as they are now;
// no analysis, even when asked for one.
var before = (await fx.Db.Jobs.ListAsync(null, null, 100, null, fx.Ct)).Items.Select(j => j.Id).ToHashSet();
await server.ReconcileAsync(id, engine, fx.Ct);
await server.ReconcileAsync(id, engine, deepAnalysis: true, fx.Ct);
var queued = (await fx.Db.Jobs.ListAsync(null, null, 100, null, fx.Ct)).Items.Where(j => !before.Contains(j.Id)).ToList();
Assert.SequenceEqual([JobKind.Proxies, JobKind.Thumbs], queued.Select(j => j.Kind).Order());
foreach (var job in queued)
@@ -101,13 +101,14 @@ public sealed class AnalysisFollowUpTests(TestContext context)
// light analysis it queues waits on the first new photo's probe, so what the fix left can be seen.
fx.Write(SyntheticSequence.Create(new SyntheticSequenceOptions { FrameCount = 18 }), "Roof", first: 12);
fx.Decoder.HoldProbeOf(12);
await fx.Archive.Service.ReconcileAsync(sequence.Id, fx.Engine, fx.Ct);
await fx.Archive.Service.ReconcileAsync(sequence.Id, fx.Engine, deepAnalysis: false, fx.Ct);
const SequenceStatus covering = SequenceStatus.AnalyzedLight | images;
var row = (await fx.Db.Sequences.GetAsync(sequence.Id, fx.Ct))!;
Assert.Equal((18, SequenceStatus.None), (row.FrameCount, row.Status & covering));
Assert.Equal(SequenceStatus.None, ManifestStore.ReadSequence(folder.ManifestPath).Status & covering);
var again = (await fx.Db.Jobs.ListAsync(null, JobKind.LightAnalyse, cancellationToken: fx.Ct)).Items.Single(j => j.Id != first.Id);
Assert.SequenceEqual([sequence.Id], again.TargetIds);
Assert.Empty((await fx.Db.Jobs.ListAsync(null, JobKind.DeepAnalyse, cancellationToken: fx.Ct)).Items);
await fx.Decoder.Holding.Task.WaitAsync(TimeSpan.FromSeconds(60), fx.Ct);
fx.Decoder.Release();
@@ -118,6 +119,44 @@ public sealed class AnalysisFollowUpTests(TestContext context)
Assert.Contains("18", ProjectSettings.FromJson(await File.ReadAllTextAsync(folder.ProjectPath, fx.Ct)).Timing.FrameRate.ReasonArgs!);
}
[Test]
public async Task PhotosTheOrphansFixIndexesGetTheDeepAnalysisAScanWouldQueue()
{
await using var fx = await ProcessingFixture.CreateAsync(context);
var sequence = await fx.AddAsync(SyntheticSequence.Create(new SyntheticSequenceOptions { FrameCount = 12 }), "Roof");
var lake = await fx.AddAsync(SyntheticSequence.Create(new SyntheticSequenceOptions { FrameCount = 12 }), "Lake");
var folder = fx.Folder(sequence);
await fx.StartEngineAsync(withArchive: true);
Task<IReadOnlyList<Job>> QueuedDeepAsync() => fx.Db.Jobs.ListQueuedAsync(JobKind.DeepAnalyse, 50, fx.Ct);
// The host asks for a deep analysis after scans: the orphans fix queues one in the background too, behind the light
// analysis, which waits on the first new photo's probe so the queue can be seen.
fx.Write(SyntheticSequence.Create(new SyntheticSequenceOptions { FrameCount = 18 }), "Roof", first: 12);
fx.Decoder.HoldProbeOf(12);
await fx.Archive.Service.ReconcileAsync(sequence.Id, fx.Engine, deepAnalysis: true, fx.Ct);
var light = (await fx.Db.Jobs.ListAsync(null, JobKind.LightAnalyse, cancellationToken: fx.Ct)).Items.Single();
var deep = (await QueuedDeepAsync()).Single();
Assert.SequenceEqual([sequence.Id], deep.TargetIds);
Assert.Equal(JobPriority.Background, deep.Priority);
await fx.Decoder.Holding.Task.WaitAsync(TimeSpan.FromSeconds(60), fx.Ct);
// The user cancels it, and asks for a deep analysis of both sequences instead. More photos and the fix again: the
// one waiting covers them, so no other is queued.
await fx.Engine.CancelAsync(deep.Id, fx.Ct);
var both = await fx.EnqueueAsync(Titano.Data.Processing.ProcessingJobs.DeepAnalysis([lake.Id, sequence.Id]));
fx.Write(SyntheticSequence.Create(new SyntheticSequenceOptions { FrameCount = 20 }), "Roof", first: 18);
await fx.Archive.Service.ReconcileAsync(sequence.Id, fx.Engine, deepAnalysis: true, fx.Ct);
Assert.SequenceEqual([both.Id], (await QueuedDeepAsync()).Select(j => j.Id));
fx.Decoder.Release();
await fx.WaitForAsync(light.Id, JobState.Done);
await fx.WaitForAsync(both.Id, JobState.Done);
var row = (await fx.Db.Sequences.GetAsync(sequence.Id, fx.Ct))!;
Assert.Equal(20, row.FrameCount);
Assert.True(row.Status.HasFlag(SequenceStatus.AnalyzedDeep), row.Status.ToString());
Assert.Equal(20, Titano.Data.Processing.SequenceAnalyser.ReadReport(folder, 20)?.FrameCount);
}
[Test]
public async Task AScanAskedForDeepAnalysisQueuesItInTheBackgroundForNewSequencesOnly()
{