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:
27 files changed
+1286
-285
No files matched your search
@@ -64,16 +64,37 @@ public sealed class ServerImportSinkTests(TestContext context)
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AHashTheServerRejectsStopsTheImport()
|
||||
public async Task AFileTheServerRefusesIsListedAndTheImportGoesOn()
|
||||
{
|
||||
var card = Card(context.CreateTempDirectory("card"), 8, Start);
|
||||
var staging = context.CreateTempDirectory("staging");
|
||||
var server = new FakeUploadServer(chunkSize: 4096) { Corrupt = true };
|
||||
var server = new FakeUploadServer(chunkSize: 4096) { CorruptFile = "IMG_0003.JPG" };
|
||||
using var client = new TitanoClient(new Uri("https://nas.local:8443/"), new CertificatePinning([]), "tests", server) { Token = "t" };
|
||||
var plan = await new UnindexedDestination(ImportDestinationKind.Server, staging).PlanAsync(card, new ImportChoices().ToOptions(), null, null, context.Cancellation);
|
||||
var error = await Assert.ThrowsAsync<TitanoApiException>(() => LocalImport.RunAsync(plan, new ServerImportSink(client, staging), true, null, context.Cancellation));
|
||||
Assert.Equal(HttpStatusCode.UnprocessableEntity, error.Status);
|
||||
Assert.Empty(server.Committed);
|
||||
var sink = new ServerImportSink(client, staging);
|
||||
|
||||
var outcome = await LocalImport.RunAsync(plan, sink, true, null, context.Cancellation, sink.Report);
|
||||
Assert.Equal(7, outcome.Copied);
|
||||
Assert.Equal(7, server.Committed.Count);
|
||||
Assert.Equal(new ImportFailure("DCIM/100CANON/IMG_0003.JPG", "Hash mismatch"), outcome.Failures.Single());
|
||||
Assert.Empty(Directory.EnumerateFileSystemEntries(staging));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ALostSignInStopsTheImportAndKeepsWhatWasUploaded()
|
||||
{
|
||||
var card = Card(context.CreateTempDirectory("card"), 8, Start);
|
||||
var staging = context.CreateTempDirectory("staging");
|
||||
var server = new FakeUploadServer(chunkSize: 4096) { SignedOutAfter = 3 };
|
||||
using var client = new TitanoClient(new Uri("https://nas.local:8443/"), new CertificatePinning([]), "tests", server) { Token = "t" };
|
||||
var plan = await new UnindexedDestination(ImportDestinationKind.Server, staging).PlanAsync(card, new ImportChoices().ToOptions(), null, null, context.Cancellation);
|
||||
var sink = new ServerImportSink(client, staging);
|
||||
|
||||
var outcome = await LocalImport.RunAsync(plan, sink, true, null, context.Cancellation, sink.Report);
|
||||
Assert.Equal(3, outcome.Copied, "the uploads the server committed before the sign-in was lost");
|
||||
Assert.Equal(5, outcome.Failures.Count);
|
||||
Assert.Equal("Sign in again", outcome.Failures[0].Message, "the server's sentence");
|
||||
Assert.False(outcome.IsComplete);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -103,8 +124,11 @@ public sealed class ServerImportSinkTests(TestContext context)
|
||||
public Dictionary<Guid, string> Titles { get; } = [];
|
||||
public int ChunkCount { get; private set; }
|
||||
|
||||
/// <summary>Flip a byte of every received chunk (a damaged transfer).</summary>
|
||||
public bool Corrupt { get; init; }
|
||||
/// <summary>Flip a byte of every chunk of this file (a damaged transfer).</summary>
|
||||
public string? CorruptFile { get; init; }
|
||||
|
||||
/// <summary>Answer 401 to new uploads once this many were committed (the sign-in expired).</summary>
|
||||
public int? SignedOutAfter { get; init; }
|
||||
|
||||
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
|
||||
{
|
||||
@@ -112,6 +136,8 @@ public sealed class ServerImportSinkTests(TestContext context)
|
||||
if (request.Method == HttpMethod.Post && path is ["api", "v1", "uploads"])
|
||||
{
|
||||
var start = (await request.Content!.ReadFromJsonAsync(ProtocolJson.Default.StartUploadRequest, cancellationToken))!;
|
||||
if (Committed.Count >= SignedOutAfter)
|
||||
return Json(new ApiError("unauthorized", "Sign in again"), ProtocolJson.Default.ApiError, HttpStatusCode.Unauthorized);
|
||||
if (_frames.TryGetValue(start.Sha256, out var existing))
|
||||
return Json(new StartUploadResponse(null, chunkSize, [], true, existing), ProtocolJson.Default.StartUploadResponse);
|
||||
var upload = new Upload(Guid.NewGuid(), start.FileName, start.Size, start.Sha256, start.SessionKey ?? "user");
|
||||
@@ -122,7 +148,7 @@ public sealed class ServerImportSinkTests(TestContext context)
|
||||
{
|
||||
var upload = _open[Guid.Parse(id)];
|
||||
var bytes = await request.Content!.ReadAsByteArrayAsync(cancellationToken);
|
||||
if (Corrupt) bytes[0] ^= 0xFF;
|
||||
if (upload.FileName == CorruptFile) bytes[0] ^= 0xFF;
|
||||
upload.Parts[int.Parse(n, System.Globalization.CultureInfo.InvariantCulture)] = bytes;
|
||||
ChunkCount++;
|
||||
return Json(new ChunkReceived(int.Parse(n, System.Globalization.CultureInfo.InvariantCulture), [.. upload.Parts.Keys]), ProtocolJson.Default.ChunkReceived);
|
||||
|
||||
Reference in new issue
Block a user