Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,27 @@ All notable changes to this project are documented here. The format follows
[Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and the project
adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Added
- **IDialogService** — abstraction for user confirmation dialogs, replacing
direct `MessageBox.Show` calls in ViewModels. Enables unit testing of
confirmation-gated code paths (CQ-003).

### Fixed
- **Disk Health** — `TemperatureColorHex` returns grey (#9AA0A6) for drives
without temperature sensors instead of misleading red (QA-004).
- **Battery Health** — `HealthPercent` clamped to 0–100, `WearPercent`
clamped to ≥0 for new batteries exceeding design capacity (QA-005).
- **Network Monitor** — `TrimBuffer` batch-removes expired points from
end-to-start, eliminating O(n²) array shifting (CQ-001).
- **Shortcut Cleaner** — COM objects (`IShellLink`, `IPersistFile`) now
released via `Marshal.ReleaseComObject` in finally block (SEC-006).

### Security
- **Speed Test** — improved download integrity comment and added
Authenticode signature verification on extracted speedtest.exe (SEC-001).

## [0.35.11] - 2026-05-12

### Fixed
Expand Down
70 changes: 70 additions & 0 deletions SysManager/SysManager.Tests/AppBlockerServiceValidationTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// SysManager · AppBlockerService input validation tests (no registry access)
using SysManager.Services;

namespace SysManager.Tests;

public class AppBlockerServiceValidationTests
{
[Theory]
[InlineData(null)]
[InlineData("")]
[InlineData(" ")]
public void BlockApp_NullOrWhitespace_ReturnsFalse(string? exeName)
{
Assert.False(AppBlockerService.BlockApp(exeName!));
}

[Theory]
[InlineData(@"..\..\windows\system32\cmd.exe")]
[InlineData(@"path\to\app.exe")]
[InlineData(@"folder/app.exe")]
[InlineData("app;malicious.exe")]
[InlineData("app&cmd.exe")]
[InlineData("app|pipe.exe")]
[InlineData("app<>.exe")]
[InlineData(@"app"".exe")]
public void BlockApp_InvalidCharsInName_ReturnsFalse(string exeName)
{
Assert.False(AppBlockerService.BlockApp(exeName));
}

[Theory]
[InlineData("notepad")]
[InlineData("notepad.exe")]
[InlineData("my-app.exe")]
[InlineData("My App.exe")]
[InlineData("app_v2.0.exe")]
public void BlockApp_ValidNames_FormatsCorrectly(string exeName)
{
// These are valid names but will fail because we don't have admin access.
// The important thing is they pass the validation check.
// The method returns false because of UnauthorizedAccessException,
// not because of invalid input. We can't distinguish in the return value,
// but we verify the format is accepted by checking IsBlocked (which also
// requires registry access and will return false gracefully).
var result = AppBlockerService.IsBlocked(exeName.EndsWith(".exe", StringComparison.OrdinalIgnoreCase) ? exeName : exeName + ".exe");
// IsBlocked reads registry - will return false if no access, but won't throw
Assert.False(result); // expected since nothing is actually blocked
}
Comment on lines +37 to +48

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

BlockApp_ValidNames_FormatsCorrectly doesn’t exercise BlockApp.

Line 45 calls IsBlocked, so this test doesn’t validate the BlockApp acceptance path its name describes. Replace it with a direct BlockApp call (and assert no-throw / expected false under non-admin) to keep coverage meaningful.

Suggested adjustment
- var result = AppBlockerService.IsBlocked(exeName.EndsWith(".exe", StringComparison.OrdinalIgnoreCase) ? exeName : exeName + ".exe");
- // IsBlocked reads registry - will return false if no access, but won't throw
- Assert.False(result); // expected since nothing is actually blocked
+ var normalized = exeName.EndsWith(".exe", StringComparison.OrdinalIgnoreCase)
+     ? exeName
+     : exeName + ".exe";
+ var ex = Record.Exception(() => AppBlockerService.BlockApp(normalized));
+ Assert.Null(ex);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@SysManager/SysManager.Tests/AppBlockerServiceValidationTests.cs` around lines
37 - 48, The test BlockApp_ValidNames_FormatsCorrectly is calling
AppBlockerService.IsBlocked instead of exercising the BlockApp acceptance path;
change the call to AppBlockerService.BlockApp (using the same exeName
normalization: append ".exe" when needed) and assert the expected behavior under
non-admin (e.g., that it does not throw and returns false/indicates failure due
to lack of privileges), rather than calling IsBlocked; keep the existing comment
about registry/admin behavior and adjust the Assert to verify BlockApp's
return/exception behavior accordingly.


[Fact]
public void GetBlockedApps_ReturnsListWithoutThrowing()
{
// Should not throw even without admin
var result = AppBlockerService.GetBlockedApps();
Assert.NotNull(result);
}

[Fact]
public void IsBlocked_EmptyName_ReturnsFalse()
{
Assert.False(AppBlockerService.IsBlocked(""));
}

[Fact]
public void IsBlocked_NormalExeName_DoesNotThrow()
{
var ex = Record.Exception(() => AppBlockerService.IsBlocked("notepad.exe"));
Assert.Null(ex);
}
}
122 changes: 122 additions & 0 deletions SysManager/SysManager.Tests/BatteryInfoEdgeCaseTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
// SysManager · BatteryInfo computed property edge-case tests
using SysManager.Models;

namespace SysManager.Tests;

public class BatteryInfoEdgeCaseTests
{
[Fact]
public void HealthPercent_ZeroDesignCapacity_ReturnsZero()
{
var info = new BatteryInfo { DesignCapacityMWh = 0, FullChargeCapacityMWh = 5000 };
Assert.Equal(0, info.HealthPercent);
}

[Fact]
public void HealthPercent_EqualCapacities_Returns100()
{
var info = new BatteryInfo { DesignCapacityMWh = 50000, FullChargeCapacityMWh = 50000 };
Assert.Equal(100.0, info.HealthPercent);
}

[Fact]
public void HealthPercent_HalfWorn_Returns50()
{
var info = new BatteryInfo { DesignCapacityMWh = 50000, FullChargeCapacityMWh = 25000 };
Assert.Equal(50.0, info.HealthPercent);
}

[Fact]
public void HealthPercent_NewBatteryOverDesign_ClampedTo100()
{
var info = new BatteryInfo { DesignCapacityMWh = 40000, FullChargeCapacityMWh = 44000 };
// QA-005 fix: clamped to 100 max
Assert.Equal(100, info.HealthPercent);
}

[Fact]
public void WearPercent_ZeroDesignCapacity_ReturnsZero()
{
var info = new BatteryInfo { DesignCapacityMWh = 0, FullChargeCapacityMWh = 5000 };
Assert.Equal(0, info.WearPercent);
}

[Fact]
public void WearPercent_EqualCapacities_ReturnsZero()
{
var info = new BatteryInfo { DesignCapacityMWh = 50000, FullChargeCapacityMWh = 50000 };
Assert.Equal(0, info.WearPercent);
}

[Fact]
public void WearPercent_HalfWorn_Returns50()
{
var info = new BatteryInfo { DesignCapacityMWh = 50000, FullChargeCapacityMWh = 25000 };
Assert.Equal(50.0, info.WearPercent);
}

[Fact]
public void WearPercent_NewBatteryOverDesign_ClampedToZero()
{
var info = new BatteryInfo { DesignCapacityMWh = 40000, FullChargeCapacityMWh = 44000 };
// QA-005 fix: clamped to 0 min
Assert.Equal(0, info.WearPercent);
}

[Fact]
public void RuntimeDisplay_PluggedIn_ShowsPluggedIn()
{
var info = new BatteryInfo { EstimatedRuntimeMinutes = -1 };
Assert.Equal("Plugged in", info.RuntimeDisplay);
}

[Fact]
public void RuntimeDisplay_Calculating_ShowsCalculating()
{
var info = new BatteryInfo { EstimatedRuntimeMinutes = 0 };
Assert.Contains("Calculating", info.RuntimeDisplay);
}

[Fact]
public void RuntimeDisplay_90Minutes_ShowsFormatted()
{
var info = new BatteryInfo { EstimatedRuntimeMinutes = 90 };
Assert.Equal("1h 30m", info.RuntimeDisplay);
}

[Fact]
public void RuntimeDisplay_60Minutes_ShowsFormatted()
{
var info = new BatteryInfo { EstimatedRuntimeMinutes = 60 };
Assert.Equal("1h 0m", info.RuntimeDisplay);
}

[Fact]
public void RuntimeDisplay_30Minutes_ShowsFormatted()
{
var info = new BatteryInfo { EstimatedRuntimeMinutes = 30 };
Assert.Equal("0h 30m", info.RuntimeDisplay);
}

[Fact]
public void PropertyChanged_FiredOnChargePercentChange()
{
var info = new BatteryInfo();
var changes = new List<string>();
info.PropertyChanged += (_, e) => changes.Add(e.PropertyName!);

info.ChargePercent = 75;

Assert.Contains("ChargePercent", changes);
}

[Fact]
public void DefaultValues_AllStringsEmpty()
{
var info = new BatteryInfo();
Assert.Equal("", info.Name);
Assert.Equal("", info.Status);
Assert.Equal("", info.Chemistry);
Assert.Equal("", info.Manufacturer);
}
}
156 changes: 156 additions & 0 deletions SysManager/SysManager.Tests/CleanupCategoryHumanSizeExtendedTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
// SysManager · CleanupCategory.HumanSize extended boundary tests
using SysManager.Models;

namespace SysManager.Tests;

public class CleanupCategoryHumanSizeExtendedTests
{
[Fact]
public void HumanSize_Zero_ReturnsZeroB()
{
Assert.Equal("0 B", CleanupCategory.HumanSize(0));
}

[Fact]
public void HumanSize_Negative_ReturnsZeroB()
{
Assert.Equal("0 B", CleanupCategory.HumanSize(-100));
}

[Fact]
public void HumanSize_OneByte_Returns1B()
{
Assert.Equal("1 B", CleanupCategory.HumanSize(1));
}

[Fact]
public void HumanSize_1023Bytes_Returns1023B()
{
Assert.Equal("1023 B", CleanupCategory.HumanSize(1023));
}

[Fact]
public void HumanSize_1024Bytes_Returns1KB()
{
Assert.Equal("1 KB", CleanupCategory.HumanSize(1024));
}

[Fact]
public void HumanSize_1MB_Returns1MB()
{
Assert.Equal("1 MB", CleanupCategory.HumanSize(1024 * 1024));
}

[Fact]
public void HumanSize_1GB_Returns1GB()
{
Assert.Equal("1 GB", CleanupCategory.HumanSize(1024L * 1024 * 1024));
}

[Fact]
public void HumanSize_1TB_Returns1TB()
{
Assert.Equal("1 TB", CleanupCategory.HumanSize(1024L * 1024 * 1024 * 1024));
}

[Fact]
public void HumanSize_1point5GB_FormatsCorrectly()
{
long bytes = (long)(1.5 * 1024 * 1024 * 1024);
Assert.Equal("1.5 GB", CleanupCategory.HumanSize(bytes));
}

[Fact]
public void HumanSize_LargeValue_StaysInTB()
{
long bytes = 10L * 1024 * 1024 * 1024 * 1024;
Assert.Equal("10 TB", CleanupCategory.HumanSize(bytes));
}

[Fact]
public void HumanSize_MaxLong_DoesNotThrow()
{
var result = CleanupCategory.HumanSize(long.MaxValue);
Assert.Contains("TB", result);
}

[Fact]
public void CleanupResult_Summary_NoErrors_FormatsCorrectly()
{
var result = new CleanupResult
{
BytesFreed = 1024 * 1024 * 50,
FilesDeleted = 100
};
Assert.Contains("50 MB", result.Summary);
Assert.Contains("100", result.Summary);
Assert.DoesNotContain("skipped", result.Summary);
}

[Fact]
public void CleanupResult_Summary_WithErrors_ShowsSkipped()
{
var result = new CleanupResult
{
BytesFreed = 1024 * 1024,
FilesDeleted = 10,
Errors = new[] { "err1", "err2" }
};
Assert.Contains("2 skipped", result.Summary);
}

[Fact]
public void LargeFileEntry_SizeDisplay_UsesHumanSize()
{
var entry = new LargeFileEntry
{
Path = @"C:\test\bigfile.iso",
Name = "bigfile.iso",
SizeBytes = 4_700_000_000,
LastModified = new DateTime(2024, 6, 15)
};
Assert.Contains("GB", entry.SizeDisplay);
}

[Fact]
public void LargeFileEntry_LastModifiedDisplay_FormatsCorrectly()
{
var entry = new LargeFileEntry
{
Path = @"C:\test\file.zip",
Name = "file.zip",
SizeBytes = 1000,
LastModified = new DateTime(2024, 3, 1)
};
Assert.Contains("2024", entry.LastModifiedDisplay);
Assert.Contains("Mar", entry.LastModifiedDisplay);
}
Comment on lines +116 to +127

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Locale-dependent assertions may be flaky across environments.

Line 126 ("Mar") and Line 154 ("1,500") assume English month names and comma group separators. These can fail on non-en-US test runners.

Suggested tweak
+using System.Globalization;
 using SysManager.Models;
@@
-        Assert.Contains("Mar", entry.LastModifiedDisplay);
+        Assert.Contains(
+            CultureInfo.CurrentCulture.DateTimeFormat.GetAbbreviatedMonthName(3),
+            entry.LastModifiedDisplay);
@@
-        Assert.Contains("1,500", cat.CountDisplay);
+        Assert.Contains(1500.ToString("N0", CultureInfo.CurrentCulture), cat.CountDisplay);

Also applies to: 144-155

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@SysManager/SysManager.Tests/CleanupCategoryHumanSizeExtendedTests.cs` around
lines 116 - 127, The tests assert locale-specific strings ("Mar" and "1,500")
which will fail on non-en-US runners; update the tests that reference
LargeFileEntry.LastModifiedDisplay and any size formatting assertions to either
(a) compare using an explicit invariant format (e.g., call
LastModified.ToString("MMM", CultureInfo.InvariantCulture) or use a specific
numeric format with CultureInfo.InvariantCulture) or (b) construct the expected
strings using CultureInfo.CurrentCulture before asserting so the test adapts to
the runner locale; locate uses of LargeFileEntry.LastModifiedDisplay and
SizeBytes/LastModified in the failing test methods and replace the hard-coded
"Mar" and "1,500" assertions with one of these locale-safe approaches.


[Fact]
public void CleanupCategory_SizeDisplay_ShowsHumanSize()
{
var cat = new CleanupCategory
{
Name = "Test",
Description = "Test category",
Paths = new[] { @"C:\temp" },
TotalSizeBytes = 2048,
FileCount = 5
};
Assert.Equal("2 KB", cat.SizeDisplay);
}

[Fact]
public void CleanupCategory_CountDisplay_FormatsWithCommas()
{
var cat = new CleanupCategory
{
Name = "Test",
Description = "Test category",
Paths = new[] { @"C:\temp" },
TotalSizeBytes = 0,
FileCount = 1500
};
Assert.Contains("1,500", cat.CountDisplay);
}
}
Loading
Loading