Files
Febe/tests/Febe.Tests/Engine/EngineMonitorTests.cs
T
Claude 0ceffffe50 Interfaccia: correzioni della revisione (web-1, web-2, web-3, web-4, web-5, web-6, web-7, web-9, web-10, web-11, web-12, web-13, web-14, web-15)
Il browser preso dalle pagine Browser e Collegamento si restituisce uscendo senza «Ho finito» (anche chiudendo o ricaricando la scheda); dopo «Ho finito» la vista remota si chiude e non si riprende il browser. Vista remota: AltGr/Option come testo, pulsante rilasciato anche fuori dalla vista. Mosaico e scheda account senza risposte vecchie né viste sovrascritte; nuovi elementi dopo la libreria vuota; intestazione sempre aggiornata. Indietro del browser con la richiesta delle modifiche non salvate; nulla resta registrato da una pagina lasciata mentre caricava; maniglie della fascia trascinabili. «Da una data» come giorno locale; niente «@null» nel riquadro di stato; orari futuri dei fermi «verso le». Prove nel browser vero (InterfaceTests).

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

Claude-Session: https://claude.ai/code/session_01Mzbb6zeFTjT6Rp8b92AVkA
2026-10-14 01:38:13 +00:00

139 lines
7.2 KiB
C#

using Febe.Core.Abstractions;
using Febe.Core.Domain;
using Febe.Core.Engine;
using Febe.Tests.Engine.Support;
namespace Febe.Tests.Engine;
[TestClass]
public sealed class EngineMonitorTests
{
[TestMethod]
public async Task AtNightTheMonitorSaysWhenWorkResumes()
{
var night = EngineTestBed.Local(2026, 10, 14, 2, 0);
await using var bed = await EngineTestBed.CreateAsync(night);
await bed.AddAccountAsync("marta.demo", followed: true);
var host = bed.Start(new ScriptedRunner(bed.Governor, bed.Clock));
await bed.RunForAsync(TimeSpan.FromMinutes(15));
var snapshot = await host.Monitor.GetSnapshotAsync();
Assert.AreEqual(EngineMode.OutsideWindow, snapshot.Mode);
Assert.AreEqual("Fuori fascia", snapshot.Headline);
StringAssert.Contains(snapshot.SidebarLine, "Riprende verso le ");
var window = await bed.Services.Planner.GetWindowAsync(new DateOnly(2026, 10, 14));
Assert.AreEqual(window!.Start, snapshot.ResumesAround);
Assert.IsNull(snapshot.Banner);
Assert.IsTrue(snapshot.Today.Spans.Any(s => s.Kind == StripSpanKind.OutsideWindow && s.Start == snapshot.Today.Start));
Assert.IsTrue(snapshot.Today.Spans.Any(s => s.Kind == StripSpanKind.PlannedSession && s.Indicative));
Assert.IsTrue(snapshot.Queue.All(q => q.When.StartsWith("verso le", StringComparison.Ordinal)));
Assert.AreEqual(4, snapshot.MainBudgets.Count);
CollectionAssert.AreEqual(
new[] { ActionKind.ProfileOpen, ActionKind.StoryView, ActionKind.BackfillPage, ActionKind.DataDownload },
snapshot.MainBudgets.Select(b => b.Kind).ToArray());
Assert.AreEqual(Enum.GetValues<ActionKind>().Length, snapshot.AllBudgets.Count);
Assert.AreEqual("Profili aperti", snapshot.ProfilesOpenedToday.Label);
Assert.AreEqual("di 100", snapshot.ProfilesOpenedToday.LimitText);
}
[TestMethod]
public async Task DuringTheDayTheStripShowsSessionsRestsAndTheSummary()
{
await using var bed = await EngineTestBed.CreateAsync(EngineTestBed.Local(2026, 10, 14, 6, 0));
await bed.AddAccountAsync("marta.demo", followed: true);
await bed.AddAccountAsync("luca.demo", followed: false, Frequency.High);
var host = bed.Start(new ScriptedRunner(bed.Governor, bed.Clock));
await bed.RunUntilAsync(EngineTestBed.Local(2026, 10, 14, 15, 0));
var snapshot = await host.Monitor.GetSnapshotAsync();
Assert.IsTrue(snapshot.Mode is EngineMode.Resting or EngineMode.InSession);
Assert.IsTrue(snapshot.Today.Spans.Count(s => s.Kind is StripSpanKind.Session or StripSpanKind.CurrentSession) >= 5);
Assert.IsTrue(snapshot.Today.Spans.Any(s => s.Kind == StripSpanKind.Rest));
StringAssert.Contains(snapshot.Today.Summary, "sessioni");
StringAssert.Contains(snapshot.Today.Summary, "nessun rallentamento");
Assert.IsNotEmpty(snapshot.RecentActions);
Assert.IsTrue(snapshot.RecentActions.Any(a => a.Title == "Giro dei profili che segui" || a.Title.StartsWith('@')));
if (snapshot.Mode == EngineMode.Resting)
{
Assert.AreEqual("In ascolto", snapshot.Headline);
StringAssert.StartsWith(snapshot.Details[0], "Riprende verso le ");
}
var profiles = snapshot.ProfilesOpenedToday;
Assert.IsTrue(profiles.UsedToday > 0);
StringAssert.StartsWith(profiles.Note, "In questa ora ");
}
[TestMethod]
public async Task AThrottleShowsAnAmberStripAndSuspendsTheQueue()
{
await using var bed = await EngineTestBed.CreateAsync();
await bed.AddAccountAsync("marta.demo", followed: true);
var host = bed.Start(new ScriptedRunner(bed.Governor, bed.Clock));
await bed.RunForAsync(TimeSpan.FromMinutes(1));
await bed.Breaker.ReportAsync(new Signal(SignalLevel.Throttle, "http-429", null, bed.Clock.Now));
var snapshot = await host.Monitor.GetSnapshotAsync();
Assert.AreEqual(EngineMode.Throttled, snapshot.Mode);
Assert.AreEqual(BannerLevel.Warning, snapshot.Banner!.Level);
StringAssert.Contains(snapshot.Banner.Message, "tetti dimezzati");
Assert.IsTrue(snapshot.Queue.All(q => q.Suspended && q.When == "Sospeso"));
Assert.IsTrue(snapshot.Today.Spans.Any(s => s.Kind == StripSpanKind.Throttle));
StringAssert.StartsWith(snapshot.ProfilesOpenedToday.Note, "Fermo dalle ");
StringAssert.Contains(snapshot.ReductionNote!, "Tetti dimezzati");
// Future engine times are always «verso le» (spec §10.4): the strip agrees with the status box.
var resumes = ItalianText.Around(bed.Breaker.State.Until!.Value, bed.Clock.Now, bed.Clock.LocalZone);
StringAssert.Contains(snapshot.Banner.Message, "riparto da solo " + resumes);
StringAssert.Contains(snapshot.SidebarLine, resumes);
StringAssert.Contains(snapshot.ReductionNote!, "verso l");
foreach (var text in new[] { snapshot.Banner.Message, snapshot.ReductionNote! })
{
Assert.DoesNotContain(" alle ", text);
Assert.DoesNotContain(" all'", text);
}
}
[TestMethod]
public async Task TheEventStreamDeliversTimelineLines()
{
await using var bed = await EngineTestBed.CreateAsync();
var host = bed.Start(new ScriptedRunner(bed.Governor, bed.Clock));
using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(20));
var received = new List<EngineNotification>();
var reading = Task.Run(async () =>
{
await foreach (var notification in host.Monitor.SubscribeAsync(cts.Token))
{
received.Add(notification);
if (notification.Kind == EngineNotificationKind.Event && notification.Event!.Code == EngineEventCodes.Paused)
{
break;
}
}
});
await Task.Delay(100);
await host.PauseAsync();
await reading;
Assert.IsTrue(received.Any(n => n.Event?.Code == EngineEventCodes.Paused));
StringAssert.Contains(received.Last().Event!.Message, "Riprendi");
}
[TestMethod]
public void ItalianTextUsesDotsCommasAndVersoLe()
{
Assert.AreEqual("7.682", ItalianText.Number(7682));
Assert.AreEqual("1.234.567", ItalianText.Number(1234567));
Assert.AreEqual("1,3 GB", ItalianText.Bytes((long)(1.3 * 1024 * 1024 * 1024)));
Assert.AreEqual("0,5", ItalianText.Decimal(0.5));
var zone = EngineTestBed.Zone;
var now = EngineTestBed.Local(2026, 10, 14, 12, 0);
Assert.AreEqual("verso le 15:30", ItalianText.Around(EngineTestBed.Local(2026, 10, 14, 15, 30), now, zone));
Assert.AreEqual("domani verso le 7:42", ItalianText.Around(EngineTestBed.Local(2026, 10, 15, 7, 42), now, zone));
Assert.AreEqual("verso l'1:05", ItalianText.Around(EngineTestBed.Local(2026, 10, 14, 13, 5).AddHours(12), now.AddHours(12), zone));
Assert.AreEqual("1 ora e 20 minuti", ItalianText.Duration(TimeSpan.FromMinutes(80)));
Assert.AreEqual("ogni 75 minuti", ItalianText.Every(TimeSpan.FromMinutes(75)));
Assert.AreEqual("ogni 3 ore", ItalianText.Every(TimeSpan.FromHours(3)));
}
}