Repository navigation
Publish Azure DevOps retry attempts as sub-results - #10431
Conversation
There was a problem hiding this comment.
Pull request overview
Adds Azure DevOps rerun publishing so retry attempts become sub-results of one test result.
Changes:
- Persists result IDs across retry processes and PATCHes subsequent attempts.
- Preserves latest outcomes, attempt history, and qualified attachments.
- Adds diagnostics, API tracking, localization metadata, and tests.
Show a summary per file
| File | Description |
|---|---|
test/UnitTests/Microsoft.Testing.Extensions.UnitTests/AzureDevOpsLivePublishingTests.cs |
Tests reruns, persistence, fallbacks, and payloads. |
Resources/xlf/AzureDevOpsResources.zh-Hant.xlf |
Adds localization unit. |
Resources/xlf/AzureDevOpsResources.zh-Hans.xlf |
Adds localization unit. |
Resources/xlf/AzureDevOpsResources.tr.xlf |
Adds localization unit. |
Resources/xlf/AzureDevOpsResources.ru.xlf |
Adds localization unit. |
Resources/xlf/AzureDevOpsResources.pt-BR.xlf |
Adds localization unit. |
Resources/xlf/AzureDevOpsResources.pl.xlf |
Adds localization unit. |
Resources/xlf/AzureDevOpsResources.ko.xlf |
Adds localization unit. |
Resources/xlf/AzureDevOpsResources.ja.xlf |
Adds localization unit. |
Resources/xlf/AzureDevOpsResources.it.xlf |
Adds localization unit. |
Resources/xlf/AzureDevOpsResources.fr.xlf |
Adds localization unit. |
Resources/xlf/AzureDevOpsResources.es.xlf |
Adds localization unit. |
Resources/xlf/AzureDevOpsResources.de.xlf |
Adds localization unit. |
Resources/xlf/AzureDevOpsResources.cs.xlf |
Adds localization unit. |
Resources/AzureDevOpsResources.resx |
Adds map-read failure diagnostic. |
InternalAPI/InternalAPI.Unshipped.txt |
Tracks new internal API surface. |
IAzureDevOpsTestResultsClient.cs |
Adds result-update contract. |
AzureDevOpsTestRunOrchestratorLifetime.cs |
Publishes and cleans up the shared map path. |
AzureDevOpsTestResultsPublisher.Flush.cs |
Splits result creation and rerun updates. |
AzureDevOpsTestResultsPublisher.cs |
Loads and saves result mappings. |
AzureDevOpsTestResultsClient.cs |
Sends PATCH requests for results. |
AzureDevOpsResultIdStore.cs |
Implements persisted attempt history. |
AzureDevOpsLivePublishingModels.cs |
Adds rerun and sub-result models. |
AzureDevOpsConstants.cs |
Adds map-path environment handoff. |
Review details
Suppressed comments (1)
src/Platform/Microsoft.Testing.Extensions.AzureDevOpsReport/AzureDevOpsResultIdStore.cs:271
- Only the key fields are validated even though the map is treated as untrusted. A missing/empty
attemptsarray makes the next PATCH replace the earlier failure with only the current attempt; malformed entries (for examplenullsub-results or invalid outcomes/sequence IDs) instead make Azure DevOps reject every retry until the current result is dropped. Validate the complete attempt history and treat any invalid entry as unseen so the safe POST fallback is used.
// Entries come from disk, so nothing about them is guaranteed however the record is
// annotated: a truncated or hand-edited file can yield nulls and non-positive ids.
if (entry is { Id: > 0, Storage: { Length: > 0 } storage, Name: { Length: > 0 } name })
{
_results[CreateKey(storage, name)] = new AzureDevOpsPublishedResult(storage, name, entry.Id, entry.Attempts ?? []);
- Files reviewed: 24/24 changed files
- Comments generated: 3
- Review effort level: Balanced
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Review details
Suppressed comments (1)
src/Platform/Microsoft.Testing.Extensions.AzureDevOpsReport/AzureDevOpsResultIdStore.cs:212
- This does not provide the PR's claimed atomic map replacement on all supported targets. For the extension's netstandard2.0/.NET Framework path,
SystemFileSystem.MoveFile(..., overwrite: true)is implemented asFile.Copyfollowed byFile.Delete(SystemFileSystem.cs:17-21), so interruption can tear the destination map. Add an atomic replace primitive (for example, replace when the destination exists and rename when it does not) rather than relying on this abstraction's non-atomic overwrite implementation.
_fileSystem.MoveFile(temporaryFilePath, _filePath, overwrite: true);
- Files reviewed: 24/24 changed files
- Comments generated: 2
- Review effort level: Balanced
There was a problem hiding this comment.
Review details
Suppressed comments (1)
src/Platform/Microsoft.Testing.Extensions.AzureDevOpsReport/AzureDevOpsResultIdStore.cs:212
- This replacement is not atomic on supported
netstandard2.0and .NET Framework builds:SystemFileSystem.MoveFile(..., overwrite: true)usesFile.Copyfollowed byFile.Delete(SystemFileSystem.cs:15-20). An interruption can therefore destroy the previous valid map during a create-only save, contrary to the PR's atomic-write guarantee, and the next retry degrades to duplicate results. Add an atomic replace operation toIFileSystemand use it here.
_fileSystem.MoveFile(temporaryFilePath, _filePath, overwrite: true);
- Files reviewed: 24/24 changed files
- Comments generated: 1
- Review effort level: Balanced
There was a problem hiding this comment.
Review details
Suppressed comments (1)
src/Platform/Microsoft.Testing.Extensions.AzureDevOpsReport/AzureDevOpsTestResultsPublisher.Flush.cs:168
- A failed/ambiguous PATCH can still cause the deleted map to be recreated with stale history. If this session already accepted a creation or an earlier update, the store is dirty; finalization then saves every loaded entry, including this failed batch's old attempts. When Azure DevOps accepted the PATCH before the transport failure, the next attempt can PATCH from that stale history and erase the accepted attempt. Mark the store non-persistable (or remove the affected entries) when an update ultimately fails, so
SaveAsynccannot restore the invalidated state; this needs a mixed- or multi-batch regression test.
else if (updates.Count > 0 && !await TryUpdateResultsAsync(updates, deferredAttachments, cancellationToken).ConfigureAwait(false))
{
RequeueUnsafe([.. updates.Select(update => update.Attempt)]);
await UploadDeferredAttachmentsAsync(deferredAttachments, cancellationToken).ConfigureAwait(false);
return;
- Files reviewed: 28/28 changed files
- Comments generated: 0 new
- Review effort level: Balanced
There was a problem hiding this comment.
Review details
Suppressed comments (1)
src/Platform/Microsoft.Testing.Extensions.AzureDevOpsReport/AzureDevOpsTestResultsPublisher.Flush.cs:356
- The new attempt-qualified attachment naming is externally visible, but the added retry tests never assert the uploaded filename (there are no
attempt-assertions in the suite). Please add coverage that publishes a retry with an attachment and verifies the parent upload uses the expected name, including preservation of the original extension, so this PR requirement cannot regress unnoticed.
renamed[i] = attachments[i].WithFileName(
$"{Path.GetFileNameWithoutExtension(fileName)}.attempt-{attemptNumber.ToString(CultureInfo.InvariantCulture)}{extension}");
- Files reviewed: 28/28 changed files
- Comments generated: 0 new
- Review effort level: Balanced
There was a problem hiding this comment.
🤖 Automated content by GitHub Copilot. Generated by the Grade Tests on PR (on open / sync) workflow. · auto · 108.8 AIC · ⌖ 3.9 AIC · ⊞ 16.2K · ◷
There was a problem hiding this comment.
Review details
Suppressed comments (2)
src/Platform/Microsoft.Testing.Extensions.AzureDevOpsReport/AzureDevOpsResultIdStore.cs:166
ExistFileis backed byFile.Exists, which returnsfalsefor access/path errors as well as for a missing file. In this safety gate that makes invalidation fail open: a transient access failure can leave the old map in place, allow the PATCH, and then let a later attempt replay stale history if saving fails or the process exits. Delete unconditionally (File.Deleteis a no-op when the file is absent) and use the existing exception handler to force the safe POST fallback when deletion cannot be confirmed.
if (!_fileSystem.ExistFile(_filePath))
{
return true;
}
src/Platform/Microsoft.Testing.Extensions.AzureDevOpsReport/AzureDevOpsTestResultsPublisher.Flush.cs:237
- This retains every created result—including passed and skipped tests—in
_resultIdStoreuntil session end and serializes all of them to disk. The retry orchestrator builds later attempt filters only from failed/error/timeout/cancelled UIDs (RetryDataConsumer.cs:73-81,RetryArgumentsBuilder.cs:109-147), so passed/skipped entries can never be looked up. For large mostly-green suites this changes the live publisher from bounded batch memory to O(total test count) memory and writes a potentially large map even when no retry runs; record only outcomes eligible for retry.
for (int i = 0; i < batch.Count; i++)
{
_resultIdStore?.RecordCreated(batch[i].Result, resultIds[i]);
- Files reviewed: 28/28 changed files
- Comments generated: 0 new
- Review effort level: Balanced
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Review details
Suppressed comments (1)
src/Platform/Microsoft.Testing.Extensions.AzureDevOpsReport/AzureDevOpsTestResultsPublisher.Flush.cs:283
- The
withexpression also copiesDurationInMsfrom only the latest attempt. Once the result becomes a rerun, that top-level duration represents the grouped test and is what Azure DevOps uses for result/run duration reporting; rerun publishers populate it with the total of the sub-result durations (the MicrosoftUpdateUnreliableTests.ps1publisher does this explicitly). A fail taking 30 s followed by a 1 s pass is therefore reported here as 1 s even though both executions are retained below it. Keep the latest outcome/error as intended, but derive the parent duration from the accumulated attempt history (and add a timing assertion).
attemptHistories[i] = AzureDevOpsResultIdStore.BuildNextAttempts(updates[i].Published, updates[i].Attempt.Result);
parents[i] = updates[i].Attempt.Result with
{
Id = updates[i].Published.Id,
ResultGroupType = AzureDevOpsLivePublishingConstants.RerunResultGroupType,
SubResults = attemptHistories[i],
};
- Files reviewed: 28/28 changed files
- Comments generated: 1
- Review effort level: Balanced
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
🤖 Automated content by GitHub Copilot. Generated by the Grade Tests on PR (on open / sync) workflow. · auto · 156.5 AIC · ⌖ 4.77 AIC · ⊞ 16.2K · ◷
Count identity collisions before payload validation and handle SecurityException across map invalidation, loading, cleanup, and orchestrator teardown. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 522344b1-f0e0-47a5-a8d0-cf897db28152
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Review details
Suppressed comments (1)
src/Platform/Microsoft.Testing.Extensions.AzureDevOpsReport/AzureDevOpsTestResultsPublisher.Flush.cs:276
- A result created in this host attempt is added to the store but its ID is not marked as claimed. If another row with the same
(storage, UID, title)arrives in a later batch (for example, duplicate folded rows split by a batch-size or interval flush), it resolves to this newly created result and is PATCHed as though it were a retry, collapsing two rows from the same attempt. Claim every newly assigned ID when recording it so later same-attempt matches take the safe-create path and mark the key ambiguous.
_resultIdStore?.RecordCreated(batch[i].Result, resultIds[i]);
- Files reviewed: 28/28 changed files
- Comments generated: 1
- Review effort level: Balanced
Prevent later duplicate rows in the same test-host attempt from PATCHing a parent created by an earlier batch. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 522344b1-f0e0-47a5-a8d0-cf897db28152
Treat every positive server result id as an ownership claim even when the surrounding persisted key is malformed. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 522344b1-f0e0-47a5-a8d0-cf897db28152
There was a problem hiding this comment.
Review details
Suppressed comments (2)
src/Platform/Microsoft.Testing.Extensions.AzureDevOpsReport/AzureDevOpsTestResultsPublisher.Flush.cs:330
- When the latest retry passes (or has no stack trace), these nullable detail fields remain
null, but the client serializes PATCH bodies withJsonIgnoreCondition.WhenWritingNull. Azure DevOps treats omitted PATCH fields as unchanged, so the parent can becomePassedwhile retaining the earlier failure'serrorMessage/stackTrace, contrary to the latest-attempt parent semantics. Serialize explicit nulls for these fields on updates (while continuing to omit rerun-only nulls on POST).
parents[i] = updates[i].Attempt.Result with
{
Id = updates[i].Published.Id,
ResultGroupType = AzureDevOpsLivePublishingConstants.RerunResultGroupType,
SubResults = attemptHistories[i],
DurationInMs = totalDurations[i],
StartedDate = startedDates[i],
CompletedDate = completedDates[i],
};
src/Platform/Microsoft.Testing.Extensions.AzureDevOpsReport/AzureDevOpsResultIdStore.cs:342
- A positive result ID is counted only when the same entry also has a complete key. Thus a malformed entry such as
{ "id": 433 }is ignored, and a later valid entry claiming ID 433 is accepted and PATCHed even though the untrusted map assigns that ID twice. Count every positive ID independently of key validation so all collisions take the safe-create path.
if (entry is null)
{
continue;
}
- Files reviewed: 27/28 changed files
- Comments generated: 0 new
- Review effort level: Balanced
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Review details
Suppressed comments (1)
src/Platform/Microsoft.Testing.Extensions.AzureDevOpsReport/AzureDevOpsTestResultsPublisher.Flush.cs:190
- When map invalidation fails during the session-end forced flush, a transient failure of the safe-create POST requeues the retry result and returns. No later flush drains that queue, so the attempt is reported as dropped instead of receiving the same immediate create retry used after a failed PATCH. On forced flushes, continue once so the retained claim reclassifies this item as a plain creation; background flushes should still return for backoff.
if (!await TryCreateResultsAsync(updateFallbacks, deferredAttachments, cancellationToken).ConfigureAwait(false))
{
RequeueUnsafe(updateFallbacks);
await UploadDeferredAttachmentsAsync(deferredAttachments, cancellationToken).ConfigureAwait(false);
return;
- Files reviewed: 27/28 changed files
- Comments generated: 0 new
- Review effort level: Balanced
Use update-specific JSON serialization so passing retries send explicit null error and stack-trace fields while create payloads retain null omission. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 522344b1-f0e0-47a5-a8d0-cf897db28152
This comment has been minimized.
This comment has been minimized.
Give the invalidation-failure fallback one immediate session-end retry while preserving background-flush backoff. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 522344b1-f0e0-47a5-a8d0-cf897db28152
🧪 Test quality grade — PR #10431No new or modified test methods were identified in the changed regions of this PR. Nothing to grade. Re-run with
|
🧵 Parallel-safety audit — PR #10431Parallelization — assembly audited:
Findings: A (global-state) 0 · B (paths) 0 · C (declaration) 0 · D (over-serialization) 0 — nothing flagged. This PR only touches
Nothing here needs to be serialized, locked, or isolated further. Clean audit. Advisory only — heuristic, non-blocking. Re-run with
|
Summary
resultGroupType: "rerun"and accumulatedsubResultsCoordination and compatibility
The retry orchestrator gives each attempt a separate results directory, so it publishes a shared map path through a new build-scoped environment-variable handoff. This is intentionally separate from the existing run-id handoff so older processes continue to parse and honor the one-run-per-build contract from #10375.
The map is scoped by a random orchestration id and validates both build id and run id. Before PATCHing an existing result, the persisted map is invalidated; if that cannot be done safely, publishing degrades to a separate POST rather than risking stale history replacing an accepted attempt.
Validation
Microsoft.Testing.Extensions.UnitTests: 928 passed, 0 failed, 6 skippedMicrosoft.Testing.Platform.UnitTests: 2024 passed, 0 failedCloses #10400