A workspace project that holds its originals now renders locally (JobKind.WorkspaceRender), so the full-resolution render no longer waits on the home. This holds also when the home is a server. - The handler reads its inputs under the project's lease. It refuses proxies-only media, and it refuses frames without an original, saying how many lack one. It renders into exports/ with unique names and a resumable checkpoint. - Each output gets a ledger entry: SHA-256, the render id from RenderJobHandler.RenderId, and the version, recorded only when versions/ holds it and its hash verifies. - After rendering, the handler queues a WorkspaceSend follow-up for the outputs it recorded. A cancel leaves no partial file. - The editor routes Originals media to the local engine even for a server home, and lists those jobs beside the server's. It treats WorkspaceRender like Render for the toast and the reload, says "Sent home" when a send ends, and shows unsent ledger renders as "Not sent". - Version on render saves a changed project as a version noted "Render" before it renders, and sends it with Sync automatically. With the setting off, the render behaves as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
129 lines
7.0 KiB
C#
129 lines
7.0 KiB
C#
using System.Globalization;
|
||
using System.IO;
|
||
using Chronos.App.Editor;
|
||
using Chronos.App.Infrastructure;
|
||
using Chronos.App.Workspace;
|
||
using Chronos.Core.Export;
|
||
using Chronos.Core.Imaging.Decoders;
|
||
using Chronos.Core.Localization;
|
||
using Chronos.Core.Model;
|
||
using Chronos.Core.Project;
|
||
using Chronos.Data.Processing;
|
||
using Chronos.Data.Workspaces;
|
||
using Chronos.Protocol.Client;
|
||
using Chronos.Testing;
|
||
|
||
namespace Chronos.App.Tests.Workspace;
|
||
|
||
/// <summary>
|
||
/// Phase 5c in Edit: a workspace project that holds its originals renders on this PC (<see cref="JobKind.WorkspaceRender"/>),
|
||
/// also when its home is a server, and Settings › Workspace › Version on render saves a changed project as a version first.
|
||
/// </summary>
|
||
[Category("workspace")]
|
||
public sealed class WorkspaceLocalRenderTests(TestContext context)
|
||
{
|
||
private const string Server = "https://nas.test:8443";
|
||
|
||
private static readonly ExportSettings Mjpeg = new()
|
||
{
|
||
Preset = new Auto<string>().WithManual("mjpeg-avi"),
|
||
Overrides = new ExportOverrides { Width = 96, Height = 64 },
|
||
NameTemplate = "clip-{codec}",
|
||
};
|
||
|
||
static WorkspaceLocalRenderTests() => Loc.SetCulture(CultureInfo.GetCultureInfo("en"));
|
||
|
||
[Test]
|
||
public async Task TheOriginalsRenderOnThisPcEvenForAServerHome()
|
||
{
|
||
await using var bed = await WorkspaceTestBed.CreateAsync(context, frames: 4);
|
||
var host = bed.Host(new AppSettings { WorkspaceAutoSync = false, WorkspaceVersionOnRender = false });
|
||
var checkout = await host.CheckoutAsync(bed.SequenceId, null, null, BundleMedia.Originals, cancellationToken: bed.Ct);
|
||
await bed.WaitForJobAsync(checkout.Copy.Id);
|
||
var projectId = checkout.Project.Id;
|
||
// Named the server's, as a copy downloaded from the server leaves it.
|
||
var folder = host.Store.Find(projectId)!;
|
||
var bundle = folder.ReadBundle();
|
||
var home = new BundleHome(BundleHome.ServerKind, bed.SequenceId, null, Server);
|
||
folder.WriteBundle(bundle with { Workspace = bundle.Workspace! with { Home = home } });
|
||
|
||
// Not signed in to the server: a render from the originals runs here all the same.
|
||
var source = new WorkspaceSequenceSource(host.Sync, projectId, bed.Db, DecoderFactory.CreateClient(null), bed.Engine,
|
||
new WorkspaceServerHome((IRemoteSequenceApi?)null));
|
||
var content = await source.LoadAsync(bed.Ct);
|
||
var session = new EditorSession(source, content, [], TimeSpan.FromMilliseconds(20));
|
||
await using (session)
|
||
{
|
||
Assert.True(source is { IsServerHome: true, RendersLocally: true, UnsentRenders: 0 });
|
||
var requests = session.RenderRequests(Mjpeg);
|
||
var request = requests.Single();
|
||
Assert.Equal(JobKind.WorkspaceRender, request.Kind);
|
||
Assert.SequenceEqual([bed.SequenceId], request.Targets);
|
||
var parameters = Assert.NotNull(WorkspaceJobs.RenderParameters(new Job { Id = Guid.CreateVersion7(), Kind = request.Kind, ParametersJson = request.ParametersJson }));
|
||
Assert.Equal((projectId, host.Store.Root, Server), (parameters.ProjectId, parameters.WorkspaceRoot, parameters.Server));
|
||
var (render, _) = ProcessingJobs.ReadRender(parameters.RenderJson);
|
||
Assert.NotNull(render.SettingsJson, "the portable settings travel with the job");
|
||
|
||
// Queued on this PC's engine and listed beside the server's jobs (the render itself is the Data tests': this bed decodes nothing).
|
||
var jobId = await source.SubmitAsync(request, bed.Ct);
|
||
var queued = Assert.NotNull(await bed.Db.Jobs.GetAsync(jobId, bed.Ct));
|
||
Assert.Equal(JobKind.WorkspaceRender, queued.Kind);
|
||
Assert.Contains(await source.ListJobsAsync(bed.Ct), j => j.Id == jobId);
|
||
await WorkspaceTestBed.UntilAsync(() => bed.Db.Jobs.GetAsync(jobId).GetAwaiter().GetResult()?.State is JobState.Done or JobState.Failed, "the render ends");
|
||
|
||
// A render the ledger holds and the home has not taken: listed with the others, not sent.
|
||
var output = Path.Combine(folder.ExportsDirectory, "clip-MJPEG.avi");
|
||
Directory.CreateDirectory(folder.ExportsDirectory);
|
||
await File.WriteAllBytesAsync(output, [1, 2, 3], bed.Ct);
|
||
var entry = new WorkspaceRenderEntry(Guid.CreateVersion7(), jobId, "clip-MJPEG.avi", new string('0', 64), 3, "Custom", "Mjpeg", 96, 64, 25, 0.16,
|
||
projectId, null, null, DateTimeOffset.UtcNow);
|
||
using (await folder.LockAsync(TimeSpan.FromSeconds(TestTiming.Budget(10)), bed.Ct)) folder.WriteRenders(WorkspaceRenders.Empty.With(entry));
|
||
var reread = await source.LoadAsync(bed.Ct);
|
||
Assert.Equal(1, source.UnsentRenders);
|
||
Assert.Equal((entry.RenderId, output), (reread.Renders[0].Id, reread.Renders[0].OutputPath));
|
||
}
|
||
}
|
||
|
||
[Test]
|
||
public async Task VersionOnRenderSavesAChangedProjectFirst()
|
||
{
|
||
await using var bed = await WorkspaceTestBed.CreateAsync(context, frames: 4);
|
||
var settings = new AppSettings();
|
||
Assert.True(settings is { WorkspaceVersionOnRender: true, WorkspaceAutoSync: true }, "on by default");
|
||
var host = bed.Host(settings);
|
||
var projectId = await bed.CheckoutAsync(host);
|
||
var (source, session) = await bed.OpenAsync(host, projectId);
|
||
var ui = new RecordingUi();
|
||
await using (session)
|
||
using (var menu = new ProjectMenuViewModel(host, source, session, ui))
|
||
{
|
||
await menu.RefreshAsync();
|
||
var folder = host.Store.Find(projectId)!;
|
||
var before = folder.Versions().Count;
|
||
|
||
// Nothing changed: nothing saved.
|
||
Assert.True(await menu.ReadyToRenderAsync());
|
||
Assert.Equal(before, folder.Versions().Count);
|
||
|
||
// Changed: saved as a version noted Render and sent (Sync automatically); the render names it.
|
||
Assert.True(session.SetHero(2));
|
||
Assert.True(await session.FlushAsync());
|
||
Assert.True(await menu.ReadyToRenderAsync());
|
||
var saved = folder.Versions()[^1];
|
||
Assert.Equal((before + 1, Loc.L("Editor.Workspace.RenderNote")), (folder.Versions().Count, saved.Note));
|
||
Assert.Equal(WorkspaceState.InSync, menu.Status!.State);
|
||
Assert.Equal(Loc.L("Editor.Workspace.SavedForRender", Formatting.Count(folder.ReadBundle().Workspace!.Base!.Number)), ui.Toasts[^1].Title);
|
||
var (render, _) = ProcessingJobs.ReadRender(session.RenderRequests(session.Project.Export)[0].ParametersJson);
|
||
Assert.Equal(folder.ReadBundle().Workspace!.Base!.VersionId, render.ProjectVersionId);
|
||
|
||
// Off: the project renders as it is, no version saved.
|
||
settings.WorkspaceVersionOnRender = false;
|
||
Assert.True(session.SetHero(3));
|
||
Assert.True(await session.FlushAsync());
|
||
Assert.True(await menu.ReadyToRenderAsync());
|
||
Assert.Equal(before + 1, folder.Versions().Count);
|
||
Assert.Empty(ui.Confirmations);
|
||
}
|
||
}
|
||
}
|