feat(workspace): copy originals into the workspace and choose the project Edit opens

Phase 5c P1. A workspace copy of kind "originals" now copies each frame's
original beside its proxy, so a later local render has full-quality input:
streamed into a .part file, hashed as written, checked against the home's
SHA-256, renamed and read back. Archive and server homes both work, a stopped
copy resumes (originals: checkpoint), and the space check counts the
originals. A frame whose original is gone, damaged or refused keeps its proxy
and the job says how many; the copy does not fail. Stale originals are
deleted only when the home holds the same SHA-256, otherwise moved to the
workspace's trash.

Proxies only... plans first (every original hashed against the home's
frames), asks for an explicit confirmation, rewrites the media to proxies
before it touches a file, refuses a plan that changed since, and trashes what
the home no longer holds instead of deleting it.

Edit: Open in workspace offers Originals (the settings' default, disabled
when the drive lacks room) with the originals' size for archive and server
homes; Settings > Workspace > Open project picks Last used, Main or asks
which; each open is recorded for the clean-up. The project menu gains Copy
originals... and Proxies only..., refused while changes are unsaved or jobs
of the sequence run.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-11-04 15:43:42 +01:00
1 parent 2e1c67f531
commit 0c51d11080
14 files changed
+1397 -70

No files matched your search

@@ -266,7 +266,8 @@ public sealed class WorkspaceFallbackTests(TestContext context)
Assert.False(facts.TooLittleSpace, "the test drive has room for four small proxies");
var dialog = new OpenInWorkspaceDialogViewModel("Synthetic", await host.HomeProjectsAsync(bed.SequenceId), _ => { }, copy: facts);
Assert.SequenceEqual([Loc.L("Editor.OpenWorkspace.Size"), Loc.L("Editor.OpenWorkspace.Free")], dialog.CopyFacts.Select(f => f.Label));
Assert.SequenceEqual([Loc.L("Editor.OpenWorkspace.Size"), Loc.L("Editor.OpenWorkspace.Free"), Loc.L("Editor.OpenWorkspace.Originals")], dialog.CopyFacts.Select(f => f.Label));
Assert.Equal(Formatting.Bytes(facts.OriginalsBytes!.Value), dialog.CopyFacts[2].Value);
Assert.Equal(Formatting.Bytes(facts.Bytes), dialog.CopyFacts[0].Value);
Assert.False(dialog.IsShortOfSpace);
@@ -0,0 +1,185 @@
using System.IO;
using Chronos.App.Infrastructure;
using Chronos.App.Shell;
using Chronos.App.Tests.Editor;
using Chronos.App.Tests.Windows;
using Chronos.App.Workspace;
using Chronos.Core.Archiving;
using Chronos.Core.Codecs.Jpeg;
using Chronos.Core.Localization;
using Chronos.Core.Metadata;
using Chronos.Core.Model;
using Chronos.Core.Project;
using Chronos.Core.Windows.Shell;
using Chronos.Data;
using Chronos.Data.Archiving;
using Chronos.Data.Projects;
using Chronos.Data.Workspaces;
using Chronos.Testing;
namespace Chronos.App.Tests.Workspace;
/// <summary>
/// Phase 5c in Edit: "Open in workspace" offers the originals (Settings › Workspace › Media first, the proxies when the
/// drive has no room), and Settings › Workspace › Open project picks the project a sequence with several opens.
/// </summary>
[WindowsOnly]
[Serial]
[Timeout(300_000)]
[Category("workspace")]
public sealed class WorkspaceOpenPolicyTests(TestContext context)
{
private static readonly SequenceProject Main = new() { Id = Guid.CreateVersion7(), SequenceId = Guid.CreateVersion7(), Name = ProjectService.MainName, IsMain = true };
[Test]
public void TheOpenDialogStartsWithTheMediaOfTheSettingsWhenTheyFit()
{
UiLanguage.Apply("en");
var room = new WorkspaceCopyFacts(10_000_000, 100_000_000_000, 4_000_000_000);
using var proxies = new OpenInWorkspaceDialogViewModel("Harbour", [Main], _ => { }, copy: room);
Assert.True(proxies is { IsProxies: true, IsOriginals: false, CanCopyOriginals: true });
Assert.Equal(BundleMedia.Proxies, proxies.Media);
Assert.Contains(proxies.CopyFacts, f => f.Label == Loc.L("Editor.OpenWorkspace.Originals"));
using var originals = new OpenInWorkspaceDialogViewModel("Harbour", [Main], _ => { }, copy: room, defaultMedia: BundleMedia.Originals);
Assert.True(originals is { IsOriginals: true, IsProxies: false, IsShortOfSpace: false });
Assert.Equal(Loc.L("Tooltips.Editor.OpenWorkspace.OriginalsReady"), originals.OriginalsToolTip);
originals.OpenCommand.Execute(null);
Assert.Equal(new OpenChoice(Main.Id, null, BundleMedia.Originals), originals.Choice.Result);
// The drive has room for the proxies, not the originals: they are offered disabled, why in the tooltip.
var tight = new WorkspaceCopyFacts(10_000_000, WorkspaceJobs.CopySpaceReserve + 20_000_000, 4_000_000_000);
using var refused = new OpenInWorkspaceDialogViewModel("Harbour", [Main], _ => { }, copy: tight, defaultMedia: BundleMedia.Originals);
Assert.True(refused is { IsProxies: true, CanCopyOriginals: false, IsShortOfSpace: false });
refused.IsOriginals = true;
Assert.False(refused.IsOriginals, "never chosen without room");
Assert.Equal(Loc.L("Tooltips.Editor.OpenWorkspace.NoRoomOriginals"), refused.OriginalsToolTip);
refused.OpenCommand.Execute(null);
Assert.Equal(BundleMedia.Proxies, refused.Choice.Result!.Media);
// Not measured (a server out of reach): offered, the copy measures again before it writes.
using var unmeasured = new OpenInWorkspaceDialogViewModel("Harbour", [Main], _ => { }, server: true);
Assert.True(unmeasured.CanCopyOriginals);
Assert.Equal(Loc.L("Tooltips.Editor.OpenWorkspace.OriginalsReady.Server"), unmeasured.OriginalsToolTip);
unmeasured.IsOriginals = true;
Assert.Equal(BundleMedia.Originals, unmeasured.Media);
}
[Test]
public Task TheOriginalsAreCopiedAndTheOpenProjectFollowsTheSettings() => ScreenHost.RunAsync(async () =>
{
var directory = context.CreateTempDirectory("workspace-open-policy");
var environment = AppEnvironment.From(AppPaths.Resolve(Directory.CreateDirectory(Path.Combine(directory, "app")).FullName,
Directory.CreateDirectory(Path.Combine(directory, "local")).FullName, []));
UiLanguage.Apply("en");
var settings = new AppSettings
{
Language = "en", FirstRunCompleted = true, CheckForUpdates = false, WorkspaceDefaultMedia = BundleMedia.Originals,
};
var services = new AppServices(environment, settings, () => { }, new NoDialogs());
await services.AttachAsync(await ChronosDatabase.OpenAsync(DatabaseOptions.Sqlite(environment.DatabasePath)), startEngine: true);
var shell = new ShellViewModel(services);
try
{
var sequenceId = await SequenceAsync(services, Path.Combine(directory, "archive"));
var section = shell.Sequence;
// The originals, as the settings say: copied beside the proxies, and the project's menu offers Proxies only.
shell.OpenSequence(sequenceId);
await WorkspaceTestBed.UntilAsync(() => section.Dialog is OpenInWorkspaceDialogViewModel, "Open in workspace asks the first time");
var ask = (OpenInWorkspaceDialogViewModel)section.Dialog!;
Assert.True(ask.IsOriginals, "the settings' media first");
ask.OpenCommand.Execute(null);
await WorkspaceTestBed.UntilAsync(() => section.Editor is not null, "the project opens once its media are copied");
var mainId = section.OpenProjectId!.Value;
var menu = Assert.NotNull(section.Editor!.Project);
Assert.True(menu.HoldsOriginals);
var media = services.Workspace.Store.Find(mainId)!.ReadMedia()!;
Assert.True(media.HoldsOriginals && media.Frames.All(f => f.HasOriginal), "every frame has its original");
Assert.True(settings.WorkspaceOpened.ContainsKey(mainId), "the open is recorded for the clean-up");
Assert.True(await section.ConfirmCloseAsync());
await section.CloseAsync();
shell.KeepSequence(null);
// A second project here, opened last.
var vertical = (await services.Archives!.Projects.CreateAsync(sequenceId, "Vertical", cancellationToken: context.Cancellation)).Id;
var checkout = await services.Workspace.CheckoutAsync(sequenceId, vertical, null);
await WorkspaceTestBed.UntilAsync(() => services.Database!.Jobs.GetAsync(checkout.Copy.Id).GetAwaiter().GetResult()?.State == JobState.Done, "its media are copied");
services.Workspace.Remember(sequenceId, vertical);
// Last used: Vertical.
settings.WorkspaceOpenProject = WorkspaceOpenPolicy.LastUsed;
Assert.Equal(vertical, await OpenAsync(shell, sequenceId));
// Main, whichever opened last.
settings.WorkspaceOpenProject = WorkspaceOpenPolicy.Main;
Assert.Equal(mainId, await OpenAsync(shell, sequenceId));
// Ask: the projects here are listed, the one opened last first; closing it opens nothing.
settings.WorkspaceOpenProject = WorkspaceOpenPolicy.Ask;
shell.OpenSequence(sequenceId);
await WorkspaceTestBed.UntilAsync(() => section.Dialog is OpenProjectDialogViewModel, "Open which project? asks");
var which = (OpenProjectDialogViewModel)section.Dialog!;
Assert.Equal(2, which.Projects.Count);
Assert.Equal(mainId, which.SelectedProject!.Entry.ProjectId);
which.CloseCommand.Execute(null);
await WorkspaceTestBed.UntilAsync(() => section.Dialog is null, "closed without a choice");
Assert.Null(section.Editor);
shell.KeepSequence(null);
shell.OpenSequence(sequenceId);
await WorkspaceTestBed.UntilAsync(() => section.Dialog is OpenProjectDialogViewModel, "Open which project? asks again");
which = (OpenProjectDialogViewModel)section.Dialog!;
which.SelectedProject = which.Projects.Single(p => p.Entry.ProjectId == vertical);
which.OpenCommand.Execute(null);
await WorkspaceTestBed.UntilAsync(() => section.Editor is not null, "the project chosen opens");
Assert.Equal(vertical, section.OpenProjectId);
}
finally
{
await shell.Sequence.CloseAsync();
shell.Dispose();
await services.DisposeAsync();
}
});
/// <summary>Opens the sequence in Edit as the settings say and returns the project that opened, closed again.</summary>
private static async Task<Guid> OpenAsync(ShellViewModel shell, Guid sequenceId)
{
var section = shell.Sequence;
shell.OpenSequence(sequenceId);
await WorkspaceTestBed.UntilAsync(() => section.Editor is not null, "the project opens");
Assert.Null(section.Dialog);
var opened = section.OpenProjectId!.Value;
Assert.True(await section.ConfirmCloseAsync());
await section.CloseAsync();
shell.KeepSequence(null);
return opened;
}
/// <summary>An archive with one sequence of six synthetic photos, indexed.</summary>
private async Task<Guid> SequenceAsync(AppServices services, string root)
{
var archives = services.Archives!;
var archive = await archives.CreateAsync(root, "Test");
var sequence = EditorFixture.Sequence(6);
var folder = Path.Combine(root, "Synthetic");
Directory.CreateDirectory(folder);
for (var i = 0; i < sequence.Count; i++)
{
using var image = sequence.Render(i);
var exif = ExifWriter.BuildJpegApp1(sequence.Metadata[i]);
File.WriteAllBytes(Path.Combine(folder, $"IMG_{i + 1:0000}.JPG"), JpegEncoder.Encode(image, new JpegEncodeOptions { Quality = 90, App1Segments = [exif[4..]] }));
}
await archives.Indexer.ScanAsync(archive, ScanMode.Full, null, _ => ValueTask.CompletedTask, context.Cancellation);
return (await services.Database!.Sequences.ListLocationsAsync(archive.Id, context.Cancellation)).Single().Id;
}
/// <summary>Dialogs that pick nothing and decline every confirmation.</summary>
private sealed class NoDialogs : IAppDialogs
{
public string? PickFolder(string title, string? initialFolder = null) => null;
public string? PickJsonFile(string title) => null;
public bool Confirm(ConfirmRequest request) => false;
public bool SignIn(string server, string? username, Func<string, string, Task<string?>> signIn) => false;
}
}
@@ -53,7 +53,7 @@ public sealed class WorkspaceSectionTests(TestContext context)
await WorkspaceTestBed.UntilAsync(() => section.Dialog is OpenInWorkspaceDialogViewModel, "Open in workspace asks the first time");
var ask = (OpenInWorkspaceDialogViewModel)section.Dialog!;
Assert.Equal(Loc.L("Editor.Project.Main"), ask.SelectedProject!.Label, "Main, made from the sequence's settings, is offered first");
Assert.True(ask.IsProxies && !ask.CanCopyOriginals, "proxies; the originals come later");
Assert.True(ask.IsProxies && ask.CanCopyOriginals, "the proxies first, the originals offered (Settings › Workspace › Media)");
Assert.True(section.ShowsPicker && !section.IsLoading, "the picker shows behind the dialog, not the progress bar");
ask.OpenCommand.Execute(null);
Assert.Null(section.Dialog);
@@ -143,7 +143,8 @@ public sealed class WorkspaceSectionTests(TestContext context)
shell.OpenSequence(sequenceId);
await WorkspaceTestBed.UntilAsync(() => section.Dialog is OpenInWorkspaceDialogViewModel, "Open in workspace asks the first time");
var ask = (OpenInWorkspaceDialogViewModel)section.Dialog!;
Assert.SequenceEqual([Loc.L("Editor.OpenWorkspace.Size"), Loc.L("Editor.OpenWorkspace.Free")], ask.CopyFacts.Select(f => f.Label), "the copy's facts reach the dialog");
Assert.SequenceEqual([Loc.L("Editor.OpenWorkspace.Size"), Loc.L("Editor.OpenWorkspace.Free"), Loc.L("Editor.OpenWorkspace.Originals")], ask.CopyFacts.Select(f => f.Label),
"the copy's facts reach the dialog");
ask.OpenCommand.Execute(null);
await WorkspaceTestBed.UntilAsync(() => toasts.Any(t => t.Title == Loc.L("Editor.Workspace.OpenFailed")), "the refusal is said");
var refused = toasts.Single(t => t.Title == Loc.L("Editor.Workspace.OpenFailed"));
@@ -0,0 +1,187 @@
using System.Security.Cryptography;
using Chronos.Core.Localization;
using Chronos.Core.Project;
using Chronos.Data.Archiving;
using Chronos.Core.Model;
using Chronos.Data.Tests.Archiving;
using Chronos.Data.Tests.Infrastructure;
using Chronos.Data.Workspaces;
using Chronos.Testing;
namespace Chronos.Data.Tests.Workspaces;
/// <summary>A workspace project's originals (phase 5c): their copy from the archive, checked and resumable, and "Proxies only".</summary>
[Category("workspace")]
public abstract class WorkspaceOriginalsTests(TestContext context) : DatabaseTest(context)
{
private async Task<WorkspaceFixture> FixtureAsync(int frames = 3, Func<ArchiveServiceOptions, ArchiveServiceOptions>? configure = null)
{
var archive = Own(await ArchiveFixture.CreateAsync(Context, database: await NewOptionsAsync(multiConnection: true), configure: configure));
var fx = Own(await WorkspaceFixture.CreateAsync(Context, archive, frames));
// The archive's own proxies: the copy takes those, so a damaged original never changes a proxy.
await archive.Service.Images.BuildProxiesAsync(archive.Archive, fx.Sequence, force: false, 0, (_, _) => ValueTask.CompletedTask, fx.Ct);
return fx;
}
private static string Sha(string path) => Convert.ToHexStringLower(SHA256.HashData(File.ReadAllBytes(path)));
private static async Task<(WorkspaceStore Store, WorkspaceProject Project)> CheckoutOriginalsAsync(WorkspaceFixture fx)
{
var (store, sync) = fx.Workspace();
var main = await fx.Archive.Service.Projects.MainAsync(fx.Sequence.Id, fx.Ct);
var project = await sync.CheckoutAsync(fx.Home, main.Id, BundleMedia.Originals, fx.Ct);
return (store, project);
}
private string Source(WorkspaceFixture fx, int index) => fx.Archive.Paths.FromRelative(fx.Frames.Single(f => f.Index == index).RelativePath);
[Test]
public async Task ACopyOfTheOriginalsHoldsEachPhotoCheckedAgainstTheHome()
{
var fx = await FixtureAsync();
var (store, project) = await CheckoutOriginalsAsync(fx);
Assert.Equal(fx.Frames.Sum(f => f.Size), await WorkspaceOriginals.ArchiveOriginalsBytesAsync(fx.Db, fx.Archive.Service, fx.Sequence.Id, cancellationToken: fx.Ct));
await fx.CopyAsync(store, project.ProjectId, media: BundleMedia.Originals);
var media = project.ReadMedia()!;
Assert.True(media.HoldsOriginals);
Assert.Equal(BundleMedia.Originals, project.ReadBundle().Workspace!.Media.Kind);
foreach (var frame in fx.Frames)
{
var entry = media.Frames.Single(f => f.Id == frame.Id);
Assert.NotNull(entry.File);
var original = project.MediaFile(Assert.NotNull(entry.Original));
Assert.Equal(frame.Sha256!.ToLowerInvariant(), entry.OriginalSha256);
Assert.Equal(entry.OriginalSha256, Sha(original));
Assert.Equal(frame.Size, entry.OriginalBytes);
Assert.Equal(WorkspaceProject.OriginalName(frame.Id, frame.Sha256, Path.GetExtension(frame.RelativePath)), entry.Original);
}
Assert.Empty(Directory.GetFiles(project.OriginalsDirectory, "*.part"));
Assert.Equal(0L, await WorkspaceOriginals.ArchiveOriginalsBytesAsync(fx.Db, fx.Archive.Service, fx.Sequence.Id, project, fx.Ct));
// The frames read by a local render are the originals.
Assert.SequenceEqual(media.Frames.Select(f => f.Original), media.ToOriginalFrames().Select(f => f.RelativePath));
}
[Test]
public async Task AnOriginalThatIsGoneOrDamagedAtTheHomeLeavesItsFrameProxied()
{
var fx = await FixtureAsync();
var (store, project) = await CheckoutOriginalsAsync(fx);
File.Delete(Source(fx, 0));
var damaged = Source(fx, 1);
var bytes = File.ReadAllBytes(damaged);
bytes[^3] ^= 0x5A;
File.WriteAllBytes(damaged, bytes);
await fx.CopyAsync(store, project.ProjectId, media: BundleMedia.Originals);
var media = project.ReadMedia()!;
Assert.True(media.HoldsOriginals);
var gone = media.Frames.Single(f => f.Index == 0);
var mismatched = media.Frames.Single(f => f.Index == 1);
Assert.Null(gone.Original);
Assert.Null(mismatched.Original);
Assert.NotNull(mismatched.File);
Assert.NotNull(media.Frames.Single(f => f.Index == 2).Original);
Assert.Equal(1, Directory.GetFiles(project.OriginalsDirectory).Length);
Assert.True(media.ToOriginalFrames().Count(f => (f.Flags & FrameFlags.Missing) != 0) == 2, "a render counts the two frames without an original");
}
[Test]
public async Task ACopyStoppedAmongTheOriginalsResumesWithWhatItHad()
{
var fx = await FixtureAsync();
var (store, project) = await CheckoutOriginalsAsync(fx);
await fx.CopyAsync(store, project.ProjectId, media: BundleMedia.Originals);
var media = project.ReadMedia()!;
var kept = project.MediaFile(media.Frames[0].Original!);
var written = File.GetLastWriteTimeUtc(kept);
var lost = project.MediaFile(media.Frames[2].Original!);
File.Delete(lost);
File.WriteAllBytes(Path.Combine(project.OriginalsDirectory, media.Frames[2].Id.ToString("N") + ".part"), [1, 2, 3]);
var row = (await fx.Db.Sequences.GetAsync(fx.Sequence.Id))!;
await fx.CopyAsync(store, project.ProjectId, checkpoint: $"originals:2:{row.FramesVersion}:{row.Folder}", media: BundleMedia.Originals);
Assert.Equal(written, File.GetLastWriteTimeUtc(kept));
Assert.Equal(media.Frames[2].OriginalSha256, Sha(lost));
Assert.Empty(Directory.GetFiles(project.OriginalsDirectory, "*.part"));
Assert.Equal(3, project.ReadMedia()!.Frames.Count(f => f.HasOriginal));
}
[Test]
public async Task TheOriginalsAreNotCopiedWhenTheDriveLacksTheirRoom()
{
long? free = null;
var fx = await FixtureAsync(configure: options => options with { FreeSpace = _ => free });
var (store, project) = await CheckoutOriginalsAsync(fx);
await fx.CopyAsync(store, project.ProjectId);
free = WorkspaceJobs.CopySpaceReserve + fx.Frames.Sum(f => f.Size) - 1;
var job = await fx.CopyAsync(store, project.ProjectId, JobState.Failed, media: BundleMedia.Originals);
var parts = Loc.L("Errors.Workspace.DiskFull", "\u0001").Split('\u0001');
Assert.True(job.Error!.StartsWith(parts[0], StringComparison.Ordinal), job.Error);
Assert.False(project.ReadMedia()!.HoldsOriginals);
Assert.False(Directory.Exists(project.OriginalsDirectory) && Directory.EnumerateFiles(project.OriginalsDirectory).Any());
}
[Test]
public async Task ProxiesOnlyDeletesWhatTheHomeHoldsAndTrashesTheRest()
{
var fx = await FixtureAsync();
var (store, project) = await CheckoutOriginalsAsync(fx);
await fx.CopyAsync(store, project.ProjectId, media: BundleMedia.Originals);
var media = project.ReadMedia()!;
// The home lost frame 1's photo: its only copy is the workspace's, which goes to the trash, not away.
var lostAtHome = project.MediaFile(media.Frames[1].Original!);
var home = await fx.Home.FramesAsync(fx.Ct);
home = home with { Frames = [.. home.Frames.Select(f => f.Index == 1 ? f with { Flags = f.Flags | FrameFlags.Missing } : f)] };
var plan = WorkspaceOriginals.PlanProxiesOnly(project, home);
Assert.Equal((2, 1), (plan.Originals, plan.ToTrash));
Assert.Equal(fx.Frames.Where(f => f.Index != 1).Sum(f => f.Size), plan.Bytes);
var trashed = await WorkspaceOriginals.ApplyProxiesOnlyAsync(project, plan, home, TimeSpan.FromSeconds(10), fx.Ct);
Assert.Equal(1, trashed);
Assert.False(Directory.Exists(project.OriginalsDirectory));
var after = project.ReadMedia()!;
Assert.False(after.HoldsOriginals);
Assert.True(after.Frames.All(f => f.Original is null && f.File is not null));
Assert.Equal(BundleMedia.Proxies, project.ReadBundle().Workspace!.Media.Kind);
var inTrash = Directory.GetFiles(Path.Combine(store.Root, WorkspaceOriginals.TrashFolder), Path.GetFileName(lostAtHome), SearchOption.AllDirectories);
Assert.Equal(1, inTrash.Length);
Assert.Equal(media.Frames[1].OriginalSha256, Sha(inTrash[0]));
}
[Test]
public async Task ProxiesOnlyRefusesAPlanTheFilesChangedSince()
{
var fx = await FixtureAsync();
var (store, project) = await CheckoutOriginalsAsync(fx);
await fx.CopyAsync(store, project.ProjectId, media: BundleMedia.Originals);
var home = await fx.Home.FramesAsync(fx.Ct);
var plan = WorkspaceOriginals.PlanProxiesOnly(project, home);
Assert.Equal((3, 0), (plan.Originals, plan.ToTrash));
var changed = project.MediaFile(project.ReadMedia()!.Frames[0].Original!);
File.AppendAllText(changed, "x");
var error = await Assert.ThrowsAsync<InvalidOperationException>(() => WorkspaceOriginals.ApplyProxiesOnlyAsync(project, plan, home, TimeSpan.FromSeconds(10), fx.Ct));
Assert.Equal(Loc.L("Errors.Workspace.MediaChanged"), error.Message);
Assert.True(project.ReadMedia()!.HoldsOriginals);
Assert.Equal(3, Directory.GetFiles(project.OriginalsDirectory).Length);
// Planned again, the changed file is no photo the home holds: it goes to the trash.
var again = WorkspaceOriginals.PlanProxiesOnly(project, home);
Assert.Equal((2, 1), (again.Originals, again.ToTrash));
Assert.Equal(1, await WorkspaceOriginals.ApplyProxiesOnlyAsync(project, again, home, TimeSpan.FromSeconds(10), fx.Ct));
}
}
public sealed class SqliteWorkspaceOriginalsTests(TestContext context) : WorkspaceOriginalsTests(context)
{
protected override Backend Backend => Backend.SqliteFile;
}
[RequiresEnvironment(PgTestServer.Variable)]
public sealed class PostgresWorkspaceOriginalsTests(TestContext context) : WorkspaceOriginalsTests(context)
{
protected override Backend Backend => Backend.Postgres;
}
@@ -192,14 +192,17 @@ public abstract class WorkspaceTests(TestContext context) : DatabaseTest(context
}
[Test]
public async Task CopyingTheOriginalsIsRefusedForNowWithItsReason()
public async Task CopyingTheOriginalsCopiesTheProxiesToo()
{
var fx = await FixtureAsync(2);
var (store, sync) = fx.Workspace();
var main = await fx.Archive.Service.Projects.MainAsync(fx.Sequence.Id, fx.Ct);
await sync.CheckoutAsync(fx.Home, main.Id, BundleMedia.Originals, fx.Ct);
var job = await fx.CopyAsync(store, main.Id, JobState.Failed, media: BundleMedia.Originals);
Assert.Equal(Loc.L("Errors.Workspace.OriginalsLater"), job.Error);
var project = await sync.CheckoutAsync(fx.Home, main.Id, BundleMedia.Originals, fx.Ct);
await fx.CopyAsync(store, main.Id, media: BundleMedia.Originals);
var media = project.ReadMedia()!;
Assert.True(media.HoldsOriginals);
Assert.True(media.Frames.All(f => f.HasOriginal), "every frame has its original");
Assert.Equal(media.Frames.Count, (await sync.OpenAsync(main.Id, fx.Ct)).Media!.Frames.Count);
}
[Test]
@@ -197,14 +197,45 @@ public sealed class ServerWorkspaceTests(TestContext context)
// Another server's job for this project, or this server's for another sequence: refused, nothing downloaded.
var other = await a.EnqueueAsync(WorkspaceJobs.CopyFromServer(sid, Title, "https://elsewhere:8443", a.Store.Root, main.Id));
Assert.Equal(Loc.L("Errors.Workspace.OtherHome"), (await a.WaitAsync(other.Id, JobState.Failed)).Error);
var originals = await a.EnqueueAsync(WorkspaceJobs.CopyFromServer(sid, Title, a.Server, a.Store.Root, main.Id, BundleMedia.Originals));
Assert.Equal(Loc.L("Errors.Workspace.OriginalsLater"), (await a.WaitAsync(originals.Id, JobState.Failed)).Error);
a.Connected = false;
var signedOut = await a.EnqueueAsync(WorkspaceJobs.CopyFromServer(sid, Title, a.Server, a.Store.Root, main.Id));
Assert.Equal(Loc.L("Errors.Sync.NotConnected"), (await a.WaitAsync(signedOut.Id, JobState.Failed)).Error);
Assert.Null(a.Store.Find(main.Id)!.ReadMedia());
}
[Test]
public async Task TheOriginalsAreDownloadedCheckedAndKeptBesideTheProxies()
{
await using var server = await TestServer.StartAsync(context, services: ArchiveModule.Register);
var (_, _, token) = await server.UserAsync("alberto", "editor");
var sid = await SequenceAsync(server, token, 3);
await using var a = await WorkspaceClient.StartAsync(context, server, token, "PC-A");
var home = a.Home(sid);
var main = (await home.ListAsync(context.Cancellation)).Single();
var project = await a.Sync.CheckoutAsync(home, main.Id, BundleMedia.Originals, context.Cancellation);
var library = Listing(a.Archive.RootPath);
var job = await a.EnqueueAsync(WorkspaceJobs.CopyFromServer(sid, Title, a.Server, a.Store.Root, main.Id, BundleMedia.Originals));
job = await a.WaitAsync(job.Id, JobState.Done);
Assert.Contains(Loc.L("Archive.Log.WorkspaceOriginalsDownloaded", Title, 3, 0, 0), job.LogTail!);
var media = Assert.NotNull(project.ReadMedia());
Assert.True(media.HoldsOriginals);
Assert.Equal(BundleMedia.Originals, project.ReadBundle().Workspace!.Media.Kind);
var manifest = await a.Client.GetManifestAsync(sid, context.Cancellation);
foreach (var (frame, entry) in manifest.Frames.OrderBy(f => f.Index).Zip(media.Frames))
{
Assert.Equal(frame.Sha256.ToLowerInvariant(), entry.OriginalSha256);
Assert.Equal(entry.OriginalSha256, Sha(project.MediaFile(Assert.NotNull(entry.Original))));
Assert.NotNull(entry.File);
}
Assert.False(Directory.Exists(Path.Combine(project.OriginalsDirectory, ".staging")));
Assert.SequenceEqual(library, Listing(a.Archive.RootPath), "this PC's library is as it was");
// Again: every original held is kept, hashed again.
job = await a.WaitAsync((await a.EnqueueAsync(WorkspaceJobs.CopyFromServer(sid, Title, a.Server, a.Store.Root, main.Id, BundleMedia.Originals))).Id, JobState.Done);
Assert.Contains(Loc.L("Archive.Log.WorkspaceOriginalsDownloaded", Title, 0, 3, 0), job.LogTail!);
}
[Test]
public async Task AProjectDeletedOnTheServerIsGoneAndItsCopyStays()
{