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
@@ -91,6 +91,21 @@ public abstract class ProjectServiceTests(TestContext context) : DatabaseTest(co
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <paramref name="version"/> as a build on the other OS wrote it before every build wrote LF: its text with the other
|
||||
/// line ends (CRLF for LF, LF for CRLF), hashed as such. Flipped, not made CRLF, so a test means the same on every OS.
|
||||
/// </summary>
|
||||
internal static ProjectVersion Foreign(ProjectVersion version)
|
||||
{
|
||||
var text = Foreign(version.SettingsJson);
|
||||
return version with { SettingsJson = text, ContentHash = ProjectContent.Hash(text) };
|
||||
}
|
||||
|
||||
/// <summary><paramref name="text"/> with the other line ends: LF where it has CRLF, CRLF where it has LF.</summary>
|
||||
internal static string Foreign(string text) => text.Contains("\r\n", StringComparison.Ordinal)
|
||||
? text.Replace("\r\n", "\n", StringComparison.Ordinal)
|
||||
: text.Replace("\n", "\r\n", StringComparison.Ordinal);
|
||||
|
||||
[Test]
|
||||
public async Task MainIsMadeFromTheSequenceSettingsWithItsPositionsParkedByPhoto()
|
||||
{
|
||||
@@ -195,6 +210,33 @@ public abstract class ProjectServiceTests(TestContext context) : DatabaseTest(co
|
||||
Assert.Equal(2, (await projects.HeadAsync(main.Id, fx.Ct)).Number);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task PushesFromAnotherOsAreNoOutsideChange()
|
||||
{
|
||||
var fx = await FixtureAsync();
|
||||
// Hashed photos: only line ends tell the texts apart (no photo named anew to compare by).
|
||||
var (sequence, frames) = await UploadedAsync(fx, 4);
|
||||
Assert.True(frames.All(f => f.Sha256 is { Length: 64 }));
|
||||
var projects = fx.Service.Projects;
|
||||
var main = await projects.MainAsync(sequence.Id, fx.Ct);
|
||||
var first = await projects.HeadAsync(main.Id, fx.Ct);
|
||||
|
||||
// A Windows desktop of a build before pushes to this home: CRLF versions on a home writing LF (and the reverse on Linux).
|
||||
var second = Foreign(Draft(first, new ProjectSettings { ExcludedFrames = [1], HeroFrame = 2 }, frames));
|
||||
Assert.Equal(PushOutcome.Stored, (await projects.PushAsync(main.Id, second, fx.Ct)).Outcome);
|
||||
var third = Foreign(Draft(second, new ProjectSettings { ExcludedFrames = [1, 3], Exposure = new ExposureSettings { ExposureOffsetEv = 0.4 } }, frames));
|
||||
Assert.Equal(PushOutcome.Stored, (await projects.PushAsync(main.Id, third, fx.Ct)).Outcome);
|
||||
Assert.Equal(PushOutcome.AlreadyStored, (await projects.PushAsync(main.Id, third, fx.Ct)).Outcome);
|
||||
|
||||
// The editor's old path writes the same settings again: the mirror of the third version, no outside change.
|
||||
await WriteSettingsAsync(fx, sequence.Id, ProjectSettings.FromJson(ProjectContent.Place(third.SettingsJson, Photos(frames))));
|
||||
var head = await projects.HeadAsync(main.Id, fx.Ct);
|
||||
Assert.Equal((third.Id, 3), (head.Id, head.Number));
|
||||
Assert.Equal(third.ContentHash, head.ContentHash);
|
||||
Assert.SequenceEqual([ProjectVersionKind.Commit, ProjectVersionKind.Commit, ProjectVersionKind.Imported],
|
||||
(await projects.HistoryAsync(main.Id, cancellationToken: fx.Ct)).Select(v => v.Kind));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task SettingsAnotherPathWritesBecomeAnExternalVersionOfMain()
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user