fix(projects): same project text on every OS; compare stored CRLF versions line-end-insensitively
Project text was indented with Environment.NewLine, so the same project read as CRLF text on Windows and LF text on the Linux server and its content hash differed. A Windows desktop pushing to a Linux server got spurious Merge and External versions, Modified/Behind states with no edits, empty commits, and renders and sends taken for other settings. Every build now writes the project JSON with LF (ProjectJson and IndentedJson). Versions already stored keep their CRLF text and hash, so SameChoices reads CRLF as LF (lossless: raw line ends are JSON whitespace) and the places that ask whether a text is a given version use the new ProjectContent.MatchesHash, true for the hash of the LF or the CRLF form. Integrity checks of stored and pushed versions stay exact. Tests pin the LF default hash, cover both comparisons both ways, and push versions with the other OS's line ends to an archive home and into a workspace: no outside change, in sync, nothing to commit. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
863c6cf27b
commit
787f030060
15 files changed
+174
-25
No files matched your search
@@ -473,28 +473,38 @@ public sealed class ProjectSettingsTests
|
||||
|
||||
/// <summary>
|
||||
/// SHA-256 of the default project's canonical text, as format-1 builds write it: none of phase 4's members, version 1.
|
||||
/// The text is indented with the OS's line ends (CRLF on Windows, LF on Linux), so the pin is of the text with CRLF.
|
||||
/// Builds before wrote it indented with the OS's line ends (CRLF on Windows, LF on Linux); this pin is of the CRLF text,
|
||||
/// the hash such a Windows build stored.
|
||||
/// </summary>
|
||||
private const string DefaultProjectHash = "df0b0f50b113475ece3753a80df0be05cc281cdaa1fa08a73a438ea9161358e0";
|
||||
|
||||
/// <summary>SHA-256 of the same text with LF, as every build writes it now on every OS.</summary>
|
||||
private const string DefaultProjectLfHash = "24e4c2d0379bfda6e42533d4687d69cca95bab72f2a49bd70e2fba267b66a3d1";
|
||||
|
||||
[Test]
|
||||
public void ProjectsWithoutTheNewMembersKeepTheirTextAndHash()
|
||||
{
|
||||
var defaults = new ProjectSettings().ToJson();
|
||||
Assert.Equal(DefaultProjectHash, ProjectContent.Hash(ProjectContent.Canonical(defaults).ReplaceLineEndings("\r\n")));
|
||||
Assert.Equal(OldBuild.Write(new OldProject()), defaults);
|
||||
Assert.False(defaults.Contains('\r', StringComparison.Ordinal), "line ends");
|
||||
Assert.Equal(DefaultProjectLfHash, ProjectContent.Hash(ProjectContent.Canonical(defaults)));
|
||||
// A version a Windows build stored before still names this text.
|
||||
Assert.True(ProjectContent.MatchesHash(ProjectContent.Canonical(defaults), DefaultProjectHash));
|
||||
Assert.Equal(DefaultProjectHash, ProjectContent.Hash(ProjectContent.Canonical(defaults).Replace("\n", "\r\n", StringComparison.Ordinal)));
|
||||
// The old build wrote the OS's line ends (OldJson leaves NewLine unset): the same text but for those.
|
||||
Assert.Equal(OldBuild.Write(new OldProject()).ReplaceLineEndings("\n"), defaults);
|
||||
Assert.Contains("\"version\": 1", defaults);
|
||||
foreach (var member in new[] { "rotate", "mirror", "flip", "straighten", "\"look\"" })
|
||||
Assert.False(defaults.Contains(member, StringComparison.Ordinal), member);
|
||||
|
||||
// A project written by a format-1 build reads and writes back the same, byte for byte.
|
||||
// A project written by a format-1 build reads and writes back the same, byte for byte but for line ends.
|
||||
var older = new ProjectSettings
|
||||
{
|
||||
Camera = new CameraSettings { Crop = [0.1, 0.2, 0.5, 0.6], Aspect = new Auto<string>().WithManual("9:16"), Keyframes = [new CameraKey(3, 0.4, 0.5, 1.5, 2)] },
|
||||
Exposure = new ExposureSettings { ExposureOffsetEv = 0.3 },
|
||||
}.ToJson();
|
||||
Assert.Equal(older, ProjectContent.Canonical(older));
|
||||
Assert.Equal(older, OldBuild.Write(OldBuild.Read(older)));
|
||||
Assert.Equal(older, OldBuild.Write(OldBuild.Read(older)).ReplaceLineEndings("\n"));
|
||||
Assert.Equal(older, ProjectContent.Canonical(older.Replace("\n", "\r\n", StringComparison.Ordinal)));
|
||||
Assert.Equal(ProjectSettings.BaseVersion, ProjectContent.FormatOf(older));
|
||||
}
|
||||
|
||||
@@ -549,8 +559,10 @@ public sealed class ProjectSettingsTests
|
||||
// A format-1 build keeps them as members it does not know, and writes them where they were.
|
||||
var old = OldBuild.Read(canonical);
|
||||
Assert.True(old.Camera.Extra!.ContainsKey("rotate") && old.Extra!.ContainsKey("look"));
|
||||
Assert.Equal(canonical, OldBuild.Write(old));
|
||||
Assert.Equal(ProjectContent.Hash(canonical), ProjectContent.Hash(OldBuild.Write(old)));
|
||||
// In the OS's line ends (CRLF on Windows): the same text and content hash but for those.
|
||||
Assert.Equal(canonical, OldBuild.Write(old).ReplaceLineEndings("\n"));
|
||||
Assert.True(ProjectContent.MatchesHash(OldBuild.Write(old), ProjectContent.Hash(canonical)));
|
||||
Assert.True(ProjectContent.SameChoices(OldBuild.Write(old), canonical, new FramePhotos([])));
|
||||
var camera = System.Text.Json.Nodes.JsonNode.Parse(canonical)!["camera"]!.AsObject().Select(p => p.Key).ToList();
|
||||
Assert.SequenceEqual(["crop", "aspect", "offsetX", "offsetY", "keyframes", "rotate", "straighten"], camera);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user