CI / Build and test (push) Successful in 8m14s
CI / Windows tests and installer (push) Skipped
CI / YAML check (push) Successful in 7s
Release / Build, test and publish (push) Successful in 13m19s
CI / PostgreSQL 16 integration (push) Successful in 4m49s
CI / PostgreSQL 17 integration (push) Successful in 5m28s
CI / Docker image (push) Successful in 53s
Release / Server image (push) Failing after 10s
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 and the system SQLite. 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; the throw-away server runs without durability) and pe-check. - Timed tests take their budget from TestTiming (CHRONOS_TEST_TIME_FACTOR, 3 on the shared runner; the weekly performance gates keep theirs). 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> Co-authored-by: Alberto Balbo <alberto.balbo.96@gmail.com>
351 lines
19 KiB
C#
351 lines
19 KiB
C#
using System.IO;
|
|
using Chronos.App.Editor;
|
|
using Chronos.Core.Archiving;
|
|
using Chronos.Core.Codecs.Jpeg;
|
|
using Chronos.Core.Imaging;
|
|
using Chronos.Core.Imaging.Decoders;
|
|
using Chronos.Core.Localization;
|
|
using Chronos.Core.Metadata;
|
|
using Chronos.Core.Model;
|
|
using Chronos.Core.Project;
|
|
using Chronos.Data;
|
|
using Chronos.Data.Archiving;
|
|
using Chronos.Data.Jobs;
|
|
using Chronos.Data.Processing;
|
|
using Chronos.Data.Repositories;
|
|
using Chronos.Testing;
|
|
|
|
namespace Chronos.App.Tests.Editor;
|
|
|
|
/// <summary>Project merges, and the local source over a real SQLite index and archive folder.</summary>
|
|
public sealed class ProjectStoreTests(TestContext context)
|
|
{
|
|
[Test]
|
|
public void AMemberOnlyTheyChangedIsKept()
|
|
{
|
|
var basis = new ProjectSettings();
|
|
var ours = basis with { Exposure = basis.Exposure with { ExposureOffsetEv = 0.5 } };
|
|
var theirs = basis with { HeroFrame = 12 };
|
|
var merged = ProjectMerge.Merge(basis, ours, theirs);
|
|
Assert.Equal(0.5, merged.Exposure.ExposureOffsetEv);
|
|
Assert.Equal(12, merged.HeroFrame);
|
|
}
|
|
|
|
[Test]
|
|
public void AdviceMergesIntoAManualValueOfTheSameSetting()
|
|
{
|
|
var basis = new ProjectSettings();
|
|
var ours = basis with { Exposure = basis.Exposure with { Deflicker = basis.Exposure.Deflicker.WithManual(true) } };
|
|
var theirs = basis with { Exposure = basis.Exposure with { Deflicker = basis.Exposure.Deflicker.WithAdvice(false, "Advisor.Reason.Deflicker.Off") } };
|
|
var merged = ProjectMerge.Merge(basis, ours, theirs).Exposure.Deflicker;
|
|
Assert.False(merged.IsAuto, "the user's manual choice stays");
|
|
Assert.True(merged.Manual);
|
|
Assert.True(merged.HasAdvice, "the new advice is stored next to it");
|
|
Assert.Equal("Advisor.Reason.Deflicker.Off", merged.ReasonKey);
|
|
}
|
|
|
|
[Test]
|
|
public void WhenBothChangedAValueTheEditorWins()
|
|
{
|
|
var basis = new ProjectSettings();
|
|
var merged = ProjectMerge.Merge(basis, basis with { HeroFrame = 3 }, basis with { HeroFrame = 9 });
|
|
Assert.Equal(3, merged.HeroFrame);
|
|
}
|
|
|
|
[Test]
|
|
public async Task TheLocalSourceReadsDecodesSavesAndQueues()
|
|
{
|
|
var (db, sequenceId, root) = await ArchiveAsync(12);
|
|
await using (db)
|
|
{
|
|
var options = new ArchiveServiceOptions { Owner = "test", LeaseWait = TimeSpan.FromSeconds(20) };
|
|
await using var source = new LocalSequenceSource(db, sequenceId, DecoderFactory.CreateClient(null), null, options);
|
|
var content = await source.LoadAsync(context.Cancellation);
|
|
Assert.Equal(12, content.Count);
|
|
Assert.Equal(96, content.SourceWidth);
|
|
Assert.Equal(64, content.SourceHeight);
|
|
Assert.Null(content.Deep, "not analysed yet");
|
|
Assert.NotNull(content.ExportsFolder);
|
|
Assert.Contains("exports", content.ExportsFolder!);
|
|
|
|
using (var frame = await source.DecodeAsync(3, 32, DecodePurpose.Thumbnail, context.Cancellation))
|
|
{
|
|
Assert.NotNull(frame);
|
|
Assert.LessOrEqual(Math.Max(frame!.Width, frame.Height), 32);
|
|
}
|
|
Assert.Null(await source.DecodeAsync(99, 32, DecodePurpose.Thumbnail, context.Cancellation));
|
|
|
|
// A save writes project.json and the index row together.
|
|
var edited = content.Project with { HeroFrame = 4, Exposure = content.Project.Exposure with { ExposureOffsetEv = 0.3 } };
|
|
var stored = await source.SaveProjectAsync(edited, content.Project, context.Cancellation);
|
|
Assert.True(ProjectMerge.SameValues(edited, stored));
|
|
var projectPath = Path.Combine(root, "Synthetic", ".chronos", "project.json");
|
|
Assert.FileExists(projectPath);
|
|
Assert.Equal(edited.ToJson(), File.ReadAllText(projectPath));
|
|
var row = await db.Sequences.GetAsync(sequenceId);
|
|
Assert.Equal(edited.ToJson(), row!.SettingsJson);
|
|
|
|
// Someone else changes the settings meanwhile (the server API): both edits survive the next save.
|
|
var theirs = stored with { Camera = stored.Camera with { OffsetY = 0.25 } };
|
|
await db.Sequences.EditAsync(sequenceId, new SequenceEdit { SettingsJson = theirs.ToJson() }, row.SettingsVersion);
|
|
var mine = stored with { HeroFrame = 7 };
|
|
var merged = await source.SaveProjectAsync(mine, stored, context.Cancellation);
|
|
Assert.Equal(7, merged.HeroFrame);
|
|
Assert.Equal(0.25, merged.Camera.OffsetY);
|
|
Assert.Equal(merged.ToJson(), File.ReadAllText(projectPath));
|
|
Assert.Equal(merged.ToJson(), (await db.Sequences.GetAsync(sequenceId))!.SettingsJson);
|
|
|
|
var reloaded = await source.LoadAsync(context.Cancellation);
|
|
Assert.True(ProjectMerge.SameValues(merged, reloaded.Project), "the index copy is read back");
|
|
|
|
await Assert.ThrowsAsync<InvalidOperationException>(() => source.SubmitAsync(ProcessingJobs.DeepAnalysis([sequenceId]), context.Cancellation));
|
|
}
|
|
}
|
|
|
|
[Test]
|
|
public async Task SetHeroReachesTheLibraryThumbnail()
|
|
{
|
|
var (db, sequenceId, root) = await ArchiveAsync(6);
|
|
await using (db)
|
|
{
|
|
await using var source = new LocalSequenceSource(db, sequenceId, DecoderFactory.CreateClient(null), null,
|
|
new ArchiveServiceOptions { Owner = "test", LeaseWait = TimeSpan.FromSeconds(20) });
|
|
var changed = new List<Sequence>();
|
|
source.HeroChanged += changed.Add;
|
|
var content = await source.LoadAsync(context.Cancellation);
|
|
var session = new EditorSession(source, content, [], TimeSpan.FromMilliseconds(20));
|
|
await using (session)
|
|
{
|
|
Assert.True(session.SetHero(4));
|
|
Assert.True(await session.FlushAsync());
|
|
Assert.Equal(content.Frames[4].Id, (await db.Sequences.GetAsync(sequenceId))!.HeroFrameId, "the index names the hero frame");
|
|
Assert.Equal(content.Frames[4].Id, Assert.Contains(changed, _ => true).HeroFrameId, "the Library is told");
|
|
|
|
session.Edit(p => p with { Exposure = p.Exposure with { ExposureOffsetEv = 0.2 } });
|
|
Assert.True(await session.FlushAsync());
|
|
Assert.Count(1, changed);
|
|
|
|
Assert.True(session.Undo());
|
|
Assert.True(session.Undo());
|
|
Assert.True(await session.FlushAsync());
|
|
Assert.Null((await db.Sequences.GetAsync(sequenceId))!.HeroFrameId, "undoing Set hero brings back the first frame");
|
|
Assert.Count(2, changed);
|
|
}
|
|
|
|
// "Save both" copies kept by a sync conflict are listed with the sequence.
|
|
File.WriteAllText(Path.Combine(root, "Synthetic", ".chronos", "project.this-pc-20261003-142200.json"), new ProjectSettings().ToJson());
|
|
Assert.Equal(new DateTime(2026, 10, 3, 14, 22, 0), Assert.Contains((await source.LoadAsync(context.Cancellation)).SavedCopies, _ => true).SavedAt);
|
|
}
|
|
}
|
|
|
|
[Test]
|
|
public async Task AnEditorOpenWhileEarlierPhotosArriveSavesOnTheFramesTheUserChose()
|
|
{
|
|
var (db, sequenceId, root) = await ArchiveAsync(10);
|
|
await using (db)
|
|
{
|
|
var options = new ArchiveServiceOptions { Owner = "test", LeaseWait = TimeSpan.FromSeconds(20) };
|
|
await using var source = new LocalSequenceSource(db, sequenceId, DecoderFactory.CreateClient(null), null, options);
|
|
var content = await source.LoadAsync(context.Cancellation);
|
|
var session = new EditorSession(source, content, [], TimeSpan.FromMilliseconds(20));
|
|
await using (session)
|
|
{
|
|
Assert.True(session.SetExcluded([5], true));
|
|
Assert.True(session.SetHero(6));
|
|
Assert.True(await session.FlushAsync());
|
|
|
|
// Three photos taken before the others are found in the folder (a sync download, an import or a scan
|
|
// inserts them the same way): the index moves the stored positions with their frames.
|
|
await InsertEarlierAsync(db, root, content, options, 3);
|
|
var moved = ProjectSettings.FromJson((await db.Sequences.GetAsync(sequenceId))!.SettingsJson!);
|
|
Assert.SequenceEqual([8], moved.ExcludedFrames);
|
|
Assert.Equal(9, moved.HeroFrame);
|
|
|
|
// The editor still shows the ten frames it read; the user excludes the eighth of them.
|
|
Assert.Equal(10, session.Content.Count);
|
|
Assert.True(session.SetExcluded([7], true));
|
|
Assert.True(await session.FlushAsync());
|
|
|
|
Assert.Equal(13, session.Content.Count, "the frames were read again before the save");
|
|
Assert.SequenceEqual([8, 10], session.Project.ExcludedFrames);
|
|
Assert.Equal(9, session.Project.HeroFrame);
|
|
var row = (await db.Sequences.GetAsync(sequenceId))!;
|
|
var stored = ProjectSettings.FromJson(row.SettingsJson!);
|
|
var frames = session.Content.Frames;
|
|
Assert.SequenceEqual([content.Frames[5].Id, content.Frames[7].Id], stored.ExcludedFrames.Select(i => frames[i].Id), "the photos the user chose");
|
|
Assert.Equal(content.Frames[6].Id, frames[stored.HeroFrame!.Value].Id);
|
|
Assert.Equal(content.Frames[6].Id, row.HeroFrameId);
|
|
Assert.Equal(row.SettingsJson, File.ReadAllText(Path.Combine(root, "Synthetic", ".chronos", "project.json")));
|
|
|
|
// Undo takes back the user's last step on the new frames too.
|
|
Assert.True(session.Undo());
|
|
Assert.True(await session.FlushAsync());
|
|
Assert.SequenceEqual([8], ProjectSettings.FromJson((await db.Sequences.GetAsync(sequenceId))!.SettingsJson!).ExcludedFrames);
|
|
}
|
|
}
|
|
}
|
|
|
|
[Test]
|
|
public async Task ARenderAfterEarlierPhotosArriveEmbedsTheFramesTheUserChose()
|
|
{
|
|
var (db, sequenceId, root) = await ArchiveAsync(10);
|
|
await using (db)
|
|
{
|
|
var options = new ArchiveServiceOptions { Owner = "test", LeaseWait = TimeSpan.FromSeconds(20) };
|
|
await using var source = new LocalSequenceSource(db, sequenceId, DecoderFactory.CreateClient(null), null, options);
|
|
var content = await source.LoadAsync(context.Cancellation);
|
|
var session = new EditorSession(source, content, [], TimeSpan.FromMilliseconds(20));
|
|
await using (session)
|
|
{
|
|
Assert.True(session.SetExcluded([5], true));
|
|
Assert.True(await session.FlushAsync());
|
|
Assert.True(await source.FramesCurrentAsync(context.Cancellation));
|
|
|
|
// Earlier photos arrive while the editor is open; the user renders without another edit.
|
|
await InsertEarlierAsync(db, root, content, options, 3);
|
|
Assert.False(await source.FramesCurrentAsync(context.Cancellation));
|
|
await session.EnsureFramesAsync(context.Cancellation);
|
|
var request = session.RenderRequests(session.Project.Export)[0];
|
|
|
|
Assert.True(await source.FramesCurrentAsync(context.Cancellation));
|
|
Assert.Equal(13, session.Content.Count);
|
|
var embedded = ProjectSettings.FromJson(ProcessingJobs.ReadRender(request.ParametersJson).Parameters.SettingsJson!);
|
|
Assert.SequenceEqual([content.Frames[5].Id], embedded.ExcludedFrames.Select(i => session.Content.Frames[i].Id), "the photo the user excluded");
|
|
}
|
|
}
|
|
}
|
|
|
|
[Test]
|
|
public async Task ASaveThatDoesNotReachTheIndexThrows()
|
|
{
|
|
var (db, sequenceId, _) = await ArchiveAsync(4);
|
|
await using (db)
|
|
{
|
|
await using var source = new LocalSequenceSource(db, sequenceId, DecoderFactory.CreateClient(null), null,
|
|
new ArchiveServiceOptions { Owner = "test", LeaseWait = TimeSpan.FromSeconds(20) });
|
|
var content = await source.LoadAsync(context.Cancellation);
|
|
Assert.True(await db.Sequences.DeleteAsync(sequenceId));
|
|
var gone = await Assert.ThrowsAsync<EditorException>(() => source.SaveProjectAsync(content.Project with { HeroFrame = 1 }, content.Project, context.Cancellation));
|
|
Assert.Equal(Loc.L("Editor.Error.Missing"), gone.Message, "the toast shows the editor's own sentence");
|
|
}
|
|
}
|
|
|
|
[Test]
|
|
public async Task JobsGoToTheEngine()
|
|
{
|
|
var (db, sequenceId, _) = await ArchiveAsync(4);
|
|
await using (db)
|
|
{
|
|
await using var engine = new JobEngine(db, [], new JobEngineOptions { WorkerId = "test" });
|
|
await using var source = new LocalSequenceSource(db, sequenceId, DecoderFactory.CreateClient(null), engine);
|
|
var content = await source.LoadAsync(context.Cancellation);
|
|
var session = new EditorSession(source, content, []);
|
|
var id = await session.SubmitAsync(session.AnalysisRequest(), context.Cancellation);
|
|
var job = await db.Jobs.GetAsync(id);
|
|
Assert.Equal(JobKind.DeepAnalyse, job!.Kind);
|
|
Assert.Equal(JobState.Queued, job.State);
|
|
Assert.SequenceEqual([sequenceId], job.TargetIds);
|
|
}
|
|
}
|
|
|
|
[Test]
|
|
public async Task AnUnreadableProjectIsReportedNotReplaced()
|
|
{
|
|
var (db, sequenceId, root) = await ArchiveAsync(4);
|
|
await using (db)
|
|
{
|
|
var path = Path.Combine(root, "Synthetic", ".chronos", "project.json");
|
|
File.WriteAllText(path, "{ not json");
|
|
await using var source = new LocalSequenceSource(db, sequenceId, DecoderFactory.CreateClient(null), null);
|
|
var unreadable = await Assert.ThrowsAsync<EditorException>(() => source.LoadAsync(context.Cancellation));
|
|
Assert.Equal(Loc.L("Editor.Error.Project"), unreadable.Message);
|
|
Assert.Equal("{ not json", File.ReadAllText(path));
|
|
|
|
// A project written by a newer Chronos reads the same, not as the parser's English sentence.
|
|
var newer = $"{{\"version\":{ProjectSettings.CurrentVersion + 1}}}";
|
|
File.WriteAllText(path, newer);
|
|
Assert.Equal(Loc.L("Editor.Error.Project"), (await Assert.ThrowsAsync<EditorException>(() => source.LoadAsync(context.Cancellation))).Message);
|
|
Assert.Equal(newer, File.ReadAllText(path));
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Writes <paramref name="count"/> photos taken before the sequence's first frame into its folder and scans the
|
|
/// archive: they are inserted in front, and the index moves the stored positions with their frames.
|
|
/// </summary>
|
|
private async Task InsertEarlierAsync(ChronosDatabase db, string root, SequenceContent content, ArchiveServiceOptions options, int count)
|
|
{
|
|
var sequence = EditorFixture.Sequence(count);
|
|
var first = content.Frames[0].CapturedAt!.Value;
|
|
for (var i = 0; i < count; i++)
|
|
{
|
|
using var image = sequence.Render(i);
|
|
var exif = ExifWriter.BuildJpegApp1(sequence.Metadata[i] with { CapturedAt = first.AddMinutes(i - count) });
|
|
File.WriteAllBytes(Path.Combine(root, "Synthetic", $"EARLY_{i + 1}.JPG"),
|
|
JpegEncoder.Encode(image, new JpegEncodeOptions { Quality = 90, App1Segments = [exif[4..]] }));
|
|
}
|
|
var archive = (await db.Archives.GetAsync(content.Sequence.ArchiveId, context.Cancellation))!;
|
|
await new ArchiveService(db, options).Indexer.ScanAsync(archive, ScanMode.Full, null, _ => ValueTask.CompletedTask, context.Cancellation);
|
|
}
|
|
|
|
/// <summary>A temporary archive with one adopted folder of synthetic JPEGs, indexed.</summary>
|
|
/// <summary>
|
|
/// A decode superseded by a newer edit (R4, owner review 1): the caller sees a cancellation, never an unreadable frame,
|
|
/// and the provider's cancellation stays inside the source's own task.
|
|
/// </summary>
|
|
[Test]
|
|
public async Task ACancelledDecodeIsACancellationNotAnUnreadableFrame()
|
|
{
|
|
var (db, sequenceId, _) = await ArchiveAsync(4);
|
|
await using (db)
|
|
{
|
|
var entered = new TaskCompletionSource();
|
|
var blocking = new ImageDecoder([new BlockingProvider(entered)]);
|
|
var options = new ArchiveServiceOptions { Owner = "test", LeaseWait = TimeSpan.FromSeconds(20) };
|
|
await using var source = new LocalSequenceSource(db, sequenceId, blocking, null, options);
|
|
await source.LoadAsync(context.Cancellation);
|
|
using var cts = new CancellationTokenSource();
|
|
var decode = source.DecodeAsync(1, 64, DecodePurpose.Proxy, cts.Token).AsTask();
|
|
await entered.Task.WaitAsync(TimeSpan.FromSeconds(10));
|
|
await cts.CancelAsync();
|
|
await Assert.ThrowsAsync<OperationCanceledException>(() => decode);
|
|
}
|
|
}
|
|
|
|
/// <summary>Decodes nothing until its token is cancelled, then throws the cancellation, as WIC does between bands.</summary>
|
|
private sealed class BlockingProvider(TaskCompletionSource entered) : IImageDecoderProvider
|
|
{
|
|
public string Name => "blocking";
|
|
public DecodeTier? TierFor(ImageFileFormat format) => DecodeTier.Native;
|
|
|
|
public DecodedImage? Decode(DecodeRequest request, CancellationToken cancellationToken = default)
|
|
{
|
|
entered.TrySetResult();
|
|
cancellationToken.WaitHandle.WaitOne(TimeSpan.FromSeconds(10));
|
|
cancellationToken.ThrowIfCancellationRequested();
|
|
return null;
|
|
}
|
|
}
|
|
|
|
private async Task<(ChronosDatabase Db, Guid SequenceId, string Root)> ArchiveAsync(int frames)
|
|
{
|
|
var directory = context.CreateTempDirectory("editor");
|
|
var root = Path.Combine(directory, "archive");
|
|
var db = await ChronosDatabase.OpenAsync(DatabaseOptions.Sqlite(Path.Combine(directory, "index.db")));
|
|
var service = new ArchiveService(db, new ArchiveServiceOptions { Owner = "test", LeaseWait = TimeSpan.FromSeconds(20) });
|
|
var archive = await service.CreateAsync(root, "Test");
|
|
var sequence = EditorFixture.Sequence(frames);
|
|
var folder = Path.Combine(root, "Synthetic");
|
|
Directory.CreateDirectory(folder);
|
|
for (var i = 0; i < sequence.Count; i++)
|
|
{
|
|
using var image = sequence.Render(i);
|
|
var exif = ExifWriter.BuildJpegApp1(sequence.Metadata[i]);
|
|
File.WriteAllBytes(Path.Combine(folder, $"IMG_{i + 1:0000}.JPG"), JpegEncoder.Encode(image, new JpegEncodeOptions { Quality = 90, App1Segments = [exif[4..]] }));
|
|
}
|
|
await service.Indexer.ScanAsync(archive, ScanMode.Full, null, _ => ValueTask.CompletedTask, context.Cancellation);
|
|
var location = (await db.Sequences.ListLocationsAsync(archive.Id, context.Cancellation)).Single();
|
|
return (db, location.Id, root);
|
|
}
|
|
}
|