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>
219 lines
12 KiB
C#
219 lines
12 KiB
C#
using System.Net;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Chronos.Core.Archiving;
|
|
using Chronos.Core.Model;
|
|
using Chronos.Core.Project;
|
|
using Chronos.Data.Jobs;
|
|
using Chronos.Data.Processing;
|
|
using Chronos.Protocol;
|
|
using Chronos.Protocol.Client;
|
|
using Chronos.Testing;
|
|
|
|
namespace Chronos.Server.Tests.Api;
|
|
|
|
/// <summary>
|
|
/// What a desktop editor of a server sequence asks of the API (BRIEF §14.5 "edit with proxies, render where the
|
|
/// originals are"): the full analysis report, settings edits carrying their version and the hero frame, and the jobs
|
|
/// it posts and reads back.
|
|
/// </summary>
|
|
[Category("server")]
|
|
public sealed class RemoteEditingTests(TestContext context)
|
|
{
|
|
[Test]
|
|
public async Task TheAnalysisReportIsServedOnceTheSequenceWasAnalysed()
|
|
{
|
|
await using var server = await TestServer.StartAsync(context);
|
|
var (editor, _, token) = await server.UserAsync("alberto", "editor");
|
|
using var client = Client(server, token);
|
|
var frame = await Uploads.UploadAsync(editor, Uploads.Photo(2000, 41));
|
|
|
|
Assert.Null(await client.GetAnalysisReportAsync(frame.SequenceId, context.Cancellation), "never deep-analysed");
|
|
|
|
var sequence = (await server.Database.Sequences.GetAsync(frame.SequenceId))!;
|
|
var path = new ArchivePaths(server.Options.ArchivePath).Sequence(sequence.Folder).AnalysisPath;
|
|
Directory.CreateDirectory(Path.GetDirectoryName(path)!);
|
|
var report = Reports.Minimal(1).ToJson();
|
|
await File.WriteAllTextAsync(path, report, context.Cancellation);
|
|
Assert.Equal(report, await client.GetAnalysisReportAsync(frame.SequenceId, context.Cancellation));
|
|
|
|
// One made for other frames is not this sequence's report.
|
|
await File.WriteAllTextAsync(path, Reports.Minimal(2).ToJson(), context.Cancellation);
|
|
Assert.Null(await client.GetAnalysisReportAsync(frame.SequenceId, context.Cancellation), "another frame count");
|
|
|
|
var gone = await Assert.ThrowsAsync<ChronosApiException>(() => client.GetAnalysisReportAsync(Guid.CreateVersion7(), context.Cancellation));
|
|
Assert.Equal(HttpStatusCode.NotFound, gone.Status);
|
|
}
|
|
|
|
[Test]
|
|
public async Task AnEditCarriesItsVersionAndTheHeroFrame()
|
|
{
|
|
await using var server = await TestServer.StartAsync(context);
|
|
var (editor, _, token) = await server.UserAsync("alberto", "editor");
|
|
using var client = Client(server, token);
|
|
var first = await Uploads.UploadAsync(editor, Uploads.Photo(2000, 42), "a.CR3", sessionKey: "harbour");
|
|
var second = await Uploads.UploadAsync(editor, Uploads.Photo(2000, 43), "b.CR3", sessionKey: "harbour");
|
|
var foreign = await Uploads.UploadAsync(editor, Uploads.Photo(2000, 44), "c.CR3", sessionKey: "elsewhere");
|
|
var id = first.SequenceId;
|
|
Assert.Equal(id, second.SequenceId);
|
|
var read = await client.GetSequenceAsync(id, context.Cancellation);
|
|
|
|
var settings = new ProjectSettings { HeroFrame = second.Index }.ToJson();
|
|
var hero = await client.UpdateSequenceAsync(id, new UpdateSequenceRequest(null, null, null, null, settings, read.SettingsVersion, second.FrameId),
|
|
context.Cancellation);
|
|
Assert.Equal(second.FrameId, hero.HeroFrameId);
|
|
Assert.Equal(read.SettingsVersion + 1, hero.SettingsVersion);
|
|
|
|
// An edit made from an older version is refused and changes nothing (the editor merges and sends again).
|
|
var stale = await Assert.ThrowsAsync<ChronosApiException>(() =>
|
|
client.UpdateSequenceAsync(id, new UpdateSequenceRequest(null, null, null, null, settings, read.SettingsVersion, first.FrameId), context.Cancellation));
|
|
Assert.Equal(HttpStatusCode.Conflict, stale.Status);
|
|
Assert.Equal(second.FrameId, (await client.GetSequenceAsync(id, context.Cancellation)).HeroFrameId);
|
|
|
|
var other = await client.UpdateSequenceAsync(id, new UpdateSequenceRequest(null, null, null, null, null, hero.SettingsVersion, foreign.FrameId),
|
|
context.Cancellation);
|
|
Assert.Equal(second.FrameId, other.HeroFrameId, "a frame of another sequence is not its hero");
|
|
var cleared = await client.UpdateSequenceAsync(id, new UpdateSequenceRequest(null, null, null, null, null, other.SettingsVersion, Guid.Empty),
|
|
context.Cancellation);
|
|
Assert.Null(cleared.HeroFrameId);
|
|
}
|
|
|
|
[Test]
|
|
public async Task SettingsAloneMoveTheHeroFrameWithTheProjectsHero()
|
|
{
|
|
await using var server = await TestServer.StartAsync(context);
|
|
var (editor, _, token) = await server.UserAsync("alberto", "editor");
|
|
using var client = Client(server, token);
|
|
await Uploads.UploadAsync(editor, Uploads.Photo(2000, 46), "a.CR3", sessionKey: "pier");
|
|
var second = await Uploads.UploadAsync(editor, Uploads.Photo(2000, 47), "b.CR3", sessionKey: "pier");
|
|
var id = second.SequenceId;
|
|
var read = await client.GetSequenceAsync(id, context.Cancellation);
|
|
|
|
// The sync of a local copy sends the project only.
|
|
var project = new ProjectSettings { HeroFrame = second.Index };
|
|
var hero = await client.UpdateSequenceAsync(id, new UpdateSequenceRequest(null, null, null, null, project.ToJson(), read.SettingsVersion),
|
|
context.Cancellation);
|
|
Assert.Equal(second.FrameId, hero.HeroFrameId);
|
|
|
|
var exposure = project with { Exposure = project.Exposure with { ExposureOffsetEv = 0.3 } };
|
|
var kept = await client.UpdateSequenceAsync(id, new UpdateSequenceRequest(null, null, null, null, exposure.ToJson(), hero.SettingsVersion),
|
|
context.Cancellation);
|
|
Assert.Equal(second.FrameId, kept.HeroFrameId, "other changes keep the hero");
|
|
|
|
var cleared = await client.UpdateSequenceAsync(id, new UpdateSequenceRequest(null, null, null, null, (exposure with { HeroFrame = null }).ToJson(),
|
|
kept.SettingsVersion), context.Cancellation);
|
|
Assert.Null(cleared.HeroFrameId, "no hero shows the first frame");
|
|
}
|
|
|
|
[Test]
|
|
public async Task JobsPostedOnePerPresetReadBackAsTheClientsJobs()
|
|
{
|
|
var handler = new BlockingJobHandler(JobKind.DeepAnalyse);
|
|
await using var server = await TestServer.StartAsync(context, services: s => s.AddSingleton<IJobHandler>(handler));
|
|
var (editor, _, token) = await server.UserAsync("alberto", "editor");
|
|
using var client = Client(server, token);
|
|
var frame = await Uploads.UploadAsync(editor, Uploads.Photo(2000, 45));
|
|
var dto = await client.GetSequenceAsync(frame.SequenceId, context.Cancellation);
|
|
var sequence = new Sequence { Id = dto.Id, ArchiveId = Guid.Empty, Folder = dto.Folder, Title = dto.Title };
|
|
|
|
var export = new ExportSettings { Preset = new Auto<string>().WithManual("4k-hevc"), Batch = ["1440p-h264"] };
|
|
var posted = new List<Job>();
|
|
foreach (var request in ProcessingJobs.RenderEach(sequence, export, 3840, 2160, new ProjectSettings { Export = export }))
|
|
{
|
|
var job = await client.CreateJobAsync(new CreateJobRequest(JobWire.Kind(request.Kind), request.Targets, request.ParametersJson), context.Cancellation);
|
|
posted.Add(Assert.NotNull(JobWire.FromDto(job)));
|
|
}
|
|
Assert.Count(2, posted);
|
|
Assert.True(posted.All(j => j is { Kind: JobKind.Render, State: JobState.Queued } && j.TargetIds.SequenceEqual([sequence.Id])));
|
|
|
|
var analysis = Assert.NotNull(JobWire.FromDto(await client.CreateJobAsync(
|
|
new CreateJobRequest(JobWire.Kind(JobKind.DeepAnalyse), [sequence.Id], null), context.Cancellation)));
|
|
Assert.Equal(JobKind.DeepAnalyse, analysis.Kind);
|
|
await handler.Started.Task.WaitAsync(TimeSpan.FromSeconds(10));
|
|
handler.Release();
|
|
for (var i = 0; i < 200 && JobWire.FromDto(await client.GetJobAsync(analysis.Id, context.Cancellation))!.State != JobState.Done; i++)
|
|
await Task.Delay(50);
|
|
var done = Assert.NotNull(JobWire.FromDto(await client.GetJobAsync(analysis.Id, context.Cancellation)));
|
|
Assert.Equal(JobState.Done, done.State);
|
|
Assert.Equal((4L, 4L), (done.ProgressDone, done.ProgressTotal));
|
|
Assert.NotNull(done.Finished);
|
|
|
|
var queued = (await client.ListJobsAsync("queued", null, context.Cancellation)).Items.Select(JobWire.FromDto).OfType<Job>().ToList();
|
|
Assert.SequenceEqual(posted.Select(j => j.Id).Order(), queued.Where(j => j.Kind == JobKind.Render).Select(j => j.Id).Order());
|
|
}
|
|
|
|
[Test]
|
|
public async Task TheJobListFiltersByKindAndGoesOnPastThePage()
|
|
{
|
|
await using var server = await TestServer.StartAsync(context);
|
|
var (_, _, token) = await server.UserAsync("alberto", "editor");
|
|
using var client = Client(server, token);
|
|
var target = Guid.CreateVersion7();
|
|
var created = DateTimeOffset.UtcNow;
|
|
// Paused, so no worker claims them: a render of the editor's sequence behind a busy server's thumbnails.
|
|
Job Paused(JobKind kind, int age) => new()
|
|
{
|
|
Id = Guid.CreateVersion7(),
|
|
Kind = kind,
|
|
TargetIds = [target],
|
|
State = JobState.Paused,
|
|
Created = created.AddSeconds(-age),
|
|
};
|
|
var render = Paused(JobKind.Render, 300);
|
|
await server.Database.Jobs.EnqueueAsync(render);
|
|
for (var i = 0; i < 205; i++) await server.Database.Jobs.EnqueueAsync(Paused(JobKind.Thumbs, i));
|
|
|
|
var renders = await client.ListJobsAsync("paused", "render", null, context.Cancellation);
|
|
Assert.SequenceEqual([render.Id], renders.Items.Select(j => j.Id));
|
|
Assert.Null(renders.NextCursor);
|
|
|
|
var first = await client.ListJobsAsync("paused", null, null, context.Cancellation);
|
|
Assert.NotNull(first.NextCursor, "more than a page");
|
|
Assert.False(first.Items.Any(j => j.Id == render.Id), "the oldest job is past the first page");
|
|
var rest = await client.ListJobsAsync("paused", null, first.NextCursor, context.Cancellation);
|
|
Assert.Null(rest.NextCursor);
|
|
Assert.Equal(206, first.Items.Concat(rest.Items).Select(j => j.Id).Distinct().Count());
|
|
}
|
|
|
|
[Test]
|
|
public async Task AnEditorHearsFramesAddedAndSettingsChangedOverItsEventSocket()
|
|
{
|
|
await using var server = await TestServer.StartAsync(context);
|
|
var (editor, _, token) = await server.UserAsync("alberto", "editor");
|
|
using var client = Client(server, token);
|
|
var first = await Uploads.UploadAsync(editor, Uploads.Photo(2000, 48), "a.CR3", sessionKey: "quay");
|
|
var id = first.SequenceId;
|
|
var opened = await client.GetManifestAsync(id, context.Cancellation);
|
|
|
|
using var listening = CancellationTokenSource.CreateLinkedTokenSource(context.Cancellation);
|
|
listening.CancelAfter(TimeSpan.FromSeconds(20));
|
|
var received = new List<SequenceChangedEvent>();
|
|
var reader = Task.Run(async () =>
|
|
{
|
|
await foreach (var e in client.EventsAsync(listening.Token))
|
|
{
|
|
if (e is not SequenceChangedEvent changed || changed.SequenceId != id) continue;
|
|
received.Add(changed);
|
|
if (changed.Change == "settings") return;
|
|
}
|
|
});
|
|
var hub = server.Services.GetRequiredService<Chronos.Server.Events.EventHub>();
|
|
for (var i = 0; i < 200 && hub.SubscriberCount == 0; i++) await Task.Delay(25);
|
|
|
|
// Someone uploads another frame, then someone edits the project: the editor checks its frames, then its settings.
|
|
await Uploads.UploadAsync(editor, Uploads.Photo(2000, 49), "b.CR3", sessionKey: "quay");
|
|
var read = await client.GetSequenceAsync(id, context.Cancellation);
|
|
await client.UpdateSequenceAsync(id, new UpdateSequenceRequest(null, null, null, null, new ProjectSettings { HeroFrame = 1 }.ToJson(), read.SettingsVersion),
|
|
context.Cancellation);
|
|
await reader.WaitAsync(TimeSpan.FromSeconds(20));
|
|
|
|
var now = await client.GetManifestAsync(id, context.Cancellation);
|
|
var frames = Assert.Contains(received, e => e.Change == "frames");
|
|
Assert.Equal(now.FramesVersion, frames.FramesVersion);
|
|
Assert.True(frames.FramesVersion > opened.FramesVersion, "a frames version the editor has not seen");
|
|
Assert.Count(2, now.Frames);
|
|
Assert.Equal(("settings", now.SettingsVersion), (received[^1].Change, received[^1].SettingsVersion));
|
|
}
|
|
|
|
private static ChronosClient Client(TestServer server, string token) => new(server.HttpBase, new CertificatePinning([]), "tests") { Token = token };
|
|
}
|