Files
Febe/tests/Febe.Tests/Engine/EngineSettingsTests.cs
Alby96andClaude Opus 5.5 63acae4e73
verifica / controlli (push) Successful in 22s
verifica / prove (push) Successful in 21m4s
verifica / installatore (push) Successful in 5m21s
verifica / immagine (push) Successful in 19m0s
Ricette fatte di richieste, un permesso per richiesta (#36, S3)
Otto ricette (controllo del profilo, storico, taggati, reel, storie di un
account, raccolta in evidenza, post singolo, elenco dei seguiti) hanno una
strada per richieste dirette accanto a quella con il browser. Ci vanno solo
se ogni ruolo che servono è un'operazione configurata di richieste.<sito>.json:
con Instagram nessuna lo è e Febe non costruisce il client del sito, quindi il
comportamento con Instagram non cambia fino a S4.

Ogni richiesta prende il suo permesso dal Governatore nella categoria di ciò
che chiede (la prima pagina dei post conta come profilo); i segnali delle
risposte vanno all'interruttore e fermano la ricetta prima di ogni altra
richiesta. Se manca un valore o la pagina successiva, la ricetta torna alle
pagine per quella volta e il motore controlla tutti e due i tetti. I tetti non
cambiano: il dimezzamento delle storie viste è tolto perché toccava anche il
browser e i «Su misura» salvati, e resta una domanda per Alberto prima di S4.

Il simulatore ha --raccolta pagine|richieste con il costo delle operazioni
separate di Instagram: sei simulazioni di 30 giorni senza superamenti.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 12:10:54 +01:00

109 lines
5.8 KiB
C#

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 AStoryViewIsARequestOrAStoryShownAndItsBudgetsStayAsTheyWere()
{
// Issue #36, S3: by requests one StoryView brings every story of an account. The budgets do not change in S3,
// so that Instagram (still by the pages) and a saved «Su misura» behave as before; halving them is a question
// for Alberto when Instagram goes by requests (S4).
Assert.AreEqual(new Budget(50, 300), CautionProfile.Prudent.Budgets[ActionKind.StoryView]);
Assert.AreEqual(new Budget(80, 500), CautionProfile.Balanced.Budgets[ActionKind.StoryView]);
Assert.AreEqual(new Budget(120, 800), CautionProfile.Fast.Budgets[ActionKind.StoryView]);
Assert.AreEqual(new Budget(240, 1600), CautionProfile.Limits.MaxBudget(ActionKind.StoryView), "«Su misura» stays within twice «Rapido».");
Assert.IsTrue(CautionProfile.Prudent.Budgets[ActionKind.StoryView].PerHour >= new Febe.Core.Collection.Recipes.RecipeOptions().MinStoryBudget, "The viewer still has room for its minimum of stories.");
}
[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("{}"));
}
}