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,120 @@
using Febe.Core.Domain;
using Febe.Core.Engine;
using Febe.Tests.Engine.Support;
namespace Febe.Tests.Engine;
[TestClass]
public sealed class AccountPlanCalculatorTests
{
private static Account Make(string name, bool followed, Frequency frequency = Frequency.Normal, AccountState state = AccountState.UpToDate, int? posts = null, long id = 0) =>
Account.Create(name, StartingPoint.EverythingAndKeepUpdated, EngineTestBed.Noon, EngineTestBed.Zone) with
{
Id = id,
IsFollowed = followed,
Frequency = frequency,
State = state,
PostCount = posts,
};
[TestMethod]
public void AProfileNotFollowedIsCheckedEveryThreeHoursAtNormalFrequency()
{
var estimate = AccountPlanCalculator.Calculate(new AccountPlanInput
{
Account = Make("studio.lumen.demo", followed: false) with { ContentTypes = ContentTypes.PostPhotos | ContentTypes.PostVideos },
Profile = CautionProfile.Prudent with { GradualStart = false },
});
Assert.AreEqual(TimeSpan.FromHours(3), estimate.ProfileCheckWanted);
Assert.IsTrue(estimate.ProfileCheckEvery!.Value.TotalHours is > 2.9 and < 3.3);
Assert.IsFalse(estimate.OverBudget);
Assert.AreEqual(100, estimate.DailyProfileBudget);
var posts = estimate.Lines.Single(l => l.Title == "Nuovi post").Text;
StringAssert.Contains(posts, "ogni 3 ore circa");
StringAssert.Contains(posts, "tra le 7:30 e le 23:30");
Assert.AreEqual("spente.", estimate.Lines.Single(l => l.Title == "Storie").Text);
Assert.IsEmpty(estimate.Warnings);
}
[TestMethod]
public void FollowedProfilesAreDiscoveredByTheSweepAndStoriesGetThreeChecksADay()
{
var estimate = AccountPlanCalculator.Calculate(new AccountPlanInput
{
Account = Make("marta.demo", followed: true, Frequency.Low),
Profile = CautionProfile.Prudent,
});
StringAssert.Contains(estimate.Lines.Single(l => l.Title == "Nuovi post").Text, "giro dei profili che segui");
StringAssert.Contains(estimate.Lines.Single(l => l.Title == "Nuovi post").Text, "20–90 minuti");
Assert.IsTrue(estimate.StoryInterval <= TimeSpan.FromHours(16) / 3);
Assert.IsTrue(estimate.StoryChecksPerDay >= 3);
StringAssert.Contains(estimate.Lines.Single(l => l.Title == "Storie").Text, "almeno 3 volte al giorno");
Assert.IsTrue(estimate.Warnings.Any(w => w.Contains("avvio graduale", StringComparison.Ordinal)));
}
[TestMethod]
public void TheBackfillEstimateUsesThePostCountWhenKnown()
{
var profile = CautionProfile.Prudent with { GradualStart = false };
var known = AccountPlanCalculator.Calculate(new AccountPlanInput
{
Account = Make("storico.demo", followed: true, state: AccountState.Backfilling, posts: 2000) with { BackfillCompletedAt = null },
Profile = profile,
ArchivedPosts = 500,
});
Assert.AreEqual(1500, known.BackfillRemainingPosts);
Assert.AreEqual(5, known.BackfillDays, "1.500 posts at 300 a day.");
StringAssert.Contains(known.Lines.Single(l => l.Title == "Storico").Text, "mancano 1.500 post, servono circa 5 giorni");
var unknown = AccountPlanCalculator.Calculate(new AccountPlanInput
{
Account = Make("nuovo.demo", followed: true, state: AccountState.Backfilling) with { BackfillCompletedAt = null },
Profile = profile,
});
Assert.IsNull(unknown.BackfillDays);
StringAssert.Contains(unknown.Lines.Single(l => l.Title == "Storico").Text, "non è ancora noto");
// Shared with other accounts in backfill, within the daily budget of history pages (100 × 12 posts).
var others = Enumerable.Range(1, 7).Select(i => Make($"altro{i}.demo", true, state: AccountState.Backfilling, id: i) with { BackfillCompletedAt = null }).ToList();
var shared = AccountPlanCalculator.Calculate(new AccountPlanInput
{
Account = Make("storico.demo", followed: true, state: AccountState.Backfilling, posts: 2000, id: 100) with { BackfillCompletedAt = null },
OtherAccounts = others,
Profile = profile,
});
Assert.AreEqual(14, shared.BackfillDays, "2.000 posts at 150 a day (1.200 shared by 8 accounts).");
}
[TestMethod]
public void TooManyAccountsMakeTheChecksSparserWithAWarning()
{
var others = Enumerable.Range(1, 40).Select(i => Make($"pubblico{i}.demo", false, Frequency.High, id: i)).ToList();
var estimate = AccountPlanCalculator.Calculate(new AccountPlanInput
{
Account = Make("studio.demo", followed: false, id: 500),
OtherAccounts = others,
Profile = CautionProfile.Prudent with { GradualStart = false },
});
Assert.IsTrue(estimate.OverBudget);
Assert.IsTrue(estimate.TotalProfileOpensPerDay > 100);
Assert.IsTrue(estimate.ProfileCheckEvery > estimate.ProfileCheckWanted, "Sparser, not forced.");
Assert.IsTrue(estimate.Warnings.Any(w => w.Contains("si diradano", StringComparison.Ordinal)));
Assert.IsTrue(estimate.ShareOfDailyBudget < 0.1);
}
[TestMethod]
public void AccountsThatAreNotContactedCostNothing()
{
var estimate = AccountPlanCalculator.Calculate(new AccountPlanInput
{
Account = Make("archivio.demo", followed: false, state: AccountState.ArchiveOnly),
Profile = CautionProfile.Prudent,
});
Assert.IsFalse(estimate.Contacted);
Assert.AreEqual(0, estimate.ProfileOpensPerDay);
StringAssert.Contains(estimate.Lines[0].Text, "Solo archivio");
}
}