- 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
96 lines
5.3 KiB
C#
96 lines
5.3 KiB
C#
using Titano.Core.Model;
|
|
using Titano.Data.Sync;
|
|
using Titano.Testing;
|
|
|
|
namespace Titano.Data.Tests.Sync;
|
|
|
|
public sealed class SyncRulesTests
|
|
{
|
|
private static readonly Sequence Local = new() { Id = Guid.CreateVersion7(), ArchiveId = Guid.CreateVersion7(), Folder = "2026/a", SettingsVersion = 4 };
|
|
|
|
private static readonly SyncLink Agreed = new()
|
|
{
|
|
Server = "https://nas",
|
|
RemoteId = Guid.CreateVersion7(),
|
|
Title = "Harbour",
|
|
RemoteSettingsVersion = 7,
|
|
BaseLocalSettings = 4,
|
|
BaseRemoteSettings = 7,
|
|
};
|
|
|
|
[Test]
|
|
public void StateFollowsLinksOriginalsAndSettingsVersions()
|
|
{
|
|
Assert.Equal(SyncStatus.LocalOnly, SyncRules.Status(Local, null));
|
|
Assert.Equal(SyncStatus.RemoteOnly, SyncRules.Status(null, Agreed));
|
|
Assert.Equal(SyncStatus.ProxiesOnly, SyncRules.Status(null, Agreed with { ProxiesCached = 3 }));
|
|
Assert.Equal(SyncStatus.InSync, SyncRules.Status(Local, Agreed));
|
|
|
|
Assert.Equal(SyncStatus.LocalAhead, SyncRules.Status(Local, Agreed with { MissingRemote = 2 }));
|
|
Assert.Equal(SyncStatus.LocalAhead, SyncRules.Status(Local with { SettingsVersion = 5 }, Agreed));
|
|
Assert.Equal(SyncStatus.ServerAhead, SyncRules.Status(Local, Agreed with { MissingLocal = 1 }));
|
|
Assert.Equal(SyncStatus.ServerAhead, SyncRules.Status(Local, Agreed with { RemoteSettingsVersion = 8 }));
|
|
// Originals never conflict: what this PC lacks is downloaded after what the server lacks is uploaded.
|
|
Assert.Equal(SyncStatus.LocalAhead, SyncRules.Status(Local, Agreed with { MissingRemote = 1, MissingLocal = 1 }));
|
|
|
|
Assert.Equal(SyncStatus.Conflict, SyncRules.Status(Local with { SettingsVersion = 5 }, Agreed with { RemoteSettingsVersion = 8 }));
|
|
// A link nothing was agreed on yet: both sides count as changed until the content is compared.
|
|
Assert.Equal(SyncStatus.Conflict, SyncRules.Status(Local, Agreed with { BaseLocalSettings = null, BaseRemoteSettings = null }));
|
|
}
|
|
|
|
[Test]
|
|
public void TheLibraryStoresOnlyStatesOfLocalCopies()
|
|
{
|
|
Assert.Equal(SyncState.InSync, SyncRules.ToSequenceState(SyncStatus.InSync));
|
|
Assert.Equal(SyncState.Conflict, SyncRules.ToSequenceState(SyncStatus.Conflict));
|
|
Assert.Equal(SyncState.LocalAhead, SyncRules.ToSequenceState(SyncStatus.LocalAhead));
|
|
Assert.Equal(SyncState.ServerAhead, SyncRules.ToSequenceState(SyncStatus.ServerAhead));
|
|
Assert.Equal(SyncState.LocalOnly, SyncRules.ToSequenceState(SyncStatus.LocalOnly));
|
|
Assert.Null(SyncRules.ToSequenceState(SyncStatus.Transferring));
|
|
Assert.Null(SyncRules.ToSequenceState(SyncStatus.RemoteOnly));
|
|
}
|
|
|
|
[Test]
|
|
public void OriginalsAreComparedByContent()
|
|
{
|
|
Assert.Equal((0, 0), SyncRules.CompareOriginals(["AA", "bb"], ["aa", "BB"]));
|
|
Assert.Equal((1, 0), SyncRules.CompareOriginals(["aa", "bb", "cc"], ["aa", "bb"]));
|
|
Assert.Equal((0, 2), SyncRules.CompareOriginals(["aa"], ["aa", "bb", "cc"]));
|
|
Assert.Equal((1, 1), SyncRules.CompareOriginals(["aa", "dd"], ["aa", "ee"]));
|
|
// Frames not hashed yet (adopted, not verified) stand for server frames no hash matched.
|
|
Assert.Equal((0, 0), SyncRules.CompareOriginals(["aa", null, null], ["aa", "bb", "cc"]));
|
|
Assert.Equal((0, 1), SyncRules.CompareOriginals([null], ["bb", "cc"]));
|
|
Assert.Equal((1, 0), SyncRules.CompareOriginals([null, null], ["bb"]));
|
|
}
|
|
|
|
[Test]
|
|
public void SettingsAreComparedAsProjectsNotAsText()
|
|
{
|
|
Assert.True(SyncRules.SameSettings(null, "{}"), "no settings is the default project");
|
|
Assert.True(SyncRules.SameSettings(SyncFixture.Window41, "{ \"exposure\": { \"deflickerWindow\": { \"manual\": 41, \"isAuto\": false } } }"));
|
|
Assert.False(SyncRules.SameSettings(SyncFixture.Window41, SyncFixture.Window33));
|
|
|
|
var difference = Assert.Contains(SyncRules.Differences(SyncFixture.Window41, SyncFixture.Window33), d => d.Path.StartsWith("exposure.deflickerWindow", StringComparison.Ordinal));
|
|
Assert.Equal("exposure.deflickerWindow.manual", difference.Path);
|
|
Assert.Equal("41", difference.Mine);
|
|
Assert.Equal("33", difference.Theirs);
|
|
Assert.Count(1, SyncRules.Differences("""{"exposure":{"exposureOffsetEv":1},"stack":{"length":3}}""", "{}", max: 1));
|
|
Assert.Empty(SyncRules.Differences(SyncFixture.Window33, SyncFixture.Window33));
|
|
}
|
|
|
|
[Test]
|
|
public void PayloadDifferencesListTheSequenceFieldsBeforeTheSettings()
|
|
{
|
|
var mine = new SyncPayload("Harbour", ["sunset", "Harbour"], 3, "mine", SyncFixture.Window41);
|
|
var theirs = new SyncPayload("Harbour at dusk", ["harbour", "SUNSET"], 3, " mine ", SyncFixture.Window33);
|
|
|
|
var differences = SyncRules.Differences(mine, theirs, 10);
|
|
|
|
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"] }));
|
|
}
|
|
}
|