M3 Motore: Governatore con tetti da action_log, interruttore con fermi 1/6/24 ore e ripresa manuale, fascia giornaliera spostata a caso e salvata, sessioni con pause log-normali e pavimento, composizione delle sessioni sulla coda persistente, «Controlla ora» con conferma fuori fascia, cruscotto per l'interfaccia e calcolatore «Con queste impostazioni», simulazione con orologio virtuale e comando --simula; prove del motore e dell'interruttore

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Claude-Session: https://claude.ai/code/session_01Mzbb6zeFTjT6Rp8b92AVkA
This commit is contained in:
Claude committed 2026-10-13 17:33:28 +00:00
1 parent e2c987873b
commit 346d5ca075
38 files changed
+9308

No files matched your search

@@ -0,0 +1,95 @@
using Febe.Core.Abstractions;
using Febe.Core.Domain;
using Febe.Core.Engine;
using Febe.Data;
using Febe.Tests.Support;
namespace Febe.Tests.Engine;
[TestClass]
public sealed class EngineSettingsTests
{
[TestMethod]
public async Task SettingsAreStoredAndReadBackWithACustomProfile()
{
using var folder = new TempFolder("impostazioni");
await using var db = await FebeDatabase.OpenAsync(folder.Combine("dati"));
Assert.AreEqual(CautionProfileKind.Prudent, (await EngineSettingsStore.LoadAsync(db.Settings)).ProfileKind, "«Prudente» is the default.");
var custom = CautionProfile.Balanced with
{
PauseMin = TimeSpan.FromMinutes(15),
WindowStart = new TimeOnly(8, 0),
WindowEnd = new TimeOnly(0, 30),
Budgets = new Dictionary<ActionKind, Budget>(CautionProfile.Balanced.Budgets) { [ActionKind.ProfileOpen] = new Budget(18, 150) },
};
var settings = new EngineSettings { Pace = GesturePace.Slow, GradualStart = false, ActiveDays = new HashSet<DayOfWeek> { DayOfWeek.Monday, DayOfWeek.Saturday } }
.WithCustomValues(custom);
await EngineSettingsStore.SaveAsync(db.Settings, settings);
var loaded = await EngineSettingsStore.LoadAsync(db.Settings);
Assert.AreEqual(CautionProfileKind.Custom, loaded.ProfileKind);
Assert.AreEqual(GesturePace.Slow, loaded.Pace);
Assert.IsFalse(loaded.GradualStart);
CollectionAssert.AreEquivalent(new[] { DayOfWeek.Monday, DayOfWeek.Saturday }, loaded.ActiveDays.ToArray());
var effective = loaded.EffectiveProfile;
Assert.AreEqual(CautionProfileKind.Custom, effective.Kind);
Assert.AreEqual(TimeSpan.FromMinutes(15), effective.PauseMin);
Assert.AreEqual(new TimeOnly(0, 30), effective.WindowEnd);
Assert.AreEqual(new Budget(18, 150), effective.Budgets[ActionKind.ProfileOpen]);
Assert.AreEqual(CautionProfile.Balanced.DataPerDayBytes, effective.DataPerDayBytes);
Assert.AreEqual(GesturePace.Slow, effective.Pace);
}
[TestMethod]
public void TheLimitsOfTheInterfaceAreEnforced()
{
var bad = CautionProfile.Fast with
{
PauseMin = TimeSpan.FromMinutes(4),
SessionMax = TimeSpan.FromMinutes(31),
WindowStart = new TimeOnly(5, 0),
WindowEnd = new TimeOnly(2, 0),
Budgets = new Dictionary<ActionKind, Budget>(CautionProfile.Fast.Budgets) { [ActionKind.StoryView] = new Budget(241, 800) },
DataPerDayBytes = CautionProfile.Limits.MaxDataPerDayBytes + 1,
};
var errors = CautionProfileRules.Validate(bad);
Assert.IsTrue(errors.Any(e => e.Contains("5 minuti", StringComparison.Ordinal)));
Assert.IsTrue(errors.Any(e => e.Contains("30 minuti", StringComparison.Ordinal)));
Assert.IsTrue(errors.Any(e => e.Contains("20 ore", StringComparison.Ordinal)));
Assert.IsTrue(errors.Any(e => e.Contains("storie viste", StringComparison.Ordinal)));
Assert.IsTrue(errors.Any(e => e.Contains("dati scaricati", StringComparison.Ordinal)));
Assert.HasCount(0, CautionProfileRules.Validate(CautionProfile.Fast));
Assert.HasCount(0, CautionProfileRules.Validate(CautionProfile.Prudent));
Assert.HasCount(0, CautionProfileRules.Validate(CautionProfile.Balanced));
Assert.AreEqual(TimeSpan.FromHours(18), CautionProfileRules.WindowLength(new TimeOnly(6, 30), new TimeOnly(0, 30)));
}
[TestMethod]
public async Task InvalidSettingsAreNotStored()
{
using var folder = new TempFolder("impostazioni");
await using var db = await FebeDatabase.OpenAsync(folder.Combine("dati"));
var settings = new EngineSettings().WithCustomValues(CautionProfile.Prudent with { PauseMin = TimeSpan.FromMinutes(1) });
var error = await Assert.ThrowsAsync<ArgumentException>(() => EngineSettingsStore.SaveAsync(db.Settings, settings));
StringAssert.Contains(error.Message, "pausa minima");
Assert.IsNull(await db.Settings.GetAsync(EngineSettingKeys.Profile));
}
[TestMethod]
public void TheCustomProfileSurvivesTheJsonRoundTrip()
{
var custom = CautionProfile.Fast with { Kind = CautionProfileKind.Custom, WindowJitter = TimeSpan.FromMinutes(25), RampUpDays = 10 };
var decoded = CautionProfileCodec.TryDecode(CautionProfileCodec.Encode(custom));
Assert.IsNotNull(decoded);
Assert.AreEqual(custom.WindowJitter, decoded!.WindowJitter);
Assert.AreEqual(10, decoded.RampUpDays);
foreach (var (kind, budget) in custom.Budgets)
{
Assert.AreEqual(budget, decoded.Budgets[kind]);
}
Assert.IsNull(CautionProfileCodec.TryDecode("{non è json"));
Assert.IsNull(CautionProfileCodec.TryDecode("{}"));
}
}