-
-
Notifications
You must be signed in to change notification settings - Fork 108
feat: add simple overload for attaching artifacts with optional display name and description #4078
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
Conversation
…ay name and description
Code Review - PR #4078SummaryThis PR adds a convenient overload for attaching test artifacts with just a file path, making the API more user-friendly. The implementation is clean and follows TUnit conventions. ✅ Strengths
🔍 Issues & RecommendationsCritical: Missing Input Validationvoid ITestOutput.AttachArtifact(string filePath, string? displayName, string? description)
{
var fileInfo = new FileInfo(filePath); // ⚠️ No validation
_artifactsBag.Add(new Artifact
{
File = fileInfo,
DisplayName = displayName ?? fileInfo.Name,
Description = description
});
}Problems:
Recommendation: void ITestOutput.AttachArtifact(string filePath, string? displayName, string? description)
{
ArgumentException.ThrowIfNullOrWhiteSpace(filePath); // C# 11+
var fileInfo = new FileInfo(filePath);
// Optional: Validate file exists (if this is a requirement)
// if (!fileInfo.Exists)
// throw new FileNotFoundException($"Artifact file not found: {filePath}", filePath);
_artifactsBag.Add(new Artifact
{
File = fileInfo,
DisplayName = displayName ?? fileInfo.Name,
Description = description
});
}Issue: Inconsistent API SurfaceThe existing public class Artifact
{
public required FileInfo File { get; init; }
public required string DisplayName { get; init; } // ⚠️ Required
public string? Description { get; init; }
}But the new overload makes // Original API: DisplayName required (compile error if omitted)
AttachArtifact(new Artifact { File = ..., DisplayName = "..." });
// New API: DisplayName optional
AttachArtifact("path.txt"); // Uses file nameRecommendation: This is acceptable if intentional (convenience overload provides sensible default), but consider whether Minor: Potential Performance ConsiderationDisplayName = displayName ?? fileInfo.Name
var fileName = fileInfo.Name;
_artifactsBag.Add(new Artifact
{
File = fileInfo,
DisplayName = displayName ?? fileName,
Description = description
});Impact: Negligible for artifact attachment (not a hot path), but good practice. Testing Gap: No Unit TestsThe PR includes integration tests in
Recommendation: Add unit tests in Documentation: Missing Error BehaviorThe XML documentation doesn't specify what happens if:
Recommendation: Update XML comments to document expected behavior: /// <param name="filePath">The path to the file to attach</param>
/// <exception cref="ArgumentNullException">When <paramref name="filePath"/> is null</exception>
/// <exception cref="ArgumentException">When <paramref name="filePath"/> is empty or contains invalid characters</exception>📊 Checklist Against CLAUDE.md
🎯 VerdictApprove with Recommendations The core implementation is solid and provides good developer experience. However, input validation is critically missing and should be added before merging to prevent runtime exceptions from common mistakes (null paths, typos, etc.). Before merging:
Nice-to-have:
Great work on the ergonomic improvement! 🚀 |
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.
Pull request overview
This PR adds a convenient overload to the AttachArtifact method that accepts a file path as a string along with optional display name and description parameters, simplifying the artifact attachment API for common use cases where users don't need to construct an Artifact object manually.
Key Changes:
- Added a new
AttachArtifactoverload that takes string parameters instead of requiring anArtifactobject - Updated documentation to demonstrate both the simple and full usage patterns
- Added test coverage for the new overload variations
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
TUnit.Core/Interfaces/ITestOutput.cs |
Added new overload signature to ITestOutput interface with XML documentation |
TUnit.Core/TestContext.Output.cs |
Implemented the new overload that creates FileInfo and Artifact objects internally |
docs/docs/test-lifecycle/artifacts.md |
Updated documentation to show the simple overload first, then the full Artifact object approach |
TUnit.TestProject/TestArtifactTests.cs |
Added two new tests covering the simple overload with and without custom display name/description |
TUnit.PublicAPI/*.verified.txt |
Updated public API snapshots for all target frameworks to reflect the new method signature |
| } | ||
|
|
||
| void ITestOutput.AttachArtifact(string filePath, string? displayName, string? description) | ||
| { |
Copilot
AI
Dec 14, 2025
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.
The filePath parameter should be validated for null or whitespace before creating a FileInfo object. Consider adding validation like ArgumentException.ThrowIfNullOrWhiteSpace(filePath) at the beginning of the method to provide a clear error message when an invalid path is provided, rather than allowing a potentially confusing exception from the FileInfo constructor.
| { | |
| { | |
| ArgumentException.ThrowIfNullOrWhiteSpace(filePath); |
No description provided.