using ClawdDotNet.Core.Config; using Shouldly; namespace ClawdDotNet.Core.Tests.Config; /// /// Alte Konfigurationen enthalten "maxTokens" — ein Wert, der als Kontextgrenze gemeint /// war, aber kumulativ über alle Schritte zählte und Läufe vorzeitig abbrach (Bug B3). /// Die Migration darf diesen Wert nicht unverändert als Kostenbudget übernehmen. /// public sealed class ConfigMigrationTests { private static InstanceConfig WithLegacyMaxTokens(int? legacy) => new() { OpenRouterApiKey = "sk-test", Agents = [ new AgentConfig { AgentId = "test", LoopGuard = new LoopGuardConfig { LegacyMaxTokens = legacy } } ] }; [Fact] public void Ein_altes_zu_knappes_maxTokens_wird_durch_den_neuen_Default_ersetzt() { var config = WithLegacyMaxTokens(80_000); // der alte, problematische Wert ConfigLoader.Migrate(config); var guard = config.Agents[0].LoopGuard; guard.MaxCumulativeTokens.ShouldBe(500_000); guard.LegacyMaxTokens.ShouldBeNull(); } [Fact] public void Ein_bewusst_grosszuegiges_maxTokens_bleibt_erhalten() { var config = WithLegacyMaxTokens(2_000_000); ConfigLoader.Migrate(config); config.Agents[0].LoopGuard.MaxCumulativeTokens.ShouldBe(2_000_000); } [Fact] public void Ohne_altes_Feld_bleibt_der_Default_unveraendert() { var config = WithLegacyMaxTokens(null); ConfigLoader.Migrate(config); config.Agents[0].LoopGuard.MaxCumulativeTokens.ShouldBe(500_000); } [Fact] public void Migration_ist_mehrfach_anwendbar() { var config = WithLegacyMaxTokens(80_000); ConfigLoader.Migrate(config); ConfigLoader.Migrate(config); config.Agents[0].LoopGuard.MaxCumulativeTokens.ShouldBe(500_000); } }