Routing sizes render jobs from the resolved preset, and the node wait applies the same routing as the claim, so a re-routed job neither keeps a stale size nor waits for a node that will never take it. Settings an older server cannot read stay on this side for the remote editor, archive sync and workspace push, and the reason is shown where it applies. A turn on one side and a framing on the other merge as one conflict. Orientation and framing fixes: an out-of-range crop turns with the content it shows, the aspect text transposes exactly, the Rotation row counts turns as shown on screen, and Reset framing undoes the orientation press by press, so keyframes and aspect stay on their content. The advisor places the horizon in the view as shown. A look at zero strength is cleared and no longer reaches the motion vectors. Preview changes: the middle button pans, a press inside a box with no slack pans while zoomed, the selected box shows a ring, and screen readers hear when the crop value changes. Tooltips in en and it updated; stale translations of changed tooltips removed so they fall back to English. Test changes: the pinned hash is OS-independent, and the tautological encoder and warning assertions became real checks. Added a non-screen test of the Straighten slider binding. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
476 lines
29 KiB
C#
476 lines
29 KiB
C#
using System.Globalization;
|
|
using System.Text.Json.Nodes;
|
|
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.Workspaces;
|
|
using Chronos.Testing;
|
|
|
|
namespace Chronos.Data.Tests.Projects;
|
|
|
|
/// <summary>The merge of projects (owner review 2, R8): one photo under two names, and settings of a newer Chronos.</summary>
|
|
public sealed class ProjectMergeTests
|
|
{
|
|
private static readonly DateTime Start = new(2026, 9, 28, 18, 0, 0);
|
|
|
|
private static FramePhoto Photo(int n) => new(n.ToString("x64", CultureInfo.InvariantCulture), 1000 + n, Start.AddSeconds(10 * n));
|
|
|
|
private static PendingFrame Waiting(FramePhoto photo, bool excluded = false, bool hero = false) =>
|
|
new() { Sha256 = photo.Sha256, Size = photo.Size, CapturedAt = photo.CapturedAt, Excluded = excluded, Hero = hero };
|
|
|
|
[Test]
|
|
public void ATurnOnOneSideAndALookOnTheOtherMergeIntoFormatTwo()
|
|
{
|
|
var basis = new ProjectSettings { Exposure = new ExposureSettings { ExposureOffsetEv = 0.2 } };
|
|
var ours = basis with { Camera = basis.Camera with { Rotate = 90, Straighten = 1.5 } };
|
|
var theirs = basis with { Look = new LookSettings { Filter = "sepia", Strength = 0.6 } };
|
|
|
|
var result = ProjectMerge.MergeWithConflicts(basis, ours, theirs);
|
|
|
|
Assert.False(result.HasConflicts);
|
|
Assert.Equal((90, 1.5), (result.Merged.Camera.Rotate, result.Merged.Camera.Straighten));
|
|
Assert.Equal("sepia", result.Merged.Look?.Filter);
|
|
Assert.Equal(2, result.Merged.Version);
|
|
Assert.Contains("\"version\": 2", result.Merged.ToJson());
|
|
|
|
// One side takes the turn away while the other keeps the look: the format the members need, not the one taken.
|
|
var undone = ProjectMerge.MergeWithConflicts(result.Merged, result.Merged with { Camera = basis.Camera }, result.Merged with { Look = null }).Merged;
|
|
Assert.Equal(1, ProjectContent.FormatOf(undone.ToJson()));
|
|
Assert.Equal(basis.ToJson(), undone.ToJson());
|
|
}
|
|
|
|
[Test]
|
|
public void BothSidesCroppingGiveOneCropConflict()
|
|
{
|
|
var basis = new ProjectSettings { Camera = new CameraSettings { Aspect = new Auto<string>().WithManual("9:16") } };
|
|
var ours = basis with { Camera = basis.Camera with { Crop = [0.1, 0, 0.3, 0.9] } };
|
|
var theirs = basis with { Camera = basis.Camera with { Crop = [0.5, 0.05, 0.2, 0.6] } };
|
|
|
|
var result = ProjectMerge.MergeWithConflicts(basis, ours, theirs);
|
|
|
|
// The box is one value: never the x of one side and the width of the other.
|
|
Assert.SequenceEqual(["camera.crop"], result.Conflicts.Select(c => c.Path));
|
|
Assert.SequenceEqual([0.1, 0, 0.3, 0.9], Assert.NotNull(result.Merged.Camera.Crop));
|
|
Assert.SequenceEqual([0.5, 0.05, 0.2, 0.6], Assert.NotNull(
|
|
ProjectMerge.MergeWithConflicts(basis, ours, theirs, new HashSet<string> { "camera.crop" }).Merged.Camera.Crop));
|
|
|
|
// With a mirror on their side too, the crop and the mirror are one conflict: their crop is in the mirrored frame.
|
|
var mirrored = theirs with { Camera = theirs.Camera with { Mirror = true } };
|
|
var coupled = ProjectMerge.MergeWithConflicts(basis, ours, mirrored);
|
|
Assert.SequenceEqual(["camera.mirror"], coupled.Conflicts.Select(c => c.Path));
|
|
Assert.SequenceEqual([0.1, 0, 0.3, 0.9], Assert.NotNull(coupled.Merged.Camera.Crop), "ours: our crop");
|
|
Assert.False(coupled.Merged.Camera.Mirror, "and unmirrored");
|
|
var taken = ProjectMerge.MergeWithConflicts(basis, ours, mirrored, new HashSet<string> { "camera.mirror" }).Merged;
|
|
Assert.SequenceEqual([0.5, 0.05, 0.2, 0.6], Assert.NotNull(taken.Camera.Crop));
|
|
Assert.True(taken.Camera.Mirror);
|
|
}
|
|
|
|
/// <summary>
|
|
/// A turn of a project without a crop changes only the orientation and the aspect (nothing else to move), so member by
|
|
/// member a crop or keyframes the other side placed in the unturned frame would apply to the turned one: one conflict.
|
|
/// </summary>
|
|
[Test]
|
|
public void ATurnOnOneSideAndAFramingOnTheOtherAreOneConflict()
|
|
{
|
|
var basis = new ProjectSettings { Camera = new CameraSettings { Aspect = new Auto<string>().WithManual("16:9") } };
|
|
var turned = basis with { Camera = Chronos.Core.Imaging.Geometry.OrientationEdit.Apply(basis.Camera, Chronos.Core.Imaging.Geometry.OrientationOp.RotateRight) };
|
|
Assert.Null(turned.Camera.Crop);
|
|
var cropped = basis with { Camera = basis.Camera with { Crop = [0.1, 0.2, 0.6, 0.3375] } };
|
|
|
|
foreach (var (ours, theirs) in new[] { (turned, cropped), (cropped, turned) })
|
|
{
|
|
var result = ProjectMerge.MergeWithConflicts(basis, ours, theirs);
|
|
Assert.SequenceEqual(["camera.rotate"], result.Conflicts.Select(c => c.Path));
|
|
Assert.Equal(ours.ToJson(), result.Merged.ToJson(), "ours whole: the orientation and the framing of one side");
|
|
var other = ProjectMerge.MergeWithConflicts(basis, ours, theirs, new HashSet<string> { "camera.rotate" }).Merged;
|
|
Assert.Equal(theirs.ToJson(), other.ToJson());
|
|
}
|
|
|
|
// Keyframes placed in the unturned frame, on the camera and on a photo that waits.
|
|
var keyed = basis with
|
|
{
|
|
Camera = basis.Camera with { Keyframes = [new CameraKey(0, 0.8, 0.5, 2, 0)] },
|
|
};
|
|
Assert.SequenceEqual(["camera.rotate"], ProjectMerge.MergeWithConflicts(basis, turned, keyed).Conflicts.Select(c => c.Path));
|
|
var photo = Photo(1);
|
|
var waiting = basis with { PendingFrames = [Waiting(photo) with { Keyframes = [new CameraKey(0, 0.8, 0.5, 2, 0)] }] };
|
|
Assert.SequenceEqual(["camera.rotate"], ProjectMerge.MergeWithConflicts(basis, waiting, turned).Conflicts.Select(c => c.Path));
|
|
|
|
// Anything else on the other side merges with the turn as before.
|
|
var brighter = basis with { Exposure = basis.Exposure with { ExposureOffsetEv = 0.3 } };
|
|
var merged = ProjectMerge.MergeWithConflicts(basis, turned, brighter);
|
|
Assert.False(merged.HasConflicts);
|
|
Assert.Equal((90, 0.3), (merged.Merged.Camera.Rotate, merged.Merged.Exposure.ExposureOffsetEv));
|
|
}
|
|
|
|
[Test]
|
|
public void AFormatThreeSideIsNeverMerged()
|
|
{
|
|
var basis = new ProjectSettings { Camera = new CameraSettings { Rotate = 90 } };
|
|
var newer = ProjectSettings.FromJson("""{ "version": 3, "camera": { "rotate": 180 }, "look": { "filter": "film" } }""", allowNewer: true);
|
|
var mine = basis with { Look = new LookSettings { Filter = "warm" } };
|
|
Assert.Throws<NewerSettingsException>(() => ProjectMerge.MergeWithConflicts(basis, mine, newer));
|
|
Assert.Throws<NewerSettingsException>(() => ProjectMerge.MergeWithConflicts(basis, newer, mine));
|
|
Assert.Equal(3, ProjectMerge.MergeWithConflicts(basis, basis, newer).Merged.Version);
|
|
}
|
|
|
|
[Test]
|
|
public void EntriesOfOnePhotoMergeAsOneWithThePositionsOfBoth()
|
|
{
|
|
var frames = new FramePhotos([(0, Photo(1)), (1, Photo(2)), (2, Photo(3))]);
|
|
var basis = new ProjectSettings();
|
|
// A version stored with an exclusion and the hero of one photo in two entries (renamed alike since they were saved).
|
|
var ours = new ProjectSettings { PendingFrames = [Waiting(Photo(2), excluded: true), Waiting(Photo(2), hero: true)] };
|
|
var theirs = basis with { Stack = new StackSettings { Mode = StackSetting.Median } };
|
|
|
|
var merged = ProjectMerge.MergeWithConflicts(basis, ours, theirs);
|
|
Assert.Empty(merged.Conflicts);
|
|
var entry = Assert.NotNull(merged.Merged.PendingFrames).Single();
|
|
Assert.True(entry.Excluded && entry.Hero);
|
|
Assert.Equal(StackSetting.Median, merged.Merged.Stack.Mode);
|
|
var placed = ProjectSettings.FromJson(ProjectContent.Place(merged.Merged.ToJson(), frames));
|
|
Assert.SequenceEqual([1], placed.ExcludedFrames);
|
|
Assert.Equal((int?)1, placed.HeroFrame);
|
|
|
|
// The same through the merge's other side, and when the other side changed the photo's flags.
|
|
Assert.True(ProjectMerge.Merge(basis, theirs, ours).PendingFrames!.Single() is { Excluded: true, Hero: true });
|
|
var unexcluded = new ProjectSettings { PendingFrames = [Waiting(Photo(2), hero: true)] };
|
|
var both = ProjectMerge.MergeWithConflicts(ours, ours, unexcluded);
|
|
Assert.Empty(both.Conflicts);
|
|
Assert.True(both.Merged.PendingFrames!.Single() is { Excluded: false, Hero: true });
|
|
}
|
|
|
|
[Test]
|
|
public void APhotoNamedAlikeOnEverySideMergesAsOnePhoto()
|
|
{
|
|
// Saved here before the photo was hashed (by size and capture time) and stored at the home after (by SHA-256): once each
|
|
// side names it as the frames hold it now, undoing the exclusion here is a change of this side only.
|
|
var unhashed = new FramePhoto(null, Photo(2).Size, Photo(2).CapturedAt);
|
|
var frames = new FramePhotos([(0, Photo(1)), (1, Photo(2)), (2, Photo(3))]);
|
|
var basis = new ProjectSettings { PendingFrames = [Waiting(unhashed, excluded: true)] };
|
|
var theirs = new ProjectSettings { PendingFrames = [Waiting(Photo(2), excluded: true)], Exposure = new ExposureSettings { ExposureOffsetEv = 0.7 } };
|
|
var ours = new ProjectSettings();
|
|
|
|
ProjectSettings Named(ProjectSettings settings) => ProjectSettings.FromJson(ProjectContent.Rebind(ProjectContent.Canonical(settings.ToJson()), frames));
|
|
var merged = ProjectMerge.MergeWithConflicts(Named(basis), Named(ours), Named(theirs));
|
|
Assert.Empty(merged.Conflicts);
|
|
Assert.Null(merged.Merged.PendingFrames);
|
|
Assert.Equal(0.7, merged.Merged.Exposure.ExposureOffsetEv);
|
|
}
|
|
|
|
[Test]
|
|
public void SettingsOfANewerChronosAreNeverMergedWithThisOnes()
|
|
{
|
|
var basis = new ProjectSettings { Exposure = new ExposureSettings { ExposureOffsetEv = 0.1 } };
|
|
var newer = ProjectSettings.FromJson("""{ "version": 3, "exposure": { "exposureOffsetEv": 0.5 }, "grade": { "look": "film" } }""", allowNewer: true);
|
|
var mine = basis with { Stack = new StackSettings { Mode = StackSetting.Median } };
|
|
|
|
// Both changed: refused, whichever side the newer one is, in a replay too.
|
|
Assert.Throws<NewerSettingsException>(() => ProjectMerge.MergeWithConflicts(basis, mine, newer));
|
|
Assert.Throws<NewerSettingsException>(() => ProjectMerge.Merge(basis, newer, mine));
|
|
Assert.Throws<NewerSettingsException>(() => ProjectMerge.Replay(basis, [mine], newer));
|
|
Assert.Throws<NewerSettingsException>(() => new ProjectMerge.Rebase(basis, newer).Apply(mine));
|
|
|
|
// A side that did not change takes the other's as they are: nothing is merged.
|
|
var taken = ProjectMerge.MergeWithConflicts(basis, basis, newer);
|
|
Assert.Empty(taken.Conflicts);
|
|
Assert.True(taken.Merged.IsNewerFormat);
|
|
Assert.Equal(newer.ToJson(), taken.Merged.ToJson());
|
|
Assert.Equal(mine.ToJson(), ProjectMerge.Merge(newer, mine, newer).ToJson());
|
|
Assert.Equal(basis.ToJson(), ProjectMerge.Merge(newer, newer, basis).ToJson());
|
|
Assert.Equal(newer.ToJson(), ProjectMerge.Replay(basis, [basis], newer).Commits.Single().ToJson());
|
|
}
|
|
}
|
|
|
|
/// <summary>A newer Chronos sharing the archive (owner review 2, R8): what it writes when it stores a version.</summary>
|
|
internal static class NewerChronos
|
|
{
|
|
/// <summary>
|
|
/// A version of settings format <see cref="ProjectSettings.CurrentVersion"/> + 1 on top of <paramref name="head"/>, written
|
|
/// as that Chronos's push writes it: the version file, then the record's head (the index adopts it from the sidecars).
|
|
/// It holds a member this Chronos does not know (a grade) and an exposure offset of 1.5.
|
|
/// </summary>
|
|
public static ProjectVersion Push(ArchiveFixture fx, Sequence sequence, ProjectVersion head)
|
|
{
|
|
var folder = fx.Paths.Sequence(sequence.Folder);
|
|
var settings = JsonNode.Parse(head.SettingsJson)!.AsObject();
|
|
settings["version"] = ProjectSettings.CurrentVersion + 1;
|
|
settings["grade"] = new JsonObject { ["look"] = "film" };
|
|
settings["exposure"] = new JsonObject { ["exposureOffsetEv"] = 1.5 };
|
|
var text = ProjectContent.Canonical(settings.ToJsonString());
|
|
var version = new ProjectVersion
|
|
{
|
|
Id = Guid.CreateVersion7(),
|
|
ProjectId = head.ProjectId,
|
|
ParentId = head.Id,
|
|
Number = head.Number + 1,
|
|
Kind = ProjectVersionKind.Commit,
|
|
ClientName = "a newer Chronos",
|
|
SettingsJson = text,
|
|
ContentHash = ProjectContent.Hash(text),
|
|
SettingsFormat = ProjectSettings.CurrentVersion + 1,
|
|
FramesVersion = head.FramesVersion,
|
|
CreatedAt = DateTimeOffset.UtcNow,
|
|
StoredAt = DateTimeOffset.UtcNow,
|
|
};
|
|
ProjectSidecars.WriteVersion(folder.VersionPath(head.ProjectId, version.Number, version.Id), version);
|
|
var record = ProjectSidecars.ReadRecord(folder.ProjectRecordPath(head.ProjectId));
|
|
ProjectSidecars.WriteRecord(folder.ProjectRecordPath(head.ProjectId), record with { Head = new ProjectHead(version.Id, version.Number), Updated = DateTimeOffset.UtcNow });
|
|
return version;
|
|
}
|
|
}
|
|
|
|
/// <summary>Main's catch-up merge (owner review 2, R8): a mirror cut short meets settings written meanwhile.</summary>
|
|
[Category("projects")]
|
|
public abstract class MainMergeTests(TestContext context) : DatabaseTest(context)
|
|
{
|
|
private async Task<ArchiveFixture> FixtureAsync() => Own(await ArchiveFixture.CreateAsync(Context, database: await NewOptionsAsync(multiConnection: true)));
|
|
|
|
[Test]
|
|
public async Task WhereBothChangedTheSettingsWrittenMeanwhileWinAndThePushStaysInMainsHistory()
|
|
{
|
|
var fx = await FixtureAsync();
|
|
var (sequence, frames) = await ProjectServiceTests.UploadedAsync(fx, 4);
|
|
var projects = fx.Service.Projects;
|
|
var main = await projects.MainAsync(sequence.Id, fx.Ct);
|
|
var first = await projects.HeadAsync(main.Id, fx.Ct);
|
|
var pushed = (await projects.PushAsync(main.Id, ProjectServiceTests.Draft(first, new ProjectSettings
|
|
{
|
|
Stack = new StackSettings { Mode = StackSetting.Median },
|
|
Exposure = new ExposureSettings { ExposureOffsetEv = 0.5 },
|
|
}, frames), fx.Ct)).Version!;
|
|
|
|
// The push's mirror cut short, and another path writes an offset of its own and an exclusion meanwhile.
|
|
var reverted = await ProjectServiceTests.WriteSettingsAsync(fx, sequence.Id, new ProjectSettings());
|
|
await fx.Db.Projects.SetMirroredAsync(main.Id, first.Id, reverted.SettingsVersion, fx.Ct);
|
|
await ProjectServiceTests.WriteSettingsAsync(fx, sequence.Id, new ProjectSettings { Exposure = new ExposureSettings { ExposureOffsetEv = 1.25 }, ExcludedFrames = [3] });
|
|
|
|
// One merge version on the push: the settings written meanwhile win where both changed, the push's offset stays in its version.
|
|
var history = await projects.HistoryAsync(main.Id, cancellationToken: fx.Ct);
|
|
Assert.SequenceEqual([ProjectVersionKind.Merge, ProjectVersionKind.Commit, ProjectVersionKind.Imported], history.Select(v => v.Kind));
|
|
Assert.Equal((pushed.Id, pushed.Id), (history[0].ParentId, history[1].Id));
|
|
Assert.Equal(0.5, ProjectSettings.FromJson(history[1].SettingsJson).Exposure.ExposureOffsetEv);
|
|
var settings = ProjectSettings.FromJson((await fx.Db.Sequences.GetAsync(sequence.Id))!.SettingsJson!);
|
|
Assert.Equal((1.25, StackSetting.Median), (settings.Exposure.ExposureOffsetEv, settings.Stack.Mode));
|
|
Assert.SequenceEqual([3], settings.ExcludedFrames);
|
|
Assert.SequenceEqual([3], ProjectSettings.FromJson(ProjectContent.Place(history[0].SettingsJson, ProjectServiceTests.Photos(frames))).ExcludedFrames);
|
|
}
|
|
|
|
[Test]
|
|
public async Task AMergeACrashCutBeforeItsMirrorIsFinishedNextTimeWithNoOtherVersion()
|
|
{
|
|
foreach (var rebuild in new[] { false, true })
|
|
{
|
|
var fx = await FixtureAsync();
|
|
var (sequence, frames) = await ProjectServiceTests.UploadedAsync(fx, 4);
|
|
var projects = fx.Service.Projects;
|
|
var main = await projects.MainAsync(sequence.Id, fx.Ct);
|
|
var first = await projects.HeadAsync(main.Id, fx.Ct);
|
|
var pushed = (await projects.PushAsync(main.Id, ProjectServiceTests.Draft(first, new ProjectSettings
|
|
{
|
|
Stack = new StackSettings { Mode = StackSetting.Median },
|
|
Exposure = new ExposureSettings { ExposureOffsetEv = 0.5 },
|
|
}, frames), fx.Ct)).Version!;
|
|
var folder = fx.Paths.Sequence(sequence.Folder);
|
|
var record = ProjectSidecars.ReadRecord(folder.ProjectRecordPath(main.Id));
|
|
ProjectSidecars.WriteRecord(folder.ProjectRecordPath(main.Id), record with { Mirrored = new ProjectHead(first.Id, 1) });
|
|
|
|
// The push's mirror cut short, another path's settings meanwhile, and the catch-up's merge cut before its mirror.
|
|
var reverted = await ProjectServiceTests.WriteSettingsAsync(fx, sequence.Id, new ProjectSettings());
|
|
await fx.Db.Projects.SetMirroredAsync(main.Id, first.Id, reverted.SettingsVersion, fx.Ct);
|
|
var theirs = new ProjectSettings { Exposure = new ExposureSettings { ExposureOffsetEv = 1.25 }, ExcludedFrames = [3] };
|
|
await ProjectServiceTests.WriteSettingsAsync(fx, sequence.Id, theirs);
|
|
File.WriteAllText(folder.ProjectPath, theirs.ToJson());
|
|
projects.Cut = step =>
|
|
{
|
|
if (step == "catchup.merge") throw new CutException(step);
|
|
};
|
|
await Assert.ThrowsAsync<CutException>(() => projects.ListAsync(sequence.Id, fx.Ct));
|
|
projects.Cut = null;
|
|
Assert.SequenceEqual([ProjectVersionKind.Merge, ProjectVersionKind.Commit, ProjectVersionKind.Imported],
|
|
(await fx.Db.Projects.ListVersionsAsync(main.Id, null, 10, fx.Ct)).Select(v => v.Kind));
|
|
Assert.Equal(StackSetting.None, ProjectSettings.FromJson(File.ReadAllText(folder.ProjectPath)).Stack.Mode);
|
|
|
|
// The next catch-up (by this index, or by one rebuilt from the sidecars) mirrors that merge version and adds none.
|
|
if (rebuild)
|
|
{
|
|
await fx.ReopenWithEmptyIndexAsync();
|
|
await fx.ScanAsync(ScanMode.Rebuild);
|
|
}
|
|
foreach (var _ in new[] { 1, 2 })
|
|
{
|
|
var history = await fx.Service.Projects.HistoryAsync(main.Id, cancellationToken: fx.Ct);
|
|
Assert.SequenceEqual([ProjectVersionKind.Merge, ProjectVersionKind.Commit, ProjectVersionKind.Imported], history.Select(v => v.Kind));
|
|
Assert.Equal(pushed.Id, history[0].ParentId);
|
|
}
|
|
foreach (var settings in new[] { ProjectSettings.FromJson((await fx.Db.Sequences.GetAsync(sequence.Id))!.SettingsJson!),
|
|
ProjectSettings.FromJson(File.ReadAllText(folder.ProjectPath)) })
|
|
{
|
|
Assert.Equal((1.25, StackSetting.Median), (settings.Exposure.ExposureOffsetEv, settings.Stack.Mode));
|
|
Assert.SequenceEqual([3], settings.ExcludedFrames);
|
|
}
|
|
}
|
|
}
|
|
|
|
[Test]
|
|
public async Task TwoOutsideEditsInARowAreNoMergeForAnyIndex()
|
|
{
|
|
foreach (var rebuild in new[] { true, false })
|
|
{
|
|
var fx = await FixtureAsync();
|
|
var (sequence, frames) = await ProjectServiceTests.UploadedAsync(fx, 3);
|
|
var projects = fx.Service.Projects;
|
|
var main = await projects.MainAsync(sequence.Id, fx.Ct);
|
|
var first = await projects.HeadAsync(main.Id, fx.Ct);
|
|
var pushed = (await projects.PushAsync(main.Id, ProjectServiceTests.Draft(first, new ProjectSettings { ExcludedFrames = [0] }, frames), fx.Ct)).Version!;
|
|
var folder = fx.Paths.Sequence(sequence.Folder);
|
|
// Another PC's index that met Main mirrored at version 2.
|
|
var (other, _) = await fx.OtherWriterAsync();
|
|
await other.Projects.ListAsync(sequence.Id, fx.Ct);
|
|
|
|
// An older path edits the settings twice, the second time back to what version 2 holds: two external versions.
|
|
foreach (var excluded in new[] { new[] { 0, 1 }, new[] { 0 } })
|
|
{
|
|
var settings = new ProjectSettings { ExcludedFrames = [.. excluded] };
|
|
await ProjectServiceTests.WriteSettingsAsync(fx, sequence.Id, settings);
|
|
File.WriteAllText(folder.ProjectPath, settings.ToJson());
|
|
await projects.ListAsync(sequence.Id, fx.Ct);
|
|
}
|
|
var latest = (await projects.HeadAsync(main.Id, fx.Ct)).Id;
|
|
Assert.Equal(latest, ProjectSidecars.ReadRecord(folder.ProjectRecordPath(main.Id)).Mirrored?.Id);
|
|
// As an older build leaves the record (naming the push as mirrored): the shape of the history decides nothing.
|
|
var record = ProjectSidecars.ReadRecord(folder.ProjectRecordPath(main.Id));
|
|
ProjectSidecars.WriteRecord(folder.ProjectRecordPath(main.Id), record with { Mirrored = new ProjectHead(pushed.Id, pushed.Number) });
|
|
|
|
var service = other;
|
|
if (rebuild)
|
|
{
|
|
await fx.ReopenWithEmptyIndexAsync();
|
|
await fx.ScanAsync(ScanMode.Rebuild);
|
|
service = fx.Service;
|
|
}
|
|
await service.Projects.ListAsync(sequence.Id, fx.Ct);
|
|
var history = await service.Projects.HistoryAsync(main.Id, cancellationToken: fx.Ct);
|
|
Assert.SequenceEqual([ProjectVersionKind.External, ProjectVersionKind.External, ProjectVersionKind.Commit, ProjectVersionKind.Imported],
|
|
history.Select(v => v.Kind));
|
|
Assert.Equal(latest, history[0].Id);
|
|
Assert.SequenceEqual([0], ProjectSettings.FromJson(ProjectContent.Place(history[0].SettingsJson, ProjectServiceTests.Photos(frames))).ExcludedFrames);
|
|
Assert.SequenceEqual([0], ProjectSettings.FromJson(File.ReadAllText(folder.ProjectPath)).ExcludedFrames);
|
|
}
|
|
}
|
|
|
|
[Test]
|
|
public async Task AnOutsideEditAfterAPushWhoseRecordLagsStaysInForce()
|
|
{
|
|
var fx = await FixtureAsync();
|
|
var (sequence, frames) = await ProjectServiceTests.UploadedAsync(fx, 3);
|
|
var projects = fx.Service.Projects;
|
|
var main = await projects.MainAsync(sequence.Id, fx.Ct);
|
|
var first = await projects.HeadAsync(main.Id, fx.Ct);
|
|
var second = (await projects.PushAsync(main.Id, ProjectServiceTests.Draft(first, new ProjectSettings { ExcludedFrames = [0] }, frames), fx.Ct)).Version!;
|
|
var third = (await projects.PushAsync(main.Id, ProjectServiceTests.Draft(second, new ProjectSettings
|
|
{
|
|
ExcludedFrames = [0],
|
|
Exposure = new ExposureSettings { ExposureOffsetEv = 0.5 },
|
|
}, frames), fx.Ct)).Version!;
|
|
|
|
// Version 3's mirror wrote project.json but not the record (it still names version 2); then an older path edits project.json.
|
|
var folder = fx.Paths.Sequence(sequence.Folder);
|
|
var record = ProjectSidecars.ReadRecord(folder.ProjectRecordPath(main.Id));
|
|
ProjectSidecars.WriteRecord(folder.ProjectRecordPath(main.Id), record with { Mirrored = new ProjectHead(second.Id, 2) });
|
|
File.WriteAllText(folder.ProjectPath, new ProjectSettings { ExcludedFrames = [0], Exposure = new ExposureSettings { ExposureOffsetEv = 1.0 } }.ToJson());
|
|
await fx.ReopenWithEmptyIndexAsync();
|
|
await fx.ScanAsync(ScanMode.Rebuild);
|
|
|
|
// The outside edit stays in force; version 3's offset stays in the history.
|
|
var history = await fx.Service.Projects.HistoryAsync(main.Id, cancellationToken: fx.Ct);
|
|
Assert.SequenceEqual([ProjectVersionKind.Merge, ProjectVersionKind.Commit, ProjectVersionKind.Commit, ProjectVersionKind.Imported], history.Select(v => v.Kind));
|
|
Assert.Equal((third.Id, 0.5), (history[1].Id, ProjectSettings.FromJson(history[1].SettingsJson).Exposure.ExposureOffsetEv));
|
|
foreach (var settings in new[] { ProjectSettings.FromJson((await fx.Db.Sequences.GetAsync(sequence.Id))!.SettingsJson!),
|
|
ProjectSettings.FromJson(File.ReadAllText(folder.ProjectPath)) })
|
|
{
|
|
Assert.Equal(1.0, settings.Exposure.ExposureOffsetEv);
|
|
Assert.SequenceEqual([0], settings.ExcludedFrames);
|
|
}
|
|
Assert.Count(4, await fx.Service.Projects.HistoryAsync(main.Id, cancellationToken: fx.Ct));
|
|
}
|
|
|
|
[Test]
|
|
public async Task AnEditMadeOnlyInProjectJsonIsNeverWrittenOverByAMirror()
|
|
{
|
|
var fx = await FixtureAsync();
|
|
var (sequence, frames) = await ProjectServiceTests.UploadedAsync(fx, 3);
|
|
var projects = fx.Service.Projects;
|
|
var main = await projects.MainAsync(sequence.Id, fx.Ct);
|
|
var second = (await projects.PushAsync(main.Id, ProjectServiceTests.Draft(await projects.HeadAsync(main.Id, fx.Ct), new ProjectSettings { ExcludedFrames = [0] },
|
|
frames), fx.Ct)).Version!;
|
|
var folder = fx.Paths.Sequence(sequence.Folder);
|
|
|
|
// Another PC (an older client) edits project.json only, and this index has not scanned it: a push to Main merges it first.
|
|
File.WriteAllText(folder.ProjectPath, new ProjectSettings { ExcludedFrames = [0], Exposure = new ExposureSettings { ExposureOffsetEv = 1.0 } }.ToJson());
|
|
var third = (await projects.PushAsync(main.Id, ProjectServiceTests.Draft(second, new ProjectSettings
|
|
{
|
|
ExcludedFrames = [0, 2],
|
|
Exposure = new ExposureSettings { ExposureOffsetEv = 0.5 },
|
|
}, frames), fx.Ct)).Version!;
|
|
var history = await projects.HistoryAsync(main.Id, cancellationToken: fx.Ct);
|
|
Assert.SequenceEqual([ProjectVersionKind.Merge, ProjectVersionKind.Commit, ProjectVersionKind.Commit, ProjectVersionKind.Imported], history.Select(v => v.Kind));
|
|
Assert.Equal((third.Id, 0.5), (history[1].Id, ProjectSettings.FromJson(history[1].SettingsJson).Exposure.ExposureOffsetEv));
|
|
foreach (var settings in new[] { ProjectSettings.FromJson((await fx.Db.Sequences.GetAsync(sequence.Id))!.SettingsJson!),
|
|
ProjectSettings.FromJson(File.ReadAllText(folder.ProjectPath)) })
|
|
{
|
|
// Where both changed the outside edit wins; the push's other change is in force too.
|
|
Assert.Equal(1.0, settings.Exposure.ExposureOffsetEv);
|
|
Assert.SequenceEqual([0, 2], settings.ExcludedFrames);
|
|
}
|
|
Assert.Count(4, await projects.HistoryAsync(main.Id, cancellationToken: fx.Ct));
|
|
|
|
// The merge's mirror wrote project.json and the record but not the index (still at version 3), and project.json is
|
|
// edited again: the mirror completing it keeps the edit as an external version.
|
|
var head = await projects.HeadAsync(main.Id, fx.Ct);
|
|
var stale = await ProjectServiceTests.WriteSettingsAsync(fx, sequence.Id, new ProjectSettings { ExcludedFrames = [0, 2], Exposure = new ExposureSettings { ExposureOffsetEv = 0.5 } });
|
|
await fx.Db.Projects.SetMirroredAsync(main.Id, third.Id, stale.SettingsVersion, fx.Ct);
|
|
File.WriteAllText(folder.ProjectPath, new ProjectSettings { ExcludedFrames = [1], Exposure = new ExposureSettings { ExposureOffsetEv = -1 } }.ToJson());
|
|
history = await projects.HistoryAsync(main.Id, cancellationToken: fx.Ct);
|
|
Assert.Equal((ProjectVersionKind.External, head.Id), (history[0].Kind, history[0].ParentId));
|
|
foreach (var settings in new[] { ProjectSettings.FromJson((await fx.Db.Sequences.GetAsync(sequence.Id))!.SettingsJson!),
|
|
ProjectSettings.FromJson(File.ReadAllText(folder.ProjectPath)) })
|
|
{
|
|
Assert.Equal(-1, settings.Exposure.ExposureOffsetEv);
|
|
Assert.SequenceEqual([1], settings.ExcludedFrames);
|
|
}
|
|
Assert.Count(5, await projects.HistoryAsync(main.Id, cancellationToken: fx.Ct));
|
|
}
|
|
|
|
[Test]
|
|
public async Task ANewerChronosHeadOfMainIsNotMergedWithSettingsWrittenMeanwhile()
|
|
{
|
|
var fx = await FixtureAsync();
|
|
var (sequence, _) = await ProjectServiceTests.UploadedAsync(fx, 3);
|
|
var projects = fx.Service.Projects;
|
|
var main = await projects.MainAsync(sequence.Id, fx.Ct);
|
|
var newer = NewerChronos.Push(fx, sequence, await projects.HeadAsync(main.Id, fx.Ct));
|
|
await ProjectServiceTests.WriteSettingsAsync(fx, sequence.Id, new ProjectSettings { Stack = new StackSettings { Mode = StackSetting.Mean } });
|
|
|
|
// Both are left as they are: the newer head stays the head, the settings stay those written.
|
|
Assert.Equal(newer.Id, (await projects.HeadAsync(main.Id, fx.Ct)).Id);
|
|
Assert.Count(2, await projects.HistoryAsync(main.Id, cancellationToken: fx.Ct));
|
|
var settings = ProjectSettings.FromJson((await fx.Db.Sequences.GetAsync(sequence.Id))!.SettingsJson!);
|
|
Assert.Equal((StackSetting.Mean, 0.0), (settings.Stack.Mode, settings.Exposure.ExposureOffsetEv));
|
|
}
|
|
}
|
|
|
|
public sealed class SqliteMainMergeTests(TestContext context) : MainMergeTests(context)
|
|
{
|
|
protected override Backend Backend => Backend.SqliteFile;
|
|
}
|
|
|
|
[RequiresEnvironment(PgTestServer.Variable)]
|
|
public sealed class PostgresMainMergeTests(TestContext context) : MainMergeTests(context)
|
|
{
|
|
protected override Backend Backend => Backend.Postgres;
|
|
}
|