fix(settings): a read of the archive's settings that overlapped an edit waits for it and reads again

A read of the open archive's settings that an Archive row edit overlapped
was dropped and left to the edit's end, so a folder change could complete
while the rows still showed the previous archive. The read now waits until
no edit is being written and reads again, so the retarget and the reload on
showing Settings are done only once the rows show what the archive holds.
A smoke test edits a row while Settings reads the archive, with the
settings lease held elsewhere.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
Claude committed 2026-10-12 19:25:32 +00:00
1 parent c341c264e1
commit dbbb5079d1
4 files changed
+135 -71

No files matched your search

@@ -217,9 +217,12 @@ public sealed class SettingsScreenSmokeTests
settings.ArchiveRoot.Text = otherRoot;
Assert.True(settings.ArchiveRoot.Commit());
await WaitAsync(() => Read(manifestPath).LayoutTemplates.File == "{date}-{n:0000}", "the edit reached the archive of the folder it was made for");
// The folder change is done only once the rows show that folder's archive, also when its read overlapped the
// edit written into the first archive: that read waits for the edit and reads again instead of leaving the rows.
await settings.ArchiveRetarget;
Assert.NotEqual("{date}-{n:0000}", Read(otherManifestPath).LayoutTemplates.File);
Assert.Equal(Read(otherManifestPath).LayoutTemplates.File, settings.FileTemplate.Text);
Assert.Equal(Read(otherManifestPath).LayoutTemplates.File, shell.Services.Settings.FileTemplate);
settings.ArchiveRoot.Text = archive.RootPath;
Assert.True(settings.ArchiveRoot.Commit());
await settings.ArchiveRetarget;
@@ -239,6 +242,56 @@ public sealed class SettingsScreenSmokeTests
Assert.Equal(480, settings.SelectedThumbnailSize.Value);
});
[Test]
public Task AnArchiveRowEditedWhileSettingsReadsTheArchiveIsNotUndoneByThatRead() => ScreenHost.RunAsync(async () =>
{
await using var app = await ScreenSmokeTests.SampleApp.StartAsync();
var shell = app.Shell;
await app.Sample.FillAsync();
var settings = shell.Settings;
var archive = Assert.NotNull(await Titano.App.Archiving.CurrentArchive.FindAsync(shell.Services.Database!, null));
var paths = new Titano.Core.Archiving.ArchivePaths(archive.RootPath);
static Titano.Core.Archiving.ArchiveManifest Read(string path) => Titano.Core.Archiving.ManifestStore.ReadArchive(path);
shell.Navigate(SectionKey.Settings);
settings.Page = SettingsPage.Archive;
settings.ArchiveRoot.Text = archive.RootPath;
Assert.True(settings.ArchiveRoot.Commit());
await settings.ArchiveRetarget;
var before = Read(paths.ManifestPath).LayoutTemplates.File;
const string edited = "{camera}_{n:00000}";
Assert.NotEqual(edited, before);
Assert.Equal(before, settings.FileTemplate.Text);
// Another PC holds the archive's settings, so the edit waits to be written. Settings is shown again just before
// the edit is committed: its read of archive.json answers meanwhile, with the file from before the edit.
var lease = Assert.NotNull(Titano.Core.Archiving.LeaseFile.TryAcquire(paths.LocksDirectory, "archive-settings", "other-pc"));
Task reload;
try
{
shell.Navigate(SectionKey.Library);
shell.Navigate(SectionKey.Settings);
reload = settings.ArchiveReload;
Assert.False(reload.IsCompleted, "the read is in flight");
settings.FileTemplate.Text = edited;
Assert.True(settings.FileTemplate.Commit());
await Task.WhenAny(reload, Task.Delay(1500));
Assert.False(reload.IsCompleted, "the read waits for the edit it overlapped");
Assert.Equal(edited, settings.FileTemplate.Text);
Assert.Equal(edited, shell.Services.Settings.FileTemplate);
Assert.Equal(before, Read(paths.ManifestPath).LayoutTemplates.File);
}
finally
{
lease.Dispose();
}
// Once the edit is written, the read is made again and shows it.
await reload.WaitAsync(TimeSpan.FromSeconds(20));
Assert.Equal(edited, Read(paths.ManifestPath).LayoutTemplates.File);
Assert.Equal(edited, settings.FileTemplate.Text);
Assert.Equal(edited, shell.Services.Settings.FileTemplate);
});
[Test]
public Task TheFirstRunDialogKeepsTheKeyboardInside() => ScreenHost.RunAsync(async () =>
{