The render upload refusal render_exists had no Server.Error.RenderExists resource, so clients showed the raw code. ApiErrors builds that key at run time, which the scan of used keys cannot see: i18n check now maps every snake_case code literal the server passes to ApiErrors, Outcome.Fail and its Fail and TooMany helpers to its Server.Error.* key and fails when one is missing (SRV-6). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
54 lines
2.5 KiB
C#
54 lines
2.5 KiB
C#
using System.Xml.Linq;
|
|
using Titano.Testing;
|
|
using Titano.Tools.Commands;
|
|
|
|
namespace Titano.Tools.Tests;
|
|
|
|
/// <summary><c>i18n check</c> also covers the messages of the server's error codes, whose keys are built at run time.</summary>
|
|
public sealed class I18nCommandTests
|
|
{
|
|
[Test]
|
|
public void ErrorCodesAreTheLiteralsPassedToTheServerErrorHelpers()
|
|
{
|
|
const string source = """
|
|
if (bad) return ApiErrors.BadRequest(context, "invalid_filter", "status");
|
|
return known.SequenceId == sequenceId
|
|
? new StartUploadResponse(null, options.ChunkSizeBytes, [], AlreadyExists: true, null)
|
|
: Outcome<StartUploadResponse>.Fail(409, "render_exists");
|
|
return Fail<ChunkReceived>(400, "chunk_size", expected.ToString(CultureInfo.InvariantCulture));
|
|
DeleteBlock.Offline => ApiErrors.Result(context, StatusCodes.Status503ServiceUnavailable,
|
|
"archive_offline"),
|
|
return TooMany(context, "rate_limited", wait);
|
|
return ApiErrors.NotFound(context, "sequence");
|
|
return ApiErrors.BadRequest(context, code, setting, setting);
|
|
await FailAsync(upload, "not_a_code");
|
|
""";
|
|
|
|
Assert.SequenceEqual(["invalid_filter", "render_exists", "chunk_size", "archive_offline", "rate_limited"], I18nCommand.ErrorCodes(source).ToList());
|
|
}
|
|
|
|
[Test]
|
|
public void AnErrorCodeNamesItsMessageKeyLikeTheServer()
|
|
{
|
|
Assert.Equal("Server.Error.RenderExists", I18nCommand.ErrorKey("render_exists"));
|
|
Assert.Equal("Server.Error.Forbidden", I18nCommand.ErrorKey("forbidden"));
|
|
Assert.Equal("Server.Error.Http413", I18nCommand.ErrorKey("http_413"));
|
|
}
|
|
|
|
[Test]
|
|
public void EveryErrorCodeOfTheServerHasAnEnglishMessage()
|
|
{
|
|
var root = Args.RepoRoot();
|
|
var keys = XDocument.Load(Path.Combine(root, "i18n", "en", "Server.resx")).Root!.Elements("data")
|
|
.Select(d => (string)d.Attribute("name")!).ToHashSet(StringComparer.Ordinal);
|
|
|
|
var missing = I18nCommand.MissingErrorMessages(root, keys).ToList();
|
|
|
|
Assert.Empty(missing.Select(m => $"{m.Code} ({Path.GetFileName(m.File)})"));
|
|
var withoutOne = keys.Where(k => k != "Server.Error.RenderExists").ToHashSet(StringComparer.Ordinal);
|
|
var reported = I18nCommand.MissingErrorMessages(root, withoutOne).ToList();
|
|
Assert.Count(1, reported);
|
|
Assert.Equal(("render_exists", "Server.Error.RenderExists", "RenderUploads.cs"), (reported[0].Code, reported[0].Key, Path.GetFileName(reported[0].File)));
|
|
}
|
|
}
|