* release: 0.1.0-beta.39 - Advanced metrics, train A: its changelog file, HANDOFF's beta.39 section with what the train decided, the traps and the next work (ask M16, then train B's plan), owner-only item 37, the release lines (Advanced PR-8) docs/changelog/0.1.0-beta.39.md holds [Unreleased] as it stood, under the release's summary: a setting, off by default, and a page of its own; Privacy Policy 2.15 and Disclaimer 2.15 shown once; schema 23. docs/HANDOFF.md's START HERE for beta.38 moves, verbatim, to docs/handoff/history/0.1.0-beta.38.md; the new one carries D109, what was decided that the plan had not, what is left open - nothing was seen in the running App, and the first run as administrator with PawnIO is still to come - and the traps this train paid for. Owner-only item 37 is what only the owner's PC can show. git diff v0.1.0-beta.38 -- src/native/FrameLedger.Overlay src/native/FrameLedger.VkLayer src/native/FrameLedger.Shm src/native/FrameLedger.Injector is empty: the code loaded into a game is beta.38's, line for line. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> * test(app): the page-load fixture loads Settings' System card once and awaits it - two pages built a moment apart could differ by a row, and the theme-switch comparison was red once on a hosted runner (Advanced PR-8) Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> --------- Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
278 lines
17 KiB
C#
278 lines
17 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.Windows;
|
|
using FrameLedger.App.Charts;
|
|
using FrameLedger.App.Controls;
|
|
using FrameLedger.App.Dialogs;
|
|
using FrameLedger.App.Pages;
|
|
using FrameLedger.App.Services;
|
|
using FrameLedger.App.ViewModels;
|
|
using FrameLedger.App.Windows;
|
|
using FrameLedger.Application.Persistence;
|
|
using FrameLedger.Application.Settings;
|
|
using FrameLedger.Application.TriState;
|
|
using FrameLedger.Domain.Metrics;
|
|
using FrameLedger.Infrastructure.Persistence;
|
|
using FrameLedger.Shared.Ipc;
|
|
|
|
namespace FrameLedger.App.Tests;
|
|
|
|
public sealed partial class PagesLoadTests
|
|
{
|
|
private sealed class NoOverride : ITriStateOverridePrompt
|
|
{
|
|
public Task<TriStateOverrideChoice?> AskAsync(TriStateChipModel chip, CancellationToken ct = default) => Task.FromResult<TriStateOverrideChoice?>(null);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Every surface the App draws, built the way the App builds it (beta.17): the six pages over loaded view models, the
|
|
/// first run, the three secondary windows, every dialog's content, the safety InfoBar and the two custom controls. The
|
|
/// view models load off the STA thread (<see cref="LoadAsync"/>); <see cref="All"/> hands out one builder per surface,
|
|
/// called on the STA thread — twice when a check compares a switched instance with a fresh one.
|
|
/// </summary>
|
|
internal sealed class Surfaces : IDisposable
|
|
{
|
|
private readonly List<IDisposable> _owned = [];
|
|
|
|
private Surfaces(ScratchLedger ledger) => Ledger = ledger;
|
|
|
|
public ScratchLedger Ledger { get; }
|
|
|
|
public DashboardViewModel Dashboard { get; private set; } = null!;
|
|
|
|
public GamesViewModel Games { get; private set; } = null!;
|
|
|
|
public GameDetailViewModel Detail { get; private set; } = null!;
|
|
|
|
public CompareViewModel Compare { get; private set; } = null!;
|
|
|
|
public SettingsViewModel Settings { get; private set; } = null!;
|
|
|
|
public LogsViewModel Logs { get; private set; } = null!;
|
|
|
|
/// <summary>
|
|
/// Settings' System card, loaded ONCE and awaited (2026-11-11). Until then every build of the page made a view model
|
|
/// of its own, whose lines arrive from the thread pool - so of two pages built a moment apart one could have its
|
|
/// "Processor" row and the other not, and the theme-switch comparison reported it as a text that "shows in a fresh
|
|
/// one only" (seen once on a hosted runner, never locally).
|
|
/// </summary>
|
|
public SystemInfoViewModel SystemInfo { get; private set; } = null!;
|
|
|
|
public AdvancedViewModel Advanced { get; private set; } = null!;
|
|
|
|
public SessionSummaryViewModel Summary { get; private set; } = null!;
|
|
|
|
public FirstRunViewModel FirstRun { get; private set; } = null!;
|
|
|
|
/// <summary>A game with a frame-generation session and a recorded-only one, every view model loaded over it.</summary>
|
|
public static async Task<Surfaces> LoadAsync(ScratchLedger s)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(s);
|
|
GameRow game = await s.GameAsync("Alpha").ConfigureAwait(false);
|
|
// beta.30 (D70): the newest session under another GPU driver, so the game page lists a numbered change under its overview
|
|
// and the readable and theme-switch sweeps measure that list and its badge.
|
|
long driver = await new SqliteHardwareSnapshotRepository(s.Db).EnsureAsync(new HardwareSnapshot { GpuName = "G", GpuDriver = "576.02" }, DateTimeOffset.UtcNow.AddHours(-1)).ConfigureAwait(false);
|
|
await s.SessionAsync(game.Id, DateTimeOffset.UtcNow.AddHours(-1), fgMode: "dlssg", native: 62, displayed: 118, factor: 1.9, shape: r => r with { SnapshotId = driver }).ConfigureAwait(false);
|
|
await s.SessionAsync(game.Id, DateTimeOffset.UtcNow.AddHours(-3), hooked: false).ConfigureAwait(false);
|
|
// beta.24 (D62): the summary's session carries a frame-generation mix, so its block is drawn and read in both themes.
|
|
string mix = Application.Recording.FgMixRecord.ToJson(new FgMix(
|
|
[
|
|
new FgMixRow(FgMixKind.Generated, 2.0, 62, 124, 2, 0.2, 1),
|
|
new FgMixRow(FgMixKind.Generated, 4.0, 60, 240, 5, 0.5, 1),
|
|
new FgMixRow(FgMixKind.None, null, 118, 118, 2, 0.2, 1),
|
|
new FgMixRow(FgMixKind.Unclassified, null, null, null, 1, 0.1, 1),
|
|
]))!;
|
|
// Advanced metrics (D101): a session recorded with the option on, so the page's Session tab has facts, statistics and a chart.
|
|
await s.SessionAsync(game.Id, DateTimeOffset.UtcNow.AddHours(-2), sensors: AdvancedFixtures.Blobs(), advanced: AdvancedFixtures.Row()).ConfigureAwait(false);
|
|
long withFrames = await s.SessionWithFramesAsync(game.Id, DateTimeOffset.UtcNow.AddHours(-5), frames: 600, spikeEvery: 200, shape: r => r with { FgMixJson = mix }).ConfigureAwait(false);
|
|
var surfaces = new Surfaces(s);
|
|
await surfaces.LoadPagesAsync(game.Id).ConfigureAwait(false);
|
|
surfaces.Summary = new SessionSummaryViewModel(s.Sessions, s.Games, s.Annotations, new SqliteHardwareSnapshotRepository(s.Db),
|
|
new SessionSeriesLoader(s.Sessions), new NoOverride(), new NoSaver(), new NoStrip());
|
|
await surfaces.Summary.LoadAsync(withFrames, CancellationToken.None).ConfigureAwait(false);
|
|
surfaces.FirstRun = surfaces.Own(new FirstRunViewModel(new LegalGate(new SqliteLegalAcceptanceStore(s.Db), LegalDocuments.Load()), new NoAgent(), readOnly: false));
|
|
return surfaces;
|
|
}
|
|
|
|
private async Task LoadPagesAsync(long gameId)
|
|
{
|
|
ScratchLedger s = Ledger;
|
|
var selection = new GameSelection { GameId = gameId };
|
|
var nav = new NoNavigation();
|
|
var strip = new NoStrip();
|
|
var consent = new HookingConsent(new NoAgent(), new NoPrompt());
|
|
|
|
// The view models load off the STA thread; the pages bind to them on it. beta.28: two games recording at once, a
|
|
// hooked one and one held, so the Dashboard's two cards are drawn and read in both themes.
|
|
var recording = new RecordingAgent(
|
|
[
|
|
new ActiveSession(Guid.NewGuid(), gameId, "Alpha", 41, 1, DateTimeOffset.UtcNow.AddMinutes(-2), null),
|
|
new ActiveSession(Guid.NewGuid(), gameId, "Beta", 42, 2, DateTimeOffset.UtcNow.AddMinutes(-1), new SessionHold("RefusedHookNotEnabled")),
|
|
]);
|
|
LiveSessions live = Own(new LiveSessions(recording));
|
|
Dashboard = new DashboardViewModel(recording, s.Library, selection, nav, new NoSummaries(), sessions: live);
|
|
Dashboard.Attach();
|
|
Task pending1 = Dashboard.Pending;
|
|
await pending1.ConfigureAwait(false);
|
|
Games = new GamesViewModel(s.Library, selection, nav, new AddGameFlow(s.Library, new NoPicker(), selection, nav, strip));
|
|
Task pending2 = Games.Pending;
|
|
await pending2.ConfigureAwait(false);
|
|
// beta.23 (D60/D61): the game page with artwork — a banner and a saturated cover — so every text on the tinted band is
|
|
// measured in both themes and through a switch; the store app's folder is one this test draws.
|
|
string artDirectory = Path.Combine(Path.GetTempPath(), "fl-surfaces-art-" + Guid.NewGuid().ToString("N"));
|
|
Own(new DeletesOnDispose(artDirectory));
|
|
GameRow game = (await s.Games.FindByIdAsync(gameId).ConfigureAwait(false))!;
|
|
string cover = TestImages.Write(Path.Combine(artDirectory, "library_600x900.jpg"), TestImages.Png(30, 45, System.Windows.Media.Color.FromRgb(230, 200, 20)));
|
|
string hero = TestImages.Write(Path.Combine(artDirectory, "library_hero.jpg"), TestImages.Png(96, 31, System.Windows.Media.Color.FromRgb(30, 60, 210)));
|
|
var art = new GameArt(new RegisteredSettings(new MemorySettings()),
|
|
new StoreRecordsReader([new TestImages.Store("steam", new Application.Import.StoreGame("steam", "374320", "Alpha", Path.GetDirectoryName(game.Fingerprint.ExePath)!, null, null))]),
|
|
[new TestImages.ArtCache("steam", "374320", new Application.Art.GameArtFiles(cover, hero, null))],
|
|
new UiMode(false, artDirectory));
|
|
Detail = new GameDetailViewModel(s.Library, selection, consent, nav, new NoConfirm(), new NoEdit(), strip, new NoSummaries(),
|
|
new SessionSeriesLoader(s.Sessions), new SqliteHardwareSnapshotRepository(s.Db), new SessionSelection(), new NoPicker(), art: art);
|
|
Task pending3 = Detail.Pending;
|
|
await pending3.ConfigureAwait(false);
|
|
Compare = new CompareViewModel(s.Library, new SessionSeriesLoader(s.Sessions), new NoMixed(), new NoSaver(), strip);
|
|
Task pending4 = Compare.Pending;
|
|
await pending4.ConfigureAwait(false);
|
|
(SettingsViewModel settings, LogsViewModel logs) = await SettingsAndLogsAsync(s, consent, strip).ConfigureAwait(false);
|
|
Settings = settings;
|
|
Logs = logs;
|
|
SystemInfo = new SystemInfoViewModel(new FixedHardware(), new NoClipboard(), strip);
|
|
Task pending6 = SystemInfo.Pending;
|
|
await pending6.ConfigureAwait(false);
|
|
// The Advanced page with this PC as the Agent last read it - facts, a table that unfolds, live rows, a chart - and
|
|
// the session above; no feed loop runs, so nothing here waits on a clock.
|
|
Advanced = new AdvancedViewModel(Own(new AdvancedMachineFeed(new NoAgent(), TimeProvider.System)), s.Sessions, s.Games, new SessionSeriesLoader(s.Sessions), new AdvancedSelection());
|
|
Task pending5 = Advanced.Pending;
|
|
await pending5.ConfigureAwait(false);
|
|
Advanced.ShowMachine(AdvancedFixtures.View());
|
|
}
|
|
|
|
/// <summary>Every surface by name, each with a builder to call on the STA thread.</summary>
|
|
public IEnumerable<(string Name, Func<FrameworkElement> Build)> All() => [.. Pages(), .. Windows(), .. Dialogs(), .. Controls()];
|
|
|
|
/// <summary>The six pages the navigation opens.</summary>
|
|
public IEnumerable<(string Name, Func<FrameworkElement> Build)> Pages() =>
|
|
[
|
|
("Dashboard", () => new DashboardPage(Dashboard)),
|
|
("Games", () => new GamesPage(Games)),
|
|
("Game detail", () => new GameDetailPage(Detail)),
|
|
("Compare", () => new ComparePage(Compare)),
|
|
("Settings", () => new SettingsPage(Settings, SystemInfo)),
|
|
("Logs", () => new LogsPage(Logs)),
|
|
("Advanced", () => new AdvancedPage(Advanced)),
|
|
];
|
|
|
|
/// <summary>The first run's gate and the secondary windows: About, the user guide, a session's summary.</summary>
|
|
public IEnumerable<(string Name, Func<FrameworkElement> Build)> Windows() =>
|
|
[
|
|
("First run", () => new FirstRunContent(FirstRun)),
|
|
("About", () => new AboutWindow(new NoUrlOpener(), new NoTheme(), new AppearanceSettings(new MemorySettings()))),
|
|
("User guide", () => new DocumentWindow(Strings.Guide_Title, EmbeddedDocuments.Guide(), new NoUrlOpener(), new NoTheme(), new AppearanceSettings(new MemorySettings()))),
|
|
("Session summary", () => new SessionSummaryWindow(Summary, new NoTheme(), new AppearanceSettings(new MemorySettings()))),
|
|
];
|
|
|
|
/// <summary>Every dialog's content, over a view model of its own.</summary>
|
|
public IEnumerable<(string Name, Func<FrameworkElement> Build)> Dialogs() =>
|
|
[
|
|
("Consent", () => new ConsentDialogContent(new ConsentDialogViewModel("Alpha"))),
|
|
("Admin mode", () => new AgentAdminDialogContent(new AgentAdminDialogViewModel())),
|
|
("Anti-cheat exception", () => new AntiCheatExceptionDialogContent(new AntiCheatExceptionDialogViewModel(new AntiCheatExceptionFacts("Alpha", "NetEase Yidun", "NEP2.dll")))),
|
|
("Bug report preview", () => new BugReportPreviewContent(new BugReportPreviewViewModel(new BugReportPreviewModel(@"C:\data\bug-report.zip",
|
|
["logs/ui-20261007.log", "system.txt"], new Uri("https://github.com/poli0981/frameledger/issues/new"), "## What happened")))),
|
|
("Edit game", () => new EditGameContent(new EditGameViewModel(new GameMetadata { Name = "Alpha" }, provenanceJson: null))),
|
|
// beta.23 (D60): the image row, with no image (its caption shows) and with the user's own (the store's button shows).
|
|
("Edit game, no image", () => new EditGameContent(new EditGameViewModel(new GameMetadata { Name = "Alpha" }, provenanceJson: null,
|
|
new EditImage(null, CurrentIsOwn: false, null, new NoImages(), static _ => Task.FromResult<System.Windows.Media.ImageSource?>(null))))),
|
|
("Edit game, own image", () => new EditGameContent(new EditGameViewModel(new GameMetadata { Name = "Alpha" }, provenanceJson: null,
|
|
new EditImage(Detail.ArtCover, CurrentIsOwn: true, Detail.ArtCover, new NoImages(), static _ => Task.FromResult<System.Windows.Media.ImageSource?>(null))))),
|
|
("Override", () => new TriStateOverrideContent(new TriStateOverrideViewModel(new TriStateChipModel("RT", Tri.Yes, TriStateSource.Measured)))),
|
|
("Bug bundle options", () => new BugBundleOptionsContent(new BugBundleOptionsViewModel(new BugBundleOffer(
|
|
new CrashDumpInfo(@"C:\data\crashdumps\ui-20261007-010203-42.dmp", DateTimeOffset.UtcNow, 2 * 1024 * 1024), new LastSessionInfo(1, "Alpha", DateTimeOffset.UtcNow))))),
|
|
("Database maintenance", () => new DatabaseMaintenanceContent(new DatabaseMaintenanceViewModel(new LedgerMaintenance(Ledger.Db), Ledger.Db.Path, new NoAgent(),
|
|
new NoSaver(), new NoMaintenancePrompts(), new RegisteredSettings(new SqliteSettingsStore(Ledger.Db))))),
|
|
("Import review", () => new ImportReviewContent(new ImportReviewViewModel(
|
|
[
|
|
new Application.Import.ImportCandidate(new Application.Import.StoreGame("steam", "1", "A", @"C:\a", @"C:\a\a.exe", null), @"C:\a\a.exe",
|
|
AlreadyInLibrary: false, ExecutableGuessed: false),
|
|
new Application.Import.ImportCandidate(new Application.Import.StoreGame("steam", "2", "B", @"C:\b", @"C:\b\b.exe", null), @"C:\b\b.exe",
|
|
AlreadyInLibrary: true, ExecutableGuessed: false),
|
|
])
|
|
{ ShowExisting = true })),
|
|
];
|
|
|
|
/// <summary>The safety notice's InfoBar (its own template, Styles/FrameLedger.xaml) and the two custom controls.</summary>
|
|
public IEnumerable<(string Name, Func<FrameworkElement> Build)> Controls() =>
|
|
[
|
|
("Safety InfoBar", NoticeWithAction),
|
|
("FPS readout", () => new FpsReadout { Model = FpsPresentation.FromRow(Detail.Sessions[0].Row) }),
|
|
("Tri-state chip", () => new TriStateChip { Model = new TriStateChipModel("RT", Tri.NotApplicable, TriStateSource.Measured) }),
|
|
("Change badge", () => new ChangeBadge { Text = "1" }),
|
|
];
|
|
|
|
public void Dispose()
|
|
{
|
|
foreach (IDisposable owned in _owned)
|
|
{
|
|
owned.Dispose();
|
|
}
|
|
}
|
|
|
|
private T Own<T>(T disposable)
|
|
where T : IDisposable
|
|
{
|
|
_owned.Add(disposable);
|
|
return disposable;
|
|
}
|
|
}
|
|
|
|
/// <summary>An Agent that answers with the sessions it is recording and says nothing else (beta.28's two live cards).</summary>
|
|
private sealed class RecordingAgent(IReadOnlyList<ActiveSession> sessions) : IAgentLink
|
|
{
|
|
public AgentConnectionState State => AgentConnectionState.Connected;
|
|
|
|
public StatusAck? Status { get; } = new("recording", null, null, sessions);
|
|
|
|
public HelloAck? Hello => null;
|
|
|
|
public bool IsConnected => true;
|
|
|
|
public event EventHandler? Changed
|
|
{
|
|
add { }
|
|
remove { }
|
|
}
|
|
|
|
public event EventHandler<AgentEventArgs>? EventReceived
|
|
{
|
|
add { }
|
|
remove { }
|
|
}
|
|
|
|
public Task<IpcEnvelope> RequestAsync<TRequest>(string type, TRequest payload, CancellationToken ct = default)
|
|
where TRequest : class => throw new NotSupportedException();
|
|
|
|
public void SetLaunchHold(bool hold)
|
|
{
|
|
}
|
|
}
|
|
|
|
/// <summary>A folder the test made, deleted with the surfaces.</summary>
|
|
private sealed class DeletesOnDispose(string directory) : IDisposable
|
|
{
|
|
public void Dispose()
|
|
{
|
|
try
|
|
{
|
|
Directory.Delete(directory, recursive: true);
|
|
}
|
|
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException)
|
|
{
|
|
}
|
|
}
|
|
}
|
|
}
|