Files
Chronos/tests/Chronos.App.Tests/Import/ImportPlansTests.cs
T
Alby96andClaude Opus 5.5 f2b58522b9
CI / Build and test (push) Successful in 8m14s
CI / Windows tests and installer (push) Skipped
CI / YAML check (push) Successful in 7s
Release / Build, test and publish (push) Successful in 13m19s
CI / PostgreSQL 16 integration (push) Successful in 4m49s
CI / PostgreSQL 17 integration (push) Successful in 5m28s
CI / Docker image (push) Successful in 53s
Release / Server image (push) Failing after 10s
refactor!: rename Titano to Chronos and move CI and releases to Gitea (#6)
The owner renamed the product and moved the repository to the self-hosted
Gitea (https://gitea.encke-hake.ts.net/BalboSoft/Chronos) for more control,
and asked for Actions and a first automatic release with the server package
and the Windows exe (docs/requests/2026-10-23-chronos-gitea.md).

- Chronos everywhere: a byte-exact rename of contents and paths, then a
  per-language review of the forms the old name's ending had dictated.
- Gitea instead of GitHub: the update check, licence, issue and support
  links read ChronosReleasesUrl; the update check takes the highest stable
  version, offers a pre-release build its final release and reports a
  repository it cannot see as a failed check. EULA, security policy and
  Gitea issue forms live at the repository root.
- Gitea Actions for the Linux act_runner (.gitea/workflows): CI, release,
  nightly image and performance gates in the .NET SDK container with git
  checkout and the system SQLite. The release cross-compiles the Windows
  programs, checks their icon, version and DPI manifest, packs installers
  and zips, publishes the Gitea release and pushes the server image
  (REGISTRY_TOKEN). Windows-only tests run in an opt-in job on a Windows
  runner (WINDOWS_RUNNER).
- New Chronos.Tools commands: zip, gitea-release, postgres-ci (replaces the
  docker-exec script, which Gitea's service containers do not allow; the
  throw-away server runs without durability) and pe-check.
- Timed tests take their budget from TestTiming (CHRONOS_TEST_TIME_FACTOR,
  3 on the shared runner; the weekly performance gates keep theirs).

BREAKING CHANGE: programs, settings, data folders, file types, environment
variables and the Docker image use the new name; nothing is migrated from
Titano, which never had a release.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Alberto Balbo <alberto.balbo.96@gmail.com>
2026-10-23 12:45:18 +02:00

187 lines
9.6 KiB
C#

using System.Globalization;
using Chronos.App.Import;
using Chronos.Core.Import;
using Chronos.Core.Localization;
using Chronos.Testing;
using static Chronos.App.Tests.Import.ImportTestData;
namespace Chronos.App.Tests.Import;
public sealed class ImportPlansTests
{
public ImportPlansTests() => Loc.SetCulture(CultureInfo.GetCultureInfo("en"));
internal static ImportPlan ThreeSessions(long? available = 200_000_000)
{
var duplicate = Guid.CreateVersion7();
return Plan(available, [new ImportProblem("DCIM/100CANON/IMG_0099.CR2", "Access denied")],
Session(1, "2026/2026-09-28 Canon EOS R5", Item(1, Start), Item(2, Start.AddSeconds(2)), Item(3, Start.AddSeconds(4)), Item(4, Start.AddSeconds(8))),
Session(2, "2026/2026-09-29 Canon EOS R5", Item(5, Start.AddDays(1)), Item(6, Start.AddDays(1).AddSeconds(120), action: ImportAction.SkipInArchive, existing: duplicate)),
Session(3, "2026/2026-09-30 Canon EOS R5", Item(7, Start.AddDays(2), action: ImportAction.SkipImported)));
}
[Test]
public void TotalsCountWhatIsCopiedSkippedAndDuplicated()
{
var totals = ImportPlans.Totals(ThreeSessions(), verify: true);
Assert.Equal(3, totals.Sessions);
Assert.Equal(7, totals.Photos);
Assert.Equal(5, totals.CopyCount);
Assert.Equal(5 * 24_000_000L, totals.CopyBytes);
Assert.Equal(1, totals.Duplicates);
Assert.Equal(1, totals.ImportedBefore);
Assert.Equal(1, totals.Problems);
Assert.Equal(80_000_000L, totals.FreeAfter);
Assert.True(totals.HasEnoughSpace);
Assert.Equal(TimeSpan.FromSeconds(3), totals.Estimate);
Assert.Equal("3 sessions · 7 photos · 120 MB · about 3 s", totals.Text);
Assert.Equal("3 sessions · 7 photos · 120 MB", totals.SummaryText);
Assert.Equal("1 duplicate", totals.DuplicatesText);
Assert.Equal("Import 5 photos", totals.ImportText);
Assert.Equal("80 MB free after import", totals.SpaceText);
}
[Test]
public void ASmallDestinationReportsTheMissingSpace()
{
var totals = ImportPlans.Totals(ThreeSessions(available: 100_000_000), verify: false);
Assert.False(totals.HasEnoughSpace);
Assert.Equal("20 MB missing", totals.SpaceText);
Assert.Equal(string.Empty, ImportPlans.Totals(ThreeSessions(available: null), verify: false).SpaceText);
Assert.Equal(TimeSpan.FromSeconds(2), ImportPlans.Totals(ThreeSessions(), verify: false).Estimate);
}
[Test]
public void TheDuplicateChoiceFlipsOnlyPhotosAlreadyInTheArchive()
{
var plan = ThreeSessions();
var again = ImportPlans.WithDuplicates(plan, DuplicatePolicy.ImportAgain);
Assert.Equal(6, again.CopyCount);
var duplicate = again.Sessions[1].Items[1];
Assert.Equal(ImportAction.Copy, duplicate.Action);
Assert.NotNull(duplicate.ExistingFrameId);
Assert.Equal(ImportAction.SkipImported, again.Sessions[2].Items[0].Action);
var skipped = ImportPlans.WithDuplicates(again, DuplicatePolicy.Skip);
Assert.Equal(ImportAction.SkipInArchive, skipped.Sessions[1].Items[1].Action);
Assert.Equal(plan.CopyCount, skipped.CopyCount);
Assert.Equal("Import again", ImportPlans.Details(again, ImportDestinationKind.Archive, true).Rows.Single(r => r.Source.EndsWith("0006.CR2", StringComparison.Ordinal)).ActionText);
}
[Test]
public void TypedTitlesNameTheirSessions()
{
var plan = ThreeSessions();
var titled = ImportPlans.WithTitles(plan, new Dictionary<string, string>
{
[plan.Sessions[0].SessionKey] = " Harbour sunset ",
[plan.Sessions[1].SessionKey] = " ",
["unknown"] = "ignored",
});
Assert.Equal("Harbour sunset", titled.Sessions[0].Title);
Assert.Null(titled.Sessions[1].Title);
Assert.Null(titled.Sessions[2].Title);
Assert.SequenceEqual(plan.Items.Select(i => i.FileName), titled.Items.Select(i => i.FileName));
}
[Test]
public void SessionRowsShowTimesIntervalsAndWhereTheyGo()
{
var plan = ThreeSessions();
var rows = ImportPlans.Sessions(plan, ImportDestinationKind.Archive, new HashSet<string>(["2026/2026-09-29 Canon EOS R5"], StringComparer.OrdinalIgnoreCase));
Assert.Equal(3, rows.Count);
Assert.Equal("4 · 2 s", rows[0].FramesText);
Assert.Equal("2 · 2 min", rows[1].FramesText);
Assert.Equal("1", rows[2].FramesText);
Assert.True(rows[0].IsNew);
Assert.Equal("New · 2026/2026-09-28 Canon EOS R5", rows[0].TargetText);
Assert.False(rows[1].IsNew);
Assert.Equal("Adds to · 2026/2026-09-29 Canon EOS R5", rows[1].TargetText);
Assert.Equal("2026-09-28 Canon EOS R5", rows[0].DefaultTitle);
Assert.Equal("Canon EOS R5", rows[0].CameraText);
Assert.Equal("96 MB", rows[0].SizeText);
Assert.Contains("6:02", rows[0].TimeText);
Assert.Equal("Server", ImportPlans.Sessions(plan, ImportDestinationKind.Server, new HashSet<string>())[0].TargetText);
}
[Test]
public void ShowPlanListsEveryFileItsDestinationAndTheConflicts()
{
var plan = ThreeSessions(available: 100_000_000);
var details = ImportPlans.Details(plan, ImportDestinationKind.Archive, verify: true);
Assert.Equal(plan.FileCount + plan.Sessions.Count, details.Rows.Count);
Assert.Equal(3, details.Rows.Count(r => r.Kind == PlanRowKind.Session));
var first = details.Rows[1];
Assert.Equal("DCIM/100CANON/IMG_0001.CR2", first.Source);
Assert.Equal("2026/2026-09-28 Canon EOS R5/originals/" + plan.Sessions[0].Items[0].FileName, first.Destination);
Assert.Equal("Copy", first.ActionText);
Assert.False(first.IsSkipped);
Assert.True(details.Rows.Single(r => r.Source.EndsWith("0007.CR2", StringComparison.Ordinal)).IsSkipped);
Assert.Equal(3, details.Conflicts.Count);
Assert.Contains("IMG_0099.CR2", details.Conflicts[0]);
Assert.Equal("7 files · copy 5 (120 MB) · 1 imported before · 1 duplicate", details.TotalsText);
var folder = ImportPlans.Details(plan, ImportDestinationKind.Folder, verify: true);
Assert.Equal("2026/2026-09-28 Canon EOS R5/" + plan.Sessions[0].Items[0].FileName, folder.Rows[1].Destination);
}
[Test]
public void ShowPlanShowsNamesUnderTheirSessionFolder()
{
var plan = ThreeSessions();
var details = ImportPlans.Details(plan, ImportDestinationKind.Archive, verify: true);
var session = details.Rows[0];
Assert.True(session.SourceText.StartsWith("Session 1 · ", StringComparison.Ordinal), session.SourceText);
Assert.Equal("2026/2026-09-28 Canon EOS R5/originals", session.DestinationText);
var file = details.Rows[2];
Assert.Equal("IMG_0002.CR2", file.SourceText);
Assert.Equal(plan.Sessions[0].Items[1].FileName, file.DestinationText);
Assert.Equal("DCIM/100CANON/IMG_0002.CR2", file.Source, "the full path stays for the tooltip");
Assert.Equal("Split at IMG_0002.CR2", file.SplitName);
}
[Test]
public void TheNamePreviewShowsTheFirstThreeCopiedFiles()
{
var plan = ThreeSessions();
var names = ImportPlans.FirstDestinations(plan, ImportDestinationKind.Archive);
Assert.Equal(3, names.Count);
Assert.Equal("2026/2026-09-28 Canon EOS R5/" + plan.Sessions[0].Items[0].FileName, names[0]);
Assert.Equal("→ " + names[0] + " · " + plan.Sessions[0].Items[1].FileName + " · " + plan.Sessions[0].Items[2].FileName, ImportPlans.NamePreview(names));
Assert.Equal(plan.Sessions[0].Items[0].FileName, ImportPlans.FirstDestinations(plan, ImportDestinationKind.Server)[0]);
// A name in another folder keeps its folder.
var across = ImportPlans.FirstDestinations(plan, ImportDestinationKind.Archive, 5);
Assert.Equal(5, across.Count);
Assert.True(ImportPlans.NamePreview(across).EndsWith(" · " + across[4], StringComparison.Ordinal), "the third session's folder is shown");
var nothing = ImportPlans.WithDuplicates(Plan(null, null, Session(1, "x", Item(1, Start, action: ImportAction.SkipImported))), DuplicatePolicy.Skip);
Assert.Empty(ImportPlans.FirstDestinations(nothing, ImportDestinationKind.Archive));
Assert.Equal(string.Empty, ImportPlans.NamePreview([]));
}
[Test]
public void ASessionMergesOnlyIntoTheEarlierSessionOfTheSameCameraAndFormat()
{
var plan = ThreeSessions();
var rows = ImportPlans.Sessions(plan, ImportDestinationKind.Archive, new HashSet<string>());
Assert.Null(rows[0].MergesInto);
Assert.Equal(1, rows[1].MergesInto);
Assert.Equal(2, rows[2].MergesInto);
Assert.Equal("DCIM/100CANON/IMG_0005.CR2", rows[1].FirstPath);
var otherBody = plan with { Sessions = [plan.Sessions[0], plan.Sessions[1] with { CameraSerial = "9999" }, plan.Sessions[2]] };
var split = ImportPlans.Sessions(otherBody, ImportDestinationKind.Archive, new HashSet<string>());
Assert.Null(split[1].MergesInto, "another camera body never merges");
Assert.Equal(1, split[2].MergesInto, "the earlier session of the same body, skipping the other camera");
}
[Test]
public void ShowPlanOffersASplitOnEveryPhotoButTheFirstOfItsSession()
{
var details = ImportPlans.Details(ThreeSessions(), ImportDestinationKind.Archive, verify: true);
Assert.False(details.Rows[0].CanSplit, "a session heading");
Assert.False(details.Rows[1].CanSplit, "the first photo already starts the session");
Assert.True(details.Rows[2].CanSplit);
}
}