Compare commits

...
Author SHA1 Message Date
poli0981andClaude Opus 5.5 6e0b46c867 test(infrastructure): a game folder Windows will not list is never gone (beta.19 PR-7)
The presence probe (#295, D55) decides whether an entry's executable is
gone — FileGone, the one answer that lets the Agent remove the entry — or
merely unreadable. File.Exists and Directory.Exists say false for what
they may not look at, so the probe asks listings: the file in its folder's,
a folder that reads as missing in its parent's, and a listing it is refused
is Unknown. The review of #295 found those two branches untested.

ExecutablePresenceProbeTests now denies the current user rights on real
folders and gives them back in a finally (the owner can always change the
access list):

- ListDirectory denied on the game folder: the executable there and a
  Gone.exe there are both Unknown, and Present again once it lists;
- ListDirectory + ReadAttributes denied on the game folder and
  ListDirectory on the library folder it is in: Directory.Exists says false
  for the game folder, and the probe still says Unknown.

Each skips (Assert.SkipUnless) when the process can list what it is denied
— a backup privilege enabled — rather than asserting something else.

Measured red on this machine: with the folder listing replaced by
File.Exists the first test fails (Present for a folder that will not list);
with the parent-listing check dropped the second fails with FileGone, the
answer that would have removed an installed game. Both restored.

FR-1.8 (02_SPEC) names the case.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-12 16:50:07 +07:00
2 changed files with 91 additions and 2 deletions

No files matched your search

+1 -1
View File
@@ -11,7 +11,7 @@ Requirement IDs (`FR-x`, `NFR-x`) are referenced by other docs, commits, and tes
- FR-1.4 Remove game (asks whether to keep or delete its sessions).
- FR-1.5 "Supports" row shows shipped-capability hints (DLSS/FSR/XeSS/FG) — visually distinct from measured per-session values (`05_DETECTION` §Capability hints).
- FR-1.7 Delete all sessions (beta.11, owner decision D40): of one game from its page, or of every game from Settings ▸ Data, after a confirmation that says how many — with their frame and sensor series and notes; the library, the settings and every consent stay. The Agent deletes them (the rows are its, `06_DATA_MODEL` §Writer ownership) and refuses while a session it would delete under is being recorded.
- FR-1.8 Uninstalled games leave the library by themselves (beta.19, owner decision D55, amending D41): an entry whose executable has been gone for ten minutes — its drive connected and the folder it was installed in still there, so an unplugged or re-lettered drive never counts — and that has no session (stored, being recorded or waiting to be recovered) is removed by the Agent, behind Settings ▸ Data ▸ *Remove uninstalled games* (on by default). Never an entry carrying an anti-cheat block, an exception or a failed-trial mark (FR-2.2, rule 2). The App is told (`GameRemoved`).
- FR-1.8 Uninstalled games leave the library by themselves (beta.19, owner decision D55, amending D41): an entry whose executable has been gone for ten minutes — its drive connected and the folder it was installed in still there, so an unplugged or re-lettered drive never counts, and neither does a folder Windows will not list (`ExecutablePresenceProbeTests`) — and that has no session (stored, being recorded or waiting to be recovered) is removed by the Agent, behind Settings ▸ Data ▸ *Remove uninstalled games* (on by default). Never an entry carrying an anti-cheat block, an exception or a failed-trial mark (FR-2.2, rule 2). The App is told (`GameRemoved`).
- FR-1.6 Recording switch per entry (2026-09-23, HANDOFF D29): off, the program is not watched at all — no session, no measurement, no injection — and a session of it that is running stops. On by default; entries an old import made for Steam's own tools start with it off. The library card says "Not recorded".
### FR-2 Hooking consent & control (new, safety-critical — see `19_SAFETY`)
@@ -1,6 +1,8 @@
// SPDX-License-Identifier: GPL-3.0-only
// Copyright (C) 2026 poli0981 - additional terms under GPLv3 section 7: see NOTICE
using System.Security.AccessControl;
using System.Security.Principal;
using FluentAssertions;
using FrameLedger.Application.Watch;
using FrameLedger.Infrastructure.Watch;
@@ -9,7 +11,8 @@ namespace FrameLedger.Infrastructure.Tests.Watch;
/// <summary>
/// beta.19, D55: what the file system says about an executable that did not read — present, gone from a folder that is
/// still there, gone with its folder, nothing left but the drive's root, or a drive that is not connected — on real folders.
/// still there, gone with its folder, nothing left but the drive's root, a drive that is not connected, or a folder Windows
/// will not list — on real folders.
/// </summary>
public sealed class ExecutablePresenceProbeTests : IDisposable
{
@@ -61,4 +64,90 @@ public sealed class ExecutablePresenceProbeTests : IDisposable
VolumeRoots.IsReady(Path.GetPathRoot(_dir)!).Should().BeTrue("the drive the temporary folder is on is a ready local drive");
Probe().Probe(@"\\server\share\Games\Title.exe").Should().Be(ExecutablePresence.Unknown, "a share is not where a library is uninstalled from");
}
/// <summary>
/// A game folder Windows will not list says nothing about what is in it (beta.19 review of D55): the probe looks for the
/// file in its folder's listing, and a listing it is refused is <see cref="ExecutablePresence.Unknown"/> — never
/// <see cref="ExecutablePresence.FileGone"/>, the one answer that lets the Agent remove the entry.
/// </summary>
[Fact]
public void AGameFolderWindowsWillNotListIsNeverGone()
{
string game = Directory.CreateDirectory(Path.Combine(_dir, "it", "a-game", "Game")).FullName;
string exe = Path.Combine(game, "Game.exe");
File.WriteAllBytes(exe, [1]);
using (new Denied(game, FileSystemRights.ListDirectory))
{
Assert.SkipUnless(CannotList(game), "this process lists a folder it is denied (a backup privilege enabled?), so the case cannot be made here");
Probe().Probe(exe).Should().Be(ExecutablePresence.Unknown, "the file cannot be looked for in a folder that will not list");
Probe().Probe(Path.Combine(game, "Gone.exe")).Should().Be(ExecutablePresence.Unknown, "nor can its absence be read there");
}
Probe().Probe(exe).Should().Be(ExecutablePresence.Present, "the same folder, listed again");
}
/// <summary>
/// A game folder that reads as missing because Windows will not say (its attributes denied, and the library folder it is in
/// will not list) is not a game whose folder went with it: <c>Directory.Exists</c> says false for both, and only the
/// parent's listing tells them apart. A probe that took the missing folder at its word would remove an installed game.
/// </summary>
[Fact]
public void AGameFolderItsLibraryWillNotListIsNeverGone()
{
string library = Directory.CreateDirectory(Path.Combine(_dir, "it")).FullName;
string game = Directory.CreateDirectory(Path.Combine(library, "a-game")).FullName;
string exe = Path.Combine(game, "Game.exe");
File.WriteAllBytes(exe, [1]);
using (new Denied(game, FileSystemRights.ListDirectory | FileSystemRights.ReadAttributes))
using (new Denied(library, FileSystemRights.ListDirectory))
{
Assert.SkipUnless(!Directory.Exists(game) && CannotList(library),
"this process can still see a folder it is denied (a backup privilege enabled?), so the case cannot be made here");
Probe().Probe(exe).Should().Be(ExecutablePresence.Unknown, "the folder reads as missing, and the library it is in will not say whether it is");
}
Probe().Probe(exe).Should().Be(ExecutablePresence.Present, "the same folders, readable again");
}
private static bool CannotList(string folder)
{
try
{
_ = Directory.EnumerateFileSystemEntries(folder).Any();
return false;
}
catch (UnauthorizedAccessException)
{
return true;
}
}
/// <summary>
/// The current user denied <c>rights</c> on one folder until disposed — always given back, so the folder can be deleted.
/// The owner can always change the folder's access list, so giving it back needs none of the rights taken.
/// </summary>
private sealed class Denied : IDisposable
{
private readonly DirectoryInfo _folder;
private readonly FileSystemAccessRule _rule;
public Denied(string folder, FileSystemRights rights)
{
_folder = new DirectoryInfo(folder);
using WindowsIdentity me = WindowsIdentity.GetCurrent();
_rule = new FileSystemAccessRule(me.User!, rights, AccessControlType.Deny);
DirectorySecurity security = _folder.GetAccessControl();
security.AddAccessRule(_rule);
_folder.SetAccessControl(security);
}
public void Dispose()
{
DirectorySecurity security = _folder.GetAccessControl();
security.RemoveAccessRuleSpecific(_rule);
_folder.SetAccessControl(security);
}
}
}