Skip to content

Share One Log Capture Helper Across Test Classes - #1133

Merged
ptr727 merged 2 commits into
developfrom
1129-log-capture
Oct 31, 2026
Merged

ptr727 merged 2 commits into
developfrom
1129-log-capture

Conversation

@ptr727

@ptr727 ptr727 commented Oct 31, 2026 •

Copy link
Copy Markdown
Owner

Summary

Three test classes each kept their own Serilog capturing sink and swapped the global Log.Logger around an action. This moves them onto one shared helper, as #1129 asks.

  • PlexCleanerTests/LogCapture.cs. A new internal static class beside FakeTools. LogCapture.Capture(Action) sends Log.Logger to a private capturing sink at Verbose, runs the action, and puts the original logger back and disposes the capture logger in finally. It returns the events as IReadOnlyList<LogEvent>.
  • FfProbeLogTests, CleanupStepRepeatTests, ToolFailureLogFormatTests. Each drops its own CapturingSink, plus its Capture() or inline swap, and calls LogCapture.Capture(). All three stay in the Sequential collection, because the helper still swaps the global logger.

Behavior change

None. ToolFailureLogFormatTests used to capture at Serilog's default Information level and now captures at Verbose. Both LogFailedResult overloads log only at Error, and the test picks its event by the Failed execution of template, so the extra levels don't change what it asserts.

Tests

  • The full suite passes locally (445 tests), with CSharpier, the build, and dotnet format style --verify-no-changes --severity=info.
  • No other test carries its own capturing sink or Log.Logger swap. The only other Log.Logger = in the tests is the global setup in PlexCleanerFixture.

Comments label

This PR carries the comments label. It adds one line above LogCapture.Capture saying that it swaps the global Log.Logger, so every caller joins the Sequential collection. Copilot asked for that line, and the code can't enforce it.

Local Review

A frontier strict review ran on this head before the push and raised no findings. It checked the change of capture level, the Sequential collection's parallel-run setting, the return-type change, and whether any other site should move onto the helper. prose_lint --diff reported nothing. A second pass over 346bd4d, the comment fix, also raised nothing.

Closes on promotion: #1129

🤖 Generated with Claude Code

Three test classes each carried their own Serilog capturing sink and Log.Logger swap.
They now share LogCapture.Capture().

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Copilot AI lite review requested due to automatic review settings October 31, 2026 17:32
@ptr727

ptr727 commented Oct 31, 2026

Copy link
Copy Markdown
Owner Author

A recorded local strict-review pass covers head e179acf9e265c09a8db08bd5f1788bff9834838e, the content this pull request carries at that commit against develop, and it recorded 0 findings.

@coderabbitai

coderabbitai Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 18 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 2 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 815fac21-4418-4096-9700-5806229cdcc7
Commits

Reviewing files that changed from the base of the PR and between b1d2315 and 346bd4d.

Files selected for processing: 4
  • PlexCleanerTests/CleanupStepRepeatTests.cs
  • PlexCleanerTests/FfProbeLogTests.cs
  • PlexCleanerTests/LogCapture.cs
  • PlexCleanerTests/ToolFailureLogFormatTests.cs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

PR Summary by Qodo

Share log capture helper across test classes

🧪 Tests 🕐 10-20 Minutes

Grey Divider

AI Description

• Consolidates duplicated Serilog capture code into one test helper to simplify maintenance.
• Migrates three test classes while retaining global logger restoration and sequential execution.
• Captures at Verbose level; existing log assertions remain unchanged.
Diagram

graph TD
  Ff["FfProbe tests"] --> Helper(["LogCapture helper"]) --> Logger(["Global logger"]) --> Sink["Capturing sink"]
  Cleanup["Cleanup tests"] --> Helper
  Failure["Failure format tests"] --> Helper
Loading
High-Level Assessment

A shared test-only helper fits this repeated global-logger pattern. Keeping separate sinks would preserve duplication, while changing production logging to support injection would be disproportionate to this test refactor.

Files changed (4) +54 / -96

Refactor (3) +18 / -96
CleanupStepRepeatTests.csUse shared capture for cleanup-step log assertions +2/-32

Use shared capture for cleanup-step log assertions

• Removes the local sink and capture method. Both logging assertions now use LogCapture.Capture and read events through IReadOnlyList.

PlexCleanerTests/CleanupStepRepeatTests.cs

FfProbeLogTests.csUse shared capture for FfProbe log assertions +4/-33

Use shared capture for FfProbe log assertions

• Replaces the class-local sink and capture method with LogCapture.Capture for empty-output and error-level assertions.

PlexCleanerTests/FfProbeLogTests.cs

ToolFailureLogFormatTests.csCapture tool-failure logs through the shared helper +12/-31

Capture tool-failure logs through the shared helper

• Removes the inline sink and global logger swap. The rendering tests now select the failure event from LogCapture.Capture's result; capture includes Verbose events rather than starting at Serilog's default Information level.

PlexCleanerTests/ToolFailureLogFormatTests.cs

Other (1) +36 / -0
LogCapture.csAdd shared Serilog capture helper +36/-0

Add shared Serilog capture helper

• Adds a test helper that captures events at Verbose level while an action runs. It restores the original global logger and disposes the capture logger in a finally block.

PlexCleanerTests/LogCapture.cs

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider

Great, no issues found!

Qodo reviewed your code and found no material issues that require review

Grey Divider

Tip of the day
💡 Did you know, you can keep summaries lean with Findings visible per group, which tucks the rest behind a View link

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

Copilot AI 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.

🟡 Changes recommended

The only remaining active item is a nit in PlexCleanerTests/LogCapture.cs: the helper temporarily swaps the global Log.Logger without documenting that callers must stay in the Sequential test collection, so a comment is needed.

1 open issue
What changed in this PR

This PR moves three test classes onto one shared log capture helper. Before, each class had its own Serilog sink and swapped the global Log.Logger around an action. The new LogCapture.Capture(Action) does that swap in one place and returns the captured events. It addresses issue #1129.

Changes:

  • Adds PlexCleanerTests/LogCapture.cs, an internal static helper that captures events at Verbose and restores the original logger in finally.
  • Removes the per-class sinks and capture helpers from FfProbeLogTests and CleanupStepRepeatTests, and switches them to the shared helper.
  • Moves ToolFailureLogFormatTests onto the same helper. It now captures at Verbose instead of the default Information level. Its assertions still pick the same Failed execution of event, so the result does not change.
File Description
PlexCleanerTests/​ToolFailureLogFormatTests.cs Drops its local sink and inline logger swap, and calls the shared helper.
PlexCleanerTests/​LogCapture.cs New shared helper that swaps Log.Logger, captures events, and restores the logger.
PlexCleanerTests/​FfProbeLogTests.cs Removes the local sink and Capture helper, and uses the shared helper.
PlexCleanerTests/​CleanupStepRepeatTests.cs Removes the local sink and Capture helper, and uses the shared helper.

Review effort: Lite

Comment thread PlexCleanerTests/LogCapture.cs Resolved
@ptr727 ptr727 added the comments Permits the comment lines the pull request adds or edits, which the prose gate otherwise refuses label Oct 31, 2026
@ptr727

ptr727 commented Oct 31, 2026

Copy link
Copy Markdown
Owner Author

A recorded local strict-review pass covers head 346bd4d52d78b52739116e8c6ad9c3e2820bf473, the content this pull request carries at that commit against develop, and it recorded 0 findings.

@ptr727
ptr727 merged commit 91500d0 into develop Oct 31, 2026
23 checks passed
@ptr727
ptr727 deleted the 1129-log-capture branch October 31, 2026 17:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comments Permits the comment lines the pull request adds or edits, which the prose gate otherwise refuses

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants