Files
Chronos/tests/Chronos.App.Tests/Library/RemoteCardsTests.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

137 lines
7.6 KiB
C#

using Chronos.App.Infrastructure;
using Chronos.App.Library;
using Chronos.Core.Localization;
using Chronos.Core.Model;
using Chronos.Data.Repositories;
using Chronos.Data.Sync;
using Chronos.Protocol;
using Chronos.Testing;
using Chronos.Ui.Controls;
namespace Chronos.App.Tests.Library;
/// <summary>Server sequences without a copy here as Library cards, and their place among the index's pages (BRIEF §4.4).</summary>
public sealed class RemoteCardsTests
{
private const string Server = "https://nas.local:8443";
private static SyncLink Link(string title, int frames = 100) => new() { Server = Server, RemoteId = Guid.CreateVersion7(), Title = title, FrameCount = frames };
private static Sequence Card(string title, DateTime? first, string? camera = null, params string[] tags) =>
RemoteCards.FromLink(Link(title)) with { FirstCapture = first, CameraModel = camera, Tags = tags };
private static Sequence Local(string title, DateTime? first) => new()
{
Id = Guid.CreateVersion7(),
ArchiveId = Guid.CreateVersion7(),
Title = title,
Folder = title,
FirstCapture = first,
};
[Test]
public void OnlyServerSequencesWithoutALocalCopyBecomeCards()
{
var harbour = new Sequence { Id = Guid.CreateVersion7(), ArchiveId = Guid.CreateVersion7(), Folder = "harbour", Title = "Harbour sunset" };
var sunrise = Link("Sunrise over Superga", 2_880) with { TotalBytes = 60_000_000_000, RemoteStatus = SequenceStatus.ProxiesBuilt, RenderCount = 1 };
var lake = Link("Lake Como storm");
SyncEntry[] table =
[
new(harbour, Link("Harbour sunset"), SyncStatus.InSync),
new(harbour with { Id = Guid.CreateVersion7() }, null, SyncStatus.LocalOnly),
new(null, sunrise, SyncStatus.RemoteOnly),
new(null, lake, SyncStatus.ProxiesOnly),
];
var cards = RemoteCards.Build(table, null);
Assert.SequenceEqual([sunrise.RemoteId, lake.RemoteId], cards.Select(c => c.Id));
var card = cards[0];
Assert.Equal("Sunrise over Superga", card.DisplayTitle);
Assert.Equal(2_880, card.FrameCount);
Assert.Equal(60_000_000_000, card.TotalBytes);
Assert.Equal(SequenceStatus.ProxiesBuilt, card.Status);
Assert.Equal(1, card.RenderedCount);
Assert.Equal(SequenceOrigin.Server, card.Origin);
Assert.Equal(SyncState.RemoteOnly, card.SyncState);
Assert.Equal(Guid.Empty, card.ArchiveId, "a remote card belongs to no archive of this PC");
}
[Test]
public void TheServersListingFillsInTheDetails()
{
var link = Link("Sunrise");
var dto = new SequenceDto(link.RemoteId, "Sunrise over Superga", "Sunrise over Superga", "2026/2026-07-02 Sony ILCE-7M4", "Sony", "ILCE-7M4", null,
new DateTime(2026, 7, 2, 5, 40, 0), new DateTime(2026, 7, 2, 7, 16, 0), 2_880, 2.0, 60_000_000_000, (int)SequenceStatus.ProxiesBuilt, 1, null,
["sunrise"], 4, null, 3, 2, 0, null, DateTimeOffset.UtcNow);
var card = RemoteCards.Build([new SyncEntry(null, link, SyncStatus.RemoteOnly)], new Dictionary<Guid, SequenceDto> { [dto.Id] = dto }).Single();
Assert.Equal("Sunrise over Superga", card.DisplayTitle);
Assert.Equal("ILCE-7M4", card.CameraModel);
Assert.Equal(new DateTime(2026, 7, 2, 5, 40, 0), card.FirstCapture);
Assert.SequenceEqual(["sunrise"], card.Tags);
Assert.Equal(4, card.Rating);
Assert.Equal(SyncState.RemoteOnly, card.SyncState);
}
[Test]
public void PreviewOnlyFramesShowAChipWithTheirCount()
{
// A server sequence of CR3s it reads only through their previews (BRIEF §8.2 tier 2).
var link = Link("Aurora");
var dto = new SequenceDto(link.RemoteId, "Aurora", "Aurora", "2026/2026-02-20 Nikon Z 8", "NIKON CORPORATION", "NIKON Z 8", null,
new DateTime(2026, 2, 20, 21, 0, 0), new DateTime(2026, 2, 21, 1, 8, 0), 1_860, 8.0, 50_000_000_000, (int)SequenceStatus.AnalyzedLight, 0, null,
[], 0, null, 1, 1, 0, null, DateTimeOffset.UtcNow, PreviewOnlyCount: 1_860);
var card = RemoteCards.Build([new SyncEntry(null, link, SyncStatus.RemoteOnly)], new Dictionary<Guid, SequenceDto> { [dto.Id] = dto }).Single();
Assert.Equal(1_860, card.PreviewOnlyCount);
Assert.Equal(1_860, RemoteCards.ToSequence(dto).PreviewOnlyCount);
var chip = SequenceItem.BuildStatuses(card, analysing: false).Single(s => s.Kind == StatusKind.PreviewOnly);
Assert.Equal(Formatting.Count(1_860), chip.Text);
Assert.Equal(Loc.Plural("Tooltips.Library.Status.PreviewOnly", 1_860), chip.ToolTip);
Assert.NotEqual(Loc.Plural("Tooltips.Library.Status.PreviewOnly", 1), chip.ToolTip, "plural forms");
Assert.False(SequenceItem.BuildStatuses(card with { PreviewOnlyCount = 0 }, analysing: false).Any(s => s.Kind == StatusKind.PreviewOnly), "no chip without them");
}
[Test]
public void CardsSortAmongThePagesAndFollowTheFilter()
{
var merge = new RemoteMerge();
var september = Card("Comet", new DateTime(2026, 9, 20), "ILCE-7M4", "stars");
var july = Card("Sunrise", new DateTime(2026, 7, 2), "ILCE-7M4");
var undated = Card("Unknown", null);
var otherYear = Card("Old", new DateTime(2024, 5, 1));
merge.Reset(new LibraryFilter(), [july, undated, september, otherYear]);
Assert.Equal(4, merge.Pending);
// Newest first: each page takes the cards that sort before its last row, the last page the rest.
var first = merge.Merge([Local("A", new DateTime(2026, 9, 28)), Local("B", new DateTime(2026, 8, 1))], last: false);
Assert.SequenceEqual(["A", "Comet", "B"], first.Select(s => s.DisplayTitle));
var second = merge.Merge([Local("C", new DateTime(2025, 1, 1))], last: false);
Assert.SequenceEqual(["Sunrise", "C"], second.Select(s => s.DisplayTitle));
var last = merge.Merge([Local("D", new DateTime(2023, 1, 1))], last: true);
Assert.SequenceEqual(["Old", "D", "Unknown"], last.Select(s => s.DisplayTitle), "undated cards come last");
Assert.Equal(0, merge.Pending);
merge.Reset(new LibraryFilter { Year = 2026, Text = "sun" }, [july, september, otherYear]);
Assert.SequenceEqual(["Sunrise"], merge.Merge([], last: true).Select(s => s.DisplayTitle));
merge.Reset(new LibraryFilter { Tag = "stars" }, [july, september]);
Assert.SequenceEqual(["Comet"], merge.Merge([], last: true).Select(s => s.DisplayTitle));
merge.Reset(new LibraryFilter { Origin = OriginFilter.Local }, [july, september]);
Assert.Equal(0, merge.Pending, "on this PC only: no remote card");
merge.Reset(new LibraryFilter { Status = StatusFilter.Analysed }, [july]);
Assert.Equal(0, merge.Pending, "a remote card not analysed does not pass the status filter");
}
[Test]
public void FiltersCompareLikeTheIndex()
{
var byTitle = new LibraryFilter { Sort = SequenceSort.Title };
Assert.True(byTitle.Compare(Local("aurora", null), Local("Comet", null)) < 0, "titles ignore case");
var bySize = new LibraryFilter { Sort = SequenceSort.Size };
Assert.True(bySize.Compare(Local("big", null) with { TotalBytes = 10 }, Local("small", null) with { TotalBytes = 1 }) < 0, "largest first");
var oldest = new LibraryFilter { Sort = SequenceSort.Oldest };
Assert.True(oldest.Compare(Local("a", new DateTime(2020, 1, 1)), Local("b", new DateTime(2021, 1, 1))) < 0);
Assert.True(oldest.Compare(Local("a", null), Local("b", new DateTime(2021, 1, 1))) > 0, "undated last");
}
}