Files
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

130 lines
9.8 KiB
C#

using System.Globalization;
using System.IO;
using System.Net;
using System.Net.Http;
using Chronos.App.Import;
using Chronos.Core.Archiving;
using Chronos.Core.Import;
using Chronos.Core.Localization;
using Chronos.Data;
using Chronos.Protocol;
using Chronos.Protocol.Client;
using Chronos.Testing;
namespace Chronos.App.Tests.Import;
/// <summary>A stopped import or plan says what happened in one localized sentence, never the exception's raw text.</summary>
public sealed class ImportFailuresTests
{
public ImportFailuresTests() => Loc.SetCulture(CultureInfo.GetCultureInfo("en"));
[Test]
public void AnImportFailureIsOneSentenceByCause()
{
const string Card = "EOS R5 · card A";
Assert.Equal("EOS R5 · card A is no longer available.", ImportFailures.Import(new ImportSourceUnavailableException(@"C:\Users\me\AppData\Local\Temp\card\"), Card));
Assert.Equal("The destination is full.", ImportFailures.Import(new IOException("There is not enough space on the disk.", unchecked((int)0x80070070)), Card));
Assert.Equal("Chronos may not write to the destination.", ImportFailures.Import(new UnauthorizedAccessException(@"Access to D:\Shoots is denied."), Card));
Assert.Equal("The server did not accept the photos.", ImportFailures.Import(new HttpRequestException("No such host is known."), Card));
Assert.Equal("The server did not accept the photos.",
ImportFailures.Import(new ChronosApiException(HttpStatusCode.InsufficientStorage, new ApiError("quota", "Quota exceeded", null)), Card));
Assert.Equal("The import stopped before the end.", ImportFailures.Import(new InvalidDataException("Bad sidecar. Second sentence."), Card));
}
[Test]
public void TheCopiesAStoppedImportNeverReachedSayWhyInOneSentence()
{
const string Card = "EOS R5 · card A";
Assert.Equal("EOS R5 · card A is no longer available.", ImportFailures.Stop(new ImportSourceUnavailableException(@"E:\"), Card));
Assert.Equal("The destination is full.", ImportFailures.Stop(new IOException("There is not enough space on the disk.", unchecked((int)0x80070070)), Card));
Assert.Equal("Chronos may not write to the destination.", ImportFailures.Stop(new UnauthorizedAccessException(@"Access to D:\Shoots is denied."), Card));
Assert.Equal("The import stopped before the end.", ImportFailures.Stop(new IOException("The specified network name is no longer available."), Card));
// The server's own sentence, else why it could not be asked.
Assert.Equal("Sign in again",
ImportFailures.Stop(new ChronosApiException(HttpStatusCode.Unauthorized, new ApiError("unauthorized", "Sign in again", null)), Card));
Assert.Equal(Loc.L("Server.Error.Unreachable"), ImportFailures.Stop(new HttpRequestException("An error occurred while sending the request."), Card));
// A reverse proxy answered while the server restarted: its reason phrase is English, never the server's sentence.
Assert.Equal(Loc.L("Server.Error.Unreachable"), ImportFailures.Stop(new ChronosApiException(HttpStatusCode.BadGateway, new ApiError("http_502", "Bad Gateway")), Card));
Assert.Equal(Loc.L("Server.Error.Unreachable"), ImportFailures.Stop(new TaskCanceledException("The operation was canceled."), Card));
Assert.Equal(Loc.L("Server.Error.Untrusted"), ImportFailures.Stop(new UntrustedCertificateException("AB:CD"), Card));
}
[Test]
public void AServerImportStoppedOnThisPcNamesItsCacheFolderNotTheServer()
{
// The server import stages its copies in this PC's cache folder; the server answers for its own space and rights.
const string Card = "EOS R5 · card A";
using var client = new ChronosClient(new Uri("https://nas.local:8443/"), new CertificatePinning([]), "tests");
var staging = Path.Combine(Path.GetTempPath(), "chronos-server-import");
Assert.True(((IImportSink)new ServerImportSink(client, staging)).StagesOnThisPc);
Assert.Equal("The drive of this PC's cache folder is full.",
ImportFailures.Stop(new IOException("There is not enough space on the disk.", unchecked((int)0x80070070)), Card, stagesOnThisPc: true));
Assert.Equal("Chronos may not write to this PC's cache folder.",
ImportFailures.Stop(new UnauthorizedAccessException(@"Access to the path 'C:\Users\me\AppData\Local\Chronos\cache\server-import' is denied."), Card,
stagesOnThisPc: true));
Assert.Equal("EOS R5 · card A is no longer available.", ImportFailures.Stop(new ImportSourceUnavailableException(@"E:\"), Card, stagesOnThisPc: true));
Assert.Equal("The import stopped before the end.", ImportFailures.Stop(new IOException("The specified network name is no longer available."), Card, stagesOnThisPc: true));
Assert.Equal(Loc.L("Server.Error.Unreachable"), ImportFailures.Stop(new HttpRequestException("No such host is known."), Card, stagesOnThisPc: true));
}
[Test]
public void AFailedImportJobShowsOnlyTheArchivesOwnSentences()
{
// The job engine keeps the text of what stopped the job: the archive's own failures are already catalog sentences.
Assert.Equal("The archive D:\\Shoots is offline.", ImportFailures.Job(new ArchiveOfflineException(@"D:\Shoots", ArchiveAvailability.Offline).Message));
Assert.Equal("The archive D:\\Shoots is read-only.", ImportFailures.Job(new ArchiveOfflineException(@"D:\Shoots", ArchiveAvailability.ReadOnly).Message));
Assert.Equal("The card or folder E:\\ is no longer available.", ImportFailures.Job(new ImportSourceUnavailableException(@"E:\").Message));
var busy = new LeaseUnavailableException("settings", new LeaseRecord("t", "Chronos Server (nas)", "nas", 42, DateTimeOffset.UnixEpoch, DateTimeOffset.UnixEpoch));
Assert.Equal(busy.Message, ImportFailures.Job(busy.Message));
var newer = new NewerFormatException(Path.Combine(Path.GetTempPath(), "archive.json"), 3);
Assert.Equal("archive.json was written by a newer Chronos (format 3).", ImportFailures.Job(newer.Message));
Assert.Equal("IMG_0001.CR3 could not be added to the sequence.", ImportFailures.Job(Loc.L("Archive.Error.DuplicateLost", "IMG_0001.CR3")));
// A database, framework or system text reads as the catalog's sentence; the tooltip keeps it.
Assert.Equal("The import stopped before the end.", ImportFailures.Job("database is locked: no write lock within 30 s"));
Assert.Equal("The import stopped before the end.",
ImportFailures.Job(@"The process cannot access the file 'D:\Shoots\2026\IMG_0001.CR3' because it is being used by another process."));
Assert.Equal("The import stopped before the end.", ImportFailures.Job("There is not enough space on the disk. : 'D:\\Shoots\\.chronos\\journal'"));
Assert.Equal("The import stopped before the end.", ImportFailures.Job($"Sequence {Guid.Empty} is not indexed."));
Assert.Equal("The import stopped before the end.", ImportFailures.Job(null));
Assert.Equal("The import stopped before the end.", ImportFailures.Job(string.Empty));
}
[Test]
public void APlanningFailureNamesTheSource()
{
const string Folder = @"D:\Shoots";
Assert.Equal(@"D:\Shoots is no longer available.", ImportFailures.Plan(new DirectoryNotFoundException(@"Could not find a part of the path 'D:\Shoots\DCIM'."), Folder));
Assert.Equal(@"D:\Shoots could not be read.", ImportFailures.Plan(new UnauthorizedAccessException("Access denied."), Folder));
Assert.Equal(@"D:\Shoots could not be read.", ImportFailures.Plan(new IOException("The device is not ready."), Folder));
Assert.Equal("The import could not be planned.", ImportFailures.Plan(new InvalidOperationException("Sequence contains no elements"), Folder));
}
[Test]
public void ACardCheckOrDeleteFailureIsOneSentenceByCause()
{
const string Card = "EOS R5 · card A";
var root = Directory.CreateTempSubdirectory("chronos-card-").FullName;
try
{
Assert.Equal("A photo or its archive copy could not be read.", ImportFailures.Check(new IOException("The semaphore timeout period has expired."), Card, root));
Assert.Equal("The index could not be read or written.", ImportFailures.Check(new DatabaseConnectionException("database is locked"), Card, root));
Assert.Equal("The archive D:\\Shoots is offline.", ImportFailures.Check(new ArchiveOfflineException(@"D:\Shoots", ArchiveAvailability.Offline), Card, root));
Assert.Equal("Something went wrong.", ImportFailures.Check(new InvalidOperationException("Collection was modified."), Card, root));
Assert.Equal("EOS R5 · card A is write-protected or holds protected photos.",
ImportFailures.Erase(new IOException("The media is write protected.", unchecked((int)0x80070013)), Card, root));
Assert.Equal("EOS R5 · card A is write-protected or holds protected photos.",
ImportFailures.Erase(new UnauthorizedAccessException(@"Access to the path 'E:\DCIM\IMG_0001.CR3' is denied."), Card, root));
Assert.Equal("Something went wrong.", ImportFailures.Erase(new IOException("The request could not be performed because of an I/O device error."), Card, root));
}
finally
{
Directory.Delete(root);
}
// A card that left explains whatever failed while it was read or written.
var gone = Path.Combine(Path.GetTempPath(), "chronos-card-" + Guid.NewGuid().ToString("N"));
Assert.Equal("EOS R5 · card A is no longer available.", ImportFailures.Check(new IOException("The device is not ready."), Card, gone));
Assert.Equal("EOS R5 · card A is no longer available.", ImportFailures.Erase(new UnauthorizedAccessException("Access denied."), Card, gone));
}
}