refactor!: rename Titano to Chronos and move CI and releases to Gitea (#6)
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
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>
This commit was merged in pull request #6.
This commit is contained in:
1 parent
c99842cc86
commit
f2b58522b9
1801 files changed
+11804
-10676
No files matched your search
@@ -0,0 +1,167 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,390 @@
|
||||
using System.Net;
|
||||
using System.Net.Http.Json;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Chronos.Core.Imaging;
|
||||
using Chronos.Core.Imaging.Decoders;
|
||||
using Chronos.Core.Model;
|
||||
using Chronos.Core.Project;
|
||||
using Chronos.Data.Repositories;
|
||||
using Chronos.Data.Sync;
|
||||
using Chronos.Protocol;
|
||||
using Chronos.Server.Events;
|
||||
using Chronos.Server.Storage;
|
||||
using Chronos.Testing;
|
||||
|
||||
namespace Chronos.Server.Tests.Sync;
|
||||
|
||||
/// <summary>The client's sync engine against the real server: uploads, downloads, proxies and live events through the API.</summary>
|
||||
[Category("server")]
|
||||
[Timeout(180_000)]
|
||||
public sealed class SyncServerTests(TestContext context)
|
||||
{
|
||||
private const string Window41 = """{"exposure":{"deflickerWindow":{"isAuto":false,"manual":41}}}""";
|
||||
private const string Window33 = """{"exposure":{"deflickerWindow":{"isAuto":false,"manual":33}}}""";
|
||||
|
||||
/// <summary>How long any wait may take on a loaded runner; every wait ends as soon as what it waits for happened.</summary>
|
||||
private static readonly TimeSpan Deadline = TimeSpan.FromSeconds(60);
|
||||
|
||||
[Test]
|
||||
public async Task ASequenceUploadedFromOnePcDownloadsIdenticallyOnAnother()
|
||||
{
|
||||
await using var server = await StartServerAsync();
|
||||
var (_, _, token) = await server.UserAsync("alberto", "editor");
|
||||
await using var studio = await SyncClient.StartAsync(context, server, token, "studio");
|
||||
await using var laptop = await SyncClient.StartAsync(context, server, token, "laptop");
|
||||
var photos = Enumerable.Range(1, 3).Select(SyncClient.Photo).ToList();
|
||||
var local = await studio.LocalAsync("Comet over the ridge", photos, Window41);
|
||||
|
||||
var upload = await studio.Sync.EnqueueUploadAsync(studio.Engine, studio.Server, local);
|
||||
await studio.WaitAsync(upload.Id);
|
||||
|
||||
var uploaded = await studio.EntryAsync("Comet over the ridge");
|
||||
Assert.Equal((0, 0), (uploaded.Link!.MissingRemote, uploaded.Link.MissingLocal));
|
||||
var remoteId = uploaded.Link!.RemoteId;
|
||||
var onServer = Assert.NotNull(await server.Database.Sequences.GetAsync(remoteId));
|
||||
Assert.Equal(41, ProjectSettings.FromJson(onServer.SettingsJson!).Exposure.DeflickerWindow.Manual, "settings travel with the originals");
|
||||
var serverFrames = await server.Database.Frames.ListBySequenceAsync(remoteId);
|
||||
Assert.True(serverFrames.Select(f => f.Sha256).ToHashSet().SetEquals(photos.Select(SyncClient.Sha)), "every original was committed");
|
||||
|
||||
await ServerIdleAsync(server);
|
||||
await laptop.Sync.RefreshAsync(laptop.Remote, new SyncPolicy(), context.Cancellation);
|
||||
Assert.Equal(SyncStatus.RemoteOnly, (await laptop.EntryAsync("Comet over the ridge")).Status);
|
||||
var download = await laptop.Sync.EnqueueDownloadAsync(laptop.Engine, laptop.Server, remoteId, "Comet over the ridge", SyncDownloadMode.Originals,
|
||||
laptop.Archive.Id);
|
||||
await laptop.WaitAsync(download.Id);
|
||||
|
||||
var copy = await laptop.EntryAsync("Comet over the ridge");
|
||||
Assert.Equal(SyncStatus.InSync, copy.Status);
|
||||
Assert.Equal(SequenceOrigin.Server, copy.Local!.Origin);
|
||||
// The server's analysis may have added its advice meanwhile; the copy has what the server has, the user's edit included.
|
||||
Assert.True(SyncRules.SameSettings((await server.Database.Sequences.GetAsync(remoteId))!.SettingsJson, copy.Local.SettingsJson));
|
||||
Assert.Equal(41, ProjectSettings.FromJson(copy.Local.SettingsJson!).Exposure.DeflickerWindow.Manual);
|
||||
var files = (await laptop.Db.Frames.ListBySequenceAsync(copy.Local.Id))
|
||||
.Select(f => File.ReadAllBytes(Path.Combine(laptop.Archive.RootPath, f.RelativePath))).ToList();
|
||||
Assert.True(files.Select(SyncClient.Sha).ToHashSet().SetEquals(photos.Select(SyncClient.Sha)), "byte-identical originals");
|
||||
|
||||
await studio.Sync.RefreshAsync(studio.Remote, new SyncPolicy(), context.Cancellation);
|
||||
Assert.Equal(SyncStatus.InSync, (await studio.EntryAsync("Comet over the ridge")).Status);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AnUploadInterruptedMidFileResumesTheServersPartialUpload()
|
||||
{
|
||||
await using var server = await StartServerAsync();
|
||||
var (http, _, token) = await server.UserAsync("alberto", "editor");
|
||||
await using var studio = await SyncClient.StartAsync(context, server, token, "studio");
|
||||
var photos = Enumerable.Range(10, 2).Select(SyncClient.Photo).ToList();
|
||||
var local = await studio.LocalAsync("Clouds", photos);
|
||||
// The crashed attempt had sent the first original (which created the server sequence) and one chunk of the second.
|
||||
var first = await Uploads.UploadAsync(http, photos[0], "IMG_0001.JPG", sessionKey: "crashed-attempt");
|
||||
var partial = await Uploads.StartAsync(http, photos[1], "IMG_0002.JPG", first.SequenceId);
|
||||
Assert.True(photos[1].Length > partial.ChunkSize, "the photo spans several chunks");
|
||||
using (var chunk = await Uploads.PutChunkAsync(http, partial.UploadId!.Value, 0, Uploads.Chunk(photos[1], partial.ChunkSize, 0)))
|
||||
await chunk.ExpectAsync(HttpStatusCode.OK);
|
||||
|
||||
var job = new Job
|
||||
{
|
||||
Id = Guid.CreateVersion7(),
|
||||
Kind = JobKind.UploadCommit,
|
||||
TargetIds = [local.Id],
|
||||
TargetLabel = "Clouds",
|
||||
ParametersJson = $$"""{"server":"{{studio.Server}}"}""",
|
||||
Checkpoint = first.SequenceId.ToString(),
|
||||
State = JobState.Queued,
|
||||
Created = DateTimeOffset.UtcNow,
|
||||
};
|
||||
await studio.Db.Jobs.EnqueueAsync(job, context.Cancellation);
|
||||
studio.Engine.Wake();
|
||||
await studio.WaitAsync(job.Id);
|
||||
|
||||
var resumed = Assert.NotNull(await server.Database.Uploads.GetAsync(partial.UploadId!.Value));
|
||||
Assert.Equal(Chronos.Data.Repositories.UploadState.Committed, resumed.State);
|
||||
Assert.Equal(2, (await server.Database.Frames.ListBySequenceAsync(first.SequenceId)).Count);
|
||||
// Every original is on both sides (the server's analysis may still be editing the settings).
|
||||
var link = (await studio.EntryAsync("Clouds")).Link!;
|
||||
Assert.Equal((first.SequenceId, 0, 0), (link.RemoteId, link.MissingRemote, link.MissingLocal));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ADownloadResumesPartialFilesAndRefusesDamagedOnes()
|
||||
{
|
||||
await using var server = await StartServerAsync();
|
||||
var (_, _, token) = await server.UserAsync("alberto", "editor");
|
||||
await using var studio = await SyncClient.StartAsync(context, server, token, "studio");
|
||||
await using var laptop = await SyncClient.StartAsync(context, server, token, "laptop");
|
||||
var photos = Enumerable.Range(20, 4).Select(SyncClient.Photo).ToList();
|
||||
var local = await studio.LocalAsync("Aurora", photos);
|
||||
await studio.WaitAsync((await studio.Sync.EnqueueUploadAsync(studio.Engine, studio.Server, local)).Id);
|
||||
var remoteId = (await studio.EntryAsync("Aurora")).Link!.RemoteId;
|
||||
|
||||
// An earlier attempt left half of one original, a damaged half of another, a third complete (stopped while it was
|
||||
// being hashed) and a fourth longer than the file: the server cannot resume either of the last two (416).
|
||||
var staging = Path.Combine(laptop.Archive.RootPath, ".chronos", "staging", "sync-" + remoteId.ToString("N"));
|
||||
Directory.CreateDirectory(staging);
|
||||
await File.WriteAllBytesAsync(Path.Combine(staging, SyncClient.Sha(photos[0]) + ".jpg.part"), photos[0][..(photos[0].Length / 2)]);
|
||||
await File.WriteAllBytesAsync(Path.Combine(staging, SyncClient.Sha(photos[1]) + ".jpg.part"), new byte[photos[1].Length / 2]);
|
||||
await File.WriteAllBytesAsync(Path.Combine(staging, SyncClient.Sha(photos[2]) + ".jpg.part"), photos[2]);
|
||||
await File.WriteAllBytesAsync(Path.Combine(staging, SyncClient.Sha(photos[3]) + ".jpg.part"), [.. photos[3], .. new byte[64]]);
|
||||
|
||||
await laptop.Sync.RefreshAsync(laptop.Remote, new SyncPolicy(), context.Cancellation);
|
||||
var download = await laptop.Sync.EnqueueDownloadAsync(laptop.Engine, laptop.Server, remoteId, "Aurora", SyncDownloadMode.Originals, laptop.Archive.Id);
|
||||
await laptop.WaitAsync(download.Id);
|
||||
|
||||
var copy = Assert.NotNull((await laptop.EntryAsync("Aurora")).Local);
|
||||
var hashes = (await laptop.Db.Frames.ListBySequenceAsync(copy.Id))
|
||||
.Select(f => SyncClient.Sha(File.ReadAllBytes(Path.Combine(laptop.Archive.RootPath, f.RelativePath)))).ToHashSet();
|
||||
Assert.True(hashes.SetEquals(photos.Select(SyncClient.Sha)), "every original arrived intact");
|
||||
Assert.False(Directory.Exists(staging), "staging cleaned up");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ServerEventsUpdateThisPcWithoutWaitingForTheNextComparison()
|
||||
{
|
||||
await using var server = await StartServerAsync();
|
||||
var (http, _, token) = await server.UserAsync("alberto", "editor");
|
||||
await using var studio = await SyncClient.StartAsync(context, server, token, "studio");
|
||||
var local = await studio.LocalAsync("Harbour sunset", [SyncClient.Photo(30)]);
|
||||
await studio.WaitAsync((await studio.Sync.EnqueueUploadAsync(studio.Engine, studio.Server, local)).Id);
|
||||
var remoteId = (await studio.EntryAsync("Harbour sunset")).Link!.RemoteId;
|
||||
await ServerIdleAsync(server);
|
||||
await using var agent = new SyncAgent(studio.Sync, studio.Remote, () => new SyncPolicy(), studio.Engine,
|
||||
new SyncAgentOptions { RefreshInterval = TimeSpan.FromHours(1), EventDelay = TimeSpan.FromMilliseconds(50) });
|
||||
agent.Start();
|
||||
var hub = server.Services.GetRequiredService<EventHub>();
|
||||
await UntilAsync(() => Task.FromResult(agent.Snapshot is not null && hub.SubscriberCount > 0), "the agent's first comparison and event socket");
|
||||
|
||||
// Someone edits the project on the server (web or another PC). The comparison its event starts writes the
|
||||
// settings on this PC before the link that records the agreement: wait for the comparison, not for the settings.
|
||||
var compared = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
studio.Sync.Changed += _ => compared.TrySetResult();
|
||||
using (var patch = await http.PatchAsJsonAsync($"/api/v1/sequences/{remoteId}",
|
||||
new UpdateSequenceRequest(null, null, null, null, Window33, null), ProtocolJson.Default.UpdateSequenceRequest))
|
||||
await patch.ExpectAsync(HttpStatusCode.OK);
|
||||
|
||||
await SignalAsync(compared.Task, "the comparison of the edit");
|
||||
Assert.Equal(33, ProjectSettings.FromJson((await studio.Db.Sequences.GetAsync(local.Id))!.SettingsJson ?? "{}").Exposure.DeflickerWindow.Manual,
|
||||
"the edit reached this PC");
|
||||
Assert.Equal(SyncStatus.InSync, (await studio.EntryAsync("Harbour sunset")).Status);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ARemoteSequenceOpensWithProxiesOnly()
|
||||
{
|
||||
await using var server = await StartServerAsync();
|
||||
var (_, _, token) = await server.UserAsync("alberto", "editor");
|
||||
await using var studio = await SyncClient.StartAsync(context, server, token, "studio");
|
||||
await using var laptop = await SyncClient.StartAsync(context, server, token, "laptop");
|
||||
var photos = Enumerable.Range(40, 2).Select(SyncClient.Photo).ToList();
|
||||
var local = await studio.LocalAsync("Milan skyline dusk", photos, Window41);
|
||||
await studio.WaitAsync((await studio.Sync.EnqueueUploadAsync(studio.Engine, studio.Server, local)).Id);
|
||||
var remoteId = (await studio.EntryAsync("Milan skyline dusk")).Link!.RemoteId;
|
||||
await ServerIdleAsync(server);
|
||||
Assert.True(((await server.Database.Sequences.GetAsync(remoteId))!.Status & SequenceStatus.ThumbsBuilt) != 0, "thumbnails on the server");
|
||||
// A remote card without a hero frame shows its first frame, read as one row instead of the whole list.
|
||||
ISyncRemote remote = laptop.Remote;
|
||||
Assert.Equal((await remote.ListFramesAsync(remoteId, context.Cancellation))[0].Id, (await remote.FirstFrameAsync(remoteId, context.Cancellation))?.Id);
|
||||
|
||||
await laptop.Sync.RefreshAsync(laptop.Remote, new SyncPolicy(), context.Cancellation);
|
||||
var job = await laptop.Sync.EnqueueDownloadAsync(laptop.Engine, laptop.Server, remoteId, "Milan skyline dusk", SyncDownloadMode.Proxies, null);
|
||||
await laptop.WaitAsync(job.Id);
|
||||
|
||||
Assert.Equal(SyncStatus.ProxiesOnly, (await laptop.EntryAsync("Milan skyline dusk")).Status);
|
||||
Assert.Empty((await laptop.Db.Sequences.ListAsync(new SequenceQuery())).Items);
|
||||
var opened = Assert.NotNull(laptop.Sync.OpenRemote(laptop.Server, remoteId));
|
||||
Assert.Equal(2, opened.CachedCount);
|
||||
Assert.Equal(41, ProjectSettings.FromJson(opened.Sequence.SettingsJson!).Exposure.DeflickerWindow.Manual);
|
||||
var source = opened.OpenFrames(DecoderFactory.CreateServer());
|
||||
await using (source as IAsyncDisposable)
|
||||
{
|
||||
using var frame = await source.GetFrameAsync(0, 0, DecodePurpose.Render, context.Cancellation);
|
||||
Assert.True(frame.Width > 0 && frame.Height > 0, "a proxy decodes");
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task RendersTravelOnRequestWithTheirIdAndAreVerified()
|
||||
{
|
||||
await using var server = await StartServerAsync();
|
||||
var (_, _, token) = await server.UserAsync("alberto", "editor");
|
||||
await using var studio = await SyncClient.StartAsync(context, server, token, "studio");
|
||||
await using var laptop = await SyncClient.StartAsync(context, server, token, "laptop");
|
||||
var photos = Enumerable.Range(50, 2).Select(SyncClient.Photo).ToList();
|
||||
var local = await studio.LocalAsync("Star trails", photos);
|
||||
await studio.WaitAsync((await studio.Sync.EnqueueUploadAsync(studio.Engine, studio.Server, local)).Id);
|
||||
var remoteId = (await studio.EntryAsync("Star trails")).Link!.RemoteId;
|
||||
await ServerIdleAsync(server);
|
||||
|
||||
// A render made on the studio PC, larger than one chunk, is sent on request and keeps its id.
|
||||
var output = Enumerable.Range(0, 200_000).Select(i => (byte)(i * 31)).ToArray();
|
||||
var render = await studio.RenderAsync(local, "Star trails 4K.mp4", output);
|
||||
await studio.Sync.RefreshAsync(studio.Remote, new SyncPolicy(), context.Cancellation);
|
||||
Assert.Equal(1, (await studio.EntryAsync("Star trails")).Link!.ExportsToSend);
|
||||
await studio.WaitAsync((await studio.Sync.EnqueueSendExportsAsync(studio.Engine, studio.Server, local)).Id);
|
||||
|
||||
var filed = Assert.NotNull(await server.Database.Renders.GetAsync(render.Id));
|
||||
Assert.Equal(remoteId, filed.SequenceId);
|
||||
Assert.SequenceEqual(output, await File.ReadAllBytesAsync(Path.Combine(server.Options.ArchivePath, filed.OutputPath)));
|
||||
Assert.Equal(0, (await studio.EntryAsync("Star trails")).Link!.ExportsToSend);
|
||||
Assert.Null(await studio.Remote.UploadRenderAsync(remoteId, studio.RenderFile(render), new RenderUploadRequest(render.Id, "Star trails 4K.mp4",
|
||||
output.Length, SyncClient.Sha(output), "4K HEVC", "hevc", 3840, 2160, 30, 10, "studio"), context.Cancellation));
|
||||
|
||||
// A damaged transfer is refused at completion.
|
||||
var bad = new RenderUploadRequest(Guid.CreateVersion7(), "Damaged.mp4", output.Length, SyncClient.Sha(output), "4K HEVC", "hevc", 3840, 2160, 30, 10, null);
|
||||
var damaged = Path.Combine(context.CreateTempDirectory("damaged"), "Damaged.mp4");
|
||||
await File.WriteAllBytesAsync(damaged, [.. output.Select(b => (byte)~b)]);
|
||||
var refused = await Assert.ThrowsAsync<Chronos.Protocol.Client.ChronosApiException>(() =>
|
||||
studio.Remote.UploadRenderAsync(remoteId, damaged, bad, context.Cancellation));
|
||||
Assert.Equal(HttpStatusCode.UnprocessableEntity, refused.Status);
|
||||
Assert.Null(await server.Database.Renders.GetAsync(bad.RenderId));
|
||||
|
||||
// Another PC with the originals gets the render into its own exports, byte-identical.
|
||||
await laptop.Sync.RefreshAsync(laptop.Remote, new SyncPolicy(), context.Cancellation);
|
||||
await laptop.WaitAsync((await laptop.Sync.EnqueueDownloadAsync(laptop.Engine, laptop.Server, remoteId, "Star trails", SyncDownloadMode.Originals,
|
||||
laptop.Archive.Id)).Id);
|
||||
Assert.Equal(1, (await laptop.EntryAsync("Star trails")).Link!.ExportsToGet);
|
||||
await laptop.WaitAsync((await laptop.Sync.EnqueueDownloadAsync(laptop.Engine, laptop.Server, remoteId, "Star trails", SyncDownloadMode.Exports, null)).Id);
|
||||
var copy = (await laptop.EntryAsync("Star trails")).Local!;
|
||||
var fetched = Assert.Contains(await laptop.Db.Renders.ListBySequenceAsync(copy.Id), r => r.Id == render.Id);
|
||||
Assert.SequenceEqual(output, await File.ReadAllBytesAsync(Path.Combine(laptop.Archive.RootPath, fetched.OutputPath)));
|
||||
Assert.Equal(0, (await laptop.EntryAsync("Star trails")).Link!.ExportsToGet);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task PositionsEditedOnTheServerStayOnTheirPhotosWhenAnotherPcDownloadsTheInsertedFrames()
|
||||
{
|
||||
await using var server = await StartServerAsync();
|
||||
var (http, _, token) = await server.UserAsync("alberto", "editor");
|
||||
await using var studio = await SyncClient.StartAsync(context, server, token, "studio");
|
||||
await using var laptop = await SyncClient.StartAsync(context, server, token, "laptop");
|
||||
var photos = Enumerable.Range(60, 5).Select(SyncClient.Photo).ToList();
|
||||
// Both PCs hold the last four photos, the third of them excluded.
|
||||
var local = await studio.LocalAsync("Harbour at dawn", photos[1..], new ProjectSettings { ExcludedFrames = [2] }.ToJson());
|
||||
await studio.WaitAsync((await studio.Sync.EnqueueUploadAsync(studio.Engine, studio.Server, local)).Id);
|
||||
var remoteId = (await studio.EntryAsync("Harbour at dawn")).Link!.RemoteId;
|
||||
await ServerIdleAsync(server);
|
||||
await laptop.Sync.RefreshAsync(laptop.Remote, new SyncPolicy(), context.Cancellation);
|
||||
await laptop.WaitAsync((await laptop.Sync.EnqueueDownloadAsync(laptop.Engine, laptop.Server, remoteId, "Harbour at dawn", SyncDownloadMode.Originals,
|
||||
laptop.Archive.Id)).Id);
|
||||
var copy = (await laptop.EntryAsync("Harbour at dawn")).Local!;
|
||||
|
||||
// The studio files an earlier photo and uploads it: the server inserts it first and moves its own positions.
|
||||
await studio.AddPhotoAsync(local.Id, photos[0], new DateTime(2026, 9, 28, 17, 59, 50));
|
||||
await studio.WaitAsync((await studio.Sync.EnqueueUploadAsync(studio.Engine, studio.Server, local)).Id);
|
||||
await ServerIdleAsync(server);
|
||||
Assert.SequenceEqual([SyncClient.Sha(photos[3])], (await ServerNamedAsync(server, remoteId)).Excluded);
|
||||
|
||||
// An editor on the server excludes the new photo too, by the server's frames, and changes the deflicker window.
|
||||
var row = (await server.Database.Sequences.GetAsync(remoteId))!;
|
||||
var current = ProjectSettings.FromJson(row.SettingsJson!);
|
||||
var edit = current with
|
||||
{
|
||||
ExcludedFrames = [0, .. current.ExcludedFrames],
|
||||
Exposure = current.Exposure with { DeflickerWindow = new Auto<int>().WithManual(33) },
|
||||
};
|
||||
using (var patch = await http.PatchAsJsonAsync($"/api/v1/sequences/{remoteId}",
|
||||
new UpdateSequenceRequest(null, null, null, null, edit.ToJson(), row.SettingsVersion), ProtocolJson.Default.UpdateSequenceRequest))
|
||||
await patch.ExpectAsync(HttpStatusCode.OK);
|
||||
|
||||
// The laptop takes the edit while it still lacks the new photo, then downloads it.
|
||||
await laptop.Sync.RefreshAsync(laptop.Remote, new SyncPolicy(), context.Cancellation);
|
||||
var taken = await LocalNamedAsync(laptop, copy.Id);
|
||||
Assert.Equal(33, taken.Project.Exposure.DeflickerWindow.Manual);
|
||||
Assert.SequenceEqual([SyncClient.Sha(photos[3])], taken.Excluded);
|
||||
Assert.True(taken.Project.PendingFrames is [{ Excluded: true } waiting] && waiting.Sha256 == SyncClient.Sha(photos[0]), "the new photo's exclusion waits for it");
|
||||
await laptop.WaitAsync((await laptop.Sync.EnqueueDownloadAsync(laptop.Engine, laptop.Server, remoteId, "Harbour at dawn", SyncDownloadMode.Originals,
|
||||
null)).Id);
|
||||
|
||||
var onServer = await ServerNamedAsync(server, remoteId);
|
||||
var here = await LocalNamedAsync(laptop, copy.Id);
|
||||
Assert.SequenceEqual([SyncClient.Sha(photos[0]), SyncClient.Sha(photos[3])], here.Excluded);
|
||||
Assert.SequenceEqual(onServer.Excluded, here.Excluded);
|
||||
Assert.Equal(onServer.Hero, here.Hero);
|
||||
Assert.Null(here.Project.PendingFrames);
|
||||
await laptop.Sync.RefreshAsync(laptop.Remote, new SyncPolicy(), context.Cancellation);
|
||||
Assert.Equal(SyncStatus.InSync, (await laptop.EntryAsync("Harbour at dawn")).Status);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task PositionsSentBeforeTheirPhotosStayOnThemWhenTheUploadArrives()
|
||||
{
|
||||
await using var server = await StartServerAsync();
|
||||
var (_, _, token) = await server.UserAsync("alberto", "editor");
|
||||
await using var studio = await SyncClient.StartAsync(context, server, token, "studio");
|
||||
var photos = Enumerable.Range(70, 5).Select(SyncClient.Photo).ToList();
|
||||
var local = await studio.LocalAsync("Pier", photos[1..]);
|
||||
await studio.WaitAsync((await studio.Sync.EnqueueUploadAsync(studio.Engine, studio.Server, local)).Id);
|
||||
var remoteId = (await studio.EntryAsync("Pier")).Link!.RemoteId;
|
||||
await ServerIdleAsync(server);
|
||||
await studio.Sync.RefreshAsync(studio.Remote, new SyncPolicy(), context.Cancellation);
|
||||
|
||||
// This PC files an earlier photo and, before uploading it, excludes it and a later one and picks the hero.
|
||||
await studio.AddPhotoAsync(local.Id, photos[0], new DateTime(2026, 9, 28, 17, 59, 50));
|
||||
var project = ProjectSettings.FromJson((await studio.Db.Sequences.GetAsync(local.Id))!.SettingsJson ?? "{}");
|
||||
await studio.EditSettingsAsync(local.Id, (project with { ExcludedFrames = [0, 3], HeroFrame = 1 }).ToJson());
|
||||
await studio.Sync.RefreshAsync(studio.Remote, new SyncPolicy(), context.Cancellation);
|
||||
|
||||
var sent = await ServerNamedAsync(server, remoteId);
|
||||
Assert.SequenceEqual([SyncClient.Sha(photos[3])], sent.Excluded);
|
||||
Assert.Equal(SyncClient.Sha(photos[1]), sent.Hero);
|
||||
Assert.True(sent.Project.PendingFrames is [{ Excluded: true } waiting] && waiting.Sha256 == SyncClient.Sha(photos[0]), "the exclusion waits for its photo");
|
||||
|
||||
await studio.WaitAsync((await studio.Sync.EnqueueUploadAsync(studio.Engine, studio.Server, local)).Id);
|
||||
await ServerIdleAsync(server);
|
||||
|
||||
var arrived = await ServerNamedAsync(server, remoteId);
|
||||
Assert.SequenceEqual([SyncClient.Sha(photos[0]), SyncClient.Sha(photos[3])], arrived.Excluded);
|
||||
Assert.Equal(SyncClient.Sha(photos[1]), arrived.Hero);
|
||||
Assert.Null(arrived.Project.PendingFrames);
|
||||
var heroFrame = (await server.Database.Sequences.GetAsync(remoteId))!.HeroFrameId;
|
||||
Assert.Equal(SyncClient.Sha(photos[1]), (await server.Database.Frames.ListBySequenceAsync(remoteId)).Single(f => f.Id == heroFrame).Sha256);
|
||||
var here = await LocalNamedAsync(studio, local.Id);
|
||||
Assert.SequenceEqual(arrived.Excluded, here.Excluded);
|
||||
Assert.Equal(arrived.Hero, here.Hero);
|
||||
await studio.Sync.RefreshAsync(studio.Remote, new SyncPolicy(), context.Cancellation);
|
||||
Assert.Equal(SyncStatus.InSync, (await studio.EntryAsync("Pier")).Status);
|
||||
}
|
||||
|
||||
/// <summary>The server's project and the photos (SHA-256) it excludes and shows as hero.</summary>
|
||||
private static async Task<(ProjectSettings Project, string?[] Excluded, string? Hero)> ServerNamedAsync(TestServer server, Guid remoteId)
|
||||
{
|
||||
var project = ProjectSettings.FromJson((await server.Database.Sequences.GetAsync(remoteId))!.SettingsJson ?? "{}");
|
||||
var frames = await server.Database.Frames.ListBySequenceAsync(remoteId);
|
||||
return (project, [.. project.ExcludedFrames.Select(i => frames[i].Sha256)], project.HeroFrame is { } hero ? frames[hero].Sha256 : null);
|
||||
}
|
||||
|
||||
/// <summary>A PC's project and the photos (SHA-256) it excludes and shows as hero.</summary>
|
||||
private static async Task<(ProjectSettings Project, string?[] Excluded, string? Hero)> LocalNamedAsync(SyncClient client, Guid localId)
|
||||
{
|
||||
var project = ProjectSettings.FromJson((await client.Db.Sequences.GetAsync(localId))!.SettingsJson ?? "{}");
|
||||
var frames = await client.Db.Frames.ListBySequenceAsync(localId);
|
||||
return (project, [.. project.ExcludedFrames.Select(i => frames[i].Sha256)], project.HeroFrame is { } hero ? frames[hero].Sha256 : null);
|
||||
}
|
||||
|
||||
private Task<TestServer> StartServerAsync() => TestServer.StartAsync(context, o => o.ChunkSizeBytes = 64 * 1024, ArchiveModule.Register);
|
||||
|
||||
/// <summary>Waits until the server's engines finished what the commits queued (thumbnails, proxies, analysis, which may edit settings).</summary>
|
||||
private Task ServerIdleAsync(TestServer server) =>
|
||||
UntilAsync(async () => await server.Database.Jobs.CountAsync(DateTimeOffset.UtcNow) is { Queued: 0, Running: 0 }, "the server's jobs");
|
||||
|
||||
private async Task UntilAsync(Func<Task<bool>> condition, string what)
|
||||
{
|
||||
var until = DateTime.UtcNow + Deadline;
|
||||
while (!await condition())
|
||||
{
|
||||
if (DateTime.UtcNow > until) Assert.Fail("Timed out waiting for " + what);
|
||||
await Task.Delay(50, context.Cancellation);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task SignalAsync(Task signal, string what)
|
||||
{
|
||||
try
|
||||
{
|
||||
await signal.WaitAsync(Deadline, context.Cancellation);
|
||||
}
|
||||
catch (TimeoutException)
|
||||
{
|
||||
Assert.Fail("Timed out waiting for " + what);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user