Files
Chronos/tests/Chronos.App.Tests/Import/ImportChoicesTests.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

119 lines
5.8 KiB
C#

using System.Text.Json;
using System.Text.Json.Serialization;
using Chronos.App.Import;
using Chronos.Core.Import;
using Chronos.Core.Model;
using Chronos.Data.Archiving;
using Chronos.Testing;
namespace Chronos.App.Tests.Import;
public sealed class ImportChoicesTests
{
[Test]
public void ACardProfileRoundTripsThroughTheForm()
{
var profile = new CardProfile
{
FolderTemplate = "{year}/{title}",
FileTemplate = "{name}",
SessionGapMinutes = 30,
MinimumSessionFrames = 4,
IncludeSubfolders = false,
VerifyCopies = false,
Duplicates = DuplicatePolicy.ImportAgain,
AfterImport = AfterImport.DeleteImported,
Eject = false,
DeepAnalysis = false,
};
var choices = ImportChoices.FromProfile(profile);
Assert.True(choices.SplitSessions);
Assert.Equal(30, choices.GapMinutes);
Assert.Equal(profile, choices.ToProfile());
}
[Test]
public void SessionsOffIsRememberedAsAZeroGapAndNeverSplits()
{
var off = new ImportChoices { SplitSessions = false, GapMinutes = 20 };
Assert.Equal(0, off.ToProfile().SessionGapMinutes);
Assert.Equal(TimeSpan.MaxValue, off.ToOptions().SessionGap);
var back = ImportChoices.FromProfile(off.ToProfile());
Assert.False(back.SplitSessions);
Assert.Equal(new CardProfile().SessionGapMinutes, back.GapMinutes);
Assert.Equal(TimeSpan.FromMinutes(20), (off with { SplitSessions = true }).ToOptions().SessionGap);
}
[Test]
public void OptionsCarryTheFormAndTheTypedTitles()
{
var titles = new Dictionary<string, string> { ["k"] = "Harbour" };
var options = new ImportChoices { MinimumFrames = 0, Duplicates = DuplicatePolicy.ImportAgain, VerifyCopies = false }.ToOptions(titles);
Assert.Equal(1, options.MinimumSessionFrames);
Assert.Equal(DuplicatePolicy.ImportAgain, options.Duplicates);
Assert.False(options.VerifyCopies);
Assert.Equal("Harbour", options.Titles["k"]);
}
[Test]
public void OnlyGroupingAndNamingChoicesNeedANewPlan()
{
var a = new ImportChoices();
Assert.False((a with { Duplicates = DuplicatePolicy.ImportAgain, VerifyCopies = false, Eject = false, AfterImport = AfterImport.FormatCard }).NeedsNewPlan(a));
Assert.False((a with { SplitSessions = false, GapMinutes = 5 }).NeedsNewPlan(a with { SplitSessions = false }));
Assert.True((a with { GapMinutes = 5 }).NeedsNewPlan(a));
Assert.True((a with { MinimumFrames = 2 }).NeedsNewPlan(a));
Assert.True((a with { FileTemplate = "{name}" }).NeedsNewPlan(a));
Assert.True((a with { Destination = ImportDestinationKind.Folder }).NeedsNewPlan(a));
Assert.True((a with { IncludeSubfolders = false }).NeedsNewPlan(a));
Assert.False((a with { FolderPath = @"D:\Shoots" }).NeedsNewPlan(a), "the folder path is not used for the archive");
var folder = a with { Destination = ImportDestinationKind.Folder, FolderPath = @"D:\Shoots" };
Assert.True((folder with { FolderPath = @"E:\Backup" }).NeedsNewPlan(folder));
Assert.False((folder with { FolderPath = @"d:\shoots" }).NeedsNewPlan(folder), "paths compare without case");
Assert.False(a.TitlesChangeNames);
Assert.True((a with { FolderTemplate = "{year}/{Title:upper}" }).TitlesChangeNames);
}
[Test]
public void ACardFollowsItsCameraProfileWhenItJoinedItOrHasNoSettingsYet()
{
var shared = new CardProfile { SessionGapMinutes = 90 };
var defaults = new CardProfile { SessionGapMinutes = 45 };
var own = Card("Canon", "Canon EOS R5", new CardProfile { SessionGapMinutes = 20 }, daysAgo: 30);
var fresh = Card("Canon", "Canon EOS R5", null, daysAgo: 0);
var camera = new CameraProfile("Canon", "Canon EOS R5", shared, []);
Assert.Equal(new ResolvedProfile(shared, true), CameraProfiles.Resolve(fresh, camera, defaults), "a new card of a known camera needs no setup");
Assert.Equal(new ResolvedProfile(defaults, false), CameraProfiles.Resolve(fresh, null, defaults));
Assert.Equal(20, CameraProfiles.Resolve(own, camera, defaults).Profile.SessionGapMinutes, "a card with its own settings keeps them");
Assert.False(CameraProfiles.Resolve(own, camera, defaults).FollowsCamera);
Assert.Equal(new ResolvedProfile(shared, true), CameraProfiles.Resolve(own, camera.With(own.Id), defaults), "a card that joined follows the shared rules");
var joined = camera.With(own.Id).With(own.Id).With(fresh.Id);
Assert.SequenceEqual([own.Id, fresh.Id], joined.Cards);
Assert.SequenceEqual([fresh.Id], joined.Without(own.Id).Cards);
}
[Test]
public void SplitsAndMergesTravelToThePlanner()
{
var options = new ImportChoices().ToOptions(null, new HashSet<string> { "DCIM/100CANON/IMG_0005.CR2" }, new HashSet<string> { "DCIM/100CANON/IMG_0009.CR2" });
Assert.True(options.SplitBefore.Contains("DCIM/100CANON/IMG_0005.CR2"));
Assert.True(options.MergeAt.Contains("DCIM/100CANON/IMG_0009.CR2"));
Assert.Empty(new ImportChoices().ToOptions().SplitBefore);
}
private static MediaCard Card(string make, string model, CardProfile? profile, int daysAgo) => new()
{
Id = Guid.CreateVersion7(),
Identity = Guid.NewGuid().ToString("N"),
CameraMake = make,
CameraModel = model,
ProfileJson = profile is null ? null : JsonSerializer.Serialize(profile, StoredProfile),
LastSeen = DateTimeOffset.UtcNow.AddDays(-daysAgo),
};
/// <summary>How the card repository stores a profile (camel case, enum names).</summary>
private static readonly JsonSerializerOptions StoredProfile = new() { PropertyNamingPolicy = JsonNamingPolicy.CamelCase, Converters = { new JsonStringEnumConverter() } };
}