Skip to content

test: improve test quality — [Collection] isolation, locale-safe assertions, stronger sanitize check#368

Merged
laurentiu021 merged 1 commit into
mainfrom
fix/test-quality
May 15, 2026
Merged

test: improve test quality — [Collection] isolation, locale-safe assertions, stronger sanitize check#368
laurentiu021 merged 1 commit into
mainfrom
fix/test-quality

Conversation

@laurentiu021

@laurentiu021 laurentiu021 commented May 15, 2026

Copy link
Copy Markdown
Owner

Summary

Addresses 3 test quality issues flagged by CodeRabbit.

Changes

OperationLockServiceEdgeCaseTests

  • Added [Collection(OperationLock)] to prevent parallel execution against shared singleton
  • PropertyChanged handler now unsubscribed in finally block to prevent callback leaks

CleanupCategoryHumanSizeExtendedTests

  • Replaced hardcoded Mar assertion with culture-aware month format to prevent failures on non-English locales

LogServiceSanitizeEdgeCaseTests

  • Renamed test to ReplacesAll and added DoesNotContain assertions for both usernames to verify complete sanitization

No release triggered

test: prefix — no version bump.

Summary by CodeRabbit

  • Tests
    • Fixed locale-dependent test failure by dynamically computing expected date format.
    • Enhanced path sanitization test to verify all user occurrences are replaced, not just the first.
    • Improved test reliability by using explicit event handler management instead of inline lambdas.

Review Change Stack

@coderabbitai

coderabbitai Bot commented May 15, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

Three test files receive focused updates: LogServiceSanitizeEdgeCaseTests changes test assertions for user-path sanitization behavior, OperationLockServiceEdgeCaseTests adds test collection organization and refactors event handler patterns, and CleanupCategoryHumanSizeExtendedTests fixes culture-dependent date formatting in assertions.

Changes

Test Suite Updates

Layer / File(s) Summary
LogService sanitization all-user-replacement test
SysManager/SysManager.Tests/LogServiceSanitizeEdgeCaseTests.cs
SanitizePath_MultipleUsersInPath_ReplacesAll test verifies LogService.SanitizePath removes all user occurrences from a path, with explicit assertions that both original usernames (alice, bob) are absent and the [user] placeholder is present.
OperationLockService test collection and event handler refactoring
SysManager/SysManager.Tests/OperationLockServiceEdgeCaseTests.cs
OperationLockServiceEdgeCaseTests class tagged with [Collection("OperationLock")] attribute; PropertyChanged_FiredOnAcquire refactored to use explicit named handler delegate for subscription/unsubscription instead of inline lambda, preserving assertions on property-change events during acquire and dispose.
CleanupCategory culture-aware date formatting test
SysManager/SysManager.Tests/CleanupCategoryHumanSizeExtendedTests.cs
LargeFileEntry_LastModifiedDisplay_FormatsCorrectly test now computes expected month abbreviation ("MMM") using CultureInfo.CurrentCulture instead of hard-coded "Mar", preventing locale-dependent test failures.

🎯 2 (Simple) | ⏱️ ~10 minutes

🐰 Three tests now fixed with care,
No hard-coded months in the air!
Sanitize all the names,
Event handlers tamed,
Culture-aware everywhere!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly matches the main objectives: it lists the three primary improvements (Collection isolation, locale-safe assertions, stronger sanitize check) made across the test files.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/test-quality

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with 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.

Inline comments:
In `@SysManager/SysManager.Tests/LogServiceSanitizeEdgeCaseTests.cs`:
- Around line 42-47: Replace the loose assertions in
SanitizePath_MultipleUsersInPath_ReplacesAll so the test checks the exact
sanitized output from LogService.SanitizePath instead of just
contains/does-not-contain; assert that result equals the expected string
"C:\Users\[user]\backup\C:\Users\[user]\file.txt" (use the same
verbatim/backslash format as the input) by replacing
Assert.Contains/DoesNotContain calls with a single Assert.Equal(expected,
result) against that exact expected value.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 8647737e-b32a-4e5a-9fa3-46c4d9e69a3b

📥 Commits

Reviewing files that changed from the base of the PR and between 0d17a3c and 4c4c74f.

📒 Files selected for processing (3)
  • SysManager/SysManager.Tests/CleanupCategoryHumanSizeExtendedTests.cs
  • SysManager/SysManager.Tests/LogServiceSanitizeEdgeCaseTests.cs
  • SysManager/SysManager.Tests/OperationLockServiceEdgeCaseTests.cs
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Build & unit tests
  • GitHub Check: Analyze (csharp)
🔇 Additional comments (3)
SysManager/SysManager.Tests/OperationLockServiceEdgeCaseTests.cs (2)

6-6: LGTM!


121-136: LGTM!

SysManager/SysManager.Tests/CleanupCategoryHumanSizeExtendedTests.cs (1)

126-128: LGTM!

Comment on lines +42 to +47
public void SanitizePath_MultipleUsersInPath_ReplacesAll()
{
var result = LogService.SanitizePath(@"C:\Users\alice\backup\C:\Users\bob\file.txt");
Assert.Contains("[user]", result);
Assert.DoesNotContain("alice", result);
Assert.DoesNotContain("bob", result);

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

Tighten this test to verify the exact sanitized output.

At Line 45–Line 47, the current checks can still pass if usernames are removed instead of both being replaced with [user]. Since the test is ReplacesAll, assert the full expected string.

✅ Suggested change
     var result = LogService.SanitizePath(@"C:\Users\alice\backup\C:\Users\bob\file.txt");
-    Assert.Contains("[user]", result);
-    Assert.DoesNotContain("alice", result);
-    Assert.DoesNotContain("bob", result);
+    Assert.Equal(@"C:\Users\[user]\backup\C:\Users\[user]\file.txt", result);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
public void SanitizePath_MultipleUsersInPath_ReplacesAll()
{
var result = LogService.SanitizePath(@"C:\Users\alice\backup\C:\Users\bob\file.txt");
Assert.Contains("[user]", result);
Assert.DoesNotContain("alice", result);
Assert.DoesNotContain("bob", result);
public void SanitizePath_MultipleUsersInPath_ReplacesAll()
{
var result = LogService.SanitizePath(@"C:\Users\alice\backup\C:\Users\bob\file.txt");
Assert.Equal(@"C:\Users\[user]\backup\C:\Users\[user]\file.txt", result);
}
🤖 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/LogServiceSanitizeEdgeCaseTests.cs` around lines
42 - 47, Replace the loose assertions in
SanitizePath_MultipleUsersInPath_ReplacesAll so the test checks the exact
sanitized output from LogService.SanitizePath instead of just
contains/does-not-contain; assert that result equals the expected string
"C:\Users\[user]\backup\C:\Users\[user]\file.txt" (use the same
verbatim/backslash format as the input) by replacing
Assert.Contains/DoesNotContain calls with a single Assert.Equal(expected,
result) against that exact expected value.

@laurentiu021
laurentiu021 merged commit 46bdc9b into main May 15, 2026
5 checks passed
@laurentiu021
laurentiu021 deleted the fix/test-quality branch May 15, 2026 06:12
@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants