fix(projects): address the line-end review
StillRestores compared the restored version with the new version's parent as raw text, so a version an older Windows build stored with CRLF never matched the same choices written as LF, and a commit on a parent already holding the restored version was labelled a restore. It now compares them with SameChoices, like every other project text comparison. The LF line ends of the project writers were only checked through Environment.NewLine, which is LF on Linux CI already; the tests now assert the NewLine option of ProjectJson and IndentedJson directly, so reverting either fails on every OS. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
787f030060
commit
d2332687da
4 files changed
+34
-2
No files matched your search
@@ -329,7 +329,7 @@ public sealed record ProjectSettings
|
||||
public const int BaseVersion = 1;
|
||||
|
||||
/// <summary>Layout of a project edited as JSON (<see cref="MoveFramePositions"/>): indented like <see cref="ToJson"/>, with LF line ends on every OS.</summary>
|
||||
private static readonly JsonSerializerOptions IndentedJson = new() { WriteIndented = true, NewLine = "\n" };
|
||||
internal static readonly JsonSerializerOptions IndentedJson = new() { WriteIndented = true, NewLine = "\n" };
|
||||
|
||||
/// <summary>Member names as a project edited as JSON reads them (an older or hand-written file may use any casing).</summary>
|
||||
private static readonly JsonNodeOptions CaseInsensitive = new() { PropertyNameCaseInsensitive = true };
|
||||
|
||||
@@ -1479,7 +1479,8 @@ public sealed class WorkspaceSync(WorkspaceStore store, string clientName)
|
||||
if (project.Versions().FirstOrDefault(v => v.Id == restoredId) is not { } restored) return true;
|
||||
var then = ProjectContent.Rebind(restored.SettingsJson, photos);
|
||||
var before = parent is null ? ProjectContent.ToPortable(new ProjectSettings(), photos) : ProjectContent.Rebind(parent.SettingsJson, photos);
|
||||
if (then == before) return false;
|
||||
// The same choices are no different, whatever line ends either was stored with (a CRLF version of an older Windows build).
|
||||
if (ProjectContent.SameChoices(then, before, photos)) return false;
|
||||
var now = ProjectContent.Rebind(portable, photos);
|
||||
var merge = ProjectMerge.MergeWithConflicts(ProjectMerge.Read(before), ProjectMerge.Read(now), ProjectMerge.Read(then));
|
||||
return merge.Conflicts.Count == 0 && ProjectContent.Canonical(merge.Merged.ToJson()) == ProjectContent.Canonical(now);
|
||||
|
||||
@@ -351,6 +351,9 @@ public sealed class ProjectContentTests
|
||||
var frames = Frames(Photo(1), Photo(2), Photo(3));
|
||||
var lf = ProjectContent.ToPortable(Positions([1], 2, 0), frames);
|
||||
var crlf = lf.Replace("\n", "\r\n", StringComparison.Ordinal);
|
||||
// Every writer of project text names LF itself: on Linux Environment.NewLine is LF already, so only these fail there.
|
||||
Assert.Equal("\n", ProjectJson.Default.Options.NewLine);
|
||||
Assert.Equal("\n", ProjectSettings.IndentedJson.NewLine);
|
||||
Assert.False(lf.Contains('\r', StringComparison.Ordinal), "portable");
|
||||
Assert.False(new ProjectSettings().ToJson().Contains('\r', StringComparison.Ordinal), "ToJson");
|
||||
Assert.Equal(lf, ProjectContent.Canonical(crlf));
|
||||
|
||||
@@ -142,6 +142,34 @@ public abstract class WorkspaceMergeTests(TestContext context) : DatabaseTest(co
|
||||
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()
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user