merge: bring phase 4b's final code (v0.1.0-rc.7) into phase 5a

Phase 5a was cut from an earlier phase 4b commit (e3cbe30b). This merges the
final 4b head 11d2c67e (squashed into main as efa87f68): fix rounds 2-3 of
the mass conversion and the replaced-photo trash, the residuals, the 4b
strings in the 36 other languages, and 4b's docs, so 5a builds on the code
that was released.

Conflicts:
- JobRepository: 5a's ListPendingAsync (the workspace copies of a sequence)
  and 4b's ListHoldsAsync (what running and paused jobs hold, without the
  parameters) are both kept.
- ARCHITECTURE: 4b's rows and paragraph kept whole, 5a's additions
  (projects, workspaces, the Edit picker, the WorkspaceCopy job) laid onto
  them; both paragraphs kept.

The resx files merged cleanly: the 36 other cultures hold 4b's
translations, and 5a's new keys stay untranslated there. JobKind values are
unchanged (Backup 16, Cleanup 17, EmptyTrash 18, Convert 19,
WorkspaceCopy 20).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-11-03 15:44:47 +01:00
commit 6e00c3c996
290 files changed
+14129 -884

No files matched your search

@@ -5,6 +5,7 @@ using System.Text.Json;
using Chronos.App.Archiving;
using Chronos.App.Infrastructure;
using Chronos.App.Tests.Import;
using Chronos.App.Tests.Uploader;
using Chronos.Core.Archiving;
using Chronos.Core.Conversion;
using Chronos.Core.Imaging;
@@ -70,17 +71,42 @@ public sealed class ConvertDialogTests(TestContext context)
Loc.Plural("Archive.Convert.SkippedPhotos", 3)), ConvertPlans.Summary(plan));
Assert.Equal(Loc.Plural("Archive.Rename.Summary", 0, 1), ConvertPlans.Summary(plan with { Sequences = [comet] }), "nothing converts, nothing more is said");
// Into a new sequence, which holds the converted copies alone: the photos skipped are not copied into it.
var copies = plan with { Mode = ConvertMode.NewSequence };
// Into a new sequence, which holds the converted copies alone: the photos skipped are not copied into it. Of a
// sequence that converts nothing no copy is made, and its photos stay as they are.
var same = new ConvertSequencePlan(Guid.CreateVersion7(), "Lake", "2025/Lake", 1, [], [new ConvertSkipped(ConvertSkip.SameFormat, 2)], []);
var copies = plan with { Mode = ConvertMode.NewSequence, Sequences = [harbour, comet, empty, untitled, same] };
var copied = ConvertPlans.Rows(copies);
Assert.SequenceEqual(
[
Loc.L("Archive.Convert.NotCopied.SameFormat") + Loc.Separator + Loc.Plural("Shell.Status.Photos", 2),
Loc.L("Archive.Convert.NotCopied.Unhashed") + Loc.Separator + Loc.Plural("Shell.Status.Photos", 1),
],
ConvertPlans.Rows(copies)[0].Kept);
Assert.SequenceEqual(busy.Kept, ConvertPlans.Rows(copies)[1].Kept, "what blocks a sequence reads the same");
Assert.Equal(string.Join(Loc.Separator, Loc.Plural("Archive.Rename.Summary", 2, 4), Loc.Plural("Shell.Status.Photos", 4), ConvertPlans.Sizes(3_500_000, 6_700_000),
Loc.Plural("Archive.Convert.NotCopiedPhotos", 3)), ConvertPlans.Summary(copies));
copied[0].Kept);
Assert.SequenceEqual(busy.Kept, copied[1].Kept, "what blocks a sequence reads the same");
Assert.SequenceEqual([Loc.L("Archive.Convert.Skipped.SameFormat") + Loc.Separator + Loc.Plural("Shell.Status.Photos", 2)], copied[3].Kept);
Assert.Equal(3, ConvertPlans.LeftOut(copies));
Assert.Equal(string.Join(Loc.Separator, Loc.Plural("Archive.Rename.Summary", 2, 5), Loc.Plural("Shell.Status.Photos", 4), ConvertPlans.Sizes(3_500_000, 6_700_000),
Loc.Plural("Archive.Convert.NotCopiedPhotos", 3), Loc.Plural("Archive.Convert.SkippedPhotos", 2)), ConvertPlans.Summary(copies));
// New sequence is confirmed too, before anything is queued: what is copied, nothing to type, and which photos the
// new sequences lack, with their count, sequence by sequence.
var copy = Assert.NotNull(ConvertPlans.NewRequest(copies));
Assert.False(copy.IsDestructive);
Assert.Null(copy.TypedConfirmation);
Assert.Equal(Loc.Plural("Archive.Convert.NewHeading", 2), copy.Heading);
Assert.Equal(Loc.L("Archive.Convert.NewMessage", Loc.Plural("Shell.Status.Photos", 4), Formatting.Bytes(3_500_000), Loc.L("Archive.Convert.Target.LinearDng"))
+ " " + Loc.Plural("Archive.Convert.NewLeftOut", 3), copy.Message);
Assert.SequenceEqual(
[
Loc.L("Archive.Delete.Line", "Harbour sunset", Loc.Plural("Shell.Status.Photos", 3), ConvertPlans.Sizes(3_000_000, 6_000_000))
+ Loc.Separator + Loc.Plural("Archive.Convert.NotCopiedPhotos", 3),
Loc.L("Archive.Delete.Line", "2026/2026-09-29", Loc.Plural("Shell.Status.Photos", 1), ConvertPlans.Sizes(500_000, 700_000)),
],
copy.Detail!.Split(Environment.NewLine));
Assert.Equal((Loc.L("Archive.Convert.Confirm"), Loc.L("Archive.Dialog.Cancel")), (copy.ActionText, copy.SafeText));
Assert.Equal(Loc.L("Archive.Convert.NewMessage", Loc.Plural("Shell.Status.Photos", 1), Formatting.Bytes(500_000), Loc.L("Archive.Convert.Target.LinearDng")),
ConvertPlans.NewRequest(copies with { Sequences = [untitled, same] })!.Message, "nothing left out, nothing said of it");
Assert.Null(ConvertPlans.NewRequest(copies with { Sequences = [comet, empty, same] }), "nothing to copy, nothing to confirm");
// The space line: enough, short, or not measurable.
var required = Formatting.Bytes(plan.Space.Required);
@@ -119,16 +145,16 @@ public sealed class ConvertDialogTests(TestContext context)
var comet = await UploadAsync(archives, archive, "comet", Start.AddDays(1), 11);
var queued = new TaskCompletionSource<ArchiveJobRequest>(TaskCreationOptions.RunContinuationsAsynchronously);
var asked = 0;
List<ConfirmRequest> asked = [];
var closed = false;
using var dialog = new ConvertDialogViewModel(archives, archive, [harbour, comet], request =>
{
queued.TrySetResult(request);
return Task.CompletedTask;
}, _ =>
}, request =>
{
asked++;
return false;
asked.Add(request);
return true;
}, _ => closed = true);
// The archival format, the default quality, and no mode: every run chooses it.
@@ -157,13 +183,13 @@ public sealed class ConvertDialogTests(TestContext context)
Assert.Equal(Loc.L("Tooltips.Archive.ConvertApplyNew"), dialog.ApplyToolTip);
Assert.True(dialog.ApplyCommand.CanExecute(null));
// JPEG to JPEG converts nothing: into a new sequence those photos are not copied, which the rows and the summary
// say, and Replace's words are that they stay as they are. A quality outside 1-100 blocks a JPEG only.
// JPEG to JPEG converts nothing: no new sequence is made of them, so in either mode the rows and the summary say the
// photos stay as they are. A quality outside 1-100 blocks a JPEG only.
dialog.IsJpeg = true;
Assert.Equal(Loc.L("Archive.Blocked.Planning"), dialog.ApplyToolTip, "the dry run on screen is not the one of the format chosen");
await dialog.PlanAsync();
Assert.SequenceEqual([Loc.L("Archive.Convert.NotCopied.SameFormat") + Loc.Separator + Loc.Plural("Shell.Status.Photos", 2)], dialog.Rows[0].Kept);
Assert.Equal(Loc.Plural("Archive.Convert.NotCopiedPhotos", 4), dialog.SummaryText.Split(Loc.Separator)[^1]);
Assert.SequenceEqual([Loc.L("Archive.Convert.Skipped.SameFormat") + Loc.Separator + Loc.Plural("Shell.Status.Photos", 2)], dialog.Rows[0].Kept);
Assert.Equal(Loc.Plural("Archive.Convert.SkippedPhotos", 4), dialog.SummaryText.Split(Loc.Separator)[^1]);
dialog.IsReplace = true;
Assert.SequenceEqual([Loc.L("Archive.Convert.Skipped.SameFormat") + Loc.Separator + Loc.Plural("Shell.Status.Photos", 2)], dialog.Rows[0].Kept);
Assert.Equal(Loc.Plural("Archive.Convert.SkippedPhotos", 4), dialog.SummaryText.Split(Loc.Separator)[^1]);
@@ -190,7 +216,10 @@ public sealed class ConvertDialogTests(TestContext context)
dialog.ApplyCommand.Execute(null);
var request = await queued.Task.WaitAsync(TimeSpan.FromSeconds(TestTiming.Budget(20)));
await UntilAsync(() => closed);
Assert.Equal(0, asked, "a new sequence leaves the originals as they are: nothing to type");
// Confirmed first, with what the new sequences hold: the originals stay as they are, so nothing to type.
var confirmed = asked.Single();
Assert.Equal(ConvertPlans.NewRequest(plan with { Mode = ConvertMode.NewSequence }), confirmed);
Assert.Null(confirmed.TypedConfirmation);
Assert.Equal(JobKind.Convert, request.Kind);
Assert.SequenceEqual(new[] { harbour, comet }.Order(), request.Targets.Order());
Assert.Equal(archive.Name, request.Label);
@@ -207,6 +236,75 @@ public sealed class ConvertDialogTests(TestContext context)
Assert.Equal(2, (await db.Frames.ListBySequenceAsync(harbour)).Count(f => f.Format == ImageFileFormat.Jpeg), "the job converts, not the dialog");
}
[Test]
public async Task ASecondDialogOnTheSameSequencesIsRefusedAndShowsThemBusy()
{
Loc.SetCulture(CultureInfo.GetCultureInfo("en"));
var directory = context.CreateTempDirectory("convert-twice");
await using var db = await ChronosDatabase.OpenAsync(DatabaseOptions.Sqlite(Path.Combine(directory, "index.db")), context.Cancellation);
var archives = Service(db);
var archive = await archives.CreateAsync(Path.Combine(directory, "archive"), "Main", cancellationToken: context.Cancellation);
var harbour = await UploadAsync(archives, archive, "harbour", Start, 1);
// Queued as the engine does: the job waits in the index.
async Task Enqueue(ArchiveJobRequest request) => await db.Jobs.EnqueueAsync(new Job
{
Id = Guid.CreateVersion7(),
Kind = request.Kind,
TargetIds = request.Targets,
ParametersJson = request.ParametersJson,
State = JobState.Queued,
Created = DateTimeOffset.UtcNow,
}, context.Cancellation);
var closed = new List<ArchiveDialogViewModel>();
ConvertDialogViewModel Open() => new(archives, archive, [harbour], Enqueue, _ => true, closed.Add) { IsNewSequence = true };
// The Library's dialog and the Archive manager's, both planned before either applies.
using var library = Open();
using var manager = Open();
await library.PlanAsync();
await manager.PlanAsync();
library.ApplyCommand.Execute(null);
await UntilAsync(() => closed.Contains(library));
// The second is refused: it says why, plans again with the sequence busy, and stays open.
manager.ApplyCommand.Execute(null);
await UntilAsync(() => manager.ErrorText is not null && !manager.IsBusy && manager.Plan is not null);
Assert.Equal(Loc.L("Archive.Convert.AlreadyQueued"), manager.ErrorText);
Assert.SequenceEqual([Loc.L("Archive.Convert.Blocked.Busy")], manager.Rows.Single().Kept);
Assert.Equal(Loc.L("Archive.Blocked.NothingToConvert"), manager.ApplyToolTip);
Assert.DoesNotContain(manager, closed);
Assert.Count(1, (await db.Jobs.ListAsync(JobState.Queued, JobKind.Convert)).Items);
}
/// <summary>
/// Apply queues the job on the dialog's own thread, the check against the conversions queued already included: the
/// desktop's enqueue tells the user with a toast, which only the UI thread may show.
/// </summary>
[Test]
public void TheJobIsQueuedOnTheDialogsThread() => SingleThreadedContext.Run(async () =>
{
Loc.SetCulture(CultureInfo.GetCultureInfo("en"));
var directory = context.CreateTempDirectory("convert-thread");
await using var db = await ChronosDatabase.OpenAsync(DatabaseOptions.Sqlite(Path.Combine(directory, "index.db")), context.Cancellation);
var archives = Service(db);
var archive = await archives.CreateAsync(Path.Combine(directory, "archive"), "Main", cancellationToken: context.Cancellation);
var harbour = await UploadAsync(archives, archive, "harbour", Start, 1);
var ui = Environment.CurrentManagedThreadId;
int? queuedOn = null;
var closed = false;
using var dialog = new ConvertDialogViewModel(archives, archive, [harbour], _ =>
{
queuedOn = Environment.CurrentManagedThreadId;
return Task.CompletedTask;
}, _ => true, _ => closed = true);
dialog.IsNewSequence = true;
await dialog.PlanAsync();
dialog.ApplyCommand.Execute(null);
await UntilAsync(() => closed);
Assert.Equal<int?>(ui, queuedOn);
});
[Test]
public async Task AVolumeWithoutTheSpaceBlocksApply()
{
@@ -70,6 +70,38 @@ public sealed class TrashDialogTests(TestContext context)
+ Loc.L("Archive.Trash.ConversionDeleted"), lone.Detail!);
}
[Test]
public void EveryEntryThatMayHoldTheLastCopyIsNamedBeforeTheTypedConfirmation()
{
Loc.SetCulture(CultureInfo.GetCultureInfo("en"));
// The trash lists newest first: ten deletions since two old conversions whose converted photos were deleted.
var newer = Enumerable.Range(1, 10).Select(i => Entry($"Deleted {i}", TrashKind.Photos, 1, 1_000_000)).ToList();
var oldest = new[]
{
Entry("Etna", TrashKind.Replaced, 3, 90_000_000) with { ConversionDeleted = true },
Entry("Stromboli", TrashKind.Replaced, 2, 60_000_000) with { ConversionDeleted = true },
};
var plan = new TrashEmptyPlan(Guid.CreateVersion7(), [.. newer, .. oldest], 160_000_000, "f1", []);
var lines = Assert.NotNull(TrashEmptyPlans.Request(plan)).Detail!.Split(Environment.NewLine);
var why = Loc.Separator + Loc.L("Archive.Trash.ConversionDeleted");
Assert.True(lines[0].Contains("Etna", StringComparison.Ordinal) && lines[0].Contains(why, StringComparison.Ordinal), lines[0]);
Assert.True(lines[1].Contains("Stromboli", StringComparison.Ordinal) && lines[1].Contains(why, StringComparison.Ordinal), lines[1]);
// The other entries fill the lines left, and the rest are counted.
Assert.Equal(DeletePlans.ListedLines + 1, lines.Length);
Assert.Equal(Loc.Plural("Archive.Delete.More", newer.Count - (DeletePlans.ListedLines - oldest.Length)), lines[^1]);
// More of them than lines: every one is named all the same.
var many = Enumerable.Range(1, DeletePlans.ListedLines + 3).Select(i => Entry($"Converted {i}", TrashKind.Replaced, 1, 1_000_000) with { ConversionDeleted = true })
.ToList();
lines = Assert.NotNull(TrashEmptyPlans.Request(plan with { Entries = [.. newer, .. many] })).Detail!.Split(Environment.NewLine);
Assert.Equal(many.Count + 1, lines.Length);
for (var i = 0; i < many.Count; i++)
Assert.True(lines[i].StartsWith(many[i].Title + " ", StringComparison.Ordinal) && lines[i].Contains(why, StringComparison.Ordinal), lines[i]);
Assert.Equal(Loc.Plural("Archive.Delete.More", newer.Count), lines[^1]);
}
[Test]
public async Task EmptyQueuesTheJobOfTheConfirmedPlanOnly()
{
@@ -143,6 +143,46 @@ public sealed class LibraryPagerTests
}
/// <summary>An in-memory library: cursors are offsets, optionally held back by a gate.</summary>
[Test]
public async Task APageInFlightIsWaitedForNotAskedForAgain()
{
// The Edit picker reads on until a sequence is listed; the list may ask for a page as it scrolls meanwhile.
var source = new FakeSource(30);
var pager = new LibraryPager(source.FetchAsync, pageSize: 10);
await pager.ResetAsync(new LibraryFilter());
Assert.True(pager.WhenLoadedAsync().IsCompleted, "nothing is loading");
source.Gate = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
var scrolled = pager.LoadMoreAsync();
var again = pager.LoadMoreAsync();
Assert.True(again.IsCompletedSuccessfully && again.Result is null, "asking again gets nothing at once");
var loaded = pager.WhenLoadedAsync();
Assert.False(loaded.IsCompleted, "the page in flight is waited for");
source.Gate.SetResult();
await loaded;
Assert.True(scrolled.IsCompleted, "the wait ends with that page");
Assert.Equal(10, Assert.NotNull(await scrolled).Items.Count);
Assert.Equal(2, source.Queries.Count);
}
[Test]
public async Task WaitingForAPageThatFailsDoesNotFail()
{
var source = new FakeSource(30);
var pager = new LibraryPager(source.FetchAsync, pageSize: 10);
await pager.ResetAsync(new LibraryFilter());
source.Gate = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
source.Fail = true;
var page = pager.LoadMoreAsync();
var loaded = pager.WhenLoadedAsync();
source.Gate.SetResult();
await loaded;
await Assert.ThrowsAsync<InvalidOperationException>(() => page);
Assert.False(pager.HasMore, "a failing page stops the reading");
}
private sealed class FakeSource(int count)
{
private readonly Guid _archive = Guid.CreateVersion7();
@@ -0,0 +1,87 @@
using System.Globalization;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using Chronos.App.Archiving;
using Chronos.App.Shell;
using Chronos.Core.Localization;
using Chronos.Data.Archiving;
using Chronos.Testing;
namespace Chronos.App.Tests.Windows;
/// <summary>
/// The confirmation dialog's detail (BRIEF §12.1): one longer than its card (an emptying of the trash that names every entry
/// that may hold the last copy of its photos) scrolls, and since it holds no control the focus could move to, the keyboard
/// reaches it and scrolls it; one that fits is no tab stop.
/// </summary>
[WindowsOnly]
[Serial]
[Timeout(120_000)]
public sealed class ConfirmDialogTests
{
[Test]
public Task ALongDetailTakesTheKeyboardAndScrolls() => ScreenHost.RunAsync(() =>
{
Loc.SetCulture(CultureInfo.GetCultureInfo("en"));
var flagged = Enumerable.Range(1, 40).Select(i => Entry($"Converted {i}") with { ConversionDeleted = true }).ToList();
var dialog = Open(Plan(flagged));
try
{
var detail = (ScrollViewer)dialog.FindName("DetailScroll");
Assert.True(detail.ScrollableHeight > 0, "the detail is longer than its card");
Assert.True(detail.Focusable && detail.IsTabStop, "Tab reaches it");
Assert.Equal(Loc.L("Tooltips.Archive.TrashEmptyPlan"), detail.ToolTip);
Assert.Equal(Loc.L("Tooltips.Archive.TrashEmptyPlan"), System.Windows.Automation.AutomationProperties.GetName(detail));
Press(detail, Key.PageDown);
dialog.UpdateLayout();
var paged = detail.VerticalOffset;
Assert.True(paged > 0, "Page Down scrolls it");
Press(detail, Key.Down);
dialog.UpdateLayout();
Assert.True(detail.VerticalOffset > paged, "and so does the arrow");
}
finally
{
dialog.Close();
}
var fits = Open(Plan([Entry("Etna")]));
try
{
var detail = (ScrollViewer)fits.FindName("DetailScroll");
Assert.Equal(0d, detail.ScrollableHeight);
Assert.False(detail.Focusable || detail.IsTabStop, "a detail that fits is no stop");
}
finally
{
fits.Close();
}
return Task.CompletedTask;
});
private static TrashEntry Entry(string title) =>
new(Guid.CreateVersion7(), FrameTrash.EntryPrefix + Guid.CreateVersion7().ToString("N"), Guid.CreateVersion7(), title, "2026/" + title, 3, 3, 90_000_000,
new DateTimeOffset(2026, 10, 27, 9, 30, 0, TimeSpan.Zero), "alberto", TrashKind.Replaced);
private static TrashEmptyPlan Plan(IReadOnlyList<TrashEntry> entries) => new(Guid.CreateVersion7(), entries, entries.Sum(e => e.Bytes), "f1", []);
/// <summary>The confirmation of emptying <paramref name="plan"/>, shown off screen and laid out.</summary>
private static ConfirmDialog Open(TrashEmptyPlan plan)
{
var dialog = new ConfirmDialog(Assert.NotNull(TrashEmptyPlans.Request(plan)))
{
WindowStartupLocation = WindowStartupLocation.Manual,
Left = -20000,
Top = -20000,
ShowActivated = false,
};
dialog.Show();
dialog.UpdateLayout();
return dialog;
}
private static void Press(UIElement target, Key key) =>
target.RaiseEvent(new KeyEventArgs(Keyboard.PrimaryDevice, PresentationSource.FromVisual(target)!, 0, key) { RoutedEvent = Keyboard.KeyDownEvent });
}