Phase 5a fix round 4, projects engine. - The reconcile reads the projects' trash before the live folders, so a deletion wins over what a sync tool has left of the live folder. A lost record is never written again while the trash holds a folder of that project; a trashed record that cannot be read holds the project back. - A lost record is written again from the index only once the folder has looked the same, file by file, on two reconciles two minutes apart, so a record a sync tool is still bringing (a rename, a newer head) wins. - IndexAsync's "behind" is the rule the heal uses: the record's head must be a version the index holds below its head. A record on another chain keeps its name. - A record written before what the index knows (its Updated time is older, e.g. a backup made before a rename) never gives its name, and the heal writes the index's name back. A record's Updated time never goes back, so a newer rename from a PC whose clock is behind is still taken. - A mirror never writes project.json over settings written there since this index last knew what it held (another PC, an older client): they are merged first (theirs win where both changed) or kept as an external version, then the result is mirrored. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
380 lines
23 KiB
C#
380 lines
23 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 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": 2, "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;
|
|
}
|