Merge branch 'review2-p1-fix-import' into claude/owner-review-2-p1

This commit is contained in:
Alby96 committed 2026-10-26 23:40:39 +01:00
commit b8fa04dc28
13 files changed
+181 -25

No files matched your search

@@ -46,6 +46,9 @@ public sealed class ImportLanguageTests
var time = ImportPlans.Sessions(plan, ImportDestinationKind.Archive, new HashSet<string>())[0].TimeText;
Assert.Contains("←", time);
Assert.False(time.Contains('→'), "a right-to-left reader would see the arrow point back to the start");
var days = ImportPlans.Sessions(OverEightDays(), ImportDestinationKind.Archive, new HashSet<string>())[0].TimeText;
Assert.Contains("←", days);
Assert.False(days.Contains('→'), "also between two dates");
}
finally
{
@@ -1,5 +1,6 @@
using System.Globalization;
using Chronos.App.Import;
using Chronos.App.Infrastructure;
using Chronos.Core.Imaging;
using Chronos.Core.Import;
using Chronos.Core.Localization;
@@ -21,6 +22,10 @@ public sealed class ImportPlansTests
Session(3, "2026/2026-09-30 Canon EOS R5", Item(7, Start.AddDays(2), action: ImportAction.SkipImported)));
}
/// <summary>A whole folder shot over eight days, as one sequence.</summary>
internal static ImportPlan OverEightDays() =>
Plan(null, null, Session(1, "2026/Construction", Item(1, Start), Item(2, Start.AddDays(8).AddMinutes(3)))) with { Grouping = ImportGrouping.WholeFolder };
[Test]
public void TotalsCountWhatIsCopiedSkippedAndDuplicated()
{
@@ -105,6 +110,21 @@ public sealed class ImportPlansTests
Assert.Equal("Server", ImportPlans.Sessions(plan, ImportDestinationKind.Server, new HashSet<string>())[0].TargetText);
}
[Test]
public void ASessionThatEndsOnAnotherDayShowsBothDates()
{
var plan = OverEightDays();
var end = Start.AddDays(8).AddMinutes(3);
var time = ImportPlans.Sessions(plan, ImportDestinationKind.Archive, new HashSet<string>())[0].TimeText;
Assert.Equal($"{Formatting.Date(Start)} {Start.ToString("t", Loc.Culture)} → {Formatting.Date(end)} {end.ToString("t", Loc.Culture)}", time);
Assert.Equal(Loc.L("Import.Details.Session", 1, time), ImportPlans.Details(plan, ImportDestinationKind.Archive, verify: true).Rows[0].SourceText,
"the Show plan heading reads the same");
var sameDay = ImportPlans.Sessions(ThreeSessions(), ImportDestinationKind.Archive, new HashSet<string>())[0].TimeText;
Assert.Equal($"{Formatting.Date(Start)} · {Start.ToString("t", Loc.Culture)} → {Start.AddSeconds(8).ToString("t", Loc.Culture)}", sameDay,
"a session within one day shows its date once");
}
[Test]
public void ShowPlanListsEveryFileItsDestinationAndTheConflicts()
{
@@ -9,6 +9,7 @@ using Chronos.App.Infrastructure;
using Chronos.App.Sections;
using Chronos.App.Shell;
using Chronos.App.Tests.Windows;
using Chronos.Core.Import;
using Chronos.Core.Localization;
using Chronos.Testing;
using Chronos.Ui.Controls;
@@ -222,6 +223,75 @@ public sealed class ImportScreenSmokeTests
await import.WaitForPlanAsync();
});
/// <summary>
/// "Group" (BRIEF §12.4) is offered for a picked folder only, and a card is always planned by sessions. Switching the
/// grouping drops the splits made on the other grouping's sessions, and the session controls it turns off say why.
/// </summary>
[Test]
public Task AWholeFolderIsOfferedForAFolderOnlyAndDropsTheSplitsMadeBefore() => ScreenHost.RunAsync(async () =>
{
await using var app = await ScreenSmokeTests.SampleApp.StartAsync();
await app.Sample.FillAsync();
var import = app.Shell.Import;
var card = SampleCards.Card(app.Services.Environment.DataDirectory);
// A card: no Group choice, and asking for a whole folder changes nothing.
await ShowAsync(app, "plan");
Assert.False(import.CanGroupFolder);
import.GroupWholeFolder = true;
Assert.True(import.GroupBySessions);
Assert.Equal(ImportGrouping.Sessions, import.Choices.Grouping);
Assert.True(import.SessionsApply);
// The card's photos picked as a folder start by sessions: night, dawn and sunset.
await import.ImportFolderAsync(card.Root);
await import.WaitForPlanAsync();
Assert.True(import.CanGroupFolder);
Assert.True(import.GroupBySessions);
Assert.Equal((ImportGrouping.Sessions, 3), (import.Plan!.Grouping, import.Plan.Sessions.Count));
// The sunset split in two halves of twelve photos.
import.ShowPlanCommand.Execute(null);
import.SplitCommand.Execute(import.Details!.Rows.Where(r => r.Kind == PlanRowKind.File).ToList()[^12]);
await import.WaitForPlanAsync();
Assert.Equal(4, import.Plan!.Sessions.Count, "the split starts a session");
// The whole folder is one sequence for its one format, not cut where the sessions were split.
import.GroupWholeFolder = true;
await WaitUntilAsync(app, () => import.Plan is { Grouping: ImportGrouping.WholeFolder } && import.Phase == ImportPhase.Ready, "the whole folder is planned");
Assert.Equal(ImportGrouping.WholeFolder, import.Choices.Grouping);
Assert.Equal(1, import.Plan!.Sessions.Count);
Assert.False(import.SessionsApply);
Assert.False(import.GapApplies);
var why = Loc.L("Import.Blocked.WholeFolder");
Assert.Equal((why, why, why), (import.SessionsToolTip, import.GapMinutes.ToolTip, import.MinimumFrames.ToolTip));
var boxes = app.FindAll<TextBox>().Where(t => IsInImport(t) && EditBehavior.GetField(t) is { } f && (f == import.GapMinutes || f == import.MinimumFrames)).ToList();
Assert.Equal(2, boxes.Count);
foreach (var box in boxes)
{
Assert.False(box.IsEnabled);
Assert.True(ToolTipService.GetShowOnDisabled(box), "a disabled session box still shows why");
Assert.Equal(why, box.ToolTip as string);
}
// Back to sessions: the split made before stays gone.
import.GroupBySessions = true;
await WaitUntilAsync(app, () => import.Plan is { Grouping: ImportGrouping.Sessions } && import.Phase == ImportPhase.Ready, "the sessions are planned again");
Assert.Equal(3, import.Plan!.Sessions.Count);
Assert.True(import.SessionsApply);
Assert.Equal(Loc.L("Tooltips.Import.Gap"), import.GapMinutes.ToolTip);
// Choosing the card again leaves the folder's whole-folder choice behind.
import.GroupWholeFolder = true;
await WaitUntilAsync(app, () => import.Plan is { Grouping: ImportGrouping.WholeFolder } && import.Phase == ImportPhase.Ready, "the whole folder is planned");
import.SelectSource(card.Identity);
await import.WaitForPlanAsync();
Assert.False(import.CanGroupFolder);
Assert.True(import.GroupBySessions);
Assert.Equal(ImportGrouping.Sessions, import.Choices.Grouping);
Assert.Equal((ImportGrouping.Sessions, 3), (import.Plan!.Grouping, import.Plan.Sessions.Count));
});
/// <summary>As <c>--capture</c> does: toasts of the previous state go, those of an insertion state stay.</summary>
private static async Task ShowAsync(ScreenSmokeTests.SampleApp app, string state)
{
@@ -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) };