Skip to content
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
4e7ca96
Publish retry attempts as sub-results of one Azure DevOps result
Evangelink Aug 4, 2026
ced5ce4
Harden Azure DevOps rerun coordination
Evangelink Aug 4, 2026
7fd5de3
Keep rerun sequence ids increasing after truncation
Evangelink Aug 4, 2026
6188fb2
Ignore invalid persisted rerun histories
Evangelink Aug 4, 2026
f8dac7f
Preserve mixed retry batches during attachment upload
Evangelink Aug 4, 2026
93c555b
Discard stale histories after ambiguous PATCH failures
Evangelink Aug 4, 2026
c06b1f2
Cover retry attachment file naming
Evangelink Aug 4, 2026
7115779
Keep retry maps limited and fail invalidation closed
Evangelink Aug 4, 2026
d7b43e2
Disambiguate folded retry rows
Evangelink Aug 4, 2026
c814b08
Strengthen Azure DevOps rerun assertions
Evangelink Aug 4, 2026
5e47cf1
Harden folded-row map handling
Evangelink Aug 4, 2026
00491c0
Avoid guessing duplicate data-row identities
Evangelink Aug 4, 2026
fdeaa17
Reject ambiguous rerun parent mappings
Evangelink Aug 4, 2026
34d5dcf
Retry failed PATCHes during forced flush
Evangelink Aug 4, 2026
fdb820c
Track rerun ambiguity and duration across batches
Evangelink Aug 4, 2026
4f20cbe
Scope result maps to inherited runs
Evangelink Aug 4, 2026
cbd0ca7
Assert rerun sub-results before inspection
Evangelink Aug 4, 2026
540ce03
Harden result map handoff and retry claims
Evangelink Aug 4, 2026
37d4ca8
Validate result map multiplicity before loading
Evangelink Aug 4, 2026
ca4bc6b
Preserve prior claims after duplicate create failure
Evangelink Aug 4, 2026
9c009ce
Treat secured result maps as unsafe
Evangelink Aug 4, 2026
90c6463
Claim newly created result ids within each attempt
Evangelink Aug 4, 2026
79f4de8
Count result IDs before validating map keys
Evangelink Aug 4, 2026
dfb9608
Clear stale failure details on rerun updates
Evangelink Aug 4, 2026
dc631e5
Retry safe creates during forced flush
Evangelink Aug 4, 2026
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 @@ -48,6 +48,62 @@ internal static class AzureDevOpsConstants
/// </remarks>
public const string TestRunIdEnvironmentVariableName = "TESTINGPLATFORM_AZUREDEVOPS_TESTRUNID";

/// <summary>
/// Name of the environment variable that carries the path of the file mapping each published test to the
/// Azure DevOps result id it was created under, so that a later attempt of the same test updates that
/// result instead of publishing a second one for the same test.
/// </summary>
/// <remarks>
/// Set by <see cref="AzureDevOpsTestRunOrchestratorLifetime"/> next to
/// <see cref="TestRunIdEnvironmentVariableName"/>. It is a separate variable rather than another field of
/// that one on purpose: a process running an older version parses the run id value positionally and
/// would reject a longer form, which would send it off to create a run of its own and undo the
/// one-run-per-build guarantee. An unknown extra variable is simply ignored instead.
/// <para>
/// The path (rather than just a directory) comes from the orchestrator because each attempt is given its
/// own results directory, so the attempts share no directory of their own. Carrying it also scopes the
/// map to a single orchestration: test hosts that merely run alongside each other never see it and keep
/// publishing independent results.
/// </para>
/// <para>
/// The value is <c>&lt;buildId&gt;:&lt;path&gt;</c>, with the build id guarding against a stale value
/// inherited from an earlier build on a reused agent, exactly as for the run id.
/// </para>
/// </remarks>
public const string ResultMapPathEnvironmentVariableName = "TESTINGPLATFORM_AZUREDEVOPS_RESULTMAP";

/// <summary>
/// Formats the handoff value that tells descendant processes where the result map lives.
/// </summary>
public static string FormatResultMapPath(int buildId, string path)
=> $"{buildId.ToString(CultureInfo.InvariantCulture)}:{path}";

/// <summary>
/// Returns the result map path established by an ancestor process for <paramref name="buildId"/>, or
/// <see langword="null"/> when there is no map to join.
/// </summary>
/// <remarks>
/// Only the first separator is significant, so a Windows path keeps its drive letter. Anything
/// malformed or belonging to another build is treated as absent, which means results are published
/// individually — the behaviour that predates reruns, rather than a loss.
/// </remarks>
public static string? TryGetInheritedResultMapPath(IEnvironment environment, int buildId)
{
string? value = environment.GetEnvironmentVariable(ResultMapPathEnvironmentVariableName);
if (value is null || value.Length == 0)
{
return null;
}

int separatorIndex = value.IndexOf(':');
return separatorIndex <= 0
|| !int.TryParse(value[..separatorIndex], NumberStyles.Integer, CultureInfo.InvariantCulture, out int inheritedBuildId)
|| inheritedBuildId != buildId
|| separatorIndex + 1 >= value.Length
? null
: value[(separatorIndex + 1)..];
}

/// <summary>
/// Formats the handoff value that tells descendant processes which run to publish into.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System.Text.Json.Serialization;
Expand All @@ -16,6 +16,24 @@ internal static class AzureDevOpsLivePublishingConstants
public const string NotExecutedTestOutcome = "NotExecuted";
public const string PassedTestOutcome = "Passed";

/// <summary>
/// Value of <c>resultGroupType</c> that tells Azure DevOps a result is the parent of several attempts
/// of the same test rather than a leaf result.
/// </summary>
/// <remarks>
/// Azure DevOps serializes <c>ResultGroupType</c> in camelCase on the wire, so the literal is
/// <c>rerun</c> and not <c>Rerun</c>.
/// </remarks>
public const string RerunResultGroupType = "rerun";

/// <summary>Maximum number of sub-results Azure DevOps accepts under a single result.</summary>
/// <remarks>
/// Matches the limit the Azure Pipelines agent enforces client-side before publishing, where exceeding
/// it truncates rather than fails. A retry sequence never approaches this, so the cap only guards
/// against an unbounded attempt history.
/// </remarks>
public const int MaxSubResultsPerResult = 1000;

/// <summary>Maximum size (in bytes) of a single attachment uploaded to Azure DevOps. Files larger than this are skipped.</summary>
public const long MaxAttachmentSizeBytes = 16L * 1024 * 1024;

Expand Down Expand Up @@ -74,6 +92,48 @@ internal sealed record AzureDevOpsTestCaseResult(
[property: JsonPropertyName("errorMessage")] string? ErrorMessage,
[property: JsonPropertyName("stackTrace")] string? StackTrace,
[property: JsonPropertyName("startedDate")] DateTimeOffset? StartedDate,
[property: JsonPropertyName("completedDate")] DateTimeOffset? CompletedDate)
{
/// <summary>
/// Gets the id Azure DevOps assigned to this result, set only when updating an already published result.
/// </summary>
/// <remarks>
/// Declared as properties rather than positional parameters so that adding them does not change the
/// record's constructor and deconstructor signatures. All three are absent from a freshly created
/// result and are only populated when a retry attempt turns an existing result into a rerun.
/// </remarks>
[JsonPropertyName("id")]
public int? Id { get; init; }

/// <summary>
/// Gets the hierarchy type of the result; <see cref="AzureDevOpsLivePublishingConstants.RerunResultGroupType"/>
/// marks it as the parent of several attempts.
/// </summary>
[JsonPropertyName("resultGroupType")]
public string? ResultGroupType { get; init; }

/// <summary>Gets the individual attempts of this test, oldest first.</summary>
[JsonPropertyName("subResults")]
public IReadOnlyList<AzureDevOpsTestSubResult>? SubResults { get; init; }
}

/// <summary>
/// One attempt of a test that ran more than once, published under the parent result rather than as a
/// result of its own.
/// </summary>
/// <remarks>
/// <see cref="SequenceId"/> is the attempt ordinal. Azure DevOps documents it only as an "index number",
/// with no stated requirement to be 1-based or contiguous, but the agent's own publisher emits it that way
/// and the Tests tab orders attempts by it, so this extension does the same.
/// </remarks>
internal sealed record AzureDevOpsTestSubResult(
[property: JsonPropertyName("sequenceId")] int SequenceId,
[property: JsonPropertyName("displayName")] string DisplayName,
[property: JsonPropertyName("outcome")] string Outcome,
[property: JsonPropertyName("durationInMs")] long? DurationInMs,
[property: JsonPropertyName("errorMessage")] string? ErrorMessage,
[property: JsonPropertyName("stackTrace")] string? StackTrace,
[property: JsonPropertyName("startedDate")] DateTimeOffset? StartedDate,
[property: JsonPropertyName("completedDate")] DateTimeOffset? CompletedDate);

/// <summary>A test case result bundled with optional attachments to upload after the result is published.</summary>
Expand Down Expand Up @@ -112,6 +172,18 @@ public static AzureDevOpsTestResultAttachment FromFile(string filePath, string a

public static AzureDevOpsTestResultAttachment FromString(string content, string fileName, string attachmentType, string? comment = null)
=> new(fileName, attachmentType, comment, filePath: null, inlineContent: content);

/// <summary>
/// Returns a copy of this attachment published under a different file name.
/// </summary>
/// <remarks>
/// Every attempt of a rerun uploads its attachments against the same parent result, where Azure DevOps
/// accumulates rather than replaces them. Two attempts would therefore both contribute a
/// <c>stdout.log</c>, leaving no way to tell which attempt produced which. Renaming per attempt keeps
/// them distinguishable without needing a sub-result id we cannot reliably obtain.
/// </remarks>
public AzureDevOpsTestResultAttachment WithFileName(string fileName)
=> new(fileName, AttachmentType, Comment, FilePath, InlineContent);
}

internal sealed record AzureDevOpsTestResultsPublisherOptions(
Expand Down
Loading
Loading