Files
ClawdDotNet/tests/ClawdDotNet.App.Tests/Settings/SettingsManagerTests.cs
T
RichardandClaude Opus 5.5 837a634a22 Stufe 4c (#764): Kommentare in C#, WebUI-Skripten, CSS und HTML auf Englisch
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>
2026-10-04 12:45:03 +02:00

107 lines
3.4 KiB
C#

using ClawdDotNet.App.Settings;
using Shouldly;
namespace ClawdDotNet.App.Tests.Settings;
/// <summary>
/// What happens to the settings that no longer exist here (#528, stage 1).
///
/// <para><b>The occasion.</b> Five keys moved from <see cref="AppSettings"/> into the
/// instance. System.Text.Json silently skips unknown keys, and
/// <c>Save</c> does not write them again afterwards — whoever had entered their own log or
/// backup directory would therefore lose the value without finding out.
/// A move without fallback logic is fine; one without an announcement is not.</para>
///
/// <para>Deliberately no takeover into the instances: an application-wide path, copied into all
/// instances, would again be the same folder for all — i.e. exactly the state
/// stage 1 eliminates.</para>
/// </summary>
public sealed class SettingsManagerTests : IDisposable
{
private readonly string _dir = Path.Combine(
Path.GetTempPath(), "clawd-tests", "settings-" + Guid.NewGuid().ToString("N")[..8]);
private string Datei => Path.Combine(_dir, "Settings.json");
public SettingsManagerTests() => Directory.CreateDirectory(_dir);
public void Dispose()
{
try { Directory.Delete(_dir, recursive: true); }
catch { /* A leftover test folder does not turn a run red. */ }
}
private SettingsManager Geladen(string json)
{
File.WriteAllText(Datei, json);
var manager = new SettingsManager(_dir);
manager.Load();
return manager;
}
[Fact]
public void Eine_alte_Datei_meldet_ihre_aufgegebenen_Schluessel()
{
var manager = Geladen("""
{
"logDirectory": "/var/log/clawd",
"backupDirectory": "/srv/sicherungen",
"backupKeepCount": 30,
"autoBackupEnabled": true,
"autoBackupTime": "02:30",
"minimumLogLevel": "Debug"
}
""");
manager.AbandonedKeys.ShouldBe(
["logDirectory", "backupDirectory", "backupKeepCount",
"autoBackupEnabled", "autoBackupTime"],
ignoreOrder: true);
}
[Fact]
public void Was_die_Datei_sonst_enthaelt_wird_weiter_gelesen()
{
// The announcement must not change the fact that the rest arrives.
var manager = Geladen("""
{
"logDirectory": "/var/log/clawd",
"minimumLogLevel": "Debug",
"maxLogLinesInUi": 4000
}
""");
manager.AppSettings.MinimumLogLevel.ShouldBe("Debug");
manager.AppSettings.MaxLogLinesInUi.ShouldBe(4000);
}
[Fact]
public void Eine_frische_Datei_meldet_nichts()
{
Geladen("""{ "minimumLogLevel": "Info" }""").AbandonedKeys.ShouldBeEmpty();
}
[Fact]
public void Speichern_wird_die_aufgegebenen_Schluessel_los()
{
var manager = Geladen("""{ "logDirectory": "/var/log/clawd" }""");
manager.Save();
File.ReadAllText(Datei).ShouldNotContain("logDirectory");
// And the second load has nothing more to report.
var erneut = new SettingsManager(_dir);
erneut.Load();
erneut.AbandonedKeys.ShouldBeEmpty();
}
[Fact]
public void Eine_unlesbare_Datei_verhindert_den_Start_nicht()
{
var manager = Geladen("{ das ist kein JSON");
manager.AppSettings.MinimumLogLevel.ShouldBe("Info");
manager.AbandonedKeys.ShouldBeEmpty();
}
}