Rund 2.600 Kommentarblöcke in 310 C#-Dateien übersetzt, Begründungen vollständig erhalten: blockweise gleiche Anzahl wie vorher, kein Block unter 60 % seiner Länge, der Code außerhalb der Kommentare per Tokenizer byte-identisch geprüft. Zitate deutscher Oberflächentexte und Testdaten bleiben deutsch. WebUI: Kommentare in JS/CSS/HTML übersetzt, JSDoc-@param an die in 4b umbenannten Parameter angeglichen. Dabei behoben: - 4b hatte "tag" (HTML-Tag) als deutsches "Tag" gelesen und zu "dayValue" gemacht (makeElement, svg, Tagesübersicht) - zurück auf tag/day. - Aufgaben "InProgress" bekamen die Plakettenart "laufend", für die es nie eine CSS-Klasse gab - jetzt "success" wie laufende Instanzen. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
98 lines
3.3 KiB
C#
98 lines
3.3 KiB
C#
using System.Net;
|
|
using ClawdDotNet.Core.Deploymentcenter;
|
|
using Microsoft.Extensions.Logging.Abstractions;
|
|
using Shouldly;
|
|
|
|
namespace ClawdDotNet.Core.Tests.Deploymentcenter;
|
|
|
|
public sealed class ErrorReporterTests
|
|
{
|
|
private static (ErrorReporter Reporter, CapturingHandler Handler) Build(
|
|
Func<DateTimeOffset>? now = null,
|
|
HttpStatusCode status = HttpStatusCode.Created)
|
|
{
|
|
var handler = new CapturingHandler(status,
|
|
"""{"status":"success","item_id":7,"is_new":true,"occurrence_count":1}""");
|
|
|
|
var api = new DeploymentcenterApi("https://dc.example", "tok", new HttpClient(handler));
|
|
var reporter = new ErrorReporter(
|
|
api, "clawddotnet", "production", "0.1.0", NullLogger.Instance, ownsApi: true, now: now);
|
|
|
|
return (reporter, handler);
|
|
}
|
|
|
|
private static Exception Thrown(string message)
|
|
{
|
|
try { throw new InvalidOperationException(message); }
|
|
catch (Exception ex) { return ex; }
|
|
}
|
|
|
|
[Fact]
|
|
public async Task Meldung_geht_an_den_Fehler_Endpunkt()
|
|
{
|
|
var (reporter, handler) = Build();
|
|
using var _ = reporter;
|
|
|
|
var sent = await reporter.ReportAsync(Thrown("Kaputt"), fatal: true);
|
|
|
|
sent.ShouldBeTrue();
|
|
handler.LastRequest!.RequestUri!.ToString().ShouldBe("https://dc.example/api/errors/v1/report");
|
|
handler.LastBody!.ShouldContain("\"exception\":\"System.InvalidOperationException\"");
|
|
handler.LastBody.ShouldNotBeNull().ShouldContain("\"message\":\"Kaputt\"");
|
|
handler.LastBody.ShouldNotBeNull().ShouldContain("\"level\":\"fatal\"");
|
|
handler.LastBody.ShouldNotBeNull().ShouldContain("\"project_slug\":\"clawddotnet\"");
|
|
}
|
|
|
|
/// <summary>
|
|
/// An error loop must not turn into a thousand requests. The same error goes out
|
|
/// at most once per time window — the server throttles too, but only
|
|
/// after the requests have already gone over the line.
|
|
/// </summary>
|
|
[Fact]
|
|
public async Task Derselbe_Fehler_geht_nur_einmal_je_Zeitfenster_raus()
|
|
{
|
|
var now = DateTimeOffset.UtcNow;
|
|
var (reporter, handler) = Build(() => now);
|
|
using var _ = reporter;
|
|
|
|
var error = Thrown("Immer wieder");
|
|
|
|
(await reporter.ReportAsync(error)).ShouldBeTrue();
|
|
(await reporter.ReportAsync(error)).ShouldBeFalse();
|
|
(await reporter.ReportAsync(error)).ShouldBeFalse();
|
|
|
|
handler.Calls.ShouldBe(1);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task Nach_dem_Zeitfenster_wird_wieder_gemeldet()
|
|
{
|
|
var now = DateTimeOffset.UtcNow;
|
|
var (reporter, handler) = Build(() => now);
|
|
using var _ = reporter;
|
|
|
|
var error = Thrown("Immer wieder");
|
|
|
|
await reporter.ReportAsync(error);
|
|
now = now.AddMinutes(6);
|
|
await reporter.ReportAsync(error);
|
|
|
|
handler.Calls.ShouldBe(2);
|
|
}
|
|
|
|
/// <summary>
|
|
/// A reporting path that throws itself would be the worst of all worlds — the
|
|
/// original error would get lost in the process.
|
|
/// </summary>
|
|
[Fact]
|
|
public async Task Ein_abgelehnter_Aufruf_wirft_nicht_nach_aussen()
|
|
{
|
|
var (reporter, _) = Build(status: HttpStatusCode.Unauthorized);
|
|
using var __ = reporter;
|
|
|
|
var sent = await reporter.ReportAsync(Thrown("Egal"));
|
|
|
|
sent.ShouldBeFalse();
|
|
}
|
|
}
|