fix: conversions name, lock and settle as phase 4a's writers do
Phase 4b was built on phase 4a before its review fixes. Integrated on the reviewed 4a, the
conversion now follows the same rules as filing and the other writers.
- Names: a converted file is named as filing names a photo of its sequence (FrameNaming: the
archive's file template, the frame's context in the sequence with its camera, lens, number
and title, {name} the card's, {ext} the target's, a long name keeping its extension).
Replace through ConvertOptions.FileName; New sequence through the ingest itself
(StagedFrame.NamedAs), which numbers and names the copies in the new sequence. Names stay
unique against every file present, those leaving included, so a Replace never moves onto a
file; a test pins a stray file that keeps its bytes.
- Leases: stage A starts from the sidecar settled under the sequence's lease where the index
has it then (SequenceWriter.ReadLocked), and FrameTrash.ReplaceAsync reads the row again
under the lease, so a folder a Reorganize moved meanwhile is followed, never made again.
A Reorganize the archive waits for keeps the conversion off its sequences (pinned).
- Journals: the replace journal is settled with the others. MassRenamer steps, restores into
a sequence and sequence deletions wait for an unsettled replacement as they wait for a
restore, and so do photo deletions, whose frames version the recovery reads
(FrameTrash.EnsureReplaced); a scan settles it and reconciles nothing meanwhile; a restore
settles its sequence's replace journal first, at the folder the index has under the lease.
- The convert job tells each sequence converted or made as it completes, as a Reorganize
tells each step, so an editor open on it reads it again while the rest of the job runs.
- Desktop: JobKind.Convert gets its row in the settings' job priority list. A click on Apply
that commits the quality no longer starts the same dry run again under the click (as 4a
fixed for Reorganize).
- Panel: a dry run answered during the confirmation with the same plan no longer drops the
confirmed Apply; a different plan is shown with Admin.Convert.PlanChanged (en, it).
- Tests: TrashDialogTests.EmptyQueuesTheJobOfTheConfirmedPlanOnly waits for the command to
end before running it again (a running AsyncRelayCommand ignored the second Execute).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 2e0d1d6dcc10575734970bb9c77749f00777c859)
This commit is contained in:
1 parent
a1c1c21ebd
commit
341fb77507
22 files changed
+345
-91
No files matched your search
@@ -151,6 +151,14 @@ public sealed class ConvertDialogTests(TestContext context)
|
||||
await dialog.PlanAsync();
|
||||
Assert.SequenceEqual([Loc.L("Archive.Convert.Skipped.SameFormat") + Loc.Separator + Loc.Plural("Shell.Status.Photos", 2)], dialog.Rows[0].Kept);
|
||||
Assert.Equal(Loc.L("Archive.Blocked.NothingToConvert"), dialog.ApplyToolTip);
|
||||
// A click on Apply takes the focus from the quality first, which commits it: the dry run on screen is of that
|
||||
// quality already, so no other one starts under the click.
|
||||
dialog.Quality.Text = "90";
|
||||
await dialog.PlanAsync();
|
||||
Assert.True(dialog.Quality.IsDirty, "typed, not committed");
|
||||
Assert.True(dialog.Quality.Commit());
|
||||
Assert.Null(dialog.BusyText);
|
||||
Assert.Equal(new ConvertOptions(ConvertTarget.Jpeg, 90), dialog.Plan!.Options);
|
||||
dialog.Quality.Text = "0";
|
||||
Assert.Null(dialog.Current());
|
||||
Assert.Equal(dialog.Quality.Error, dialog.ApplyToolTip);
|
||||
|
||||
@@ -103,7 +103,8 @@ public sealed class TrashDialogTests(TestContext context)
|
||||
|
||||
// Kept: the confirmation was dismissed, nothing is queued.
|
||||
dialog.EmptyCommand.Execute(null);
|
||||
await UntilAsync(() => asked is not null && !dialog.IsBusy);
|
||||
// Until the command has ended, not only the dialog's work: a command still running ignores the next Execute.
|
||||
await UntilAsync(() => asked is not null && !dialog.IsBusy && dialog.EmptyCommand.CanExecute(null));
|
||||
Assert.Equal("1", asked!.TypedConfirmation);
|
||||
Assert.False(queued.Task.IsCompleted);
|
||||
Assert.False(closed);
|
||||
|
||||
@@ -7,6 +7,7 @@ using Chronos.Core.Imaging;
|
||||
using Chronos.Core.Imaging.Decoders;
|
||||
using Chronos.Core.Metadata;
|
||||
using Chronos.Core.Model;
|
||||
using Chronos.Core.Naming;
|
||||
using Chronos.Testing;
|
||||
|
||||
namespace Chronos.Core.Tests.Conversion;
|
||||
@@ -253,12 +254,35 @@ public sealed class FrameConverterTests(TestContext context)
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConvertedNamesKeepTheStemAndTheCaseOfTheExtension()
|
||||
public void ConvertedNamesAreTheNamesFilingGives()
|
||||
{
|
||||
Assert.Equal("originals/IMG_0001.DNG", new ConvertOptions(ConvertTarget.LinearDng).NameFor("originals/IMG_0001.CR2"));
|
||||
Assert.Equal("originals/img_0001.tif", new ConvertOptions(ConvertTarget.Tiff16).NameFor("originals/img_0001.cr3"));
|
||||
Assert.Equal("originals/2026-09-28_0001.jpg", new ConvertOptions(ConvertTarget.Jpeg).NameFor("originals/2026-09-28_0001.Nef"));
|
||||
Assert.Equal("frame.jpg", new ConvertOptions(ConvertTarget.Jpeg).NameFor("frame"));
|
||||
var dng = new ConvertOptions(ConvertTarget.LinearDng);
|
||||
Assert.Equal("originals/IMG_0001.dng", dng.WithExtension("originals/IMG_0001.CR2"));
|
||||
Assert.Equal("frame.jpg", new ConvertOptions(ConvertTarget.Jpeg).WithExtension("frame"));
|
||||
|
||||
// The second frame of a sequence filed by a Canon, named with the sequence's camera, its number, the title and the
|
||||
// name it had on the card, as an upload or a Reorganize names it; {ext} is the target's.
|
||||
var first = Frame("2026-09-28_0001.CR3", ImageFileFormat.Cr3, 96, 64) with { I = 0, Original = "IMG_0001.CR3" };
|
||||
var second = Frame("2026-09-28_0002.CR3", ImageFileFormat.Cr3, 96, 64) with { I = 1, Original = "IMG_0002.CR3", CapturedAt = Captured.AddSeconds(10) };
|
||||
var sequence = new SequenceManifest
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
Title = "Harbour",
|
||||
Camera = new SidecarCamera { Make = "Canon", Model = "Canon EOS R5" },
|
||||
Frames = [first, second],
|
||||
};
|
||||
Assert.Equal("originals/Harbour_Canon EOS R5_0002_IMG_0002.dng",
|
||||
dng.FileName(PathTemplate.Parse("{title}_{camera}_{n}_{name}.{ext}"), second, sequence));
|
||||
Assert.Equal("originals/2026-09-28_0002.tif",
|
||||
new ConvertOptions(ConvertTarget.Tiff16).FileName(PathTemplate.Parse("{date}_{n}"), second, sequence));
|
||||
Assert.Equal(PathTemplate.Parse("{date}_{n}").ExpandFile(FrameNaming.Context(second with { File = "originals/x.dng" }, sequence, "Harbour")),
|
||||
Path.GetFileName(dng.FileName(PathTemplate.Parse("{date}_{n}"), second, sequence)));
|
||||
// A frame adopted in place stays in its folder; a long name keeps the target's extension whole.
|
||||
var adopted = second with { File = "IMG_0002.CR3", Original = new string('x', 300) + ".CR3" };
|
||||
var named = dng.FileName(PathTemplate.Parse("{name}.{ext}"), adopted, sequence);
|
||||
Assert.False(named.Contains('/'));
|
||||
Assert.True(named.EndsWith(".dng", StringComparison.Ordinal) && named.Length <= PathTemplate.MaxSegmentLength, named);
|
||||
|
||||
Assert.Equal(ConvertTarget.LinearDng, ConvertOptions.ArchivalTarget);
|
||||
Assert.False(new ConvertOptions(ConvertTarget.Jpeg, 0).IsValid);
|
||||
Assert.False(new ConvertOptions(ConvertTarget.Jpeg, 101).IsValid);
|
||||
|
||||
@@ -152,10 +152,10 @@ public sealed class ConvertTests(TestContext context)
|
||||
Assert.Equal(before.Versions.Frames + 1, row.FramesVersion);
|
||||
Assert.SequenceEqual(originals.Select(f => (f.Id, f.Index)), frames.Select(f => (f.Id, f.Index)));
|
||||
var after = Sidecar(fx, row);
|
||||
var options = new ConvertOptions(ConvertTarget.LinearDng);
|
||||
foreach (var (was, now) in before.Frames.Zip(after.Frames))
|
||||
{
|
||||
Assert.Equal((options.NameFor(was.File), ImageFileFormat.Dng, DecodeTier.Native, 1), (now.File, now.Format, now.Tier, now.Orientation));
|
||||
// Named as filing named the original, with the target's extension: the same template, frame and sequence.
|
||||
Assert.Equal((Path.ChangeExtension(was.File, ".dng"), ImageFileFormat.Dng, DecodeTier.Native, 1), (now.File, now.Format, now.Tier, now.Orientation));
|
||||
Assert.Equal((was.CapturedAt, was.Original, was.Flags), (now.CapturedAt, now.Original, now.Flags));
|
||||
var source = Assert.NotNull(now.Source);
|
||||
Assert.Equal((was.Sha256, was.Format, was.File, was.Size), (source.Sha256, source.Format, source.File, source.Size));
|
||||
@@ -282,7 +282,9 @@ public sealed class ConvertTests(TestContext context)
|
||||
var frames = await FramesAsync(fx, made);
|
||||
Assert.SequenceEqual(originals.Select(f => f.CapturedAt), frames.Select(f => f.CapturedAt));
|
||||
Assert.True(frames.All(f => f.Format == ImageFileFormat.Tiff));
|
||||
Assert.SequenceEqual(originals.Select(f => Path.ChangeExtension(f.FileName, ".tif")), frames.Select(f => Path.ChangeExtension(f.FileName, ".tif")));
|
||||
// Filed as the ingest files every photo: the archive's template in the new sequence, {name} the card's, {ext} the target's.
|
||||
Assert.SequenceEqual(originals.Select(f => Path.ChangeExtension(f.FileName, ".tif")), frames.Select(f => f.FileName));
|
||||
Assert.SequenceEqual(originals.Select(f => f.OriginalFileName), frames.Select(f => f.OriginalFileName));
|
||||
var settings = ProjectSettings.FromJson(copy.SettingsJson!);
|
||||
Assert.SequenceEqual([1], settings.ExcludedFrames);
|
||||
Assert.Equal((2, frames[2].Id), (settings.HeroFrame, copy.HeroFrameId));
|
||||
@@ -577,4 +579,96 @@ public sealed class ConvertTests(TestContext context)
|
||||
_ = JsonSerializer.Serialize(new ConvertJobParameters(fx.Archive.Id, ConvertTarget.Jpeg, 80, ConvertMode.NewSequence, [new ConvertSequence(first, 2)], "f"),
|
||||
ArchiveJobJson.Default.ConvertJobParameters);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ConvertedFilesAreNamedAsFilingNamesThemAndNothingIsOverwritten()
|
||||
{
|
||||
await using var fx = await FixtureAsync();
|
||||
await fx.Service.UpdateSettingsAsync(fx.Archive.Id, s => s with { Templates = s.Templates with { File = "{name}_{n:00}" } }, fx.Ct);
|
||||
var roof = await UploadedAsync(fx, 2);
|
||||
var lake = await UploadedAsync(fx, 2, "upload-2", seed: 200);
|
||||
Assert.SequenceEqual(["IMG_0001_01.JPG", "IMG_0002_02.JPG"], (await FramesAsync(fx, roof)).Select(f => f.FileName));
|
||||
await fx.Service.SetSequenceInfoAsync(roof, "Roof", [], 0, null, fx.Ct);
|
||||
await fx.Service.SetSequenceInfoAsync(lake, "Lake", [], 0, null, fx.Ct);
|
||||
// Filing names a photo with the template of the moment: a conversion names its files as filing would now.
|
||||
await fx.Service.UpdateSettingsAsync(fx.Archive.Id, s => s with { Templates = s.Templates with { File = "{title}_{n:00}" } }, fx.Ct);
|
||||
// A file that is no frame holds the first name: it is never written over, the converted file takes the next.
|
||||
var stray = fx.Paths.Sequence((await fx.Db.Sequences.GetAsync(roof))!.Folder).File("originals/Roof_01.dng");
|
||||
File.WriteAllBytes(stray, [1, 2, 3]);
|
||||
var engine = await fx.StartEngineAsync();
|
||||
|
||||
await RunAsync(fx, engine, await PlanAsync(fx, ConvertTarget.LinearDng, ConvertMode.Replace, roof));
|
||||
var replaced = await FramesAsync(fx, roof);
|
||||
Assert.SequenceEqual(["Roof_01_2.dng", "Roof_02.dng"], replaced.Select(f => f.FileName));
|
||||
Assert.SequenceEqual(["IMG_0001.JPG", "IMG_0002.JPG"], replaced.Select(f => f.OriginalFileName));
|
||||
Assert.SequenceEqual(new byte[] { 1, 2, 3 }, File.ReadAllBytes(stray));
|
||||
|
||||
var job = await RunAsync(fx, engine, await PlanAsync(fx, ConvertTarget.Tiff16, ConvertMode.NewSequence, lake));
|
||||
var made = Assert.NotNull(await fx.Db.Sequences.FindBySessionKeyAsync(fx.Archive.Id, MassConverter.SessionKey(job.Id, lake)));
|
||||
var copies = await FramesAsync(fx, made);
|
||||
Assert.SequenceEqual(["Lake (TIFF)_01.tif", "Lake (TIFF)_02.tif"], copies.Select(f => f.FileName));
|
||||
Assert.SequenceEqual(["IMG_0001.JPG", "IMG_0002.JPG"], copies.Select(f => f.OriginalFileName));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AFolderMovedWhileTheJobWaitsForItsLeaseIsWhereTheConvertedFilesGo()
|
||||
{
|
||||
await using var fx = await FixtureAsync();
|
||||
var id = await UploadedAsync(fx, 2);
|
||||
var engine = await fx.StartEngineAsync();
|
||||
var plan = await PlanAsync(fx, ConvertTarget.Tiff16, ConvertMode.Replace, id);
|
||||
var row = (await fx.Db.Sequences.GetAsync(id))!;
|
||||
var from = fx.Paths.Sequence(row.Folder).Folder;
|
||||
Job job;
|
||||
var planned = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
void OnProgress(JobProgressInfo info)
|
||||
{
|
||||
if (info.Kind == JobKind.Convert && info.Total == 2) planned.TrySetResult();
|
||||
}
|
||||
engine.Progress += OnProgress;
|
||||
using (await LeaseFile.AcquireAsync(fx.Paths.LocksDirectory, $"seq-{id:N}", "editor", TimeSpan.FromSeconds(5), cancellationToken: fx.Ct))
|
||||
{
|
||||
job = await engine.EnqueueAsync(ArchiveJobs.Convert(fx.Archive, plan), cancellationToken: fx.Ct);
|
||||
// Planned again where the index had the sequence then: the job now waits for its lease to convert it.
|
||||
await planned.Task.WaitAsync(TimeSpan.FromSeconds(TestTiming.Budget(30)), fx.Ct);
|
||||
// What a Reorganize step does under that lease meanwhile: the folder moves, and its index row follows.
|
||||
var to = fx.Paths.Sequence("moved/Roof").Folder;
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(to)!);
|
||||
Directory.Move(from, to);
|
||||
Assert.True(await fx.Db.Sequences.RelocateAsync(id, "moved/Roof", null, fx.Ct));
|
||||
}
|
||||
engine.Progress -= OnProgress;
|
||||
|
||||
await fx.WaitForAsync(job.Id, JobState.Done, (int)TestTiming.Budget(60));
|
||||
var frames = await FramesAsync(fx, id);
|
||||
Assert.True(frames.All(f => f.Format == ImageFileFormat.Tiff && f.RelativePath.StartsWith("moved/Roof/", StringComparison.Ordinal)));
|
||||
Assert.False(Directory.Exists(from), "the folder the sequence left is never made again");
|
||||
Assert.Equal("moved/Roof", (await fx.Service.ListTrashAsync(fx.Archive.Id, fx.Ct)).Single().Folder);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AReorganizeTheArchiveWaitsForKeepsTheConversionOffItsSequences()
|
||||
{
|
||||
await using var fx = await FixtureAsync();
|
||||
var id = await UploadedAsync(fx, 2);
|
||||
var originals = await FramesAsync(fx, id);
|
||||
var plan = await PlanAsync(fx, ConvertTarget.Tiff16, ConvertMode.Replace, id);
|
||||
// A Reorganize paused by its user holds the archive: its plan waits for it.
|
||||
await fx.Db.Jobs.EnqueueAsync(new Job
|
||||
{
|
||||
Id = Guid.CreateVersion7(),
|
||||
Kind = JobKind.Move,
|
||||
TargetIds = [fx.Archive.Id],
|
||||
State = JobState.Paused,
|
||||
Created = DateTimeOffset.UtcNow,
|
||||
});
|
||||
Assert.SequenceEqual([ConvertBlock.Busy], (await PlanAsync(fx, ConvertTarget.Tiff16, ConvertMode.Replace, id)).Sequences.Single().Blocked);
|
||||
|
||||
var engine = await fx.StartEngineAsync();
|
||||
var job = await RunAsync(fx, engine, plan, JobState.Failed);
|
||||
Assert.Equal(Loc.Plural("Archive.Error.ConvertKept", 1), job.Error);
|
||||
Assert.Contains(Loc.L("Archive.Log.ConvertBlocked", (await fx.Db.Sequences.GetAsync(id))!.DisplayTitle), job.LogTail);
|
||||
Assert.SequenceEqual(originals.Select(f => (f.Id, f.Sha256, f.RelativePath)), (await FramesAsync(fx, id)).Select(f => (f.Id, f.Sha256, f.RelativePath)));
|
||||
Assert.Empty(await fx.Service.ListTrashAsync(fx.Archive.Id, fx.Ct));
|
||||
}
|
||||
}
|
||||
@@ -62,6 +62,10 @@ public sealed partial class AdminConvertTests(TestContext context)
|
||||
Assert.True(Regex.IsMatch(dialog, @"confirmDialog\(replace \? \{[^}]*typed: t\(""Admin\.Convert\.ReplaceWord""\),\s+typedKind: ""word"",\s+\} : \{[^}]*\}\)", RegexOptions.Singleline),
|
||||
"Replace asks for the word, New sequence does not");
|
||||
Assert.Contains("#/jobs?job=", dialog);
|
||||
// A dry run answered during the confirmation: the same plan again is applied, a different one shown.
|
||||
Assert.Contains("if (plan !== shownPlan && (plan?.key !== shownPlan.key || plan.fingerprint !== shownPlan.fingerprint)) {", dialog);
|
||||
Assert.Contains(@"showError(t(""Admin.Convert.PlanChanged""))", dialog);
|
||||
Assert.True(!dialog.Contains("plan !== shownPlan) return;", StringComparison.Ordinal), "a confirmed apply is dropped when the same plan is answered again");
|
||||
// The panel runs under a strict CSP: no inline handlers or styles.
|
||||
Assert.True(!Regex.IsMatch(dialog, @"\son[a-z]+="""), "inline handler");
|
||||
Assert.True(!dialog.Contains(" style=", StringComparison.Ordinal), "inline style");
|
||||
|
||||
Reference in new issue
Block a user