-
-
Notifications
You must be signed in to change notification settings - Fork 2
fix: code review batch 2 — IDialogService, QA/security fixes #252
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
SysManager/SysManager.Tests/AppBlockerServiceValidationTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| } | ||
|
|
||
| [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
122
SysManager/SysManager.Tests/BatteryInfoEdgeCaseTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
156
SysManager/SysManager.Tests/CleanupCategoryHumanSizeExtendedTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Locale-dependent assertions may be flaky across environments. Line 126 ( 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 |
||
|
|
||
| [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); | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BlockApp_ValidNames_FormatsCorrectlydoesn’t exerciseBlockApp.Line 45 calls
IsBlocked, so this test doesn’t validate theBlockAppacceptance path its name describes. Replace it with a directBlockAppcall (and assert no-throw / expected false under non-admin) to keep coverage meaningful.Suggested adjustment
🤖 Prompt for AI Agents