Files
Chronos/tests/Chronos.Data.Tests/Processing/AnalysisFollowUpTests.cs
T
Alby96andClaude Opus 5.5 5f27a86406
CI / Build and test (pull_request) Failing after 2m3s
CI / PostgreSQL 16 integration (pull_request) Skipped
CI / PostgreSQL 17 integration (pull_request) Skipped
CI / Docker image (pull_request) Skipped
CI / Windows tests and installer (pull_request) Skipped
CI / YAML check (pull_request) Successful in 4s
refactor!: rename Titano to Chronos and move CI and releases to Gitea
The owner renamed the product and moved the repository to the self-hosted
Gitea (https://gitea.encke-hake.ts.net/BalboSoft/Chronos) for more control,
and asked for Actions and a first automatic release with the server package
and the Windows exe (docs/requests/2026-10-23-chronos-gitea.md).

- Chronos everywhere: a byte-exact rename of contents and paths, then a
  per-language review of the forms the old name's ending had dictated.
- Gitea instead of GitHub: the update check, licence, issue and support
  links read ChronosReleasesUrl; the update check takes the highest stable
  version, offers a pre-release build its final release and reports a
  repository it cannot see as a failed check. EULA, security policy and
  Gitea issue forms live at the repository root.
- Gitea Actions for the Linux act_runner (.gitea/workflows): CI, release,
  nightly image and performance gates in the .NET SDK container with git
  checkout. The release cross-compiles the Windows programs, checks their
  icon, version and DPI manifest, packs installers and zips, publishes the
  Gitea release and pushes the server image (REGISTRY_TOKEN). Windows-only
  tests run in an opt-in job on a Windows runner (WINDOWS_RUNNER).
- New Chronos.Tools commands: zip, gitea-release, postgres-ci (replaces the
  docker-exec script, which Gitea's service containers do not allow) and
  pe-check.

BREAKING CHANGE: programs, settings, data folders, file types, environment
variables and the Docker image use the new name; nothing is migrated from
Titano, which never had a release.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-23 11:34:48 +02:00

223 lines
13 KiB
C#

using Chronos.Core.Archiving;
using Chronos.Core.Diagnostics.Synthetic;
using Chronos.Core.Import;
using Chronos.Core.Model;
using Chronos.Core.Project;
using Chronos.Data.Archiving;
using Chronos.Data.Tests.Archiving;
using Chronos.Testing;
namespace Chronos.Data.Tests.Processing;
/// <summary>New sequences get their light analysis (and so their Auto values) without any user action (BRIEF §1.1).</summary>
[Category("processing")]
public sealed class AnalysisFollowUpTests(TestContext context)
{
[Test]
public async Task AnAdoptingScanQueuesLightAnalysisOfTheNewSequencesOnly()
{
await using var fx = await ProcessingFixture.CreateAsync(context);
fx.Write(SyntheticSequence.Create(new SyntheticSequenceOptions { FrameCount = 12 }), "Roof");
await fx.StartEngineAsync(withArchive: true);
var scan = await fx.EnqueueAsync(ArchiveJobs.Scan(fx.Archive.Archive, full: true));
await fx.WaitForAsync(scan.Id, JobState.Done);
var light = Assert.NotNull(await SingleLightJobAsync(fx));
await fx.WaitForAsync(light.Id, JobState.Done);
var sequence = (await fx.Db.Sequences.GetAsync(light.TargetIds.Single(), fx.Ct))!;
Assert.Equal("Roof", sequence.Folder);
Assert.True(sequence.Status.HasFlag(SequenceStatus.AnalyzedLight), "analysed");
Assert.True(ProjectSettings.FromJson(await File.ReadAllTextAsync(fx.Folder(sequence).ProjectPath, fx.Ct)).Timing.Mode.HasAdvice, "advised");
// Scans that find nothing new queue nothing more.
foreach (var full in new[] { false, true })
{
var again = await fx.EnqueueAsync(ArchiveJobs.Scan(fx.Archive.Archive, full));
await fx.WaitForAsync(again.Id, JobState.Done);
}
Assert.Equal(light.Id, (await SingleLightJobAsync(fx))?.Id);
}
[Test]
public async Task AnImportQueuesLightAnalysisOfTheSequencesItFilled()
{
await using var fx = await ProcessingFixture.CreateAsync(context);
var card = context.CreateTempDirectory("card");
Photos.WriteSeries(Path.Combine(card, "DCIM", "100CANON"), ArchiveFixture.Start, 10);
var plan = await fx.Archive.Service.PlanImportAsync(fx.Archive.Archive.Id, card, new ImportOptions(), null, null, fx.Ct);
await fx.StartEngineAsync(withArchive: true);
var import = await fx.Engine.EnqueueAsync(ArchiveJobs.Import(fx.Archive.Archive, plan, null), createdBy: Guid.CreateVersion7(), cancellationToken: fx.Ct);
await fx.WaitForAsync(import.Id, JobState.Done);
var light = Assert.NotNull(await SingleLightJobAsync(fx));
await fx.WaitForAsync(light.Id, JobState.Done);
var sequenceId = await fx.Db.Sequences.FindBySessionKeyAsync(fx.Archive.Archive.Id, plan.Sessions.Single().SessionKey, fx.Ct);
Assert.SequenceEqual([Assert.NotNull(sequenceId)], light.TargetIds);
Assert.Equal(import.CreatedBy, light.CreatedBy);
Assert.Equal(JobPriority.Background, light.Priority);
Assert.True((await fx.Db.Sequences.GetAsync(sequenceId.Value, fx.Ct))!.Status.HasFlag(SequenceStatus.AnalyzedLight), "analysed");
}
[Test]
public async Task PhotosAddedToAnAnalysedFolderAreAnalysedAgain()
{
await using var fx = await ProcessingFixture.CreateAsync(context);
var sequence = await fx.AddAsync(SyntheticSequence.Create(new SyntheticSequenceOptions { FrameCount = 12 }), "Roof");
await fx.StartEngineAsync(withArchive: true);
var first = await fx.EnqueueAsync(Chronos.Data.Processing.ProcessingJobs.LightAnalysis([sequence.Id]));
await fx.WaitForAsync(first.Id, JobState.Done);
// The camera kept shooting into the folder: the next scan indexes the new photos and analyses the sequence again.
fx.Write(SyntheticSequence.Create(new SyntheticSequenceOptions { FrameCount = 18 }), "Roof", first: 12);
var scan = await fx.EnqueueAsync(ArchiveJobs.Scan(fx.Archive.Archive));
await fx.WaitForAsync(scan.Id, JobState.Done);
var again = (await fx.Db.Jobs.ListAsync(null, JobKind.LightAnalyse, cancellationToken: fx.Ct)).Items.Single(j => j.Id != first.Id);
await fx.WaitForAsync(again.Id, JobState.Done);
var analysed = (await fx.Db.Sequences.GetAsync(sequence.Id, fx.Ct))!;
Assert.Equal(18, analysed.FrameCount);
Assert.True(analysed.Status.HasFlag(SequenceStatus.AnalyzedLight), "analysed again");
Assert.True(ManifestStore.ReadSequence(fx.Folder(sequence).ManifestPath).Status.HasFlag(SequenceStatus.AnalyzedLight), "sidecar status");
}
[Test]
public async Task PhotosTheOrphansFixIndexesAreAnalysedAgain()
{
await using var fx = await ProcessingFixture.CreateAsync(context);
var sequence = await fx.AddAsync(SyntheticSequence.Create(new SyntheticSequenceOptions { FrameCount = 12 }), "Roof");
var folder = fx.Folder(sequence);
await fx.StartEngineAsync(withArchive: true);
var first = await fx.EnqueueAsync(Chronos.Data.Processing.ProcessingJobs.LightAnalysis([sequence.Id]));
await fx.WaitForAsync(first.Id, JobState.Done);
// A server sharing the archive drew the twelve frames and made their proxies.
const SequenceStatus images = SequenceStatus.ThumbsBuilt | SequenceStatus.ProxiesBuilt;
var manifest = ManifestStore.ReadSequence(folder.ManifestPath);
ManifestStore.WriteSequence(folder.ManifestPath, manifest with { Status = manifest.Status | images });
await fx.Db.Sequences.UpdateStatusAsync(sequence.Id, images, SequenceStatus.None, fx.Ct);
// Photos copied into the folder by hand: the Archive screen's orphans check lists them, and its fix indexes them. The
// 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, 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();
await fx.WaitForAsync(again.Id, JobState.Done);
row = (await fx.Db.Sequences.GetAsync(sequence.Id, fx.Ct))!;
Assert.True(row.Status.HasFlag(SequenceStatus.AnalyzedLight), "analysed again");
Assert.True(ManifestStore.ReadSequence(folder.ManifestPath).Status.HasFlag(SequenceStatus.AnalyzedLight), "sidecar status");
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(Chronos.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, Chronos.Data.Processing.SequenceAnalyser.ReadReport(folder, 20)?.FrameCount);
}
[Test]
public async Task AScanAskedForDeepAnalysisQueuesItInTheBackgroundForNewSequencesOnly()
{
await using var fx = await ProcessingFixture.CreateAsync(context);
fx.Write(SyntheticSequence.Create(new SyntheticSequenceOptions { FrameCount = 12 }), "Roof");
await fx.StartEngineAsync(withArchive: true);
var scan = await fx.EnqueueAsync(ArchiveJobs.Scan(fx.Archive.Archive, full: true, deepAnalysis: true));
await fx.WaitForAsync(scan.Id, JobState.Done);
var deep = (await fx.Db.Jobs.ListAsync(null, JobKind.DeepAnalyse, cancellationToken: fx.Ct)).Items.Single();
Assert.Equal(JobPriority.Background, deep.Priority);
Assert.NotNull(await SingleLightJobAsync(fx));
var done = await fx.WaitForAsync(deep.Id, JobState.Done);
var sequence = (await fx.Db.Sequences.GetAsync(done.TargetIds.Single(), fx.Ct))!;
Assert.Equal("Roof", sequence.Folder);
Assert.True(sequence.Status.HasFlag(SequenceStatus.AnalyzedDeep), "analysed in depth");
// A scan that indexes nothing new asks for nothing; a scan without the option never does.
var again = await fx.EnqueueAsync(ArchiveJobs.Scan(fx.Archive.Archive, full: true, deepAnalysis: true));
await fx.WaitForAsync(again.Id, JobState.Done);
fx.Write(SyntheticSequence.Create(new SyntheticSequenceOptions { FrameCount = 12 }), "Lake");
var plain = await fx.EnqueueAsync(ArchiveJobs.Scan(fx.Archive.Archive));
await fx.WaitForAsync(plain.Id, JobState.Done);
Assert.Count(1, (await fx.Db.Jobs.ListAsync(null, JobKind.DeepAnalyse, cancellationToken: fx.Ct)).Items);
}
[Test]
public async Task ASequenceWaitingForLightAnalysisIsNotQueuedAgain()
{
await using var fx = await ProcessingFixture.CreateAsync(context);
var sequence = await fx.AddAsync(SyntheticSequence.Create(new SyntheticSequenceOptions { FrameCount = 12 }), "Roof");
// Queued before the scan, which runs first (user priority) and finds the sequence not analysed yet.
var waiting = await QueueAsync(fx, Chronos.Data.Processing.ProcessingJobs.LightAnalysis([sequence.Id]));
var scan = await QueueAsync(fx, ArchiveJobs.Scan(fx.Archive.Archive, full: true));
await fx.StartEngineAsync(withArchive: true);
await fx.WaitForAsync(scan.Id, JobState.Done);
await fx.WaitForAsync(waiting.Id, JobState.Done);
Assert.Equal(waiting.Id, (await SingleLightJobAsync(fx))?.Id);
}
/// <summary>Queues a job before the engine starts.</summary>
private static async Task<Job> QueueAsync(ProcessingFixture fx, Chronos.Data.Archiving.Jobs.ArchiveJobRequest request)
{
var job = new Job
{
Id = Guid.CreateVersion7(),
Kind = request.Kind,
TargetIds = request.Targets,
TargetLabel = request.Label,
ParametersJson = request.ParametersJson,
Priority = request.Priority,
State = JobState.Queued,
Created = DateTimeOffset.UtcNow,
};
await fx.Db.Jobs.EnqueueAsync(job, fx.Ct);
return job;
}
private static async Task<Job?> SingleLightJobAsync(ProcessingFixture fx) =>
(await fx.Db.Jobs.ListAsync(null, JobKind.LightAnalyse, cancellationToken: fx.Ct)).Items.SingleOrDefault();
}