fix(phase4): close the owner review 1 phase 4 findings

Routing sizes render jobs from the resolved preset, and the node wait
applies the same routing as the claim, so a re-routed job neither keeps a
stale size nor waits for a node that will never take it. Settings an older
server cannot read stay on this side for the remote editor, archive sync
and workspace push, and the reason is shown where it applies. A turn on
one side and a framing on the other merge as one conflict.

Orientation and framing fixes: an out-of-range crop turns with the content
it shows, the aspect text transposes exactly, the Rotation row counts
turns as shown on screen, and Reset framing undoes the orientation press
by press, so keyframes and aspect stay on their content. The advisor
places the horizon in the view as shown. A look at zero strength is
cleared and no longer reaches the motion vectors.

Preview changes: the middle button pans, a press inside a box with no
slack pans while zoomed, the selected box shows a ring, and screen readers
hear when the crop value changes. Tooltips in en and it updated; stale
translations of changed tooltips removed so they fall back to English.

Test changes: the pinned hash is OS-independent, and the tautological
encoder and warning assertions became real checks. Added a non-screen
test of the Straighten slider binding.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-11-04 21:40:07 +01:00
1 parent 4e21aaa548
commit eeaddc2d14
83 files changed
+823 -270

No files matched your search

@@ -37,6 +37,21 @@ public sealed class CameraTabTests
foreach (var row in rows) row.Refresh();
}
[Test]
public void TheRotationRowCountsTheTurnsAsShown()
{
var camera = new CameraSettings();
foreach (var op in new[] { OrientationOp.Mirror, OrientationOp.RotateRight, OrientationOp.RotateRight, OrientationOp.Flip, OrientationOp.RotateRight })
{
var before = CameraTab.ShownTurns(camera);
camera = OrientationEdit.Apply(camera, op);
var expected = op == OrientationOp.RotateRight ? (before + 1) % 4 : (4 - before) % 4;
Assert.Equal(expected, CameraTab.ShownTurns(camera), $"after {op}");
}
Assert.Equal(3, CameraTab.ShownTurns(new CameraSettings { Rotate = 90, Mirror = true }));
Assert.Equal(1, CameraTab.ShownTurns(new CameraSettings { Rotate = 90, Mirror = true, Flip = true }));
}
[Test]
public async Task CropSizeAndPlaceMoveTheBoxLockedToTheAspect()
{
@@ -226,6 +241,9 @@ public sealed class CameraTabTests
Assert.Equal("60 %", strength.DisplayValue);
strength.Value = 1;
Assert.Null(session.Project.Look!.Strength);
// 0 % would be a look that changes nothing yet changes the text: None is the one way there.
Assert.Equal(ExposureTab.MinimumStrength, strength.Minimum);
Assert.Null(ExposureTab.WithLook(session.Project, "sepia", 0).Look, "the identity is written as no look");
Refresh(rows);
filter.Selected = filter.Options.Single(o => Equals(o.Value, "none"));
@@ -220,6 +220,10 @@ public sealed class EditPathTests
Assert.Equal(Loc.L("Editor.Step.Edited"), State(EditPath.Exposure, content, project: project with { Look = new LookSettings { Filter = "sepia" } }).Text,
"a look");
Assert.Equal(Loc.L("Common.Auto"), State(EditPath.Exposure, content, project: project with { Look = null }).Text, "no look");
Assert.Equal(Loc.L("Common.Auto"), State(EditPath.Exposure, content, project: project with { Look = new LookSettings { Filter = "sepia", Strength = 0 } }).Text,
"a look at 0 % changes no pixel");
Assert.Equal(Loc.L("Common.Auto"), State(EditPath.Exposure, content, project: project with { Look = new LookSettings { Filter = "grain" } }).Text,
"a filter this Chronos does not know renders as none");
}
[Test]
@@ -536,7 +536,7 @@ public sealed class EditorSessionTests
}
[Test]
public async Task ResetFramingClearsTheCropAndTheOrientationAndKeepsTheKeyframes()
public async Task ResetFramingClearsTheCropAndTheOrientationAndKeepsTheKeyframesOnTheirContent()
{
var framed = WithAspect("9:16", [0.2, 0, 0.3, 1]);
var key = new CameraKey(3, 0.4, 0.5, 2, 0);
@@ -553,8 +553,11 @@ public sealed class EditorSessionTests
var camera = session.Project.Camera;
Assert.Null(camera.Crop);
Assert.True(camera is { OffsetX: 0, OffsetY: 0, Rotate: 0, Mirror: false, Flip: false, Straighten: 0 });
Assert.SequenceEqual([key], camera.Keyframes, "keyframes stay");
Assert.Equal("9:16", camera.Aspect.Manual, "the aspect is not framing");
var back = OrientationEdit.Apply(OrientationEdit.Apply(OrientationEdit.Apply(OrientationEdit.Apply(OrientationEdit.Apply(framed,
OrientationOp.Flip), OrientationOp.Mirror), OrientationOp.RotateLeft), OrientationOp.RotateLeft), OrientationOp.RotateLeft);
Assert.SequenceEqual(back.Camera.Keyframes, camera.Keyframes, "keyframes stay on the content they framed");
Assert.Equal(1, camera.Keyframes.Count);
Assert.Equal("16:9", camera.Aspect.Manual, "the aspect turns back with the picture");
Assert.Equal("sepia", session.Project.Look?.Filter, "nor the look");
Assert.False(EditorSession.HasFraming(camera));
Assert.False(session.ResetFraming(), "nothing left to clear");
@@ -563,6 +566,21 @@ public sealed class EditorSessionTests
}
}
[Test]
public void ResetFramingTurnsAKeyframeBackWithThePicture()
{
var turned = new ProjectSettings();
turned = turned with { Camera = turned.Camera with { Rotate = 90, Aspect = turned.Camera.Aspect.WithManual("9:16"), Keyframes = [new CameraKey(2, 0.2, 0.3, 1.5, 0)] } };
var reset = EditorSession.WithoutFraming(turned);
var (x, y) = OrientationEdit.MapPoint(0.2, 0.3, OrientationOp.RotateLeft);
Assert.True(reset.Camera.Keyframes[0] is { CenterX: var cx, CenterY: var cy } && cx == x && cy == y, "moved as the picture turns back");
Assert.True((x, y) != (0.2, 0.3));
Assert.Equal("16:9", reset.Camera.Aspect.Manual);
var again = OrientationEdit.Apply(reset, OrientationOp.RotateRight);
Assert.True(again.Camera is { Rotate: 90 } && again.Camera.Keyframes[0] is { CenterX: 0.2, CenterY: 0.3 }, "turning again puts it where it was");
Assert.Equal("9:16", again.Camera.Aspect.Manual);
}
[Test]
public async Task ASequencePresetKeepsTheOrientationAndTheLook()
{
@@ -512,7 +512,10 @@ public sealed class EditorSmokeTests
var ratio = editor.CropLockRatio;
editor.Session.Edit(p => p with { Camera = p.Camera with { Rotate = 90, Crop = null } });
Assert.Equal(ratio, editor.CropLockRatio, "the box of the picture on screen until the turned one comes");
Assert.False(editor.CropEditable, "and it cannot be dragged meanwhile: it would land in the turned frame");
Assert.False(editor.CommitCropCommand.CanExecute(editor.EditCrop));
Assert.True(await editor.WhenIdleAsync(TimeSpan.FromSeconds(60)));
Assert.True(editor.CropEditable, "the turned picture is on screen");
var picture = (System.Windows.Media.Imaging.BitmapSource)editor.PreviewImage!;
Assert.Less(picture.PixelWidth, picture.PixelHeight, "the landscape source shows turned");
Assert.Equal(Geometry().LockRatio, editor.CropLockRatio);
@@ -77,6 +77,11 @@ public sealed class PreviewRendererTests
using var last = await renderer.RenderAsync(new PreviewRequest(EditorFixture.Sunset.Count - 1, new ProjectSettings(), 96, PreviewFraming.Source, true),
null, CancellationToken.None);
Assert.Empty(last!.Vectors);
// The flow sees the frames as the render's does, before the look (owner review 1, phase 4): the same vectors with Vivid.
var vivid = new ProjectSettings { Look = new LookSettings { Filter = "vivid" } };
using var looked = await renderer.RenderAsync(new PreviewRequest(10, vivid, 96, PreviewFraming.Source, Vectors: true), null, CancellationToken.None);
Assert.SequenceEqual(frame.Vectors, looked!.Vectors);
}
[Test]
@@ -65,6 +65,30 @@ public sealed class RemoteSequenceSourceTests(TestContext context)
}
}
/// <summary>
/// Owner review 1, phase 4: an older server (format 1) stores whatever settings it is sent and then fails every render of
/// them, so a turn or a look is never sent to it; an edit of the base format still is.
/// </summary>
[Test]
public async Task SettingsAnOlderServerCannotReadAreNotSent()
{
var (source, api, _) = Open(serverFormat: ProjectSettings.BaseVersion);
await using (source)
{
var content = await source.LoadAsync(context.Cancellation);
var turned = content.Project with { Camera = content.Project.Camera with { Rotate = 90 } };
var refused = await Assert.ThrowsAsync<EditorException>(() => source.SaveProjectAsync(turned, content.Project, context.Cancellation));
Assert.Equal(Loc.L("Tooltips.Server.NeedsNewerServer"), refused.Message);
var look = content.Project with { Look = new LookSettings { Filter = "sepia" } };
await Assert.ThrowsAsync<EditorException>(() => source.SaveProjectAsync(look, content.Project, context.Cancellation));
Assert.Empty(api.Edits);
var brighter = content.Project with { Exposure = content.Project.Exposure with { ExposureOffsetEv = 0.5 } };
await source.SaveProjectAsync(brighter, content.Project, context.Cancellation);
Assert.Count(1, api.Edits);
}
}
[Test]
public async Task SavesSendTheVersionTheyWereMadeFrom()
{
@@ -574,12 +598,12 @@ public sealed class RemoteSequenceSourceTests(TestContext context)
}
private (RemoteSequenceSource Source, FakeRemoteSequenceApi Api, RemoteSequence Remote) Open(int frames = 6, int cached = int.MaxValue,
bool readOnly = false) =>
Open(EditorFixture.Sequence(frames), cached, readOnly);
bool readOnly = false, int serverFormat = ProjectSettings.CurrentVersion) =>
Open(EditorFixture.Sequence(frames), cached, readOnly, serverFormat);
/// <summary>A server sequence whose first <paramref name="cached"/> proxies are on this PC (synthetic JPEGs).</summary>
private (RemoteSequenceSource Source, FakeRemoteSequenceApi Api, RemoteSequence Remote) Open(SyntheticSequence sunset, int cached = int.MaxValue,
bool readOnly = false)
bool readOnly = false, int serverFormat = ProjectSettings.CurrentVersion)
{
var folder = context.CreateTempDirectory("proxies");
var sequence = new Sequence
@@ -603,7 +627,7 @@ public sealed class RemoteSequenceSourceTests(TestContext context)
}
var remote = new RemoteSequence(Server, sequence, frames, files);
var api = new FakeRemoteSequenceApi(sequence, [.. frames.Select(f => f.Id)]) { SettingsJson = new ProjectSettings().ToJson() };
return (new RemoteSequenceSource(remote, api, DecoderFactory.CreateClient(null), readOnly), api, remote);
return (new RemoteSequenceSource(remote, api, DecoderFactory.CreateClient(null), readOnly, serverFormat), api, remote);
}
/// <summary>Someone on the server sets the exposure offset to 0.3 and moves the framing.</summary>
@@ -0,0 +1,81 @@
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using Chronos.App.Editor;
using Chronos.App.Shell;
using Chronos.Core.Localization;
using Chronos.Testing;
namespace Chronos.App.Tests.Editor;
/// <summary>
/// The Camera step's Straighten slider reports its use to the editor (owner review 1, R6): the NumberRow template of
/// <c>Editor/EditorPanels.xaml</c> turns <see cref="SliderActivity"/> on for the row that shows the grid, and binds its
/// <see cref="SliderActivity.IsActiveProperty"/> one way to the source <c>Editor.IsStraightening</c> of the step. Built off
/// screen on the test dispatcher (no window): the slider's activity is set as <see cref="SliderActivity"/> sets it when the
/// slider takes the focus or the mouse capture.
/// </summary>
[WindowsOnly]
[Serial]
public sealed class StraightenGridBindingTests
{
[Test]
public async Task UsingTheStraightenSliderTellsTheEditor()
{
var content = EditorFixture.Content(EditorFixture.Sunset);
var session = new EditorSession(new FakeSequenceSource(EditorFixture.Sunset, content), content, [], TimeSpan.FromMilliseconds(20));
await using (session)
{
var rows = CameraTab.FramingRows(session);
Windows.WpfApplication.Dispatcher.Invoke(() =>
{
AppResources.Merge(Application.Current);
var step = new FakeStep();
var items = new ItemsControl { ItemsSource = rows, DataContext = step };
items.Resources.MergedDictionaries.Add(new ResourceDictionary
{
Source = new Uri("pack://application:,,,/Chronos;component/Editor/EditorPanels.xaml", UriKind.Absolute),
});
var host = new Border { Child = items };
host.Measure(new Size(320, 2000));
host.Arrange(new Rect(0, 0, 320, 2000));
host.UpdateLayout();
var sliders = Descendants<Slider>(host).ToList();
Assert.Equal(rows.OfType<NumberRow>().Count(), sliders.Count);
var straighten = Assert.NotNull(sliders.SingleOrDefault(s => s.DataContext is NumberRow { ShowsGrid: true }));
Assert.Equal(Loc.L("Editor.Camera.Straighten"), ((NumberRow)straighten.DataContext).Header);
Assert.True(SliderActivity.GetTracks(straighten), "the Straighten slider is tracked");
Assert.False(sliders.Where(s => !ReferenceEquals(s, straighten)).Any(SliderActivity.GetTracks), "no other slider is");
Assert.False(step.Editor.IsStraightening);
straighten.SetCurrentValue(SliderActivity.IsActiveProperty, true);
Assert.True(step.Editor.IsStraightening, "focused or dragged: the editor shows the grid");
straighten.SetCurrentValue(SliderActivity.IsActiveProperty, false);
Assert.False(step.Editor.IsStraightening, "let go: the grid goes");
});
}
}
private static IEnumerable<T> Descendants<T>(DependencyObject root)
where T : DependencyObject
{
for (var i = 0; i < VisualTreeHelper.GetChildrenCount(root); i++)
{
var child = VisualTreeHelper.GetChild(root, i);
if (child is T match) yield return match;
foreach (var nested in Descendants<T>(child)) yield return nested;
}
}
/// <summary>The step's data context as the template reads it: <c>Editor.IsStraightening</c>.</summary>
public sealed class FakeStep
{
public FakeEditor Editor { get; } = new();
}
public sealed class FakeEditor
{
public bool IsStraightening { get; set; }
}
}
@@ -360,6 +360,19 @@ public sealed class VisualsSmokeTests
Assert.Equal(PreviewViewport.DragMode.Pan, Take(new Rect(nx - 0.03, 0.44, 0.06, 0.12), At(preview, nx + 0.06, 0.5).X), $"{label}: outside");
}
// A box that spans the view both ways (no crop) cannot move: zoomed in, a press inside pans; the middle button pans
// anywhere, inside a box that can move too.
preview.IsCompareEnabled = false;
preview.Zoom = 2;
preview.EditCrop = new Rect(0, 0, 1, 1);
preview.Press(At(preview, 0.5, 0.5));
Assert.Equal(PreviewViewport.DragMode.Pan, preview.Dragging, "zoomed, the whole view: pan");
preview.EndDrag(commit: false);
preview.EditCrop = new Rect(0.4, 0.4, 0.2, 0.2);
preview.PressPan(At(preview, 0.5, 0.5));
Assert.Equal(PreviewViewport.DragMode.Pan, preview.Dragging, "middle button inside a box");
preview.EndDrag(commit: false);
// Not editable: no handle and no box to take, the divider and pan only.
preview.CropEditable = false;
preview.EditCrop = new Rect(0.4, 0.4, 0.2, 0.2);
@@ -286,6 +286,22 @@ public sealed class ServerHomeTests(TestContext context)
await menu.SyncAsync();
Assert.Equal(before, host.Store.Find(projectId)!.ReadBundle().Workspace!.Base!.VersionId, "nothing was sent");
// Saved as a version with the turn, then turned back: the working state is of the base format, but the version
// waiting to be sent is not. Sync stays disabled, and the workspace itself never sends it (Send first, Delete,
// Resolve reach the host without the menu's gate), saying why.
await host.SaveVersionAsync(projectId, null, bed.Ct);
Assert.True(session.Edit(p => p with { Camera = p.Camera with { Rotate = 0 } }));
Assert.True(await session.FlushAsync());
await menu.RefreshAsync();
Assert.Equal(ProjectSettings.BaseVersion, session.Project.WrittenFormat);
Assert.Equal(2, menu.Status!.UnpushedFormat);
Assert.Equal(Loc.L("Tooltips.Server.NeedsNewerServer"), menu.PushBlockedReason);
Assert.False(menu.SyncCommand.CanExecute(null));
var refused = await Assert.ThrowsAsync<WorkspaceSyncException>(() => host.SyncAsync(projectId, bed.Ct));
Assert.True(refused.HomeReadsOlderFormat);
Assert.Equal(Loc.L("Tooltips.Server.NeedsNewerServer"), WorkspaceText.Failure(refused, server: true));
Assert.Equal(before, host.Store.Find(projectId)!.ReadBundle().Workspace!.Base!.VersionId, "nothing was sent");
// A server of this format takes it.
server.SettingsFormat = ProjectSettings.CurrentVersion;
Assert.Null(menu.PushBlockedReason);
@@ -2,6 +2,7 @@ using Chronos.Core.Advice;
using Chronos.Core.Analysis;
using Chronos.Core.Analysis.Deep;
using Chronos.Core.Diagnostics.Synthetic;
using Chronos.Core.Imaging.Geometry;
using Chronos.Core.Mathematics;
using Chronos.Core.Project;
using Chronos.Core.Tests.Analysis.Deep;
@@ -347,6 +348,30 @@ public sealed class AdvisorTests(TestContext context)
Assert.Equal("9:16", project.Camera.Aspect.AutoValue);
}
/// <summary>
/// The horizon framing places the decoded frame's horizon in the view as shown, as the preview draws it: a half turn or a
/// flip shows it upside down, a straighten turns it about the centre and magnifies it by its cover zoom (10° on 3:2
/// moves a horizon at 0.70 to about 0.745, which the framing must put on the third).
/// </summary>
[Test]
public void TheHorizonIsPlacedInTheViewAsShown()
{
double[] horizon = [0.70, 0.70, 0.70, 0.70, 0.70];
Assert.Approximately(0.70, AdvisorRules.ViewRow(FrameOrientation.Identity(6000, 4000), horizon), 1e-12);
Assert.Approximately(0.30, AdvisorRules.ViewRow(FrameOrientation.Of(0, false, true, 0, 6000, 4000), horizon), 1e-9);
Assert.Approximately(0.30, AdvisorRules.ViewRow(FrameOrientation.Of(180, false, false, 0, 6000, 4000), horizon), 1e-9);
Assert.Approximately(0.70, AdvisorRules.ViewRow(FrameOrientation.Of(0, true, false, 0, 6000, 4000), horizon), 1e-9);
var straightened = FrameOrientation.Of(0, false, false, 10, 6000, 4000);
var centre = (4000 - 1) / 2.0;
var expected = (centre + straightened.CoverZoom * double.Cos(10 * double.Pi / 180) * (0.70 * 4000 - 0.5 - centre) + 0.5) / 4000;
Assert.Approximately(expected, AdvisorRules.ViewRow(straightened, horizon), 1e-9);
Assert.InRange(expected, 0.74, 0.75);
// The context carries the straighten, so the advice is worked out again for it.
Assert.Equal(10.0, new SequenceContext().ForCamera(new CameraSettings { Straighten = 10 }).Straighten);
}
[Test]
public async Task RecommendationsAreDeterministic()
{
@@ -57,6 +57,73 @@ public sealed class OrientationEditTests
Assert.Equal(text, Framed.ToJson());
}
/// <summary>
/// Values off the 12-decimal grid (a crop or keyframe centre an older Chronos, a hand or another program wrote) cannot
/// come back bit for bit, as 1 − v drops bits of a v below ½: they land on the grid at the first press, no visible change,
/// and from then on every net-zero sequence of presses gives back the same text.
/// </summary>
[Test]
public void ValuesOffTheGridLandOnItOnceAndThenStay()
{
var legacy = new ProjectSettings
{
Camera = new CameraSettings { Crop = [1 / 3.0, 0.2, 0.25, 0.3], Keyframes = [new CameraKey(0, 0.47368421052631576, 1 / 7.0, 1.5, 0)] },
};
var once = legacy;
for (var k = 0; k < 4; k++) once = OrientationEdit.Apply(once, OrientationOp.RotateRight);
Assert.Approximately(1 / 3.0, once.Camera.Crop![0], 1e-12);
Assert.Approximately(0.47368421052631576, once.Camera.Keyframes[0].CenterX, 1e-12);
Assert.Approximately(1 / 7.0, once.Camera.Keyframes[0].CenterY, 1e-12);
var text = once.ToJson();
var turned = once;
for (var k = 0; k < 4; k++) turned = OrientationEdit.Apply(turned, OrientationOp.RotateRight);
Assert.Equal(text, turned.ToJson(), "four turns of gridded values");
var mirrored = OrientationEdit.Apply(OrientationEdit.Apply(once, OrientationOp.Mirror), OrientationOp.Mirror);
Assert.Equal(text, mirrored.ToJson(), "two mirrors of gridded values");
foreach (var op in Ops)
{
var opposite = op switch
{
OrientationOp.RotateLeft => OrientationOp.RotateRight,
OrientationOp.RotateRight => OrientationOp.RotateLeft,
_ => op,
};
Assert.Equal(text, OrientationEdit.Apply(OrientationEdit.Apply(once, op), opposite).ToJson(), $"{op} undone");
}
// What the editor writes itself is on the grid already.
Assert.Equal(0.473684210526, CropFrame.Grid(0.47368421052631576));
}
/// <summary>A crop out of range turns with the content it shows (as it renders, clamped), not with its stored numbers.</summary>
[Test]
public void AnOutOfRangeCropTurnsWithTheContentItShows()
{
var camera = new CameraSettings { Crop = [0.5, 0, 0.7, 1] };
Assert.Equal(new RectD(0.5, 0, 0.5, 1), CropFrame.Of(camera.Crop));
var mirrored = OrientationEdit.Apply(camera, OrientationOp.Mirror);
Assert.Equal(new RectD(0, 0, 0.5, 1), CropFrame.Of(mirrored.Crop), "the left half: the right half mirrored");
var turned = OrientationEdit.Apply(camera, OrientationOp.RotateRight);
Assert.Equal(new RectD(0, 0.5, 1, 0.5), CropFrame.Of(turned.Crop), "the right half turned clockwise is the bottom half");
// A crop in range stays as stored.
Assert.SequenceEqual([0.6, 0.2, 0.3, 0.4], OrientationEdit.Apply(new CameraSettings { Crop = [0.1, 0.2, 0.3, 0.4] }, OrientationOp.Mirror).Crop!);
}
/// <summary>A turn transposes the aspect text as written, never reduced: turning back gives the stored text (21:9, not 7:3).</summary>
[Test]
public void TurningBackGivesTheStoredAspectText()
{
foreach (var aspect in new[] { "21:9", "1920:1080", "16:9", "4/5" })
{
var project = new ProjectSettings { Camera = new CameraSettings { Aspect = new Auto<string>().WithManual(aspect) } };
var right = OrientationEdit.Apply(project, OrientationOp.RotateRight);
Assert.True(AspectRatio.TryParse(right.Camera.Aspect.Manual, out var transposed));
Assert.True(AspectRatio.TryParse(aspect, out var stored));
Assert.Equal((stored.Height, stored.Width), (transposed.Width, transposed.Height));
Assert.Equal(project.ToJson(), OrientationEdit.Apply(right, OrientationOp.RotateLeft).ToJson(), aspect);
}
Assert.Equal("9:21", OrientationEdit.Transposed(new Auto<string>().WithManual("21:9")).Manual);
}
[Test]
public void MirrorMovesTheCropAndNegatesTheAngles()
{
@@ -471,14 +471,17 @@ public sealed class ProjectSettingsTests
Assert.Equal(10, s.BitDepth);
}
/// <summary>SHA-256 of the default project's canonical text, as format-1 builds write it: none of phase 4's members, version 1.</summary>
/// <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.
/// </summary>
private const string DefaultProjectHash = "df0b0f50b113475ece3753a80df0be05cc281cdaa1fa08a73a438ea9161358e0";
[Test]
public void ProjectsWithoutTheNewMembersKeepTheirTextAndHash()
{
var defaults = new ProjectSettings().ToJson();
Assert.Equal(DefaultProjectHash, ProjectContent.Hash(ProjectContent.Canonical(defaults)));
Assert.Equal(DefaultProjectHash, ProjectContent.Hash(ProjectContent.Canonical(defaults).ReplaceLineEndings("\r\n")));
Assert.Equal(OldBuild.Write(new OldProject()), defaults);
Assert.Contains("\"version\": 1", defaults);
foreach (var member in new[] { "rotate", "mirror", "flip", "straighten", "\"look\"" })
@@ -176,7 +176,7 @@ public sealed class RenderProcessingTests
var project = With(camera: new CameraSettings { Aspect = On("9:16") });
var (encode, result) = await CaptureAsync(Input(source, project), Preset("png-sequence", 96, 64), cancellationToken: _context.Cancellation);
Assert.Equal((54, 96), (result.Width, result.Height));
Assert.DoesNotContain("Export.Render.AspectFromPreset", result.Warnings.Select(w => w.Key));
Assert.Empty(result.Warnings);
using var expected = GeometryStage.Apply(reference, new GeometrySettings { Crop = new RectD(30, 0, 36, 64), OutputWidth = 54, OutputHeight = 96 });
Assert.Greater(Psnr(expected, encode.Frames[2]), 60);
}
@@ -47,7 +47,7 @@ public sealed class SelfTestTests
[Test]
public async Task GeometryChecksPass()
{
string[] ids = ["proc.orient", "proc.straighten", "proc.portrait", "proc.aspect", "proc.crop"];
string[] ids = ["proc.orient", "proc.straighten", "proc.portrait", "proc.aspect", "proc.crop", "proc.look"];
var results = await SelfTest.RunAsync(new SelfTestOptions { WorkDirectory = _context.CreateTempDirectory(), Filters = ids }, cancellationToken: _context.Cancellation);
foreach (var r in results) _context.Log($"{r.Id}: {r.Outcome} {r.Detail}");
Assert.SequenceEqual(ids.Order(StringComparer.Ordinal), results.Select(r => r.Id).Order(StringComparer.Ordinal));
@@ -163,7 +163,8 @@ public sealed class MediaFoundationEncoderTests(TestContext context)
{
var (portrait, landscape) = (Accepts(capability, 2160, 3840), Accepts(capability, 3840, 2160));
Assert.Equal(landscape, portrait, $"{capability.Name} takes portrait UHD as it takes landscape UHD");
Assert.Equal(EncoderSelector.Takes(capability, 3840, 2160), EncoderSelector.Takes(capability, 2160, 3840), "announced either way round");
Assert.True(EncoderSelector.Takes(capability, 2160, 3840), $"{capability.Name} announces portrait UHD");
if (!capability.Hardware) Assert.False(EncoderSelector.Takes(capability, 2400, 3840), $"{capability.Name}: the short edge is over the software limit");
}
var request = Settings(Path.Combine(context.CreateTempDirectory(), "portrait.mp4"), VideoCodec.H264, 8);
Assert.Equal(provider.CanEncode(request with { Width = 3840, Height = 2160 }), provider.CanEncode(request with { Width = 2160, Height = 3840 }));
@@ -630,6 +630,17 @@ public sealed class RenderJobTests(TestContext context)
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.
@@ -47,16 +47,63 @@ public sealed class ProjectMergeTests
{
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], Mirror = true } };
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.True(result.Merged.Camera.Mirror);
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]
@@ -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()
{
@@ -181,7 +181,21 @@ public sealed class RenderNodeTests(TestContext context)
Assert.True(await Availability().AwaitsNodeAsync(queued with { Created = DateTimeOffset.UtcNow }, parameters, context.Cancellation), "a node may be reconnecting");
Assert.False(await Availability().AwaitsNodeAsync(job, parameters, context.Cancellation), "only a node of format 1 is online");
Assert.True(await Availability().AwaitsNodeAsync(job, parameters with { RequiredSettingsFormat = 1 }, context.Cancellation), "it renders a job of format 1");
Assert.True(await Availability().AwaitsNodeAsync(job, parameters with { RequiredSettingsFormat = 1, SettingsJson = null }, context.Cancellation),
"it renders a job of format 1");
Assert.False(await Availability().AwaitsNodeAsync(job, parameters with { RequiredSettingsFormat = 1 }, context.Cancellation),
"a job queued as format 1 whose settings route it to format 2 is never claimed by that node, so it does not wait for it");
// Queued as format 1 on the sequence's own settings, which then took a turn: the claim skips the older node, and so
// does the wait, so the server's own engine takes the job.
var plain = (await server.Database.Jobs.GetAsync((await JobApiTests.CreateAsync(editor, "render", sequence, H264Job(1920, 1080))).Id))!;
var plainParameters = ProcessingJobs.ReadRender(plain.ParametersJson).Parameters;
var waited = plain with { Created = DateTimeOffset.UtcNow - TimeSpan.FromSeconds(61) };
Assert.Equal(1, plainParameters.RequiredSettingsFormat);
Assert.True(await Availability().AwaitsNodeAsync(waited, plainParameters, context.Cancellation), "plain settings: the older node renders it");
var row = (await server.Database.Sequences.GetAsync(sequence))!;
await server.Database.Sequences.EditAsync(sequence, new SequenceEdit { SettingsJson = turned }, row.SettingsVersion);
Assert.False(await Availability().AwaitsNodeAsync(waited, plainParameters, context.Cancellation), "the turn needs a node of format 2");
using (var registered = await editor.PostAsJsonAsync("/api/v1/nodes/register", new RegisterNodeRequest("studio-pc", [new NodeEncoder("h264", "NVENC", true, false)],
4096, 4096, SettingsFormat: 2), ProtocolJson.Default.RegisterNodeRequest))
await registered.ExpectAsync(HttpStatusCode.OK);
@@ -335,7 +349,8 @@ public sealed class RenderNodeTests(TestContext context)
}
private static string H264Job(int width, int height) => JsonSerializer.Serialize(
new RenderJobParameters("H.264", """{"preset":{"isAuto":false,"manual":"4k-h264"}}""", "h264", width, height, UseProxies: false, null),
new RenderJobParameters("H.264", $$$"""{"preset":{"isAuto":false,"manual":"4k-h264"},"overrides":{"width":{{{width}}},"height":{{{height}}}}}""", "h264", width, height,
UseProxies: false, null),
ProtocolJson.Default.RenderJobParameters);
/// <summary>Render job parameters <paramref name="parametersJson"/> with <paramref name="settingsJson"/> embedded.</summary>