Unione dell'ondata 5 (desktop M6, rifiniture M8): avvisi collegati una sola volta nella composizione condivisa per le due vesti
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Mzbb6zeFTjT6Rp8b92AVkA
This commit is contained in:
62 files changed
+4168
-327
No files matched your search
@@ -220,26 +220,35 @@ public sealed class DesktopCompositionTests
|
||||
{
|
||||
await using var bed = await DesktopTestBed.StartAsync();
|
||||
var events = bed.App.Engine!.Services.Events;
|
||||
var received = bed.Shell.Alerts.Received;
|
||||
var alerts = bed.App.Alerts!;
|
||||
var received = bed.Shell.NativeShell.Notified;
|
||||
|
||||
// The shared alert service of M8, the same as Docker's: Windows notifications through the native shell.
|
||||
await events.WriteAsync(EventSeverity.Error, EngineEventCodes.ChallengeStop, "Instagram ha chiesto una verifica: Febe si è fermato.", ct: TestContext.CancellationToken);
|
||||
await events.WriteAsync(EventSeverity.Info, EngineEventCodes.SessionEnded, "Sessione finita.", ct: TestContext.CancellationToken);
|
||||
await events.WriteAsync(EventSeverity.Success, EngineEventCodes.BackfillCompleted, "Storico di marta.prova completato.", ct: TestContext.CancellationToken);
|
||||
await alerts.FlushAsync();
|
||||
await DesktopTestBed.WaitUntilAsync(() => received.Count >= 2, TimeSpan.FromSeconds(10), "due notifiche");
|
||||
var alerts = received.ToArray();
|
||||
Assert.AreEqual(AlertKind.Verification, alerts[0].Kind);
|
||||
Assert.AreEqual("Instagram chiede una verifica", alerts[0].Title);
|
||||
Assert.AreEqual(AlertKind.BackfillDone, alerts[1].Kind);
|
||||
var notified = received.ToArray();
|
||||
Assert.HasCount(2, notified);
|
||||
Assert.AreEqual(AlertCatalog.Title(AlertKind.Verification), notified[0].Title);
|
||||
StringAssert.Contains(notified[0].Message, "«Riprendi»");
|
||||
Assert.AreEqual(AlertCatalog.Title(AlertKind.BackfillDone), notified[1].Title);
|
||||
|
||||
// Alberto turns off «Storico completato» and then the Windows notifications: nothing more arrives.
|
||||
var settings = AlertSettings.Default with { Events = AlertEvents.All with { BackfillDone = false } };
|
||||
await AlertSettingsStore.SaveAsync(bed.App.Database.Settings, settings, TestContext.CancellationToken);
|
||||
await events.WriteAsync(EventSeverity.Success, EngineEventCodes.BackfillCompleted, "Storico di luca.prova completato.", ct: TestContext.CancellationToken);
|
||||
await alerts.FlushAsync();
|
||||
await AlertSettingsStore.SaveAsync(bed.App.Database.Settings, settings with { WindowsNotifications = false }, TestContext.CancellationToken);
|
||||
await events.WriteAsync(EventSeverity.Error, EngineEventCodes.DisconnectStop, "Sessione terminata.", ct: TestContext.CancellationToken);
|
||||
await Task.Delay(500, TestContext.CancellationToken);
|
||||
await alerts.FlushAsync();
|
||||
Assert.HasCount(2, received);
|
||||
Assert.HasCount(1, bed.App.Alerts!.Channels);
|
||||
|
||||
// Impostazioni ▸ Notifiche: Windows notifications through the shell, Telegram through the composition's channel.
|
||||
var status = await bed.JsonAsync(HttpMethod.Get, "/api/settings/notifications");
|
||||
Assert.IsTrue(status.GetProperty("windowsAvailable").GetBoolean(), status.ToString());
|
||||
Assert.IsTrue(status.GetProperty("telegramAvailable").GetBoolean(), status.ToString());
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
|
||||
@@ -3,14 +3,16 @@ using Febe.Core.Alerts;
|
||||
using Febe.Core.Domain;
|
||||
using Febe.Core.Engine;
|
||||
using Febe.Core.Library;
|
||||
using Febe.Tests.Alerts.Support;
|
||||
using Febe.Tests.Engine.Support;
|
||||
using Febe.Tests.Support;
|
||||
|
||||
namespace Febe.Tests.Desktop;
|
||||
|
||||
/// <summary>
|
||||
/// Pieces of the shared composition (<see cref="FebeApp"/>) that both shells use: the alerts hook (spec §13.3) and the
|
||||
/// library folder that changes while Febe runs (desktop, spec §4.7). The Docker composition on top of it is proved by
|
||||
/// the Server tests (end-to-end with a real Chromium), unchanged.
|
||||
/// Pieces of the shared composition (<see cref="FebeApp"/>) that both shells use: which events become alerts (spec
|
||||
/// §13.3, <see cref="AlertCatalog"/>), the disk watch and the library folder that change while Febe runs (desktop,
|
||||
/// spec §4.7). The Docker composition on top of it is proved by the Server tests (end-to-end with a real Chromium).
|
||||
/// </summary>
|
||||
[TestClass]
|
||||
public sealed class SharedCompositionTests
|
||||
@@ -27,35 +29,55 @@ public sealed class SharedCompositionTests
|
||||
{
|
||||
[EngineEventCodes.ChallengeStop] = AlertKind.Verification,
|
||||
[EngineEventCodes.DisconnectStop] = AlertKind.Disconnection,
|
||||
[EngineEventCodes.ThrottleStop] = AlertKind.Throttle,
|
||||
[EngineEventCodes.ThrottleEnd] = AlertKind.Throttle,
|
||||
[EngineEventCodes.Resumed] = AlertKind.Throttle,
|
||||
[EngineEventCodes.ThrottleStop] = AlertKind.ThrottleStop,
|
||||
[EngineEventCodes.ThrottleEnd] = AlertKind.ThrottleEnd,
|
||||
[EngineEventCodes.BackfillCompleted] = AlertKind.BackfillDone,
|
||||
[EngineEventCodes.FormatUnrecognized] = AlertKind.UnknownFormat,
|
||||
[AlertRules.DiskLowCode] = AlertKind.DiskLow,
|
||||
[EngineEventCodes.RecipeSuspended] = AlertKind.RecipeSuspended,
|
||||
["disco-quasi-pieno"] = AlertKind.DiskLow,
|
||||
};
|
||||
foreach (var (code, kind) in expected)
|
||||
{
|
||||
var alert = AlertRules.FromEvent(Event(code));
|
||||
Assert.IsNotNull(alert, code);
|
||||
Assert.AreEqual(kind, alert.Kind, code);
|
||||
Assert.AreEqual(kind, AlertCatalog.KindOf(code), code);
|
||||
var alert = AlertCatalog.FromEvent(kind, Event(code), TimeZoneInfo.Utc);
|
||||
Assert.AreEqual(at, alert.At);
|
||||
Assert.IsFalse(string.IsNullOrWhiteSpace(alert.Title));
|
||||
Assert.IsFalse(string.IsNullOrWhiteSpace(alert.Message));
|
||||
}
|
||||
|
||||
foreach (var code in new[] { EngineEventCodes.SessionEnded, EngineEventCodes.BudgetReached, EngineEventCodes.Paused, "ricetta.ProfileCheck", "collegamento.primo" })
|
||||
foreach (var code in new[] { EngineEventCodes.SessionEnded, EngineEventCodes.BudgetReached, EngineEventCodes.Paused, EngineEventCodes.Resumed, AlertEventCodes.DeliveryFailed, "ricetta.ProfileCheck", "collegamento.primo" })
|
||||
{
|
||||
Assert.IsNull(AlertRules.FromEvent(Event(code)), code);
|
||||
Assert.IsNull(AlertCatalog.KindOf(code), code);
|
||||
}
|
||||
|
||||
// A long line (the key structure of an unknown format) is cut for a notification.
|
||||
var long_ = AlertRules.FromEvent(Event(EngineEventCodes.FormatUnrecognized, new string('k', 1000)))!;
|
||||
Assert.IsLessThanOrEqualTo(240, long_.Message.Length);
|
||||
|
||||
var none = new AlertEvents(false, false, false, false, false, false);
|
||||
Assert.IsFalse(Enum.GetValues<AlertKind>().Any(k => AlertRules.Wanted(k, none)));
|
||||
Assert.IsTrue(Enum.GetValues<AlertKind>().All(k => AlertRules.Wanted(k, AlertEvents.All)));
|
||||
Assert.IsFalse(AlertRules.Wanted(AlertKind.Throttle, AlertEvents.All with { Throttle = false }));
|
||||
Assert.IsFalse(Enum.GetValues<AlertKind>().Any(k => AlertCatalog.IsWanted(k, none)));
|
||||
Assert.IsTrue(Enum.GetValues<AlertKind>().All(k => AlertCatalog.IsWanted(k, AlertEvents.All)));
|
||||
var noThrottle = AlertEvents.All with { Throttle = false };
|
||||
Assert.IsFalse(AlertCatalog.IsWanted(AlertKind.ThrottleStop, noThrottle));
|
||||
Assert.IsFalse(AlertCatalog.IsWanted(AlertKind.ThrottleEnd, noThrottle));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task TheDiskWatchFollowsALibraryFolderChangedWhileFebeRuns()
|
||||
{
|
||||
await using var engine = await EngineTestBed.CreateAsync();
|
||||
var probe = new FakeFreeSpaceProbe();
|
||||
var library = "/prova/libreria";
|
||||
using var alerts = new AlertService(
|
||||
engine.Db.Settings,
|
||||
engine.Clock,
|
||||
engine.Services.Events,
|
||||
[],
|
||||
new AlertServiceOptions { FolderSource = () => [WatchedFolder.Library(library), WatchedFolder.Data("/prova/dati")], FreeSpace = probe });
|
||||
|
||||
// Impostazioni ▸ Generali ▸ «Cambia…» moves the library to an almost full disk: the next check sees it.
|
||||
probe.Set("/disco-piccolo/libreria", FakeFreeSpaceProbe.GB, 100 * FakeFreeSpaceProbe.GB);
|
||||
Assert.IsEmpty((await alerts.CheckDiskSpaceAsync(TestContext.CancellationToken)).Low);
|
||||
library = "/disco-piccolo/libreria";
|
||||
var check = await alerts.CheckDiskSpaceAsync(TestContext.CancellationToken);
|
||||
Assert.AreEqual("libreria", check.Key);
|
||||
Assert.AreEqual(library, check.Low.Single().Folder.Path);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
|
||||
@@ -5,7 +5,6 @@ using Febe.App;
|
||||
using Febe.Browser.Cdp;
|
||||
using Febe.Browser.Hosting;
|
||||
using Febe.Core.Abstractions;
|
||||
using Febe.Core.Alerts;
|
||||
using Febe.Desktop.Core;
|
||||
using Febe.Web.Native;
|
||||
|
||||
@@ -16,12 +15,8 @@ internal sealed class FakeDesktopShell : IDesktopShell
|
||||
{
|
||||
public FakeNativeShell NativeShell { get; } = new();
|
||||
|
||||
public RecordingAlertChannel Alerts { get; } = new();
|
||||
|
||||
public INativeShell Native => NativeShell;
|
||||
|
||||
public IAlertChannel? Notifications => Alerts;
|
||||
|
||||
/// <summary>The WebView2 runtime this «Windows» has (null: missing).</summary>
|
||||
public string? RuntimeVersion { get; set; } = "141.0.3537.71";
|
||||
|
||||
@@ -57,7 +52,7 @@ internal sealed class FakeDesktopShell : IDesktopShell
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Folder picker, explorer, default browser, notifications and autostart, faked.</summary>
|
||||
/// <summary>Folder picker, explorer, default browser, notifications (the Windows alerts) and autostart, faked.</summary>
|
||||
internal sealed class FakeNativeShell : INativeShell
|
||||
{
|
||||
public bool CanPickFolder => true;
|
||||
@@ -109,20 +104,6 @@ internal sealed class FakeNativeShell : INativeShell
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>The Windows notifications, recorded.</summary>
|
||||
internal sealed class RecordingAlertChannel : IAlertChannel
|
||||
{
|
||||
public ConcurrentQueue<FebeAlert> Received { get; } = new();
|
||||
|
||||
public bool IsEnabled(AlertSettings settings) => settings.WindowsNotifications;
|
||||
|
||||
public Task SendAsync(FebeAlert alert, AlertSettings settings, CancellationToken ct)
|
||||
{
|
||||
Received.Enqueue(alert);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The window «Browser di Febe», faked: a CDP session that answers like a browser on a blank page, a session cookie
|
||||
/// that exists once «Alberto» has logged in, and a record of every time the window came to the front or went away.
|
||||
|
||||
Reference in new issue
Block a user