From fa01b26f29fd3fa24e6c6ab0923e0c4f59533207 Mon Sep 17 00:00:00 2001 From: bgard68 <30295154+bgard68@users.noreply.github.com> Date: Mon, 24 Aug 2026 12:24:57 -0500 Subject: [PATCH] fix(tests): cleanup failures are reported, never swallowed silently MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The previous fix narrowed the catch types and left the bodies empty — trading cs/catch-of-all-exceptions for cs/empty-catch-block, which is the same defect wearing a different rule id. An empty catch discards the one piece of evidence anyone debugging a full temp disk would need. House rule, now standing: no empty catch blocks anywhere, tests included. A caught exception is accounted for or it is not caught. Cleanup failure here writes the leftover path and the reason to the test error output; the run still passes, because a temp directory surviving is survivable — invisibly surviving is not. Co-Authored-By: Claude Opus 5 --- .../GitHubInstallationTokenProviderTests.cs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/tests/DevSecOpsSentinel.Infrastructure.Tests/GitHubInstallationTokenProviderTests.cs b/tests/DevSecOpsSentinel.Infrastructure.Tests/GitHubInstallationTokenProviderTests.cs index 35c1b08..f860f5a 100644 --- a/tests/DevSecOpsSentinel.Infrastructure.Tests/GitHubInstallationTokenProviderTests.cs +++ b/tests/DevSecOpsSentinel.Infrastructure.Tests/GitHubInstallationTokenProviderTests.cs @@ -145,17 +145,18 @@ await Assert.ThrowsAsync( public void Dispose() { - // Best-effort cleanup of the per-test key directory; only the failures a - // filesystem delete can actually produce are worth swallowing. + // Best-effort cleanup of the per-test key directory. A failure must not fail + // the test run, but it is never silent: the leftover path and the reason go to + // the test output, because an empty catch discards the one piece of evidence + // anyone debugging a full temp disk would need. try { Directory.Delete(_keyDirectory, recursive: true); } - catch (IOException) - { - } - catch (UnauthorizedAccessException) + catch (Exception exception) when (exception is IOException or UnauthorizedAccessException) { + Console.Error.WriteLine( + $"Test cleanup left '{_keyDirectory}' behind: {exception.Message}"); } } }