fix(archive): the admin form reads archive.json; a poll never undoes an admin's edit
GET /api/v1/archive/settings refreshes the served archive from archive.json first, so the admin form (which saves every field) starts from a desktop's change made since the last poll instead of writing the old templates back. ServerArchive.RefreshAsync replaces the served archive only when the refresh registered a change, and only through a compare-and-swap against the archive it read, so a poll racing an admin's PUT no longer puts the pre-edit row back for ten minutes. RefreshSettingsAsync now ignores an archive.json a newer Titano wrote, as documented, instead of registering what this version reads of it. AppServicesTests now points the folder at an archive the index does not list first, and checks that the archive no longer chosen gets no scan. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
7 files changed
+98
-20
No files matched your search
@@ -74,17 +74,30 @@ public sealed class AppServicesTests
|
||||
Assert.Equal<TimeSpan?>(TimeSpan.FromMinutes(30), services.PollingPeriod);
|
||||
|
||||
// The first-run dialog creates an archive: the next rescan is of it.
|
||||
await services.ArchiveSetup.CreateAsync(Path.Combine(environment.DataDirectory, "first"));
|
||||
Assert.Equal("first", (await services.RescanAsync())?.Name);
|
||||
var firstRoot = Path.Combine(environment.DataDirectory, "first");
|
||||
await services.ArchiveSetup.CreateAsync(firstRoot);
|
||||
var first = Assert.NotNull(await services.RescanAsync());
|
||||
Assert.Equal("first", first.Name);
|
||||
|
||||
// Settings › Archive moves to another archive: the next rescan is of that one, no longer of the first.
|
||||
var second = Path.Combine(environment.DataDirectory, "second");
|
||||
await new ArchiveService(services.Database!).CreateAsync(second, "Second");
|
||||
settings.LastArchivePath = second;
|
||||
// Settings › Archive moves to another archive, which the index lists after the first one: the next rescan
|
||||
// is of the archive at the folder, no longer of the first one.
|
||||
var other = Path.Combine(environment.DataDirectory, "zeta");
|
||||
await new ArchiveService(services.Database!).CreateAsync(other, "zeta");
|
||||
Assert.Equal("first", (await services.Database!.Archives.ListAsync())[0].Name);
|
||||
async Task<int> ScansOfAsync(Guid archiveId) =>
|
||||
(await services.Database!.Jobs.ListAsync(null, JobKind.Scan)).Items.Count(j => j.TargetIds.Contains(archiveId));
|
||||
var scansOfFirst = await ScansOfAsync(first.Id);
|
||||
settings.LastArchivePath = other;
|
||||
services.SaveSettings();
|
||||
var rescanned = Assert.NotNull(await services.RescanAsync());
|
||||
Assert.Equal("Second", rescanned.Name);
|
||||
Assert.Contains((await services.Database!.Jobs.ListAsync(null, JobKind.Scan)).Items, j => j.TargetIds.Contains(rescanned.Id));
|
||||
Assert.Equal("zeta", rescanned.Name);
|
||||
Assert.True(await ScansOfAsync(rescanned.Id) > 0, "the archive at the folder is rescanned");
|
||||
Assert.Equal(scansOfFirst, await ScansOfAsync(first.Id));
|
||||
|
||||
// And back: the folder decides, whatever the order of the index.
|
||||
settings.LastArchivePath = firstRoot;
|
||||
services.SaveSettings();
|
||||
Assert.Equal(first.Id, (await services.RescanAsync())?.Id);
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user