Files
Chronos/tests/Titano.App.Tests/Editor/ExportSyncTests.cs
T
Claude 36486cb31b test(editor): remote source, export sync, saved copies and hero frame
The remote source loads, saves with the settings version, merges a 409, posts one server
job per preset and follows the server's job events; Export "Sync" gating and the send it
queues; "Save both" copies listed and restored through undo; Set hero reaches the index.
A smoke test opens the sample server's proxied sequence in the real window.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
2026-10-03 11:44:43 +00:00

75 lines
4.1 KiB
C#

using System.IO;
using Titano.App.Editor;
using Titano.Core.Model;
using Titano.Core.Project;
using Titano.Data;
using Titano.Data.Archiving;
using Titano.Data.Jobs;
using Titano.Data.Processing;
using Titano.Data.Sync;
using Titano.Testing;
namespace Titano.App.Tests.Editor;
/// <summary>Export "Sync" (Export.html): when it applies, how the project remembers it, and the send it queues after a render.</summary>
public sealed class ExportSyncTests(TestContext context)
{
private const string Server = "https://nas.test:8443";
[Test]
public void TheOptionSaysWhyItCannotBeUsed()
{
Assert.Equal(ExportSyncGate.Available, ExportSync.Gate(false, Server, linked: true, canUpload: true));
Assert.Equal(ExportSyncGate.Remote, ExportSync.Gate(true, Server, linked: true, canUpload: true));
Assert.Equal(ExportSyncGate.SignedOut, ExportSync.Gate(false, null, linked: false, canUpload: false));
Assert.Equal(ExportSyncGate.NotLinked, ExportSync.Gate(false, Server, linked: false, canUpload: true));
Assert.Equal(ExportSyncGate.NoUpload, ExportSync.Gate(false, Server, linked: true, canUpload: false));
}
[Test]
public void TheProjectRemembersTheChoiceAndOlderProjectsReadItOff()
{
Assert.False(new ProjectSettings().Export.SyncToServer, "renders travel on request");
Assert.False(ProjectSettings.FromJson("""{"export":{"nameTemplate":"{title}"}}""").Export.SyncToServer);
var chosen = new ProjectSettings { Export = new ExportSettings { SyncToServer = true } };
Assert.Contains("\"syncToServer\": true", chosen.ToJson());
Assert.True(ProjectSettings.FromJson(chosen.ToJson()).Export.SyncToServer);
}
[Test]
public async Task AFinishedRenderIsSentOnlyWhenAskedLinkedAndAllowed()
{
var directory = context.CreateTempDirectory("export-sync");
await using var db = await TitanoDatabase.OpenAsync(DatabaseOptions.Sqlite(Path.Combine(directory, "index.db")));
var archives = new ArchiveService(db, new ArchiveServiceOptions { Owner = "test" });
var archive = await archives.CreateAsync(Path.Combine(directory, "archive"), "Test");
var sequence = new Sequence { Id = Guid.CreateVersion7(), ArchiveId = archive.Id, Title = "Harbour sunset", Folder = "Harbour", FrameCount = 1 };
await db.Sequences.UpsertAsync(sequence);
var sync = new SyncService(db, archives, new SyncOptions { ProxyCacheDirectory = Path.Combine(directory, "proxies") });
await using var engine = new JobEngine(db, [], new JobEngineOptions { WorkerId = "test" });
var exports = new ExportSync(db, sync, engine);
Job Render(bool syncToServer, JobState state = JobState.Done) => new()
{
Id = Guid.CreateVersion7(),
Kind = JobKind.Render,
TargetIds = [sequence.Id],
ParametersJson = ProcessingJobs.Render(sequence, new ExportSettings { SyncToServer = syncToServer }, 1920, 1080).ParametersJson,
State = state,
};
Assert.Null(await exports.SendAsync(Render(true), Server, canUpload: true), "the server does not have the sequence");
await sync.LinkAsync(Server, Guid.CreateVersion7(), sequence.Id);
Assert.Null(await exports.SendAsync(Render(false), Server, canUpload: true), "the export did not ask for it");
Assert.Null(await exports.SendAsync(Render(true), null, canUpload: true), "signed out");
Assert.Null(await exports.SendAsync(Render(true), Server, canUpload: false), "no Upload right");
Assert.Null(await exports.SendAsync(Render(true, JobState.Failed), Server, canUpload: true), "nothing was rendered");
var send = Assert.NotNull(await exports.SendAsync(Render(true), Server, canUpload: true));
Assert.Equal(JobKind.UploadCommit, send.Kind);
Assert.Equal(SyncTransferKind.SendExports, SyncService.TransferKind(send));
Assert.SequenceEqual([sequence.Id], send.TargetIds);
Assert.Equal(send.Id, (await exports.SendAsync(Render(true), Server, canUpload: true))!.Id, "a send already waiting takes the next render too");
}
}