feat(editor): visual crop, rotate/mirror/flip/straighten, colour looks (owner review 1 phase 4) (#26)
CI / Build and test (push) Successful in 8m19s
CI / Windows tests and installer (push) Skipped
CI / YAML check (push) Successful in 7s
Release / Build, test and publish (push) Successful in 12m9s
CI / PostgreSQL 16 integration (push) Successful in 7m49s
CI / PostgreSQL 17 integration (push) Successful in 7m19s
CI / Docker image (push) Successful in 46s
Release / Server image (push) Successful in 1m14s

Owner review 1 R5 + R6. Camera rotation, mirror, flip, straighten and crop handles locked to the output; an Exposure Look group; Export output size ("proportions win"); settings format 2 with older-node gates. Also fixes project text and hashes differing between Windows and Linux.

Closes #19
Closes #20

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Alberto Balbo <alberto.balbo.96@gmail.com>
This commit was merged in pull request #26.
This commit is contained in:
Alby96andClaude Opus 5.5 authored and Alby96 committed 2026-11-05 01:09:09 +01:00
1 parent db389a54f2
commit 188b2c2e55
355 files changed
+10549 -1061

No files matched your search

@@ -39,6 +39,23 @@ public sealed class AnalysisJobTests(TestContext context)
Longitude = 12.3,
});
[Test]
public async Task LightAnalysisAdvisesTheAspectOfTheTurnedView()
{
await using var fx = await ProcessingFixture.CreateAsync(context);
var sequence = await fx.AddAsync(Flickering());
var turned = new ProjectSettings { Camera = new CameraSettings { Rotate = 90 } };
await fx.Db.Sequences.EditAsync(sequence.Id, new SequenceEdit { SettingsJson = turned.ToJson() }, null, fx.Ct);
await fx.StartEngineAsync();
var job = await fx.EnqueueAsync(ProcessingJobs.LightAnalysis([sequence.Id], sequence.DisplayTitle));
await fx.WaitForAsync(job.Id, JobState.Done);
var project = ProjectSettings.FromJson(await File.ReadAllTextAsync(fx.Folder(sequence).ProjectPath, fx.Ct));
Assert.Equal(90, project.Camera.Rotate);
Assert.Equal("9:16", project.Camera.Aspect.AutoValue);
}
[Test]
public async Task LightAnalysisFillsAutoValuesAndKeepsManualOnes()
{
@@ -0,0 +1,54 @@
using Chronos.Core.Diagnostics.Synthetic;
using Chronos.Core.Localization;
using Chronos.Core.Project;
using Chronos.Data.Archiving;
using Chronos.Data.Processing;
using Chronos.Testing;
namespace Chronos.Data.Tests.Processing;
/// <summary>
/// The project of a sequence as the engine reads and writes it (owner review 1, phase 4): a format-1 project stays format 1
/// through every edit that uses nothing newer, a transform raises it to 2 and its removal brings it back, and settings of
/// a newer Chronos are refused saying so in the user's language.
/// </summary>
[Category("processing")]
public sealed class ProjectStoreTests(TestContext context)
{
[Test]
public async Task AnEditNeverRaisesTheFormatOfAProjectThatUsesNothingNewer()
{
await using var fixture = await ProcessingFixture.CreateAsync(context);
var sequence = await fixture.AddAsync(SyntheticSequence.Create(new SyntheticSequenceOptions { Width = 64, Height = 48, FrameCount = 4 }));
var store = new ProjectStore(fixture.Db, new SequenceWriter(new ArchiveServiceOptions { Owner = "test", LeaseWait = TimeSpan.FromSeconds(20) }));
async Task<int> StoredFormatAsync()
{
var row = (await fixture.Db.Sequences.GetAsync(sequence.Id, fixture.Ct))!;
var file = await File.ReadAllTextAsync(fixture.Folder(sequence).ProjectPath, fixture.Ct);
Assert.Equal(row.SettingsJson, file, "the index and project.json hold the same text");
return ProjectContent.FormatOf(file);
}
Assert.True(await store.UpdateAsync(fixture.Archive.Paths, sequence, p => p with { Exposure = p.Exposure with { ExposureOffsetEv = 0.5 } }, fixture.Ct));
Assert.Equal(ProjectSettings.BaseVersion, await StoredFormatAsync());
// A read project of the base format is never stamped higher, even when it says the highest this Chronos reads.
Assert.True(await store.UpdateAsync(fixture.Archive.Paths, sequence, p => p with { Version = ProjectSettings.CurrentVersion, HeroFrame = 2 }, fixture.Ct));
Assert.Equal(ProjectSettings.BaseVersion, await StoredFormatAsync());
Assert.True(await store.UpdateAsync(fixture.Archive.Paths, sequence, p => p with { Camera = p.Camera with { Rotate = 90 } }, fixture.Ct));
Assert.Equal(2, await StoredFormatAsync());
Assert.True(await store.UpdateAsync(fixture.Archive.Paths, sequence, p => p with { Camera = p.Camera with { Rotate = 0 } }, fixture.Ct));
Assert.Equal(ProjectSettings.BaseVersion, await StoredFormatAsync());
Assert.False(await store.UpdateAsync(fixture.Archive.Paths, sequence, p => p with { Version = ProjectSettings.BaseVersion }, fixture.Ct), "nothing changed");
}
[Test]
public void SettingsOfANewerChronosAreRefusedSayingSo()
{
var refused = Assert.Throws<InvalidDataException>(() => ProjectStore.Parse("""{"version":3,"camera":{"rotate":90}}"""));
Assert.Equal(Loc.L("Errors.Render.NewerSettings"), refused.Message);
Assert.Equal(90, ProjectStore.Parse("""{"version":2,"camera":{"rotate":90}}""").Camera.Rotate);
// Text that is not a project keeps its own reason.
Assert.NotEqual(Loc.L("Errors.Render.NewerSettings"), Assert.Throws<InvalidDataException>(() => ProjectStore.Parse("[1]")).Message);
}
}
@@ -599,6 +599,105 @@ public sealed class RenderJobTests(TestContext context)
Assert.SequenceEqual(["mjpeg", "gif"], ProcessingJobs.Split(posted, 96, 64).Select(p => p.Codec));
}
/// <summary>
/// Owner review 1, phase 4: a render job carries the output size its settings give it (the chosen proportions win over a
/// fixed-size preset, a quarter turn swaps a source-sized output) and the settings format its render needs, so a render
/// node is matched to what it will write; a job posted by an older client gets both from the server (<see cref="ProcessingJobs.Split"/>).
/// </summary>
[Test]
public void RenderJobsCarryTheSizeAndFormatOfTheirSettings()
{
var sequence = new Sequence { Id = Guid.CreateVersion7(), ArchiveId = Guid.CreateVersion7(), Folder = "Synthetic", Title = "Roof" };
var uhd = new ExportSettings { Preset = new Auto<string>().WithManual("4k-h264") };
var portrait = new ProjectSettings { Camera = new CameraSettings { Aspect = new Auto<string>().WithManual("9:16") } };
static Chronos.Protocol.RenderJobParameters Read(Chronos.Data.Archiving.Jobs.ArchiveJobRequest request) => ProcessingJobs.ReadRender(request.ParametersJson).Parameters;
var adapted = Read(ProcessingJobs.Render(sequence, uhd, 6000, 4000, portrait));
Assert.Equal((2160, 3840, 2), (adapted.Width, adapted.Height, adapted.RequiredSettingsFormat));
var source = Read(ProcessingJobs.Render(sequence, uhd, 6000, 4000, new ProjectSettings()));
Assert.Equal((3840, 2160, 1), (source.Width, source.Height, source.RequiredSettingsFormat));
// A source-sized output turns with the picture; the turn needs format 2.
var png = new ExportSettings { Preset = new Auto<string>().WithManual("png-sequence") };
var turned = Read(ProcessingJobs.Render(sequence, png, 6000, 4000, new ProjectSettings { Camera = new CameraSettings { Rotate = 90 } }));
Assert.Equal((4000, 6000, 2), (turned.Width, turned.Height, turned.RequiredSettingsFormat));
// The sequence's own settings when the job embeds none.
var own = Read(ProcessingJobs.Render(sequence with { SettingsJson = portrait.ToJson() }, uhd, 6000, 4000));
Assert.Equal((2160, 3840, 2), (own.Width, own.Height, own.RequiredSettingsFormat));
// Posted by an older client (the preset's size, no format) with a batch: the server sizes each job for the settings.
var posted = Read(ProcessingJobs.Render(sequence, uhd with { Batch = ["1080p-h264"] }, 6000, 4000)) with { SettingsJson = portrait.ToJson() };
Assert.Equal((3840, 2160, 1), (posted.Width, posted.Height, posted.RequiredSettingsFormat));
var split = ProcessingJobs.Split(posted, 6000, 4000, portrait);
Assert.SequenceEqual([(2160, 3840, 2), (1080, 1920, 2)], split.Select(p => (p.Width, p.Height, p.RequiredSettingsFormat)));
Assert.Equal(split[0], ProcessingJobs.Routed(split[0], portrait, 6000, 4000), "a size already adapted stays");
// The sequence's settings change between posting and routing: the size comes from the preset again, never from the
// size a newer client already adapted (2160×2160 for 1:1 would adapt to 2160×1215 for 16:9).
var square = new ProjectSettings { Camera = new CameraSettings { Aspect = new Auto<string>().WithManual("1:1") } };
var wide = new ProjectSettings { Camera = new CameraSettings { Aspect = new Auto<string>().WithManual("16:9") } };
var squared = Read(ProcessingJobs.Render(sequence, uhd, 6000, 4000, square));
Assert.Equal((2160, 2160), (squared.Width, squared.Height));
var rerouted = ProcessingJobs.Routed(squared, wide, 6000, 4000);
Assert.Equal((3840, 2160), (rerouted.Width, rerouted.Height), "the preset's box adapted to the new aspect");
var tall = Read(ProcessingJobs.Render(sequence, uhd, 6000, 4000, new ProjectSettings { Camera = new CameraSettings { Aspect = new Auto<string>().WithManual("4:5") } }));
Assert.Equal((2160, 2700), (tall.Width, tall.Height));
Assert.Equal((3840, 2160), (ProcessingJobs.Routed(tall, wide, 6000, 4000).Width, ProcessingJobs.Routed(tall, wide, 6000, 4000).Height));
Assert.Equal((3840, 2160, 1), ProcessingJobs.Split(posted, 6000, 4000).Select(p => (p.Width, p.Height, p.RequiredSettingsFormat)).First(),
"settings that cannot be read keep the size the job was posted with");
// What the desktop asks of a server before a render: the highest format of the export and its batch.
Assert.Equal(1, ProcessingJobs.RequiredFormat(portrait, png, 6000, 4000), "a source-sized output keeps the proportions");
Assert.Equal(2, ProcessingJobs.RequiredFormat(portrait, png with { Batch = ["4k-h264"] }, 6000, 4000));
}
/// <summary>
/// Owner review 1, phase 4, end to end: a turned, portrait project with a look renders each output at the size its job
/// was routed with (the fixed box adapted to 9:16, the source-sized output on the turned view) and records it so.
/// </summary>
[Test]
public async Task ATurnedPortraitProjectRendersAtTheSizeItsJobWasRoutedWith()
{
await using var fx = await ProcessingFixture.CreateAsync(context);
var sequence = await fx.AddAsync(Scene());
await fx.StartEngineAsync();
var settings = new ProjectSettings
{
Camera = new CameraSettings { Aspect = new Auto<string>().WithManual("9:16"), Rotate = 90, Straighten = 2 },
Look = new LookSettings { Filter = "sepia", Strength = 0.6 },
};
var request = ProcessingJobs.Render(sequence, Mjpeg with { Batch = ["png-sequence"] }, 96, 64, settings);
var routed = ProcessingJobs.ReadRender(request.ParametersJson).Parameters;
Assert.Equal((54, 96, 2), (routed.Width, routed.Height, routed.RequiredSettingsFormat));
await fx.WaitForAsync((await fx.EnqueueAsync(request)).Id, JobState.Done);
var renders = (await fx.Db.Renders.ListBySequenceAsync(sequence.Id, fx.Ct)).OrderBy(r => r.OutputPath, StringComparer.Ordinal).ToList();
Assert.SequenceEqual([(54, 96), (54, 96)], renders.Select(r => (r.Width, r.Height)));
var pngs = Directory.GetFiles(Path.Combine(fx.Folder(sequence).Exports, "clip-PNG")).Order().ToList();
Assert.Equal(Frames, pngs.Count);
using var decoded = DecoderFactory.CreateServer().Decode(new DecodeRequest(pngs[^1]));
Assert.Equal((54, 96), (Assert.NotNull(decoded).Pixels.Width, decoded.Pixels.Height));
}
/// <summary>Settings of a newer Chronos fail the render with the reason in the user's language, never as an English message.</summary>
[Test]
public async Task AnOverFormatRenderFailsSayingANewerChronosIsNeeded()
{
await using var fx = await ProcessingFixture.CreateAsync(context);
var sequence = await fx.AddAsync(Scene());
await fx.StartEngineAsync();
var parameters = ProcessingJobs.ReadRender(ProcessingJobs.Render(sequence, Mjpeg, 96, 64).ParametersJson).Parameters with
{
SettingsJson = """{"version":3,"camera":{"rotate":90},"grade":{"lut":"teal"}}""",
};
var request = new Chronos.Data.Archiving.Jobs.ArchiveJobRequest(JobKind.Render, [sequence.Id], "newer",
System.Text.Json.JsonSerializer.Serialize(parameters, Chronos.Protocol.ProtocolJson.Default.RenderJobParameters), JobPriority.User);
Assert.Equal(3, ProcessingJobs.ReadRender(ProcessingJobs.Render(sequence, Mjpeg, 96, 64,
ProjectSettings.FromJson(parameters.SettingsJson, allowNewer: true)).ParametersJson).Parameters.RequiredSettingsFormat, "routed to none older");
var failed = await fx.WaitForAsync((await fx.EnqueueAsync(request)).Id, JobState.Failed);
Assert.Equal(Loc.L("Errors.Render.NewerSettings"), failed.Error);
Assert.Empty(await fx.Db.Renders.ListBySequenceAsync(sequence.Id, fx.Ct));
}
/// <summary>MJPEG job parameters whose preset JSON is <paramref name="presetJson"/>.</summary>
private static string WithPreset(string presetJson) => System.Text.Json.JsonSerializer.Serialize(
new Chronos.Protocol.RenderJobParameters("MJPEG", presetJson, "mjpeg", 96, 64, false, null), Chronos.Protocol.ProtocolJson.Default.RenderJobParameters);
@@ -21,6 +21,102 @@ public sealed class ProjectMergeTests
private static PendingFrame Waiting(FramePhoto photo, bool excluded = false, bool hero = false) =>
new() { Sha256 = photo.Sha256, Size = photo.Size, CapturedAt = photo.CapturedAt, Excluded = excluded, Hero = hero };
[Test]
public void ATurnOnOneSideAndALookOnTheOtherMergeIntoFormatTwo()
{
var basis = new ProjectSettings { Exposure = new ExposureSettings { ExposureOffsetEv = 0.2 } };
var ours = basis with { Camera = basis.Camera with { Rotate = 90, Straighten = 1.5 } };
var theirs = basis with { Look = new LookSettings { Filter = "sepia", Strength = 0.6 } };
var result = ProjectMerge.MergeWithConflicts(basis, ours, theirs);
Assert.False(result.HasConflicts);
Assert.Equal((90, 1.5), (result.Merged.Camera.Rotate, result.Merged.Camera.Straighten));
Assert.Equal("sepia", result.Merged.Look?.Filter);
Assert.Equal(2, result.Merged.Version);
Assert.Contains("\"version\": 2", result.Merged.ToJson());
// One side takes the turn away while the other keeps the look: the format the members need, not the one taken.
var undone = ProjectMerge.MergeWithConflicts(result.Merged, result.Merged with { Camera = basis.Camera }, result.Merged with { Look = null }).Merged;
Assert.Equal(1, ProjectContent.FormatOf(undone.ToJson()));
Assert.Equal(basis.ToJson(), undone.ToJson());
}
[Test]
public void BothSidesCroppingGiveOneCropConflict()
{
var basis = new ProjectSettings { Camera = new CameraSettings { Aspect = new Auto<string>().WithManual("9:16") } };
var ours = basis with { Camera = basis.Camera with { Crop = [0.1, 0, 0.3, 0.9] } };
var theirs = basis with { Camera = basis.Camera with { Crop = [0.5, 0.05, 0.2, 0.6] } };
var result = ProjectMerge.MergeWithConflicts(basis, ours, theirs);
// The box is one value: never the x of one side and the width of the other.
Assert.SequenceEqual(["camera.crop"], result.Conflicts.Select(c => c.Path));
Assert.SequenceEqual([0.1, 0, 0.3, 0.9], Assert.NotNull(result.Merged.Camera.Crop));
Assert.SequenceEqual([0.5, 0.05, 0.2, 0.6], Assert.NotNull(
ProjectMerge.MergeWithConflicts(basis, ours, theirs, new HashSet<string> { "camera.crop" }).Merged.Camera.Crop));
// With a mirror on their side too, the crop and the mirror are one conflict: their crop is in the mirrored frame.
var mirrored = theirs with { Camera = theirs.Camera with { Mirror = true } };
var coupled = ProjectMerge.MergeWithConflicts(basis, ours, mirrored);
Assert.SequenceEqual(["camera.mirror"], coupled.Conflicts.Select(c => c.Path));
Assert.SequenceEqual([0.1, 0, 0.3, 0.9], Assert.NotNull(coupled.Merged.Camera.Crop), "ours: our crop");
Assert.False(coupled.Merged.Camera.Mirror, "and unmirrored");
var taken = ProjectMerge.MergeWithConflicts(basis, ours, mirrored, new HashSet<string> { "camera.mirror" }).Merged;
Assert.SequenceEqual([0.5, 0.05, 0.2, 0.6], Assert.NotNull(taken.Camera.Crop));
Assert.True(taken.Camera.Mirror);
}
/// <summary>
/// A turn of a project without a crop changes only the orientation and the aspect (nothing else to move), so member by
/// member a crop or keyframes the other side placed in the unturned frame would apply to the turned one: one conflict.
/// </summary>
[Test]
public void ATurnOnOneSideAndAFramingOnTheOtherAreOneConflict()
{
var basis = new ProjectSettings { Camera = new CameraSettings { Aspect = new Auto<string>().WithManual("16:9") } };
var turned = basis with { Camera = Chronos.Core.Imaging.Geometry.OrientationEdit.Apply(basis.Camera, Chronos.Core.Imaging.Geometry.OrientationOp.RotateRight) };
Assert.Null(turned.Camera.Crop);
var cropped = basis with { Camera = basis.Camera with { Crop = [0.1, 0.2, 0.6, 0.3375] } };
foreach (var (ours, theirs) in new[] { (turned, cropped), (cropped, turned) })
{
var result = ProjectMerge.MergeWithConflicts(basis, ours, theirs);
Assert.SequenceEqual(["camera.rotate"], result.Conflicts.Select(c => c.Path));
Assert.Equal(ours.ToJson(), result.Merged.ToJson(), "ours whole: the orientation and the framing of one side");
var other = ProjectMerge.MergeWithConflicts(basis, ours, theirs, new HashSet<string> { "camera.rotate" }).Merged;
Assert.Equal(theirs.ToJson(), other.ToJson());
}
// Keyframes placed in the unturned frame, on the camera and on a photo that waits.
var keyed = basis with
{
Camera = basis.Camera with { Keyframes = [new CameraKey(0, 0.8, 0.5, 2, 0)] },
};
Assert.SequenceEqual(["camera.rotate"], ProjectMerge.MergeWithConflicts(basis, turned, keyed).Conflicts.Select(c => c.Path));
var photo = Photo(1);
var waiting = basis with { PendingFrames = [Waiting(photo) with { Keyframes = [new CameraKey(0, 0.8, 0.5, 2, 0)] }] };
Assert.SequenceEqual(["camera.rotate"], ProjectMerge.MergeWithConflicts(basis, waiting, turned).Conflicts.Select(c => c.Path));
// Anything else on the other side merges with the turn as before.
var brighter = basis with { Exposure = basis.Exposure with { ExposureOffsetEv = 0.3 } };
var merged = ProjectMerge.MergeWithConflicts(basis, turned, brighter);
Assert.False(merged.HasConflicts);
Assert.Equal((90, 0.3), (merged.Merged.Camera.Rotate, merged.Merged.Exposure.ExposureOffsetEv));
}
[Test]
public void AFormatThreeSideIsNeverMerged()
{
var basis = new ProjectSettings { Camera = new CameraSettings { Rotate = 90 } };
var newer = ProjectSettings.FromJson("""{ "version": 3, "camera": { "rotate": 180 }, "look": { "filter": "film" } }""", allowNewer: true);
var mine = basis with { Look = new LookSettings { Filter = "warm" } };
Assert.Throws<NewerSettingsException>(() => ProjectMerge.MergeWithConflicts(basis, mine, newer));
Assert.Throws<NewerSettingsException>(() => ProjectMerge.MergeWithConflicts(basis, newer, mine));
Assert.Equal(3, ProjectMerge.MergeWithConflicts(basis, basis, newer).Merged.Version);
}
[Test]
public void EntriesOfOnePhotoMergeAsOneWithThePositionsOfBoth()
{
@@ -69,7 +165,7 @@ public sealed class ProjectMergeTests
public void SettingsOfANewerChronosAreNeverMergedWithThisOnes()
{
var basis = new ProjectSettings { Exposure = new ExposureSettings { ExposureOffsetEv = 0.1 } };
var newer = ProjectSettings.FromJson("""{ "version": 2, "exposure": { "exposureOffsetEv": 0.5 }, "grade": { "look": "film" } }""", allowNewer: true);
var newer = ProjectSettings.FromJson("""{ "version": 3, "exposure": { "exposureOffsetEv": 0.5 }, "grade": { "look": "film" } }""", allowNewer: true);
var mine = basis with { Stack = new StackSettings { Mode = StackSetting.Median } };
// Both changed: refused, whichever side the newer one is, in a replay too.
@@ -327,7 +327,7 @@ public abstract class ProjectRecoveryTests(TestContext context) : DatabaseTest(c
var folder = fx.Paths.Sequence(sequence.Folder);
// A newer Chronos on another PC sharing the archive pushes version 2 in its settings format, and mirrors it.
var settings = """{ "version": 2, "exposure": { "exposureOffsetEv": 0.5 }, "futureThing": true }""";
var settings = """{ "version": 3, "exposure": { "exposureOffsetEv": 0.5 }, "futureThing": true }""";
var now = DateTimeOffset.UtcNow;
var future = new ProjectVersion
{
@@ -339,7 +339,7 @@ public abstract class ProjectRecoveryTests(TestContext context) : DatabaseTest(c
ClientName = "newer",
SettingsJson = settings,
ContentHash = ProjectContent.Hash(settings),
SettingsFormat = 2,
SettingsFormat = 3,
FramesVersion = head.FramesVersion,
CreatedAt = now,
StoredAt = now,
@@ -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()
{
@@ -54,6 +54,11 @@ internal sealed class FakeSyncRemote : ISyncRemote
/// <summary>Edits the server accepted, in order.</summary>
public List<UpdateSequenceRequest> Updates { get; } = [];
/// <summary>The settings format the server announces (an older server's 1).</summary>
public int SettingsFormat { get; set; } = Chronos.Core.Project.ProjectSettings.CurrentVersion;
public Task<int> SettingsFormatAsync(CancellationToken cancellationToken) => Task.FromResult(SettingsFormat);
public FakeSequence Add(string? title, IEnumerable<byte[]> originals, string? settingsJson = null,
SequenceStatus status = SequenceStatus.ProxiesBuilt | SequenceStatus.ThumbsBuilt)
{
@@ -243,6 +243,20 @@ public sealed class SyncRulesTests
Assert.Empty(SyncRules.Differences(SyncFixture.Window33, SyncFixture.Window33));
}
/// <summary>
/// Owner review 1, phase 4: the "version" member follows the content (format 2 only while a turn or a look is set), so a
/// rotation alone is one difference, the rotation's; a newer Chronos's format still differs.
/// </summary>
[Test]
public void TheDerivedFormatIsNoDifferenceOfItsOwn()
{
var plain = new ProjectSettings().ToJson();
var turned = new ProjectSettings { Camera = new CameraSettings { Rotate = 90 } }.ToJson();
Assert.Contains("\"version\": 2", turned);
Assert.SequenceEqual(["camera.rotate"], SyncRules.Differences(turned, plain).Select(d => d.Path));
Assert.Contains(SyncRules.Differences("""{"version":3,"camera":{"rotate":90}}""", turned, max: 5), d => d.Path == "version");
}
[Test]
public void PayloadDifferencesListTheSequenceFieldsBeforeTheSettings()
{
@@ -701,6 +701,35 @@ public sealed class SyncServiceTests(TestContext context)
Assert.Equal(SyncStatus.InSync, recovered.Status);
}
/// <summary>
/// Owner review 1, phase 4: settings an older server cannot read (a turn needs format 2) stay on this PC, the sync row
/// saying why; it would store them and then fail every render of them. Settings of the base format are sent as before.
/// </summary>
[Test]
public async Task SettingsAnOlderServerCannotReadStayHere()
{
await using var f = await SyncFixture.CreateAsync(context);
var photos = f.NewPhotos(1);
var local = await f.LocalAsync("Harbour", photos);
var remote = f.Remote.Add("Harbour", photos);
f.Remote.SettingsFormat = ProjectSettings.BaseVersion;
await f.Sync.LinkAsync(f.Server, remote.Id, local.Id, f.Ct);
await f.RefreshAsync();
await f.EditLocalSettingsAsync(local.Id, new ProjectSettings { Camera = new CameraSettings { Rotate = 90 } }.ToJson());
await f.RefreshAsync();
Assert.Null(remote.SettingsJson);
Assert.Empty(f.Remote.Updates);
var entry = await f.EntryAsync("Harbour");
Assert.Equal(SyncStatus.LocalAhead, entry.Status);
Assert.Equal(Loc.L("Tooltips.Server.NeedsNewerServer"), entry.Link!.Error);
await f.EditLocalSettingsAsync(local.Id, SyncFixture.Window41);
await f.RefreshAsync();
Assert.True(SyncRules.SameSettings(SyncFixture.Window41, remote.SettingsJson), "the base format is sent");
Assert.Null((await f.EntryAsync("Harbour")).Link!.Error);
}
[Test]
public async Task WithoutTheEditRightThisPcsEditsWaitInsteadOfFailing()
{
@@ -118,6 +118,58 @@ 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 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()
{
@@ -332,7 +384,7 @@ public abstract class WorkspaceMergeTests(TestContext context) : DatabaseTest(co
Assert.Equal(local.Id, sync.Unpushed(id).Single().Id);
Assert.Equal(local.SettingsJson, sync.Unpushed(id).Single().SettingsJson);
var working = (await sync.OpenAsync(id, fx.Ct)).Working;
Assert.Equal((ProjectSettings.CurrentVersion, 0.3), (working.Version, working.Exposure.ExposureOffsetEv));
Assert.Equal((ProjectSettings.BaseVersion, 0.3), (working.Version, working.Exposure.ExposureOffsetEv));
Assert.SequenceEqual([1], working.ExcludedFrames);
Assert.Equal(WorkspaceState.Conflict, (await sync.PullAsync(id, fx.Home, fx.Ct)).Status.State);
@@ -455,7 +455,7 @@ public abstract class WorkspaceTests(TestContext context) : DatabaseTest(context
var (_, sync) = fx.Workspace();
var project = await fx.CheckoutAsync(sync);
var bundle = project.ReadBundle();
File.WriteAllText(project.BundlePath, bundle.ToJson().Replace("\"version\": 1", "\"version\": 2", StringComparison.Ordinal));
File.WriteAllText(project.BundlePath, bundle.ToJson().Replace("\"version\": 1", "\"version\": 3", StringComparison.Ordinal));
var session = await sync.OpenAsync(project.ProjectId, fx.Ct);
Assert.True(session.IsReadOnly);