Files
RichardandClaude Opus 5.5 77062facc9 Stufe 4c (#764): Bezeichner auf Englisch - Typen, Methoden, Felder, Parameter, Locals, Testnamen
Mit Roslyn umbenannt (Verweise folgen, Zeichenketten bleiben unberuehrt).
Nicht umbenannt, weil gespeichert oder ueber die API gebunden (Stufe 4e):
Properties, Record-Parameter, Enum-Member sowie die Parameter der
Endpunkt-Handler (Routen-/Query-Bindung ueber den Namen). Die JSON-Felder
anonymer Objekte bleiben ausdruecklich benannt (JsonFilter: pfad).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-04 13:18:43 +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 Loaded(string json)
{
File.WriteAllText(Datei, json);
var manager = new SettingsManager(_dir);
manager.Load();
return manager;
}
[Fact]
public void An_old_file_reports_its_abandoned_keys()
{
var manager = Loaded("""
{
"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 Whatever_else_the_file_contains_is_still_read()
{
// The announcement must not change the fact that the rest arrives.
var manager = Loaded("""
{
"logDirectory": "/var/log/clawd",
"minimumLogLevel": "Debug",
"maxLogLinesInUi": 4000
}
""");
manager.AppSettings.MinimumLogLevel.ShouldBe("Debug");
manager.AppSettings.MaxLogLinesInUi.ShouldBe(4000);
}
[Fact]
public void A_fresh_file_reports_nothing()
{
Loaded("""{ "minimumLogLevel": "Info" }""").AbandonedKeys.ShouldBeEmpty();
}
[Fact]
public void Saving_drops_the_abandoned_keys()
{
var manager = Loaded("""{ "logDirectory": "/var/log/clawd" }""");
manager.Save();
File.ReadAllText(Datei).ShouldNotContain("logDirectory");
// And the second load has nothing more to report.
var again = new SettingsManager(_dir);
again.Load();
again.AbandonedKeys.ShouldBeEmpty();
}
[Fact]
public void An_unreadable_file_does_not_prevent_the_start()
{
var manager = Loaded("{ das ist kein JSON");
manager.AppSettings.MinimumLogLevel.ShouldBe("Info");
manager.AbandonedKeys.ShouldBeEmpty();
}
}