- A take of the library's values cut past its commit point settles its conflict (replay journal marks Settles); a later stale choice finds nothing to settle, and one cut before it keeps the conflict so the next choice is applied. - A local version that changes nothing once replayed on the head is not sent nor written as a Merge; its file stays in versions/.replaced. - Save both journals its intent (name, base, time) before the home is asked, so a cut after the copy was made reuses that copy on retry. - A project deleted at the home reads as Gone from pull, push, resolve and save both, logged once, without retry loops; versions and working state stay. - Save both keeps the restore recorded in sync.json. - The copy job writes a photo's new bytes under a name of its own while the editor's media still name the old file, switching at the commit; a cancelled first copy removes its own half media under the lease (VM hook removed). - Status reads the version files once, re-reads the home's frames only when its stamp moved, reports damage only when confirmed under the lease, and waits once for a busy lease before calling the media outdated. - versions/.replaced is pruned after a sync that ended well (30 days, newest 20 kept, never a file a journal names). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
408 lines
23 KiB
C#
408 lines
23 KiB
C#
using Chronos.Core.Archiving;
|
|
using Chronos.Core.Model;
|
|
using Chronos.Core.Project;
|
|
using Chronos.Data.Archiving;
|
|
using Chronos.Data.Projects;
|
|
using Chronos.Data.Tests.Archiving;
|
|
using Chronos.Data.Tests.Infrastructure;
|
|
using Chronos.Data.Tests.Projects;
|
|
using Chronos.Data.Workspaces;
|
|
using Chronos.Testing;
|
|
|
|
namespace Chronos.Data.Tests.Workspaces;
|
|
|
|
/// <summary>
|
|
/// What a workspace's sync merges (owner review 2, R8): one photo named alike on every side whatever the home did to it since
|
|
/// the copy (hashed, converted), and settings of a newer Chronos never merged with this one's.
|
|
/// </summary>
|
|
[Category("workspace")]
|
|
public abstract class WorkspaceMergeTests(TestContext context) : DatabaseTest(context)
|
|
{
|
|
private async Task<WorkspaceFixture> FixtureAsync(int frames = 5)
|
|
{
|
|
var archive = Own(await ArchiveFixture.CreateAsync(Context, database: await NewOptionsAsync(multiConnection: true)));
|
|
return Own(await WorkspaceFixture.CreateAsync(Context, archive, frames));
|
|
}
|
|
|
|
private static async Task EditAsync(WorkspaceSync sync, Guid projectId, Func<ProjectSettings, ProjectSettings> edit, CancellationToken ct)
|
|
{
|
|
var session = await sync.OpenAsync(projectId, ct);
|
|
await sync.SaveAsync(projectId, edit(session.Working), ct);
|
|
}
|
|
|
|
/// <summary>The photo at <paramref name="index"/> not hashed at the home, as in a folder adopted and not verified yet: its sidecar, then a full scan.</summary>
|
|
private static async Task UnhashAsync(WorkspaceFixture fx, int index)
|
|
{
|
|
var folder = fx.Archive.Paths.Sequence(fx.Sequence.Folder);
|
|
var manifest = ManifestStore.ReadSequence(folder.ManifestPath);
|
|
ManifestStore.WriteSequence(folder.ManifestPath, manifest with { Frames = [.. manifest.Frames.Select((f, i) => i == index ? f with { Sha256 = null } : f)] });
|
|
await fx.Archive.ScanAsync(ScanMode.Full);
|
|
Assert.Null((await fx.Db.Frames.ListBySequenceAsync(fx.Sequence.Id))[index].Sha256);
|
|
}
|
|
|
|
/// <summary>The archive verified: the photos not hashed yet are hashed (the frames version stays, so no Update media is offered).</summary>
|
|
private static async Task VerifyAsync(WorkspaceFixture fx)
|
|
{
|
|
var before = (await fx.Db.Sequences.GetAsync(fx.Sequence.Id))!.FramesVersion;
|
|
await fx.Archive.Service.Verifier.VerifyAsync(fx.Archive.Archive, null, default, (_, _, _) => ValueTask.CompletedTask, null, fx.Ct);
|
|
Assert.Equal(before, (await fx.Db.Sequences.GetAsync(fx.Sequence.Id))!.FramesVersion);
|
|
}
|
|
|
|
/// <summary>The sequence's settings changed at the home by another path (an analysis): Main takes them as an external version, its photos named as the home's frames hold them.</summary>
|
|
private static async Task WriteAtHomeAsync(WorkspaceFixture fx, Func<ProjectSettings, ProjectSettings> edit)
|
|
{
|
|
var row = (await fx.Db.Sequences.GetAsync(fx.Sequence.Id))!;
|
|
await ProjectServiceTests.WriteSettingsAsync(fx.Archive, fx.Sequence.Id, edit(ProjectSettings.FromJson(row.SettingsJson!)));
|
|
}
|
|
|
|
private static async Task<ProjectSettings> SequenceSettingsAsync(WorkspaceFixture fx) =>
|
|
ProjectSettings.FromJson((await fx.Db.Sequences.GetAsync(fx.Sequence.Id))!.SettingsJson!);
|
|
|
|
[Test]
|
|
public async Task AnEditSurvivesAPullOnceTheHomeHashedAPhotoTheCopyHadNot()
|
|
{
|
|
var fx = await FixtureAsync();
|
|
await UnhashAsync(fx, 2);
|
|
var (_, sync) = fx.Workspace();
|
|
var project = await fx.CheckoutAsync(sync);
|
|
var id = project.ProjectId;
|
|
var copied = project.ReadMedia()!;
|
|
Assert.Null(copied.Frames[2].Sha256);
|
|
await EditAsync(sync, id, s => s with { ExcludedFrames = [2] }, fx.Ct);
|
|
await sync.CommitAsync(id, cancellationToken: fx.Ct);
|
|
await sync.PushAsync(id, fx.Home, fx.Ct);
|
|
|
|
// The home hashes the photo, then an analysis writes the settings: Main's new version names the photo by its hash.
|
|
await VerifyAsync(fx);
|
|
var hashed = (await fx.Db.Frames.ListBySequenceAsync(fx.Sequence.Id))[2].Sha256!;
|
|
await WriteAtHomeAsync(fx, s => s with { Exposure = s.Exposure with { ExposureOffsetEv = 0.7 } });
|
|
Assert.Contains(hashed, (await fx.Home.HeadAsync(id, fx.Ct)).SettingsJson);
|
|
|
|
// Photo 2 brought back here: the pull takes the analysis's value and keeps the photo in, with nothing to settle.
|
|
await EditAsync(sync, id, s => s with { ExcludedFrames = [] }, fx.Ct);
|
|
var pulled = await sync.PullAsync(id, fx.Home, fx.Ct);
|
|
Assert.Null(pulled.Status.Conflict);
|
|
Assert.Equal(WorkspaceState.Modified, pulled.Status.State);
|
|
var working = (await sync.OpenAsync(id, fx.Ct)).Working;
|
|
Assert.Equal(0.7, working.Exposure.ExposureOffsetEv);
|
|
Assert.Empty(working.ExcludedFrames);
|
|
// The media learnt the hash: the frames and their files are as they were copied.
|
|
var media = project.ReadMedia()!;
|
|
Assert.Equal(hashed, media.Frames[2].Sha256);
|
|
Assert.Equal(copied.FramesVersion, media.FramesVersion);
|
|
Assert.SequenceEqual(copied.Frames.Select(f => f.FileSha256), media.Frames.Select(f => f.FileSha256));
|
|
|
|
Assert.NotNull(await sync.CommitAsync(id, cancellationToken: fx.Ct));
|
|
Assert.Equal(WorkspaceState.InSync, (await sync.PushAsync(id, fx.Home, fx.Ct)).Status.State);
|
|
var settings = await SequenceSettingsAsync(fx);
|
|
Assert.Empty(settings.ExcludedFrames);
|
|
Assert.Equal(0.7, settings.Exposure.ExposureOffsetEv);
|
|
}
|
|
|
|
[Test]
|
|
public async Task APullWithNothingEditedHereIsInSyncOnceTheHomeHashedAPhoto()
|
|
{
|
|
var fx = await FixtureAsync();
|
|
await UnhashAsync(fx, 2);
|
|
var (_, sync) = fx.Workspace();
|
|
var id = (await fx.CheckoutAsync(sync)).ProjectId;
|
|
await EditAsync(sync, id, s => s with { ExcludedFrames = [2] }, fx.Ct);
|
|
await sync.CommitAsync(id, cancellationToken: fx.Ct);
|
|
await sync.PushAsync(id, fx.Home, fx.Ct);
|
|
await VerifyAsync(fx);
|
|
await WriteAtHomeAsync(fx, s => s with { Exposure = s.Exposure with { ExposureOffsetEv = 0.7 } });
|
|
|
|
var pulled = await sync.PullAsync(id, fx.Home, fx.Ct);
|
|
Assert.Equal(WorkspaceState.InSync, pulled.Status.State);
|
|
Assert.SequenceEqual([2], (await sync.OpenAsync(id, fx.Ct)).Working.ExcludedFrames);
|
|
Assert.Null(await sync.CommitAsync(id, cancellationToken: fx.Ct));
|
|
}
|
|
|
|
[Test]
|
|
public async Task ABaseNamingAPhotoByItsHashReadsAsTheWorkingStateOnMediaThatHaveNotLearntIt()
|
|
{
|
|
var fx = await FixtureAsync();
|
|
await UnhashAsync(fx, 2);
|
|
var (_, sync) = fx.Workspace();
|
|
var project = await fx.CheckoutAsync(sync);
|
|
var id = project.ProjectId;
|
|
var copied = project.ReadMedia()!;
|
|
await EditAsync(sync, id, s => s with { ExcludedFrames = [2] }, fx.Ct);
|
|
await sync.CommitAsync(id, cancellationToken: fx.Ct);
|
|
await sync.PushAsync(id, fx.Home, fx.Ct);
|
|
await VerifyAsync(fx);
|
|
await WriteAtHomeAsync(fx, s => s with { Exposure = s.Exposure with { ExposureOffsetEv = 0.7 } });
|
|
Assert.Equal(WorkspaceState.InSync, (await sync.PullAsync(id, fx.Home, fx.Ct)).Status.State);
|
|
var hashed = (await fx.Db.Frames.ListBySequenceAsync(fx.Sequence.Id))[2].Sha256!;
|
|
Assert.Contains(hashed, (await fx.Home.HeadAsync(id, fx.Ct)).SettingsJson);
|
|
|
|
// Media that have not learnt the hash (copied so, the home out of reach since): the base still holds the working state.
|
|
project.WriteMedia(copied);
|
|
var status = await sync.StatusAsync(id, cancellationToken: fx.Ct);
|
|
Assert.Equal((WorkspaceState.InSync, false), (status.State, status.Modified));
|
|
Assert.Null(await sync.CommitAsync(id, cancellationToken: fx.Ct));
|
|
Assert.Empty(sync.Unpushed(id));
|
|
|
|
// A change of the user's own still reads as one, and its version keeps the exclusion.
|
|
await EditAsync(sync, id, s => s with { Exposure = s.Exposure with { ExposureOffsetEv = 0.9 } }, fx.Ct);
|
|
Assert.True((await sync.StatusAsync(id, cancellationToken: fx.Ct)).Modified);
|
|
var saved = Assert.NotNull(await sync.CommitAsync(id, cancellationToken: fx.Ct));
|
|
Assert.SequenceEqual([2], ProjectSettings.FromJson(ProjectContent.Place(saved.SettingsJson, copied.Photos)).ExcludedFrames);
|
|
Assert.Equal(WorkspaceState.InSync, (await sync.PushAsync(id, fx.Home, fx.Ct)).Status.State);
|
|
var settings = await SequenceSettingsAsync(fx);
|
|
Assert.Equal((0.9, 2), (settings.Exposure.ExposureOffsetEv, settings.ExcludedFrames.Single()));
|
|
}
|
|
|
|
[Test]
|
|
public async Task APhotoHashedAtTheHomeIsOutdatedMediaUntilTheMediaLearnItsHash()
|
|
{
|
|
var fx = await FixtureAsync();
|
|
await UnhashAsync(fx, 2);
|
|
var (_, sync) = fx.Workspace();
|
|
var project = await fx.CheckoutAsync(sync);
|
|
var id = project.ProjectId;
|
|
await EditAsync(sync, id, s => s with { ExcludedFrames = [2] }, fx.Ct);
|
|
await sync.CommitAsync(id, cancellationToken: fx.Ct);
|
|
await sync.PushAsync(id, fx.Home, fx.Ct);
|
|
Assert.False((await sync.StatusAsync(id, fx.Home, fx.Ct)).MediaOutdated);
|
|
await VerifyAsync(fx);
|
|
await WriteAtHomeAsync(fx, s => s with { Exposure = s.Exposure with { ExposureOffsetEv = 0.7 } });
|
|
var hashed = (await fx.Db.Frames.ListBySequenceAsync(fx.Sequence.Id))[2].Sha256!;
|
|
|
|
// Asked while another operation holds the project: outdated, the media as they were, nothing to save here.
|
|
WorkspaceStatus busy;
|
|
using (await project.LockAsync(TimeSpan.FromSeconds(TestTiming.Budget(10)), fx.Ct))
|
|
busy = await sync.StatusAsync(id, fx.Home, fx.Ct);
|
|
Assert.True(busy.MediaOutdated);
|
|
Assert.Equal((WorkspaceState.Behind, false), (busy.State, busy.Modified));
|
|
Assert.Null(project.ReadMedia()!.Frames[2].Sha256);
|
|
Assert.False((await sync.StatusAsync(id, cancellationToken: fx.Ct)).MediaOutdated, "without a home nothing is known of it");
|
|
|
|
// Asked again with the project free: the media learn the hash, the frames and their files as copied.
|
|
var learnt = await sync.StatusAsync(id, fx.Home, fx.Ct);
|
|
Assert.False(learnt.MediaOutdated);
|
|
Assert.Equal((WorkspaceState.Behind, false), (learnt.State, learnt.Modified));
|
|
Assert.Equal(hashed, project.ReadMedia()!.Frames[2].Sha256);
|
|
var pulled = await sync.PullAsync(id, fx.Home, fx.Ct);
|
|
Assert.Equal((WorkspaceState.InSync, false), (pulled.Status.State, pulled.Status.MediaOutdated));
|
|
Assert.SequenceEqual([2], (await sync.OpenAsync(id, fx.Ct)).Working.ExcludedFrames);
|
|
}
|
|
|
|
[Test]
|
|
public async Task AProjectHeldForAMomentStillLetsTheMediaLearnTheHomesNames()
|
|
{
|
|
var fx = await FixtureAsync();
|
|
await UnhashAsync(fx, 2);
|
|
var (_, sync) = fx.Workspace();
|
|
var project = await fx.CheckoutAsync(sync);
|
|
var id = project.ProjectId;
|
|
await VerifyAsync(fx);
|
|
var hashed = (await fx.Db.Frames.ListBySequenceAsync(fx.Sequence.Id))[2].Sha256!;
|
|
|
|
// Another read of the state holds the project for a moment as this one asks: it waits for it, once.
|
|
var lease = await project.LockAsync(TimeSpan.FromSeconds(TestTiming.Budget(10)), fx.Ct);
|
|
var release = Task.Run(async () =>
|
|
{
|
|
await Task.Delay(150, fx.Ct);
|
|
lease.Dispose();
|
|
}, fx.Ct);
|
|
var status = await sync.StatusAsync(id, fx.Home, fx.Ct);
|
|
await release;
|
|
Assert.False(status.MediaOutdated);
|
|
Assert.Equal(hashed, project.ReadMedia()!.Frames[2].Sha256);
|
|
}
|
|
|
|
[Test]
|
|
public async Task APhotoConvertedAtTheHomeIsOutdatedMediaAndTheMediaLearnItsEncodings()
|
|
{
|
|
var fx = await FixtureAsync(4);
|
|
var (store, sync) = fx.Workspace();
|
|
var project = await fx.CheckoutAsync(sync);
|
|
var id = project.ProjectId;
|
|
var copied = project.ReadMedia()!;
|
|
Assert.Null(copied.Aliases);
|
|
await ProjectServiceTests.ConvertAsync(fx.Archive, fx.Sequence.Id, [1], 700);
|
|
var converted = (await fx.Db.Frames.ListBySequenceAsync(fx.Sequence.Id))[1].Sha256!;
|
|
|
|
// Opened again: the media learn the encodings the conversion joined, but still hold the photo as copied.
|
|
await sync.CheckoutAsync(fx.Home, id, cancellationToken: fx.Ct);
|
|
var link = Assert.NotNull(project.ReadMedia()!.Aliases).Single();
|
|
Assert.Equal((copied.Frames[1].Sha256!.ToLowerInvariant(), converted.ToLowerInvariant()), (link.Sha256.ToLowerInvariant(), link.Replacement.ToLowerInvariant()));
|
|
Assert.Equal(copied.Frames[1].Sha256, project.ReadMedia()!.Frames[1].Sha256);
|
|
var status = await sync.StatusAsync(id, fx.Home, fx.Ct);
|
|
Assert.True(status.MediaOutdated, "the file is not the library's any more: Update media copies it again");
|
|
Assert.False(status.Modified);
|
|
|
|
await fx.CopyAsync(store, id);
|
|
Assert.False((await sync.StatusAsync(id, fx.Home, fx.Ct)).MediaOutdated);
|
|
Assert.Equal(converted, project.ReadMedia()!.Frames[1].Sha256);
|
|
}
|
|
|
|
[Test]
|
|
public async Task AVersionSavedBeforeAnotherWorkspaceNamedThePhotoByItsHashKeepsItsEdit()
|
|
{
|
|
var fx = await FixtureAsync();
|
|
await UnhashAsync(fx, 2);
|
|
var (_, one) = fx.Workspace("one");
|
|
var id = (await fx.CheckoutAsync(one)).ProjectId;
|
|
await EditAsync(one, id, s => s with { ExcludedFrames = [2] }, fx.Ct);
|
|
await one.CommitAsync(id, cancellationToken: fx.Ct);
|
|
await one.PushAsync(id, fx.Home, fx.Ct);
|
|
await VerifyAsync(fx);
|
|
|
|
// Two copies the media once hashed and changes the stack.
|
|
var (_, two) = fx.Workspace("two");
|
|
await fx.CheckoutAsync(two, id);
|
|
await EditAsync(two, id, s => s with { Stack = new StackSettings { Mode = StackSetting.Mean } }, fx.Ct);
|
|
await two.CommitAsync(id, cancellationToken: fx.Ct);
|
|
await two.PushAsync(id, fx.Home, fx.Ct);
|
|
|
|
// One brings photo 2 back as a version of its own, then syncs: the version replayed still brings it back.
|
|
await EditAsync(one, id, s => s with { ExcludedFrames = [] }, fx.Ct);
|
|
await one.CommitAsync(id, "bring 2 back", cancellationToken: fx.Ct);
|
|
var pushed = await one.PushAsync(id, fx.Home, fx.Ct);
|
|
Assert.Equal(WorkspaceState.InSync, pushed.Status.State);
|
|
Assert.Equal("bring 2 back", pushed.Pushed.Single().Note);
|
|
var settings = await SequenceSettingsAsync(fx);
|
|
Assert.Empty(settings.ExcludedFrames);
|
|
Assert.Equal(StackSetting.Mean, settings.Stack.Mode);
|
|
}
|
|
|
|
[Test]
|
|
public async Task APhotoConvertedAtTheHomeBeforeUpdateMediaMergesAsOnePhotoAndKeepMineKeepsMine()
|
|
{
|
|
var fx = await FixtureAsync(4);
|
|
var (_, sync) = fx.Workspace();
|
|
var project = await fx.CheckoutAsync(sync);
|
|
var id = project.ProjectId;
|
|
await EditAsync(sync, id, s => s with { ExcludedFrames = [1], Camera = s.Camera with { Keyframes = [new CameraKey(1, 0.2, 0.5, 1.2, 0)] } }, fx.Ct);
|
|
await sync.CommitAsync(id, cancellationToken: fx.Ct);
|
|
await sync.PushAsync(id, fx.Home, fx.Ct);
|
|
|
|
// Photo 1 converted at the home (the media still hold the encoding copied), then the home moves its keyframe.
|
|
await ProjectServiceTests.ConvertAsync(fx.Archive, fx.Sequence.Id, [1], 700);
|
|
await WriteAtHomeAsync(fx, s => s with
|
|
{
|
|
Exposure = s.Exposure with { ExposureOffsetEv = 0.7 },
|
|
Camera = s.Camera with { Keyframes = [new CameraKey(1, 0.5, 0.5, 1.2, 0)] },
|
|
});
|
|
|
|
// Here photo 1 is brought back and its keyframe moved elsewhere: the keyframe is the one thing both changed.
|
|
await EditAsync(sync, id, s => s with { ExcludedFrames = [], Camera = s.Camera with { Keyframes = [new CameraKey(1, 0.8, 0.5, 1.2, 0)] } }, fx.Ct);
|
|
var pulled = await sync.PullAsync(id, fx.Home, fx.Ct);
|
|
var difference = Assert.NotNull(pulled.Status.Conflict).Differences.Single();
|
|
Assert.True(difference.Path.EndsWith(".keyframes", StringComparison.Ordinal), difference.Path);
|
|
Assert.Contains(project.ReadMedia()!.Frames[1].Sha256!, difference.Path);
|
|
|
|
await sync.ResolveAsync(id, fx.Home, ConflictChoice.KeepMine, cancellationToken: fx.Ct);
|
|
var working = (await sync.OpenAsync(id, fx.Ct)).Working;
|
|
Assert.Empty(working.ExcludedFrames);
|
|
Assert.Equal((1, 0.8), (working.Camera.Keyframes.Single().Frame, working.Camera.Keyframes.Single().CenterX));
|
|
Assert.Equal(0.7, working.Exposure.ExposureOffsetEv);
|
|
await sync.CommitAsync(id, cancellationToken: fx.Ct);
|
|
Assert.Equal(WorkspaceState.InSync, (await sync.PushAsync(id, fx.Home, fx.Ct)).Status.State);
|
|
var settings = await SequenceSettingsAsync(fx);
|
|
Assert.Empty(settings.ExcludedFrames);
|
|
Assert.Equal((1, 0.8), (settings.Camera.Keyframes.Single().Frame, settings.Camera.Keyframes.Single().CenterX));
|
|
}
|
|
|
|
/// <summary>What a newer Chronos sharing the archive writes for a push: its version file after the head, then the record's head.</summary>
|
|
private static ProjectVersion NewerPush(WorkspaceFixture fx, ProjectVersion head) => NewerChronos.Push(fx.Archive, fx.Sequence, head);
|
|
|
|
[Test]
|
|
public async Task LocalVersionsMeetingANewerChronosHeadStayAsTheyAreAndSaveBothSendsThem()
|
|
{
|
|
var fx = await FixtureAsync(3);
|
|
var (_, sync) = fx.Workspace();
|
|
var named = await fx.Archive.Service.Projects.CreateAsync(fx.Sequence.Id, "Grade", null, null, fx.Ct);
|
|
var project = await fx.CheckoutAsync(sync, named.Id);
|
|
var id = project.ProjectId;
|
|
await EditAsync(sync, id, s => s with { Exposure = s.Exposure with { ExposureOffsetEv = 0.3 } }, fx.Ct);
|
|
var local = Assert.NotNull(await sync.CommitAsync(id, "offset", cancellationToken: fx.Ct));
|
|
await EditAsync(sync, id, s => s with { ExcludedFrames = [1] }, fx.Ct);
|
|
var newer = NewerPush(fx, await fx.Home.HeadAsync(id, fx.Ct));
|
|
Assert.Equal(newer.Id, (await fx.Home.HeadAsync(id, fx.Ct)).Id);
|
|
|
|
// Nothing is merged into the newer settings: the local version, the working state and the base stay; a conflict of format waits.
|
|
var stopped = await sync.PushAsync(id, fx.Home, fx.Ct);
|
|
Assert.Empty(stopped.Pushed);
|
|
var conflict = Assert.NotNull(stopped.Status.Conflict);
|
|
Assert.True(conflict.NewerFormat);
|
|
Assert.Equal((WorkspaceState.Conflict, 1, false), (stopped.Status.State, stopped.Status.Ahead, stopped.Status.ReadOnly));
|
|
Assert.Equal(local.Id, sync.Unpushed(id).Single().Id);
|
|
Assert.Equal(local.SettingsJson, sync.Unpushed(id).Single().SettingsJson);
|
|
var working = (await sync.OpenAsync(id, fx.Ct)).Working;
|
|
Assert.Equal((ProjectSettings.CurrentVersion, 0.3), (working.Version, working.Exposure.ExposureOffsetEv));
|
|
Assert.SequenceEqual([1], working.ExcludedFrames);
|
|
Assert.Equal(WorkspaceState.Conflict, (await sync.PullAsync(id, fx.Home, fx.Ct)).Status.State);
|
|
|
|
// Merging either way is refused and leaves everything as it was.
|
|
var refused = await Assert.ThrowsAsync<WorkspaceSyncException>(() => sync.ResolveAsync(id, fx.Home, ConflictChoice.KeepMine, cancellationToken: fx.Ct));
|
|
Assert.Equal(PushOutcome.NewerFormat, refused.Outcome);
|
|
await Assert.ThrowsAsync<WorkspaceSyncException>(() => sync.ResolveAsync(id, fx.Home, ConflictChoice.TakeServer, cancellationToken: fx.Ct));
|
|
Assert.True((await sync.StatusAsync(id, fx.Home, fx.Ct)).Conflict!.NewerFormat);
|
|
Assert.Equal(local.Id, sync.Unpushed(id).Single().Id);
|
|
|
|
// Save both: this workspace's work (the change not saved yet too) goes to a new project in this Chronos's format.
|
|
var both = await sync.ResolveAsync(id, fx.Home, ConflictChoice.SaveBoth, cancellationToken: fx.Ct);
|
|
var copy = Assert.NotNull(both.SavedAs);
|
|
Assert.Equal(2, both.Pushed.Count);
|
|
var kept = ProjectSettings.FromJson(ProjectContent.Place((await fx.Home.HeadAsync(copy.Id, fx.Ct)).SettingsJson, ProjectServiceTests.Photos(fx.Frames)));
|
|
Assert.Equal(0.3, kept.Exposure.ExposureOffsetEv);
|
|
Assert.SequenceEqual([1], kept.ExcludedFrames);
|
|
// This project shows the newer Chronos's head, read-only.
|
|
Assert.True(both.Status.ReadOnly);
|
|
Assert.Equal(newer.Id, both.Status.Base!.VersionId);
|
|
Assert.Equal(1.5, (await sync.OpenAsync(id, fx.Ct)).Working.Exposure.ExposureOffsetEv);
|
|
}
|
|
|
|
[Test]
|
|
public async Task AChangeNotSavedYetMeetingANewerChronosHeadWaitsOnAConflict()
|
|
{
|
|
var fx = await FixtureAsync(3);
|
|
var (_, sync) = fx.Workspace();
|
|
var named = await fx.Archive.Service.Projects.CreateAsync(fx.Sequence.Id, "Grade", null, null, fx.Ct);
|
|
var id = (await fx.CheckoutAsync(sync, named.Id)).ProjectId;
|
|
await EditAsync(sync, id, s => s with { Exposure = s.Exposure with { ExposureOffsetEv = 0.7 } }, fx.Ct);
|
|
NewerPush(fx, await fx.Home.HeadAsync(id, fx.Ct));
|
|
|
|
var pulled = await sync.PullAsync(id, fx.Home, fx.Ct);
|
|
Assert.True(Assert.NotNull(pulled.Status.Conflict).NewerFormat);
|
|
Assert.Equal((WorkspaceState.Conflict, true, false), (pulled.Status.State, pulled.Status.Modified, pulled.Status.ReadOnly));
|
|
Assert.Equal(0.7, (await sync.OpenAsync(id, fx.Ct)).Working.Exposure.ExposureOffsetEv);
|
|
|
|
var both = await sync.ResolveAsync(id, fx.Home, ConflictChoice.SaveBoth, cancellationToken: fx.Ct);
|
|
Assert.Equal(0.7, ProjectSettings.FromJson(Assert.NotNull(both.Pushed.SingleOrDefault()).SettingsJson).Exposure.ExposureOffsetEv);
|
|
Assert.True(both.Status.ReadOnly);
|
|
}
|
|
|
|
[Test]
|
|
public async Task ANewerChronosHeadOverNothingOfThisWorkspacesIsTakenReadOnly()
|
|
{
|
|
var fx = await FixtureAsync(3);
|
|
var (_, sync) = fx.Workspace();
|
|
var named = await fx.Archive.Service.Projects.CreateAsync(fx.Sequence.Id, "Grade", null, null, fx.Ct);
|
|
var id = (await fx.CheckoutAsync(sync, named.Id)).ProjectId;
|
|
var newer = NewerPush(fx, await fx.Home.HeadAsync(id, fx.Ct));
|
|
|
|
var pulled = await sync.PullAsync(id, fx.Home, fx.Ct);
|
|
Assert.Null(pulled.Status.Conflict);
|
|
Assert.Equal((WorkspaceState.InSync, true), (pulled.Status.State, pulled.Status.ReadOnly));
|
|
Assert.Equal(newer.Id, pulled.Status.Base!.VersionId);
|
|
var session = await sync.OpenAsync(id, fx.Ct);
|
|
Assert.True(session.IsReadOnly);
|
|
Assert.Equal("film", session.Working.Extra!["grade"].GetProperty("look").GetString());
|
|
}
|
|
}
|
|
|
|
public sealed class SqliteWorkspaceMergeTests(TestContext context) : WorkspaceMergeTests(context)
|
|
{
|
|
protected override Backend Backend => Backend.SqliteFile;
|
|
}
|
|
|
|
[RequiresEnvironment(PgTestServer.Variable)]
|
|
public sealed class PostgresWorkspaceMergeTests(TestContext context) : WorkspaceMergeTests(context)
|
|
{
|
|
protected override Backend Backend => Backend.Postgres;
|
|
}
|