Merge branch 'review2-p5a-fix2-merge' into review2-p5a-int2

This commit is contained in:
Alby96 committed 2026-11-03 12:10:16 +01:00
commit fd35e83dfc
10 files changed
+321 -19

No files matched your search

@@ -1,5 +1,6 @@
using Chronos.App.Editor;
using Chronos.Core.Project;
using Chronos.Data.Projects;
using Chronos.Testing;
namespace Chronos.App.Tests.Editor;
@@ -113,6 +114,38 @@ public sealed class ProjectHistoryTests
Assert.Null(history.Current.HeroFrame, "the user's step reverts the value it set");
}
[Test]
public void SettingsOfANewerChronosAdoptedDropTheStepsInsteadOfMergingThem()
{
var newer = ProjectSettings.FromJson("""{ "version": 2, "exposure": { "exposureOffsetEv": 1.5 }, "grade": { "look": "film" } }""", allowNewer: true);
// The workspace's merge throws as ProjectMerge does where both sides changed and one is a newer Chronos's.
foreach (var merge in new Func<ProjectSettings, ProjectSettings, ProjectSettings, ProjectSettings>?[]
{ null, (basis, ours, theirs) => ProjectMerge.MergeWithConflicts(basis, ours, theirs).Merged })
{
var history = new ProjectHistory(new ProjectSettings(), merge: merge);
history.Apply(WithOffset(history.Current, 0.3));
history.Apply(history.Current with { HeroFrame = 2 });
history.Undo();
Assert.True(history.CanUndo && history.CanRedo);
var changes = 0;
history.Changed += () => changes++;
// A pull took the newer settings (nothing of the editor's waited): shown as they are, read-only.
history.Replace(newer);
Assert.True(history.Current.IsNewerFormat);
Assert.Equal(1.5, history.Current.Exposure.ExposureOffsetEv);
Assert.False(history.CanUndo, "no step brings back this Chronos's values over a newer one's");
Assert.False(history.CanRedo);
Assert.False(history.Undo());
Assert.Equal(1, changes);
// Back to this Chronos's format (a Save both took another project): nothing is merged into the newer settings either.
history.Replace(WithOffset(new ProjectSettings(), 0.6));
Assert.Equal(0.6, history.Current.Exposure.ExposureOffsetEv);
Assert.False(history.CanUndo);
}
}
[Test]
public void EndingARunMakesTheNextEditANewStep()
{
@@ -0,0 +1,49 @@
using Chronos.Core.Project;
using Chronos.Testing;
namespace Chronos.App.Tests.Workspace;
/// <summary>
/// The editor of a workspace project whose home moved to settings of a newer Chronos (owner review 2, R8): shown read-only,
/// never merged with this Chronos's, the editor usable whatever its undo steps hold.
/// </summary>
[Category("workspace")]
public sealed class WorkspaceNewerFormatTests(TestContext context)
{
private static ProjectSettings Exposure(ProjectSettings p, double ev) => p with { Exposure = p.Exposure with { ExposureOffsetEv = ev } };
[Test]
public async Task AnEditorWithUndoStepsTakesANewerChronossSettingsReadOnly()
{
await using var bed = await WorkspaceTestBed.CreateAsync(context);
var host = bed.Host();
var projectId = await bed.CheckoutAsync(host);
var (_, session) = await bed.OpenAsync(host, projectId);
await using (session)
{
// Edited, saved and kept as a version: every edit is stored, the undo steps stay.
Assert.True(session.Edit(p => Exposure(p, 0.4)));
Assert.True(session.Edit(p => p with { ExcludedFrames = [2] }));
Assert.True(await session.FlushAsync());
Assert.NotNull(await host.CommitAsync(projectId, bed.Ct));
Assert.True(session.History.CanUndo);
// A pull with nothing of this PC's waiting moved the working state onto a newer Chronos's settings.
var folder = host.Store.Find(projectId)!;
var stored = folder.ReadBundle();
folder.WriteBundle(stored with { Project = Exposure(stored.Project, 1.5) with { Version = ProjectSettings.CurrentVersion + 1 } });
await session.ReloadAsync();
Assert.True(session.IsReadOnly);
Assert.True(session.Project.IsNewerFormat);
Assert.Equal(1.5, session.Project.Exposure.ExposureOffsetEv);
Assert.False(session.History.CanUndo, "no step brings this Chronos's values back over the newer ones");
Assert.False(session.Undo());
Assert.False(session.Edit(p => Exposure(p, 0.2)));
Assert.False(session.HasPendingSave);
// Read again (another analysis, another pull): the editor stays as it is.
await session.ReloadAsync();
Assert.Equal(1.5, session.Project.Exposure.ExposureOffsetEv);
}
}
}