Files
ThreadPilot/Tests/ThreadPilot.Core.Tests/PersistentProcessRuleMatcherTests.cs
T
Prime Build bffbdeeccc CPU topology v2 phase 8: add persistent rules engine foundation (#14)
Add persistent rules engine foundation

Introduce the foundation for Apply at process start without adding a background loop, Windows Service, installer changes, registry affinity or anti-cheat bypass behavior.

- Add PersistentProcessRule and PersistentRuleApplyResult models
- Add process-name and executable-path rule matching
- Add PersistentRulesEngine using existing safe affinity and priority services
- Add JSON-backed persistent rule store
- Add safe Apply at process start user-facing copy
- Validate incomplete rules so missing affinity/priority payloads fail safely
- Add tests for matching, CpuSelection, legacy affinity, priority, Realtime guardrails, access denied, protected processes, process exit, disabled rules and storage roundtrip

No process monitor hook, UI management, Windows Service, registry/IFEO expansion, version bump or tag changes.
2026-05-20 16:45:43 +02:00

98 lines
3.1 KiB
C#

/*
* ThreadPilot - persistent process rule matcher tests.
*/
namespace ThreadPilot.Core.Tests
{
using ThreadPilot.Models;
using ThreadPilot.Services;
public sealed class PersistentProcessRuleMatcherTests
{
private readonly PersistentProcessRuleMatcher matcher = new();
[Fact]
public void IsMatch_WithProcessName_MatchesCaseInsensitive()
{
var rule = CreateRule(processName: "GAME.EXE");
var process = CreateProcess(name: "game.exe");
var result = this.matcher.IsMatch(rule, process);
Assert.True(result);
}
[Fact]
public void IsMatch_WithExecutablePath_MatchesCaseInsensitive()
{
var rule = CreateRule(executablePath: @"C:\Games\App\Game.exe");
var process = CreateProcess(executablePath: @"c:\games\app\game.exe");
var result = this.matcher.IsMatch(rule, process);
Assert.True(result);
}
[Fact]
public void IsMatch_WithNameAndPath_UsesExecutablePathPriority()
{
var rule = CreateRule(processName: "game.exe", executablePath: @"C:\Games\App\Game.exe");
var process = CreateProcess(name: "game.exe", executablePath: @"C:\Other\Game.exe");
var result = this.matcher.IsMatch(rule, process);
Assert.False(result);
}
[Fact]
public void IsMatch_WithDisabledRule_ReturnsFalse()
{
var rule = CreateRule(processName: "game.exe") with { IsEnabled = false };
var process = CreateProcess(name: "game.exe");
var result = this.matcher.IsMatch(rule, process);
Assert.False(result);
}
[Fact]
public void IsMatch_WithProcessWithoutExecutablePath_CanMatchProcessName()
{
var rule = CreateRule(processName: "game.exe");
var process = CreateProcess(name: "GAME.EXE", executablePath: string.Empty);
var result = this.matcher.IsMatch(rule, process);
Assert.True(result);
}
[Fact]
public void IsMatch_WithNullPaths_DoesNotThrow()
{
var rule = CreateRule(processName: null, executablePath: null);
var process = CreateProcess(name: "game.exe", executablePath: null);
var exception = Record.Exception(() => this.matcher.IsMatch(rule, process));
Assert.Null(exception);
}
private static PersistentProcessRule CreateRule(string? processName = null, string? executablePath = null) =>
new()
{
Id = Guid.NewGuid().ToString("N"),
Name = "Rule",
IsEnabled = true,
ProcessName = processName,
ExecutablePath = executablePath,
};
private static ProcessModel CreateProcess(string name = "game.exe", string? executablePath = @"C:\Games\Game.exe") =>
new()
{
ProcessId = 42,
Name = name,
ExecutablePath = executablePath ?? string.Empty,
};
}
}