Overview
The file src/Platform/Microsoft.Testing.Extensions.AzureDevOpsReport/AzureDevOpsTestResultsPublisher.cs has grown to 828 lines, making it harder to navigate and maintain. This task involves splitting it into smaller, single-responsibility partial classes.
Note: XxHashShared.cs (911 lines) is the technically larger file, but it is a verbatim port of dotnet/runtime code and is not a candidate for refactoring.
Current State
- File:
src/Platform/Microsoft.Testing.Extensions.AzureDevOpsReport/AzureDevOpsTestResultsPublisher.cs
- Size: 828 lines
- Language: C#
Structural Analysis
The file contains a single internal sealed class AzureDevOpsTestResultsPublisher that implements IDataConsumer, ITestSessionLifetimeHandler, and IDisposable. It mixes four distinct concerns in one file:
| Lines |
Responsibility |
| 1–286 |
Class declaration, fields, constructors, properties, lifecycle methods (Dispose, IsEnabledAsync, OnTestSessionStartingAsync, ConsumeAsync, OnTestSessionFinishingAsync) |
| 288–477 |
Test result & attachment factory — CreateTestCaseResult, BuildAttachmentsFromTestNode, TruncateInline, GetUtf8ByteCount, TryCreateRunAttachment, CreateResult, BuildTimeoutMessage |
| 473–673 |
Background flush & batch upload engine — BackgroundFlushLoopAsync, FlushPendingResultsAsync, BatchHasAttachments, ShouldFlushUnsafe, UploadPendingRunAttachmentsAsync, UploadResultAttachmentsAsync |
| 675–828 |
Publish configuration & environment resolution — TryCreatePublishConfiguration, GetRequiredEnvironmentVariable, GetRunName, SanitizeRunNameComponent, GetTargetFrameworkMoniker |
Refactoring Strategy
Because the type is sealed, the idiomatic C# approach is partial classes — no visibility changes required and no callers need updating.
Proposed File Splits
-
AzureDevOpsTestResultsPublisher.cs (~250 lines)
- Contents: all fields, both constructors, all properties,
Dispose, IsEnabledAsync, OnTestSessionStartingAsync, ConsumeAsync, OnTestSessionFinishingAsync
- Responsibility: Public contract entry-points — lifecycle coordination and data consumption
-
AzureDevOpsTestResultsPublisher.ResultFactory.cs (~190 lines)
- Contents:
CreateTestCaseResult, BuildAttachmentsFromTestNode, TruncateInline, GetUtf8ByteCount, TryCreateRunAttachment, CreateResult, BuildTimeoutMessage
- Responsibility: Transform
TestNode / SessionFileArtifact data into Azure DevOps API model objects
-
AzureDevOpsTestResultsPublisher.Flush.cs (~200 lines)
- Contents:
BackgroundFlushLoopAsync, FlushPendingResultsAsync, BatchHasAttachments, ShouldFlushUnsafe, UploadPendingRunAttachmentsAsync, UploadResultAttachmentsAsync
- Responsibility: Batching, back-pressure, and upload scheduling
-
AzureDevOpsTestResultsPublisher.Configuration.cs (~155 lines)
- Contents:
TryCreatePublishConfiguration, GetRequiredEnvironmentVariable, GetRunName, SanitizeRunNameComponent, GetTargetFrameworkMoniker
- Responsibility: Resolve ADO environment variables and build the
AzureDevOpsPublishConfiguration value
Implementation Guidelines
- Preserve Behavior: All existing functionality must work identically after the split
- Maintain Public API: No change to any
public or internal symbol names or accessibility
- Add
partial modifier: Add partial to the class declaration in each new file and in the existing file
- No new files elsewhere: No changes needed outside
src/Platform/Microsoft.Testing.Extensions.AzureDevOpsReport/
- Test After Each Split: Run
./build.sh -test after splitting each partial file to catch compile errors early
- One file at a time: Split one partial at a time to keep reviews manageable
Acceptance Criteria
Priority: Medium
Effort: Small (mechanical partial-class split; no logic changes required)
Expected Impact: Improved code navigability, easier code review, reduced merge conflicts on the publisher class
Generated by Daily File Diet · sonnet46 1M · ◷
Overview
The file
src/Platform/Microsoft.Testing.Extensions.AzureDevOpsReport/AzureDevOpsTestResultsPublisher.cshas grown to 828 lines, making it harder to navigate and maintain. This task involves splitting it into smaller, single-responsibility partial classes.Current State
src/Platform/Microsoft.Testing.Extensions.AzureDevOpsReport/AzureDevOpsTestResultsPublisher.csStructural Analysis
The file contains a single
internal sealed class AzureDevOpsTestResultsPublisherthat implementsIDataConsumer,ITestSessionLifetimeHandler, andIDisposable. It mixes four distinct concerns in one file:Dispose,IsEnabledAsync,OnTestSessionStartingAsync,ConsumeAsync,OnTestSessionFinishingAsync)CreateTestCaseResult,BuildAttachmentsFromTestNode,TruncateInline,GetUtf8ByteCount,TryCreateRunAttachment,CreateResult,BuildTimeoutMessageBackgroundFlushLoopAsync,FlushPendingResultsAsync,BatchHasAttachments,ShouldFlushUnsafe,UploadPendingRunAttachmentsAsync,UploadResultAttachmentsAsyncTryCreatePublishConfiguration,GetRequiredEnvironmentVariable,GetRunName,SanitizeRunNameComponent,GetTargetFrameworkMonikerRefactoring Strategy
Because the type is
sealed, the idiomatic C# approach is partial classes — no visibility changes required and no callers need updating.Proposed File Splits
AzureDevOpsTestResultsPublisher.cs(~250 lines)Dispose,IsEnabledAsync,OnTestSessionStartingAsync,ConsumeAsync,OnTestSessionFinishingAsyncAzureDevOpsTestResultsPublisher.ResultFactory.cs(~190 lines)CreateTestCaseResult,BuildAttachmentsFromTestNode,TruncateInline,GetUtf8ByteCount,TryCreateRunAttachment,CreateResult,BuildTimeoutMessageTestNode/SessionFileArtifactdata into Azure DevOps API model objectsAzureDevOpsTestResultsPublisher.Flush.cs(~200 lines)BackgroundFlushLoopAsync,FlushPendingResultsAsync,BatchHasAttachments,ShouldFlushUnsafe,UploadPendingRunAttachmentsAsync,UploadResultAttachmentsAsyncAzureDevOpsTestResultsPublisher.Configuration.cs(~155 lines)TryCreatePublishConfiguration,GetRequiredEnvironmentVariable,GetRunName,SanitizeRunNameComponent,GetTargetFrameworkMonikerAzureDevOpsPublishConfigurationvalueImplementation Guidelines
publicorinternalsymbol names or accessibilitypartialmodifier: Addpartialto the class declaration in each new file and in the existing filesrc/Platform/Microsoft.Testing.Extensions.AzureDevOpsReport/./build.sh -testafter splitting each partial file to catch compile errors earlyAcceptance Criteria
AzureDevOpsTestResultsPublisher.csis split into four focused partial-class files./build.sh -test)AzureDevOpsReportproject directoryPriority: Medium
Effort: Small (mechanical partial-class split; no logic changes required)
Expected Impact: Improved code navigability, easier code review, reduced merge conflicts on the publisher class