fix(server): keep Reorganize dry runs for the confirm, test the protocol's key paths

An all:true dry run reads every sidecar and photo folder of the archive inside
the request, and the confirm planned the whole archive again before answering
202. The server now keeps each dry run's plan for five minutes (eight plans at
most) by archive, selection, templates and a stamp of the archive's index rows:
the same dry run again and its confirmation take the kept plan, and any change
the index records (an upload, an edit, a move, a scan, a verify) gives another
stamp and a new plan. A change made on disk alone is not in the stamp; the move
job still plans again and refuses a plan that no longer matches.

Server tests now cover an all:true apply around a sequence already in place, a
real plan_changed after an upload, a move job paused between two sequences and
resumed, archive_offline, job_unavailable, more than 1,000 ids and the kept
plans themselves; a Data test covers the index stamp.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 71bb53fbf8eb7d0327ea692d046634b12f8d37e9)
This commit is contained in:
Alby96 committed 2026-10-27 16:30:00 +01:00
1 parent 9ce201cd70
commit 9ae773aa5a
7 files changed
+468 -9

No files matched your search

@@ -1,4 +1,6 @@
using System.Globalization;
using System.Security.Cryptography;
using System.Text;
using Chronos.Core.Imaging;
using Chronos.Core.Model;
@@ -425,6 +427,24 @@ public sealed class SequenceRepository
}, cancellationToken);
}
/// <summary>
/// A digest of the index rows of <paramref name="archiveId"/> (owner review 2, R7): another value once a sequence is
/// added or removed, or once a row changes in what a Reorganize plans from (folder, title, first capture, camera, lens,
/// frame count) or in what every write of it moves (its versions, verify time and time of change). A change made on
/// disk alone, which the index does not have yet, leaves it as it was.
/// </summary>
public async Task<string> GetStampAsync(Guid archiveId, CancellationToken cancellationToken = default)
{
var rows = await _db.ListAsync(
"SELECT id, folder, title, first_capture, camera_make, camera_model, lens, frame_count, frames_version, settings_version, verified_at, updated_at " +
"FROM sequences WHERE archive_id = $1 ORDER BY id", [archiveId],
r => string.Create(CultureInfo.InvariantCulture,
$"{r.GetGuid(0):N}\u001f{r.GetString(1)}\u001f{r.GetStringOrNull(2)}\u001f{r.GetDateTimeOrNull(3):O}\u001f{r.GetStringOrNull(4)}\u001f" +
$"{r.GetStringOrNull(5)}\u001f{r.GetStringOrNull(6)}\u001f{r.GetInt32(7)}\u001f{r.GetInt32(8)}\u001f{r.GetInt32(9)}\u001f" +
$"{r.GetDateTimeOffsetOrNull(10):O}\u001f{r.GetDateTimeOffset(11):O}"), cancellationToken).ConfigureAwait(false);
return Convert.ToHexStringLower(SHA256.HashData(Encoding.UTF8.GetBytes(string.Join('\n', rows))));
}
/// <summary>
/// The sequences of <paramref name="archiveId"/> a rolling verification checks next (owner review 2, R10): those never
/// verified first, then the longest unverified, at most <paramref name="limit"/>. With <paramref name="verifiedBefore"/>