Files
frameledger/tests/FrameLedger.Agent.Tests/AgentEndToEndTests.cs
poli0981andClaude Fable 5.2 b6d7a58ee1 feat(advanced): a session shows whether each Streamline feature is supported and loaded, and what the game did with it - two facts from six calls, one sentence for their states, Privacy Policy 2.19 (beta.45 PR-3; D129-D131) (#429)
The Agent and the App read what the six hooks of this release keep.

- InGameAdvancedSampler: sl.feature.support (<feature> · slIsFeatureSupported as NVIDIA's own sl::Result
  name, a refusal included; <feature> · slIsFeatureLoaded on or off) and sl.feature.lifecycle
  (<feature> · slSetFeatureLoaded on, off or both; slAllocateResources and slFreeResources as counts,
  ">= 15" where the four bits stopped; a row slShutdown). A feature with nothing to say has no row.
- AdvancedSources: one member a call (Read / NeverCalled / NotHooked), null in every row written before.
  The page says the six in one sentence, each call by its name under what became of it.
- sl.init.preferences has reach BeforeAttach (D129): the game makes the call once, before FrameLedger is
  inside it. No catalog entry waits for a hook any more.
- Privacy Policy 2.19 (wording approved with the plan): what is read for each feature, and two more
  things never read - what identifies the graphics card a game hands over with its question, and the
  content of a graphics resource. "Four further calls" is ten. The Disclaimer stays 2.15.
- Strings in en, vi, ja. LIMITATIONS, the guide, docs 06/08/18, the accuracy block (three copies),
  CLAUDE.md, the changelog.

No native change, no layout change (5), no schema change (23). The Agent's end-to-end test on the
harness's Streamline target stores both facts and all six calls as Read; the FSR target stores NotHooked.

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

526 lines
29 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// SPDX-License-Identifier: GPL-3.0-only
// Copyright (C) 2026 poli0981 - additional terms under GPLv3 section 7: see NOTICE
using System.Diagnostics;
using System.IO.MemoryMappedFiles;
using FluentAssertions;
using FrameLedger.Application.Advanced;
using FrameLedger.Application.Capture;
using FrameLedger.Application.Consent;
using FrameLedger.Application.Persistence;
using FrameLedger.Application.Settings;
using FrameLedger.Domain.Consent;
using FrameLedger.Domain.Sessions;
using FrameLedger.Infrastructure.Persistence;
using FrameLedger.Infrastructure.Settings;
using FrameLedger.Testing;
namespace FrameLedger.Agent.Tests;
/// <summary>
/// The shipped Agent as a separate process (P2 PR-F): <c>--console capture</c> against our own harness, with a
/// scratch ledger under <c>--data-dir</c>, ends as ONE <c>sessions</c> row — the milestone's technical half,
/// from outside the process.
/// </summary>
/// <remarks>
/// <para>
/// <b>hook-harness is the only thing this suite ever injects into</b>, and
/// <c>TheTargetAndTheConsentRecordAreBothOurOwnHarness</c> asserts that on the suite itself, exactly as the
/// capture host's suite does. The consent record is written through the real store rather than through
/// <c>consent grant</c>, which refuses redirected stdin by design; the test is standing in for a human, so the
/// self-constraint pins WHICH executable it may stand in for.
/// </para>
/// <para>
/// <b>The scratch ledger is this test's, never the profile's.</b> <c>--data-dir</c> is the whole reason decision
/// D6 exists; every Agent this class starts is given one, and the directory is deleted with the test.
/// </para>
/// </remarks>
// ONE COLLECTION FOR EVERY CLASS THAT STARTS hook-harness, so they never run at the same time. xUnit
// parallelises across classes but never within a collection, and two harnesses of the same image are exactly
// the ambiguity TargetResolver refuses on ("2 processes share the image and none can be singled out") —
// measured 2026-09-10, when this class and its sibling first ran concurrently. Refusing was correct; the
// suites were wrong to be concurrent.
[Trait("Category", "Integration")]
[Collection("agent-harness")]
public sealed class AgentEndToEndTests : IDisposable
{
private static string Harness => Path.Combine(AppContext.BaseDirectory, "hook-harness.exe");
private static string Agent => Path.Combine(AppContext.BaseDirectory, "FrameLedger.Agent.exe");
private readonly string _dataDir = Path.Combine(Path.GetTempPath(), "fl-agent-e2e-" + Guid.NewGuid().ToString("N"));
/// <summary>
/// The ONE executable this suite may write a consent record for: our harness, copied under a run-unique name
/// (beta.16). The Agent resolves its target BY NAME (<c>TargetResolver</c>), and <c>build.ps1</c> runs the test projects as
/// parallel processes: a <c>hook-harness.exe</c> another project was still starting - its module list a partial copy -
/// is an unreadable process of the same name, which the resolver must count, and it refused <c>TargetAmbiguous</c>
/// (#269's first CI run). No other test starts a process of this name.
/// </summary>
private string ConsentedExecutable => Path.Combine(_dataDir, "hook-harness-" + Path.GetFileName(_dataDir) + ".exe");
private string Ledger => Path.Combine(_dataDir, LedgerPaths.DatabaseFileName);
public void Dispose()
{
try
{
Directory.Delete(_dataDir, recursive: true);
}
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException)
{
}
}
[Fact]
public void TheTargetAndTheConsentRecordAreBothOurOwnHarness()
{
StageTarget();
Path.GetFileName(Harness).Should().Be("hook-harness.exe");
Path.GetDirectoryName(Harness).Should().Be(AppContext.BaseDirectory.TrimEnd(Path.DirectorySeparatorChar));
Path.GetFileName(ConsentedExecutable).Should().StartWith("hook-harness-");
Path.GetDirectoryName(ConsentedExecutable).Should().Be(_dataDir, "the copy lives in this run's scratch directory and nowhere else");
File.ReadAllBytes(ConsentedExecutable).Should().Equal(File.ReadAllBytes(Harness), "the target IS hook-harness, byte for byte, under another name");
Path.GetFileName(Agent).Should().Be("FrameLedger.Agent.exe");
}
/// <summary>This run's copy of hook-harness, once per test; its overlay logs are this assembly's to remove (<c>17_HOOK_ENGINE</c> §Native logging).</summary>
private void StageTarget()
{
if (File.Exists(ConsentedExecutable))
{
return;
}
File.Exists(Harness).Should().BeTrue(
"hook-harness.exe must be staged beside the test binary (FrameLedger.DrainFixtures.targets). "
+ "This FAILS rather than skipping: an integration test that quietly does nothing when its fixture "
+ "is absent is a gate that cannot fail.");
Directory.CreateDirectory(_dataDir);
HarnessOverlayLogSweep.Own(_dataDir);
File.Copy(Harness, ConsentedExecutable);
}
private async Task<ConsentWriteOutcome> GrantConsentAsync()
{
StageTarget();
ExecutableFingerprint fingerprint = Infrastructure.Io.ExecutableIdentity.Read(ConsentedExecutable)!.Value;
Directory.CreateDirectory(_dataDir);
LedgerDatabase db = await LedgerDatabase.OpenAsync(Ledger, ct: TestContext.Current.CancellationToken).ConfigureAwait(false);
await using (db.ConfigureAwait(false))
{
return await new SqliteGameConsentStore(db).RecordOperatorAcknowledgementAsync(new OperatorAcknowledgement
{
Fingerprint = fingerprint,
DisclosureVersion = OperatorDisclosure.AgentConsoleVersion,
AcknowledgedAt = DateTimeOffset.UtcNow,
Provenance = ConsentProvenance.AgentConsoleOperator,
}, TestContext.Current.CancellationToken).ConfigureAwait(false);
}
}
private async Task SetAdvancedMetricsAsync(bool on)
{
Directory.CreateDirectory(_dataDir);
LedgerDatabase db = await LedgerDatabase.OpenAsync(Ledger, ct: TestContext.Current.CancellationToken).ConfigureAwait(false);
await using (db.ConfigureAwait(false))
{
await new RegisteredSettings(new SqliteSettingsStore(db)).SetAsync(SettingsRegistry.TelemetryAdvanced, on, TestContext.Current.CancellationToken).ConfigureAwait(false);
}
}
private async Task SetKillSwitchAsync(bool engaged)
{
Directory.CreateDirectory(_dataDir);
LedgerDatabase db = await LedgerDatabase.OpenAsync(Ledger, ct: TestContext.Current.CancellationToken).ConfigureAwait(false);
await using (db.ConfigureAwait(false))
{
await new SettingsKillSwitch(new SqliteSettingsStore(db)).SetAsync(engaged, TestContext.Current.CancellationToken).ConfigureAwait(false);
}
}
private async Task<Process> StartHarnessAsync(string arguments)
{
StageTarget();
File.Exists(Agent).Should().BeTrue("the Agent must be built and copied beside this test");
var p = Process.Start(new ProcessStartInfo(ConsentedExecutable, arguments) { UseShellExecute = false, CreateNoWindow = true, RedirectStandardOutput = true })!;
bool presenting = await HarnessReady.WaitUntilPresentingAsync(p, TestContext.Current.CancellationToken).ConfigureAwait(false);
if (!presenting && !p.HasExited)
{
p.Kill(entireProcessTree: true);
}
presenting.Should().BeTrue("the harness must reach its present loop before anything looks for it or is injected into it (HarnessReady)");
p.HasExited.Should().BeFalse("the harness must be running before the Agent looks for it");
return p;
}
private Process StartAgent(params string[] consoleArgs)
{
var psi = new ProcessStartInfo(Agent) { UseShellExecute = false, CreateNoWindow = true, RedirectStandardOutput = true, RedirectStandardError = true };
psi.ArgumentList.Add("--console");
psi.ArgumentList.Add("--data-dir");
psi.ArgumentList.Add(_dataDir);
foreach (string a in consoleArgs)
{
psi.ArgumentList.Add(a);
}
return Process.Start(psi)!;
}
private static async Task<(string Stdout, int Exit)> FinishAsync(Process p)
{
Task<string> err = p.StandardError.ReadToEndAsync(TestContext.Current.CancellationToken);
string stdout = await p.StandardOutput.ReadToEndAsync(TestContext.Current.CancellationToken).ConfigureAwait(false);
await p.WaitForExitAsync(TestContext.Current.CancellationToken).ConfigureAwait(false);
return (stdout + "\n---- stderr ----\n" + await err.ConfigureAwait(false) + $"\n---- exit {p.ExitCode} ----\n", p.ExitCode);
}
private static void Kill(Process p)
{
try
{
if (!p.HasExited)
{
p.Kill(entireProcessTree: true);
}
}
catch (InvalidOperationException)
{
}
p.Dispose();
}
[Fact]
public async Task AConsentedBoundedCaptureLandsAsOneHookedRowInTheScratchLedger()
{
// THE MILESTONE'S TECHNICAL HALF, from outside the process: the shipped Agent, our harness, one row.
(await GrantConsentAsync()).Should().Be(ConsentWriteOutcome.Written);
Process harness = await StartHarnessAsync("--real --hold-presenting 40");
try
{
using Process agent = StartAgent("capture", "--exe", ConsentedExecutable, "--seconds", "8");
(string output, int exit) = await FinishAsync(agent);
exit.Should().Be(0, output);
output.Should().Contain("ledger: session ").And.Contain("SAVED as sessions.id=", output);
output.Should().Contain("telemetry=l1", output);
LedgerDatabase db = await LedgerDatabase.OpenAsync(Ledger, ct: TestContext.Current.CancellationToken).ConfigureAwait(true);
await using (db.ConfigureAwait(true))
{
var sessions = new SqliteSessionRepository(db);
SessionRow row = (await sessions.ListRecentAsync(1, TestContext.Current.CancellationToken).ConfigureAwait(true)).Should().ContainSingle().Subject;
row.Tier.Should().Be(CaptureTier.Hooked);
row.Mode.Should().Be(CaptureMode.Attach);
row.ExitStatus.Should().Be(ExitStatus.Normal, "the harness was still presenting when the bounded capture ended");
row.FrameCount.Should().BeGreaterThan(100, "8 s at ~120/s");
row.Api.Should().Be("d3d11");
row.GuardTicksPublished.Should().BeGreaterThanOrEqualTo(1);
row.OverlayBuildId.Should().NotBeNullOrEmpty();
row.TelemetrySource.Should().Contain("l1", "the Agent composes L1 + L2 + L3 for every session");
FrameBlobs? frames = await sessions.FindFramesAsync(row.Id, TestContext.Current.CancellationToken).ConfigureAwait(true);
frames.Should().NotBeNull();
frames.SampleCount.Should().Be(row.FrameCount);
}
Directory.EnumerateFiles(Path.Combine(_dataDir, "tmp"), "*.partial").Should().BeEmpty("finalize deletes the .partial");
}
finally
{
Kill(harness);
}
}
[Fact]
public async Task WhatTheGameTellsFsrIsStoredOnlyByASessionThatRecordsAdvancedMetrics()
{
// ADVANCED METRICS INSIDE THE GAME, end to end (train B, 0.1.0-beta.40): the shipped Agent, the real Overlay,
// and a target that hands FSR everything on every frame and asks it for its memory. ONE target, TWO sessions,
// which is the order that matters: the first does not record Advanced metrics and must store nothing of it
// though the game says it all; the second asks - in a game that kept running - and stores what the game said.
(await GrantConsentAsync()).Should().Be(ConsentWriteOutcome.Written);
Process harness = await StartHarnessAsync("--real --ffx-topology 2x --advanced --ffx-memory-query v2 --hold-presenting-ffx 90");
try
{
using (Process off = StartAgent("capture", "--exe", ConsentedExecutable, "--seconds", "6"))
{
(string output, int exit) = await FinishAsync(off);
exit.Should().Be(0, output);
}
await SetAdvancedMetricsAsync(on: true);
using (Process on = StartAgent("capture", "--exe", ConsentedExecutable, "--seconds", "10"))
{
(string output, int exit) = await FinishAsync(on);
exit.Should().Be(0, output);
}
LedgerDatabase db = await LedgerDatabase.OpenAsync(Ledger, ct: TestContext.Current.CancellationToken).ConfigureAwait(true);
await using (db.ConfigureAwait(true))
{
var sessions = new SqliteSessionRepository(db);
IReadOnlyList<SessionRow> rows = await sessions.ListRecentAsync(2, TestContext.Current.CancellationToken).ConfigureAwait(true);
rows.Should().HaveCount(2);
SessionRow second = rows[0];
SessionRow first = rows[1];
first.Tier.Should().Be(CaptureTier.Hooked);
second.Tier.Should().Be(CaptureTier.Hooked);
// OFF: no row, and no series under the advanced prefix - the game said it all, and none of it was kept.
(await sessions.FindAdvancedAsync(first.Id, TestContext.Current.CancellationToken).ConfigureAwait(true)).Should().BeNull();
(await sessions.FindAdvancedSensorsAsync(first.Id, TestContext.Current.CancellationToken).ConfigureAwait(true))
.Should().NotContain(static b => b.Series.StartsWith(AdvancedMetric.SeriesPrefix, StringComparison.Ordinal));
// ON: the values hook-harness --advanced sends (main.cpp, kAdv*), as fl_guard asserts them natively.
AdvancedSessionRow row = (await sessions.FindAdvancedAsync(second.Id, TestContext.Current.CancellationToken).ConfigureAwait(true)).Should().BeOfType<AdvancedSessionRow>().Subject;
AssertWhatTheHarnessToldFsr(row);
(await sessions.FindAdvancedSensorsAsync(second.Id, TestContext.Current.CancellationToken).ConfigureAwait(true))
.Select(static b => b.Series).Should().Contain([InGameAdvancedSampler.FrameTimeSeries, InGameAdvancedSampler.MemorySeries]);
}
}
finally
{
Kill(harness);
}
}
[Fact]
public async Task WhatTheGameTellsStreamlineAndIsAnsweredAboutAFeatureIsStoredByASessionThatRecordsAdvancedMetrics()
{
// The Streamline side of the same road, end to end (0.1.0-beta.44; until then no Agent test ran a Streamline
// target): the shipped Agent, the real Overlay, and a target that chains its DLSS options into every
// evaluation, calls slSetConstants every frame and asks the stub interposer about a feature every sixteenth -
// which is what lets a session that attached after the game's start still see an answer. Three calls hooked
// only because this session asked.
(await GrantConsentAsync()).Should().Be(ConsentWriteOutcome.Written);
Process harness = await StartHarnessAsync("--real --advanced --hold-presenting-upscaled 90");
try
{
await SetAdvancedMetricsAsync(on: true);
using (Process on = StartAgent("capture", "--exe", ConsentedExecutable, "--seconds", "10"))
{
(string output, int exit) = await FinishAsync(on);
exit.Should().Be(0, output);
}
LedgerDatabase db = await LedgerDatabase.OpenAsync(Ledger, ct: TestContext.Current.CancellationToken).ConfigureAwait(true);
await using (db.ConfigureAwait(true))
{
var sessions = new SqliteSessionRepository(db);
SessionRow session = (await sessions.ListRecentAsync(1, TestContext.Current.CancellationToken).ConfigureAwait(true)).Should().ContainSingle().Subject;
session.Tier.Should().Be(CaptureTier.Hooked);
AdvancedSessionRow row = (await sessions.FindAdvancedAsync(session.Id, TestContext.Current.CancellationToken).ConfigureAwait(true)).Should().BeOfType<AdvancedSessionRow>().Subject;
AssertWhatTheHarnessToldStreamline(row);
}
}
finally
{
Kill(harness);
}
}
/// <summary>The stored row of a session that asked, against what <c>hook-harness --advanced</c> tells Streamline and the stub interposer answers.</summary>
private static void AssertWhatTheHarnessToldStreamline(AdvancedSessionRow row)
{
(IReadOnlyList<AdvancedFact> facts, AdvancedSources sources) = AdvancedJson.ParseSession(row.FactsJson);
string[] Rows(string id) => [.. facts.Single(f => string.Equals(f.Id, id, StringComparison.Ordinal)).Value.Rows!.Select(static r => r.Name + "=" + r.Value)];
// What the harness tells slSetConstants for its first viewport (main.cpp, kAdvSl*).
Rows("sl.constants.jitter").Should().Equal("jitterOffset.x=≤ 0.3125", "jitterOffset.y=≤ 0.4375");
Rows("sl.constants.depth").Should().Equal("cameraNear=0.25", "cameraFar=4000", "depthInverted=on");
Rows("sl.constants.projection").Should().Equal("cameraFOV=0.8 – 1.2 rad (45.8° – 68.8°)", "cameraAspectRatio=1.75", "orthographicProjection=off");
// What the stub interposer answers about the two features it knows (stub_sl_interposer.cpp), and
// nothing of the one it refuses or of the one asked about with a struct that is not the headers'.
Rows("sl.feature.versions").Should().Equal(
"kFeatureDLSS · versionSL=2.14.1",
"kFeatureDLSS · versionNGX=310.4.0",
"kFeatureDLSS_G · versionSL=2.14.1",
"kFeatureDLSS_G · versionNGX=310.4.1");
Rows("sl.feature.requirements").Should().Equal(
"kFeatureDLSS · flags=eD3D11Supported, eD3D12Supported, eVulkanSupported",
"kFeatureDLSS · maxNumCPUThreads=2",
"kFeatureDLSS · maxNumViewports=32",
"kFeatureDLSS · numRequiredTags=3",
"kFeatureDLSS · osVersionDetected=10.0.26100",
"kFeatureDLSS · osVersionRequired=10.0.19041",
"kFeatureDLSS · driverVersionDetected=591.44.0",
"kFeatureDLSS · driverVersionRequired=512.15.0",
"kFeatureDLSS_G · flags=eD3D12Supported, eVSyncOffRequired, eHardwareSchedulingRequired",
"kFeatureDLSS_G · maxNumCPUThreads=1",
"kFeatureDLSS_G · maxNumViewports=1",
"kFeatureDLSS_G · numRequiredTags=4",
"kFeatureDLSS_G · osVersionDetected=10.0.26100",
"kFeatureDLSS_G · osVersionRequired=10.0.19041",
"kFeatureDLSS_G · driverVersionDetected=591.44.0",
"kFeatureDLSS_G · driverVersionRequired=551.23.0");
sources.InGame.Should().Be(AdvancedInGameStatus.Reading, row.FactsJson);
sources.StreamlineConstants.Should().Be(AdvancedInGameCall.Read, row.FactsJson);
sources.StreamlineFeatureVersion.Should().Be(AdvancedInGameCall.Read, row.FactsJson);
sources.StreamlineFeatureRequirements.Should().Be(AdvancedInGameCall.Read, row.FactsJson);
sources.FsrFrameGeneration.Should().Be(AdvancedInGameCall.NotHooked, "this target loads no FidelityFX library: " + row.FactsJson);
AssertWhatTheHarnessDidWithStreamlinesFeatures(row);
}
/// <summary>
/// 0.1.0-beta.45: whether each feature is supported and loaded, as the stub says - a refusal is the answer and is
/// named - and what the harness does with two of them every sixteenth frame. The counts depend on how long the
/// session ran; that they are there, and for the right feature, does not.
/// </summary>
private static void AssertWhatTheHarnessDidWithStreamlinesFeatures(AdvancedSessionRow row)
{
(IReadOnlyList<AdvancedFact> facts, AdvancedSources sources) = AdvancedJson.ParseSession(row.FactsJson);
string[] Rows(string id) => [.. facts.Single(f => string.Equals(f.Id, id, StringComparison.Ordinal)).Value.Rows!.Select(static r => r.Name + "=" + r.Value)];
Rows("sl.feature.support").Should().Equal(
"kFeatureDLSS · slIsFeatureSupported=eOk",
"kFeatureDLSS · slIsFeatureLoaded=on",
"kFeatureDLSS_G · slIsFeatureSupported=eOk",
"kFeatureNIS · slIsFeatureSupported=eErrorFeatureNotSupported",
"kFeatureReflex · slIsFeatureSupported=eErrorFeatureMissing",
"kFeaturePCL · slIsFeatureLoaded=off");
string[] lifecycle = Rows("sl.feature.lifecycle");
lifecycle.Should().Contain("kFeatureDLSS · slSetFeatureLoaded=on").And.Contain("kFeatureDLSS_G · slSetFeatureLoaded=on_and_off");
lifecycle.Should().Contain(static r => r.StartsWith("kFeatureDLSS · slAllocateResources=", StringComparison.Ordinal))
.And.Contain(static r => r.StartsWith("kFeatureDLSS_G · slFreeResources=", StringComparison.Ordinal))
.And.Contain(static r => r.StartsWith("slShutdown=", StringComparison.Ordinal))
.And.NotContain(static r => r.StartsWith("kFeatureDLSS_G · slAllocateResources=", StringComparison.Ordinal));
sources.StreamlineFeatureSupported.Should().Be(AdvancedInGameCall.Read, row.FactsJson);
sources.StreamlineFeatureLoaded.Should().Be(AdvancedInGameCall.Read, row.FactsJson);
sources.StreamlineSetFeatureLoaded.Should().Be(AdvancedInGameCall.Read, row.FactsJson);
sources.StreamlineAllocateResources.Should().Be(AdvancedInGameCall.Read, row.FactsJson);
sources.StreamlineFreeResources.Should().Be(AdvancedInGameCall.Read, row.FactsJson);
sources.StreamlineShutdown.Should().Be(AdvancedInGameCall.Read, row.FactsJson);
}
/// <summary>The stored row of a session that asked, against what <c>hook-harness --advanced --ffx-memory-query</c> sends and the FSR stub answers.</summary>
private static void AssertWhatTheHarnessToldFsr(AdvancedSessionRow row)
{
(IReadOnlyList<AdvancedFact> facts, AdvancedSources sources) = AdvancedJson.ParseSession(row.FactsJson);
sources.InGame.Should().Be(AdvancedInGameStatus.Reading, row.FactsJson);
string[] Rows(string id) => [.. facts.Single(f => string.Equals(f.Id, id, StringComparison.Ordinal)).Value.Rows!.Select(static r => r.Name + "=" + r.Value)];
Rows("ffx.upscale.sharpening").Should().Equal("enableSharpening=on", "sharpness=0.35");
Rows("ffx.upscale.jitter").Should().Equal("jitterOffset.x=≤ 0.3", "jitterOffset.y=≤ 0.4");
Rows("ffx.upscale.depth").Should().Equal("cameraNear=0.1", "cameraFar=1000", "cameraFovAngleVertical=0.9 – 1.1 rad (51.6° – 63°)");
facts.Single(static f => string.Equals(f.Id, "ffx.upscale.exposure", StringComparison.Ordinal)).Value.Text.Should().Be("1.25");
facts.Single(static f => string.Equals(f.Id, "ffx.upscale.flags", StringComparison.Ordinal)).Value.Tokens.Should().Equal("non_linear_color_pq");
facts.Should().NotContain(static f => f.Id.StartsWith("sl.", StringComparison.Ordinal), "this target chains no DLSS options");
// 0.1.0-beta.43: the frame-generation configuration the harness sends through ffxConfigure before each frame
// (kAdvFfxFg*), read by a hook that was not in the game during the first session - nothing had asked - and
// was installed when this one did. Streamline's library is not in this target at all, and the row says that
// rather than "the game never called".
Rows("ffx.framegen.config").Should().Equal(
"frameGenerationEnabled=on",
"allowAsyncWorkloads=off",
"onlyPresentGenerated=off",
"flags=DRAW_DEBUG_PACING_LINES",
"generationRect=1920 × 1080 at 0, 0");
sources.FsrFrameGeneration.Should().Be(AdvancedInGameCall.Read, row.FactsJson);
sources.StreamlineConstants.Should().Be(AdvancedInGameCall.NotHooked, row.FactsJson);
sources.StreamlineFeatureVersion.Should().Be(AdvancedInGameCall.NotHooked, row.FactsJson);
sources.StreamlineFeatureRequirements.Should().Be(AdvancedInGameCall.NotHooked, row.FactsJson);
sources.StreamlineFeatureSupported.Should().Be(AdvancedInGameCall.NotHooked, row.FactsJson);
sources.StreamlineShutdown.Should().Be(AdvancedInGameCall.NotHooked, row.FactsJson);
IReadOnlyDictionary<string, Application.Recording.SensorSeriesStats> stats = AdvancedJson.ParseStats(row.StatsJson);
stats.Should().ContainKey(InGameAdvancedSampler.FrameTimeSeries, row.StatsJson);
stats[InGameAdvancedSampler.FrameTimeSeries].Mean.Should().BeApproximately(16.0, 0.01, "every dispatch states 16 ms");
stats.Should().ContainKey(InGameAdvancedSampler.MemorySeries, row.StatsJson);
stats[InGameAdvancedSampler.MemorySeries].Max.Should().BeApproximately(123456789 / (1024.0 * 1024.0), 0.01, "what the FSR stub answers the memory query with");
}
[Fact]
public async Task WithTheKillSwitchOnAConsentedGameIsRefusedAndNothingIsEverInjected()
{
// FR-2.4 from outside the process (decision D7): consent is present and enabled, the switch is on, the
// gate refuses with its own reason, and no ring ever exists in the target.
(await GrantConsentAsync()).Should().Be(ConsentWriteOutcome.Written);
await SetKillSwitchAsync(engaged: true);
Process harness = await StartHarnessAsync("--real --hold-presenting 20");
try
{
using Process agent = StartAgent("capture", "--exe", ConsentedExecutable, "--seconds", "3");
(string output, int exit) = await FinishAsync(agent);
output.Should().Contain(nameof(SessionEndReason.RefusedKillSwitch), output);
exit.Should().NotBe(0, output);
harness.HasExited.Should().BeFalse();
Action open = () => MemoryMappedFile.OpenExisting($@"Local\FrameLedger.Ring.{harness.Id}", MemoryMappedFileRights.Read).Dispose();
open.Should().Throw<FileNotFoundException>("no ring means no Overlay means no injection");
}
finally
{
Kill(harness);
}
}
/// <summary>
/// beta.16: the collision #269's first CI run hit. Another hook-harness.exe running beside this suite's run - another
/// test project's, or one left over - shares neither the copy's name nor its path, so the Agent's resolver never counts
/// it. Until beta.16 this suite consented to the staged hook-harness.exe itself, and a second one was a second match:
/// TargetAmbiguous, exit 6.
/// </summary>
[Fact]
public async Task AnotherHookHarnessRunningBesideTheSuiteDoesNotMakeTheTargetAmbiguous()
{
(await GrantConsentAsync()).Should().Be(ConsentWriteOutcome.Written);
Process stranger = Process.Start(new ProcessStartInfo(Harness, "--real --hold-presenting 30") { UseShellExecute = false, CreateNoWindow = true, RedirectStandardOutput = true })!;
Process harness = await StartHarnessAsync("--real --hold-presenting 30");
try
{
using Process agent = StartAgent("capture", "--exe", ConsentedExecutable, "--seconds", "3");
(string output, int exit) = await FinishAsync(agent);
exit.Should().Be(0, output);
output.Should().Contain("SAVED as sessions.id=", output);
output.Should().NotContain("TargetAmbiguous", output);
}
finally
{
Kill(harness);
Kill(stranger);
}
}
[Fact]
public async Task ConsentGrantRefusesRedirectedStdinAndWritesNothing()
{
StageTarget();
using Process agent = StartAgent("consent", "grant", "--exe", ConsentedExecutable);
(string output, int exit) = await FinishAsync(agent);
exit.Should().Be(2, output);
output.Should().Contain("stdin is redirected", output);
output.Should().Contain("OPERATOR SURFACE", "the Agent's disclosure names its own surface first");
using Process list = StartAgent("consent", "list");
(string listed, int listExit) = await FinishAsync(list);
listExit.Should().Be(0, listed);
listed.Should().Contain("nothing is enabled", listed);
}
[Fact]
public async Task TheAppsDiagFlagAnswersNotThisBinarysWithExitTwo()
{
// The four maintenance flags are real since P3 PR-8b and run against the PRODUCT directory (a registration,
// a scheduled task), so an end-to-end test never invokes them; --diag is the App's and still exits 2 here.
var psi = new ProcessStartInfo(Agent) { UseShellExecute = false, CreateNoWindow = true, RedirectStandardOutput = true, RedirectStandardError = true };
psi.ArgumentList.Add("--diag");
using Process agent = Process.Start(psi)!;
(string output, int exit) = await FinishAsync(agent);
exit.Should().Be(2, output);
output.Should().Contain("not this binary", output);
}
}