Files
ClawdDotNet/tests/ClawdDotNet.Manager.Tests/BackupManagementTests.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

97 lines
3.1 KiB
C#

using ClawdDotNet.Core.Backup;
using ClawdDotNet.Core.Config;
using ClawdDotNet.Core.Instances;
using Shouldly;
namespace ClawdDotNet.Manager.Tests;
/// <summary>
/// Tests for backup and restore in the manager (#530, stage 6).
/// </summary>
public sealed class BackupManagementTests : IDisposable
{
private readonly string _root = Path.Combine(
Path.GetTempPath(), "clawd-tests", "backup-" + Guid.NewGuid().ToString("N")[..8]);
public BackupManagementTests()
{
Directory.CreateDirectory(_root);
}
public void Dispose()
{
try { Directory.Delete(_root, recursive: true); }
catch { }
}
[Fact]
public void BackupDirectory_wird_standardmaessig_unter_Backups_aufgeloest()
{
var instancePath = Path.Combine(_root, "TestInstance");
Directory.CreateDirectory(instancePath);
var config = new InstanceConfig { WorkingDirectory = instancePath };
var backupDir = InstanceLayout.ResolveBackupDirectory(config, instancePath);
backupDir.ShouldBe(Path.Combine(instancePath, "Backups"));
}
[Fact]
public async Task Backup_kann_erstellt_geprueft_und_wiederhergestellt_werden()
{
var instancePath = Path.Combine(_root, "InstanceAlpha");
Directory.CreateDirectory(instancePath);
var settingsPath = Path.Combine(instancePath, "InstanceSettings.json");
await File.WriteAllTextAsync(settingsPath, """
{
"instanceId": "alpha-123",
"instanceName": "Alpha",
"workingDirectory": ""
}
""");
var testDataPath = Path.Combine(instancePath, "data.txt");
await File.WriteAllTextAsync(testDataPath, "Wichtige Testdaten");
var backupDir = InstanceLayout.ResolveBackupDirectory(
new InstanceConfig { WorkingDirectory = instancePath }, instancePath);
Directory.CreateDirectory(backupDir);
var zipPath = Path.Combine(backupDir, "backup_Alpha_test.zip");
var service = new BackupService();
var backupResult = await service.CreateAsync(instancePath, zipPath, new BackupOptions
{
Secrets = SecretMode.Exclude,
IncludeChatHistory = true,
IncludeLogs = false
});
File.Exists(zipPath).ShouldBeTrue();
backupResult.SizeBytes.ShouldBeGreaterThan(0);
// Check
var manifest = await service.InspectAsync(zipPath);
manifest.InstanceId.ShouldBe("alpha-123");
manifest.InstanceName.ShouldBe("Alpha");
manifest.Files.Count.ShouldBeGreaterThan(0);
// Modify a file in the target and check the restore
await File.WriteAllTextAsync(testDataPath, "Überschriebene Testdaten");
var restoreResult = await service.RestoreAsync(
zipPath,
instancePath,
new RestoreOptions { Overwrite = true });
restoreResult.Written.ShouldContain("data.txt");
var restoredContent = await File.ReadAllTextAsync(testDataPath);
restoredContent.ShouldBe("Wichtige Testdaten");
// Delete
File.Delete(zipPath);
File.Exists(zipPath).ShouldBeFalse();
}
}