fix(import): keep a server rename on re-import and show multi-day sessions

A whole folder imported again to the server sent its folder name as the
sequence title on every run, undoing a rename made on the server. The
sink now sends a typed title as before, but the folder's default name
only to a sequence that has no title yet (it reads the sequence first).
The archive already applied a title only when it created the sequence.

A session that ends on another day, as a whole folder often does,
showed only its first date ("28/09/2026 · 18:02 → 18:05"), which read
as a few minutes on one day. Its plan row and Show plan heading now
show both dates, from two new invariant resources (with the
right-to-left arrow).

The Gap and Minimum boxes now show their tooltip while disabled, so the
reason Whole folder turns them off reaches them, not only the Sessions
check box. Doc comments that said a merge needs the same camera now
mention the whole-folder rule.

Tests: a server whole-folder import run twice keeps the server's rename
and still applies a typed title; multi-day time text in both reading
directions; and the Import view model's Group rules (folder only, cards
planned by sessions, switching drops splits, tooltips say why).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-10-26 23:33:16 +01:00
1 parent a34b33d50b
commit a809416199
13 files changed
+181 -25

No files matched your search

@@ -46,6 +46,39 @@ public sealed class ServerImportSinkTests(TestContext context)
Assert.Empty(Directory.EnumerateFileSystemEntries(staging));
}
[Test]
public async Task AWholeFolderImportedAgainKeepsTheNameItsSequenceWasGivenOnTheServer()
{
var folder = Card(Path.Combine(context.CreateTempDirectory("folder"), "Etna"), 4, Start);
var staging = context.CreateTempDirectory("staging");
var server = new FakeUploadServer(chunkSize: 4096);
using var client = new ChronosClient(new Uri("https://nas.local:8443/"), new CertificatePinning([]), "tests", server) { Token = "t" };
var destination = new UnindexedDestination(ImportDestinationKind.Server, staging);
var options = new ImportChoices { Grouping = ImportGrouping.WholeFolder }.ToOptions();
var first = await destination.PlanAsync(folder, options, null, null, context.Cancellation);
await LocalImport.RunAsync(first, new ServerImportSink(client, staging), "Etna", verify: true, null, context.Cancellation);
var (sequence, title) = server.Titles.Single();
Assert.Equal("Etna", title, "a new sequence takes the folder's name");
// Renamed on the server; a photo added to the folder joins the same sequence and leaves its name alone.
server.Titles[sequence] = "Etna 2026 eruption";
var photos = Path.Combine(folder, "DCIM", "100CANON");
File.WriteAllBytes(Path.Combine(photos, "IMG_0005.JPG"), Jpeg(Start.AddMinutes(10), 5));
var again = await destination.PlanAsync(folder, options, null, null, context.Cancellation);
var outcome = await LocalImport.RunAsync(again, new ServerImportSink(client, staging), "Etna", verify: true, null, context.Cancellation);
Assert.Equal((1, 4), (outcome.Copied, outcome.Duplicates));
Assert.Equal("Etna 2026 eruption", server.Titles[sequence]);
Assert.Equal(1, server.TitleUpdates, "only the new sequence was named");
// A title the user types still names it.
File.WriteAllBytes(Path.Combine(photos, "IMG_0006.JPG"), Jpeg(Start.AddMinutes(20), 6));
var typed = ImportPlans.WithTitles(await destination.PlanAsync(folder, options, null, null, context.Cancellation),
new Dictionary<string, string> { [again.Sessions[0].SessionKey] = "Etna at night" });
await LocalImport.RunAsync(typed, new ServerImportSink(client, staging), "Etna", verify: true, null, context.Cancellation);
Assert.Equal("Etna at night", server.Titles.Single().Value);
}
[Test]
public async Task PhotosTheServerAlreadyHoldsAreNotSentAgain()
{
@@ -233,7 +266,7 @@ public sealed class ServerImportSinkTests(TestContext context)
public void Advance(TimeSpan by) => Interlocked.Add(ref _ticks, by.Ticks);
}
/// <summary>Start, chunk and complete of BRIEF §14.4, plus the title update and card reports; the hash is checked at completion.</summary>
/// <summary>Start, chunk and complete of BRIEF §14.4, plus the sequence's title and card reports; the hash is checked at completion.</summary>
private sealed class FakeUploadServer(int chunkSize) : HttpMessageHandler
{
private readonly Dictionary<Guid, Upload> _open = [];
@@ -241,7 +274,11 @@ public sealed class ServerImportSinkTests(TestContext context)
private readonly Dictionary<string, Guid> _frames = new(StringComparer.Ordinal);
public List<Upload> Committed { get; } = [];
/// <summary>Each sequence's title on the server (a test may rename one, as a user would there).</summary>
public Dictionary<Guid, string> Titles { get; } = [];
public int TitleUpdates { get; private set; }
public int ChunkCount { get; private set; }
/// <summary>Flip a byte of every chunk of this file (a damaged transfer).</summary>
@@ -321,16 +358,21 @@ public sealed class ServerImportSinkTests(TestContext context)
return Json(new CompleteUploadResponse(frame, sequence, Committed.Count(u => u.SessionKey == upload.SessionKey) - 1),
ProtocolJson.Default.CompleteUploadResponse);
}
if (request.Method == HttpMethod.Get && path is ["api", "v1", "sequences", var read])
return Json(Sequence(Guid.Parse(read), Titles.GetValueOrDefault(Guid.Parse(read))), ProtocolJson.Default.SequenceDto);
if (request.Method == HttpMethod.Patch && path is ["api", "v1", "sequences", var sequenceId])
{
var update = (await request.Content!.ReadFromJsonAsync(ProtocolJson.Default.UpdateSequenceRequest, cancellationToken))!;
Titles[Guid.Parse(sequenceId)] = update.Title!;
return Json(new SequenceDto(Guid.Parse(sequenceId), update.Title, update.Title!, "f", null, null, null, null, null, 0, null, 0, 0, 0, null, [], 0, null,
1, 1, 0, null, DateTimeOffset.UtcNow), ProtocolJson.Default.SequenceDto);
TitleUpdates++;
return Json(Sequence(Guid.Parse(sequenceId), update.Title), ProtocolJson.Default.SequenceDto);
}
return new HttpResponseMessage(HttpStatusCode.NotFound);
}
private static SequenceDto Sequence(Guid id, string? title) =>
new(id, title, title ?? "f", "f", null, null, null, null, null, 0, null, 0, 0, 0, null, [], 0, null, 1, 1, 0, null, DateTimeOffset.UtcNow);
private static HttpResponseMessage Json<T>(T value, System.Text.Json.Serialization.Metadata.JsonTypeInfo<T> type, HttpStatusCode status = HttpStatusCode.OK) =>
new(status) { Content = JsonContent.Create(value, type) };