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
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>
206 lines
8.7 KiB
C#
206 lines
8.7 KiB
C#
using System.Collections.Concurrent;
|
|
using System.IO;
|
|
using System.Net;
|
|
using System.Runtime.CompilerServices;
|
|
using System.Threading.Channels;
|
|
using Chronos.App.Editor;
|
|
using Chronos.Core.Model;
|
|
using Chronos.Protocol;
|
|
using Chronos.Protocol.Client;
|
|
|
|
namespace Chronos.App.Tests.Editor;
|
|
|
|
/// <summary>
|
|
/// One server sequence as the API serves it to an editor: its frames, settings with a version that refuses stale edits
|
|
/// (409), recorded edits and posted jobs (with their priority, cancel and retry), jobs other clients run, an analysis
|
|
/// report and an event stream the test feeds.
|
|
/// </summary>
|
|
internal sealed class FakeRemoteSequenceApi(Sequence sequence, IReadOnlyList<Guid> frames) : IRemoteSequenceApi
|
|
{
|
|
private readonly Lock _gate = new();
|
|
private readonly TaskCompletionSource _subscribed = new(TaskCreationOptions.RunContinuationsAsynchronously);
|
|
private Channel<ServerEvent> _events = Channel.CreateUnbounded<ServerEvent>();
|
|
|
|
/// <summary>The server's frames in order (another list when frames are added or removed on the server).</summary>
|
|
public IReadOnlyList<Guid> Frames { get; set; } = frames;
|
|
|
|
public int FramesVersion { get; set; } = 1;
|
|
|
|
public string? SettingsJson { get; set; }
|
|
|
|
public int SettingsVersion { get; set; } = 3;
|
|
|
|
public string? Report { get; set; }
|
|
|
|
public bool Gone { get; set; }
|
|
|
|
/// <summary>Every edit the server accepted or refused, in order.</summary>
|
|
public List<(UpdateSequenceRequest Request, bool Accepted)> Edits { get; } = [];
|
|
|
|
public List<CreateJobRequest> Posted { get; } = [];
|
|
|
|
/// <summary>Priorities set after jobs were posted (job, wire name).</summary>
|
|
public List<(Guid Job, string Priority)> Priorities { get; } = [];
|
|
|
|
/// <summary>The server's jobs; tests change them while the source's event loop reads them.</summary>
|
|
public ConcurrentDictionary<Guid, JobDto> Jobs { get; } = new();
|
|
|
|
/// <summary>Thrown by the next read of a job (a failure the editor's event listener does not expect).</summary>
|
|
public Exception? FailNextJobRead { get; set; }
|
|
|
|
/// <summary>Thrown by the next edit before it reaches the server (the connection dropped).</summary>
|
|
public Exception? FailNextEdit { get; set; }
|
|
|
|
/// <summary>Someone else edits the settings before each of the next edits reaches the server (it is refused with 409).</summary>
|
|
public Queue<Func<string?, string>> EditsBefore { get; } = new();
|
|
|
|
public bool Disposed { get; private set; }
|
|
|
|
/// <summary>Completes once the editor's listener has opened an event stream (the stream open then is the one it reads).</summary>
|
|
public Task Subscribed => _subscribed.Task;
|
|
|
|
/// <summary>A job of the server, as <c>GET /jobs/{id}</c> returns it.</summary>
|
|
public JobDto Job(Guid id, string kind, string state, Guid? target = null, long done = 0, long total = 0) =>
|
|
new(id, kind, [target ?? sequence.Id], sequence.DisplayTitle, state, "user", done, total, null, null, null, null, 0, null, DateTimeOffset.UtcNow,
|
|
state == "queued" ? null : DateTimeOffset.UtcNow, state is "done" or "failed" ? DateTimeOffset.UtcNow : null);
|
|
|
|
public void Publish(ServerEvent e) => Volatile.Read(ref _events).Writer.TryWrite(e);
|
|
|
|
/// <summary>The event socket drops: the stream open now fails, and the next one starts empty.</summary>
|
|
public void DropEvents() => Interlocked.Exchange(ref _events, Channel.CreateUnbounded<ServerEvent>()).Writer.TryComplete(new IOException("connection lost"));
|
|
|
|
public Task<SequenceDto> GetSequenceAsync(Guid id, CancellationToken cancellationToken)
|
|
{
|
|
lock (_gate) return Task.FromResult(Dto(id));
|
|
}
|
|
|
|
public Task<SequenceManifest> GetManifestAsync(Guid id, CancellationToken cancellationToken)
|
|
{
|
|
lock (_gate)
|
|
{
|
|
Check(id);
|
|
return Task.FromResult(new SequenceManifest(id, FramesVersion, SettingsVersion, SettingsJson, [],
|
|
[.. Frames.Select((frame, i) => new ManifestFrame(frame, i, $"IMG_{i:0000}.JPG", 1_000, "00", true, true))], [
|
|
new RenderDto(Guid.CreateVersion7(), "4K archive", "hevc", 3840, 2160, 24, 5, 2_000_000_000, DateTimeOffset.UtcNow.AddDays(-1), "studio-pc"),
|
|
]));
|
|
}
|
|
}
|
|
|
|
public Task<SequenceDto> UpdateSequenceAsync(Guid id, UpdateSequenceRequest request, CancellationToken cancellationToken)
|
|
{
|
|
lock (_gate)
|
|
{
|
|
Check(id);
|
|
if (FailNextEdit is { } failure)
|
|
{
|
|
FailNextEdit = null;
|
|
throw failure;
|
|
}
|
|
if (EditsBefore.TryDequeue(out var theirs))
|
|
{
|
|
SettingsJson = theirs(SettingsJson);
|
|
SettingsVersion++;
|
|
}
|
|
if (request.ExpectedSettingsVersion is { } expected && expected != SettingsVersion)
|
|
{
|
|
Edits.Add((request, false));
|
|
throw new ChronosApiException(HttpStatusCode.Conflict, new ApiError("settings_conflict", "changed", SettingsVersion.ToString()));
|
|
}
|
|
if (request.ExpectedFramesVersion is { } frames && frames != FramesVersion)
|
|
{
|
|
Edits.Add((request, false));
|
|
throw new ChronosApiException(HttpStatusCode.Conflict, new ApiError("frames_conflict", "frames changed", FramesVersion.ToString()));
|
|
}
|
|
Edits.Add((request, true));
|
|
SettingsJson = request.SettingsJson ?? SettingsJson;
|
|
SettingsVersion++;
|
|
return Task.FromResult(Dto(id));
|
|
}
|
|
}
|
|
|
|
public Task<string?> GetAnalysisReportAsync(Guid id, CancellationToken cancellationToken)
|
|
{
|
|
lock (_gate)
|
|
{
|
|
Check(id);
|
|
return Task.FromResult(Report);
|
|
}
|
|
}
|
|
|
|
public Task<JobDto> CreateJobAsync(CreateJobRequest request, CancellationToken cancellationToken)
|
|
{
|
|
lock (_gate)
|
|
{
|
|
Posted.Add(request);
|
|
var job = Job(Guid.CreateVersion7(), request.Kind, "queued", request.Target[0]);
|
|
Jobs[job.Id] = job;
|
|
return Task.FromResult(job);
|
|
}
|
|
}
|
|
|
|
public Task<JobDto> GetJobAsync(Guid id, CancellationToken cancellationToken)
|
|
{
|
|
lock (_gate)
|
|
{
|
|
if (FailNextJobRead is { } failure)
|
|
{
|
|
FailNextJobRead = null;
|
|
throw failure;
|
|
}
|
|
return Jobs.TryGetValue(id, out var job)
|
|
? Task.FromResult(job)
|
|
: throw new ChronosApiException(HttpStatusCode.NotFound, new ApiError("not_found", "job", "job"));
|
|
}
|
|
}
|
|
|
|
public Task<IReadOnlyList<JobDto>> ListActiveJobsAsync(CancellationToken cancellationToken)
|
|
{
|
|
lock (_gate) return Task.FromResult<IReadOnlyList<JobDto>>([.. Jobs.Values.Where(j => j.State is "queued" or "running" or "paused")]);
|
|
}
|
|
|
|
public Task<JobDto> CancelJobAsync(Guid id, CancellationToken cancellationToken) =>
|
|
Change(id, job => job with { State = "cancelled", Finished = DateTimeOffset.UtcNow });
|
|
|
|
public Task<JobDto> RetryJobAsync(Guid id, CancellationToken cancellationToken) => Change(id, job => job with { State = "queued", Error = null, Finished = null });
|
|
|
|
public Task<JobDto> SetJobPriorityAsync(Guid id, string priority, CancellationToken cancellationToken)
|
|
{
|
|
lock (_gate) Priorities.Add((id, priority));
|
|
return Change(id, job => job with { Priority = priority });
|
|
}
|
|
|
|
public async IAsyncEnumerable<ServerEvent> EventsAsync([EnumeratorCancellation] CancellationToken cancellationToken)
|
|
{
|
|
var events = Volatile.Read(ref _events).Reader;
|
|
_subscribed.TrySetResult();
|
|
while (await events.WaitToReadAsync(cancellationToken))
|
|
{
|
|
while (events.TryRead(out var e)) yield return e;
|
|
}
|
|
}
|
|
|
|
public void Dispose() => Disposed = true;
|
|
|
|
private SequenceDto Dto(Guid id)
|
|
{
|
|
Check(id);
|
|
return new SequenceDto(id, sequence.Title, sequence.DisplayTitle, sequence.Folder, sequence.CameraMake, sequence.CameraModel, null,
|
|
sequence.FirstCapture, sequence.LastCapture, sequence.FrameCount, sequence.MedianInterval, 0, (long)SequenceStatus.ProxiesBuilt, 1, null, [], 0,
|
|
null, SettingsVersion, 1, 0, null, DateTimeOffset.UtcNow);
|
|
}
|
|
|
|
private Task<JobDto> Change(Guid id, Func<JobDto, JobDto> change)
|
|
{
|
|
lock (_gate)
|
|
{
|
|
if (!Jobs.TryGetValue(id, out var job)) throw new ChronosApiException(HttpStatusCode.NotFound, new ApiError("not_found", "job", "job"));
|
|
return Task.FromResult(Jobs[id] = change(job));
|
|
}
|
|
}
|
|
|
|
private void Check(Guid id)
|
|
{
|
|
if (Gone || id != sequence.Id) throw new ChronosApiException(HttpStatusCode.NotFound, new ApiError("not_found", "gone", "sequence"));
|
|
}
|
|
}
|