Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,15 @@ .. orderedInputs.Select(input => $"{Path.GetFullPath(input.Path)}\0{input.Execut
];
Guid artifactId = CtrfReportMerger.CreateDeterministicId(identityInputs);
string mergedDirectory = Path.Combine(outputDirectory, MergedReportDirectoryName);
Directory.CreateDirectory(mergedDirectory);
try
{
Directory.CreateDirectory(mergedDirectory);
}
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException)
{
return null;
}

if (ArtifactPostProcessingHelper.IsReparsePoint(mergedDirectory))
{
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,15 @@ .. ArtifactPostProcessingHelper.OrderInputs(inputs, includeModuleMetadata: false
// outside the supplied output directory (Directory.CreateDirectory succeeds on an existing link).
// Materialize the directory here and refuse to merge through a reparse point instead. Returning
// null leaves the per-module reports untouched, matching the never-fail-the-run invariant.
Directory.CreateDirectory(mergedDirectory);
try
{
Directory.CreateDirectory(mergedDirectory);
}
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException)
{
return null;
}

if (ArtifactPostProcessingHelper.IsReparsePoint(mergedDirectory))
{
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,34 @@ public async Task ProcessAsync_WithDifferentExecutionProvenance_ProducesDifferen
}
}

[TestMethod]
public async Task ProcessAsync_WhenMergedPathIsAFile_DoesNotMerge()
{
string root = CreateTemporaryDirectory();
string resultsDirectory = Path.Combine(root, "results");
Directory.CreateDirectory(resultsDirectory);
File.WriteAllText(Path.Combine(resultsDirectory, "merged"), string.Empty);
try
{
string firstPath = WriteReport(resultsDirectory, "first.ctrf.json", "first");
string secondPath = WriteReport(resultsDirectory, "second.ctrf.json", "second");

ProcessedArtifact? output = await new CtrfArtifactPostProcessor().ProcessAsync(
[CreateInput(firstPath, "execution-1"), CreateInput(secondPath, "execution-2")],
resultsDirectory,
new ArtifactPostProcessingContext(ArtifactPostProcessingTruncationReason.None),
CancellationToken.None);

Assert.IsNull(output);
Assert.IsTrue(File.Exists(firstPath));
Assert.IsTrue(File.Exists(secondPath));
}
finally
{
Directory.Delete(root, recursive: true);
}
}

#if NETCOREAPP
[TestMethod]
public async Task ProcessAsync_WhenMergedDirectoryIsAReparsePoint_DoesNotMerge()
Expand Down Expand Up @@ -262,6 +290,45 @@ public async Task ProcessAsync_WhenMergedDirectoryIsAReparsePoint_DoesNotMerge()
Directory.Delete(root, recursive: true);
}
}

[TestMethod]
public async Task ProcessAsync_WhenMergedDirectoryIsADanglingReparsePoint_DoesNotMerge()
{
string root = CreateTemporaryDirectory();
string resultsDirectory = Path.Combine(root, "results");
string missingDirectory = Path.Combine(root, "missing");
Directory.CreateDirectory(resultsDirectory);
try
{
try
{
Directory.CreateSymbolicLink(Path.Combine(resultsDirectory, "merged"), missingDirectory);
}
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException or PlatformNotSupportedException)
{
Assert.Inconclusive("Host cannot create directory symbolic links.");
return;
}

string firstPath = WriteReport(resultsDirectory, "first.ctrf.json", "first");
string secondPath = WriteReport(resultsDirectory, "second.ctrf.json", "second");

ProcessedArtifact? output = await new CtrfArtifactPostProcessor().ProcessAsync(
[CreateInput(firstPath, "execution-1"), CreateInput(secondPath, "execution-2")],
resultsDirectory,
new ArtifactPostProcessingContext(ArtifactPostProcessingTruncationReason.None),
CancellationToken.None);

Assert.IsNull(output);
Assert.IsTrue(File.Exists(firstPath));
Assert.IsTrue(File.Exists(secondPath));
Assert.IsFalse(Directory.Exists(missingDirectory));
}
finally
{
Directory.Delete(root, recursive: true);
}
}
#endif

private static InputArtifact CreateInput(string path, string executionId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,39 @@ public async Task ProcessAsync_NestsAttachmentDeploymentRootBesideTheMergedRepor
}
}

[TestMethod]
public async Task ProcessAsync_WhenMergedPathIsAFile_DoesNotMerge()
{
string root = Path.Combine(Path.GetTempPath(), $"trx-post-processor-{Guid.NewGuid():N}");
string resultsDirectory = Path.Combine(root, "results");
Directory.CreateDirectory(resultsDirectory);
File.WriteAllText(Path.Combine(resultsDirectory, "merged"), string.Empty);
try
{
string firstPath = Path.Combine(resultsDirectory, "first.trx");
string secondPath = Path.Combine(resultsDirectory, "second.trx");
WriteMinimalReport(firstPath, "first");
WriteMinimalReport(secondPath, "second");

ProcessedArtifact? output = await new TrxArtifactPostProcessor().ProcessAsync(
[
new InputArtifact(firstPath, TrxReportEngine.TrxArtifactKind, null, null, null, "execution-1"),
new InputArtifact(secondPath, TrxReportEngine.TrxArtifactKind, null, null, null, "execution-2"),
],
resultsDirectory,
new ArtifactPostProcessingContext(ArtifactPostProcessingTruncationReason.None),
CancellationToken.None);

Assert.IsNull(output);
Assert.IsTrue(File.Exists(firstPath));
Assert.IsTrue(File.Exists(secondPath));
}
finally
{
Directory.Delete(root, recursive: true);
}
}

#if NETCOREAPP
[TestMethod]
public async Task ProcessAsync_WhenMergedDirectoryIsAReparsePoint_DoesNotMerge()
Expand Down Expand Up @@ -226,6 +259,50 @@ public async Task ProcessAsync_WhenMergedDirectoryIsAReparsePoint_DoesNotMerge()
Directory.Delete(root, recursive: true);
}
}

[TestMethod]
public async Task ProcessAsync_WhenMergedDirectoryIsADanglingReparsePoint_DoesNotMerge()
{
string root = Path.Combine(Path.GetTempPath(), $"trx-post-processor-{Guid.NewGuid():N}");
string resultsDirectory = Path.Combine(root, "results");
string missingDirectory = Path.Combine(root, "missing");
Directory.CreateDirectory(resultsDirectory);
try
{
try
{
Directory.CreateSymbolicLink(Path.Combine(resultsDirectory, "merged"), missingDirectory);
}
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException or PlatformNotSupportedException)
{
Assert.Inconclusive("Host cannot create directory symbolic links.");
return;
}

string firstPath = Path.Combine(resultsDirectory, "first.trx");
string secondPath = Path.Combine(resultsDirectory, "second.trx");
WriteMinimalReport(firstPath, "first");
WriteMinimalReport(secondPath, "second");

ProcessedArtifact? output = await new TrxArtifactPostProcessor().ProcessAsync(
[
new InputArtifact(firstPath, TrxReportEngine.TrxArtifactKind, null, null, null, "execution-1"),
new InputArtifact(secondPath, TrxReportEngine.TrxArtifactKind, null, null, null, "execution-2"),
],
resultsDirectory,
new ArtifactPostProcessingContext(ArtifactPostProcessingTruncationReason.None),
CancellationToken.None);

Assert.IsNull(output);
Assert.IsTrue(File.Exists(firstPath));
Assert.IsTrue(File.Exists(secondPath));
Assert.IsFalse(Directory.Exists(missingDirectory));
}
finally
{
Directory.Delete(root, recursive: true);
}
}
#endif

[TestMethod]
Expand Down