fix(sync): resolve conflicts against the versions shown, isolate failures, renders on request

- Conflicts are settled against the versions the user was shown; a later change on
  either side refuses the choice and compares again. Title, tags, rating and notes
  changed differently on both sides are a conflict too (no silent tag union).
- Links are written under the engine's gate and forgotten only after a 404; linked
  local copies are read by id; unlinked copies with the same originals are linked
  by content.
- A failure on one sequence is recorded on its link; the others are still compared.
- Downloads hash unverified local copies first and restore originals missing here.
- Background proxy downloads give way to the user's requests; "Keep proxies offline"
  refreshes the caches of sequences opened with proxies, checks free space and backs
  off after a failure.
- Renders travel on request: Send exports (chunked, hash-verified upload keeping the
  render id; new POST /sequences/{id}/renders endpoints) and Get exports.
- Server screen: stable row buttons, mockup column grid, Tab through rows, conflict
  rows first on the card colour, localised conflict detail, Save both confirmation,
  Pause metered uploads, culture switch, Library one-word sync glyphs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
Claude committed 2026-10-03 10:26:56 +00:00
1 parent 3601e0a47f
commit 2d40a613b9
48 files changed
+2498 -465

No files matched your search

@@ -188,6 +188,54 @@ public sealed class SyncServerTests(TestContext context)
}
}
[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<Titano.Protocol.Client.TitanoApiException>(() =>
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);
}
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>