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
391 changes: 391 additions & 0 deletions docs/decisions/ci-diagnostic-context.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ static TProperty GetSingleOrDefaultValue<TProperty>(TProperty? existingProperty,
isFlaky);
_rows.Add(new SummaryRow(
uid,
new TestRecord(displayName, fullyQualifiedName, kind, duration, isFlaky, failure),
new TestRecord(displayName, fullyQualifiedName, kind, duration, isFlaky, failure,
kind == TerminalKind.Skipped ? state?.Explanation : null),
historyTest,
dependencies));
if (isFlaky)
Expand Down Expand Up @@ -380,7 +381,8 @@ private void ClearFlakyRows(string uid)
record.Kind,
record.Duration,
isFlaky: false,
record.Failure);
record.Failure,
record.SkipReason);
row.HistoryTest?.IsFlaky = false;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Microsoft.Testing.Extensions.AzureDevOpsReport.Resources;
using Microsoft.Testing.Platform;

namespace Microsoft.Testing.Extensions.AzureDevOpsReport;
Expand All @@ -25,7 +26,9 @@ internal static string BuildAggregateMarkdown(CiRunSummaryAggregate aggregate)
aggregate.SkippedTests,
aggregate.FlakyTests.Count,
aggregate.Duration,
aggregate.ExitCode);
aggregate.HasAuthoritativeRunSummary ? null : aggregate.ExitCode,
isRunElapsed: true);
CiRunSummaryExitCode.AppendRunnerPolicy(builder, aggregate, AzureDevOpsResources.ResourceManager);
if (aggregate.IsPartial)
{
builder.Append("> **Partial summary:** the test run was truncated.\n\n");
Expand All @@ -38,9 +41,10 @@ internal static string BuildAggregateMarkdown(CiRunSummaryAggregate aggregate)
CiCoverageSummary.AppendMarkdown(builder, aggregate.Coverage, headingLevel: 3);
AppendHistoryMarkdown(builder, aggregate.Modules, headingLevel: 3);
AppendDependenciesMarkdown(builder, aggregate.Modules, headingLevel: 3);
AppendSkipReasonsMarkdown(builder, aggregate.Modules, headingLevel: 3);

builder.Append("### Test modules\n\n");
builder.Append("| Result | Test module | Total | Passed | Failed | Skipped | Flaky | Duration |\n");
builder.Append("| Result | Test module | Total | Passed | Failed | Skipped | Flaky | Test time |\n");
builder.Append("| :---: | --- | ---: | ---: | ---: | ---: | ---: | ---: |\n");
CiRunSummaryModule[] orderedModules =
[
Expand All @@ -66,6 +70,7 @@ .. aggregate.Modules
}

builder.Append('\n');
builder.Append(TestTimeExplanation);

int remainingFailureDetails = MaxAggregateFailureDetails;
CiRunSummaryModule[] modulesWithFailures =
Expand Down Expand Up @@ -107,7 +112,7 @@ .. aggregate.Modules
{
builder.Append("- **").Append(FormatDuration(TimeSpan.FromTicks(test.DurationTicks))).Append("** — ")
.Append(FormatTestName(test.DisplayName))
.Append(" — ");
.Append(" — ").Append(test.Outcome ?? "outcome unavailable").Append(" — ");
AppendModuleIdentity(builder, aggregate.Modules, module);
builder.Append('\n');
}
Expand Down Expand Up @@ -212,13 +217,14 @@ .. module.Failures
AppendDependenciesMarkdown(builder, [module], headingLevel);
}

if (module.SlowestTests.Length > 0)
if (includeInsights && module.SlowestTests.Length > 0)
{
builder.Append(heading).Append(" ⏱ Slowest tests\n\n");
foreach (CiRunSummaryTest test in module.SlowestTests)
{
builder.Append("- **").Append(FormatDuration(TimeSpan.FromTicks(test.DurationTicks))).Append("** — ")
.Append(FormatTestName(test.DisplayName)).Append('\n');
.Append(FormatTestName(test.DisplayName))
.Append(" — ").Append(test.Outcome ?? "outcome unavailable").Append('\n');
}

builder.Append('\n');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ private static void AppendStatusStrip(
long skipped,
long flaky,
TimeSpan? duration,
int? exitCode)
int? exitCode,
bool isRunElapsed)
{
builder.Append("**").Append(total.ToString(CultureInfo.InvariantCulture))
.Append(total == 1 ? " test**" : " tests**")
Expand All @@ -31,7 +32,8 @@ private static void AppendStatusStrip(
builder.Append(" · ⚠ **").Append(flaky.ToString(CultureInfo.InvariantCulture)).Append(" flaky**");
}

builder.Append(" · ⏱ **").Append(duration is { } value ? FormatDuration(value) : "Unavailable").Append("**");
builder.Append(isRunElapsed ? " · ⏱ Elapsed: **" : " · ⏱ Test time: **")
.Append(duration is { } value ? FormatDuration(value) : "Unavailable").Append("**");
if (exitCode is int processExitCode && processExitCode != 0)
{
builder.Append(" · exit code **").Append(processExitCode.ToString(CultureInfo.InvariantCulture)).Append("** (");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ .. modules
];

string heading = new('#', headingLevel);
if (durationHistory.Length == 0 && modules.Any(static module => module.TotalTests > 0))
{
builder.Append("> Duration history unavailable for the observed tests; current timings are not a historical baseline.\n\n");
}

if (flakyHistory.Length > 0)
{
builder.Append(heading).Append(" Flakiness history\n\n");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

namespace Microsoft.Testing.Extensions.AzureDevOpsReport;

internal sealed partial class AzureDevOpsSummaryReporter
{
private static void AppendSkipReasonsMarkdown(
StringBuilder builder,
IReadOnlyList<CiRunSummaryModule> modules,
int headingLevel)
{
long skippedTests = modules.Sum(static module => module.SkippedTests);
if (skippedTests == 0)
{
return;
}

(CiRunSummaryModule Module, CiRunSummarySkipReason Reason)[] reasons =
[
.. modules
.Where(static module => module.SkippedTests > 0)
.SelectMany(static module => (module.SkipReasons
?? [new CiRunSummarySkipReason { Reason = "Skip reason unavailable (older fragment)", Count = module.SkippedTests }])
.Select(reason => (Module: module, Reason: reason)))
.OrderByDescending(static item => item.Reason.Count)
.ThenBy(static item => item.Reason.Reason, StringComparer.Ordinal)
.ThenBy(static item => item.Module.AssemblyName, StringComparer.Ordinal)
.ThenBy(static item => item.Module.TargetFramework, StringComparer.Ordinal)
.ThenBy(static item => item.Module.Architecture, StringComparer.Ordinal)
.ThenBy(static item => item.Module.AttemptNumber)
.ThenBy(static item => item.Module.SessionUid, StringComparer.Ordinal)
.Take(MaxSkipReasonRows),
];

builder.Append(new string('#', headingLevel)).Append(" Skipped tests by reason\n\n");
builder.Append("| Skipped | Reason | Platform | Test module |\n");
builder.Append("| ---: | --- | --- | --- |\n");
foreach ((CiRunSummaryModule module, CiRunSummarySkipReason reason) in reasons)
{
builder.Append("| ").Append(reason.Count.ToString(CultureInfo.InvariantCulture))
.Append(" | ").Append(EscapeCell(reason.Reason))
.Append(" | ").Append(EscapeCell(module.OperatingSystem ?? "Unavailable"))
.Append(" | ");
AppendModuleIdentity(builder, modules, module);
builder.Append(" |\n");
}

builder.Append('\n');
long omittedTests = skippedTests - reasons.Sum(static item => item.Reason.Count);
if (omittedTests > 0)
{
builder.Append("> ").Append(omittedTests.ToString(CultureInfo.InvariantCulture))
.Append(" additional skipped tests are not shown.\n\n");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ internal sealed partial class AzureDevOpsSummaryReporter
private const int MaxDependencies = 50;
private const int MaxAggregateFailureDetails = 20;
private const int MaxSlowestTests = 10;
private const int MaxSkipReasonRows = 10;
private const string TestTimeExplanation = "> Test time is the sum of reported test durations, not elapsed time; tests may run concurrently.\n\n";

internal static /* for testing */ string BuildMarkdown(
IReadOnlyList<TestRecord> records,
Expand Down Expand Up @@ -52,8 +54,11 @@ private static string BuildMarkdown(CiRunSummaryModule module)
module.SkippedTests,
module.FlakyTests.Length,
TimeSpan.FromTicks(module.TestDurationTicks),
module.ExitCode);
module.ExitCode,
isRunElapsed: false);
builder.Append(TestTimeExplanation);
CiCoverageSummary.AppendMarkdown(builder, module.Coverage, headingLevel: 3);
AppendSkipReasonsMarkdown(builder, [module], headingLevel: 3);
_ = AppendModuleDiagnostics(
builder,
module,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#nullable enable
*REMOVED*Microsoft.Testing.Extensions.TestRecord.TestRecord(string! displayName, string! fullyQualifiedName, Microsoft.Testing.Extensions.TerminalKind kind, System.TimeSpan duration, bool isFlaky, Microsoft.Testing.Extensions.TestFailureDetails? failure = null) -> void
Microsoft.Testing.Extensions.TestRecord.TestRecord(string! displayName, string! fullyQualifiedName, Microsoft.Testing.Extensions.TerminalKind kind, System.TimeSpan duration, bool isFlaky, Microsoft.Testing.Extensions.TestFailureDetails? failure) -> void
Microsoft.Testing.Extensions.TestRecord.SkipReason.get -> string?
Microsoft.Testing.Extensions.TestRecord.TestRecord(string! displayName, string! fullyQualifiedName, Microsoft.Testing.Extensions.TerminalKind kind, System.TimeSpan duration, bool isFlaky, Microsoft.Testing.Extensions.TestFailureDetails? failure, string? skipReason) -> void
*REMOVED*const Microsoft.Testing.Extensions.AzureDevOpsReport.AzureDevOpsLivePublishingConstants.MaxAttachmentSizeBytes = 16777216 -> long
const Microsoft.Testing.Extensions.AzureDevOpsReport.AzureDevOpsLivePublishingConstants.MaxAttachmentSizeBytes = 78643200 -> long
static Microsoft.Testing.Extensions.TestNodeIdentity.GetDisplayLabel(string! identity, string! displayName) -> string!
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ This package extends Microsoft.Testing.Platform with:

The Markdown summary is independent from the self-contained HTML report produced by `--report-html`. Both options can be enabled together: Azure DevOps renders the Markdown in the Extensions tab, while the HTML remains a report file that can be published as a build artifact or displayed by a separately installed Azure DevOps web extension.

The aggregate contains one top-ten slowest-test list across modules, including failed tests and their outcomes, module names, and target frameworks. **Elapsed** is the SDK-reported run duration; each module's **test time** is the sum of reported test durations and may exceed elapsed time when tests run concurrently. Missing duration history is explicitly unavailable, not a baseline for comparison.

When the SDK supplies an authoritative final invocation exit, the aggregate shows it separately as **Runner policy**, including exit `0`. A policy such as `--ignore-exit-code 2` can accept an invocation that still contains failed tests: the test-result indicator, failed counts and failure details remain unchanged. Partial runs keep their warning; older fragments without authoritative context do not invent a policy verdict.

Skipped tests are grouped by their reported reason and execution platform, with module/target-framework context and at most ten groups shown. Issue references in reasons are retained; skipped test names are not dumped into the summary. Omitted groups are accounted for by a skipped-test count. Older summary fragments remain supported and label unavailable outcomes, skip reasons, and platform metadata explicitly.

## Usage

Enable Azure DevOps reporting with the `--report-azdo` command line option.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ internal static AggregateRenderResult BuildAggregateMarkdown(

if ((sections & GitHubActionsStepSummarySections.TestResults) != 0)
{
CiRunSummaryExitCode.AppendRunnerPolicy(builder, aggregate, GitHubActionsResources.ResourceManager);
if (aggregate.IsPartial)
{
builder.Append("> [!WARNING]\n> This summary is partial because the test run was truncated.\n\n");
Expand All @@ -54,15 +55,16 @@ internal static AggregateRenderResult BuildAggregateMarkdown(
builder.Append("> [!NOTE]\n> Counts reflect the observed module fragments. The outer `dotnet test` duration and exit verdict were not supplied by the SDK.\n\n");
}

if (aggregate.ExitCode is int authoritativeExitCode
&& !GitHubActionsExitCode.IsTestResultOutcome(authoritativeExitCode))
if (!aggregate.HasAuthoritativeRunSummary
&& aggregate.ExitCode is int observedExitCode
&& !GitHubActionsExitCode.IsTestResultOutcome(observedExitCode))
{
string calloutText = string.Format(
CultureInfo.InvariantCulture,
GitHubActionsResources.ExitCodeCallout,
authoritativeExitCode.ToString(CultureInfo.InvariantCulture),
GitHubActionsExitCode.GetName(authoritativeExitCode),
GitHubActionsExitCode.GetReason(authoritativeExitCode));
observedExitCode.ToString(CultureInfo.InvariantCulture),
GitHubActionsExitCode.GetName(observedExitCode),
GitHubActionsExitCode.GetReason(observedExitCode));
builder.Append("> [!WARNING]\n> ").Append(GitHubActionsFailureDetails.EscapeInlineCode(calloutText)).Append("\n\n");
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
#nullable enable
*REMOVED*Microsoft.Testing.Extensions.TestRecord.TestRecord(string! displayName, string! fullyQualifiedName, Microsoft.Testing.Extensions.TerminalKind kind, System.TimeSpan duration, bool isFlaky, Microsoft.Testing.Extensions.TestFailureDetails? failure = null) -> void
Microsoft.Testing.Extensions.TestRecord.TestRecord(string! displayName, string! fullyQualifiedName, Microsoft.Testing.Extensions.TerminalKind kind, System.TimeSpan duration, bool isFlaky, Microsoft.Testing.Extensions.TestFailureDetails? failure) -> void
Microsoft.Testing.Extensions.TestRecord.SkipReason.get -> string?
Microsoft.Testing.Extensions.TestRecord.TestRecord(string! displayName, string! fullyQualifiedName, Microsoft.Testing.Extensions.TerminalKind kind, System.TimeSpan duration, bool isFlaky, Microsoft.Testing.Extensions.TestFailureDetails? failure, string? skipReason) -> void
static Microsoft.Testing.Extensions.TestNodeIdentity.GetDisplayLabel(string! identity, string! displayName) -> string!
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ Job-summary test names retain their fully qualified method names and include fra
>
> Cross-module aggregation is negotiated with `dotnet test`. If the SDK does not provide the authoritative run-summary context, the extension keeps its standalone behavior; a manually invoked post-processor labels totals as observed and leaves overall duration and exit verdict unavailable rather than reconstructing them.

When authoritative context is available, the aggregate labels the final invocation outcome and exit separately as **Runner policy**, including exit `0`. Exit-code policies do not rewrite failed test results or remove their details. The existing `on-failure` behavior retains visibility for actual failed tests and partial runs even when runner policy accepts the invocation; it is not an exit-code-only suppression switch.

### Running through `dotnet test`

Log groups, failure and skip annotations, and slow-test notices are forwarded unchanged through the SDK's informational display-message channel. This requires an SDK that negotiates Microsoft.Testing.Platform protocol 1.3.0 or later. The Markdown job summary is written independently and does not require that channel.
Expand Down
34 changes: 34 additions & 0 deletions src/Platform/SharedExtensionHelpers/CiRunSummaryAggregateReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ private static void ValidateModule(
|| RoslynString.IsNullOrWhiteSpace(module.ModulePath)
|| RoslynString.IsNullOrWhiteSpace(module.TargetFramework)
|| RoslynString.IsNullOrWhiteSpace(module.Architecture)
|| (module.OperatingSystem is not null
&& (RoslynString.IsNullOrWhiteSpace(module.OperatingSystem) || module.OperatingSystem.Length > 64))
|| RoslynString.IsNullOrWhiteSpace(module.SessionUid)
|| module.AttemptNumber <= 0
|| module.TotalTests < 0
Expand All @@ -114,6 +116,7 @@ private static void ValidateModule(
|| module.Failures is null
|| module.FlakyTests is null
|| module.SlowestTests is null
|| !AreValidSkipReasons(module.SkipReasons, module.SkippedTests)
|| module.HistoryTests is null
|| module.HistoryTests.Length > MaxHistoryTests
|| module.Dependencies is null
Expand Down Expand Up @@ -224,8 +227,39 @@ private static bool IsValidTest(CiRunSummaryTest test)
=> !RoslynString.IsNullOrWhiteSpace(test.DisplayName)
&& !RoslynString.IsNullOrWhiteSpace(test.FullyQualifiedName)
&& test.DurationTicks >= 0
&& test.Outcome is null or "passed" or "failed" or "skipped"
&& test.LineNumber is null or >= 0;

private static bool AreValidSkipReasons(CiRunSummarySkipReason[]? reasons, long skippedTests)
{
if (reasons is null)
{
return true;
}

if (reasons.Length > MaxSkipReasons)
{
return false;
}

long remaining = skippedTests;
foreach (CiRunSummarySkipReason reason in reasons)
{
if (reason is null
|| RoslynString.IsNullOrWhiteSpace(reason.Reason)
|| reason.Reason.Length > MaxSkipReasonLength
|| reason.Count <= 0
|| reason.Count > remaining)
{
return false;
}

remaining -= reason.Count;
}

return true;
}

private static bool IsValidExactPercentage(string? value, double percentage)
=> value is null
|| (decimal.TryParse(value, NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out decimal exact)
Expand Down
Loading
Loading