Files
Alby96andClaude Opus 5.5 188b2c2e55
CI / Build and test (push) Successful in 8m19s
CI / Windows tests and installer (push) Skipped
CI / YAML check (push) Successful in 7s
Release / Build, test and publish (push) Successful in 12m9s
CI / PostgreSQL 16 integration (push) Successful in 7m49s
CI / PostgreSQL 17 integration (push) Successful in 7m19s
CI / Docker image (push) Successful in 46s
Release / Server image (push) Successful in 1m14s
feat(editor): visual crop, rotate/mirror/flip/straighten, colour looks (owner review 1 phase 4) (#26)
Owner review 1 R5 + R6. Camera rotation, mirror, flip, straighten and crop handles locked to the output; an Exposure Look group; Export output size ("proportions win"); settings format 2 with older-node gates. Also fixes project text and hashes differing between Windows and Linux.

Closes #19
Closes #20

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Alberto Balbo <alberto.balbo.96@gmail.com>
2026-11-05 01:09:09 +01:00

460 lines
26 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 ABaseSavedWithTheOtherOsLineEndsReadsAsTheWorkingState()
{
var fx = await FixtureAsync();
Assert.True(fx.Frames.All(f => f.Sha256 is { Length: 64 }));
var projects = fx.Archive.Service.Projects;
var main = await projects.MainAsync(fx.Sequence.Id, fx.Ct);
// The head a build before stored on the other OS (CRLF where this build writes LF, and the reverse on Linux).
var foreign = ProjectServiceTests.Foreign(ProjectServiceTests.Draft(await projects.HeadAsync(main.Id, fx.Ct),
new ProjectSettings { ExcludedFrames = [1], HeroFrame = 3 }, fx.Frames));
Assert.Equal(PushOutcome.Stored, (await projects.PushAsync(main.Id, foreign, fx.Ct)).Outcome);
var (_, sync) = fx.Workspace();
var project = await fx.CheckoutAsync(sync);
var id = project.ProjectId;
Assert.Equal(foreign.ContentHash, project.ReadBundle().Workspace!.Base!.ContentHash);
Assert.SequenceEqual([1], (await sync.OpenAsync(id, fx.Ct)).Working.ExcludedFrames);
// Nothing edited here: in step with its base, and nothing to save.
Assert.Equal(WorkspaceState.InSync, (await sync.StatusAsync(id, fx.Home, fx.Ct)).State);
Assert.Null(await sync.CommitAsync(id, cancellationToken: fx.Ct));
Assert.Equal(foreign.Id, (await fx.Home.HeadAsync(id, fx.Ct)).Id);
}
[Test]
public async Task ARestoreOfAVersionTheBaseHoldsWithOtherLineEndsIsNoRestore()
{
var fx = await FixtureAsync();
var projects = fx.Archive.Service.Projects;
var main = await projects.MainAsync(fx.Sequence.Id, fx.Ct);
var choices = new ProjectSettings { ExcludedFrames = [1], HeroFrame = 3 };
// A version an older build stored on the other OS, then the same choices as this build writes them (the base).
var foreign = ProjectServiceTests.Foreign(ProjectServiceTests.Draft(await projects.HeadAsync(main.Id, fx.Ct), choices, fx.Frames));
Assert.Equal(PushOutcome.Stored, (await projects.PushAsync(main.Id, foreign, fx.Ct)).Outcome);
var same = ProjectServiceTests.Draft(foreign, choices, fx.Frames);
Assert.NotEqual(foreign.SettingsJson, same.SettingsJson);
Assert.Equal(PushOutcome.Stored, (await projects.PushAsync(main.Id, same, fx.Ct)).Outcome);
var (_, sync) = fx.Workspace();
var project = await fx.CheckoutAsync(sync);
var id = project.ProjectId;
Assert.Equal(same.Id, project.ReadBundle().Workspace!.Base!.VersionId);
// The foreign version restored before a pull moved the base onto the same choices: the restore stays recorded.
await sync.RestoreAsync(id, foreign.Id, fx.Home, fx.Ct);
project.WriteSync(project.ReadSync() with { RestoredFrom = foreign.Id });
// Edited further and saved: the parent already holds the restored version, so the new version is a plain one.
await EditAsync(sync, id, s => s with { Exposure = s.Exposure with { ExposureOffsetEv = 0.4 } }, fx.Ct);
var next = Assert.NotNull(await sync.CommitAsync(id, cancellationToken: fx.Ct));
Assert.Equal((ProjectVersionKind.Commit, (Guid?)null), (next.Kind, next.RestoredFrom));
}
[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.BaseVersion, 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;
}