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>
168 lines
8.1 KiB
C#
168 lines
8.1 KiB
C#
using System.Security.Cryptography;
|
|
using Chronos.Core.Codecs.Jpeg;
|
|
using Chronos.Core.Model;
|
|
using Chronos.Data;
|
|
using Chronos.Data.Archiving;
|
|
using Chronos.Data.Jobs;
|
|
using Chronos.Data.Sync;
|
|
using Chronos.Protocol.Client;
|
|
using Chronos.Testing;
|
|
|
|
namespace Chronos.Server.Tests.Sync;
|
|
|
|
/// <summary>A desktop client's sync side: its own index and archive, the sync engine and a job engine, signed in to a test server.</summary>
|
|
internal sealed class SyncClient : IAsyncDisposable
|
|
{
|
|
private readonly TestContext _context;
|
|
private readonly ChronosClient _client;
|
|
|
|
private SyncClient(TestContext context, ChronosDatabase db, ArchiveService archives, Archive archive, SyncService sync, ChronosClient client, JobEngine engine)
|
|
{
|
|
_context = context;
|
|
Db = db;
|
|
Archives = archives;
|
|
Archive = archive;
|
|
Sync = sync;
|
|
_client = client;
|
|
Engine = engine;
|
|
Remote = new ChronosSyncRemote(client, ownsClient: false);
|
|
}
|
|
|
|
public ChronosDatabase Db { get; }
|
|
public ArchiveService Archives { get; }
|
|
public Archive Archive { get; }
|
|
public SyncService Sync { get; }
|
|
public JobEngine Engine { get; }
|
|
|
|
/// <summary>The connection the table and the agent use (jobs get their own from the connector).</summary>
|
|
public ChronosSyncRemote Remote { get; }
|
|
|
|
public string Server => Remote.Server;
|
|
private CancellationToken Ct => _context.Cancellation;
|
|
|
|
public static async Task<SyncClient> StartAsync(TestContext context, TestServer server, string token, string name)
|
|
{
|
|
var db = await ChronosDatabase.OpenAsync(DatabaseOptions.Sqlite(Path.Combine(context.CreateTempDirectory(name + "-db"), "chronos.db")), context.Cancellation);
|
|
var options = new ArchiveServiceOptions { Owner = name, LeaseWait = TimeSpan.FromSeconds(20) };
|
|
var archives = new ArchiveService(db, options);
|
|
var archive = await archives.CreateAsync(context.CreateTempDirectory(name + "-archive"), "Main", cancellationToken: context.Cancellation);
|
|
var sync = new SyncService(db, archives, new SyncOptions { Archive = options, ProxyCacheDirectory = context.CreateTempDirectory(name + "-proxies") });
|
|
var client = new ChronosClient(server.HttpBase, new CertificatePinning([]), name) { Token = token };
|
|
var engine = new JobEngine(db, [.. archives.CreateJobHandlers(), .. sync.CreateJobHandlers(new Connector(client))],
|
|
new JobEngineOptions { Workers = 2, WorkerId = name, PollInterval = TimeSpan.FromMilliseconds(50), CheckpointInterval = TimeSpan.FromMilliseconds(50) });
|
|
await engine.StartAsync(context.Cancellation);
|
|
return new SyncClient(context, db, archives, archive, sync, client, engine);
|
|
}
|
|
|
|
/// <summary>Distinct JPEGs larger than one 64 KiB chunk.</summary>
|
|
public static byte[] Photo(int seed)
|
|
{
|
|
const int width = 512, height = 384;
|
|
var pixels = new byte[width * height * 3];
|
|
new Random(seed).NextBytes(pixels);
|
|
return JpegEncoder.Encode(pixels, width, height, 3, new JpegEncodeOptions { Quality = 95 });
|
|
}
|
|
|
|
public static string Sha(byte[] bytes) => Convert.ToHexStringLower(SHA256.HashData(bytes));
|
|
|
|
/// <summary>A local sequence committed through the archive ingest, optionally with project settings edited on this PC.</summary>
|
|
public async Task<Sequence> LocalAsync(string title, IReadOnlyList<byte[]> photos, string? settingsJson = null)
|
|
{
|
|
var staging = Path.Combine(Archive.RootPath, ".chronos", "staging", "test");
|
|
Directory.CreateDirectory(staging);
|
|
Guid? id = null;
|
|
for (var i = 0; i < photos.Count; i++)
|
|
{
|
|
var path = Path.Combine(staging, $"{Guid.NewGuid():N}.part");
|
|
await File.WriteAllBytesAsync(path, photos[i], Ct);
|
|
var result = await Archives.Ingest.CommitAsync(new IngestRequest(Archive.Id, id, id is null ? title : null, null, path, $"IMG_{i + 1:0000}.JPG",
|
|
photos[i].Length, Sha(photos[i]), new DateTime(2026, 9, 28, 18, 0, 0).AddSeconds(10 * i), null), Ct);
|
|
id = result.SequenceId;
|
|
}
|
|
var sequence = (await Db.Sequences.GetAsync(id!.Value, Ct))!;
|
|
if (settingsJson is null) return sequence;
|
|
var edited = await Db.Sequences.EditAsync(sequence.Id, new Chronos.Data.Repositories.SequenceEdit { SettingsJson = settingsJson }, null, Ct);
|
|
return edited.Sequence!;
|
|
}
|
|
|
|
/// <summary>One more photo imported into a local sequence, captured at <paramref name="captured"/> (before others: it is inserted).</summary>
|
|
public async Task<IngestResult> AddPhotoAsync(Guid sequenceId, byte[] photo, DateTime captured)
|
|
{
|
|
var staging = Path.Combine(Archive.RootPath, ".chronos", "staging", "test");
|
|
Directory.CreateDirectory(staging);
|
|
var path = Path.Combine(staging, $"{Guid.NewGuid():N}.part");
|
|
await File.WriteAllBytesAsync(path, photo, Ct);
|
|
return await Archives.Ingest.CommitAsync(new IngestRequest(Archive.Id, sequenceId, null, null, path, $"IMG_{captured:HHmmss}.JPG", photo.Length, Sha(photo),
|
|
captured, null), Ct);
|
|
}
|
|
|
|
/// <summary>An edit on this PC, as the editor makes it (project file and index, settings version + 1).</summary>
|
|
public async Task<Sequence> EditSettingsAsync(Guid sequenceId, string settingsJson)
|
|
{
|
|
var sequence = (await Db.Sequences.GetAsync(sequenceId, Ct))!;
|
|
await File.WriteAllTextAsync(new Chronos.Core.Archiving.ArchivePaths(Archive.RootPath).Sequence(sequence.Folder).ProjectPath, settingsJson, Ct);
|
|
return (await Db.Sequences.EditAsync(sequenceId, new Chronos.Data.Repositories.SequenceEdit { SettingsJson = settingsJson }, sequence.SettingsVersion, Ct))
|
|
.Sequence!;
|
|
}
|
|
|
|
/// <summary>A render of <paramref name="sequence"/> made on this PC: its file in the sequence's exports and its row.</summary>
|
|
public async Task<Render> RenderAsync(Sequence sequence, string fileName, byte[] bytes)
|
|
{
|
|
var exports = Path.Combine(Archive.RootPath, sequence.Folder, "exports");
|
|
Directory.CreateDirectory(exports);
|
|
await File.WriteAllBytesAsync(Path.Combine(exports, fileName), bytes, Ct);
|
|
var render = new Render
|
|
{
|
|
Id = Guid.CreateVersion7(),
|
|
SequenceId = sequence.Id,
|
|
PresetName = "4K HEVC",
|
|
OutputPath = sequence.Folder + "/exports/" + fileName,
|
|
Codec = "hevc",
|
|
Width = 3840,
|
|
Height = 2160,
|
|
Fps = 30,
|
|
DurationSeconds = 10,
|
|
Bytes = bytes.Length,
|
|
Created = DateTimeOffset.UtcNow,
|
|
ProducedBy = "studio",
|
|
};
|
|
await Db.Renders.InsertAsync(render, Ct);
|
|
return render;
|
|
}
|
|
|
|
public string RenderFile(Render render) => Path.Combine(Archive.RootPath, render.OutputPath);
|
|
|
|
public async Task<Job> WaitAsync(Guid jobId, JobState state = JobState.Done)
|
|
{
|
|
var until = DateTime.UtcNow.AddSeconds(60);
|
|
while (true)
|
|
{
|
|
var job = await Db.Jobs.GetAsync(jobId, Ct);
|
|
if (job?.State == state) return job;
|
|
if (job?.State is JobState.Failed && state != JobState.Failed) Assert.Fail($"Job failed: {job.Error}\n{job.LogTail}");
|
|
if (DateTime.UtcNow > until) Assert.Fail($"Job {jobId} did not reach {state} (now {job?.State})");
|
|
await Task.Delay(25, Ct);
|
|
}
|
|
}
|
|
|
|
public async Task<SyncEntry> EntryAsync(string title) => (await Sync.ListAsync(Server, Ct)).Single(e => e.Title == title);
|
|
|
|
public async ValueTask DisposeAsync()
|
|
{
|
|
await Engine.DisposeAsync();
|
|
Remote.Dispose();
|
|
_client.Dispose();
|
|
await Db.DisposeAsync();
|
|
}
|
|
|
|
/// <summary>Every job gets its own remote over the shared signed-in client.</summary>
|
|
private sealed class Connector(ChronosClient client) : ISyncConnector
|
|
{
|
|
public ValueTask<ISyncRemote?> ConnectAsync(string server, CancellationToken cancellationToken)
|
|
{
|
|
ISyncRemote remote = new ChronosSyncRemote(client, ownsClient: false);
|
|
return ValueTask.FromResult<ISyncRemote?>(remote.Server == server ? remote : null);
|
|
}
|
|
}
|
|
}
|