2ee397ac83
A user reported that the CPU affinity feature did nothing when applying a rule. Two distinct defects were behind it. ProcessService.SetProcessorAffinity(process, long) silently substituted SetProcessDefaultCpuSets for the hard affinity write. CPU Sets are only a soft scheduling hint and leave the mask returned by GetProcessAffinityMask untouched, so the single caller - AffinityApplyService.ApplyAsync, which reads the mask back and compares - always reported VerificationMismatch. The Rules tab path (ProcessMonitorManagerService association core masks) therefore failed while the affinity never changed. Reproduced on a 16-CPU machine: requesting 0x3 left the process at 0xFFFF and returned a failure. The overload now writes the affinity mask it was asked for; soft assignment keeps its own entry points (CpuAssignmentMode.CpuSets, CpuSelectionAffinityApplier). The shipped DefaultCpuAssignmentMode was Automatic, which is CPU-Sets-first, so out of the box "Apply CPU Assignment" produced no change visible in Task Manager while reporting success. The default is now AffinityMask, and the CPU Sets result message states that it is a soft preference rather than claiming "Affinity applied successfully". Save Current Settings as Rule only captured the core selection while edits were staged, otherwise falling back to process.ProcessorAffinity - which soft modes never change - saving a rule pinned to every CPU. It now captures what the core checkboxes show. Adds a regression test that spawns a real process and asserts the hard affinity mask actually changes; it fails on the previous implementation. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AhS1xyuMPFvxrojERQ4NuY
73 lines
2.7 KiB
C#
73 lines
2.7 KiB
C#
namespace ThreadPilot.Core.Tests
|
|
{
|
|
using ThreadPilot.Models;
|
|
|
|
public sealed class ApplicationSettingsModelTests
|
|
{
|
|
[Fact]
|
|
public void Constructor_StartMinimizedDefaultsFalse_ForManualLaunchVisibility()
|
|
{
|
|
var settings = new ApplicationSettingsModel();
|
|
|
|
Assert.True(settings.AutostartWithWindows);
|
|
Assert.False(settings.StartMinimized);
|
|
Assert.True(settings.ApplyPersistentRulesOnProcessStart);
|
|
Assert.True(settings.EnableAutomationMonitoring);
|
|
Assert.False(settings.HasSeenStartupMinimizedSuggestion);
|
|
Assert.Equal("en-US", settings.Language);
|
|
Assert.True(settings.EnableAutomaticUpdateChecks);
|
|
Assert.False(settings.IncludePrereleaseUpdates);
|
|
Assert.Null(settings.LastUpdateCheckUtc);
|
|
Assert.Equal(CpuAssignmentMode.AffinityMask, settings.DefaultCpuAssignmentMode);
|
|
}
|
|
|
|
[Fact]
|
|
public void CopyFrom_CopiesLanguage()
|
|
{
|
|
var source = new ApplicationSettingsModel
|
|
{
|
|
Language = "zh-CN",
|
|
EnableAutomationMonitoring = false,
|
|
DefaultCpuAssignmentMode = CpuAssignmentMode.IdealProcessor,
|
|
};
|
|
var target = new ApplicationSettingsModel();
|
|
|
|
target.CopyFrom(source);
|
|
|
|
Assert.Equal("zh-CN", target.Language);
|
|
Assert.False(target.EnableAutomationMonitoring);
|
|
Assert.Equal(CpuAssignmentMode.IdealProcessor, target.DefaultCpuAssignmentMode);
|
|
}
|
|
|
|
[Fact]
|
|
public void HasSameUserSettingsAs_ReturnsTrue_WhenChangedSettingIsRestored()
|
|
{
|
|
var savedSettings = new ApplicationSettingsModel
|
|
{
|
|
EnableNotifications = true,
|
|
};
|
|
|
|
var editableSettings = (ApplicationSettingsModel)savedSettings.Clone();
|
|
editableSettings.EnableNotifications = false;
|
|
Assert.False(editableSettings.HasSameUserSettingsAs(savedSettings));
|
|
|
|
editableSettings.EnableNotifications = true;
|
|
|
|
Assert.True(editableSettings.HasSameUserSettingsAs(savedSettings));
|
|
}
|
|
|
|
[Fact]
|
|
public void HasSameUserSettingsAs_IgnoresMetadataTimestamps()
|
|
{
|
|
var savedSettings = new ApplicationSettingsModel
|
|
{
|
|
UpdatedAt = new System.DateTime(2026, 5, 16, 10, 0, 0, System.DateTimeKind.Utc),
|
|
};
|
|
var editableSettings = (ApplicationSettingsModel)savedSettings.Clone();
|
|
editableSettings.UpdatedAt = savedSettings.UpdatedAt.AddMinutes(5);
|
|
|
|
Assert.True(editableSettings.HasSameUserSettingsAs(savedSettings));
|
|
}
|
|
}
|
|
}
|