The owner asked (2026-10-12, after beta.19's Unity, Godot and RPG Maker
versions) for the version of Ren'Py games. The renpy rule had no version
extractor.
Ren'Py ships its engine as Python beside the game's launcher, and
renpy/vc_version.py names its release: version = '8.5.0.25111603', beside
branch, nightly, official and version_name. Measured read-only on the
owner's one Ren'Py install, Bound Between Desks (Steam): 109 bytes, the
same number the game's log.txt printed at its last start; the launcher has
no version resource (spike-notes §18).
- Rules 2026.10.3: renpy -> {"type": "renpy_build"}; the schema's enum of
code-decided extractors gains it. Every entry is read again once.
- Domain: RenPyBuildFacts + RenPyVersion.Decide keep MAJOR.MINOR.PATCH,
as Ren'Py names its releases (the fourth number is the build), source
renpy_vc_version; VersionExtractorType.RenPyBuild; the evaluator leaves
it to the detector, as the other code-decided types.
- Application: IGameFileProbe.ReadRenPyBuildAsync; StaticGameDetector
makes the one second read for a Ren'Py match.
- Infrastructure: RenPyBuildReader reads the first 4 KiB of
renpy/vc_version.py beside the executable, its version line only.
- App: the game page says "Ren'Py 8.5.0" and that it was read from the
engine's version file (en/vi/ja, ja marked review); a Ren'Py row whose
file names no version says "Not found in the game's files".
- Privacy Policy 2.9: §4's list of the version marks an engine keeps in
its own files names Ren'Py's (legal-drift-history). The Legal Gate shows
it once at the next update.
- The accuracy block (ACCURACY, README, DISCLAIMER), LIMITATIONS,
05_DETECTION §Engine version - Ren'Py, 06_DATA_MODEL, 08_UI, CHANGELOG.
- HANDOFF: owner-only item 15 struck, passed 2026-10-12 (the owner's
report, and the Agent's log for the removal: one check at 18:04:00 took
three session-less entries); the rules-reseed trap gains the backup the
session made of the owner's two rules files.
Through the shipped pipeline (StaticGameDetector over GameFileProbe, read
only): Bound Between Desks renpy 8.5.0 renpy_vc_version in 79 ms; Dialoop,
Plethora of Bullets 2, A Doll's Locket and City of Bones read as before.
Tests: RenPyVersionTests (the measured value; the build dropped; shapes
that are not a version), EngineBuildReadersTests (the measured file beside
the launcher; no file, a version_name only, past the bounded head),
StaticGameDetectorTests (one read for the matched engine),
GameDetailViewModelTests and FormatsTests (the page's words).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
443 lines
23 KiB
C#
443 lines
23 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.Detection;
|
|
using FrameLedger.Application.Persistence;
|
|
using FrameLedger.Application.Tests.Recording;
|
|
using FrameLedger.Application.Tests.Watch;
|
|
using FrameLedger.Application.Watch;
|
|
using FrameLedger.Domain.Consent;
|
|
using FrameLedger.Domain.Detection;
|
|
|
|
namespace FrameLedger.Application.Tests.Detection;
|
|
|
|
/// <summary>
|
|
/// The sweep (P4 PR-1): a game is scanned when its cache key is stale — never scanned, the exe changed, the rules
|
|
/// moved on — and left alone when it is current (<c>05_DETECTION</c> §Caching). An unreadable exe is skipped, an
|
|
/// unusable rules file scans nothing, and <c>RequestNow</c> wakes the loop before its interval.
|
|
/// </summary>
|
|
public sealed class DetectionSweepTests
|
|
{
|
|
private const string _exe = @"C:\Games\Title\game.exe";
|
|
|
|
private static CancellationToken Ct => TestContext.Current.CancellationToken;
|
|
|
|
private sealed class ScriptedRules(string version) : IDetectionRulesSource
|
|
{
|
|
public string Version { get; set; } = version;
|
|
|
|
public bool Unusable { get; set; }
|
|
|
|
public ValueTask<DetectionRuleSet> LoadAsync(CancellationToken ct = default) => Unusable
|
|
? throw new InvalidOperationException("rules unusable")
|
|
: ValueTask.FromResult(new DetectionRuleSet
|
|
{
|
|
SchemaVersion = 2,
|
|
RulesVersion = Version,
|
|
Engines = [new EngineRule { Id = "unity", Name = "Unity", Signals = new SignalGroup { Combinator = SignalCombinator.All, Signals = [new DetectionSignal { Type = DetectionSignalType.SiblingGlob, Value = "UnityPlayer.dll" }] } }],
|
|
Platforms = [new PlatformRule { Id = "steam", Name = "Steam", Signals = new SignalGroup { Combinator = SignalCombinator.Any, Signals = [new DetectionSignal { Type = DetectionSignalType.SiblingGlob, Value = "steam_api64.dll" }] } }],
|
|
Capabilities = [new CapabilityRule { Id = "dlss", Name = "DLSS", Signals = new SignalGroup { Combinator = SignalCombinator.Any, Signals = [new DetectionSignal { Type = DetectionSignalType.SiblingGlob, Value = "nvngx_dlss.dll" }] } }],
|
|
});
|
|
}
|
|
|
|
private sealed class ScriptedProbe : IGameFileProbe
|
|
{
|
|
public int Calls { get; private set; }
|
|
|
|
public bool? VulkanLoaderReferenced { get; set; }
|
|
|
|
public string Architecture { get; set; } = ExecutableArchitecture.X64;
|
|
|
|
public IReadOnlyList<LibraryFile> Libraries { get; set; } = [];
|
|
|
|
public ValueTask<GameFileSnapshot> SnapshotAsync(string exePath, DetectionRuleSet rules, CancellationToken ct = default)
|
|
{
|
|
Calls++;
|
|
return ValueTask.FromResult(new GameFileSnapshot
|
|
{
|
|
VulkanLoaderReferenced = VulkanLoaderReferenced,
|
|
ExePath = exePath,
|
|
ExeNameWithoutExtension = "game",
|
|
GameDirectory = "C:/Games/Title",
|
|
RelativeFiles = ["game.exe", "UnityPlayer.dll", "steam_api64.dll", "nvngx_dlss.dll"],
|
|
RelativeDirectories = [],
|
|
FileListingComplete = true,
|
|
SiblingFileVersions = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase),
|
|
MatchedStringNeedles = new HashSet<string>(StringComparer.Ordinal),
|
|
StringsRegexCaptures = new Dictionary<string, string>(StringComparer.Ordinal),
|
|
ManifestFields = new Dictionary<string, string>(StringComparer.Ordinal),
|
|
UncollectedFacts = new HashSet<DetectionSignalType>(),
|
|
ExeArchitecture = Architecture,
|
|
PeFileVersion = "1.0.2.0",
|
|
PeProductVersion = "1.0.2",
|
|
Libraries = Libraries,
|
|
});
|
|
}
|
|
|
|
// Unity rules only here: the sweep's second read is StaticGameDetector's, pinned in StaticGameDetectorTests.
|
|
public ValueTask<UnrealBuildFacts?> ReadUnrealBuildAsync(GameFileSnapshot snapshot, CancellationToken ct = default) =>
|
|
ValueTask.FromResult<UnrealBuildFacts?>(null);
|
|
|
|
public ValueTask<UnityBuildFacts?> ReadUnityBuildAsync(GameFileSnapshot snapshot, CancellationToken ct = default) =>
|
|
ValueTask.FromResult<UnityBuildFacts?>(null);
|
|
|
|
public ValueTask<GodotBuildFacts?> ReadGodotBuildAsync(GameFileSnapshot snapshot, CancellationToken ct = default) =>
|
|
ValueTask.FromResult<GodotBuildFacts?>(null);
|
|
|
|
public ValueTask<RpgMakerBuildFacts?> ReadRpgMakerBuildAsync(GameFileSnapshot snapshot, CancellationToken ct = default) =>
|
|
ValueTask.FromResult<RpgMakerBuildFacts?>(null);
|
|
|
|
public ValueTask<RenPyBuildFacts?> ReadRenPyBuildAsync(GameFileSnapshot snapshot, CancellationToken ct = default) =>
|
|
ValueTask.FromResult<RenPyBuildFacts?>(null);
|
|
}
|
|
|
|
private sealed class FakeIdentity : IExecutableIdentitySource
|
|
{
|
|
public ExecutableFingerprint? OnDisk { get; set; } = new() { ExePath = _exe, SizeBytes = 5, MtimeUnixMs = 5 };
|
|
|
|
/// <summary>When set, the disk is THIS map and nothing else — a relocation test needs an answer per path.</summary>
|
|
public Dictionary<string, ExecutableFingerprint>? ByPath { get; set; }
|
|
|
|
public ExecutableFingerprint? Read(string normalisedExePath) => ByPath is null ? OnDisk : ByPath.TryGetValue(normalisedExePath, out ExecutableFingerprint f) ? f : null;
|
|
|
|
public string Normalise(string exePath) => exePath;
|
|
}
|
|
|
|
private static async Task<(DetectionSweep Sweep, FakeGameRepository Games, ScriptedRules Rules, ScriptedProbe Probe, FakeIdentity Identity, List<string> Log)> BuildAsync()
|
|
{
|
|
var games = new FakeGameRepository();
|
|
await games.EnsureAsync(new ExecutableFingerprint { ExePath = _exe, SizeBytes = 1, MtimeUnixMs = 1 }, "Title", Ct).ConfigureAwait(false);
|
|
var rules = new ScriptedRules("2026.09.1");
|
|
var probe = new ScriptedProbe();
|
|
var identity = new FakeIdentity();
|
|
List<string> log = [];
|
|
return (new DetectionSweep(games, rules, probe, identity, log.Add), games, rules, probe, identity, log);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task AGameNeverScannedIsScannedOnceAndThenLeftAloneWhileItsKeyHolds()
|
|
{
|
|
(DetectionSweep sweep, FakeGameRepository games, _, ScriptedProbe probe, _, List<string> log) = await BuildAsync();
|
|
|
|
DetectionSweepReport first = await sweep.SweepOnceAsync(Ct);
|
|
first.Scanned.Should().Be(1);
|
|
first.Current.Should().Be(0);
|
|
probe.Calls.Should().Be(1);
|
|
(long GameId, DetectionWrite Write) w = games.Detections.Single();
|
|
w.Write.EngineId.Should().Be("unity");
|
|
w.Write.PlatformId.Should().Be("steam");
|
|
w.Write.CapabilityIds.Should().Equal("dlss");
|
|
w.Write.RulesVersion.Should().Be("2026.09.1");
|
|
w.Write.ExeSizeBytes.Should().Be(5, "the key's exe half is what is on disk NOW, not the consent fingerprint the row was added with");
|
|
w.Write.ExeMtimeMs.Should().Be(5);
|
|
log.Should().ContainSingle(static l => l.Contains("engine=unity", StringComparison.Ordinal) && l.Contains("capabilities=[dlss]", StringComparison.Ordinal));
|
|
|
|
DetectionSweepReport second = await sweep.SweepOnceAsync(Ct);
|
|
second.Scanned.Should().Be(0);
|
|
second.Current.Should().Be(1, "the stored key matches the file and the rules");
|
|
probe.Calls.Should().Be(1, "a current game is not walked again");
|
|
}
|
|
|
|
/// <summary>beta.8 (schema 0011): the executable's own facts ride the same write — what it runs as, its versions, what it ships.</summary>
|
|
[Fact]
|
|
public async Task TheExecutablesOwnFactsAreWrittenWithTheDetection()
|
|
{
|
|
(DetectionSweep sweep, FakeGameRepository games, _, ScriptedProbe probe, _, List<string> log) = await BuildAsync();
|
|
probe.Libraries = [new LibraryFile("dlss", "Engine/Plugins/DLSS/nvngx_dlss.dll", "3.7.10.0", "3.7.10")];
|
|
|
|
await sweep.SweepOnceAsync(Ct);
|
|
|
|
DetectionWrite w = games.Detections.Single().Write;
|
|
w.ExeArchitecture.Should().Be(ExecutableArchitecture.X64);
|
|
(w.ExeFileVersion, w.ExeProductVersion).Should().Be(("1.0.2.0", "1.0.2"));
|
|
w.Libraries.Should().ContainSingle().Which.FileName.Should().Be("nvngx_dlss.dll");
|
|
games.Rows[_exe].ExeMachine.Should().Be("x64");
|
|
log.Should().Contain(static l => l.Contains("arch=x64 libraries=1", StringComparison.Ordinal));
|
|
games.Disabled.Should().BeEmpty("nothing about an x64 executable turns hooking off");
|
|
}
|
|
|
|
/// <summary>A row this build has not read the executable's facts for is stale once, whatever its key says (schema 0011).</summary>
|
|
[Fact]
|
|
public void ARowWithoutTheExecutablesFactsIsStaleOnce()
|
|
{
|
|
var onDisk = new ExecutableFingerprint { ExePath = _exe, SizeBytes = 5, MtimeUnixMs = 5 };
|
|
var row = new GameRow
|
|
{
|
|
Id = 1,
|
|
Name = "T",
|
|
Fingerprint = onDisk,
|
|
DetectionRulesVersion = "2026.09.1",
|
|
DetectionExeSizeBytes = 5,
|
|
DetectionExeMtimeMs = 5,
|
|
HookEnabled = false,
|
|
HookCrashCount = 0,
|
|
AddedAt = DateTimeOffset.UnixEpoch,
|
|
UpdatedAt = DateTimeOffset.UnixEpoch,
|
|
};
|
|
|
|
DetectionSweep.IsStale(row, onDisk, "2026.09.1").Should().BeTrue("exe_machine is NULL: read under an older build");
|
|
DetectionSweep.IsStale(row with { ExeMachine = ExecutableArchitecture.Unknown }, onDisk, "2026.09.1").Should().BeFalse(
|
|
"looked at and unreadable is an answer, stored so the file is not read again every pass");
|
|
}
|
|
|
|
/// <summary>
|
|
/// beta.8: an executable the x64 hook cannot enter has its hooking turned off by the sweep when a row enabled before this
|
|
/// build still has it on — rather than a refusal at every launch — with the architecture in the row's reason.
|
|
/// </summary>
|
|
[Theory]
|
|
[InlineData(ExecutableArchitecture.X86)]
|
|
[InlineData(ExecutableArchitecture.AnyCpu32)]
|
|
[InlineData(ExecutableArchitecture.Arm64)]
|
|
public async Task AHookEnabledRowWhoseExecutableCannotRunAsX64IsTurnedOff(string architecture)
|
|
{
|
|
(DetectionSweep sweep, FakeGameRepository games, _, ScriptedProbe probe, _, List<string> log) = await BuildAsync();
|
|
games.Rows[_exe] = games.Rows[_exe] with { HookEnabled = true };
|
|
probe.Architecture = architecture;
|
|
|
|
await sweep.SweepOnceAsync(Ct);
|
|
|
|
games.Disabled.Should().ContainSingle().Which.Reason.Should().Be(DetectionSweep.NotX64Reason(architecture));
|
|
log.Should().Contain(l => l.Contains("hooking turned off", StringComparison.Ordinal));
|
|
}
|
|
|
|
[Fact]
|
|
public async Task ARowWhoseHookingIsOffIsNotTouchedWhateverItsArchitecture()
|
|
{
|
|
(DetectionSweep sweep, FakeGameRepository games, _, ScriptedProbe probe, _, _) = await BuildAsync();
|
|
probe.Architecture = ExecutableArchitecture.X86;
|
|
|
|
await sweep.SweepOnceAsync(Ct);
|
|
|
|
games.Disabled.Should().BeEmpty("nothing to turn off; the page says why it cannot be turned on");
|
|
games.Rows[_exe].ExeMachine.Should().Be(ExecutableArchitecture.X86);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task AChangedExeOrANewRulesVersionRescans()
|
|
{
|
|
(DetectionSweep sweep, FakeGameRepository games, ScriptedRules rules, ScriptedProbe probe, FakeIdentity identity, _) = await BuildAsync();
|
|
await sweep.SweepOnceAsync(Ct);
|
|
|
|
identity.OnDisk = new ExecutableFingerprint { ExePath = _exe, SizeBytes = 6, MtimeUnixMs = 9 };
|
|
(await sweep.SweepOnceAsync(Ct)).Scanned.Should().Be(1, "the exe on disk changed (a patch)");
|
|
games.Detections[^1].Write.ExeSizeBytes.Should().Be(6);
|
|
|
|
rules.Version = "2026.10.1";
|
|
(await sweep.SweepOnceAsync(Ct)).Scanned.Should().Be(1, "the rules moved on — the trigger 05_DETECTION §Caching names");
|
|
games.Detections[^1].Write.RulesVersion.Should().Be("2026.10.1");
|
|
probe.Calls.Should().Be(3);
|
|
|
|
(await sweep.SweepOnceAsync(Ct)).Scanned.Should().Be(0);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task AnUnreadableExeIsSkippedAndNamedAndAnUnusableRulesFileScansNothing()
|
|
{
|
|
(DetectionSweep sweep, FakeGameRepository games, ScriptedRules rules, ScriptedProbe probe, FakeIdentity identity, List<string> log) = await BuildAsync();
|
|
|
|
identity.OnDisk = null;
|
|
DetectionSweepReport r = await sweep.SweepOnceAsync(Ct);
|
|
r.Unreadable.Should().Be(1);
|
|
r.Scanned.Should().Be(0);
|
|
probe.Calls.Should().Be(0, "nothing is walked for a file that cannot be read");
|
|
log.Should().ContainSingle(static l => l.Contains("unreadable", StringComparison.Ordinal));
|
|
|
|
identity.OnDisk = new ExecutableFingerprint { ExePath = _exe, SizeBytes = 5, MtimeUnixMs = 5 };
|
|
rules.Unusable = true;
|
|
DetectionSweepReport bad = await sweep.SweepOnceAsync(Ct);
|
|
bad.RulesUnusable.Should().BeTrue();
|
|
bad.Scanned.Should().Be(0);
|
|
games.Detections.Should().BeEmpty("an unusable rules file writes nothing rather than a wrong answer");
|
|
}
|
|
|
|
/// <summary>
|
|
/// The owner's log repeated "executable unreadable" for the same entries every 15 s (2026-09-22/23): an unreadable
|
|
/// entry is said once, again only when its path changes or after it has read in between.
|
|
/// </summary>
|
|
[Fact]
|
|
public async Task AnUnreadableExeIsSaidOnceUntilItChanges()
|
|
{
|
|
(DetectionSweep sweep, _, _, _, FakeIdentity identity, List<string> log) = await BuildAsync();
|
|
identity.OnDisk = null;
|
|
|
|
await sweep.SweepOnceAsync(Ct);
|
|
await sweep.SweepOnceAsync(Ct);
|
|
await sweep.SweepOnceAsync(Ct);
|
|
log.Where(static l => l.Contains("unreadable", StringComparison.Ordinal)).Should().ContainSingle();
|
|
|
|
identity.OnDisk = new ExecutableFingerprint { ExePath = _exe, SizeBytes = 5, MtimeUnixMs = 5 };
|
|
await sweep.SweepOnceAsync(Ct);
|
|
identity.OnDisk = null;
|
|
(await sweep.SweepOnceAsync(Ct)).Unreadable.Should().Be(1, "the count stays honest; only the line is not repeated");
|
|
log.Where(static l => l.Contains("unreadable", StringComparison.Ordinal)).Should().HaveCount(2, "it read in between, so going unreadable again is news");
|
|
}
|
|
|
|
private sealed class PruneClock : TimeProvider
|
|
{
|
|
public DateTimeOffset Now { get; set; } = new(2026, 10, 12, 8, 0, 0, TimeSpan.Zero);
|
|
|
|
public override DateTimeOffset GetUtcNow() => Now;
|
|
}
|
|
|
|
private sealed class GonePresence : IExecutablePresence
|
|
{
|
|
public ExecutablePresence Probe(string exePath) => ExecutablePresence.FileGone;
|
|
}
|
|
|
|
private sealed class DeletingPrune : IGamePrune
|
|
{
|
|
public List<long> Deleted { get; } = [];
|
|
|
|
public ValueTask<bool> RemoveUninstalledAsync(long gameId, string exePath, CancellationToken ct = default)
|
|
{
|
|
Deleted.Add(gameId);
|
|
return ValueTask.FromResult(true);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// beta.19, D55: an unreadable entry whose game is no longer installed is asked about after the relocator, and once the
|
|
/// prune removes it the sweep counts it removed — not unreadable — and says nothing else about it.
|
|
/// </summary>
|
|
[Fact]
|
|
public async Task AnUninstalledEntryIsRemovedAfterTheGraceAndCountedAsRemoved()
|
|
{
|
|
var games = new FakeGameRepository();
|
|
await games.EnsureAsync(new ExecutableFingerprint { ExePath = _exe, SizeBytes = 1, MtimeUnixMs = 1 }, "Title", Ct);
|
|
var identity = new FakeIdentity { OnDisk = null };
|
|
var clock = new PruneClock();
|
|
var deleting = new DeletingPrune();
|
|
List<string> log = [];
|
|
var prune = new UninstalledEntryPrune(deleting, new GonePresence(), static _ => ValueTask.FromResult(true), static _ => false, log.Add, clock: clock);
|
|
using var sweep = new DetectionSweep(games, new ScriptedRules("2026.10.2"), new ScriptedProbe(), identity, log.Add, prune: prune);
|
|
|
|
DetectionSweepReport first = await sweep.SweepOnceAsync(Ct);
|
|
first.Unreadable.Should().Be(1);
|
|
first.Removed.Should().Be(0, "the first sweep that sees it gone only starts the count");
|
|
|
|
clock.Now += UninstalledEntryPrune.Grace;
|
|
DetectionSweepReport second = await sweep.SweepOnceAsync(Ct);
|
|
second.Removed.Should().Be(1);
|
|
second.Unreadable.Should().Be(0);
|
|
deleting.Deleted.Should().ContainSingle();
|
|
log.Should().Contain(static l => l.StartsWith("library: removed 'Title'", StringComparison.Ordinal));
|
|
}
|
|
|
|
[Fact]
|
|
public async Task RequestNowWakesTheWaitBeforeTheIntervalAndIsIdempotent()
|
|
{
|
|
(DetectionSweep sweep, _, _, _, _, _) = await BuildAsync();
|
|
|
|
sweep.RequestNow();
|
|
sweep.RequestNow();
|
|
(await sweep.WaitAsync(TimeSpan.FromSeconds(30), Ct)).Should().BeTrue("woken at once — the request was queued before the wait");
|
|
(await sweep.WaitAsync(TimeSpan.FromMilliseconds(50), Ct)).Should().BeFalse("two requests while nobody waited are one wake; the second wait times out");
|
|
|
|
Task<bool> waiting = sweep.WaitAsync(TimeSpan.FromSeconds(30), Ct);
|
|
sweep.RequestNow();
|
|
(await waiting).Should().BeTrue("a waiter is woken early");
|
|
}
|
|
|
|
/// <summary>The Vulkan fact rides in <c>capability_flags</c> under its own id (P4 PR-2): appended when the probe saw the loader, absent when it did not or could not look.</summary>
|
|
[Fact]
|
|
public async Task TheVulkanFactIsStoredAsACapabilityIdOnlyWhenTheLoaderWasSeen()
|
|
{
|
|
(DetectionSweep sweep, FakeGameRepository games, _, ScriptedProbe probe, _, List<string> log) = await BuildAsync();
|
|
|
|
probe.VulkanLoaderReferenced = true;
|
|
await sweep.SweepOnceAsync(Ct);
|
|
games.Detections[^1].Write.CapabilityIds.Should().Equal("dlss", "vulkan");
|
|
log[^1].Should().Contain("vulkan=yes");
|
|
|
|
probe.VulkanLoaderReferenced = null;
|
|
games.Rows[_exe] = games.Rows[_exe] with { DetectionRulesVersion = null }; // stale again
|
|
await sweep.SweepOnceAsync(Ct);
|
|
games.Detections[^1].Write.CapabilityIds.Should().Equal("dlss");
|
|
log[^1].Should().Contain("vulkan=unknown", "could not look is not \"no\", and it is not stored as a fact either way");
|
|
}
|
|
|
|
[Fact]
|
|
public void StalenessIsTheCacheKeyFieldByField()
|
|
{
|
|
var onDisk = new ExecutableFingerprint { ExePath = _exe, SizeBytes = 5, MtimeUnixMs = 7 };
|
|
GameRow current = new() { Id = 1, Name = "T", Fingerprint = onDisk, HookEnabled = false, HookCrashCount = 0, AddedAt = DateTimeOffset.UnixEpoch, UpdatedAt = DateTimeOffset.UnixEpoch, DetectionRulesVersion = "v", DetectionExeSizeBytes = 5, DetectionExeMtimeMs = 7, ExeMachine = "x64" };
|
|
DetectionSweep.IsStale(current, onDisk, "v").Should().BeFalse();
|
|
DetectionSweep.IsStale(current with { ExeMachine = null }, onDisk, "v").Should().BeTrue("the executable's facts were never read (schema 0011)");
|
|
DetectionSweep.IsStale(current with { DetectionRulesVersion = null }, onDisk, "v").Should().BeTrue("never scanned");
|
|
DetectionSweep.IsStale(current, onDisk, "w").Should().BeTrue("rules moved");
|
|
DetectionSweep.IsStale(current with { DetectionExeSizeBytes = 4 }, onDisk, "v").Should().BeTrue("size changed");
|
|
DetectionSweep.IsStale(current with { DetectionExeMtimeMs = 8 }, onDisk, "v").Should().BeTrue("mtime changed");
|
|
}
|
|
|
|
/// <summary>
|
|
/// A drive that changed its letter (2026-09-22): the sweep finds the same file under another root, moves the row and
|
|
/// scans it there in the same pass — the owner's 46 "unreadable" rows the morning the drive came back as H:.
|
|
/// </summary>
|
|
[Fact]
|
|
public async Task AMovedDriveIsRelocatedAndScannedInTheSamePass()
|
|
{
|
|
var games = new FakeGameRepository();
|
|
var stored = new ExecutableFingerprint { ExePath = @"D:\SteamLibrary\steamapps\common\Title\game.exe", SizeBytes = 5, MtimeUnixMs = 5 };
|
|
GameRow row = await games.EnsureAsync(stored, "Title", Ct);
|
|
const string moved = @"H:\SteamLibrary\steamapps\common\Title\game.exe";
|
|
var identity = new FakeIdentity
|
|
{
|
|
ByPath = new Dictionary<string, ExecutableFingerprint>(StringComparer.OrdinalIgnoreCase)
|
|
{
|
|
[moved] = new ExecutableFingerprint { ExePath = moved, SizeBytes = 5, MtimeUnixMs = 5 },
|
|
},
|
|
};
|
|
List<string> log = [];
|
|
using var sweep = new DetectionSweep(games, new ScriptedRules("2026.09.1"), new ScriptedProbe(), identity, log.Add,
|
|
new ExecutableRelocator(games, identity, () => [@"C:\", @"D:\", @"H:\"], log.Add));
|
|
|
|
DetectionSweepReport report = await sweep.SweepOnceAsync(Ct);
|
|
|
|
report.Relocated.Should().Be(1);
|
|
report.Unreadable.Should().Be(0, "the file was found under H:, so the row is not unreadable");
|
|
report.Scanned.Should().Be(1, "and it was scanned there in the same pass");
|
|
games.Rows.Should().ContainKey(moved).And.NotContainKey(stored.ExePath);
|
|
games.Rows[moved].Id.Should().Be(row.Id);
|
|
games.Detections.Should().ContainSingle().Which.GameId.Should().Be(row.Id);
|
|
log.Should().Contain(l => l.Contains("executable moved", StringComparison.Ordinal));
|
|
|
|
// The drive gone again: unreadable, as before, and nothing invented.
|
|
identity.ByPath.Clear();
|
|
DetectionSweepReport gone = await sweep.SweepOnceAsync(Ct);
|
|
gone.Unreadable.Should().Be(1);
|
|
gone.Relocated.Should().Be(0);
|
|
}
|
|
|
|
/// <summary>
|
|
/// A twin merged away in the pass (2026-09-23, D26) is not an entry any more, so it is not reported unreadable: the
|
|
/// owner's log would otherwise say the entry it just merged could not be read.
|
|
/// </summary>
|
|
[Fact]
|
|
public async Task AnEntryMergedIntoItsTwinIsNotUnreadable()
|
|
{
|
|
var games = new FakeGameRepository();
|
|
const string live = @"H:\SteamLibrary\steamapps\common\Title\game.exe";
|
|
GameRow owner = await games.EnsureAsync(new ExecutableFingerprint { ExePath = live, SizeBytes = 5, MtimeUnixMs = 5 }, "Title", Ct);
|
|
GameRow stale = await games.EnsureAsync(new ExecutableFingerprint { ExePath = @"D:\SteamLibrary\steamapps\common\Title\game.exe", SizeBytes = 5, MtimeUnixMs = 5 }, "Title (D:)", Ct);
|
|
var identity = new FakeIdentity
|
|
{
|
|
ByPath = new Dictionary<string, ExecutableFingerprint>(StringComparer.OrdinalIgnoreCase)
|
|
{
|
|
[live] = new ExecutableFingerprint { ExePath = live, SizeBytes = 5, MtimeUnixMs = 5 },
|
|
},
|
|
};
|
|
List<string> log = [];
|
|
using var sweep = new DetectionSweep(games, new ScriptedRules("2026.09.1"), new ScriptedProbe(), identity, log.Add,
|
|
new ExecutableRelocator(games, identity, () => [@"C:\", @"D:\", @"H:\"], log.Add, merge: new FakeGameMerge(games)));
|
|
|
|
DetectionSweepReport report = await sweep.SweepOnceAsync(Ct);
|
|
|
|
report.Unreadable.Should().Be(0);
|
|
report.Relocated.Should().Be(1);
|
|
games.Rows.Should().ContainSingle().Which.Value.Id.Should().Be(owner.Id, "made first (a tie keeps the lower id), so it stays");
|
|
log.Should().Contain(l => l.Contains("merged", StringComparison.Ordinal))
|
|
.And.NotContain(l => l.Contains("unreadable", StringComparison.Ordinal) && l.Contains(stale.Name, StringComparison.Ordinal));
|
|
}
|
|
}
|