fix(app): import gates, partial results and plan editing after review

- a card that leaves needs a new check; formatting re-lists the card and refuses
  one that changed since its check; files that are not photos are named in the
  format confirmation
- an import never stays stuck in Running; Retry never resumes an older job
- server imports list refused files and keep what was uploaded when stopped
- the archive result matches each copy to its job's record and shows the job's
  own error per file
- refreshing devices keeps typed titles and choices; titles lock while copying
- three destination names, merge and split of sessions, camera profiles shared
  by the cards of a camera, photo counts and a new-card toast
- disabled controls say why; keyboard focus follows the nickname field and
  Show plan (Esc closes it); label column fits longer languages
- capture states for insertion, running, failed and a new card

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-03 10:44:22 +00:00
1 parent 5aa5edab57
commit 29c82eba5c
27 files changed
+1286 -285

No files matched your search

@@ -33,7 +33,7 @@ public sealed class ImportFlowTests(TestContext context)
var plan = await destination.PlanAsync(card, choices.ToOptions(), media.Id, null, context.Cancellation);
Assert.Equal(3, plan.Sessions.Count);
Assert.Equal(30, plan.CopyCount);
var before = new CardActions(ImportDestinationKind.Archive, true, true, true, null, null, plan.FileCount);
var before = new CardActions(ImportDestinationKind.Archive, true, true, true, null, null, null);
Assert.False(before.CanCheck, "no import, no erase");
Assert.False(before.CanDelete);
Assert.False(before.CanFormat);
@@ -41,32 +41,54 @@ public sealed class ImportFlowTests(TestContext context)
var unverified = await archives.PlanCardEraseAsync(archive.Id, media.Id, card, null, context.Cancellation);
Assert.Empty(unverified.ToDelete);
Job queued;
await using (var engine = new JobEngine(db, archives.CreateJobHandlers(),
new JobEngineOptions { Workers = 1, WorkerId = "test", PollInterval = TimeSpan.FromMilliseconds(50), CheckpointInterval = TimeSpan.FromMilliseconds(50) }))
{
await engine.StartAsync(context.Cancellation);
var job = await engine.EnqueueAsync(ArchiveJobs.Import(archive, plan, media.Id, choices.VerifyCopies), cancellationToken: context.Cancellation);
await WaitDoneAsync(db, job.Id);
queued = await engine.EnqueueAsync(ArchiveJobs.Import(archive, plan, media.Id, choices.VerifyCopies), cancellationToken: context.Cancellation);
await WaitDoneAsync(db, queued.Id);
}
var outcome = await ImportOutcome.CheckAsync(plan, choices.VerifyCopies,
async (item, ct) => (await db.Frames.FindBySizeAndCaptureAsync(archive.Id, item.Size, item.CapturedAt, ct)).Count > 0, context.Cancellation);
// The verification result comes from the job's own records: every planned copy has its frame.
var job = (await db.Jobs.GetAsync(queued.Id, context.Cancellation))!;
var outcome = await ArchiveImportCheck.CheckAsync(db, archive.Id, plan, job, media.Id, choices.VerifyCopies, context.Cancellation);
Assert.Equal(30, outcome.Copied);
Assert.True(outcome.IsComplete);
var afterImport = new CardActions(ImportDestinationKind.Archive, true, true, true, outcome, null, plan.FileCount);
Assert.Equal(30, (await ArchiveImportCheck.CheckAsync(db, archive.Id, plan, job, null, choices.VerifyCopies, context.Cancellation)).Copied,
"a folder source, without import history, finds its frames in the sessions' sequences");
var afterImport = new CardActions(ImportDestinationKind.Archive, true, true, true, outcome, null, null);
Assert.True(afterImport.CanCheck);
Assert.False(afterImport.CanDelete, "the dry run must come first");
Assert.Equal(Loc.L("Import.Blocked.NoDryRun"), afterImport.DeleteBlocker);
var snapshot = CardSnapshot.Take(card, Volume.Identity);
var erase = await archives.PlanCardEraseAsync(archive.Id, media.Id, card, null, context.Cancellation);
var ready = afterImport with { Erase = erase };
var ready = afterImport with { Erase = erase, Card = snapshot };
Assert.True(ready.CanDelete);
Assert.True(ready.CanFormat);
Assert.Equal(30, ready.DeleteCount);
Assert.Equal("30 verified on the card · " + Infrastructure.Formatting.Bytes(ready.DeleteBytes), ready.EraseText);
Assert.False((ready with { Card = null }).CanDelete, "the dry run lists the card too");
Assert.True(snapshot.IsUnchanged(CardSnapshot.Take(card, Volume.Identity)));
Assert.False(snapshot.IsUnchanged(CardSnapshot.Take(card, "another card")), "another card with the same files is not the checked card");
// A video is not a photo: it never blocks formatting but is named as never imported.
File.WriteAllBytes(Path.Combine(card, "DCIM", "100CANON", "MVI_0031.MP4"), [1, 2, 3]);
var withVideo = ready with { Card = CardSnapshot.Take(card, Volume.Identity) };
Assert.True(withVideo.CanFormat);
Assert.SequenceEqual(["DCIM/100CANON/MVI_0031.MP4"], withVideo.NotImported);
Assert.Equal("30 verified on the card · " + Infrastructure.Formatting.Bytes(ready.DeleteBytes) + " · 1 other file not imported", withVideo.EraseText);
Assert.False(snapshot.IsUnchanged(withVideo.Card!), "a file added since the check changes the card");
File.Delete(Path.Combine(card, "DCIM", "100CANON", "MVI_0031.MP4"));
// A photo added to the card after the import is not verified: formatting would lose it.
Assert.False((ready with { CardPhotos = 31 }).CanFormat);
File.WriteAllBytes(Path.Combine(card, "DCIM", "100CANON", "IMG_0031.JPG"), Jpeg(Start.AddDays(2), 31));
var withPhoto = ready with { Card = CardSnapshot.Take(card, Volume.Identity) };
Assert.False(withPhoto.CanFormat);
Assert.Equal(Loc.L("Import.Blocked.NotAllVerified"), withPhoto.FormatBlocker);
Assert.True(withPhoto.CanDelete, "the verified photos may still be deleted");
File.Delete(Path.Combine(card, "DCIM", "100CANON", "IMG_0031.JPG"));
Assert.False((ready with { Outcome = outcome with { Verified = false } }).CanFormat);
Assert.False((ready with { Destination = ImportDestinationKind.Folder }).CanDelete);
Assert.False((ready with { IsInserted = false }).CanDelete);
@@ -101,22 +123,47 @@ public sealed class ImportFlowTests(TestContext context)
new FolderImportSink(target), verify: true, null, context.Cancellation);
Assert.Equal(0, again.Copied);
Assert.Equal(16, again.Duplicates);
Assert.False(new CardActions(ImportDestinationKind.Folder, false, true, true, outcome, null, 16).CanCheck);
Assert.False(new CardActions(ImportDestinationKind.Folder, false, true, true, outcome, null, null).CanCheck);
}
[Test]
public async Task TheIndexCheckReportsPlannedCopiesThatNeverArrived()
public async Task TheIndexCheckReportsPlannedCopiesThatNeverArrivedWithTheJobsOwnError()
{
Loc.SetCulture(CultureInfo.GetCultureInfo("en"));
var plan = Plan(null, null, Session(1, "f", Item(1, Start), Item(2, Start.AddSeconds(2)), Item(3, Start.AddSeconds(4), action: ImportAction.SkipImported)));
var outcome = await ImportOutcome.CheckAsync(plan, true, (item, _) => Task.FromResult(!item.SourcePath.EndsWith("0002.CR2", StringComparison.Ordinal)),
var plan = Plan(null, null, Session(1, "f", Item(1, Start), Item(2, Start.AddSeconds(2)), Item(3, Start.AddSeconds(4), action: ImportAction.SkipImported),
Item(4, Start.AddSeconds(6))));
var errors = ImportOutcome.JobErrors("18:02:11 Not copied: DCIM/100CANON/IMG_0002.CR2 (Disk full)\n18:02:12 Imported 1, skipped 1, failed 1");
var outcome = await ImportOutcome.CheckAsync(plan, true,
(item, _) => Task.FromResult(item.SourcePath.EndsWith("0001.CR2", StringComparison.Ordinal) ? CommitCheck.Copied : CommitCheck.Missing), errors,
context.Cancellation);
Assert.Equal(1, outcome.Copied);
Assert.Equal(1, outcome.Skipped);
Assert.Equal("DCIM/100CANON/IMG_0002.CR2", outcome.Failures.Single().SourcePath);
Assert.Equal(2, outcome.Failures.Count);
Assert.Equal(new ImportFailure("DCIM/100CANON/IMG_0002.CR2", "Disk full"), outcome.Failures[0]);
Assert.Equal(Loc.L("Import.Result.NotCommitted"), outcome.Failures[1].Message, "no log line for it: not committed");
Assert.False(outcome.IsComplete);
}
[Test]
public void AnAbortedRunCountsWhatTheDestinationCommittedAndFailsTheRest()
{
Loc.SetCulture(CultureInfo.GetCultureInfo("en"));
var plan = Plan(null, null, Session(1, "f", Item(1, Start), Item(2, Start.AddSeconds(2)), Item(3, Start.AddSeconds(4)), Item(4, Start.AddSeconds(6),
action: ImportAction.SkipImported)));
var items = plan.Sessions[0].Items;
var report = new ImportSinkReport();
report.Committed[items[1].SourcePath] = new SinkCommit(Guid.NewGuid(), items[1].FileName, Duplicate: false);
report.Rejected[items[0].SourcePath] = "Hash mismatch";
var results = new[] { new ImportItemResult(plan.Sessions[0], items[0], ImportItemStatus.Copied, "a", new SinkCommit(null, items[0].FileName, false), null) };
var outcome = ImportOutcome.From(plan, results, verified: true, report, stopped: "Connection lost");
Assert.Equal(1, outcome.Copied, "committed in the batch the abort interrupted");
Assert.Equal(1, outcome.Skipped);
Assert.SequenceEqual(
[new ImportFailure(items[0].SourcePath, "Hash mismatch"), new ImportFailure(items[2].SourcePath, "Connection lost")],
outcome.Failures);
}
private async Task WaitDoneAsync(TitanoDatabase db, Guid jobId)
{
var until = DateTime.UtcNow.AddSeconds(60);