using System; using System.Collections.Generic; using System.IO; using Microsoft.Data.Sqlite; using Xunit; using ytLive.Services; using ytLive.ViewModels; namespace ytLive.Tests; /// /// Game-bar meter honesty (creator bug 2026-09-01): the WASAPI loopback tap is /// PRE-endpoint-volume, so lowering the desktop slider left the meter pegged /// yellow/red at 20% — the mic formula scales level × volume, the game clone /// dropped the factor. The meter, the stream gain, and the headphones must all /// follow the one knob. /// [Collection("RealApp")] public sealed class GameMeterHonestyTests { private readonly RealAppHost _app; public GameMeterHonestyTests(RealAppHost app) => _app = app; [Fact] public void Game_Meter_Scales_By_Volume() { _app.Run(Run); } private void Run() { var tempDb = Path.Combine(Path.GetTempPath(), $"ytLlive-gamemeter-{Guid.NewGuid():N}.db"); MainViewModel.LayoutPathOverride = tempDb; var pushed = new List(); MainViewModel.VolumePushOverride = v => pushed.Add(v); var window = default(MainWindow); try { using (var schema = new LayoutStore(tempDb)) { } SqliteConnection.ClearAllPools(); window = new MainWindow(); var vm = (MainViewModel)window.DataContext; window.Show(); // Hot desktop bed pegged at full linear level (ToDisplay ~= 1.0). vm.GameAudioVolume = 1.0; vm.GameAudioLevel = 1.0; Assert.True(vm.GameMeterFillWidth > 230, "unity volume must keep the meter hot"); Assert.Equal("#ef4444", vm.GameMeterBrush); // Drop the knob to 20% — the captured level does NOT change (the OS // tap is pre-endpoint-volume); the meter must scale it anyway. vm.GameAudioVolume = 0.2; vm.GameAudioLevel = 1.0; Assert.InRange(vm.GameMeterFillWidth, 40, 80); Assert.Equal("#22c55e", vm.GameMeterBrush); // And the push really reached the (faked) endpoint — one knob, honest. Assert.Contains(0.2, pushed); } finally { MainViewModel.VolumePushOverride = null; if (window != null) window.Close(); MainViewModel.LayoutPathOverride = null; SqliteConnection.ClearAllPools(); try { File.Delete(tempDb); } catch { /* best-effort */ } } } }