Files
Chronos/tests/Chronos.App.Tests/Editor/EditorTextTests.cs
T
Alby96 03d32f18d3 feat(projects): workspace projects with linear versions, the local archive as their home
Owner review 2, phase 5a (R8): editing moves out of the library into a workspace on a fast disk, and a
sequence gets several projects, each with a linear version history pushed and pulled like git.

- Core: ProjectSettings keeps members a newer Chronos wrote (Extra) and reads a newer settings format
  read-only; ProjectContent is the portable form of a version (every frame position parked by photo,
  canonical text, SHA-256 content hash); ProjectBundle format 2 adds the workspace section, and a file
  without it is still written as format 1. JobKind.WorkspaceCopy = 20 (19 kept for Convert).
- Data: migration 0009 (projects, project_versions, the render's project columns); ProjectService on
  ArchiveService.Projects keeps projects as sidecars first (.chronos/projects/<id>/), then the index,
  under the sequence lease: create, rename, delete into the projects' trash, history, push with
  fast-forward, idempotent repeat, divergence and hash checks. Main is made from the sequence's settings
  and mirrored both ways, so every older code path keeps working; outside writes become "external"
  versions, a mirror a crash cut short is completed or merged. Full scans and rebuilds take the projects
  back from their sidecars.
- ProjectMerge moves from the App to Data/Projects, merges pending frames photo by photo and replays
  unpushed commits on a moved head.
- Workspaces: WorkspaceStore, WorkspaceSync (checkout, save, commit, push, pull with replay and merge,
  conflicts settled by keep mine / take server / save both, restore, status) and the WorkspaceCopy job
  (proxies copied hash-verified and resumable; originals refused until phase 5c).
- Renders of a project version place its positions on the frames and record the project and version.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit c4c1802884e403db8759ed0501f770a67a047f20)
2026-10-27 22:51:32 +01:00

90 lines
4.8 KiB
C#

using Chronos.App.Editor;
using Chronos.Core.Advice;
using Chronos.Core.Imaging;
using Chronos.Core.Localization;
using Chronos.Core.Project;
using Chronos.Data.Projects;
using Chronos.Testing;
namespace Chronos.App.Tests.Editor;
/// <summary>Composed texts of the editor (the conflict prompt among them), crop margins and the waveform monitor.</summary>
public sealed class EditorTextTests
{
static EditorTextTests() => _ = EditorFixture.Sunset;
[Test]
public void ColourTemperatureShowsToTheNearestTen()
{
Assert.Equal(5560.0, ExposureTab.RoundToTens(5557.2));
Assert.Equal(3200.0, ExposureTab.RoundToTens(3203.9));
Assert.Equal(12_000.0, ExposureTab.RoundToTens(11_998));
}
[Test]
public void OptimiseReportsValuesAsTheControlsShowThem()
{
Assert.Equal("Frame 0413", EditorText.Value(AdvisorParameters.Hero, 412), "1-based, four digits, like the Frames tab");
Assert.Equal("Source", EditorText.Value(AdvisorParameters.Aspect, "source"));
Assert.Equal("16:9", EditorText.Value(AdvisorParameters.Aspect, "16:9"));
Assert.Equal("24 fps", EditorText.Value(AdvisorParameters.FrameRate, "24"));
Assert.Equal("41 frames", EditorText.Value(AdvisorParameters.DeflickerWindow, 41));
Assert.Equal("0.80", EditorText.Value(AdvisorParameters.DeflickerStrength, 0.8));
Assert.Equal("Centred", EditorText.Value(AdvisorParameters.OffsetY, 0.0));
Assert.Equal("On", EditorText.Value(AdvisorParameters.Deflicker, true));
Assert.Equal("Horizon", EditorText.Value(AdvisorParameters.Regions, RegionMode.Horizon));
Assert.Equal("None", EditorText.Value(AdvisorParameters.Hero, null));
Assert.Equal("3 frames", EditorText.Value(AdvisorParameters.Excluded, new[] { 1, 2, 3 }));
}
[Test]
public void CropMarginsKeepAtLeastATenthOfTheFrame()
{
Assert.SequenceEqual([0.0, 0, 0, 0], CropMargins.Of(null));
var crop = CropMargins.With(null, CropSide.Left, 0.2);
Assert.SequenceEqual([0.2, 0, 0.8, 1], crop!);
crop = CropMargins.With(crop, CropSide.Top, 0.6);
Assert.Approximately(CropMargins.MaxMargin, crop![1], 1e-12, "no margin beyond the maximum");
crop = CropMargins.With(crop, CropSide.Left, 0.45);
crop = CropMargins.With(crop, CropSide.Right, 0.45);
Assert.Approximately(CropMargins.MinSize, crop![2], 1e-12, "opposite margins leave a tenth of the width");
var margins = CropMargins.Of(crop);
Assert.Approximately(0.45, margins[0], 1e-12);
Assert.Approximately(0.45, margins[1], 1e-12);
Assert.Null(CropMargins.With(CropMargins.With(CropMargins.With(crop, CropSide.Left, 0), CropSide.Right, 0), CropSide.Top, 0),
"no margin left is the whole frame");
Assert.SequenceEqual([0.0, 0, 0, 0], CropMargins.Of([double.NaN, 0, 1, 1]), "an invalid crop is ignored, as the render does");
}
[Test]
public void AFlatGreyPictureIsOneLineOfTheWaveform()
{
using var grey = new ImageBuffer(40, 10);
grey.Data.Fill((float)ColorSpace.SrgbToLinear(0.5));
var waveform = LumaWaveform.Measure(grey);
Assert.Equal(40, waveform.Columns);
Assert.Equal(LumaWaveform.Levels, waveform.Rows);
var lit = Enumerable.Range(0, waveform.Rows).Where(r => waveform.Density[r * waveform.Columns] > 0).ToList();
Assert.Equal(1, lit.Count, "one level");
Assert.LessOrEqual(Math.Abs(lit[0] - (LumaWaveform.Levels - 1) / 2.0), 1.0, "half grey sits halfway up");
Assert.Equal(255, waveform.Density[lit[0] * waveform.Columns], "every pixel of the column there");
}
[Test]
public void TheConflictPromptSaysWhatDiffersAndTakesTheServersValuesUnlessAsked()
{
var basis = new ProjectSettings();
var mine = basis with { Exposure = basis.Exposure with { ExposureOffsetEv = 0.5 }, HeroFrame = 3 };
var theirs = basis with { Exposure = basis.Exposure with { ExposureOffsetEv = 0.3 } };
var conflict = new ProjectConflictException("changed", theirs, ProjectMerge.Conflicts(basis, mine, theirs));
var request = EditorViewModel.ConflictRequest(conflict, "Harbour sunset", "Studio NAS");
Assert.Equal(Loc.L("Server.Conflict.Difference", Loc.L("Server.Setting.ExposureOffset"), 0.5.ToString("0.###", Loc.Culture),
0.3.ToString("0.###", Loc.Culture)), request.Detail, "only the setting both changed; the editor's value first");
Assert.Equal(Loc.L("Server.Sync.Action.TakeServer"), request.SafeText, "the safe default loses nothing: Ctrl+Z brings the editor's values back");
Assert.Equal(Loc.L("Server.Sync.Action.KeepMine"), request.ActionText);
Assert.True(request.IsDestructive, "Keep mine overwrites the server's values");
Assert.Contains("Studio NAS", request.Heading);
}
}