Files
Alby96andClaude Opus 5.5 7e4a3b481d
CI / Build and test (push) Successful in 9m15s
CI / Windows tests and installer (push) Skipped
CI / YAML check (push) Successful in 6s
Release / Build, test and publish (push) Successful in 15m35s
CI / PostgreSQL 16 integration (push) Successful in 7m26s
CI / PostgreSQL 17 integration (push) Successful in 6m47s
CI / Docker image (push) Successful in 59s
Release / Server image (push) Successful in 1m24s
feat: owner review 2 phase 4a: Reorganize sequences after import (#12)
- Reorganize… on the web panel and the desktop: folder, file and title templates applied to existing sequences, with a dry run and an explicit Apply that runs as a job.
- One naming rule (FrameNaming) for import, upload and Reorganize.
- Crash-safe plan and file journals, held plans, stale-plan refusal; exports move with their folder.
- Writers refuse a folder another program moved or gave to another sequence.
- Server: POST /api/v1/archive/reorganize with a bounded plan cache; template rules.
- Phase 3 docs and translations merged; strings in all 38 languages.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Alberto Balbo <alberto.balbo.96@gmail.com>
2026-10-27 21:58:39 +01:00

77 lines
5.1 KiB
C#

using System.Globalization;
using System.IO;
using System.Net;
using System.Net.Http;
using Chronos.App.Infrastructure;
using Chronos.App.Shell;
using Chronos.Core.Archiving;
using Chronos.Core.Localization;
using Chronos.Data.Archiving;
using Chronos.Protocol;
using Chronos.Protocol.Client;
using Chronos.Testing;
namespace Chronos.App.Tests.Infrastructure;
/// <summary>An error toast says what happened in one localized sentence; framework and OS messages stay in the log.</summary>
public sealed class ErrorTextTests
{
public ErrorTextTests() => Loc.SetCulture(CultureInfo.GetCultureInfo("en"));
[Test]
public void AServerFailureIsTheServersSentenceOrThatItDoesNotAnswer()
{
const string Unreachable = "The server does not answer; check the address and the network.";
Assert.Equal("The server is out of disk space.",
ErrorText.ForServer(new ChronosApiException(HttpStatusCode.InsufficientStorage, new ApiError("insufficient_storage", "The server is out of disk space.", null))));
Assert.Equal(Unreachable, ErrorText.ForServer(new HttpRequestException("No such host is known. (nas.local:8443)")));
Assert.Equal(Unreachable, ErrorText.ForServer(new TaskCanceledException("A task was canceled.")));
Assert.Equal(Unreachable, ErrorText.ForServer(new IOException("The response ended prematurely.")));
Assert.Equal(Unreachable, ErrorText.ForServer(new AggregateException(new HttpRequestException("Connection refused"))));
Assert.Equal("The certificate was not trusted, so nothing was sent.", ErrorText.ForServer(new UntrustedCertificateException("AB:CD")));
// Failures that already carry a catalog sentence keep it.
Assert.Equal(@"The archive D:\Shoots is offline.", ErrorText.ForServer(new ArchiveOfflineException(@"D:\Shoots", ArchiveAvailability.Offline)));
Assert.Equal("Something went wrong.", ErrorText.ForServer(new InvalidOperationException("Sequence contains no elements")));
Assert.Equal("Something went wrong.", ErrorText.ForServer(new ChronosApiException(HttpStatusCode.Conflict, new ApiError("conflict", " ", null))));
Assert.Equal(Unreachable, ErrorText.ForServer(new ChronosApiException(HttpStatusCode.BadGateway, new ApiError("bad_gateway", " ", null))));
}
[Test]
public void AReplyThatIsNotTheServersOwnSaysWhatItsStatusMeans()
{
// A reverse proxy answers for the server (the NAS setup): its page is no Chronos JSON, so ChronosClient keeps only
// the reason phrase, in English, which never reaches the screen.
static ChronosApiException Proxy(HttpStatusCode status, string reason) => new(status, new ApiError("http_" + (int)status, reason));
const string Unreachable = "The server does not answer; check the address and the network.";
Assert.Equal(Unreachable, ErrorText.ForServer(Proxy(HttpStatusCode.BadGateway, "Bad Gateway")));
Assert.Equal(Unreachable, ErrorText.ForServer(Proxy(HttpStatusCode.ServiceUnavailable, "Service Unavailable")));
Assert.Equal(Unreachable, ErrorText.ForServer(Proxy(HttpStatusCode.GatewayTimeout, "Gateway Timeout")));
Assert.Equal(Unreachable, ErrorText.For(Proxy(HttpStatusCode.BadGateway, "Bad Gateway")));
Assert.Equal("The request is larger than the server accepts.", ErrorText.ForServer(Proxy(HttpStatusCode.RequestEntityTooLarge, "Request Entity Too Large")));
Assert.Equal("Too many attempts; wait a minute and try again.", ErrorText.ForServer(Proxy(HttpStatusCode.TooManyRequests, "Too Many Requests")));
Assert.Equal("Unexpected server error; try again.", ErrorText.ForServer(Proxy(HttpStatusCode.InternalServerError, "Internal Server Error")));
Assert.Equal("Something went wrong.", ErrorText.ForServer(Proxy(HttpStatusCode.NotFound, "Not Found")));
// JSON of another shape has no code: its message is not the server's either.
Assert.Equal(Unreachable, ErrorText.ForServer(new ChronosApiException(HttpStatusCode.BadGateway, new ApiError(null!, "upstream connect error"))));
}
[Test]
public void AnyOtherFailureNeverShowsTheFrameworkText()
{
Assert.Equal("Something went wrong.", ErrorText.For(new HttpRequestException("No such host is known.")));
Assert.Equal("Something went wrong.", ErrorText.For(new IOException(@"Access to the path 'D:\Archive' is denied.")));
Assert.Equal(@"The archive D:\Shoots is read-only.", ErrorText.For(new ArchiveOfflineException(@"D:\Shoots", ArchiveAvailability.ReadOnly)));
}
[Test]
public void ATemplateAnArchiveRefusesSaysTheRuleItBreaks()
{
// A new archive with this PC's templates, one saved before the rules existed: the toast says what to change.
var refused = new TemplateRuleException("fileTemplate", "NotUnique");
const string Sentence = "Names would repeat: add the frame number, the time or the original name.";
Assert.Equal(Sentence, ErrorText.For(refused));
Assert.Equal(Sentence, ArchiveActions.Cause(refused));
Assert.Equal("Something went wrong.", ArchiveActions.Cause(new ArgumentException("The archive setting name is invalid.", "name")));
}
}