Files
Chronos/tests/Chronos.Data.Tests/Processing/ProcessingProgressDetailTests.cs
T
Alby96andClaude Opus 5.5 45e6911082 feat(jobs): every job handler reports a structured progress detail
The job list showed a bar and a free-text line that each handler worded
its own way. Each handler now reports its step, the item it is on, photo
x of y and sequence/folder/output/step n of m through the P2.1 JobContext
detail. Clients can word and lay that out themselves, and the 2/s
throttle keeps the cost low: counts within a step go through
ReportItemAsync, which allocates nothing.

- scan: List, then Index (folder n of m, photo x of y as an adopted or
  reconciled folder is read) or Check, then FollowUps
- verify, thumbs, proxies, deep analysis: photo x of y of sequence n of m;
  light analysis: sequence n of m; a thumbnail/proxy checkpoint carries
  the frame count it saves
- convert: Verify (resume), Convert photo x of y, Replace; reorganize:
  step n of m with the title; import: the file being copied, photo x of y
- maintenance: the step key, step n of 5, then Check; duplicates, orphans
  and backup run with no count; cleanup names step n of m; empty trash:
  entry n of m
- render (local, workspace, render node): Analyse, Encode (frames of the
  last output, output n of m in a batch), Verify; sync, video copy,
  workspace copy/send/move: Upload/Download/CopyProxy/CopyOriginal/
  CopyVideo/Reorganize with their items and counts

The detail carries keys and names only, never localized text. The
existing Message strings stay for clients that still show them.

Refs #65

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 13:38:05 +01:00

83 lines
3.8 KiB
C#

using Chronos.Core.Diagnostics.Synthetic;
using Chronos.Core.Export;
using Chronos.Core.Model;
using Chronos.Core.Project;
using Chronos.Data.Archiving;
using Chronos.Data.Archiving.Jobs;
using Chronos.Data.Jobs;
using Chronos.Data.Processing;
using Chronos.Data.Tests.Jobs;
using Chronos.Testing;
namespace Chronos.Data.Tests.Processing;
/// <summary>What the analysis and render jobs say they are doing (owner review 5, #65), as the job's progress detail.</summary>
[Category("processing")]
public sealed class ProcessingProgressDetailTests(TestContext context)
{
private const int Frames = 12;
private static SyntheticSequence Scene() => SyntheticSequence.Create(new SyntheticSequenceOptions { FrameCount = Frames, StartEv = 0.5, EndEv = -0.5 });
private static async Task<(DetailRecorder Recorder, JobEngine Engine)> StartAsync(ProcessingFixture fx)
{
var recorder = new DetailRecorder();
var engine = recorder.Engine(fx.Db, fx.Processing.CreateJobHandlers());
await engine.StartAsync(fx.Ct);
return (recorder, engine);
}
private static async Task<Guid> RunAsync(ProcessingFixture fx, JobEngine engine, ArchiveJobRequest request)
{
var job = await engine.EnqueueAsync(request, cancellationToken: fx.Ct);
await fx.WaitForAsync(job.Id, JobState.Done);
return job.Id;
}
[Test]
public async Task AnAnalysisNamesEachSequenceAndADeepOneCountsItsPhotos()
{
await using var fx = await ProcessingFixture.CreateAsync(context);
var first = await fx.AddAsync(Scene(), "First");
var second = await fx.AddAsync(Scene(), "Second");
var (recorder, engine) = await StartAsync(fx);
await using var _ = engine;
var light = await RunAsync(fx, engine, ProcessingJobs.LightAnalysis([first.Id, second.Id], "both"));
var details = recorder.Details(light);
Assert.True(details.All(d => d.Step == JobStep.Analyse && d.PartUnit == JobPartUnit.Sequence && d.Parts == 2 && d.ItemTotal == 0), string.Join("; ", details));
Assert.SequenceEqual([(1, first.DisplayTitle), (2, second.DisplayTitle)], details.Select(d => (d.Part, d.Item!)));
var deep = await RunAsync(fx, engine, ProcessingJobs.DeepAnalysis([first.Id]));
details = recorder.Details(deep);
Assert.True(details.All(d => d.Step == JobStep.Analyse && d.Item == first.DisplayTitle && d.Part == 1 && d.Parts == 1 && d.ItemTotal == Frames),
string.Join("; ", details));
Assert.True(details.Max(d => d.ItemDone) > 0, string.Join("; ", details));
Assert.True(details.All(d => d.ItemDone <= Frames));
}
[Test]
public async Task ARenderPreparesEncodesThenVerifiesWithoutTextInTheDetail()
{
await using var fx = await ProcessingFixture.CreateAsync(context);
var sequence = await fx.AddAsync(Scene());
var (recorder, engine) = await StartAsync(fx);
await using var _ = engine;
var mjpeg = new ExportSettings
{
Preset = new Auto<string>().WithManual("mjpeg-avi"),
Overrides = new ExportOverrides { Width = 96, Height = 64 },
NameTemplate = "clip-{codec}",
};
var id = await RunAsync(fx, engine, ProcessingJobs.Render(sequence, mjpeg, 96, 64));
Assert.SequenceEqual([JobStep.Analyse, JobStep.Encode, JobStep.Verify], recorder.Steps(id));
var details = recorder.Details(id);
Assert.Equal(new JobDetail(JobStep.Analyse, sequence.DisplayTitle), details[0]);
var encode = details.Where(d => d.Step == JobStep.Encode).ToList();
Assert.True(encode.All(d => d.Item == sequence.DisplayTitle && d.Parts == 0 && d.ItemDone <= d.ItemTotal), string.Join("; ", encode));
Assert.True(encode.Max(d => d.ItemDone) > 0, string.Join("; ", encode));
Assert.Equal(new JobDetail(JobStep.Verify, "clip-MJPEG.avi"), details[^1]);
}
}