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:
48 files changed
+2498
-465
No files matched your search
@@ -1,7 +1,11 @@
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using Titano.App.Infrastructure;
|
||||
using Titano.App.Sections;
|
||||
using Titano.App.Server;
|
||||
using Titano.App.Shell;
|
||||
using Titano.App.Tests.Windows;
|
||||
using Titano.Core.Localization;
|
||||
using Titano.Core.Model;
|
||||
using Titano.Data.Sync;
|
||||
using Titano.Testing;
|
||||
@@ -9,7 +13,7 @@ using Titano.Ui.Controls;
|
||||
|
||||
namespace Titano.App.Tests.Server;
|
||||
|
||||
/// <summary>The Server screen's sync table on the capture sample data: comparison, transfer, conflict and the Library's glyphs.</summary>
|
||||
/// <summary>The Server screen's sync table on the capture sample data: comparison, transfers, conflict and the Library's glyphs.</summary>
|
||||
[WindowsOnly]
|
||||
[Serial]
|
||||
[Timeout(300_000)]
|
||||
@@ -24,45 +28,77 @@ public sealed class ServerScreenSmokeTests
|
||||
await shell.Library.RefreshAsync();
|
||||
await shell.Services.Server.RestoreAsync();
|
||||
Assert.NotNull(await shell.Services.Sync.RefreshAsync());
|
||||
await app.Sample.CacheProxiesAsync();
|
||||
var table = shell.Server.Sync;
|
||||
await table.ReloadAsync();
|
||||
|
||||
// 36 sequences here (4 also on the server) and 2 only on the server.
|
||||
// 36 sequences here (6 also on the server) and 2 only on the server; the conflict is listed first.
|
||||
Assert.True(table.IsActive);
|
||||
Assert.Equal(38, table.Rows.Count);
|
||||
Assert.Equal("Holy grail · Monviso", table.Rows[0].Title);
|
||||
Assert.True(table.Rows[0].IsConflict);
|
||||
Assert.Equal(1, Chip(table, SyncFilter.Conflicts).Count);
|
||||
Assert.Equal(2, Chip(table, SyncFilter.Remote).Count);
|
||||
Assert.Equal(32, Chip(table, SyncFilter.LocalOnly).Count);
|
||||
Assert.Equal(30, Chip(table, SyncFilter.LocalOnly).Count);
|
||||
Assert.Equal(SyncStatus.InSync, Row(table, "Harbour sunset").Entry.Status);
|
||||
Assert.Equal(SyncStatus.ServerAhead, Row(table, "Construction cam · week 38").Entry.Status);
|
||||
Assert.SequenceEqual([SyncAction.DownloadOriginals], Row(table, "Construction cam · week 38").Actions.Select(a => a.Action));
|
||||
Assert.SequenceEqual([SyncAction.OpenWithProxies, SyncAction.DownloadOriginals], Row(table, "Sunrise over Superga").Actions.Select(a => a.Action));
|
||||
Assert.SequenceEqual([SyncAction.Upload], Row(table, "Clouds over the Langhe").Actions.Select(a => a.Action));
|
||||
Assert.SequenceEqual([SyncAction.DownloadOriginals], Actions(Row(table, "Construction cam · week 38")));
|
||||
Assert.SequenceEqual([SyncAction.Upload], Actions(Row(table, "Milan skyline dusk")));
|
||||
Assert.SequenceEqual([SyncAction.GetExports], Actions(Row(table, "Star trails, Colle del Nivolet")));
|
||||
var sunrise = Row(table, "Sunrise over Superga");
|
||||
Assert.Equal(SyncStatus.ProxiesOnly, sunrise.Entry.Status);
|
||||
Assert.Equal(Loc.L("Server.Sync.Proxies"), sunrise.LocalText);
|
||||
Assert.SequenceEqual([SyncAction.OpenWithProxies, SyncAction.DownloadOriginals], Actions(sunrise));
|
||||
Assert.SequenceEqual([SyncAction.Upload], Actions(Row(table, "Clouds over the Langhe")));
|
||||
var conflict = Row(table, "Holy grail · Monviso");
|
||||
Assert.Equal(StatusKind.Warning, conflict.StateKind);
|
||||
Assert.SequenceEqual([SyncAction.KeepMine, SyncAction.TakeServer, SyncAction.SaveBoth], conflict.Actions.Select(a => a.Action));
|
||||
Assert.Contains("41", conflict.StateToolTip);
|
||||
Assert.SequenceEqual([SyncAction.KeepMine, SyncAction.TakeServer, SyncAction.SaveBoth], Actions(conflict));
|
||||
Assert.Equal(Loc.L("Server.Conflict.Difference", Loc.L("Server.Setting.DeflickerWindow"), "41", "33"), conflict.StateToolTip);
|
||||
Assert.NotNull(table.LastSyncText);
|
||||
Assert.NotNull(table.ArchiveText);
|
||||
Assert.True(table.UploadAllCommand.CanExecute(null), "the table filled after the view bound");
|
||||
|
||||
// The Library shows the real sync state of each local copy.
|
||||
// Resolving shows the plan first: what differs and which side is overwritten.
|
||||
var keepMine = SyncTableViewModel.ConflictRequest(conflict.Entry, SyncAction.KeepMine);
|
||||
Assert.True(keepMine.IsDestructive);
|
||||
Assert.Contains(Loc.L("Server.Setting.DeflickerWindow"), keepMine.Detail);
|
||||
Assert.False(SyncTableViewModel.ConflictRequest(conflict.Entry, SyncAction.SaveBoth).IsDestructive);
|
||||
|
||||
// The Library shows the real sync state of each local copy, in one word.
|
||||
var holyGrail = shell.Library.Items.Single(i => i.Title == "Holy grail · Monviso");
|
||||
Assert.Equal(SyncState.Conflict, holyGrail.Sequence.SyncState);
|
||||
Assert.Contains(holyGrail.Statuses, s => s.Kind == StatusKind.Warning);
|
||||
Assert.Equal(StatusKind.Warning, holyGrail.Statuses[^1].Kind);
|
||||
Assert.Contains(shell.Library.Items.Single(i => i.Title == "Harbour sunset").Statuses, s => s.Kind == StatusKind.Synced);
|
||||
var milan = shell.Library.Items.Single(i => i.Title == "Milan skyline dusk").Statuses[^1];
|
||||
Assert.Equal((StatusKind.Synced, Loc.L("Library.Status.Synced")), (milan.Kind, milan.Text));
|
||||
|
||||
shell.Navigate(SectionKey.Server);
|
||||
await app.ExpectAsync<ServerView>("server");
|
||||
|
||||
// An upload in progress: the row shows what the server received and offers Pause.
|
||||
// Tab walks the row buttons of every row: the rows take no focus, the list passes Tab on to their content.
|
||||
var list = app.FindAll<ListBox>().Single(l => l.Name == "SyncList");
|
||||
Assert.Equal(KeyboardNavigationMode.Continue, KeyboardNavigation.GetTabNavigation(list));
|
||||
var rowButtons = app.FindAll<Button>().Where(b => b.DataContext is SyncRowAction && b.IsVisible).ToList();
|
||||
Assert.True(rowButtons.Select(b => b.DataContext).OfType<SyncRowAction>().Count() > 3, "buttons of several rows are on screen");
|
||||
Assert.True(rowButtons.All(b => b.Focusable && b.IsTabStop), "every row button is a tab stop");
|
||||
|
||||
// Transfers in every state: the rows show what moves and offer Pause or Resume.
|
||||
await app.Sample.FillSyncAsync();
|
||||
await table.ReloadAsync();
|
||||
var comet = Row(table, "Comet over the ridge");
|
||||
Assert.Equal(SyncStatus.Transferring, comet.Entry.Status);
|
||||
Assert.SequenceEqual([SyncAction.Pause], comet.Actions.Select(a => a.Action));
|
||||
Assert.SequenceEqual([SyncAction.Pause], Actions(comet));
|
||||
Assert.Contains("46", comet.ServerText);
|
||||
Assert.Equal(StatusKind.Queued, Row(table, "Fog lifting, Asti").StateKind);
|
||||
Assert.Equal((StatusKind.Running, Loc.L("Server.Sync.State.Downloading")), (Row(table, "Sunrise over Superga").StateKind, Row(table, "Sunrise over Superga").StateText));
|
||||
Assert.SequenceEqual([SyncAction.Resume], Actions(Row(table, "Lake Como storm")));
|
||||
await app.ExpectAsync<ServerView>("server-sync");
|
||||
|
||||
// A reload keeps the row's buttons (focus, tooltips and clicks survive progress and comparisons).
|
||||
var pause = comet.Actions[0];
|
||||
await table.ReloadAsync();
|
||||
Assert.Same(pause, Row(table, "Comet over the ridge").Actions[0]);
|
||||
|
||||
// The conflict filter leaves the one row waiting for a choice.
|
||||
Chip(table, SyncFilter.Conflicts).SelectCommand.Execute(null);
|
||||
Assert.Equal("Holy grail · Monviso", Assert.Contains(table.Rows, _ => true).Title);
|
||||
@@ -71,6 +107,17 @@ public sealed class ServerScreenSmokeTests
|
||||
table.SearchText = "nothing like this";
|
||||
Assert.False(table.HasRows);
|
||||
Assert.NotNull(table.EmptyText);
|
||||
|
||||
// Another language relabels chips and rows at once.
|
||||
UiLanguage.Apply("it");
|
||||
try
|
||||
{
|
||||
Assert.Equal("Tutte · 38", Chip(table, SyncFilter.All).Text);
|
||||
}
|
||||
finally
|
||||
{
|
||||
UiLanguage.Apply("en");
|
||||
}
|
||||
});
|
||||
|
||||
[Test]
|
||||
@@ -90,6 +137,8 @@ public sealed class ServerScreenSmokeTests
|
||||
|
||||
Assert.False(shell.Server.Sync.IsActive);
|
||||
Assert.False(shell.Server.Sync.HasRows);
|
||||
Assert.False(shell.Server.Sync.UploadAllCommand.CanExecute(null));
|
||||
Assert.Equal(Loc.L("Tooltips.Server.Sync.UploadAll.NotConnected"), shell.Server.Sync.UploadAllToolTip);
|
||||
shell.Navigate(SectionKey.Server);
|
||||
await app.ExpectAsync<ServerView>("server-signedout-table");
|
||||
});
|
||||
@@ -97,4 +146,6 @@ public sealed class ServerScreenSmokeTests
|
||||
private static SyncFilterChip Chip(SyncTableViewModel table, SyncFilter filter) => table.Chips.Single(c => c.Filter == filter);
|
||||
|
||||
private static SyncRow Row(SyncTableViewModel table, string title) => table.Rows.Single(r => r.Title == title);
|
||||
|
||||
private static IEnumerable<SyncAction> Actions(SyncRow row) => row.Actions.Select(a => a.Action);
|
||||
}
|
||||
@@ -38,9 +38,9 @@ public sealed class SyncTextTests
|
||||
[Test]
|
||||
public void RightsFollowTheServerPermissions()
|
||||
{
|
||||
Assert.Equal(new SyncRights(true, true), Editor);
|
||||
Assert.Equal(new SyncRights(false, false), Viewer);
|
||||
Assert.Equal(new SyncRights(false, true), SyncRights.Of((long)Permissions.RenderNode));
|
||||
Assert.Equal(new SyncRights(true, true, true), Editor);
|
||||
Assert.Equal(new SyncRights(false, false, false), Viewer);
|
||||
Assert.Equal(new SyncRights(false, true, false), SyncRights.Of((long)Permissions.RenderNode));
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -56,6 +56,19 @@ public sealed class SyncTextTests
|
||||
Assert.SequenceEqual([SyncAction.KeepMine, SyncAction.TakeServer, SyncAction.SaveBoth], SyncText.Actions(Entry(SyncStatus.Conflict), Editor));
|
||||
Assert.Empty(SyncText.Actions(Entry(SyncStatus.InSync), Editor));
|
||||
|
||||
// Without the edit right nothing of this PC is sent: no "Keep mine", no settings push.
|
||||
Assert.SequenceEqual([SyncAction.TakeServer, SyncAction.SaveBoth], SyncText.Actions(Entry(SyncStatus.Conflict), Viewer));
|
||||
Assert.Empty(SyncText.Actions(Entry(SyncStatus.LocalAhead), Viewer));
|
||||
Assert.SequenceEqual([SyncAction.SyncSettings], SyncText.Actions(Entry(SyncStatus.ServerAhead), Viewer));
|
||||
|
||||
// Renders travel on request once the originals agree.
|
||||
var exports = Link with { ExportsToGet = 3, ExportsToGetBytes = 1_900_000_000, ExportsToSend = 1, ExportsToSendBytes = 600_000_000 };
|
||||
Assert.SequenceEqual([SyncAction.GetExports, SyncAction.SendExports], SyncText.Actions(Entry(SyncStatus.InSync, exports), Editor));
|
||||
Assert.SequenceEqual([SyncAction.GetExports], SyncText.Actions(Entry(SyncStatus.InSync, exports), Viewer));
|
||||
Assert.SequenceEqual([SyncAction.KeepMine, SyncAction.TakeServer, SyncAction.SaveBoth], SyncText.Actions(Entry(SyncStatus.Conflict, exports), Editor));
|
||||
Assert.Equal(Loc.Plural("Tooltips.Server.Sync.GetExports", 3, Titano.App.Infrastructure.Formatting.Bytes(1_900_000_000)),
|
||||
SyncText.ToolTip(Entry(SyncStatus.InSync, exports), SyncAction.GetExports));
|
||||
|
||||
Assert.SequenceEqual([SyncAction.Pause], SyncText.Actions(Entry(SyncStatus.Transferring, transfer: Upload(JobState.Running)), Editor));
|
||||
Assert.SequenceEqual([SyncAction.Pause], SyncText.Actions(Entry(SyncStatus.Transferring, transfer: Upload(JobState.Queued)), Editor));
|
||||
Assert.SequenceEqual([SyncAction.Resume], SyncText.Actions(Entry(SyncStatus.Transferring, transfer: Upload(JobState.Paused)), Editor));
|
||||
@@ -93,14 +106,32 @@ public sealed class SyncTextTests
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AConflictNamesTheSettingsThatDiffer()
|
||||
public void AConflictNamesTheSettingsThatDifferInWords()
|
||||
{
|
||||
var conflict = Entry(SyncStatus.Conflict, Link with { ConflictSettingsJson = """{"exposure":{"deflickerWindow":{"isAuto":false,"manual":33}}}""" });
|
||||
var theirs = new SyncPayload(Local.Title, ["boats"], 0, null, """{"exposure":{"deflickerWindow":{"isAuto":false,"manual":33},"deflicker":{"isAuto":false,"manual":true}}}""");
|
||||
var conflict = Entry(SyncStatus.Conflict, Link with { ConflictRemote = theirs });
|
||||
|
||||
var text = SyncText.State(conflict).ToolTip;
|
||||
var lines = SyncText.Conflict(conflict, 10);
|
||||
|
||||
Assert.Equal(Loc.L("Server.Conflict.Difference", "exposure.deflickerWindow.manual", "41", "33"), text);
|
||||
Assert.Equal(Loc.L("Tooltips.Server.Sync.State.Conflict"), SyncText.Conflict(Entry(SyncStatus.Conflict)));
|
||||
Assert.SequenceEqual(
|
||||
[
|
||||
Loc.L("Server.Conflict.Difference", Loc.L("Server.Setting.Tags"), Loc.L("Server.Sync.None"), "boats"),
|
||||
Loc.L("Server.Conflict.Difference", Loc.L("Server.Setting.Deflicker"), Loc.L("Server.Setting.Auto"), Loc.L("Server.Setting.Manual")),
|
||||
Loc.L("Server.Conflict.Difference", Loc.L("Server.Setting.DeflickerWindow"), "41", "33"),
|
||||
], lines);
|
||||
// The State tooltip is one line: the first difference and how many more.
|
||||
Assert.Equal(Loc.L("Server.Conflict.More", lines[0], "2"), SyncText.State(conflict).ToolTip);
|
||||
Assert.False(SyncText.State(conflict).ToolTip.Contains('\n', StringComparison.Ordinal), "one line");
|
||||
Assert.Equal(Loc.L("Tooltips.Server.Sync.State.Conflict"), SyncText.ConflictSummary(Entry(SyncStatus.Conflict)));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ASequenceThatCouldNotBeComparedSaysWhy()
|
||||
{
|
||||
var (kind, text, tip) = SyncText.State(Entry(SyncStatus.InSync, Link with { Error = "403 forbidden" }));
|
||||
|
||||
Assert.Equal((StatusKind.Warning, Loc.L("Server.Sync.State.Failed")), (kind, text));
|
||||
Assert.Contains("403 forbidden", tip);
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
||||
@@ -29,6 +29,15 @@ internal sealed class FakeSyncRemote : ISyncRemote
|
||||
/// <summary>The next original download of this frame returns damaged bytes.</summary>
|
||||
public Guid? CorruptOnce { get; set; }
|
||||
|
||||
/// <summary>Sequences the listing skips (a page boundary moved while it was read); they are still there.</summary>
|
||||
public HashSet<Guid> Unlisted { get; } = [];
|
||||
|
||||
/// <summary>Sequences whose manifest the server refuses (403), as for an account that lost a right.</summary>
|
||||
public HashSet<Guid> Refused { get; } = [];
|
||||
|
||||
/// <summary>Proxy and thumbnail downloads fail with a server error.</summary>
|
||||
public bool FailAssets { get; set; }
|
||||
|
||||
public FakeSequence Add(string? title, IEnumerable<byte[]> originals, string? settingsJson = null,
|
||||
SequenceStatus status = SequenceStatus.ProxiesBuilt | SequenceStatus.ThumbsBuilt)
|
||||
{
|
||||
@@ -61,13 +70,24 @@ internal sealed class FakeSyncRemote : ISyncRemote
|
||||
FailingListings--;
|
||||
throw new HttpRequestException("connection refused");
|
||||
}
|
||||
return Task.FromResult<IReadOnlyList<SequenceDto>>([.. Sequences.Values.Select(s => s.Dto())]);
|
||||
return Task.FromResult<IReadOnlyList<SequenceDto>>([.. Sequences.Values.Where(s => !Unlisted.Contains(s.Id)).Select(s => s.Dto())]);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>The next request for this sequence times out (HttpClient reports a timeout as a cancellation).</summary>
|
||||
public Guid? TimeoutOnce { get; set; }
|
||||
|
||||
public Task<SequenceDto> GetSequenceAsync(Guid id, CancellationToken cancellationToken)
|
||||
{
|
||||
lock (_gate) return Task.FromResult(Find(id).Dto());
|
||||
lock (_gate)
|
||||
{
|
||||
if (TimeoutOnce == id)
|
||||
{
|
||||
TimeoutOnce = null;
|
||||
throw new TaskCanceledException("The request timed out.");
|
||||
}
|
||||
return Task.FromResult(Find(id).Dto());
|
||||
}
|
||||
}
|
||||
|
||||
public Task<SequenceManifest> GetManifestAsync(Guid id, CancellationToken cancellationToken)
|
||||
@@ -75,6 +95,7 @@ internal sealed class FakeSyncRemote : ISyncRemote
|
||||
lock (_gate)
|
||||
{
|
||||
ManifestCalls++;
|
||||
if (Refused.Contains(id)) throw new TitanoApiException(HttpStatusCode.Forbidden, new ApiError("forbidden", "refused"));
|
||||
return Task.FromResult(Find(id).Manifest());
|
||||
}
|
||||
}
|
||||
@@ -137,6 +158,7 @@ internal sealed class FakeSyncRemote : ISyncRemote
|
||||
{
|
||||
"original" when CorruptOnce == frameId => [.. frame.Bytes.Select(b => (byte)~b)],
|
||||
"original" => frame.Bytes,
|
||||
"proxy" or "thumb" when FailAssets => throw new TitanoApiException(HttpStatusCode.InternalServerError, new ApiError("internal", "failed")),
|
||||
"proxy" when (sequence.Status & SequenceStatus.ProxiesBuilt) != 0 => frame.Proxy,
|
||||
"thumb" when (sequence.Status & SequenceStatus.ThumbsBuilt) != 0 => frame.Proxy[..Math.Min(frame.Proxy.Length, 64)],
|
||||
_ => throw NotFound(),
|
||||
@@ -149,6 +171,32 @@ internal sealed class FakeSyncRemote : ISyncRemote
|
||||
await destination.WriteAsync(bytes.AsMemory(offset), cancellationToken);
|
||||
}
|
||||
|
||||
public async Task<string?> DownloadRenderAsync(Guid renderId, Stream destination, CancellationToken cancellationToken)
|
||||
{
|
||||
FakeRender render;
|
||||
lock (_gate) render = Sequences.Values.SelectMany(s => s.Renders).FirstOrDefault(r => r.Id == renderId) ?? throw NotFound();
|
||||
var offset = destination.CanSeek ? (int)Math.Min(destination.Length, render.Bytes.Length) : 0;
|
||||
if (destination.CanSeek) destination.Seek(0, SeekOrigin.End);
|
||||
await destination.WriteAsync(render.Bytes.AsMemory(offset), cancellationToken);
|
||||
return render.FileName;
|
||||
}
|
||||
|
||||
/// <summary>Like the server: the SHA-256 is checked and a render keeps its id; one it already has is not sent again.</summary>
|
||||
public async Task<RenderDto?> UploadRenderAsync(Guid sequenceId, string path, RenderUploadRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
var bytes = await File.ReadAllBytesAsync(path, cancellationToken);
|
||||
if (Convert.ToHexStringLower(SHA256.HashData(bytes)) != request.Sha256 || bytes.Length != request.Size)
|
||||
throw new TitanoApiException(HttpStatusCode.UnprocessableEntity, new ApiError("hash_mismatch", "hash"));
|
||||
lock (_gate)
|
||||
{
|
||||
var sequence = Find(sequenceId);
|
||||
if (sequence.Renders.Any(r => r.Id == request.RenderId)) return null;
|
||||
var render = new FakeRender(request.RenderId, request.FileName, request.PresetName, bytes);
|
||||
sequence.Renders.Add(render);
|
||||
return render.Dto();
|
||||
}
|
||||
}
|
||||
|
||||
public async IAsyncEnumerable<ServerEvent> EventsAsync([EnumeratorCancellation] CancellationToken cancellationToken)
|
||||
{
|
||||
while (await _events.Reader.WaitToReadAsync(cancellationToken))
|
||||
@@ -178,7 +226,10 @@ internal sealed class FakeSequence
|
||||
public int FramesVersion { get; set; }
|
||||
public SequenceStatus Status { get; set; }
|
||||
public DateTimeOffset UpdatedAt { get; set; } = DateTimeOffset.UtcNow;
|
||||
public DateTime? FirstCapture { get; set; }
|
||||
public string? CameraModel { get; set; } = "Canon EOS R5";
|
||||
public List<FakeFrame> Frames { get; } = [];
|
||||
public List<FakeRender> Renders { get; } = [];
|
||||
|
||||
public FakeFrame AddFrame(byte[] bytes, string? name = null, DateTime? capturedAt = null)
|
||||
{
|
||||
@@ -189,12 +240,17 @@ internal sealed class FakeSequence
|
||||
return frame;
|
||||
}
|
||||
|
||||
public SequenceDto Dto() => new(Id, Title, Title ?? "Untitled", "2026/" + Id.ToString("N"), "Canon", "Canon EOS R5", null, null, null, Frames.Count, 10,
|
||||
Frames.Sum(f => (long)f.Bytes.Length), (long)Status, 0, null, Tags, Rating, Notes, SettingsVersion, FramesVersion, 0, null, UpdatedAt);
|
||||
public SequenceDto Dto() => new(Id, Title, Title ?? "Untitled", "2026/" + Id.ToString("N"), "Canon", CameraModel, null, FirstCapture, null, Frames.Count, 10,
|
||||
Frames.Sum(f => (long)f.Bytes.Length), (long)Status, Renders.Count, null, Tags, Rating, Notes, SettingsVersion, FramesVersion, 0, null, UpdatedAt);
|
||||
|
||||
public SequenceManifest Manifest() => new(Id, FramesVersion, SettingsVersion, SettingsJson, Tags,
|
||||
[.. Frames.Select((f, i) => new ManifestFrame(f.Id, i, f.FileName, f.Bytes.Length, f.Sha256, (Status & SequenceStatus.ProxiesBuilt) != 0,
|
||||
(Status & SequenceStatus.ThumbsBuilt) != 0))], []);
|
||||
(Status & SequenceStatus.ThumbsBuilt) != 0))], [.. Renders.Select(r => r.Dto())]);
|
||||
}
|
||||
|
||||
internal sealed record FakeRender(Guid Id, string FileName, string PresetName, byte[] Bytes)
|
||||
{
|
||||
public RenderDto Dto() => new(Id, PresetName, "hevc", 3840, 2160, 30, 12, Bytes.Length, new DateTimeOffset(2026, 9, 20, 21, 0, 0, TimeSpan.Zero), "Studio NAS");
|
||||
}
|
||||
|
||||
internal sealed record FakeFrame(Guid Id, string FileName, byte[] Bytes, DateTime? CapturedAt)
|
||||
|
||||
@@ -61,30 +61,83 @@ public sealed class SyncAgentTests(TestContext context)
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task KeepingProxiesOfflineQueuesThemForRemoteSequences()
|
||||
public async Task ATimedOutComparisonIsRecordedAndLiveUpdatesGoOn()
|
||||
{
|
||||
await using var f = await SyncFixture.CreateAsync(context);
|
||||
var photos = f.NewPhotos(1);
|
||||
var local = await f.LocalAsync("Harbour", photos);
|
||||
var remote = f.Remote.Add("Harbour", photos);
|
||||
await f.Sync.LinkAsync(f.Server, remote.Id, local.Id, f.Ct);
|
||||
await using var agent = new SyncAgent(f.Sync, f.Remote, () => new SyncPolicy(), null, EventsOnly);
|
||||
agent.Start();
|
||||
await WaitAsync(() => agent.Snapshot is not null, "first comparison");
|
||||
|
||||
f.Remote.TimeoutOnce = remote.Id;
|
||||
f.Remote.Publish(new SequenceChangedEvent(remote.Id, "settings", remote.FramesVersion, remote.SettingsVersion));
|
||||
await WaitAsync(async () => (await f.EntryAsync("Harbour")).Link!.Error is not null, "the timeout recorded on the sequence");
|
||||
|
||||
f.Remote.EditSettings(remote.Id, SyncFixture.Window33);
|
||||
f.Remote.Publish(new SequenceChangedEvent(remote.Id, "settings", remote.FramesVersion, remote.SettingsVersion));
|
||||
await WaitAsync(async () => SyncRules.SameSettings(SyncFixture.Window33, (await f.Db.Sequences.GetAsync(local.Id, f.Ct))!.SettingsJson),
|
||||
"a later event still reaches this PC");
|
||||
Assert.Null((await f.EntryAsync("Harbour")).Link!.Error);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task KeepingProxiesOfflineRefreshesTheCachesThisPcOpened()
|
||||
{
|
||||
await using var f = await SyncFixture.CreateAsync(context);
|
||||
var photos = f.NewPhotos(2);
|
||||
var local = await f.LocalAsync("Harbour", photos);
|
||||
await f.Sync.LinkAsync(f.Server, f.Remote.Add("Harbour", photos).Id, local.Id, f.Ct);
|
||||
var remote = f.Remote.Add("Construction cam", f.NewPhotos(2));
|
||||
f.Remote.Add("No proxies yet", f.NewPhotos(1), status: SequenceStatus.ThumbsBuilt);
|
||||
var opened = f.Remote.Add("Construction cam", f.NewPhotos(2));
|
||||
var never = f.Remote.Add("Never opened", f.NewPhotos(1));
|
||||
var engine = await f.StartEngineAsync();
|
||||
await f.RefreshAsync();
|
||||
var first = await f.Sync.EnqueueDownloadAsync(engine, f.Server, opened.Id, "Construction cam", SyncDownloadMode.Proxies, null);
|
||||
await f.Archive.WaitForAsync(first.Id, JobState.Done);
|
||||
opened.AddFrame(f.NewPhotos(1)[0]);
|
||||
var keep = false;
|
||||
await using var agent = new SyncAgent(f.Sync, f.Remote, () => new SyncPolicy(KeepProxiesOffline: keep), engine, EventsOnly);
|
||||
agent.Start();
|
||||
await WaitAsync(() => agent.Snapshot is not null, "first comparison");
|
||||
Assert.Null(f.Sync.OpenRemote(f.Server, remote.Id));
|
||||
Assert.True((await f.EntryAsync("Construction cam")).Link!.ProxiesStale);
|
||||
|
||||
keep = true;
|
||||
await agent.RefreshAsync(f.Ct);
|
||||
await WaitAsync(() => f.Sync.OpenRemote(f.Server, remote.Id) is { CachedCount: 2 }, "proxies of the remote sequence");
|
||||
await WaitAsync(() => f.Sync.OpenRemote(f.Server, opened.Id) is { CachedCount: 3 }, "the stale cache brought up to date");
|
||||
Assert.Null(f.Sync.OpenRemote(f.Server, never.Id));
|
||||
var entries = await f.Sync.ListAsync(f.Server, f.Ct);
|
||||
Assert.Equal(SyncStatus.ProxiesOnly, entries.Single(e => e.Title == "Construction cam").Status);
|
||||
Assert.Equal(SyncStatus.RemoteOnly, entries.Single(e => e.Title == "No proxies yet").Status);
|
||||
Assert.Equal(SyncStatus.RemoteOnly, entries.Single(e => e.Title == "Never opened").Status);
|
||||
Assert.Equal(SyncStatus.InSync, entries.Single(e => e.Title == "Harbour").Status);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AFailedProxyRefreshWaitsForItsBackoff()
|
||||
{
|
||||
await using var f = await SyncFixture.CreateAsync(context);
|
||||
var opened = f.Remote.Add("Construction cam", f.NewPhotos(2));
|
||||
var engine = await f.StartEngineAsync();
|
||||
await f.RefreshAsync();
|
||||
await f.Archive.WaitForAsync((await f.Sync.EnqueueDownloadAsync(engine, f.Server, opened.Id, "Construction cam", SyncDownloadMode.Proxies, null)).Id,
|
||||
JobState.Done);
|
||||
opened.AddFrame(f.NewPhotos(1)[0]);
|
||||
f.Remote.FailAssets = true;
|
||||
await using var agent = new SyncAgent(f.Sync, f.Remote, () => new SyncPolicy(KeepProxiesOffline: true), engine,
|
||||
EventsOnly with { MinBackoff = TimeSpan.FromHours(1), MaxBackoff = TimeSpan.FromHours(2) });
|
||||
agent.Start();
|
||||
await WaitAsync(async () => (await DownloadsAsync(f)).Any(j => j.State == JobState.Failed), "the background refresh failing");
|
||||
|
||||
await agent.RefreshAsync(f.Ct);
|
||||
await agent.RefreshAsync(f.Ct);
|
||||
|
||||
Assert.Equal(2, (await DownloadsAsync(f)).Count);
|
||||
}
|
||||
|
||||
private static async Task<IReadOnlyList<Job>> DownloadsAsync(SyncFixture f) =>
|
||||
(await f.Db.Jobs.ListAsync(null, JobKind.Download, 100, null, f.Ct)).Items;
|
||||
|
||||
private async Task WaitAsync(Func<bool> condition, string what) => await WaitAsync(() => Task.FromResult(condition()), what);
|
||||
|
||||
private async Task WaitAsync(Func<Task<bool>> condition, string what)
|
||||
|
||||
@@ -79,19 +79,17 @@ public sealed class SyncRulesTests
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void MetadataMergeUnitesTagsAndTakesTheRestFromTheNewerSide()
|
||||
public void PayloadDifferencesListTheSequenceFieldsBeforeTheSettings()
|
||||
{
|
||||
var mine = new SyncPayload("Harbour", ["sunset", "Harbour"], 3, "mine", SyncFixture.Window41);
|
||||
var theirs = new SyncPayload("Harbour at dusk", ["harbour", "boats"], 5, null, SyncFixture.Window41);
|
||||
var theirs = new SyncPayload("Harbour at dusk", ["harbour", "SUNSET"], 3, " mine ", SyncFixture.Window33);
|
||||
|
||||
var newerHere = SyncRules.Merge(mine, theirs, localIsNewer: true);
|
||||
Assert.Equal("Harbour", newerHere.Title);
|
||||
Assert.Equal(3, newerHere.Rating);
|
||||
Assert.SequenceEqual(["sunset", "Harbour", "boats"], newerHere.Tags);
|
||||
var differences = SyncRules.Differences(mine, theirs, 10);
|
||||
|
||||
var newerThere = SyncRules.Merge(mine, theirs, localIsNewer: false);
|
||||
Assert.Equal("Harbour at dusk", newerThere.Title);
|
||||
Assert.Null(newerThere.Notes);
|
||||
Assert.True(newerThere.SameMetadata(newerThere with { Tags = ["BOATS", "harbour", "SUNSET"] }), "tags ignore case and order");
|
||||
Assert.SequenceEqual(["sequence.title", "exposure.deflickerWindow.manual"], differences.Select(d => d.Path));
|
||||
Assert.Equal(("Harbour", "Harbour at dusk"), (differences[0].Mine, differences[0].Theirs));
|
||||
Assert.Count(1, SyncRules.Differences(mine, theirs, 1));
|
||||
Assert.True(mine.SameMetadata(mine with { Tags = ["HARBOUR", "sunset"], Notes = "mine " }), "tags ignore case and order, blanks are trimmed");
|
||||
Assert.Empty(SyncRules.Differences(mine, mine with { Tags = ["harbour", "SUNSET"] }));
|
||||
}
|
||||
}
|
||||
@@ -109,13 +109,13 @@ public sealed class SyncServiceTests(TestContext context)
|
||||
Assert.Equal(SyncStatus.LocalAhead, (await f.EntryAsync("Harbour")).Status);
|
||||
Assert.Null(remote.SettingsJson);
|
||||
|
||||
await f.Sync.SyncSettingsAsync(f.Remote, remote.Id, f.Ct);
|
||||
await f.Sync.SyncSettingsAsync(f.Remote, remote.Id, new SyncPolicy(AutoSyncSettings: false), f.Ct);
|
||||
Assert.True(SyncRules.SameSettings(SyncFixture.Window41, remote.SettingsJson));
|
||||
Assert.Equal(SyncStatus.InSync, (await f.EntryAsync("Harbour")).Status);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task OnlyMetadataChangedOnBothSidesIsMergedWithoutAConflict()
|
||||
public async Task TagsChangedDifferentlyOnBothSidesAreAConflictToo()
|
||||
{
|
||||
await using var f = await SyncFixture.CreateAsync(context);
|
||||
var photos = f.NewPhotos(1);
|
||||
@@ -124,17 +124,35 @@ public sealed class SyncServiceTests(TestContext context)
|
||||
await f.Sync.LinkAsync(f.Server, remote.Id, local.Id, f.Ct);
|
||||
await f.RefreshAsync();
|
||||
|
||||
// The server is edited first, so this PC's later title and rating win; tags are united.
|
||||
await f.Remote.UpdateSequenceAsync(remote.Id, new UpdateSequenceRequest(null, ["boats"], 2, null, null, null), f.Ct);
|
||||
await Task.Delay(20, f.Ct);
|
||||
await f.Archive.Service.SetSequenceInfoAsync(local.Id, "Harbour", ["sunset"], 4, null, f.Ct);
|
||||
await f.Remote.UpdateSequenceAsync(remote.Id, new UpdateSequenceRequest(null, ["boats"], null, null, null, null), f.Ct);
|
||||
await f.Archive.Service.SetSequenceInfoAsync(local.Id, "Harbour", ["sunset"], 0, null, f.Ct);
|
||||
await f.RefreshAsync();
|
||||
|
||||
// No side wins silently: a tag removed on one side must not come back, and an edit must not be lost.
|
||||
var entry = await f.EntryAsync("Harbour");
|
||||
Assert.Equal(SyncStatus.Conflict, entry.Status);
|
||||
Assert.SequenceEqual(["boats"], entry.Link!.ConflictRemote!.Tags);
|
||||
Assert.Equal("sequence.tags", SyncRules.Differences(SyncPayload.Of(entry.Local!), entry.Link.ConflictRemote)[0].Path);
|
||||
Assert.SequenceEqual(["boats"], remote.Tags);
|
||||
Assert.SequenceEqual(["sunset"], (await f.Db.Sequences.GetAsync(local.Id, f.Ct))!.Tags);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TheSameEditOnBothSidesIsAgreedWithoutAConflict()
|
||||
{
|
||||
await using var f = await SyncFixture.CreateAsync(context);
|
||||
var photos = f.NewPhotos(1);
|
||||
var local = await f.LocalAsync("Harbour", photos);
|
||||
var remote = f.Remote.Add("Harbour", photos);
|
||||
await f.Sync.LinkAsync(f.Server, remote.Id, local.Id, f.Ct);
|
||||
await f.RefreshAsync();
|
||||
|
||||
await f.Remote.UpdateSequenceAsync(remote.Id, new UpdateSequenceRequest(null, ["sunset"], null, null, SyncFixture.Window41, null), f.Ct);
|
||||
await f.Archive.Service.SetSequenceInfoAsync(local.Id, "Harbour", ["SUNSET"], 0, null, f.Ct);
|
||||
await f.EditLocalSettingsAsync(local.Id, SyncFixture.Window41);
|
||||
await f.RefreshAsync();
|
||||
|
||||
Assert.Equal(SyncStatus.InSync, (await f.EntryAsync("Harbour")).Status);
|
||||
var merged = (await f.Db.Sequences.GetAsync(local.Id, f.Ct))!;
|
||||
Assert.True(merged.Tags.ToHashSet().SetEquals(["sunset", "boats"]), string.Join(",", merged.Tags));
|
||||
Assert.True(remote.Tags.ToHashSet().SetEquals(["sunset", "boats"]), string.Join(",", remote.Tags));
|
||||
Assert.Equal(4, remote.Rating);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -146,8 +164,8 @@ public sealed class SyncServiceTests(TestContext context)
|
||||
var entry = await f.EntryAsync("Holy grail");
|
||||
Assert.Equal(SyncStatus.Conflict, entry.Status);
|
||||
Assert.Equal(SyncState.Conflict, entry.Local!.SyncState);
|
||||
Assert.True(SyncRules.SameSettings(SyncFixture.Window33, entry.Link!.ConflictSettingsJson), "the server's side is kept for display");
|
||||
Assert.Equal("exposure.deflickerWindow.manual", SyncRules.Differences(entry.Local.SettingsJson, entry.Link.ConflictSettingsJson)[0].Path);
|
||||
Assert.True(SyncRules.SameSettings(SyncFixture.Window33, entry.Link!.ConflictRemote!.SettingsJson), "the server's side is kept for display");
|
||||
Assert.Equal("exposure.deflickerWindow.manual", SyncRules.Differences(entry.Local.SettingsJson, entry.Link.ConflictRemote.SettingsJson)[0].Path);
|
||||
|
||||
// Neither side is overwritten while the conflict stands, and the comparison does not fetch it again.
|
||||
var manifests = f.Remote.ManifestCalls;
|
||||
@@ -184,7 +202,7 @@ public sealed class SyncServiceTests(TestContext context)
|
||||
Assert.True(SyncRules.SameSettings(SyncFixture.Window33, taken.SettingsJson));
|
||||
Assert.True(SyncRules.SameSettings(SyncFixture.Window33, await File.ReadAllTextAsync(f.Archive.Paths.Sequence(taken.Folder).ProjectPath, f.Ct)));
|
||||
Assert.True(SyncRules.SameSettings(SyncFixture.Window33, remote.SettingsJson));
|
||||
Assert.Empty(Directory.GetFiles(f.Archive.Paths.Sequence(taken.Folder).MetaDirectory, "project.local-*.json"));
|
||||
Assert.Empty(Directory.GetFiles(f.Archive.Paths.Sequence(taken.Folder).MetaDirectory, "project.this-pc-*.json"));
|
||||
Assert.Equal(SyncStatus.InSync, (await f.EntryAsync("Holy grail")).Status);
|
||||
}
|
||||
|
||||
@@ -194,25 +212,74 @@ public sealed class SyncServiceTests(TestContext context)
|
||||
await using var f = await SyncFixture.CreateAsync(context);
|
||||
var (local, remote) = await ConflictAsync(f);
|
||||
|
||||
await f.Sync.ResolveAsync(f.Remote, remote.Id, SyncResolution.SaveBoth, f.Ct);
|
||||
var copy = await f.Sync.ResolveAsync(f.Remote, remote.Id, SyncResolution.SaveBoth, f.Ct);
|
||||
|
||||
var taken = (await f.Db.Sequences.GetAsync(local.Id, f.Ct))!;
|
||||
Assert.True(SyncRules.SameSettings(SyncFixture.Window33, taken.SettingsJson));
|
||||
var copy = Assert.Contains(Directory.GetFiles(f.Archive.Paths.Sequence(taken.Folder).MetaDirectory, "project.local-*.json"), _ => true);
|
||||
Assert.True(SyncRules.SameSettings(SyncFixture.Window41, await File.ReadAllTextAsync(copy, f.Ct)), "this PC's version is kept");
|
||||
Assert.Equal(copy, Assert.Contains(Directory.GetFiles(f.Archive.Paths.Sequence(taken.Folder).MetaDirectory, "project.this-pc-*.json"), _ => true));
|
||||
Assert.True(SyncRules.SameSettings(SyncFixture.Window41, await File.ReadAllTextAsync(copy!, f.Ct)), "this PC's version is kept");
|
||||
Assert.Equal(SyncStatus.InSync, (await f.EntryAsync("Holy grail")).Status);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task KeepMineRefusesWhenTheServerChangedAgainMeanwhile()
|
||||
public async Task KeepMineRefusesWhenTheServerChangedAfterTheConflictWasShown()
|
||||
{
|
||||
await using var f = await SyncFixture.CreateAsync(context);
|
||||
var (_, remote) = await ConflictAsync(f);
|
||||
var racing = new RacingRemote(f.Remote, () => f.Remote.EditSettings(remote.Id, SyncFixture.Window33.Replace("33", "35", StringComparison.Ordinal)));
|
||||
var later = SyncFixture.Window33.Replace("33", "35", StringComparison.Ordinal);
|
||||
f.Remote.EditSettings(remote.Id, later);
|
||||
|
||||
var error = await Assert.ThrowsAsync<TitanoApiException>(() => f.Sync.ResolveAsync(racing, remote.Id, SyncResolution.KeepMine, f.Ct));
|
||||
Assert.Equal(System.Net.HttpStatusCode.Conflict, error.Status);
|
||||
Assert.True(SyncRules.SameSettings(SyncFixture.Window33.Replace("33", "35", StringComparison.Ordinal), remote.SettingsJson), "nothing overwritten");
|
||||
await Assert.ThrowsAsync<SyncConflictChangedException>(() => f.Sync.ResolveAsync(f.Remote, remote.Id, SyncResolution.KeepMine, f.Ct));
|
||||
|
||||
Assert.True(SyncRules.SameSettings(later, remote.SettingsJson), "the edit the user never saw is not overwritten");
|
||||
var entry = await f.EntryAsync("Holy grail");
|
||||
Assert.Equal(SyncStatus.Conflict, entry.Status);
|
||||
Assert.True(SyncRules.SameSettings(later, entry.Link!.ConflictRemote!.SettingsJson), "the conflict now shows the server's latest edit");
|
||||
await f.Sync.ResolveAsync(f.Remote, remote.Id, SyncResolution.KeepMine, f.Ct);
|
||||
Assert.True(SyncRules.SameSettings(SyncFixture.Window41, remote.SettingsJson));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task KeepMineRefusesWhenTheServerChangesWhileItIsSent()
|
||||
{
|
||||
await using var f = await SyncFixture.CreateAsync(context);
|
||||
var (_, remote) = await ConflictAsync(f);
|
||||
var later = SyncFixture.Window33.Replace("33", "35", StringComparison.Ordinal);
|
||||
var racing = new RacingRemote(f.Remote, () => f.Remote.EditSettings(remote.Id, later), beforeUpdate: true);
|
||||
|
||||
await Assert.ThrowsAsync<SyncConflictChangedException>(() => f.Sync.ResolveAsync(racing, remote.Id, SyncResolution.KeepMine, f.Ct));
|
||||
Assert.True(SyncRules.SameSettings(later, remote.SettingsJson), "nothing overwritten");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TakeServerRefusesWhenThisPcChangedAfterTheConflictWasShown()
|
||||
{
|
||||
await using var f = await SyncFixture.CreateAsync(context);
|
||||
var (local, remote) = await ConflictAsync(f);
|
||||
var later = SyncFixture.Window41.Replace("41", "45", StringComparison.Ordinal);
|
||||
await f.EditLocalSettingsAsync(local.Id, later);
|
||||
|
||||
await Assert.ThrowsAsync<SyncConflictChangedException>(() => f.Sync.ResolveAsync(f.Remote, remote.Id, SyncResolution.TakeServer, f.Ct));
|
||||
|
||||
Assert.True(SyncRules.SameSettings(later, (await f.Db.Sequences.GetAsync(local.Id, f.Ct))!.SettingsJson), "this PC's later edit is kept");
|
||||
Assert.True(SyncRules.SameSettings(SyncFixture.Window33, remote.SettingsJson));
|
||||
var entry = await f.EntryAsync("Holy grail");
|
||||
Assert.Equal(SyncStatus.Conflict, entry.Status);
|
||||
Assert.Equal(entry.Local!.SettingsVersion, entry.Link!.ConflictLocalSettings);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TakeServerRefusesWhenTheServerChangedAfterTheConflictWasShown()
|
||||
{
|
||||
await using var f = await SyncFixture.CreateAsync(context);
|
||||
var (local, remote) = await ConflictAsync(f);
|
||||
f.Remote.EditSettings(remote.Id, SyncFixture.Window33.Replace("33", "35", StringComparison.Ordinal));
|
||||
|
||||
await Assert.ThrowsAsync<SyncConflictChangedException>(() => f.Sync.ResolveAsync(f.Remote, remote.Id, SyncResolution.SaveBoth, f.Ct));
|
||||
|
||||
var kept = (await f.Db.Sequences.GetAsync(local.Id, f.Ct))!;
|
||||
Assert.True(SyncRules.SameSettings(SyncFixture.Window41, kept.SettingsJson), "nothing taken that the user did not see");
|
||||
Assert.Empty(Directory.GetFiles(f.Archive.Paths.Sequence(kept.Folder).MetaDirectory, "project.this-pc-*.json"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -234,6 +301,121 @@ public sealed class SyncServiceTests(TestContext context)
|
||||
Assert.Equal(SyncState.LocalOnly, (await f.Db.Sequences.GetAsync(local.Id, f.Ct))!.SyncState);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ALinkIsForgottenOnlyWhenTheServerSaysTheSequenceIsGone()
|
||||
{
|
||||
await using var f = await SyncFixture.CreateAsync(context);
|
||||
var photos = f.NewPhotos(2);
|
||||
var local = await f.LocalAsync("Harbour", photos);
|
||||
var remote = f.Remote.Add("Harbour", photos);
|
||||
await f.Sync.LinkAsync(f.Server, remote.Id, local.Id, f.Ct);
|
||||
await f.RefreshAsync();
|
||||
|
||||
// A listing whose pages moved while they were read misses the sequence: it is asked for by id instead.
|
||||
f.Remote.Unlisted.Add(remote.Id);
|
||||
await f.RefreshAsync();
|
||||
var kept = await f.EntryAsync("Harbour");
|
||||
Assert.Equal(SyncStatus.InSync, kept.Status);
|
||||
Assert.Equal(remote.Id, kept.Link!.RemoteId);
|
||||
|
||||
f.Remote.Sequences.Remove(remote.Id);
|
||||
await f.RefreshAsync();
|
||||
Assert.Equal(SyncStatus.LocalOnly, (await f.EntryAsync("Harbour")).Status);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AServerRefusalOnOneSequenceIsRecordedAndTheOthersAreStillCompared()
|
||||
{
|
||||
await using var f = await SyncFixture.CreateAsync(context);
|
||||
var photos = f.NewPhotos(4);
|
||||
var harbour = await f.LocalAsync("Harbour", photos[..2]);
|
||||
var aurora = await f.LocalAsync("Aurora", photos[2..]);
|
||||
var refused = f.Remote.Add("Harbour", photos[..2]);
|
||||
var fine = f.Remote.Add("Aurora", photos[2..]);
|
||||
await f.Sync.LinkAsync(f.Server, refused.Id, harbour.Id, f.Ct);
|
||||
await f.Sync.LinkAsync(f.Server, fine.Id, aurora.Id, f.Ct);
|
||||
f.Remote.Refused.Add(refused.Id);
|
||||
|
||||
await f.RefreshAsync();
|
||||
|
||||
Assert.NotNull((await f.EntryAsync("Harbour")).Link!.Error);
|
||||
var compared = await f.EntryAsync("Aurora");
|
||||
Assert.Equal(SyncStatus.InSync, compared.Status);
|
||||
Assert.Null(compared.Link!.Error);
|
||||
|
||||
f.Remote.Refused.Clear();
|
||||
await f.RefreshAsync();
|
||||
var recovered = await f.EntryAsync("Harbour");
|
||||
Assert.Null(recovered.Link!.Error);
|
||||
Assert.Equal(SyncStatus.InSync, recovered.Status);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task WithoutTheEditRightThisPcsEditsWaitInsteadOfFailing()
|
||||
{
|
||||
await using var f = await SyncFixture.CreateAsync(context);
|
||||
var photos = f.NewPhotos(1);
|
||||
var local = await f.LocalAsync("Harbour", photos);
|
||||
var remote = f.Remote.Add("Harbour", photos);
|
||||
await f.Sync.LinkAsync(f.Server, remote.Id, local.Id, f.Ct);
|
||||
await f.RefreshAsync();
|
||||
|
||||
await f.EditLocalSettingsAsync(local.Id, SyncFixture.Window41);
|
||||
await f.RefreshAsync(new SyncPolicy(CanEdit: false));
|
||||
|
||||
Assert.Null(remote.SettingsJson);
|
||||
var entry = await f.EntryAsync("Harbour");
|
||||
Assert.Equal(SyncStatus.LocalAhead, entry.Status);
|
||||
Assert.Null(entry.Link!.Error);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task CopiesHoldingTheSameOriginalsAreLinkedByContent()
|
||||
{
|
||||
await using var f = await SyncFixture.CreateAsync(context);
|
||||
var photos = f.NewPhotos(3);
|
||||
var local = await f.LocalAsync("Comet", photos);
|
||||
// The Uploader sent the same card to the server; nothing links the two yet.
|
||||
var remote = f.Remote.Add("2026-09-28 Canon", photos);
|
||||
remote.FirstCapture = local.FirstCapture;
|
||||
remote.CameraModel = local.CameraModel;
|
||||
var other = f.Remote.Add("Other card", f.NewPhotos(2));
|
||||
other.FirstCapture = local.FirstCapture;
|
||||
other.CameraModel = local.CameraModel;
|
||||
|
||||
await f.RefreshAsync();
|
||||
|
||||
var entry = await f.EntryAsync("Comet");
|
||||
Assert.Equal(remote.Id, entry.Link?.RemoteId);
|
||||
Assert.Equal((0, 0), (entry.Link!.MissingRemote, entry.Link.MissingLocal));
|
||||
Assert.Null((await f.EntryAsync("Other card")).Local);
|
||||
var manifests = f.Remote.ManifestCalls;
|
||||
await f.RefreshAsync();
|
||||
Assert.Equal(manifests, f.Remote.ManifestCalls);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ABackgroundProxyDownloadGivesWayToTheUsersRequest()
|
||||
{
|
||||
await using var f = await SyncFixture.CreateAsync(context);
|
||||
var remote = f.Remote.Add("Construction cam", f.NewPhotos(1));
|
||||
await f.RefreshAsync();
|
||||
await using var engine = new Titano.Data.Jobs.JobEngine(f.Db, f.Sync.CreateJobHandlers(new SyncFixture.Connector(f.Remote)));
|
||||
|
||||
var background = await f.Sync.EnqueueDownloadAsync(engine, f.Server, remote.Id, "Construction cam", SyncDownloadMode.Proxies, null, JobPriority.Background);
|
||||
Assert.Equal(background.Id, (await f.Sync.EnqueueDownloadAsync(engine, f.Server, remote.Id, "Construction cam", SyncDownloadMode.Proxies, null,
|
||||
JobPriority.Background)).Id);
|
||||
var opened = await f.Sync.EnqueueDownloadAsync(engine, f.Server, remote.Id, "Construction cam", SyncDownloadMode.Proxies, null);
|
||||
Assert.NotEqual(background.Id, opened.Id);
|
||||
Assert.Equal(JobPriority.User, opened.Priority);
|
||||
Assert.Equal(JobState.Cancelled, (await f.Db.Jobs.GetAsync(background.Id, f.Ct))!.State);
|
||||
|
||||
var originals = await f.Sync.EnqueueDownloadAsync(engine, f.Server, remote.Id, "Construction cam", SyncDownloadMode.Originals, f.Archive.Archive.Id);
|
||||
Assert.NotEqual(opened.Id, originals.Id);
|
||||
Assert.Equal(SyncTransferKind.DownloadOriginals, SyncService.TransferKind(originals));
|
||||
Assert.Equal(originals.Id, (await f.EntryAsync("Construction cam")).Transfer!.Id);
|
||||
}
|
||||
|
||||
/// <summary>A linked sequence whose settings changed differently on both sides since they last agreed (41 here, 33 on the server).</summary>
|
||||
private static async Task<(Sequence Local, FakeSequence Remote)> ConflictAsync(SyncFixture f)
|
||||
{
|
||||
@@ -250,8 +432,8 @@ public sealed class SyncServiceTests(TestContext context)
|
||||
return (local, remote);
|
||||
}
|
||||
|
||||
/// <summary>A remote where someone else edits the settings right after the first read of a sequence.</summary>
|
||||
private sealed class RacingRemote(FakeSyncRemote inner, Action race) : ISyncRemote
|
||||
/// <summary>A remote where someone else edits the settings right after the first read of a sequence, or right before the first edit.</summary>
|
||||
private sealed class RacingRemote(FakeSyncRemote inner, Action race, bool beforeUpdate = false) : ISyncRemote
|
||||
{
|
||||
private Action? _race = race;
|
||||
|
||||
@@ -260,14 +442,18 @@ public sealed class SyncServiceTests(TestContext context)
|
||||
public async Task<SequenceDto> GetSequenceAsync(Guid id, CancellationToken cancellationToken)
|
||||
{
|
||||
var dto = await inner.GetSequenceAsync(id, cancellationToken);
|
||||
Interlocked.Exchange(ref _race, null)?.Invoke();
|
||||
if (!beforeUpdate) Interlocked.Exchange(ref _race, null)?.Invoke();
|
||||
return dto;
|
||||
}
|
||||
|
||||
public Task<IReadOnlyList<SequenceDto>> ListSequencesAsync(CancellationToken cancellationToken) => inner.ListSequencesAsync(cancellationToken);
|
||||
public Task<SequenceManifest> GetManifestAsync(Guid id, CancellationToken cancellationToken) => inner.GetManifestAsync(id, cancellationToken);
|
||||
public Task<IReadOnlyList<FrameDto>> ListFramesAsync(Guid sequenceId, CancellationToken cancellationToken) => inner.ListFramesAsync(sequenceId, cancellationToken);
|
||||
public Task<SequenceDto> UpdateSequenceAsync(Guid id, UpdateSequenceRequest request, CancellationToken cancellationToken) => inner.UpdateSequenceAsync(id, request, cancellationToken);
|
||||
public Task<SequenceDto> UpdateSequenceAsync(Guid id, UpdateSequenceRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
if (beforeUpdate) Interlocked.Exchange(ref _race, null)?.Invoke();
|
||||
return inner.UpdateSequenceAsync(id, request, cancellationToken);
|
||||
}
|
||||
|
||||
public Task<CompleteUploadResponse?> UploadFileAsync(string path, Guid? sequenceId, string? sessionKey, string sha256, DateTime? capturedAt,
|
||||
CancellationToken cancellationToken) =>
|
||||
@@ -276,6 +462,12 @@ public sealed class SyncServiceTests(TestContext context)
|
||||
public Task DownloadFrameAsync(Guid frameId, string kind, Stream destination, CancellationToken cancellationToken) =>
|
||||
inner.DownloadFrameAsync(frameId, kind, destination, cancellationToken);
|
||||
|
||||
public Task<string?> DownloadRenderAsync(Guid renderId, Stream destination, CancellationToken cancellationToken) =>
|
||||
inner.DownloadRenderAsync(renderId, destination, cancellationToken);
|
||||
|
||||
public Task<RenderDto?> UploadRenderAsync(Guid sequenceId, string path, RenderUploadRequest request, CancellationToken cancellationToken) =>
|
||||
inner.UploadRenderAsync(sequenceId, path, request, cancellationToken);
|
||||
|
||||
public IAsyncEnumerable<ServerEvent> EventsAsync(CancellationToken cancellationToken) => inner.EventsAsync(cancellationToken);
|
||||
|
||||
public void Dispose()
|
||||
|
||||
@@ -113,6 +113,7 @@ public sealed class SyncTransferTests(TestContext context)
|
||||
var local = await f.LocalAsync("Harbour", photos[..1], SyncFixture.Window41);
|
||||
var remote = f.Remote.Add("Harbour", photos);
|
||||
await f.Sync.LinkAsync(f.Server, remote.Id, local.Id, f.Ct);
|
||||
await f.RefreshAsync();
|
||||
await f.Sync.ResolveAsync(f.Remote, remote.Id, SyncResolution.KeepMine, f.Ct);
|
||||
var engine = await f.StartEngineAsync();
|
||||
|
||||
@@ -126,6 +127,115 @@ public sealed class SyncTransferTests(TestContext context)
|
||||
Assert.True(SyncRules.SameSettings(SyncFixture.Window41, entry.Local.SettingsJson), "an existing copy keeps its settings");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task DownloadingIntoAnUnverifiedCopyHashesItFirstAndFetchesOnlyWhatItLacks()
|
||||
{
|
||||
await using var f = await SyncFixture.CreateAsync(context);
|
||||
var photos = f.NewPhotos(5);
|
||||
// An adopted folder: indexed by a scan, never verified, so its frames have no hash yet.
|
||||
var folder = Path.Combine(f.Archive.Paths.Root, "Adopted");
|
||||
Directory.CreateDirectory(folder);
|
||||
for (var i = 0; i < 3; i++) await File.WriteAllBytesAsync(Path.Combine(folder, $"IMG_{i + 1:0000}.JPG"), photos[i], f.Ct);
|
||||
await f.Archive.ScanAsync();
|
||||
var local = Assert.Contains((await f.Db.Sequences.ListAsync(new Titano.Data.Repositories.SequenceQuery(), f.Ct)).Items, s => s.Folder == "Adopted");
|
||||
Assert.True((await f.Db.Frames.ListBySequenceAsync(local.Id, cancellationToken: f.Ct)).All(fr => fr.Sha256 is null), "adopted frames are unhashed");
|
||||
var remote = f.Remote.Add("Adopted", photos);
|
||||
await f.Sync.LinkAsync(f.Server, remote.Id, local.Id, f.Ct);
|
||||
await f.RefreshAsync();
|
||||
Assert.Equal(2, (await f.EntryAsync(local.DisplayTitle)).Link!.MissingLocal);
|
||||
var engine = await f.StartEngineAsync();
|
||||
|
||||
var job = await f.Sync.EnqueueDownloadAsync(engine, f.Server, remote.Id, "Adopted", SyncDownloadMode.Originals, null);
|
||||
await f.Archive.WaitForAsync(job.Id, JobState.Done);
|
||||
|
||||
var frames = await f.Db.Frames.ListBySequenceAsync(local.Id, cancellationToken: f.Ct);
|
||||
Assert.Equal(5, frames.Count);
|
||||
Assert.True(frames.Select(fr => fr.Sha256).ToHashSet().SetEquals(photos.Select(Sha)), "no original arrived twice");
|
||||
Assert.Equal(SyncStatus.InSync, (await f.EntryAsync(local.DisplayTitle)).Status);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task DownloadingOriginalsRestoresTheOnesMissingHere()
|
||||
{
|
||||
await using var f = await SyncFixture.CreateAsync(context);
|
||||
var photos = f.NewPhotos(3);
|
||||
var local = await f.LocalAsync("Harbour", photos);
|
||||
var lost = (await f.Db.Frames.ListBySequenceAsync(local.Id, cancellationToken: f.Ct))[1];
|
||||
var place = f.Archive.Paths.FromRelative(lost.RelativePath);
|
||||
File.Delete(place);
|
||||
await f.Archive.Service.Verifier.VerifyAsync(f.Archive.Archive, [local.Id], default, (_, _, _) => ValueTask.CompletedTask, cancellationToken: f.Ct);
|
||||
var remote = f.Remote.Add("Harbour", photos);
|
||||
await f.Sync.LinkAsync(f.Server, remote.Id, local.Id, f.Ct);
|
||||
await f.RefreshAsync();
|
||||
var behind = await f.EntryAsync("Harbour");
|
||||
Assert.Equal((SyncStatus.ServerAhead, 1), (behind.Status, behind.Link!.MissingLocal));
|
||||
var engine = await f.StartEngineAsync();
|
||||
|
||||
var job = await f.Sync.EnqueueDownloadAsync(engine, f.Server, remote.Id, "Harbour", SyncDownloadMode.Originals, null);
|
||||
await f.Archive.WaitForAsync(job.Id, JobState.Done);
|
||||
|
||||
Assert.Equal(lost.Sha256, Sha(await File.ReadAllBytesAsync(place, f.Ct)));
|
||||
var frames = await f.Db.Frames.ListBySequenceAsync(local.Id, cancellationToken: f.Ct);
|
||||
Assert.Equal(3, frames.Count);
|
||||
Assert.True(frames.All(fr => (fr.Flags & FrameFlags.Missing) == 0), "the restored original is no longer missing");
|
||||
Assert.Equal(SyncStatus.InSync, (await f.EntryAsync("Harbour")).Status);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TheServersRendersAreFetchedIntoTheLocalExports()
|
||||
{
|
||||
await using var f = await SyncFixture.CreateAsync(context);
|
||||
var photos = f.NewPhotos(2);
|
||||
var local = await f.LocalAsync("Star trails", photos);
|
||||
var remote = f.Remote.Add("Star trails", photos);
|
||||
var render = new FakeRender(Guid.CreateVersion7(), "Star trails 4K.mp4", "4K HEVC", [.. Enumerable.Range(0, 5000).Select(i => (byte)i)]);
|
||||
remote.Renders.Add(render);
|
||||
await f.Sync.LinkAsync(f.Server, remote.Id, local.Id, f.Ct);
|
||||
await f.RefreshAsync();
|
||||
var entry = await f.EntryAsync("Star trails");
|
||||
Assert.Equal((SyncStatus.InSync, 1, 5000L), (entry.Status, entry.Link!.ExportsToGet, entry.Link.ExportsToGetBytes));
|
||||
var engine = await f.StartEngineAsync();
|
||||
|
||||
var job = await f.Sync.EnqueueDownloadAsync(engine, f.Server, remote.Id, "Star trails", SyncDownloadMode.Exports, null);
|
||||
await f.Archive.WaitForAsync(job.Id, JobState.Done);
|
||||
|
||||
var fetched = Assert.Contains(await f.Db.Renders.ListBySequenceAsync(local.Id, f.Ct), r => r.Id == render.Id);
|
||||
Assert.Equal("4K HEVC", fetched.PresetName);
|
||||
var file = f.Archive.Paths.FromRelative(fetched.OutputPath);
|
||||
Assert.Equal(Path.Combine(f.Archive.Paths.Sequence(local.Folder).Exports, "Star trails 4K.mp4"), file);
|
||||
Assert.SequenceEqual(render.Bytes, await File.ReadAllBytesAsync(file, f.Ct));
|
||||
Assert.Equal(0, (await f.EntryAsync("Star trails")).Link!.ExportsToGet);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task RendersMadeHereAreSentOnRequestAndAGoneFileIsReported()
|
||||
{
|
||||
await using var f = await SyncFixture.CreateAsync(context);
|
||||
var photos = f.NewPhotos(2);
|
||||
var local = await f.LocalAsync("Harbour", photos);
|
||||
var remote = f.Remote.Add("Harbour", photos);
|
||||
await f.Sync.LinkAsync(f.Server, remote.Id, local.Id, f.Ct);
|
||||
var exports = f.Archive.Paths.Sequence(local.Folder).Exports;
|
||||
Directory.CreateDirectory(exports);
|
||||
var bytes = Enumerable.Range(0, 3000).Select(i => (byte)(i * 7)).ToArray();
|
||||
await File.WriteAllBytesAsync(Path.Combine(exports, "Harbour 1080p.mp4"), bytes, f.Ct);
|
||||
var made = await AddRenderAsync(f, local, "Harbour 1080p.mp4", bytes.Length);
|
||||
var gone = await AddRenderAsync(f, local, "Harbour draft.mp4", 10);
|
||||
await f.RefreshAsync();
|
||||
Assert.Equal((1, 3000L), ((await f.EntryAsync("Harbour")).Link!.ExportsToSend, (await f.EntryAsync("Harbour")).Link!.ExportsToSendBytes));
|
||||
var engine = await f.StartEngineAsync();
|
||||
|
||||
var job = await f.Sync.EnqueueSendExportsAsync(engine, f.Server, local);
|
||||
Assert.Equal(SyncTransferKind.SendExports, SyncService.TransferKind(job));
|
||||
var failed = await f.Archive.WaitForAsync(job.Id, JobState.Failed);
|
||||
|
||||
Assert.Contains("1", failed.Error);
|
||||
var sent = Assert.Contains(remote.Renders, r => r.Id == made.Id);
|
||||
Assert.SequenceEqual(bytes, sent.Bytes);
|
||||
Assert.DoesNotContain(gone.Id, remote.Renders.Select(r => r.Id));
|
||||
Assert.Equal(0, (await f.EntryAsync("Harbour")).Link!.ExportsToSend);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ProxiesOpenARemoteSequenceForTheEditor()
|
||||
{
|
||||
@@ -192,5 +302,26 @@ public sealed class SyncTransferTests(TestContext context)
|
||||
Assert.Empty(f.Remote.Sequences);
|
||||
}
|
||||
|
||||
private static async Task<Render> AddRenderAsync(SyncFixture f, Sequence local, string name, long bytes)
|
||||
{
|
||||
var render = new Render
|
||||
{
|
||||
Id = Guid.CreateVersion7(),
|
||||
SequenceId = local.Id,
|
||||
PresetName = "1080p H.264",
|
||||
OutputPath = local.Folder + "/exports/" + name,
|
||||
Codec = "h264",
|
||||
Width = 1920,
|
||||
Height = 1080,
|
||||
Fps = 30,
|
||||
DurationSeconds = 10,
|
||||
Bytes = bytes,
|
||||
Created = DateTimeOffset.UtcNow,
|
||||
ProducedBy = "studio",
|
||||
};
|
||||
await f.Db.Renders.InsertAsync(render, f.Ct);
|
||||
return render;
|
||||
}
|
||||
|
||||
private static string Sha(byte[] bytes) => Convert.ToHexStringLower(System.Security.Cryptography.SHA256.HashData(bytes));
|
||||
}
|
||||
@@ -85,6 +85,33 @@ internal sealed class SyncClient : IAsyncDisposable
|
||||
return edited.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);
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in new issue
Block a user