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:
Claude committed 2026-10-12 16:33:56 +00:00
1 parent bf2183764f
commit c68590920f
7 files changed
+98 -20

No files matched your search

@@ -143,6 +143,15 @@ public sealed class ArchiveSettingsTests(TestContext context)
Assert.Null(await fx.Service.RefreshSettingsAsync(fx.Archive.Id, fx.Ct));
Assert.Equal("{year}/{camera}", (await fx.Db.Archives.GetAsync(fx.Archive.Id, fx.Ct))!.FolderTemplate);
// A newer Titano rewrote the file: what this one reads of it is neither shown nor registered.
ManifestStore.WriteArchive(fx.Paths.ManifestPath, manifest with { Name = "Newer", LayoutTemplates = manifest.LayoutTemplates with { Folder = "{camera}" } });
var newer = JsonNode.Parse(await File.ReadAllTextAsync(fx.Paths.ManifestPath, fx.Ct))!;
newer["schemaVersion"] = ArchiveManifest.CurrentSchemaVersion + 1;
await File.WriteAllTextAsync(fx.Paths.ManifestPath, newer.ToJsonString(), fx.Ct);
Assert.Null(await fx.Service.RefreshSettingsAsync(fx.Archive.Id, fx.Ct));
var kept = (await fx.Db.Archives.GetAsync(fx.Archive.Id, fx.Ct))!;
Assert.Equal(("Shared", "{year}/{camera}"), (kept.Name, kept.FolderTemplate));
// The folder now holds another archive: its settings are neither shown nor registered as this one's.
ManifestStore.WriteArchive(fx.Paths.ManifestPath, manifest with { Id = Guid.CreateVersion7(), Name = "Other" });
Assert.Null(await fx.Service.RefreshSettingsAsync(fx.Archive.Id, fx.Ct));