Merge branch 'or1p4-p5' into or1-p4

This commit is contained in:
Alby96 committed 2026-11-04 19:49:17 +01:00
commit a433b55be3
27 files changed
+663 -47

No files matched your search

@@ -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,65 @@ 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");
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>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);