A dead encoder used to run the whole stop path, so a one-second blip ended the broadcast. Now a dropped push is relaunched against the same ingest while the broadcast is still alive. - `Services/StreamRetryPolicy.cs` — immediate, +1 s, +2 s, +3 s. Minimum waits on purpose (creator ruling): YouTube's grace is short, so every second not pushing is grace spent. - `Services/StreamRecovery.cs` — the loop, with the audio pipe recreated before every attempt (its server is single-instance and unusable after the old client dies, so a naive relaunch fails on a missing input). After a push comes up it asks the API whether the broadcast survived: "complete" ends recovery as `BroadcastComplete` instead of showing a live sign over a dead stream; an API hiccup counts as recovered rather than ending a healthy session. - `FramePump.EncoderFailed` — a dead push is recoverable; a compositor fault still goes through `Failed` and ends the session, because retrying it would loop. - `MainViewModel.Recovery.cs` — wires the steps, reports each episode into the left panel alert stack (one row per episode, updated in place, log range painted), and cancels on Stop. - Alert stack polish: a rule and a gap now separate the stack from the scene layers (they read as one list before), and the licence indicator uses the creator's wording — `STEAM ID NOT PRESENT` / `Steam ID Limit: 30fps` / `Click for More Info`, becoming `STEAM ID PRESENT` / `60fps` with a close control once owned. Tests: `StreamRecoveryTests` (schedule, recover on attempt 2 with the pipe restarted each time, complete-broadcast honesty, unknown liveness, give-up, cancel, audio-restart fault), `FramePumpTests` now pin that process death raises `EncoderFailed` and not `Failed`. FAST gate: 538 passed (one documented pre-existing audio failure), 0 warnings.
151 lines
5.9 KiB
C#
151 lines
5.9 KiB
C#
using System;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using Microsoft.Data.Sqlite;
|
|
using Xunit;
|
|
using ytLive.Models;
|
|
using ytLive.Services.Entitlement;
|
|
using ytLive.ViewModels;
|
|
|
|
namespace ytLive.Tests;
|
|
|
|
/// <summary>
|
|
/// The left panel's alert stack (creator design, 2026-11-05). Row 1 is the Steam licence indicator and
|
|
/// nothing displaces it: pinned (no close) while higher tiers are unavailable, closable — permanently —
|
|
/// once ownership is verified, and back as pinned if ownership is later lost.
|
|
/// <para>Event rows stack beneath it, newest first, each dismissible, and clicking one opens the Logs
|
|
/// tab with that event's lines painted (the range is what the row carries).</para>
|
|
/// </summary>
|
|
[Collection("RealApp")]
|
|
public sealed class AttentionAlertStackTests
|
|
{
|
|
private readonly RealAppHost _app;
|
|
|
|
public AttentionAlertStackTests(RealAppHost app) => _app = app;
|
|
|
|
[Fact]
|
|
public void LicenceIndicator_IsPinnedFirst_AndShowsStatusNotAPunishment()
|
|
{
|
|
WithVm(vm =>
|
|
{
|
|
// A Debug build fakes ownership; this test is about the NOT-OWNED state.
|
|
vm.EntitlementOverride = new FakeEntitlement(false, "Steam licensing is not configured in this build.");
|
|
|
|
var row = Assert.Single(vm.AttentionAlerts);
|
|
Assert.Equal("STEAM ID NOT PRESENT", row.Label);
|
|
Assert.True(row.IsPinned);
|
|
Assert.True(row.ShowsPin);
|
|
Assert.False(row.CanDismiss);
|
|
Assert.Equal(AttentionAlertAction.About, row.Action);
|
|
|
|
// Creator wording: the limit this build runs at, and where to find out why.
|
|
Assert.Contains("Steam ID Limit: 30fps", row.Text);
|
|
Assert.Contains("Click for More Info", row.Text);
|
|
Assert.DoesNotContain("unavailable", row.Text, StringComparison.OrdinalIgnoreCase);
|
|
});
|
|
}
|
|
|
|
[Fact]
|
|
public void OwnedLicence_MakesTheIndicatorClosable_AndTheCloseIsPermanent()
|
|
{
|
|
WithVm((vm, db) =>
|
|
{
|
|
vm.EntitlementOverride = new FakeEntitlement(true);
|
|
|
|
var row = Assert.Single(vm.AttentionAlerts);
|
|
Assert.False(row.IsPinned);
|
|
Assert.False(row.ShowsPin);
|
|
Assert.True(row.CanDismiss);
|
|
Assert.Contains("Steam ID Limit: 60fps", row.Text);
|
|
|
|
vm.DismissAlertCommand.Execute(row);
|
|
Assert.Empty(vm.AttentionAlerts);
|
|
|
|
// Permanent: a fresh view-model on the same profile must not bring it back…
|
|
var reloaded = new MainViewModel();
|
|
Assert.DoesNotContain(reloaded.AttentionAlerts, alert => alert.Label.StartsWith("STEAM ID"));
|
|
|
|
// …but losing ownership restores it as a pinned indicator: a change of state, not a preference.
|
|
reloaded.EntitlementOverride = new FakeEntitlement(false, "Steam licensing is not configured in this build.");
|
|
var restored = reloaded.AttentionAlerts.First(alert => alert.Label == "STEAM ID NOT PRESENT");
|
|
Assert.True(restored.IsPinned);
|
|
});
|
|
}
|
|
|
|
[Fact]
|
|
public void PinnedIndicator_CannotBeDismissed()
|
|
{
|
|
WithVm(vm =>
|
|
{
|
|
vm.EntitlementOverride = new FakeEntitlement(false, "Steam licensing is not configured in this build.");
|
|
var row = vm.AttentionAlerts.Single();
|
|
vm.DismissAlertCommand.Execute(row);
|
|
Assert.Single(vm.AttentionAlerts); // still there: it is state, not an alert to clear
|
|
});
|
|
}
|
|
|
|
[Fact]
|
|
public void EventRows_StackBeneathTheIndicator_NewestFirst_AndDismissIndividually()
|
|
{
|
|
WithVm(vm =>
|
|
{
|
|
vm.EntitlementOverride = new FakeEntitlement(false, "Steam licensing is not configured in this build.");
|
|
vm.PushAttentionAlertForTest("drop-1", "STREAM", "Stream dropped — reconnecting (attempt 1 of 4)", 10, 12);
|
|
vm.PushAttentionAlertForTest("drop-2", "STREAM", "Stream dropped — reconnecting (attempt 2 of 4)", 13, 15);
|
|
|
|
Assert.Equal(new[] { "STEAM ID NOT PRESENT", "STREAM", "STREAM" }, vm.AttentionAlerts.Select(a => a.Label));
|
|
// Newest event sits directly under the indicator.
|
|
Assert.Contains("attempt 2", vm.AttentionAlerts[1].Text);
|
|
Assert.Contains("attempt 1", vm.AttentionAlerts[2].Text);
|
|
|
|
// The same event advancing updates its row instead of adding another.
|
|
vm.PushAttentionAlertForTest("drop-2", "STREAM", "Stream recovered after 1.4 s", 13, 16);
|
|
Assert.Equal(3, vm.AttentionAlerts.Count);
|
|
Assert.Contains("recovered", vm.AttentionAlerts[1].Text);
|
|
|
|
vm.DismissAlertCommand.Execute(vm.AttentionAlerts[1]);
|
|
Assert.Equal(2, vm.AttentionAlerts.Count);
|
|
Assert.Equal("STEAM ID NOT PRESENT", vm.AttentionAlerts[0].Label);
|
|
});
|
|
}
|
|
|
|
[Fact]
|
|
public void ClickingAnEventRow_OpensTheLogsTab_AndHighlightsItsRange()
|
|
{
|
|
WithVm(vm =>
|
|
{
|
|
vm.PushAttentionAlertForTest("drop-1", "STREAM", "Stream dropped", 41, 47);
|
|
|
|
vm.ActivateAlertCommand.Execute(vm.AttentionAlerts[1]);
|
|
|
|
Assert.True(vm.IsLogsTabSelected);
|
|
Assert.Equal(41, vm.HighlightedLogFrom);
|
|
Assert.Equal(47, vm.HighlightedLogTo);
|
|
});
|
|
}
|
|
|
|
private void WithVm(Action<MainViewModel> body) => WithVm((vm, _) => body(vm));
|
|
|
|
private void WithVm(Action<MainViewModel, string> body)
|
|
{
|
|
_app.Run(() =>
|
|
{
|
|
var tempDb = Path.Combine(Path.GetTempPath(), $"ytLlive-alerts-{Guid.NewGuid():N}.db");
|
|
MainViewModel.LayoutPathOverride = tempDb;
|
|
var window = new MainWindow();
|
|
var vm = (MainViewModel)window.DataContext;
|
|
try
|
|
{
|
|
body(vm, tempDb);
|
|
}
|
|
finally
|
|
{
|
|
window.Close();
|
|
MainViewModel.LayoutPathOverride = null;
|
|
SqliteConnection.ClearAllPools();
|
|
try { File.Delete(tempDb); } catch { /* best-effort cleanup */ }
|
|
}
|
|
});
|
|
}
|
|
}
|