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 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-11-18 14:01:45 +01:00
1 parent e002c583d6
commit 6db4c2e80c
10 files changed
+168 -10

No files matched your search

@@ -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()
{