Files
frameledger/tests/FrameLedger.App.Tests/ReasonTextTests.cs
poli0981andClaude Opus 5.5 042fdd631c feat: Xbox games start through Windows and are recorded once they appear; the guard refuses an app container and a game under code protection by their own reasons; one exe-path reader for the capture path (D78, D80) (beta.33 PR-2) (#352)
* feat: Xbox games start through Windows and are recorded once they appear; the guard refuses an app container and a game under code protection by their own reasons; one exe-path reader for the capture path (D78, D80) (beta.33 PR-2)

Play on a game the Xbox app or the Microsoft Store installed runs
`explorer.exe shell:AppsFolder\<AUMID>` in either Play mode and from an
elevated App: the user's shell activates the package as its Start-menu
tile does. Started by its path a GDK game is never the game in its
package (spike-notes §25), so the agent answers LaunchGame for an
executable whose install root is a GDK package root with `PackagedGame`
and starts nothing; the watcher records the game when it appears.

The guard asks one last question before the primitive, from the target's
own token and mitigation policies: kTargetAppContainer (a UWP app, D78)
and kTargetMitigation (signed-only images, no dynamic code, a strict or
non-CET-blocking user shadow stack, strict CFG). Neither is a finding;
both are Tier 2 with the reason. Each ended before as a failed
injection, a hook that installed nothing, or a risk of ending the game.
"Could not tell" refuses as kProcessUnreadable. Catch2 holds each
refusal through the seam, and two against Windows itself (a child
started under ProhibitDynamicCode + MicrosoftSignedOnly).

TargetResolver re-finds a game by the kernel's image name, as the
watcher keys it (ProcessImagePath), instead of the loader's
(MainModule), still opening candidates with the guard's rights so a
process an anti-cheat driver closes stays TargetUnreadable (D21).

Also: SonarCloud's two findings on PR-1 - the wcslen in
IsGdkPackageRoot (cpp:S5813) and new-code coverage under 80 %.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test: a PC with no games folder names none - the hosted runner has no .GamingRoot, and FluentAssertions' OnlyContain fails an empty list (beta.33 PR-2)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-03 06:14:56 +00:00

157 lines
8.5 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.Application.Capture;
using FrameLedger.Application.Recording;
using FrameLedger.Domain.AntiCheat;
using FrameLedger.Domain.Sessions;
using FrameLedger.Shared.Ipc;
namespace FrameLedger.App.Tests;
/// <summary>
/// Clearer reasons (beta.8, owner item 5): every way a session can end and every refusal no anti-cheat family names has
/// its own words — the enums are walked so none falls through to a raw name — a crash names its exception while End
/// task's exit code is an ordinary end, a launch says why it could not start, and a missing executable says whether its
/// drive or the file is gone.
/// </summary>
[Collection(StringsCultureCollection.Name)]
public sealed class ReasonTextTests
{
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;
}
}
[Fact]
public void EveryEndReasonHasItsOwnSentence()
{
foreach (SessionEndReason reason in Enum.GetValues<SessionEndReason>())
{
Formats.EndReasonText(reason.ToString()).Should().NotBeNullOrWhiteSpace($"{reason} has no words, so a row would print its name");
}
Formats.EndReasonText("SomethingLater").Should().BeNull();
}
/// <summary>Every reason the guard can give without naming an anti-cheat family has a clause of its own.</summary>
[Fact]
public void EveryFamilylessGuardReasonHasItsOwnWords() => InEnglish(() =>
{
foreach (AntiCheatRefusalReason reason in Enum.GetValues<AntiCheatRefusalReason>())
{
// The findings name their family, the two allows are never said as a refusal (D33's names its family too), and
// the kill switch always carries its own label and end reason.
if (reason is AntiCheatRefusalReason.Allow or AntiCheatRefusalReason.AllowedUnderUserModeException
or AntiCheatRefusalReason.BlockedModule or AntiCheatRefusalReason.BlockedDriver
or AntiCheatRefusalReason.BlockedService or AntiCheatRefusalReason.BlockedExecutable or AntiCheatRefusalReason.BlockedStoreId
or AntiCheatRefusalReason.AntiCheatDirectory or AntiCheatRefusalReason.AntiCheatFile or AntiCheatRefusalReason.KillSwitchEngaged)
{
continue;
}
Formats.GuardReasonText(reason.ToString()).Should().NotStartWith("reason ", $"{reason} falls through to its raw name");
}
return 0;
});
[Fact]
public void AFamilylessRefusalIsSaidAsWhatItIsNeverAsDetected() => InEnglish(() =>
{
Formats.Tier2Reason("end=RefusedByGuard; tier2: attach=NotEvaluated; guard=TargetIsWow64||target is a WOW64 process")
.Should().Be("The anti-cheat guard did not hook this game: the game is 32-bit, and the hook runs in 64-bit games only.");
Formats.Tier2Reason("end=RefusedByGuard; tier2: attach=NotEvaluated; guard=ProcessUnreadable/Access is denied")
.Should().Be("The anti-cheat guard did not hook this game: the game's process could not be opened.", "a row from before beta.8 reads the same");
var link = new FakeAgentLink();
using var notices = new SafetyNotices(link, new RecordingStrip());
link.Raise(IpcMessageType.CaptureRefused, new CaptureRefusedEvent(7, "Title", "RefusedByGuard", null, "the folder could not be listed", GuardReason: "PreScanFailed"));
notices.Items.Should().ContainSingle().Which.Body.Should().StartWith("The anti-cheat guard did not hook this game: the game's folder could not be scanned.")
.And.NotContain("detected");
new HookingConsentResult(HookingConsentOutcome.Refused, Refusal: new RefusedAck(7, "ProcessUnreadable", null, "Access is denied")).RefusalText()
.Should().Be("The anti-cheat guard did not hook this game: the game's process could not be opened.");
return 0;
});
/// <summary>beta.33 (D78): a game the Overlay cannot load into at all is said as that — never as a failure the user could fix.</summary>
[Fact]
public void AnAppContainerOrAProtectedGameIsSaidAsWhatItIs() => InEnglish(() =>
{
Formats.Tier2Reason("end=RefusedByGuard; tier2: attach=NotEvaluated; guard=TargetAppContainer||the target's token is an AppContainer's")
.Should().Be("The anti-cheat guard did not hook this game: the game runs in an app container (a Microsoft Store app, not a desktop game), which FrameLedger does not load into.");
Formats.Tier2Reason("end=RefusedByGuard; tier2: attach=NotEvaluated; guard=TargetMitigation||dynamic code policy: dynamic code prohibited")
.Should().Be("The anti-cheat guard did not hook this game: Windows protects the game in a way FrameLedger's component can neither load into nor hook.");
return 0;
});
[Fact]
public void ACrashNamesItsExceptionAndEndTasksCodeIsAnOrdinaryEnd() => InEnglish(() =>
{
Formats.ExitText(ExitStatus.Crashed, CaptureNotes.Parse("end=TargetExited; exit_code=-1073741819")).Should().Be("crashed (0xC0000005 access violation)");
Formats.ExitText(ExitStatus.Crashed, CaptureNotes.Parse("end=TargetExited; exit_code=-1073741818"))
.Should().Contain("0xC0000006 in-page I/O error", "the owner's failing USB drive, 2026-09-21");
Formats.ExitText(ExitStatus.Crashed, CaptureNotes.Parse("end=TargetExited; exit_code=0; crash_event=application_log"))
.Should().Be("crashed (Windows logged an application error)");
// beta.14: Unreal's own crash handling ends with exit code 3 and the crash reporter it started is the witness.
Formats.ExitText(ExitStatus.Crashed, CaptureNotes.Parse("end=TargetExited; exit_code=3; crash_reporter=CrashReportClient.exe"))
.Should().Be("crashed (the game started its crash reporter, CrashReportClient.exe)");
Formats.ExitText(ExitStatus.Normal, CaptureNotes.Parse("end=TargetExited; exit_code=1")).Should().StartWith("ended with exit code 1 — what End task and taskkill leave");
Formats.ExitText(ExitStatus.Normal, CaptureNotes.Parse("end=TargetExited; exit_code=0")).Should().Be("ended normally");
Formats.ExitText(ExitStatus.Normal, CaptureNotes.Parse("end=TargetExited; exit_code=-1")).Should().Be("ended with exit code -1");
Formats.ExitText(ExitStatus.Normal, CaptureNotes.Parse("end=TargetExited; exit_code=-1073741510")).Should().Be("ended with exit code 0xC000013A");
Formats.ExitText(ExitStatus.UnhookedSafety, default).Should().Be(Formats.ExitStatusText(ExitStatus.UnhookedSafety));
return 0;
});
[Fact]
public void ALaunchThatCouldNotStartSaysWhy() => InEnglish(() =>
{
Formats.Tier2Reason("end=LaunchCannotStart; launch_error=740").Should().Be("FrameLedger could not start the game. (the game requires administrator rights)");
Formats.LaunchErrorText(2).Should().Be("the file was not found");
Formats.LaunchErrorText(1392).Should().Be("Windows error 1392");
Formats.Tier2Reason("end=LaunchCannotStart").Should().Be("FrameLedger could not start the game.", "a row from before says what it can");
return 0;
});
[Fact]
public void AMissingExecutableSaysWhetherItsDriveOrTheFileIsGone() => InEnglish(() =>
{
string missingDrive = FreeDriveLetter() + @"Games\Title\game.exe";
Formats.ExecutableMissingText(missingDrive).Should().StartWith("The drive " + missingDrive[..3] + " is not connected.");
string gone = Path.Combine(Path.GetTempPath(), "fl-gone-" + Guid.NewGuid().ToString("N") + ".exe");
Formats.ExecutableMissingText(gone).Should().Be("The game's executable is no longer at " + gone + ".");
return 0;
});
private static string FreeDriveLetter()
{
for (char c = 'Z'; c >= 'D'; c--)
{
string root = c + @":\";
if (!Directory.Exists(root))
{
return root;
}
}
throw new InvalidOperationException("every drive letter is taken");
}
}