Files
frameledger/tests/FrameLedger.Infrastructure.Tests/Detection/GameFileProbeRootFilesTests.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

61 lines
2.7 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.Domain.Detection;
using FrameLedger.Infrastructure.Detection;
using FrameLedger.Infrastructure.Import;
namespace FrameLedger.Infrastructure.Tests.Detection;
/// <summary>
/// beta.33: what a <c>root_file</c> signal is answered from — the install root's own listing, files only, taken once —
/// and a root that cannot be listed is no listing at all, never an empty one (an empty one would read every
/// <c>root_file</c> as a miss).
/// </summary>
public sealed class GameFileProbeRootFilesTests : IDisposable
{
private static readonly DetectionRuleSet _rules = new()
{
SchemaVersion = 2,
RulesVersion = "t",
Engines = [],
Platforms = [],
Capabilities = [],
};
private readonly string _root = Path.Combine(Path.GetTempPath(), "fl-rootfiles-" + Guid.NewGuid().ToString("N"));
public GameFileProbeRootFilesTests() => Directory.CreateDirectory(_root);
public void Dispose() => Directory.Delete(_root, recursive: true);
private static CancellationToken Ct => TestContext.Current.CancellationToken;
[Fact]
public async Task ThePackageRootsOwnFilesAreListedAndNothingBelowIt()
{
string content = Path.Combine(_root, "Valor Mortis", "Content");
string binaries = Path.Combine(content, "ValorMortis", "Binaries", "Win64");
Directory.CreateDirectory(binaries);
await File.WriteAllTextAsync(Path.Combine(content, GdkPackageFiles.ConfigFileName), "<Game />", Ct);
await File.WriteAllTextAsync(Path.Combine(content, GdkPackageFiles.ManifestFileName), "<Package />", Ct);
string exe = Path.Combine(binaries, "ValorMortisMSG-Win64-Shipping.exe");
await File.WriteAllBytesAsync(exe, [0x4D, 0x5A], Ct);
GameFileSnapshot snapshot = await new GameFileProbe().SnapshotAsync(exe, _rules, Ct);
snapshot.GameDirectory.Should().Be(content.Replace('\\', '/'), "a GDK package root is the install root of an executable three levels down");
snapshot.RootFiles.Should().BeEquivalentTo([GdkPackageFiles.ConfigFileName, GdkPackageFiles.ManifestFileName]);
snapshot.RootFiles!.Contains("MICROSOFTGAME.CONFIG").Should().BeTrue("a file name is matched as NTFS matches it");
}
[Fact]
public async Task ARootThatCannotBeListedIsNoListing()
{
GameFileSnapshot snapshot = await new GameFileProbe().SnapshotAsync(Path.Combine(_root, "gone", "game.exe"), _rules, Ct);
snapshot.RootFiles.Should().BeNull("a folder that is not there answers Unknown, never \"no such file\"");
}
}