fix(workspace): newer-format editor stays usable; media learn the home's photo names
A pull onto a newer Chronos's settings made the editor throw: ProjectHistory.Replace rebased every undo and redo snapshot through ProjectMerge, which refuses to merge a newer format when both sides changed, so any non-empty undo stack broke the reload after a sync that had succeeded. Replace now drops the steps instead when either side (or a step) is of a newer format: the project is shown read-only and undo never brings back values from before the newer settings. The media learnt the home's hashes and conversion aliases only inside a replay, so a status or Save version before that compared a SHA-named base with photo-named media and read a false Modified or saved a version that only re-keyed photos. Now: - ProjectContent.SameChoices also compares the texts as placed on the frames, hashed or not (Bound), so status and commit without a home agree with the base; - a status asked of the home teaches the media its names (written under the lease, or when the lease is free), and so does a checkout of a project already here; - WorkspaceStatus.MediaOutdated reports frames moved at the home, or names the media could not learn yet, and the project menu offers Update media for it (tooltip text updated in en and it). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
8256b72913
commit
43b092bd5d
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -135,6 +135,29 @@ public sealed class ProjectContentTests
|
||||
Assert.Equal(newer, ProjectContent.Rebind(newer, now));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ChoicesSavedWhereAPhotoWasHashedReadAsTheSameOnFramesCopiedBeforeIt()
|
||||
{
|
||||
// A workspace copied photo 1 before its home hashed it; a version the home made since names it by its SHA-256.
|
||||
var copied = Frames(Photo(1, hashed: false), Photo(2), Photo(3));
|
||||
var home = Frames(Photo(1), Photo(2), Photo(3));
|
||||
var choices = new ProjectSettings { ExcludedFrames = [0], Camera = new CameraSettings { Keyframes = [new CameraKey(0, 0.3, 0.5, 1.2, 0)] } };
|
||||
var atHome = ProjectContent.ToPortable(choices, home);
|
||||
var here = ProjectContent.ToPortable(choices, copied);
|
||||
Assert.NotEqual(atHome, here);
|
||||
|
||||
// The same choices on the frames held here: no change to show or to save as a version.
|
||||
Assert.True(ProjectContent.SameChoices(atHome, here, copied));
|
||||
Assert.True(ProjectContent.SameChoices(here, atHome, copied));
|
||||
// What is kept keeps the hash the frames do not know yet; a choice of its own still differs.
|
||||
Assert.Equal(atHome, ProjectContent.Rebind(atHome, copied));
|
||||
Assert.False(ProjectContent.SameChoices(atHome, ProjectContent.ToPortable(new ProjectSettings { ExcludedFrames = [1] }, copied), copied));
|
||||
Assert.False(ProjectContent.SameChoices(atHome, ProjectContent.ToPortable(choices with { ExcludedFrames = [] }, copied), copied));
|
||||
// A photo none of the frames holds is compared as it is named.
|
||||
var gone = ProjectContent.ToPortable(choices, Frames(Photo(4)));
|
||||
Assert.False(ProjectContent.SameChoices(gone, ProjectContent.ToPortable(choices, Frames(Photo(4, hashed: false))), copied));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void APhotoOfABurstToldApartByItsOrderKeepsItsPositionOnceHashed()
|
||||
{
|
||||
|
||||
@@ -118,6 +118,102 @@ public abstract class WorkspaceMergeTests(TestContext context) : DatabaseTest(co
|
||||
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 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()
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user