Files
poli0981andClaude Fable 5.2 42fb21bb18 feat(telemetry): the NVAPI bridge's ABI 3 - the reads "Advanced metrics" needs, measured on an RTX 5080, mapped to the catalog; and "never a setter" as a build gate (Advanced PR-2, D101/D104/D108) (#388)
FrameLedger.NvapiBridge.dll - loaded by the Agent into its own process,
never into a game - gains five reads. Nothing composes them yet: no Agent
code calls the reader, so no behaviour changes.

- Native (fl_nvapi_bridge.h/.cpp, ABI 3, additive): FlNvReadFacts (the
  card's type, bus, PCI ids, VBIOS, architecture, core counts, base and
  boost clocks, memory sizes, the driver's package, the chipset),
  FlNvReadLive (free video memory with evictions and promotions, the
  frame-buffer / video / bus utilisation, video clock, P-state, board and
  power-supply temperatures, the throttle word, encoder statistics),
  FlNvReadDisplays (HDR formats and luminances, variable refresh,
  adaptive sync per connected display), FlNvSessionDisplay (one display's
  variable-refresh state and one process's colour space) and
  FlNvProfileSettings (every setting of the global profile, or what a
  game's own profile sets). Each struct carries its size and a present
  mask; a clear bit is N/A, never 0. No ABI 2 struct changed size, and
  FL_NV_FIELD_VRAM stays clear, so which layer fills vram_adapter does
  not change.
- No identifier has an entry point (D104): no board serial, unique id,
  EDID, or list of encoding programs. A display is passed on by its place
  in the list, never by NVAPI's handle.
- tools/nvapi-readonly-check.ps1 (D108), wired into build.ps1: every
  NvAPI_* call of the bridge's source is on tools/nvapi-allowed-calls.txt
  and every name there is called - forty-four - and a name that sets,
  saves, restores, registers or controls, or returns an identifier, is red
  even when the list names it. Seventeen self-test cases, both directions;
  the self-test caught two holes in the rule as first written.
- Managed: mirrors of the five structs, INvapiAdvancedBridge (a port of
  its own; a DLL that predates ABI 3 answers Unavailable, never throws),
  NvapiAdvancedReader (the structs become the catalog's facts and
  readings - every nvapi. entry of the Agent's reach and no other, held
  in both directions) and Application.Advanced's value model: a fact is a
  number, the vendor's words, our own tokens the App will translate, or
  rows; one that was not read is absent.
- Measured the day it was written (ctest fl_nvapi_bridge, AVAILABLE
  branch, RTX 5080): all twenty facts answer; eight of ten live groups -
  the card has no board or power-supply temperature sensor; the display
  answers its four groups; the global profile lists 24 settings.
  20_OPEN_QUESTIONS M12 is half answered, with what is still open.
- The vendored nvapi.h misspells NV_ENCODER_STATISTICS_VER; the bridge
  names NV_ENCODER_STATISTICS_VER1.
- Fixed from #387: Qodana's one result, a redundant "!" in
  AdvancedMetricCatalogTests.
- docs: 18_GPU_VENDOR_APIS (ABI 3, the gate), 12_BUILD (gate 14e),
  CLAUDE.md, CHANGELOG.

Hook overhead: not applicable - nothing in code loaded into a game
changes (Overlay, VkLayer, Shm, Injector untouched).

Gate on the dev box: all passed in 301 s (native 32/32).

Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-11 08:30:54 +00:00

117 lines
4.2 KiB
C#

// SPDX-License-Identifier: GPL-3.0-only
// Copyright (C) 2026 poli0981 - additional terms under GPLv3 section 7: see NOTICE
using FluentAssertions;
using FrameLedger.Application.Advanced;
namespace FrameLedger.Application.Tests.Advanced;
/// <summary>
/// An advanced fact's value has exactly one shape, and no shape means "unknown": a fact that was not read is absent.
/// </summary>
public sealed class AdvancedValueTests
{
[Fact]
public void ANumberIsANumberAndNothingElse()
{
AdvancedValue v = AdvancedValue.Of(84);
v.Number.Should().Be(84);
v.Text.Should().BeNull();
v.Tokens.Should().BeNull();
v.Rows.Should().BeNull();
}
[Theory]
[InlineData(double.NaN)]
[InlineData(double.PositiveInfinity)]
[InlineData(double.NegativeInfinity)]
public void ANumberThatIsNotOneIsRefused(double value)
=> FluentActions.Invoking(() => AdvancedValue.Of(value)).Should().Throw<ArgumentOutOfRangeException>("a fact that was not read is absent, not NaN");
[Fact]
public void AFlagIsOneOrZero()
{
AdvancedValue.Of(true).Number.Should().Be(1);
AdvancedValue.Of(false).Number.Should().Be(0, "a flag that is off was read, and is not an absence");
}
[Fact]
public void TheVendorsWordsAreKeptAsTheyAre()
{
AdvancedValue v = AdvancedValue.OfText("98.03.6c.00.68");
v.Text.Should().Be("98.03.6c.00.68");
v.Number.Should().BeNull();
v.Tokens.Should().BeNull();
FluentActions.Invoking(static () => AdvancedValue.OfText(" ")).Should().Throw<ArgumentException>();
FluentActions.Invoking(static () => AdvancedValue.OfText(null!)).Should().Throw<ArgumentException>();
}
[Fact]
public void OurOwnWordsAreTokensInTheOrderGivenAndMayBeNone()
{
AdvancedValue.OfTokens("hdr10", "dolby_vision").Tokens.Should().Equal("hdr10", "dolby_vision");
AdvancedValue.OfTokens().Tokens.Should().BeEmpty("the source answered, and named nothing");
AdvancedValue.OfTokens("hdr10").Text.Should().BeNull();
}
[Fact]
public void TheTokensAreCopiedSoTheCallersListCannotChangeAStoredValue()
{
var mine = new List<string> { "discrete" };
AdvancedValue v = AdvancedValue.OfTokens(mine);
mine.Add("integrated");
v.Tokens.Should().Equal("discrete");
}
[Theory]
[InlineData("Discrete")]
[InlineData("pci express")]
[InlineData("pci-express")]
[InlineData("1st")]
[InlineData("")]
public void AWordThatIsNotATokenIsRefused(string word)
{
AdvancedValue.IsToken(word).Should().BeFalse();
FluentActions.Invoking(() => AdvancedValue.OfTokens(word)).Should().Throw<ArgumentException>();
}
[Fact]
public void ATokenIsLowerCaseLettersDigitsAndUnderscoresStartingWithALetter()
{
AdvancedValue.IsToken("hdr10_plus_gaming").Should().BeTrue();
AdvancedValue.IsToken("_x").Should().BeFalse();
AdvancedValue.IsToken(null).Should().BeFalse();
FluentActions.Invoking(static () => AdvancedValue.OfTokens(null!)).Should().Throw<ArgumentNullException>();
}
[Fact]
public void ATableIsItsRowsCopiedAndMayBeEmpty()
{
var mine = new List<AdvancedRow> { new("Vertical Sync (0x00A879CF)", "0x60925292", "user_set") };
AdvancedValue v = AdvancedValue.OfRows(mine);
mine.Clear();
v.Rows.Should().Equal(new AdvancedRow("Vertical Sync (0x00A879CF)", "0x60925292", "user_set"));
AdvancedValue.OfRows([]).Rows.Should().BeEmpty("a profile that sets nothing is an answer");
FluentActions.Invoking(static () => AdvancedValue.OfRows(null!)).Should().Throw<ArgumentNullException>();
}
[Fact]
public void AFactAndAReadingCarryWhatTheyWereGiven()
{
var fact = new AdvancedFact("nvapi.display.luminance_max", "2", AdvancedValue.Of(417));
var reading = new AdvancedReading("adv.lhm.board.voltage.lpc_0_7", -11.97);
fact.Id.Should().Be("nvapi.display.luminance_max");
fact.Instance.Should().Be("2");
fact.Value.Number.Should().Be(417);
reading.Series.Should().Be("adv.lhm.board.voltage.lpc_0_7");
reading.Value.Should().Be(-11.97, "a voltage rail is negative, and that is a reading (D102)");
}
}