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:
Alby96andClaude Opus 5.5 committed 2026-11-04 22:48:27 +01:00
1 parent 863c6cf27b
commit 787f030060
15 files changed
+174 -25

No files matched your search

+4
View File
@@ -53,6 +53,10 @@ commits follow Conventional Commits (release notes are generated from them by `C
Italian wording.
- A workspace copy cancelled just before it committed (its last query already answered, the project's lease then free)
could commit anyway and end *Done*, keeping the media it wrote; it now stops at the commit and its clean-up runs.
- A project saved on Windows and the same project on the Linux server no longer read as different: the desktop wrote
project text with Windows line ends, so an unchanged project showed *Modified* or *Behind*, saved empty versions,
made the server add *Merge* or *External* versions, and marked renders and sends as of other settings. Every build now
writes the same text, and versions saved before compare equal to it.
### Changed
- *Pause uploads on metered* (Server screen) is now *Pause metered transfers*: on a metered connection the sync's
+1
View File
@@ -721,3 +721,4 @@ One line per decision: date · decision · alternative · reason.
| 2026-11-04 | Phase 4 groundwork details: `ProjectSettings.WrittenFormat` (the format `ToJson` stamps, a newer project's own number); `EditPath.HasHandValues` counts a crop only when not whole (`CropFrame.IsWhole`), which matches today; FrameFinish clamps the look strength to 0..1 (missing = 1) and an unknown look still writes format 2 (it is a newer Chronos's); look names are ordinal and case-sensitive; `OrientationEdit` also remaps offsets and pending keyframes, negates straighten on mirror/flip, normalises rotate to 0..270 and rounds remapped coordinates to 12 decimals so four turns give the original text; the SelfTest geometry and colour checks sit before the robustness checks. (Owner review 1, phase 4.) | — | Simplest safe choices where the plan was silent. |
| 2026-11-04 | Phase 4 review fixes, routing and gates: render routing sizes a job from its resolved preset box, never from the size posted with it (the posted size only without a preset size); the server's wait for a node re-routes the job as the claim does; the remote editor lets edits happen but refuses to save settings the server cannot read (`NeedsNewerServer` toast); archive sync keeps such settings here (`ServerFormatException`, the row stays LocalAhead with the reason; the server's format is cached for 1 minute, none announced = 1); a workspace push is refused whole, before its first version, when any unpushed version needs a newer home, and Sync's reason includes the unpushed versions; a local render of a workspace project (`RendersLocally`) is not gated by the server's format; the Library's Render on a remote card applies the editor's older-server gate and sizes the job on the project it read, without embedding it (the server renders the sequence's settings of the moment). (Owner review 1, phase 4.) | Let the server refuse | Nothing an older server would store and then fail to render is sent to it, and no job waits for a node that never takes it. |
| 2026-11-04 | Phase 4 review fixes, editing: a turn or mirror on one side and a framing edit on the other (crop, keyframes, offsets, aspect, keyframes of waiting photos) are one merge conflict at the orientation member, settled with that side's framing; the derived top-level `version` is no settings difference while both are at most this Chronos's; a quarter turn transposes the aspect text without reducing it (21:9 → 9:21); an out-of-range crop is turned as it renders (clamped first); off-grid crop and keyframe values land on the 12-decimal grid at their first press and the keyframe centre sliders write gridded values; the Rotation row shows the turn as seen (reversed while exactly one of Mirror and Flip is on); Reset framing undoes the orientation press by press so keyframes and aspect stay on their content; the look strength minimum is 1 % and 0 or less clears the look; motion vectors are computed without the look and the knee; the horizon advisor maps its rows through turn, flip, straighten and cover zoom (the mirror moves only columns); inside a box with no slack a press pans while zoomed and the middle button always pans; the selected box shows a 2 px Accent ring; translations of keys whose English meaning changed are deleted (English fallback) instead of new keys. (Owner review 1, phase 4.) | — | Simplest safe choices for the review's findings. |
| 2026-11-04 | Project text is written with LF on every OS (`NewLine = "\n"` in the `ProjectJson` source-gen options and in `ProjectSettings.IndentedJson`), so a project's canonical text and content hash are the same on Windows and on the Linux server. Versions already stored keep their text and hash (a Windows build's are CRLF): `ProjectContent.SameChoices` compares both texts with CRLF read as LF (lossless: a raw CR or LF in the JSON is whitespace between tokens), and the places that ask "is this text that version" (the workspace's tip and base, the head a render names, the render job's version, the send's matching version, the history's current marker) use `ProjectContent.MatchesHash`, true for the hash of the text's LF or CRLF form. Integrity checks (`Verifies` of a stored or pushed version, stored hash against stored hash) stay exact. The other indented JSON writers (`AdvisorJson`, `ArchiveJsonIndented`, `WorkspaceJson`, `WorkspaceMoveJson`, the `ProjectBundle` writer, settings files) feed no project hash and are left as they are. | LF only, comparisons exact | With LF alone, every version a Windows build stored would stop matching the text the new build writes: unchanged projects would read as modified at the upgrade. |
@@ -595,7 +595,7 @@ public sealed class WorkspaceSequenceSource : ISequenceSource, IProjectRenders
ContentHash = hash,
};
var requests = ProcessingJobs.RenderVersion(sequence, tip, export, sourceWidth, sourceHeight);
if (tipId is not null && string.Equals(tipHash, hash, StringComparison.OrdinalIgnoreCase)) return requests;
if (tipId is not null && ProjectContent.MatchesHash(portable, tipHash)) return requests;
return [.. requests.Select(r => r with { ParametersJson = WithoutVersion(r.ParametersJson) })];
}
@@ -607,7 +607,7 @@ public sealed class WorkspaceSequenceSource : ISequenceSource, IProjectRenders
private IReadOnlyList<ArchiveJobRequest> LocalRenderRequests(Sequence sequence, BundleHome home, string portable, string hash, ExportSettings export,
int sourceWidth, int sourceHeight)
{
var head = HeadVersion(hash);
var head = HeadVersion(portable);
var version = new ProjectVersion { Id = head ?? Guid.Empty, ProjectId = ProjectId, Number = 0, SettingsJson = portable, ContentHash = hash };
var root = _sync.Store.Root;
var server = home.IsArchive ? null : home.Server;
@@ -618,12 +618,12 @@ public sealed class WorkspaceSequenceSource : ISequenceSource, IProjectRenders
];
}
/// <summary>The id of the newest version the workspace holds when it holds <paramref name="hash"/>; null otherwise.</summary>
private Guid? HeadVersion(string hash)
/// <summary>The id of the newest version the workspace holds when it holds <paramref name="portable"/> (any line ends); null otherwise.</summary>
private Guid? HeadVersion(string portable)
{
try
{
return Project.Versions() is [.., var last] && string.Equals(last.ContentHash, hash, StringComparison.OrdinalIgnoreCase) ? last.Id : null;
return Project.Versions() is [.., var last] && ProjectContent.MatchesHash(portable, last.ContentHash) ? last.Id : null;
}
catch (Exception ex) when (ex is IOException or InvalidDataException or UnauthorizedAccessException)
{
@@ -679,7 +679,7 @@ public sealed class WorkspaceSequenceSource : ISequenceSource, IProjectRenders
{
if (_sync.Unpushed(ProjectId).Count > 0 || Project.ReadBundle().Workspace?.Base is not { } basis) return null;
var working = ProjectContent.ToPortable(project, Photos);
if (string.Equals(ProjectContent.Hash(working), basis.ContentHash, StringComparison.OrdinalIgnoreCase)) return basis;
if (ProjectContent.MatchesHash(working, basis.ContentHash)) return basis;
// Saved before a hash or a conversion at the home named its photos anew: the same choices are in step too.
return Project.Versions().FirstOrDefault(v => v.Id == basis.VersionId) is { } version && ProjectContent.SameChoices(version.SettingsJson, working, Photos)
? basis
@@ -560,7 +560,7 @@ public sealed class ProjectMenuViewModel : LocalizedViewModel
{
await StoreEditAsync();
var history = await _host.HistoryAsync(ProjectId, Math.Max(50, _host.Settings.WorkspaceKeptVersions));
dialog.Show(history, ProjectContent.Hash(ProjectContent.ToPortable(_session.Project, _source.Photos)));
dialog.Show(history, ProjectContent.ToPortable(_session.Project, _source.Photos));
}
catch (Exception ex) when (ex is not OutOfMemoryException)
{
@@ -472,14 +472,17 @@ public sealed class HistoryDialogViewModel : ArchiveDialogViewModel
public IReadOnlyList<string> Compared { get => _compared; private set => Set(ref _compared, value); }
/// <summary>Lists <paramref name="history"/>; <paramref name="currentHash"/> marks the version the project is now.</summary>
public void Show(WorkspaceHistory history, string? currentHash)
/// <summary>
/// Lists <paramref name="history"/>; <paramref name="currentPortable"/>, the project's portable text now, marks the version
/// holding it (whatever line ends that version was saved with).
/// </summary>
public void Show(WorkspaceHistory history, string? currentPortable)
{
ArgumentNullException.ThrowIfNull(history);
Rows.Clear();
foreach (var version in history.Versions)
{
var current = currentHash is not null && string.Equals(version.ContentHash, currentHash, StringComparison.OrdinalIgnoreCase);
var current = currentPortable is not null && ProjectContent.MatchesHash(currentPortable, version.ContentHash);
Rows.Add(new HistoryRowViewModel(version, history.Unsent.Contains(version.Id), current,
new AsyncRelayCommand(() => CompareAsync(version), () => !IsBusy), new AsyncRelayCommand(() => RestoreAsync(version), () => !IsBusy), _server));
}
@@ -189,6 +189,7 @@ public static class ProjectContent
/// same once their pending frames are named as the frames hold their photos now (<see cref="Rebind"/>), or as the frame
/// each lands on is named, hashed or not (<see cref="Bound"/>): a version saved where a photo was hashed after these
/// frames were copied holds what a working state saved on them does, so it reads neither as a change nor as one to save.
/// Line ends do not count: a text a build wrote on Windows with CRLF holds what the same text with LF does.
/// </summary>
/// <exception cref="JsonException">A text is not a project object.</exception>
public static bool SameChoices(string portable, string other, FramePhotos frames)
@@ -197,6 +198,9 @@ public static class ProjectContent
ArgumentNullException.ThrowIfNull(other);
ArgumentNullException.ThrowIfNull(frames);
if (portable == other) return true;
portable = WithLf(portable);
other = WithLf(other);
if (portable == other) return true;
if (frames.Count == 0) return false;
return Rebind(portable, frames) == Rebind(other, frames) || (frames.HasUnhashed && Bound(portable, frames) == Bound(other, frames));
}
@@ -235,6 +239,26 @@ public static class ProjectContent
/// <summary>Whether <paramref name="hash"/> is the content hash of <paramref name="text"/> (any case).</summary>
public static bool Verifies(string text, string? hash) => hash is { Length: 64 } && string.Equals(Hash(text), hash, StringComparison.OrdinalIgnoreCase);
/// <summary>
/// Whether <paramref name="hash"/> is the content hash of <paramref name="text"/> whatever its line ends: of the text with
/// LF (as every build writes it now) or with CRLF (as builds before wrote it on Windows, versions stored since keep that
/// hash). For comparing a text with a version's hash; an integrity check of a stored version stays exact
/// (<see cref="Verifies"/>).
/// </summary>
public static bool MatchesHash(string text, string? hash)
{
ArgumentNullException.ThrowIfNull(text);
if (hash is not { Length: 64 }) return false;
var lf = WithLf(text);
return Verifies(lf, hash) || (lf.Contains('\n', StringComparison.Ordinal) && Verifies(lf.Replace("\n", "\r\n", StringComparison.Ordinal), hash));
}
/// <summary>
/// The text with CRLF line ends as LF. Lossless for JSON: a raw CR or LF can only be whitespace between tokens (one inside
/// a string is escaped).
/// </summary>
private static string WithLf(string text) => text.Contains('\r', StringComparison.Ordinal) ? text.Replace("\r\n", "\n", StringComparison.Ordinal) : text;
/// <summary>The settings format (<see cref="ProjectSettings.Version"/>) a project's text declares; 1 when it says none or is not a project.</summary>
public static int FormatOf(string? json)
{
+5 -2
View File
@@ -328,8 +328,8 @@ public sealed record ProjectSettings
/// <summary>The format of a project that uses nothing added since the first one, which most projects are written as.</summary>
public const int BaseVersion = 1;
/// <summary>Layout of a project edited as JSON (<see cref="MoveFramePositions"/>): indented like <see cref="ToJson"/>.</summary>
private static readonly JsonSerializerOptions IndentedJson = new() { WriteIndented = true };
/// <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" };
/// <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 };
@@ -811,8 +811,11 @@ public sealed record ProjectSettings
}
}
// LF on every OS (not Environment.NewLine): the text is hashed, and a project must read and hash alike on Windows and on
// the Linux server.
[JsonSourceGenerationOptions(
WriteIndented = true,
NewLine = "\n",
PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase,
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
UseStringEnumConverter = true,
@@ -157,7 +157,7 @@ internal sealed class RenderJobHandler(ChronosDatabase db, ProcessingOptions opt
|| await db.Projects.GetVersionAsync(versionId, cancellationToken).ConfigureAwait(false) is not { } version
|| (project is { } named && version.ProjectId != named)
|| await db.Projects.GetAsync(version.ProjectId, cancellationToken).ConfigureAwait(false) is not { } of || of.SequenceId != sequence.Id
|| (parameters.SettingsJson is { } embedded && !ProjectContent.Verifies(embedded, version.ContentHash)))
|| (parameters.SettingsJson is { } embedded && !ProjectContent.MatchesHash(embedded, version.ContentHash)))
return (project, null);
return (version.ProjectId, versionId);
}
@@ -167,7 +167,7 @@ internal sealed class WorkspaceRenderJobHandler(ChronosDatabase db, ArchiveServi
else if (named is not null) portable = version?.SettingsJson ?? throw new InvalidOperationException(Loc.L("Errors.Workspace.RenderVersion"));
else portable = versions.Count > 0 ? versions[^1].SettingsJson : ProjectContent.ToPortable(bundle.Project, media.Photos);
// Recorded only for the settings it holds (a version is never named for settings it did not render).
Guid? versionId = version is not null && ProjectContent.Verifies(portable, version.ContentHash) ? version.Id : null;
Guid? versionId = version is not null && ProjectContent.MatchesHash(portable, version.ContentHash) ? version.Id : null;
var settings = portable.Contains("pendingFrames", StringComparison.OrdinalIgnoreCase) ? Place(portable, media.Photos) : portable;
var placed = ProjectStore.Parse(settings);
var excluded = placed.ExcludedFrames.ToHashSet();
@@ -217,7 +217,10 @@ internal sealed class WorkspaceSendJobHandler(ChronosDatabase db, ArchiveService
if (entry.SettingsHash is { Length: > 0 } hash)
{
var history = await home.HistoryAsync(projectId, null, ReplayedLookBack, ct).ConfigureAwait(false);
same = history.FirstOrDefault(v => string.Equals(v.ContentHash, hash, StringComparison.OrdinalIgnoreCase));
// Of the same content whatever its line ends: a version stored by a Windows build before every build wrote LF
// holds the CRLF text and its hash.
same = history.FirstOrDefault(v => string.Equals(v.ContentHash, hash, StringComparison.OrdinalIgnoreCase)
|| (v.SettingsJson is { Length: > 0 } text && ProjectContent.MatchesHash(text, hash)));
}
if (same is not null)
{
+3 -3
View File
@@ -1133,7 +1133,6 @@ public sealed class WorkspaceSync(WorkspaceStore store, string clientName)
var workspace = bundle.Workspace!;
var media = project.ReadMedia();
var portable = Portable(bundle.Project, media) ?? throw MediaMissing(project.ProjectId);
var hash = ProjectContent.Hash(portable);
var versions = project.Versions();
var locals = Unpushed(versions, bundle);
// Saved after a gap, the new version would hang from the versions before it and the ones after it would be left out.
@@ -1141,7 +1140,8 @@ public sealed class WorkspaceSync(WorkspaceStore store, string clientName)
var (tipId, tipNumber, tipHash) = locals.Count > 0
? (locals[^1].Id, locals[^1].Number, locals[^1].ContentHash)
: (workspace.Base?.VersionId, workspace.Base?.Number ?? 0, workspace.Base?.ContentHash);
if (hash == tipHash || SameAsTip(versions, bundle, locals, portable, media)) return null;
// The tip's hash may be of the text with CRLF (saved by a Windows build before every build wrote LF).
if (ProjectContent.MatchesHash(portable, tipHash) || SameAsTip(versions, bundle, locals, portable, media)) return null;
var sync = project.ReadSync();
// A restore taken back since (Undo, Ctrl+Z) no longer shows in the working state: that version is no restore.
var restoredFrom = sync.RestoredFrom is { } restored && StillRestores(project, restored, Tip(project, bundle, locals), portable, media?.Photos ?? NoFrames)
@@ -1229,7 +1229,7 @@ public sealed class WorkspaceSync(WorkspaceStore store, string clientName)
}
var tipHash = locals.Count > 0 ? locals[^1].ContentHash : workspace.Base?.ContentHash;
var modified = !bundle.IsReadOnly && (Portable(bundle.Project, media) is not { } portable
|| (ProjectContent.Hash(portable) != tipHash && !SameAsTip(versions, bundle, locals, portable, media)));
|| (!ProjectContent.MatchesHash(portable, tipHash) && !SameAsTip(versions, bundle, locals, portable, media)));
var behind = head is not null && head.Id != workspace.Base?.VersionId ? Math.Max(1, head.Number - (workspace.Base?.Number ?? 0)) : 0;
// A local commit the home stored although its answer was lost reads as behind by the commits it holds: they are ours.
if (head is not null && locals.Any(v => v.Id == head.Id)) behind = 0;
@@ -344,6 +344,39 @@ public sealed class ProjectContentTests
Assert.Equal(portable, ProjectContent.Place(portable, Frames(Photo(2))));
}
[Test]
public void TheTextAndItsHashAreTheSameOnEveryOs()
{
// Built with explicit "\r\n", not Environment.NewLine, so the test fails without the fix on Linux too.
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);
Assert.False(lf.Contains('\r', StringComparison.Ordinal), "portable");
Assert.False(new ProjectSettings().ToJson().Contains('\r', StringComparison.Ordinal), "ToJson");
Assert.Equal(lf, ProjectContent.Canonical(crlf));
Assert.Equal(lf, ProjectContent.ToPortable(crlf, NoFrames()));
// A version stored by a Windows build before (CRLF text, CRLF hash) holds what the LF text holds.
foreach (var photos in new[] { frames, NoFrames() })
{
Assert.True(ProjectContent.SameChoices(crlf, lf, photos));
Assert.True(ProjectContent.SameChoices(lf, crlf, photos));
}
Assert.True(ProjectContent.MatchesHash(lf, ProjectContent.Hash(crlf)));
Assert.True(ProjectContent.MatchesHash(crlf, ProjectContent.Hash(lf)));
Assert.True(ProjectContent.MatchesHash(lf, ProjectContent.Hash(lf).ToUpperInvariant()));
Assert.False(ProjectContent.MatchesHash(lf, ProjectContent.Hash(ProjectContent.ToPortable(Positions([2], 2, 0), frames))));
Assert.False(ProjectContent.MatchesHash(lf, null));
Assert.False(ProjectContent.MatchesHash(lf, "abc"));
// The integrity check stays exact.
Assert.True(ProjectContent.Verifies(crlf, ProjectContent.Hash(crlf)));
Assert.False(ProjectContent.Verifies(lf, ProjectContent.Hash(crlf)));
// Other choices are still other choices.
Assert.False(ProjectContent.SameChoices(crlf, ProjectContent.ToPortable(Positions([2], 2, 0), frames), frames));
}
private static FramePhotos NoFrames() => new([]);
[Test]
public void TextThatIsNoProjectIsRefused()
{
@@ -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);
}
@@ -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()
{
@@ -118,6 +118,30 @@ public abstract class WorkspaceMergeTests(TestContext context) : DatabaseTest(co
Assert.Null(await sync.CommitAsync(id, cancellationToken: fx.Ct));
}
[Test]
public async Task ABaseSavedWithTheOtherOsLineEndsReadsAsTheWorkingState()
{
var fx = await FixtureAsync();
Assert.True(fx.Frames.All(f => f.Sha256 is { Length: 64 }));
var projects = fx.Archive.Service.Projects;
var main = await projects.MainAsync(fx.Sequence.Id, fx.Ct);
// The head a build before stored on the other OS (CRLF where this build writes LF, and the reverse on Linux).
var foreign = ProjectServiceTests.Foreign(ProjectServiceTests.Draft(await projects.HeadAsync(main.Id, fx.Ct),
new ProjectSettings { ExcludedFrames = [1], HeroFrame = 3 }, fx.Frames));
Assert.Equal(PushOutcome.Stored, (await projects.PushAsync(main.Id, foreign, fx.Ct)).Outcome);
var (_, sync) = fx.Workspace();
var project = await fx.CheckoutAsync(sync);
var id = project.ProjectId;
Assert.Equal(foreign.ContentHash, project.ReadBundle().Workspace!.Base!.ContentHash);
Assert.SequenceEqual([1], (await sync.OpenAsync(id, fx.Ct)).Working.ExcludedFrames);
// Nothing edited here: in step with its base, and nothing to save.
Assert.Equal(WorkspaceState.InSync, (await sync.StatusAsync(id, fx.Home, fx.Ct)).State);
Assert.Null(await sync.CommitAsync(id, cancellationToken: fx.Ct));
Assert.Equal(foreign.Id, (await fx.Home.HeadAsync(id, fx.Ct)).Id);
}
[Test]
public async Task ABaseNamingAPhotoByItsHashReadsAsTheWorkingStateOnMediaThatHaveNotLearntIt()
{