using ClawdDotNet.Core.Config; using Shouldly; namespace ClawdDotNet.Core.Tests.Config; /// /// Old configurations contain "maxTokens" — a value that was meant as a context limit, /// but counted cumulatively over all steps and aborted runs prematurely (bug B3). /// The migration must not take over this value unchanged as the cost budget. /// 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); // the old, problematic value 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); } }