Files
frameledger/tests/FrameLedger.App.Tests/ViewerModeTests.cs
poli0981andClaude Fable 5.2 f780738bc2 feat(advanced): the switch - Settings > Recording > Advanced metrics (telemetry.advanced, off by default); on, a session holds the Agent's one reader and stores its series and facts; Privacy Policy 2.15 and Disclaimer 2.15 (Advanced PR-5, D101/D109) (#391)
telemetry.advanced becomes RecorderOptions.AdvancedMetrics at each session's start. The Agent registers one
AdvancedHardwareHub; SessionRecorder holds it for a session's length only when the option is on, and the session's
TelemetryPoller gets it on the same condition. A session's facts are read once, off the capture loop, fifteen seconds
after the game's process is known or at the session's end; which display is the game's comes from Windows
(WindowGeometryProbe.MonitorDeviceOf). Off: not held, not asked, no chunk 9 or 10, no session_advanced row.

Settings gains the row (off in a viewer), strings in en/vi/ja, the guide's settings page. Privacy Policy 2.15 names
what is read and stored only while the option is on, and what never is. Disclaimer 2.15 (the owner's answer of
2026-11-11, D109): PawnIO and the admin mode are no longer "for the CPU temperature" alone; the admin mode's
disclosure follows (agent-admin-dialog/2), with Settings, the first run, the guide and LIMITATIONS.md. The accuracy
block gains an item. Nothing in src/native changes.

Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-11 12:11:57 +00:00

174 lines
11 KiB
C#

// SPDX-License-Identifier: GPL-3.0-only
// Copyright (C) 2026 poli0981 - additional terms under GPLv3 section 7: see NOTICE
using System.IO;
using System.Xml.Linq;
using FluentAssertions;
using FrameLedger.App.Services;
using FrameLedger.App.Update;
using FrameLedger.Application.Settings;
using FrameLedger.Shared.Ipc;
using FrameLedger.Shared.Safety;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
namespace FrameLedger.App.Tests;
/// <summary>
/// beta.15 (D52): a viewer over a copy starts and contacts no Agent and changes nothing on this PC. The composition holds
/// that structurally — nothing that could reach the pipe, start an Agent, write the Run entry, run the Agent's flags or
/// update is registered — and every control that would ask is disabled on its page.
/// </summary>
public sealed class ViewerModeTests
{
private static readonly UiMode _viewer = new(true, @"C:\copy-of-FrameLedger");
private sealed class CountingPrompt : IConsentPrompt
{
public int Shown { get; private set; }
public Task<bool> ShowAsync(string gameName, CancellationToken ct = default)
{
Shown++;
return Task.FromResult(true);
}
}
[Fact]
public async Task TheViewersLinkIsNeverConnectedAndSendsNothing()
{
var link = new ViewerAgentLink();
link.State.Should().Be(AgentConnectionState.Viewer);
link.IsConnected.Should().BeFalse();
link.Hello.Should().BeNull();
link.Status.Should().BeNull();
await FluentActions.Awaiting(() => link.RequestAsync(IpcMessageType.SetHookEnabled, new SetHookEnabledRequest(1, true, SafetyDisclosure.Version)))
.Should().ThrowAsync<InvalidOperationException>();
AgentStatusPresentation.Pill(AgentConnectionState.Viewer).Text.Should().Be(Strings.Agent_State_Viewer);
AgentStatusPresentation.Banner(AgentConnectionState.Viewer).Should().BeNull("the viewer's own banner says it; the offline banner's Retry has nothing to retry");
}
/// <summary>Rule 1's door: in a viewer the consent dialog never opens, so no acknowledgement can be typed for a request that cannot be sent.</summary>
[Fact]
public async Task TheConsentDialogNeverOpensInAViewer()
{
var prompt = new CountingPrompt();
var consent = new HookingConsent(new ViewerAgentLink(), prompt);
(await consent.EnableAsync(1, "Game", TestContext.Current.CancellationToken)).Outcome.Should().Be(HookingConsentOutcome.AgentUnavailable);
(await consent.DisableAsync(1, TestContext.Current.CancellationToken)).Outcome.Should().Be(HookingConsentOutcome.AgentUnavailable);
prompt.Shown.Should().Be(0);
}
[Fact]
public async Task AViewersCompositionHoldsNothingThatReachesPastItsLedger()
{
var services = new ServiceCollection();
MachineFacingServices.Add(services, _viewer);
services.Should().NotContain(static d => d.ServiceType == typeof(AgentConnection) || d.ServiceType == typeof(IAgentLauncher) || d.ServiceType == typeof(IHostedService),
"no pipe client, no launcher, and no hosted service: neither the connection's rounds nor the update check run");
services.Should().NotContain(static d => d.ImplementationType == typeof(RunAtLogonRegistry) || d.ImplementationType == typeof(AgentTool) || d.ImplementationType == typeof(VelopackUpdateClient));
await using ServiceProvider provider = services.BuildServiceProvider();
IAgentLink link = provider.GetRequiredService<IAgentLink>();
link.Should().BeOfType<ViewerAgentLink>();
provider.GetRequiredService<IAgentRequests>().Should().BeSameAs(link);
provider.GetRequiredService<IRunAtLogon>().Should().BeOfType<ViewerRunAtLogon>().Which.IsSet.Should().BeFalse();
provider.GetRequiredService<IUpdateClient>().IsInstalled.Should().BeFalse("a viewer never looks for, downloads or applies an update");
(await provider.GetRequiredService<IAgentTool>().RunAsync("--install-task", TestContext.Current.CancellationToken)).ExitCode.Should().Be(ViewerAgentTool.ExitViewer);
provider.GetRequiredService<UiMode>().Should().Be(_viewer);
provider.GetRequiredService<IShellStarter>().Should().BeOfType<ViewerShellStarter>("beta.21: Play hands nothing to a store's app");
provider.GetRequiredService<IShellStarter>().OpenLink("steam://rungameid/1").Should().BeFalse();
provider.GetRequiredService<LiveSessions>().Should().NotBeNull();
}
[Fact]
public void TheProfilesCompositionStillHasTheAgentAndTheMachine()
{
var services = new ServiceCollection();
MachineFacingServices.Add(services, UiMode.Profile);
services.Should().Contain(static d => d.ServiceType == typeof(AgentConnection));
services.Should().Contain(static d => d.ServiceType == typeof(IAgentLauncher));
services.Where(static d => d.ServiceType == typeof(IHostedService)).Select(static d => d.ImplementationType)
.Should().BeEquivalentTo([typeof(AgentConnectionHostedService), typeof(UpdateHostedService)]);
services.Should().Contain(static d => d.ImplementationType == typeof(RunAtLogonRegistry));
services.Should().Contain(static d => d.ImplementationType == typeof(AgentTool));
services.Should().Contain(static d => d.ImplementationType == typeof(VelopackUpdateClient));
services.Should().Contain(static d => d.ImplementationType == typeof(ShellStarter));
}
/// <summary>Every control that asks the Agent or changes this PC binds the viewer's switch, page by page.</summary>
[Theory]
[InlineData("MainWindow.xaml", "Command", "UpdateRulesCommand")]
[InlineData("MainWindow.xaml", "Command", "CheckForUpdatesCommand")]
[InlineData("Pages/GameDetailPage.xaml", "Command", "PlayCommand")]
[InlineData("Pages/GameDetailPage.xaml", "Command", "GrantExceptionCommand")]
[InlineData("Pages/GameDetailPage.xaml", "Command", "WithdrawExceptionCommand")]
[InlineData("Pages/GameDetailPage.xaml", "Command", "ReEnableHookingCommand")]
[InlineData("Pages/GameDetailPage.xaml", "Command", "DeleteAllSessionsCommand")]
[InlineData("Pages/SettingsPage.xaml", "Command", "DeleteAllSessionsCommand")]
[InlineData("Pages/SettingsPage.xaml", "Command", "RefreshExceptionsCommand")]
[InlineData("Pages/SettingsPage.xaml", "IsChecked", "KillSwitch, Mode=TwoWay")]
[InlineData("Pages/SettingsPage.xaml", "IsChecked", "RunElevated, Mode=TwoWay")]
[InlineData("Pages/SettingsPage.xaml", "IsChecked", "StartWithWindows, Mode=TwoWay")]
[InlineData("Pages/SettingsPage.xaml", "IsChecked", "AutoCheckUpdates, Mode=TwoWay")]
[InlineData("Pages/SettingsPage.xaml", "SelectedValue", "UpdateChannel, Mode=TwoWay")]
[InlineData("Pages/SettingsPage.xaml", "ItemsSource", "ExceptionGames")]
public void EveryControlThatAsksTheAgentOrChangesThisPcIsOffInAViewer(string file, string attribute, string binding)
{
ArgumentNullException.ThrowIfNull(file);
string relative = file.Replace('/', Path.DirectorySeparatorChar);
XDocument xaml = AccessibilityTests.AppXaml().Single(x => string.Equals(x.File, relative, StringComparison.Ordinal)).Xaml;
XElement control = xaml.Descendants().Single(e => string.Equals((string?)e.Attribute(attribute), "{Binding ViewModel." + binding + "}", StringComparison.Ordinal));
((string?)control.Attribute("IsEnabled")).Should().Be("{Binding ViewModel.ActsOnThisPc}", $"{file}: {binding}");
}
/// <summary>beta.21 (D59): every Play on the library — a card's and a row's — binds the page's viewer switch too.</summary>
[Fact]
public void EveryPlayOnTheLibraryIsOffInAViewer()
{
const string Through = ", RelativeSource={RelativeSource AncestorType={x:Type pages:GamesPage}}}";
XDocument xaml = AccessibilityTests.AppXaml().Single(static x => string.Equals(x.File, Path.Combine("Pages", "GamesPage.xaml"), StringComparison.Ordinal)).Xaml;
List<XElement> plays = [.. xaml.Descendants().Where(static e => string.Equals((string?)e.Attribute("Command"), "{Binding ViewModel.PlayCommand" + Through, StringComparison.Ordinal))];
plays.Should().HaveCount(2, "the card's and the row's");
plays.Should().AllSatisfy(static e => ((string?)e.Attribute("IsEnabled")).Should().Be("{Binding ViewModel.ActsOnThisPc" + Through));
}
/// <summary>
/// beta.18: every setting the Agent reads is off in a viewer, which has no Agent — the exception option and the three
/// Recording numbers stayed live, and a change said "Applied. The capture agent reads it at the next session start." The
/// registry says which settings the Agent reads, so a new one without its control here turns this red.
/// </summary>
[Fact]
public void EverySettingTheAgentReadsIsOffInAViewer()
{
Dictionary<string, (string Attribute, string Binding)> controls = new(StringComparer.Ordinal)
{
[SettingsRegistry.HookingKillSwitch.Key] = ("IsChecked", "KillSwitch, Mode=TwoWay"),
[SettingsRegistry.HookingUserModeExceptions.Key] = ("IsChecked", "UserModeExceptions, Mode=TwoWay"),
[SettingsRegistry.CaptureRunElevated.Key] = ("IsChecked", "RunElevated, Mode=TwoWay"),
[SettingsRegistry.CaptureMinSessionSeconds.Key] = ("Value", "MinSessionSeconds, Mode=TwoWay"),
[SettingsRegistry.TelemetryIntervalMs.Key] = ("Value", "TelemetryIntervalMs, Mode=TwoWay"),
[SettingsRegistry.TelemetryAdvanced.Key] = ("IsChecked", "AdvancedMetrics, Mode=TwoWay"),
[SettingsRegistry.RetentionRawSessionsPerGame.Key] = ("Value", "RetentionRawSessions, Mode=TwoWay"),
[SettingsRegistry.RetentionRemoveUninstalledGames.Key] = ("IsChecked", "RemoveUninstalledGames, Mode=TwoWay"),
};
XDocument xaml = AccessibilityTests.AppXaml().Single(static x => string.Equals(x.File, Path.Combine("Pages", "SettingsPage.xaml"), StringComparison.Ordinal)).Xaml;
List<string> live = [.. controls
.Select(c => (c.Key, Control: xaml.Descendants().Single(e => string.Equals((string?)e.Attribute(c.Value.Attribute), "{Binding ViewModel." + c.Value.Binding + "}", StringComparison.Ordinal))))
.Where(static c => !string.Equals((string?)c.Control.Attribute("IsEnabled"), "{Binding ViewModel.ActsOnThisPc}", StringComparison.Ordinal))
.Select(static c => c.Key)];
SettingsRegistry.All.Where(static d => d.AgentReads).Select(static d => d.Key).Should().BeEquivalentTo(controls.Keys, "every setting the Agent reads has its control named here");
string.Join(", ", live).Should().BeEmpty("a viewer has no Agent to read them");
}
}