* ci: Qodana - a workflow of its own from JetBrains' template, Qodana Community for .NET over FrameLedger.slnx (D93) The first run: the linter in its Linux container, EnableWindowsTargeting passed to it, no quality gate yet - what it builds and what it reports decides the rest. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> * ci: Qodana's gate is zero problems, and the inspections this project argues with are off in .editorconfig, each with its reason (D93) Pushed before the fixes on purpose: the run this starts has the settings and none of the fixes, so it shows the gate failing on what is left. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> * fix: what Qodana's first run reported, settled - about 400 fixes in 181 files, none changing behaviour; the documents (D93) Redundant qualifiers, casts, using directives, nullable suppressions and unsafe modifiers removed from the report's own positions; var for built-in types and one-line block bodies brought to .editorconfig's style by dotnet format; every XAML item template names its DataType and a binding that reached its page through DataContext.ViewModel names the page's type; two unread fields, two overwritten initialisers and an unused parameter removed; SpokenTextAutomationPeer no longer assumes the base peer's name is a string. docs/13_CI_CD.md §Qodana, CLAUDE.md, the wiki's workflow table, HANDOFF's decisions index (D93) and the changelog entry. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> --------- Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
282 lines
17 KiB
C#
282 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.Globalization;
|
||
using System.IO;
|
||
using FluentAssertions;
|
||
using FrameLedger.App.Services;
|
||
using FrameLedger.Domain.Detection;
|
||
using FrameLedger.Domain.Sessions;
|
||
|
||
namespace FrameLedger.App.Tests;
|
||
|
||
/// <summary>The page numbers as text, in English: durations, playtime, resolutions, the token → product-name maps, and N/A where a value is missing.</summary>
|
||
[Collection(StringsCultureCollection.Name)]
|
||
public sealed class FormatsTests
|
||
{
|
||
private static T InEnglish<T>(Func<T> f)
|
||
{
|
||
CultureInfo? previous = Strings.Culture;
|
||
CultureInfo previousCulture = CultureInfo.CurrentCulture;
|
||
try
|
||
{
|
||
Strings.Culture = CultureInfo.GetCultureInfo("en");
|
||
CultureInfo.CurrentCulture = CultureInfo.GetCultureInfo("en");
|
||
return f();
|
||
}
|
||
finally
|
||
{
|
||
Strings.Culture = previous;
|
||
CultureInfo.CurrentCulture = previousCulture;
|
||
}
|
||
}
|
||
|
||
/// <summary>beta.14 (D49): a share to one decimal, a frame-time difference in ms, frames per joule as FPS/W; N/A, never 0.</summary>
|
||
[Fact]
|
||
public void SharesMillisecondsAndFramesPerWatt()
|
||
{
|
||
InEnglish(static () => (Formats.Share(9.62), Formats.Share(0.04), Formats.Share(null))).Should().Be(("9.6%", "0.0%", "N/A"));
|
||
InEnglish(static () => (Formats.Milliseconds(0.875), Formats.Milliseconds(null))).Should().Be(("0.88 ms", "N/A"));
|
||
InEnglish(static () => (Formats.FramesPerJoule(0.3125), Formats.FramesPerJoule(null))).Should().Be(("0.31 FPS/W", "N/A"));
|
||
InEnglish(static () => (Formats.Frequency(2655.4), Formats.Rpm(1450.4))).Should().Be(("2,655 MHz", "1,450 RPM"));
|
||
}
|
||
|
||
[Fact]
|
||
public void DurationsAndPlaytime()
|
||
{
|
||
InEnglish(() => Formats.Duration(5025)).Should().Be("1h 23m");
|
||
InEnglish(() => Formats.Duration(245)).Should().Be("4m 05s");
|
||
InEnglish(() => Formats.Playtime(9000)).Should().Be("2.5 h");
|
||
InEnglish(() => Formats.Playtime(1500)).Should().Be("25 min");
|
||
InEnglish(() => Formats.Duration(-3)).Should().Be("0m 00s");
|
||
}
|
||
|
||
/// <summary>
|
||
/// 03_METRICS §Upscaling's ladder as the UI states it (2026-09-21): a hook's name outranks the driver's, the driver's
|
||
/// name says it is the driver's and never takes a quality, and a DLSS quality byte is the preset's name.
|
||
/// </summary>
|
||
[Fact]
|
||
public void TheUpscalerLadderNamesTheDriverOnlyWhereNoHookDid()
|
||
{
|
||
InEnglish(() => Formats.Upscaler("unknown", null, "dlss")).Should().Be("DLSS (driver-reported)", "an NGX-direct title: the hook ran and saw nothing, the driver saw the feature evaluated");
|
||
InEnglish(() => Formats.Upscaler(null, null, "dlss")).Should().Be("DLSS (driver-reported)");
|
||
InEnglish(() => Formats.Upscaler("unknown", "2", "dlss")).Should().Be("DLSS (driver-reported)", "the driver's word is identity only");
|
||
InEnglish(() => Formats.Upscaler("fsr3", null, "dlss")).Should().Be("FSR 3", "a hook's name always outranks the driver's");
|
||
InEnglish(() => Formats.Upscaler("dlss", "2", "dlss")).Should().Be("DLSS Balanced");
|
||
InEnglish(() => Formats.Upscaler("dlss", "6", null)).Should().Be("DLSS DLAA");
|
||
InEnglish(() => Formats.Upscaler("dlss", "9", null)).Should().Be("DLSS 9", "a value with no name is shown as stored");
|
||
InEnglish(() => Formats.Upscaler("unknown", null, null)).Should().Be("Upscaler not identified");
|
||
InEnglish(() => Formats.Upscaler("unknown", "2", null)).Should().Be("Upscaler not identified", "a quality without a name to hang it on is not printed");
|
||
InEnglish(() => Formats.Upscaler("none", null, null)).Should().Be("No upscaler");
|
||
InEnglish(() => Formats.Upscaler(null, null, null)).Should().Be("N/A");
|
||
}
|
||
|
||
/// <summary>
|
||
/// D63 (beta.24): a session's mode on every surface — the NVIDIA App's override where the driver reports it applied,
|
||
/// marked as the App's; the game's own hooked mode otherwise; an override whose mode is not settled says so and never
|
||
/// shows the game's value instead. The driver words are the owner's Expedition 33 session's (2026-09-06).
|
||
/// </summary>
|
||
[Fact]
|
||
public void ASessionsModeIsTheNvidiaAppsWhereTheDriverConfirmsItsOverride()
|
||
{
|
||
const string quality = "{\"Outcome\":\"Answered\",\"Sr\":\"0x8067F\",\"Mode\":2,\"Preset\":11,\"Readings\":3,\"Answered\":3}";
|
||
const string disagreeing = "{\"Outcome\":\"Answered\",\"Sr\":\"0x8067F\",\"Mode\":0,\"Readings\":3,\"Answered\":3}";
|
||
string profile = Application.Recording.DriverProfileRecord.Serialize(new Application.Capture.DriverProfileReading
|
||
{
|
||
Outcome = Application.Capture.DriverProfileOutcome.Application,
|
||
ProfileName = "Clair Obscur: Expedition 33",
|
||
Settings = [new Application.Capture.DriverSettingReading(Application.Capture.NvidiaDriverSettings.DlssSrMode, 2, Application.Capture.DriverSettingLocation.Profile, false)],
|
||
})!;
|
||
|
||
InEnglish(() => Formats.UpscalerOf(Row("unknown", null, "dlss", quality, profile))).Should().Be("DLSS (driver-reported) Quality · NVIDIA App");
|
||
InEnglish(() => Formats.UpscalerOf(Row("dlss", "1", null, quality, null))).Should().Be("DLSS Quality · NVIDIA App", "the override replaces what the game passed");
|
||
InEnglish(() => Formats.UpscalerOf(Row("unknown", null, "dlss", disagreeing, profile))).Should().Be("DLSS (driver-reported) · NVIDIA App override", "two NVIDIA sources disagree: no mode");
|
||
InEnglish(() => Formats.UpscalerOf(Row("dlss", "3", null, null, null))).Should().Be("DLSS Quality", "no override: the game's own");
|
||
InEnglish(() => Formats.UpscalerOf(Row("dlss", "9", null, null, null))).Should().Be("DLSS 9");
|
||
InEnglish(() => Formats.UpscalerOf(Row("unknown", null, null, quality, profile))).Should().Be("Upscaler not identified", "the driver never saw super resolution run");
|
||
|
||
InEnglish(() => Formats.UpscalerOf(new Shared.Ipc.SessionProgressEvent { SessionGuid = Guid.Empty, Presents5s = 500, ElapsedS = 5, PresentedQualifier = "census_not_run", FgMode = "na", Upscaler = "unknown", UpscalerDriverReported = "dlss", UpscalerQualityOverride = "dlaa" }))
|
||
.Should().Be("DLSS (driver-reported) DLAA · NVIDIA App");
|
||
InEnglish(() => Formats.UpscalerOf(new Shared.Ipc.SessionProgressEvent { SessionGuid = Guid.Empty, Presents5s = 500, ElapsedS = 5, PresentedQualifier = "census_not_run", FgMode = "na", Upscaler = "dlss", UpscalerQuality = "2", UpscalerQualityOverride = "override" }))
|
||
.Should().Be("DLSS · NVIDIA App override", "live, an override the report alone cannot settle");
|
||
InEnglish(() => Formats.UpscalerOf(new Shared.Ipc.SessionProgressEvent { SessionGuid = Guid.Empty, Presents5s = 500, ElapsedS = 5, PresentedQualifier = "census_not_run", FgMode = "na", Upscaler = "dlss", UpscalerQuality = "2" }))
|
||
.Should().Be("DLSS Balanced");
|
||
InEnglish(() => Formats.QualityName(new Application.Recording.ResolvedQuality(Domain.Metrics.UpscalerQualityMode.Custom, Application.Recording.QualitySource.NvidiaApp, 77)))
|
||
.Should().Be("custom 77%");
|
||
InEnglish(() => Formats.QualityName(new Application.Recording.ResolvedQuality(Domain.Metrics.UpscalerQualityMode.UltraQuality, Application.Recording.QualitySource.Game)))
|
||
.Should().Be("Ultra Quality");
|
||
InEnglish(() => Formats.UpscalerOf(Row("fsr3", "17", null, null, null))).Should().Be("FSR 3 Quality", "beta.25 (D65): the mode FSR's query named");
|
||
InEnglish(() => Formats.UpscalerOf(Row("fsr", "16", null, null, null))).Should().Be("FSR Native AA");
|
||
}
|
||
|
||
private static Application.Persistence.SessionRow Row(string? upscaler, string? quality, string? driverReported, string? words, string? profile) => new()
|
||
{
|
||
SessionGuid = Guid.NewGuid(),
|
||
GameId = 1,
|
||
SnapshotId = 1,
|
||
StartedAt = DateTimeOffset.UnixEpoch,
|
||
EndedAt = DateTimeOffset.UnixEpoch.AddMinutes(5),
|
||
QpcEpoch = 0,
|
||
QpcFrequency = 1,
|
||
Tier = CaptureTier.Hooked,
|
||
Mode = CaptureMode.Launch,
|
||
ExitStatus = ExitStatus.Normal,
|
||
Upscaler = upscaler,
|
||
UpscalerQuality = quality,
|
||
UpscalerDriverReported = driverReported,
|
||
NgxDriverWordsJson = words,
|
||
DriverProfileJson = profile,
|
||
};
|
||
|
||
[Fact]
|
||
public void ResolutionsUpscalersAndFrameGeneration()
|
||
{
|
||
InEnglish(() => Formats.Resolution(1485, 835, 2560, 1440)).Should().Be("1485×835 → 2560×1440");
|
||
InEnglish(() => Formats.Resolution(2560, 1440, 2560, 1440)).Should().Be("2560×1440", "no upscale: one pair");
|
||
InEnglish(() => Formats.Resolution(null, null, 2560, 1440)).Should().Be("2560×1440");
|
||
InEnglish(() => Formats.Resolution(null, null, null, null)).Should().Be("N/A");
|
||
Formats.Upscaler("dlss").Should().Be("DLSS");
|
||
Formats.Upscaler("fsr3").Should().Be("FSR 3");
|
||
InEnglish(() => Formats.Upscaler("none")).Should().Be("No upscaler");
|
||
InEnglish(() => Formats.Upscaler(null)).Should().Be("N/A");
|
||
Formats.FrameGeneration("dlssg").Should().Be("DLSS-G");
|
||
InEnglish(() => Formats.FrameGeneration("active")).Should().Contain("not identified");
|
||
InEnglish(() => Formats.FrameGeneration("na")).Should().Be("N/A");
|
||
Formats.Api("d3d12").Should().Be("D3D12");
|
||
InEnglish(() => Formats.Api("weird")).Should().Be("N/A");
|
||
}
|
||
|
||
[Fact]
|
||
public void FpsAndTemperaturesAndExitStatus()
|
||
{
|
||
InEnglish(() => Formats.Fps(61.6)).Should().Be("62");
|
||
InEnglish(() => Formats.Fps(null)).Should().Be("N/A");
|
||
InEnglish(() => Formats.FpsOrDash(null)).Should().Be("—");
|
||
InEnglish(() => Formats.Temperature(71.4)).Should().Be("71 °C");
|
||
InEnglish(() => Formats.Temperature(null)).Should().Be("N/A");
|
||
InEnglish(() => Formats.ExitStatusText(ExitStatus.Crashed)).Should().Be("crashed");
|
||
InEnglish(() => Formats.ExitStatusText(ExitStatus.UnhookedSafety)).Should().Be("unhooked (safety)");
|
||
Formats.Platform("steam").Should().Be("Steam");
|
||
Formats.Platform("xbox").Should().Be("Xbox", "beta.33, D79: the Xbox app and the Microsoft Store");
|
||
Formats.Platform("none").Should().BeEmpty();
|
||
}
|
||
|
||
/// <summary>The engine ids as names (2026-09-23): proper nouns in every language; an id this table does not know passes through.</summary>
|
||
/// <summary>beta.8: what an executable runs as, in words — an id this build does not know reads as "could not be read".</summary>
|
||
[Fact]
|
||
public void ArchitecturesAreSaidInWords() => InEnglish(() =>
|
||
{
|
||
Formats.Architecture(ExecutableArchitecture.X64).Should().Be("64-bit (x64)");
|
||
Formats.Architecture(ExecutableArchitecture.X86).Should().Be("32-bit (x86)");
|
||
Formats.Architecture(ExecutableArchitecture.AnyCpu).Should().Be(".NET, any CPU (runs as 64-bit)");
|
||
Formats.Architecture(ExecutableArchitecture.AnyCpu32).Should().Contain("runs as 32-bit");
|
||
Formats.Architecture(ExecutableArchitecture.Arm64).Should().Be("ARM64");
|
||
Formats.Architecture(ExecutableArchitecture.Other).Should().Be("another architecture");
|
||
Formats.Architecture(ExecutableArchitecture.Unknown).Should().Be("could not be read");
|
||
Formats.Architecture("mips").Should().Be("could not be read");
|
||
return 0;
|
||
});
|
||
|
||
/// <summary>beta.8: a store's version is said as one; a version the user typed is shown as typed; none is none.</summary>
|
||
[Fact]
|
||
public void AStoreVersionIsLabelledWithItsStore() => InEnglish(() =>
|
||
{
|
||
Formats.StoreVersion("steam", "20374416", detected: true).Should().Be("Steam build 20374416");
|
||
Formats.StoreVersion("gog", "1.2.3", detected: true).Should().Be("GOG version 1.2.3");
|
||
Formats.StoreVersion("epic", "++Fortnite+Release-31.10", detected: true).Should().Be("Epic version ++Fortnite+Release-31.10");
|
||
Formats.StoreVersion("xbox", "1.3.5124.0", detected: true).Should().Be("Xbox version 1.3.5124.0", "the package version an import read");
|
||
Formats.StoreVersion("itch", "0.9", detected: true).Should().Be("0.9", "itch has no store version to label");
|
||
Formats.StoreVersion("steam", "1.04 (my patch)", detected: false).Should().Be("1.04 (my patch)", "the user's words are theirs");
|
||
Formats.StoreVersion("steam", " ", detected: true).Should().BeNull();
|
||
return 0;
|
||
});
|
||
|
||
[Theory]
|
||
[InlineData("3.7.10.0", "3.7.10.0", true)]
|
||
[InlineData("2,8,0,0", "2.8.0.0", true)]
|
||
[InlineData("3.7.10.0 built by: dlss-release", "3.7.10.0", true)]
|
||
[InlineData("3.7.10", "3.7.10.0", true)]
|
||
[InlineData("310.2.1.0", "3.7.10.0", false)]
|
||
[InlineData(null, "3.7.10.0", null)]
|
||
[InlineData("3.7.10.0", null, null)]
|
||
[InlineData("n/a", "3.7.10.0", null)]
|
||
public void TwoFileVersionsAreTheSameFourNumbers(string? a, string? b, bool? expected) =>
|
||
Formats.SameVersion(a, b).Should().Be(expected);
|
||
|
||
/// <summary>
|
||
/// beta.8 (owner request): two decimals, always, when <c>ui.fps_decimals</c> is on; a whole number otherwise. Half away
|
||
/// from zero both ways — 62.125 is exactly representable, and rounding half to even would say 62.12.
|
||
/// </summary>
|
||
[Fact]
|
||
public void FpsHasTwoDecimalsWhenAskedAndRoundsHalfAwayFromZero() => InEnglish(() =>
|
||
{
|
||
Formats.FpsNumber(62.4, twoDecimals: true).Should().Be("62.40");
|
||
Formats.FpsNumber(62, twoDecimals: true).Should().Be("62.00");
|
||
Formats.FpsNumber(62.125, twoDecimals: true).Should().Be("62.13");
|
||
Formats.FpsNumber(62.5, twoDecimals: false).Should().Be("63");
|
||
Formats.FpsNumber(61.5, twoDecimals: false).Should().Be("62");
|
||
Formats.FpsNumber(62.4, twoDecimals: false).Should().Be("62");
|
||
return 0;
|
||
});
|
||
|
||
[Fact]
|
||
public void EnginesAreNamedAndAnUnknownIdPassesThrough()
|
||
{
|
||
Formats.Engine("re_engine").Should().Be("RE Engine");
|
||
Formats.Engine("fromsoftware").Should().Be("FromSoftware");
|
||
Formats.Engine("rpgmaker_mv").Should().Be("RPG Maker MV/MZ");
|
||
Formats.Engine("unreal").Should().Be("Unreal Engine");
|
||
Formats.Engine("My Own Engine").Should().Be("My Own Engine", "an engine the user typed is shown as typed");
|
||
Formats.Engine(null).Should().BeEmpty();
|
||
}
|
||
|
||
/// <summary>
|
||
/// beta.19: each RPG Maker rule covers several makers, and the file the version was read from names which; the RGSS
|
||
/// number is the runtime library's, and says so.
|
||
/// </summary>
|
||
[Fact]
|
||
public void TheVersionsWitnessNamesTheMakerAndRgssSaysWhoseNumberItIs()
|
||
{
|
||
Formats.Engine("rpgmaker_mv", EngineVersionSource.RpgMakerMzCore).Should().Be("RPG Maker MZ");
|
||
Formats.Engine("rpgmaker_mv", EngineVersionSource.RpgMakerMvCore).Should().Be("RPG Maker MV");
|
||
Formats.Engine("rpgmaker_rgss", EngineVersionSource.Rgss1Library).Should().Be("RPG Maker XP");
|
||
Formats.Engine("rpgmaker_rgss", EngineVersionSource.Rgss2Library).Should().Be("RPG Maker VX");
|
||
Formats.Engine("rpgmaker_rgss", EngineVersionSource.Rgss3Library).Should().Be("RPG Maker VX Ace");
|
||
Formats.Engine("rpgmaker_mv", null).Should().Be("RPG Maker MV/MZ", "no witness, no maker");
|
||
Formats.Engine("unity", EngineVersionSource.RpgMakerMzCore).Should().Be("Unity", "a witness names a maker only for its own rule");
|
||
|
||
Formats.EngineWithVersion("rpgmaker_mv", "1.10.0", EngineVersionSource.RpgMakerMzCore).Should().Be("RPG Maker MZ 1.10.0");
|
||
Formats.EngineWithVersion("rpgmaker_rgss", "3.0.1", EngineVersionSource.Rgss3Library).Should().Be("RPG Maker VX Ace (RGSS 3.0.1)");
|
||
Formats.EngineWithVersion("unity", "2022.3.39f1", EngineVersionSource.UnityPlayer).Should().Be("Unity 2022.3.39f1");
|
||
Formats.EngineWithVersion("godot", "4.4.1", EngineVersionSource.GodotPack).Should().Be("Godot 4.4.1");
|
||
Formats.EngineWithVersion("renpy", "8.5.0", EngineVersionSource.RenPyVcVersion).Should().Be("Ren'Py 8.5.0");
|
||
Formats.EngineWithVersion("unreal", "5.4.4", EngineVersionSource.UnrealFileVersion).Should().Be("Unreal Engine 5.4.4");
|
||
Formats.EngineWithVersion("unity", "6000.0", null).Should().Be("Unity 6000.0", "a version the user typed has no witness");
|
||
Formats.EngineWithVersion("godot", null, null).Should().Be("Godot");
|
||
Formats.EngineWithVersion(null, "1.0", null).Should().BeEmpty();
|
||
}
|
||
|
||
/// <summary>
|
||
/// Every engine the shipped rules can detect has a name here, and it is the rule's own <c>name</c> (2026-09-23): a rule
|
||
/// added without one would show its raw id on every card that engine lands on — which is what every engine did until
|
||
/// this date.
|
||
/// </summary>
|
||
[Fact]
|
||
public void EveryShippedEngineIdIsShownByItsRulesName()
|
||
{
|
||
var dir = new DirectoryInfo(AppContext.BaseDirectory);
|
||
while (dir is not null && !File.Exists(Path.Combine(dir.FullName, "FrameLedger.slnx")))
|
||
{
|
||
dir = dir.Parent;
|
||
}
|
||
|
||
dir.Should().NotBeNull("the check needs the repository's rules file");
|
||
using System.Text.Json.JsonDocument rules = System.Text.Json.JsonDocument.Parse(File.ReadAllText(Path.Combine(dir.FullName, "rules", "detection-rules.json")));
|
||
List<(string Id, string Name)> engines = [.. rules.RootElement.GetProperty("engines").EnumerateArray()
|
||
.Select(static e => (e.GetProperty("id").GetString()!, e.GetProperty("name").GetString()!))];
|
||
|
||
engines.Should().NotBeEmpty();
|
||
engines.Should().AllSatisfy(static e => Formats.Engine(e.Id).Should().Be(e.Name, $"the rule '{e.Id}' names its engine"));
|
||
}
|
||
}
|