From 6db4c2e80c8f1c7b8cac0b76fc9739c4017dd9c9 Mon Sep 17 00:00:00 2001 From: Alberto Balbo Date: Wed, 18 Nov 2026 14:01:45 +0100 Subject: [PATCH] fix(copies): close the eleventh verification round of owner review 6 - A merge's Verify stage journals a second version, with the hash it is filed as, before it files it. A run that stops between filing it and leaving it out of Main (a drive dropping out, project.json held, the app closing) now leaves it out on resume, instead of reading it as the kept sequence's own photo and keeping both versions in Main for good. - Upload all local ignores a Kept apart pair whose server sequence is confirmed deleted only when the answer came before the first 404. A Keep here, answered after the deletion was shown, skips the sequence again instead of uploading it and erasing the answer. - An upload's checkpoint records whether the job joined a server sequence this PC already knew. A resumed or retried upload no longer takes such a sequence for one it made and overwrites its details. Refs #73 Co-Authored-By: Claude Opus 5.5 --- docs/CHANGELOG.md | 6 ++ docs/DECISIONS.md | 3 + .../Archiving/Jobs/MergeJobHandler.cs | 18 +++++- src/Chronos.Data/Archiving/MergeJournal.cs | 6 ++ src/Chronos.Data/Copies/UploadAllRule.cs | 12 ++-- src/Chronos.Data/Sync/SyncTransfers.cs | 15 ++++- .../Archiving/SequenceMergerTests.cs | 34 +++++++++++ .../Copies/CopyEngineTests.cs | 24 ++++++++ .../Copies/FoundCopyStoreTests.cs | 4 +- .../Sync/SyncTransferCopyTests.cs | 56 +++++++++++++++++++ 10 files changed, 168 insertions(+), 10 deletions(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 3412ca3b..6d07ef48 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -243,6 +243,12 @@ match. A 1.1 server works as before, without Integrate; a 1.2 server adds the ph - An upload of a sequence asked about again makes a new server sequence instead of joining, re-linking and overwriting the one an earlier upload made; one that joins a server sequence this PC already knows compares its details instead of overwriting them. + - A second version a merge's verify files is left out of Main also when the run stopped right after filing it (a + drive dropping out, project.json held, the app closing): the resumed merge leaves it out then. + - *Upload all local* leaves out again a sequence answered *Keep here* after its server copy was deleted, and the + answer stays; only a *Keep apart* given before the deletion lets it send the sequence. + - An upload that joined a server sequence this PC already knew still compares its details when it is resumed or + retried, instead of overwriting the server's title, tags, rating, notes and settings. ## [1.1.1] — 2026-11-16 diff --git a/docs/DECISIONS.md b/docs/DECISIONS.md index b73a1384..e4241be0 100644 --- a/docs/DECISIONS.md +++ b/docs/DECISIONS.md @@ -1028,3 +1028,6 @@ One line per decision: date · decision · alternative · reason. | 2026-11-18 | Supersedes the 2026-11-18 unlinked-404 row: a 404 for a server sequence no local copy is linked to deletes only its Candidate pairs; each Kept apart pair naming it counts the hit as a linked pair does (once per refresh, a second only after `GoneRecheck`), a listing clears the count, and Upload all local sends the local sequence only once the pair reads deleted on the server (two hits) (#73) | Count observation links in the sweep test | A single 404 (trash and restore, access withdrawn for a moment) erased the Keep apart answer, and the pair was asked again or linked by itself (owner Q1) | | 2026-11-18 | Download originals whose server-sequence key names a local copy paired with that server sequence (Candidate, Linked or Integrated, no link) links that copy first and fills it as a linked copy (its tombstones honoured), then compares it as a new link instead of taking the server's details; a holder with no pair (a run that stopped before linking) is joined as before (#73) | Use a key of the job for a Candidate holder too | The round-9 rule refills the local copy a 404 or Ask again left without a link; treated as new it got photos deleted here back and lost its details (owner Q3, Q4, Q6) | | 2026-11-18 | An upload without a target goes under a key of the job when its local sequence has a Candidate or Kept apart pair with that server, and one whose first original joins a server sequence this PC already knows (listed, linked or paired) compares it as a new link instead of sending all its details (#73) | Keep the own key for a Candidate pair | The own key filed the photos into the sequence an earlier upload made, linked it unasked and overwrote edits made there (owner Q1, Q4) | +| 2026-11-18 | A merge's Verify stage journals a second version (`SecondVersions`, and in `VersionShas` the SHA-256 it is filed as) before it files it; a resumed verify that finds such a frame in the kept sequence leaves it out of Main again (a no-op when it already is), and one that reads other bytes for it stops with "changed" (#73) | Save the journal right after filing | The ingest commits the frame before any save can follow: a failed exclusion or a crash in between left the version in Main for good, since a resumed verify read it as the kept sequence's own | +| 2026-11-18 | Supersedes the 2026-11-18 unlinked-404 rows on Upload all local: a Kept apart pair whose server sequence reads deleted on the server holds nothing back only when it was answered before the first 404 (`AnsweredAt < RemoteGoneAt`); a Keep here (answered after the deletion was shown) still skips the local sequence (#73) | A separate Keep here state or marker | Both answers are stored as Kept apart with the gone mark; the answer time already tells them apart, and Keep here's tooltip and design §6.3 promise Upload all local leaves it out | +| 2026-11-18 | An upload's checkpoint names the server sequence its first original reached with `:joined` appended when that was one this PC already knew; a resumed or retried upload sends all its details only when the checkpoint names the target without that mark (a plain id from an older run still means made by this job) (#73) | Look the sequence up again in the known remotes on resume | After the first attempt the link to it exists, so a resume cannot tell a sequence it made from one it joined; only the attempt that sent the first original knows | diff --git a/src/Chronos.Data/Archiving/Jobs/MergeJobHandler.cs b/src/Chronos.Data/Archiving/Jobs/MergeJobHandler.cs index 20e47f80..67d864ba 100644 --- a/src/Chronos.Data/Archiving/Jobs/MergeJobHandler.cs +++ b/src/Chronos.Data/Archiving/Jobs/MergeJobHandler.cs @@ -52,6 +52,9 @@ internal sealed class MergeJobHandler(ChronosDatabase db, SequenceMerger merger, /// Called before each stage runs (tests: a crash, a change made between stages). internal Func? BeforeStage { get; set; } + /// Called before a second version is left out of Main (tests: a failure between filing it and saving the journal). + internal Func? BeforeLeaveOutOfMain { get; set; } + public async Task RunAsync(JobContext context) { var job = context.Job; @@ -395,6 +398,7 @@ internal sealed class MergeJobHandler(ChronosDatabase db, SequenceMerger merger, private async Task LeaveOutOfMainAsync(string sha) { var ct = CancellationToken.None; + if (owner.BeforeLeaveOutOfMain is { } hook) await hook(sha).ConfigureAwait(false); for (var attempt = 1; ; attempt++) { var keep = await _db.Sequences.GetAsync(journal.KeepId, ct).ConfigureAwait(false) ?? throw new StaleCopyPlanException(); @@ -655,9 +659,17 @@ internal sealed class MergeJobHandler(ChronosDatabase db, SequenceMerger merger, ?? throw new InvalidOperationException(Loc.L("Errors.Copies.ChangedFile", frame.FileName)); if (frame.Sha256 is { Length: > 0 } recorded && !string.Equals(recorded, sha, StringComparison.OrdinalIgnoreCase)) throw new InvalidOperationException(Loc.L("Errors.Copies.ChangedFile", frame.FileName)); + var version = journal.SecondVersions.Contains(frame.Id); + if (version && !string.Equals(journal.VersionShas.GetValueOrDefault(frame.Id), sha, StringComparison.OrdinalIgnoreCase)) + // A run that stopped while filing it as a second version read other bytes: changed since. + throw new InvalidOperationException(Loc.L("Errors.Copies.ChangedFile", frame.FileName)); if (held.TryGetValue(sha, out var keepFrame)) { + // Filed as a second version by a run that stopped before the journal said so: left out of Main again + // (nothing changes when it already is), and still left out at the Details stage. + if (version) await LeaveOutOfMainAsync(sha).ConfigureAwait(false); journal.Verified[frame.Id] = new MergeVerified(sha, keepFrame); + if (version) Save(); continue; } if (journal.Absent.Contains(sha)) @@ -669,9 +681,13 @@ internal sealed class MergeJobHandler(ChronosDatabase db, SequenceMerger merger, if (frame.Sha256 is not { Length: > 0 } && !keepRemoved.Contains(sha)) { // Compared by size and time only, and another photo after all: filed in the kept sequence as a second version. + // The journal says so before it is filed: a run that stops before it is left out of Main (the exclusion + // fails, the app ends) finds it in the kept sequence on resume and leaves it out then. + if (!version) journal.SecondVersions.Add(frame.Id); + journal.VersionShas[frame.Id] = sha.ToLowerInvariant(); + Save(); var filed = await FileAsync(frame, sha, planned: false).ConfigureAwait(false); await LeaveOutOfMainAsync(sha).ConfigureAwait(false); - journal.SecondVersions.Add(frame.Id); journal.Verified[frame.Id] = new MergeVerified(sha, filed.FrameId); held.TryAdd(sha, filed.FrameId); Save(); diff --git a/src/Chronos.Data/Archiving/MergeJournal.cs b/src/Chronos.Data/Archiving/MergeJournal.cs index d9a92299..dc927cf6 100644 --- a/src/Chronos.Data/Archiving/MergeJournal.cs +++ b/src/Chronos.Data/Archiving/MergeJournal.cs @@ -105,6 +105,12 @@ internal sealed class MergeJournal /// Drop frames the verify found to be another photo than keep's (unhashed, same size and time) and filed as a second version. public List SecondVersions { get; set; } = []; + /// + /// Drop frame of → the SHA-256 it is filed as, written before it is filed: a resumed verify + /// that finds it in the kept sequence leaves it out of Main again, and one that reads other bytes stops. + /// + public Dictionary VersionShas { get; set; } = []; + /// Drop frames the verify found nothing of to lose: last copies the plan listed, or photos a third sequence holds. public List Settled { get; set; } = []; diff --git a/src/Chronos.Data/Copies/UploadAllRule.cs b/src/Chronos.Data/Copies/UploadAllRule.cs index 11522c57..36d531e3 100644 --- a/src/Chronos.Data/Copies/UploadAllRule.cs +++ b/src/Chronos.Data/Copies/UploadAllRule.cs @@ -55,10 +55,10 @@ public static class UploadAllRule foreach (var entry in localOnly) { if (entry.Local is not { } local) continue; - // A Kept apart answer about a server sequence confirmed deleted there (two 404s apart) holds nothing back: that - // sequence is no copy of anything any more, and the local one is this PC's only. - var pairs = (bySequence.GetValueOrDefault(local.Id) ?? []).Where(p => p is not { Kind: CopyKind.LocalServer, State: CopyState.KeptApart, RemoteGone: true }) - .ToList(); + // A Kept apart answer given before a server sequence was confirmed deleted there (two 404s apart) holds nothing + // back: that sequence is no copy of anything any more, and the local one is this PC's only. A Keep here, answered + // once the deletion was shown, is the user's answer about the deletion itself: it still skips. + var pairs = (bySequence.GetValueOrDefault(local.Id) ?? []).Where(p => !ApartBeforeDeletion(p)).ToList(); UploadSkip? why = busy.Contains(local.Id) || pairs.Any(p => p.State == CopyState.Integrating) ? UploadSkip.Busy : pairs.Any(p => p.Kind == CopyKind.LocalServer && p.RemoteGoneHits >= 1) ? UploadSkip.DeletedOnServer @@ -71,6 +71,10 @@ public static class UploadAllRule } return (upload, skipped); + static bool ApartBeforeDeletion(FoundCopy p) => + p is { Kind: CopyKind.LocalServer, State: CopyState.KeptApart, RemoteGone: true, AnsweredAt: { } answered, RemoteGoneAt: { } gone } + && answered < gone; + void Add(Guid id, FoundCopy copy) { if (!bySequence.TryGetValue(id, out var list)) bySequence[id] = list = []; diff --git a/src/Chronos.Data/Sync/SyncTransfers.cs b/src/Chronos.Data/Sync/SyncTransfers.cs index 155bd0b0..06d34cc5 100644 --- a/src/Chronos.Data/Sync/SyncTransfers.cs +++ b/src/Chronos.Data/Sync/SyncTransfers.cs @@ -37,6 +37,9 @@ internal sealed class SyncTransfers(SyncService sync) { private const long SpaceReserve = 512L << 20; + /// The upload checkpoint's suffix for a server sequence the job joined (one this PC already knew), not made. + private const string JoinedMark = ":joined"; + /// Space a cached proxy is assumed to take before it is downloaded (1920 px JPEG, BRIEF §8.5). private const long ProxyEstimate = 3L << 19; @@ -94,7 +97,9 @@ internal sealed class SyncTransfers(SyncService sync) { remoteId = sent.SequenceId; if (knownRemotes.Contains(sent.SequenceId)) created = false; - await context.CheckpointAsync(sent.SequenceId.ToString(), progress.Done + 1, frames.Count).ConfigureAwait(false); + // Saved with the target: a resumed or retried attempt reads whether this job made it, never infers it. + await context.CheckpointAsync(sent.SequenceId.ToString() + (created ? string.Empty : JoinedMark), progress.Done + 1, frames.Count) + .ConfigureAwait(false); await sync.LinkAsync(remote.Server, sent.SequenceId, local, ct).ConfigureAwait(false); } await progress.StepAsync().ConfigureAwait(false); @@ -962,11 +967,15 @@ internal sealed class SyncTransfers(SyncService sync) /// /// The server sequence an upload fills and whether this job creates it: the linked one, the one an interrupted /// attempt created (unless the user kept it apart or unlinked it since), or none yet (the first original creates it). + /// The checkpoint names the server sequence an earlier attempt reached, with when that attempt + /// joined one this PC already knew (its details are compared, never sent all over the server's, on every attempt). /// private async Task<(Guid? RemoteId, bool Created)> TargetAsync(JobContext context, ISyncRemote remote, Sequence local) { var ct = context.Cancellation; - Guid? started = Guid.TryParse(context.Checkpoint, out var saved) ? saved : null; + var checkpoint = context.Checkpoint ?? string.Empty; + var joined = checkpoint.EndsWith(JoinedMark, StringComparison.Ordinal); + Guid? started = Guid.TryParse(joined ? checkpoint[..^JoinedMark.Length] : checkpoint, out var saved) ? saved : null; var link = await sync.Links.FindByLocalAsync(remote.Server, local.Id, ct).ConfigureAwait(false); foreach (var candidate in new[] { link?.RemoteId, started }) { @@ -978,7 +987,7 @@ internal sealed class SyncTransfers(SyncService sync) if (await ExistsAsync(remote, id, ct).ConfigureAwait(false)) { if (link?.RemoteId != id) await sync.LinkAsync(remote.Server, id, local, ct).ConfigureAwait(false); - return (id, id == started); + return (id, id == started && !joined); } // Deleted on the server meanwhile: the originals go into a new sequence. if (id == link?.RemoteId) await sync.ForgetGoneAsync(remote.Server, id, ct).ConfigureAwait(false); diff --git a/tests/Chronos.Data.Tests/Archiving/SequenceMergerTests.cs b/tests/Chronos.Data.Tests/Archiving/SequenceMergerTests.cs index cc4e8b38..0428f029 100644 --- a/tests/Chronos.Data.Tests/Archiving/SequenceMergerTests.cs +++ b/tests/Chronos.Data.Tests/Archiving/SequenceMergerTests.cs @@ -599,6 +599,40 @@ public abstract class SequenceMergerTests(TestContext context) : DatabaseTest(co AssertVersions(await new CopySides(fx.Db).VersionsAsync(keep.Id, Ct), Sha(mine, 0), Sha(theirs, 0)); } + [Test] + public async Task AVersionTheVerifyFiledBeforeTheRunStoppedIsLeftOutOfMainOnResume() + { + var fx = await FixtureAsync(); + var (mine, theirs) = EqualSizeSeeds(0); + var keep = await SequenceAsync(fx, "keep", [(mine, 0, "IMG_0001.JPG")]); + var drop = await SequenceAsync(fx, "drop", [(theirs, 0, "IMG_0001.JPG")]); + await new DbAccess(fx.Db.Database).ExecuteAsync("UPDATE frames SET sha256 = NULL WHERE sequence_id = $1 OR sequence_id = $2", [keep.Id, drop.Id], Ct); + var copy = await PairAsync(fx, keep.Id, drop.Id); + var merger = Merger(fx); + var (engine, handler) = Engine(fx, merger, new FakeProjects(), new FakeWorkspace()); + await engine.StartAsync(Ct); + // Filed at the verify, then the exclusion fails (a drive drops out, project.json is held) before the journal says so. + var failedOnce = false; + handler.BeforeLeaveOutOfMain = _ => + { + if (failedOnce) return Task.CompletedTask; + failedOnce = true; + throw new IOException("project.json is in use"); + }; + var plan = await merger.PlanAsync(copy.Id, keep.Id, drop.Id, await ChoicesAsync(fx, keep.Id, drop.Id, CopyPhotoPolicy.Union), NoContext, Ct); + Assert.Empty(plan.Photos); + var job = await merger.EnqueueAsync(engine, new FoundCopyStore(fx.Db), plan, keep.DisplayTitle, Ct); + await fx.WaitForAsync(job.Id, JobState.Failed); + Assert.True((await HashesAsync(fx, keep.Id)).SetEquals([Sha(mine, 0), Sha(theirs, 0)])); + + await engine.ResumeAsync(job.Id, Ct); + await fx.WaitForAsync(job.Id, JobState.Done); + + // The resumed verify finds the version in the kept sequence and leaves it out of Main: one photo at that instant. + Assert.Null(await fx.Db.Sequences.GetAsync(drop.Id)); + AssertVersions(await new CopySides(fx.Db).VersionsAsync(keep.Id, Ct), Sha(mine, 0), Sha(theirs, 0)); + } + [Test] public async Task ASecondVersionCopiedInByAMergeAbandonedBeforeItsDetailsStaysOutOfMain() { diff --git a/tests/Chronos.Data.Tests/Copies/CopyEngineTests.cs b/tests/Chronos.Data.Tests/Copies/CopyEngineTests.cs index 7701e1f3..7641cb80 100644 --- a/tests/Chronos.Data.Tests/Copies/CopyEngineTests.cs +++ b/tests/Chronos.Data.Tests/Copies/CopyEngineTests.cs @@ -183,6 +183,30 @@ public sealed class CopyEngineTests(TestContext context) Assert.NotNull(await f.Sync.Links.GetAsync(f.Server, remote.Id, f.Ct)); } + [Test] + public async Task KeepHereOfASequenceDeletedOnTheServerIsLeftOutOfUploadAllLocal() + { + await using var f = await FixtureAsync(context); + var local = await f.LocalAsync("Comet", f.NewPhotos(2)); + var gone = Guid.CreateVersion7(); + var pair = await f.Sync.Copies.EnsureLinkedAsync(f.Server, gone, local.Id, f.Ct); + // Deleted on the server: two 404s the re-check apart, read as deleted on server. + var at = DateTimeOffset.UtcNow.AddHours(-2); + await f.Sync.Copies.MarkRemoteGoneAsync(f.Server, gone, local.Id, Guid.NewGuid(), at, f.Ct); + await f.Sync.Copies.MarkRemoteGoneAsync(f.Server, gone, local.Id, Guid.NewGuid(), at.AddHours(1), f.Ct); + using var engine = Engine(f); + + await engine.KeepHereAsync(pair.Id, f.Ct); + + // Kept here: Upload all local leaves it out, and the answer stays. + var row = (await f.Sync.Copies.GetAsync(pair.Id, f.Ct))!; + Assert.Equal((CopyState.KeptApart, true), (row.State, row.RemoteGone)); + var entry = new SyncEntry(local, null, SyncStatus.LocalOnly); + var (upload, skipped) = UploadAllRule.Select([entry], await f.Sync.Copies.ListAsync(f.Ct), new HashSet(), new HashSet()); + Assert.Empty(upload); + Assert.Equal(local.Id, skipped.Single().Entry.Local!.Id); + } + [Test] public async Task LinkIsRefusedWhenTheLocalCopyIsLinkedToAnotherServerSequence() { diff --git a/tests/Chronos.Data.Tests/Copies/FoundCopyStoreTests.cs b/tests/Chronos.Data.Tests/Copies/FoundCopyStoreTests.cs index 4fb8722e..2bd347ea 100644 --- a/tests/Chronos.Data.Tests/Copies/FoundCopyStoreTests.cs +++ b/tests/Chronos.Data.Tests/Copies/FoundCopyStoreTests.cs @@ -288,10 +288,10 @@ public abstract class FoundCopyStoreTests(TestContext context) : RepositoryTest( Assert.True(await store.SetStateAsync(linked.Id, CopyState.Candidate, CopyState.Linked, Answer(), Ct)); var elsewhere = await store.UpsertFoundAsync(Remote(s[3].Id, Guid.CreateVersion7()), Ct); - // An observation-only link answers 404: no local copy is linked to it. + // After the answers, an observation-only link answers 404: no local copy is linked to it. var first = Guid.NewGuid(); - await store.MarkRemoteGoneAsync(Nas, remote, null, first, TestData.Now, Ct); await store.MarkRemoteGoneAsync(Nas, remote, null, first, TestData.Now.AddMinutes(1), Ct); + await store.MarkRemoteGoneAsync(Nas, remote, null, first, TestData.Now.AddMinutes(2), Ct); // The unanswered match is gone; the Keep apart answer stays and counts the 404 once, not read as deleted yet. Assert.Null(await store.GetAsync(candidate.Id, Ct)); diff --git a/tests/Chronos.Data.Tests/Sync/SyncTransferCopyTests.cs b/tests/Chronos.Data.Tests/Sync/SyncTransferCopyTests.cs index 212c561a..b60df382 100644 --- a/tests/Chronos.Data.Tests/Sync/SyncTransferCopyTests.cs +++ b/tests/Chronos.Data.Tests/Sync/SyncTransferCopyTests.cs @@ -394,6 +394,62 @@ public sealed class SyncTransferCopyTests(TestContext context) Assert.Equal("Comet", (await f.Db.Sequences.GetAsync(local.Id, f.Ct))!.Title); } + [Test] + public async Task ARetriedUploadThatJoinedAServerSequenceItKnewStillComparesItsDetails() + { + await using var f = Capable(await SyncFixture.CreateAsync(context)); + var photos = f.NewPhotos(4); + var local = await f.LocalAsync("Comet", [photos[0], photos[1]]); + var engine = await f.StartEngineAsync(); + var job = await f.Sync.EnqueueUploadAsync(engine, f.Server, local); + await f.Archive.WaitForAsync(job.Id, JobState.Done); + var first = Assert.NotNull(await f.Sync.Links.FindByLocalAsync(f.Server, local.Id, f.Ct)).RemoteId; + // The link and its pair were forgotten; the server sequence is listed again and renamed there. + var observed = Assert.NotNull(await f.Sync.Links.GetAsync(f.Server, first, f.Ct)) with { LocalId = null }; + await f.Sync.Links.UpsertAsync(observed, f.Ct); + await using (var session = await f.Db.Database.OpenAsync(f.Ct)) + await session.ExecuteAsync("DELETE FROM found_copies WHERE remote_id = $1", [first], f.Ct); + var server = f.Remote.Sequences[first]; + server.Title = "Comet NAS"; + server.SettingsVersion++; + server.UpdatedAt = DateTimeOffset.UtcNow; + await f.AddLocalAsync(local.Id, photos[2]); + await f.AddLocalAsync(local.Id, photos[3]); + // One original unreadable for the first attempt: it fails after joining the known sequence. + var damaged = (await f.Db.Frames.ListBySequenceAsync(local.Id, cancellationToken: f.Ct)).Single(fr => fr.Sha256 == Sha(photos[3])); + var path = f.Archive.Paths.FromRelative(damaged.RelativePath); + var bytes = await File.ReadAllBytesAsync(path, f.Ct); + var broken = bytes.ToArray(); + broken[^3] ^= 0xFF; + await File.WriteAllBytesAsync(path, broken, f.Ct); + + var row = new Job + { + Id = Guid.CreateVersion7(), + Kind = JobKind.UploadCommit, + TargetIds = [local.Id], + State = JobState.Running, + NodeId = "t#0", + Created = DateTimeOffset.UtcNow, + Started = DateTimeOffset.UtcNow, + }; + await f.Db.Jobs.EnqueueAsync(row, f.Ct); + var jobs = new JobEngine(f.Db, [], new JobEngineOptions { WorkerId = "t" }); + var attempt = new JobContext(jobs, row, f.Ct); + await Assert.ThrowsAsync(() => new SyncTransfers(f.Sync).UploadAsync(attempt, f.Remote, local.Id)); + Assert.Equal(first, Assert.NotNull(await f.Sync.Links.FindByLocalAsync(f.Server, local.Id, f.Ct)).RemoteId); + + // Retried from that attempt's checkpoint, the original readable again. + await File.WriteAllBytesAsync(path, bytes, f.Ct); + var retry = new JobContext(jobs, row with { Checkpoint = attempt.Checkpoint }, f.Ct); + await new SyncTransfers(f.Sync).UploadAsync(retry, f.Remote, local.Id); + + // Still joined, not made by this upload: the server's title is not overwritten unseen. + Assert.True(server.Frames.Select(fr => fr.Sha256).ToHashSet().SetEquals(photos.Select(Sha))); + Assert.Equal("Comet NAS", server.Title); + Assert.Equal("Comet", (await f.Db.Sequences.GetAsync(local.Id, f.Ct))!.Title); + } + [Test] public async Task AnAutomaticUploadAfterTheServerCopyIsGoneFailsAndCreatesNothing() {