From 15b5364181f669d54e12ace4c7cd2e1051a5734c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 28 Sep 2026 06:40:59 +0000 Subject: [PATCH 1/8] Initial plan From 5af974d9b0dc48fd9bdfe7be24e1d610d775f248 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 28 Sep 2026 06:51:51 +0000 Subject: [PATCH 2/8] Share retry artifact manifest protocol Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com> --- .../ActivatedAppTestHostHandle.cs | 19 +++------- ...soft.Testing.Extensions.PackagedApp.csproj | 1 + .../Microsoft.Testing.Extensions.Retry.csproj | 1 + .../RetryOrchestrator.ArtifactRecovery.cs | 32 ++++++---------- .../RetryArtifactManifest.cs | 38 +++++++++++++++++++ .../RetryTests.cs | 32 ++++++++++++++-- 6 files changed, 86 insertions(+), 37 deletions(-) create mode 100644 src/Platform/SharedExtensionHelpers/RetryArtifactManifest.cs diff --git a/src/Platform/Microsoft.Testing.Extensions.PackagedApp/ActivatedAppTestHostHandle.cs b/src/Platform/Microsoft.Testing.Extensions.PackagedApp/ActivatedAppTestHostHandle.cs index 4b3640b241..a5490383aa 100644 --- a/src/Platform/Microsoft.Testing.Extensions.PackagedApp/ActivatedAppTestHostHandle.cs +++ b/src/Platform/Microsoft.Testing.Extensions.PackagedApp/ActivatedAppTestHostHandle.cs @@ -132,10 +132,6 @@ private static void RecoverScratchArtifacts(string? scratchDirectory, string? re private void RecoverRetryArtifactManifest() { - const long MaxManifestBytes = 16L * 1024 * 1024; - const int MaxManifestLineChars = 64 * 1024; - const int MaxManifestRecords = 10_000; - if (_retryArtifactManifestPath is null || _retryArtifactManifestDestinationPath is null || _scratchDirectory is null) @@ -146,27 +142,25 @@ private void RecoverRetryArtifactManifest() try { if (!File.Exists(_retryArtifactManifestPath) - || new FileInfo(_retryArtifactManifestPath).Length > MaxManifestBytes) + || new FileInfo(_retryArtifactManifestPath).Length > RetryArtifactManifest.MaxBytes) { return; } var recoveredLines = new List(); - foreach (string line in File.ReadLines(_retryArtifactManifestPath).Take(MaxManifestRecords)) + foreach (string line in File.ReadLines(_retryArtifactManifestPath).Take(RetryArtifactManifest.MaxRecords)) { - if (line.Length > MaxManifestLineChars) + if (line.Length > RetryArtifactManifest.MaxLineLength) { continue; } - int separatorIndex = line.IndexOf('\t'); - if (separatorIndex <= 0) + if (!RetryArtifactManifest.TryParseEntry(line, out string sourcePath, out string encodedKind)) { continue; } - string sourcePath = Path.GetFullPath( - Encoding.UTF8.GetString(Convert.FromBase64String(line.Substring(0, separatorIndex)))); + sourcePath = Path.GetFullPath(sourcePath); string? recoveredPath = TryGetRecoveredArtifactPath( sourcePath, _resultsScratchDirectory, @@ -180,8 +174,7 @@ private void RecoverRetryArtifactManifest() continue; } - recoveredLines.Add( - $"{Convert.ToBase64String(Encoding.UTF8.GetBytes(Path.GetFullPath(recoveredPath)))}{line[separatorIndex..]}"); + recoveredLines.Add(RetryArtifactManifest.WriteEntry(Path.GetFullPath(recoveredPath), encodedKind)); } if (recoveredLines.Count == 0) diff --git a/src/Platform/Microsoft.Testing.Extensions.PackagedApp/Microsoft.Testing.Extensions.PackagedApp.csproj b/src/Platform/Microsoft.Testing.Extensions.PackagedApp/Microsoft.Testing.Extensions.PackagedApp.csproj index 42557ff227..b4ddbb91f7 100644 --- a/src/Platform/Microsoft.Testing.Extensions.PackagedApp/Microsoft.Testing.Extensions.PackagedApp.csproj +++ b/src/Platform/Microsoft.Testing.Extensions.PackagedApp/Microsoft.Testing.Extensions.PackagedApp.csproj @@ -46,6 +46,7 @@ $(CommonProductDescription)]]> + diff --git a/src/Platform/Microsoft.Testing.Extensions.Retry/Microsoft.Testing.Extensions.Retry.csproj b/src/Platform/Microsoft.Testing.Extensions.Retry/Microsoft.Testing.Extensions.Retry.csproj index ed81db2d47..d3683f2b1e 100644 --- a/src/Platform/Microsoft.Testing.Extensions.Retry/Microsoft.Testing.Extensions.Retry.csproj +++ b/src/Platform/Microsoft.Testing.Extensions.Retry/Microsoft.Testing.Extensions.Retry.csproj @@ -28,6 +28,7 @@ + diff --git a/src/Platform/Microsoft.Testing.Extensions.Retry/RetryOrchestrator.ArtifactRecovery.cs b/src/Platform/Microsoft.Testing.Extensions.Retry/RetryOrchestrator.ArtifactRecovery.cs index 5f0e01fc61..7f5b0a8ab2 100644 --- a/src/Platform/Microsoft.Testing.Extensions.Retry/RetryOrchestrator.ArtifactRecovery.cs +++ b/src/Platform/Microsoft.Testing.Extensions.Retry/RetryOrchestrator.ArtifactRecovery.cs @@ -12,9 +12,6 @@ internal sealed partial class RetryOrchestrator private const string AppContainerArtifactRootsConfiguredEnvironmentVariable = "TESTINGPLATFORM_PACKAGEDAPP_APPCONTAINER_ARTIFACT_ROOTS_CONFIGURED"; private const string ArtifactPathDestinationRootEnvironmentVariable = "TESTINGPLATFORM_ARTIFACT_PATH_DESTINATION_ROOT"; private const string DiagnosticArtifactPathDestinationRootEnvironmentVariable = "TESTINGPLATFORM_DIAGNOSTIC_ARTIFACT_PATH_DESTINATION_ROOT"; - private const long MaxRecoveredArtifactManifestBytes = 16L * 1024 * 1024; - private const int MaxRecoveredArtifactManifestLineBytes = 64 * 1024; - private const int MaxRecoveredArtifactManifestRecords = 10_000; private const int MaxRecoveredArtifactPathChars = 32 * 1024; private const int MaxRecoveredArtifactKindChars = 1024; @@ -35,7 +32,7 @@ private static void CollectRecoveredArtifacts( using IFileStream stream = fileSystem.NewFileStream(manifestPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); var reader = new BoundedManifestLineReader(stream.Stream); int recordCount = 0; - while (recordCount++ < MaxRecoveredArtifactManifestRecords) + while (recordCount++ < RetryArtifactManifest.MaxRecords) { BoundedManifestLineReadResult readResult = reader.ReadLine(out string line); if (readResult == BoundedManifestLineReadResult.End) @@ -49,20 +46,15 @@ private static void CollectRecoveredArtifacts( return; } - int separatorIndex = line.IndexOf('\t'); - if (separatorIndex <= 0) - { - logger.LogWarning($"Ignoring malformed recovered retry artifact manifest entry in '{manifestPath}'."); - continue; - } - try { - string path = Encoding.UTF8.GetString(Convert.FromBase64String(line.Substring(0, separatorIndex))); - string encodedKind = line.Substring(separatorIndex + 1); - string? kind = encodedKind == "-" - ? null - : Encoding.UTF8.GetString(Convert.FromBase64String(encodedKind)); + if (!RetryArtifactManifest.TryParseEntry(line, out string path, out string encodedKind)) + { + logger.LogWarning($"Ignoring malformed recovered retry artifact manifest entry in '{manifestPath}'."); + continue; + } + + string? kind = RetryArtifactManifest.DecodeKind(encodedKind); if (path.Length > MaxRecoveredArtifactPathChars || kind?.Length > MaxRecoveredArtifactKindChars) { @@ -101,7 +93,7 @@ private static void CollectRecoveredArtifacts( } } - logger.LogWarning($"Stopped reading recovered retry artifact manifest '{manifestPath}' after the maximum of {MaxRecoveredArtifactManifestRecords} records."); + logger.LogWarning($"Stopped reading recovered retry artifact manifest '{manifestPath}' after the maximum of {RetryArtifactManifest.MaxRecords} records."); } catch (Exception ex) when (ex is IOException or UnauthorizedAccessException) { @@ -195,7 +187,7 @@ private sealed class BoundedManifestLineReader(Stream stream) private const int BufferSize = 8192; private readonly byte[] _readBuffer = new byte[BufferSize]; - private readonly byte[] _lineBuffer = new byte[MaxRecoveredArtifactManifestLineBytes]; + private readonly byte[] _lineBuffer = new byte[RetryArtifactManifest.MaxLineLength]; private int _readOffset; private int _readCount; private long _bytesRead; @@ -205,7 +197,7 @@ public BoundedManifestLineReadResult ReadLine(out string line) int lineLength = 0; while (TryReadByte(out byte value)) { - if (++_bytesRead > MaxRecoveredArtifactManifestBytes) + if (++_bytesRead > RetryArtifactManifest.MaxBytes) { line = string.Empty; return BoundedManifestLineReadResult.LimitExceeded; @@ -216,7 +208,7 @@ public BoundedManifestLineReadResult ReadLine(out string line) return DecodeLine(lineLength, out line); } - if (lineLength >= MaxRecoveredArtifactManifestLineBytes) + if (lineLength >= RetryArtifactManifest.MaxLineLength) { line = string.Empty; return BoundedManifestLineReadResult.LimitExceeded; diff --git a/src/Platform/SharedExtensionHelpers/RetryArtifactManifest.cs b/src/Platform/SharedExtensionHelpers/RetryArtifactManifest.cs new file mode 100644 index 0000000000..05656999df --- /dev/null +++ b/src/Platform/SharedExtensionHelpers/RetryArtifactManifest.cs @@ -0,0 +1,38 @@ +// 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; + +#pragma warning disable RS0051 // Recovery infrastructure is shared-source implementation detail, not package API. + +internal static class RetryArtifactManifest +{ + public const long MaxBytes = 16L * 1024 * 1024; + public const int MaxLineLength = 64 * 1024; + public const int MaxRecords = 10_000; + + public static bool TryParseEntry(string line, out string path, out string encodedKind) + { + int separatorIndex = line.IndexOf('\t'); + if (separatorIndex <= 0) + { + path = string.Empty; + encodedKind = string.Empty; + return false; + } + + path = Encoding.UTF8.GetString(Convert.FromBase64String(line.Substring(0, separatorIndex))); + encodedKind = line.Substring(separatorIndex + 1); + return true; + } + + public static string? DecodeKind(string encodedKind) + => encodedKind == "-" + ? null + : Encoding.UTF8.GetString(Convert.FromBase64String(encodedKind)); + + public static string WriteEntry(string path, string encodedKind) + => $"{Convert.ToBase64String(Encoding.UTF8.GetBytes(path))}\t{encodedKind}"; +} + +#pragma warning restore RS0051 diff --git a/test/UnitTests/Microsoft.Testing.Extensions.UnitTests/RetryTests.cs b/test/UnitTests/Microsoft.Testing.Extensions.UnitTests/RetryTests.cs index c2757615ed..a6c165c43c 100644 --- a/test/UnitTests/Microsoft.Testing.Extensions.UnitTests/RetryTests.cs +++ b/test/UnitTests/Microsoft.Testing.Extensions.UnitTests/RetryTests.cs @@ -372,13 +372,35 @@ public void CollectRecoveredArtifacts_RecoveredKind_ReplacesPreviouslyPublishedA fileSystem.Verify(fs => fs.DeleteFile(manifestPath), Times.Once); } + [TestMethod] + public void CollectRecoveredArtifacts_NullKind_AddsRecoveredArtifact() + { + const string manifestPath = "recovered-artifacts.txt"; + string attemptDirectory = Path.GetFullPath("attempt"); + string recoveredArtifactPath = Path.Combine(attemptDirectory, "recovered.xml"); + var fileSystem = new Mock(); + fileSystem.Setup(fs => fs.ExistFile(It.IsAny())).Returns(true); + fileSystem.Setup(fs => fs.NewFileStream(manifestPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) + .Returns(new ReadOnlyMemoryFileStream(CreateManifestLine(recoveredArtifactPath, kind: null))); + List artifacts = []; + + InvokeCollectRecoveredArtifacts(fileSystem.Object, manifestPath, attemptDirectory, artifacts); + + ArtifactRequest artifact = Assert.ContainsSingle(artifacts); + Assert.AreEqual(recoveredArtifactPath, artifact.Path); + Assert.IsNull(artifact.Kind); + fileSystem.Verify(fs => fs.DeleteFile(manifestPath), Times.Once); + } + [TestMethod] public void CollectRecoveredArtifacts_OversizedLine_IsRejectedAndManifestIsDeleted() { const string manifestPath = "recovered-artifacts.txt"; string attemptDirectory = Path.GetFullPath("attempt"); - int maxLineBytes = (int)typeof(RetryOrchestrator) - .GetField("MaxRecoveredArtifactManifestLineBytes", BindingFlags.Static | BindingFlags.NonPublic)! + Type manifestType = typeof(RetryOrchestrator).Assembly + .GetType("Microsoft.Testing.Extensions.RetryArtifactManifest")!; + int maxLineBytes = (int)manifestType + .GetField("MaxLineLength", BindingFlags.Static | BindingFlags.Public)! .GetRawConstantValue()!; var fileSystem = new Mock(); fileSystem.Setup(fs => fs.ExistFile(manifestPath)).Returns(true); @@ -398,8 +420,10 @@ public void CollectRecoveredArtifacts_RecordLimit_IsEnforcedAndManifestIsDeleted const string manifestPath = "recovered-artifacts.txt"; string attemptDirectory = Path.GetFullPath("attempt"); string recoveredArtifactPath = Path.Combine(attemptDirectory, "recovered.xml"); - int maxRecords = (int)typeof(RetryOrchestrator) - .GetField("MaxRecoveredArtifactManifestRecords", BindingFlags.Static | BindingFlags.NonPublic)! + Type manifestType = typeof(RetryOrchestrator).Assembly + .GetType("Microsoft.Testing.Extensions.RetryArtifactManifest")!; + int maxRecords = (int)manifestType + .GetField("MaxRecords", BindingFlags.Static | BindingFlags.Public)! .GetRawConstantValue()!; var manifest = new StringBuilder(); for (int i = 0; i < maxRecords; i++) From 7e1f42cfb1b16da088b87292b3a142a1b3c7ca83 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 28 Sep 2026 06:53:25 +0000 Subject: [PATCH 3/8] Clarify manifest decode boundaries Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com> --- .../ActivatedAppTestHostHandle.cs | 4 ++-- .../RetryOrchestrator.ArtifactRecovery.cs | 3 ++- .../SharedExtensionHelpers/RetryArtifactManifest.cs | 9 ++++++--- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/Platform/Microsoft.Testing.Extensions.PackagedApp/ActivatedAppTestHostHandle.cs b/src/Platform/Microsoft.Testing.Extensions.PackagedApp/ActivatedAppTestHostHandle.cs index a5490383aa..5893140ec0 100644 --- a/src/Platform/Microsoft.Testing.Extensions.PackagedApp/ActivatedAppTestHostHandle.cs +++ b/src/Platform/Microsoft.Testing.Extensions.PackagedApp/ActivatedAppTestHostHandle.cs @@ -155,12 +155,12 @@ private void RecoverRetryArtifactManifest() continue; } - if (!RetryArtifactManifest.TryParseEntry(line, out string sourcePath, out string encodedKind)) + if (!RetryArtifactManifest.TrySplitEntry(line, out string encodedPath, out string encodedKind)) { continue; } - sourcePath = Path.GetFullPath(sourcePath); + string sourcePath = Path.GetFullPath(RetryArtifactManifest.DecodePath(encodedPath)); string? recoveredPath = TryGetRecoveredArtifactPath( sourcePath, _resultsScratchDirectory, diff --git a/src/Platform/Microsoft.Testing.Extensions.Retry/RetryOrchestrator.ArtifactRecovery.cs b/src/Platform/Microsoft.Testing.Extensions.Retry/RetryOrchestrator.ArtifactRecovery.cs index 7f5b0a8ab2..50b3f2bd24 100644 --- a/src/Platform/Microsoft.Testing.Extensions.Retry/RetryOrchestrator.ArtifactRecovery.cs +++ b/src/Platform/Microsoft.Testing.Extensions.Retry/RetryOrchestrator.ArtifactRecovery.cs @@ -48,12 +48,13 @@ private static void CollectRecoveredArtifacts( try { - if (!RetryArtifactManifest.TryParseEntry(line, out string path, out string encodedKind)) + if (!RetryArtifactManifest.TrySplitEntry(line, out string encodedPath, out string encodedKind)) { logger.LogWarning($"Ignoring malformed recovered retry artifact manifest entry in '{manifestPath}'."); continue; } + string path = RetryArtifactManifest.DecodePath(encodedPath); string? kind = RetryArtifactManifest.DecodeKind(encodedKind); if (path.Length > MaxRecoveredArtifactPathChars || kind?.Length > MaxRecoveredArtifactKindChars) diff --git a/src/Platform/SharedExtensionHelpers/RetryArtifactManifest.cs b/src/Platform/SharedExtensionHelpers/RetryArtifactManifest.cs index 05656999df..1c42deb81c 100644 --- a/src/Platform/SharedExtensionHelpers/RetryArtifactManifest.cs +++ b/src/Platform/SharedExtensionHelpers/RetryArtifactManifest.cs @@ -11,21 +11,24 @@ internal static class RetryArtifactManifest public const int MaxLineLength = 64 * 1024; public const int MaxRecords = 10_000; - public static bool TryParseEntry(string line, out string path, out string encodedKind) + public static bool TrySplitEntry(string line, out string encodedPath, out string encodedKind) { int separatorIndex = line.IndexOf('\t'); if (separatorIndex <= 0) { - path = string.Empty; + encodedPath = string.Empty; encodedKind = string.Empty; return false; } - path = Encoding.UTF8.GetString(Convert.FromBase64String(line.Substring(0, separatorIndex))); + encodedPath = line.Substring(0, separatorIndex); encodedKind = line.Substring(separatorIndex + 1); return true; } + public static string DecodePath(string encodedPath) + => Encoding.UTF8.GetString(Convert.FromBase64String(encodedPath)); + public static string? DecodeKind(string encodedKind) => encodedKind == "-" ? null From 87f662f0cff303095923a2a1b7a31d742231e067 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 28 Sep 2026 06:54:15 +0000 Subject: [PATCH 4/8] Clarify encoded manifest kind contract Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com> --- .../ActivatedAppTestHostHandle.cs | 2 +- src/Platform/SharedExtensionHelpers/RetryArtifactManifest.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Platform/Microsoft.Testing.Extensions.PackagedApp/ActivatedAppTestHostHandle.cs b/src/Platform/Microsoft.Testing.Extensions.PackagedApp/ActivatedAppTestHostHandle.cs index 5893140ec0..61a6ec74cf 100644 --- a/src/Platform/Microsoft.Testing.Extensions.PackagedApp/ActivatedAppTestHostHandle.cs +++ b/src/Platform/Microsoft.Testing.Extensions.PackagedApp/ActivatedAppTestHostHandle.cs @@ -174,7 +174,7 @@ private void RecoverRetryArtifactManifest() continue; } - recoveredLines.Add(RetryArtifactManifest.WriteEntry(Path.GetFullPath(recoveredPath), encodedKind)); + recoveredLines.Add(RetryArtifactManifest.WriteEntryWithEncodedKind(Path.GetFullPath(recoveredPath), encodedKind)); } if (recoveredLines.Count == 0) diff --git a/src/Platform/SharedExtensionHelpers/RetryArtifactManifest.cs b/src/Platform/SharedExtensionHelpers/RetryArtifactManifest.cs index 1c42deb81c..6a8072263e 100644 --- a/src/Platform/SharedExtensionHelpers/RetryArtifactManifest.cs +++ b/src/Platform/SharedExtensionHelpers/RetryArtifactManifest.cs @@ -34,7 +34,7 @@ public static string DecodePath(string encodedPath) ? null : Encoding.UTF8.GetString(Convert.FromBase64String(encodedKind)); - public static string WriteEntry(string path, string encodedKind) + public static string WriteEntryWithEncodedKind(string path, string encodedKind) => $"{Convert.ToBase64String(Encoding.UTF8.GetBytes(path))}\t{encodedKind}"; } From 97bf38db1597cb1d2c4ef0dcf73854bb87ad0515 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 28 Sep 2026 06:55:59 +0000 Subject: [PATCH 5/8] Make manifest split contract explicit Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com> --- .../ActivatedAppTestHostHandle.cs | 2 +- .../RetryOrchestrator.ArtifactRecovery.cs | 12 ++++++------ .../SharedExtensionHelpers/RetryArtifactManifest.cs | 9 ++++++--- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/Platform/Microsoft.Testing.Extensions.PackagedApp/ActivatedAppTestHostHandle.cs b/src/Platform/Microsoft.Testing.Extensions.PackagedApp/ActivatedAppTestHostHandle.cs index 61a6ec74cf..f91a145f0e 100644 --- a/src/Platform/Microsoft.Testing.Extensions.PackagedApp/ActivatedAppTestHostHandle.cs +++ b/src/Platform/Microsoft.Testing.Extensions.PackagedApp/ActivatedAppTestHostHandle.cs @@ -155,7 +155,7 @@ private void RecoverRetryArtifactManifest() continue; } - if (!RetryArtifactManifest.TrySplitEntry(line, out string encodedPath, out string encodedKind)) + if (!RetryArtifactManifest.TrySplitEntry(line, out string? encodedPath, out string? encodedKind)) { continue; } diff --git a/src/Platform/Microsoft.Testing.Extensions.Retry/RetryOrchestrator.ArtifactRecovery.cs b/src/Platform/Microsoft.Testing.Extensions.Retry/RetryOrchestrator.ArtifactRecovery.cs index 50b3f2bd24..a49c33f500 100644 --- a/src/Platform/Microsoft.Testing.Extensions.Retry/RetryOrchestrator.ArtifactRecovery.cs +++ b/src/Platform/Microsoft.Testing.Extensions.Retry/RetryOrchestrator.ArtifactRecovery.cs @@ -46,14 +46,14 @@ private static void CollectRecoveredArtifacts( return; } - try + if (!RetryArtifactManifest.TrySplitEntry(line, out string? encodedPath, out string? encodedKind)) { - if (!RetryArtifactManifest.TrySplitEntry(line, out string encodedPath, out string encodedKind)) - { - logger.LogWarning($"Ignoring malformed recovered retry artifact manifest entry in '{manifestPath}'."); - continue; - } + logger.LogWarning($"Ignoring malformed recovered retry artifact manifest entry in '{manifestPath}'."); + continue; + } + try + { string path = RetryArtifactManifest.DecodePath(encodedPath); string? kind = RetryArtifactManifest.DecodeKind(encodedKind); if (path.Length > MaxRecoveredArtifactPathChars diff --git a/src/Platform/SharedExtensionHelpers/RetryArtifactManifest.cs b/src/Platform/SharedExtensionHelpers/RetryArtifactManifest.cs index 6a8072263e..0b40aef116 100644 --- a/src/Platform/SharedExtensionHelpers/RetryArtifactManifest.cs +++ b/src/Platform/SharedExtensionHelpers/RetryArtifactManifest.cs @@ -11,13 +11,16 @@ internal static class RetryArtifactManifest public const int MaxLineLength = 64 * 1024; public const int MaxRecords = 10_000; - public static bool TrySplitEntry(string line, out string encodedPath, out string encodedKind) + public static bool TrySplitEntry( + string line, + [NotNullWhen(true)] out string? encodedPath, + [NotNullWhen(true)] out string? encodedKind) { int separatorIndex = line.IndexOf('\t'); if (separatorIndex <= 0) { - encodedPath = string.Empty; - encodedKind = string.Empty; + encodedPath = null; + encodedKind = null; return false; } From 846b4a9376b951a0a223b0182a46e962d24f5a47 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 28 Sep 2026 06:57:22 +0000 Subject: [PATCH 6/8] Clarify manifest null-kind sentinel Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com> --- .../ActivatedAppTestHostHandle.cs | 6 ++++-- .../RetryOrchestrator.ArtifactRecovery.cs | 4 ++-- .../RetryArtifactManifest.cs | 16 ++++++++-------- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/Platform/Microsoft.Testing.Extensions.PackagedApp/ActivatedAppTestHostHandle.cs b/src/Platform/Microsoft.Testing.Extensions.PackagedApp/ActivatedAppTestHostHandle.cs index f91a145f0e..33c776e067 100644 --- a/src/Platform/Microsoft.Testing.Extensions.PackagedApp/ActivatedAppTestHostHandle.cs +++ b/src/Platform/Microsoft.Testing.Extensions.PackagedApp/ActivatedAppTestHostHandle.cs @@ -155,7 +155,7 @@ private void RecoverRetryArtifactManifest() continue; } - if (!RetryArtifactManifest.TrySplitEntry(line, out string? encodedPath, out string? encodedKind)) + if (!RetryArtifactManifest.TrySplitEntry(line, out string? encodedPath, out string? encodedKindOrNullSentinel)) { continue; } @@ -174,7 +174,9 @@ private void RecoverRetryArtifactManifest() continue; } - recoveredLines.Add(RetryArtifactManifest.WriteEntryWithEncodedKind(Path.GetFullPath(recoveredPath), encodedKind)); + recoveredLines.Add(RetryArtifactManifest.WriteEntryWithEncodedKind( + Path.GetFullPath(recoveredPath), + encodedKindOrNullSentinel)); } if (recoveredLines.Count == 0) diff --git a/src/Platform/Microsoft.Testing.Extensions.Retry/RetryOrchestrator.ArtifactRecovery.cs b/src/Platform/Microsoft.Testing.Extensions.Retry/RetryOrchestrator.ArtifactRecovery.cs index a49c33f500..f8f334b51f 100644 --- a/src/Platform/Microsoft.Testing.Extensions.Retry/RetryOrchestrator.ArtifactRecovery.cs +++ b/src/Platform/Microsoft.Testing.Extensions.Retry/RetryOrchestrator.ArtifactRecovery.cs @@ -46,7 +46,7 @@ private static void CollectRecoveredArtifacts( return; } - if (!RetryArtifactManifest.TrySplitEntry(line, out string? encodedPath, out string? encodedKind)) + if (!RetryArtifactManifest.TrySplitEntry(line, out string? encodedPath, out string? encodedKindOrNullSentinel)) { logger.LogWarning($"Ignoring malformed recovered retry artifact manifest entry in '{manifestPath}'."); continue; @@ -55,7 +55,7 @@ private static void CollectRecoveredArtifacts( try { string path = RetryArtifactManifest.DecodePath(encodedPath); - string? kind = RetryArtifactManifest.DecodeKind(encodedKind); + string? kind = RetryArtifactManifest.DecodeKind(encodedKindOrNullSentinel); if (path.Length > MaxRecoveredArtifactPathChars || kind?.Length > MaxRecoveredArtifactKindChars) { diff --git a/src/Platform/SharedExtensionHelpers/RetryArtifactManifest.cs b/src/Platform/SharedExtensionHelpers/RetryArtifactManifest.cs index 0b40aef116..7a7a123c26 100644 --- a/src/Platform/SharedExtensionHelpers/RetryArtifactManifest.cs +++ b/src/Platform/SharedExtensionHelpers/RetryArtifactManifest.cs @@ -14,31 +14,31 @@ internal static class RetryArtifactManifest public static bool TrySplitEntry( string line, [NotNullWhen(true)] out string? encodedPath, - [NotNullWhen(true)] out string? encodedKind) + [NotNullWhen(true)] out string? encodedKindOrNullSentinel) { int separatorIndex = line.IndexOf('\t'); if (separatorIndex <= 0) { encodedPath = null; - encodedKind = null; + encodedKindOrNullSentinel = null; return false; } encodedPath = line.Substring(0, separatorIndex); - encodedKind = line.Substring(separatorIndex + 1); + encodedKindOrNullSentinel = line.Substring(separatorIndex + 1); return true; } public static string DecodePath(string encodedPath) => Encoding.UTF8.GetString(Convert.FromBase64String(encodedPath)); - public static string? DecodeKind(string encodedKind) - => encodedKind == "-" + public static string? DecodeKind(string encodedKindOrNullSentinel) + => encodedKindOrNullSentinel == "-" ? null - : Encoding.UTF8.GetString(Convert.FromBase64String(encodedKind)); + : Encoding.UTF8.GetString(Convert.FromBase64String(encodedKindOrNullSentinel)); - public static string WriteEntryWithEncodedKind(string path, string encodedKind) - => $"{Convert.ToBase64String(Encoding.UTF8.GetBytes(path))}\t{encodedKind}"; + public static string WriteEntryWithEncodedKind(string path, string encodedKindOrNullSentinel) + => $"{Convert.ToBase64String(Encoding.UTF8.GetBytes(path))}\t{encodedKindOrNullSentinel}"; } #pragma warning restore RS0051 From d19e2916b0e1f9ec846d69cb920bd0ea40795685 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 28 Sep 2026 09:42:56 +0000 Subject: [PATCH 7/8] Add WriteEntry API and migrate report writer to shared manifest helper Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com> --- .../Microsoft.Testing.Extensions.CtrfReport.csproj | 1 + .../Microsoft.Testing.Extensions.HtmlReport.csproj | 1 + .../Microsoft.Testing.Extensions.JUnitReport.csproj | 1 + .../ReportProcessLifetimeHandler.cs | 9 +++------ .../SharedExtensionHelpers/RetryArtifactManifest.cs | 5 +++++ 5 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/Platform/Microsoft.Testing.Extensions.CtrfReport/Microsoft.Testing.Extensions.CtrfReport.csproj b/src/Platform/Microsoft.Testing.Extensions.CtrfReport/Microsoft.Testing.Extensions.CtrfReport.csproj index 2170ff8714..a57c7e0410 100644 --- a/src/Platform/Microsoft.Testing.Extensions.CtrfReport/Microsoft.Testing.Extensions.CtrfReport.csproj +++ b/src/Platform/Microsoft.Testing.Extensions.CtrfReport/Microsoft.Testing.Extensions.CtrfReport.csproj @@ -65,6 +65,7 @@ $(CommonProductDescription)]]> + diff --git a/src/Platform/Microsoft.Testing.Extensions.HtmlReport/Microsoft.Testing.Extensions.HtmlReport.csproj b/src/Platform/Microsoft.Testing.Extensions.HtmlReport/Microsoft.Testing.Extensions.HtmlReport.csproj index 743621f5e9..b72388b60f 100644 --- a/src/Platform/Microsoft.Testing.Extensions.HtmlReport/Microsoft.Testing.Extensions.HtmlReport.csproj +++ b/src/Platform/Microsoft.Testing.Extensions.HtmlReport/Microsoft.Testing.Extensions.HtmlReport.csproj @@ -67,6 +67,7 @@ $(CommonProductDescription)]]> + diff --git a/src/Platform/Microsoft.Testing.Extensions.JUnitReport/Microsoft.Testing.Extensions.JUnitReport.csproj b/src/Platform/Microsoft.Testing.Extensions.JUnitReport/Microsoft.Testing.Extensions.JUnitReport.csproj index 83cd707b4e..b63bfeea80 100644 --- a/src/Platform/Microsoft.Testing.Extensions.JUnitReport/Microsoft.Testing.Extensions.JUnitReport.csproj +++ b/src/Platform/Microsoft.Testing.Extensions.JUnitReport/Microsoft.Testing.Extensions.JUnitReport.csproj @@ -65,6 +65,7 @@ $(CommonProductDescription)]]> + diff --git a/src/Platform/SharedExtensionHelpers/ReportProcessLifetimeHandler.cs b/src/Platform/SharedExtensionHelpers/ReportProcessLifetimeHandler.cs index dbc02d2e00..c39693eb84 100644 --- a/src/Platform/SharedExtensionHelpers/ReportProcessLifetimeHandler.cs +++ b/src/Platform/SharedExtensionHelpers/ReportProcessLifetimeHandler.cs @@ -183,10 +183,7 @@ private async Task WriteRetryArtifactManifestAsync( _fileSystem.CreateDirectory(directory); } - string encodedPath = Convert.ToBase64String(Encoding.UTF8.GetBytes(artifactPath)); - string encodedKind = artifactKind is null - ? "-" - : Convert.ToBase64String(Encoding.UTF8.GetBytes(artifactKind)); + string entry = RetryArtifactManifest.WriteEntry(artifactPath, artifactKind); using IFileStream stream = _fileSystem.NewFileStream( manifestPath, FileMode.Append, @@ -194,10 +191,10 @@ private async Task WriteRetryArtifactManifestAsync( FileShare.Read); using var writer = new StreamWriter(stream.Stream, new UTF8Encoding(encoderShouldEmitUTF8Identifier: false)); #if NETCOREAPP - await writer.WriteLineAsync($"{encodedPath}\t{encodedKind}".AsMemory(), cancellationToken).ConfigureAwait(false); + await writer.WriteLineAsync(entry.AsMemory(), cancellationToken).ConfigureAwait(false); #else cancellationToken.ThrowIfCancellationRequested(); - await writer.WriteLineAsync($"{encodedPath}\t{encodedKind}").ConfigureAwait(false); + await writer.WriteLineAsync(entry).ConfigureAwait(false); #endif } catch (Exception ex) when (ex is not OperationCanceledException) diff --git a/src/Platform/SharedExtensionHelpers/RetryArtifactManifest.cs b/src/Platform/SharedExtensionHelpers/RetryArtifactManifest.cs index 7a7a123c26..98ca45af29 100644 --- a/src/Platform/SharedExtensionHelpers/RetryArtifactManifest.cs +++ b/src/Platform/SharedExtensionHelpers/RetryArtifactManifest.cs @@ -39,6 +39,11 @@ public static string DecodePath(string encodedPath) public static string WriteEntryWithEncodedKind(string path, string encodedKindOrNullSentinel) => $"{Convert.ToBase64String(Encoding.UTF8.GetBytes(path))}\t{encodedKindOrNullSentinel}"; + + public static string WriteEntry(string path, string? kind) + => WriteEntryWithEncodedKind( + path, + kind is null ? "-" : Convert.ToBase64String(Encoding.UTF8.GetBytes(kind))); } #pragma warning restore RS0051 From ea0a25fb2a9a60b00f4452dc850f23fa65c1890b Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 28 Sep 2026 17:21:23 +0000 Subject: [PATCH 8/8] Test retry artifact manifest writers Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com> --- .../RetryTests.cs | 81 ++++++++++++++++++- 1 file changed, 80 insertions(+), 1 deletion(-) diff --git a/test/UnitTests/Microsoft.Testing.Extensions.UnitTests/RetryTests.cs b/test/UnitTests/Microsoft.Testing.Extensions.UnitTests/RetryTests.cs index a6c165c43c..c0d57ae030 100644 --- a/test/UnitTests/Microsoft.Testing.Extensions.UnitTests/RetryTests.cs +++ b/test/UnitTests/Microsoft.Testing.Extensions.UnitTests/RetryTests.cs @@ -392,6 +392,50 @@ public void CollectRecoveredArtifacts_NullKind_AddsRecoveredArtifact() fileSystem.Verify(fs => fs.DeleteFile(manifestPath), Times.Once); } + [TestMethod] + public void RetryArtifactManifest_WriteEntry_RoundTripsNonNullKind() + { + const string path = "report\t✓.xml"; + const string kind = "microsoft.testing\tjunit✓"; + + string entry = InvokeWriteManifestEntry(path, kind); + + Assert.HasCount(2, entry.Split('\t')); + (string encodedPath, string encodedKindOrNullSentinel) = SplitManifestEntry(entry); + Assert.AreEqual(path, DecodeManifestPath(encodedPath)); + Assert.AreEqual(kind, DecodeManifestKind(encodedKindOrNullSentinel)); + } + + [TestMethod] + public void RetryArtifactManifest_WriteEntry_RoundTripsNullKind() + { + const string path = "report.xml"; + + string entry = InvokeWriteManifestEntry(path, kind: null); + + Assert.HasCount(2, entry.Split('\t')); + (string encodedPath, string encodedKindOrNullSentinel) = SplitManifestEntry(entry); + Assert.AreEqual(path, DecodeManifestPath(encodedPath)); + Assert.AreEqual("-", encodedKindOrNullSentinel); + Assert.IsNull(DecodeManifestKind(encodedKindOrNullSentinel)); + } + + [TestMethod] + public void RetryArtifactManifest_WriteEntryWithEncodedKind_RoundTripsEncodedKind() + { + const string path = "report.xml"; + const string kind = "microsoft.testing.junit"; + string encodedKind = Convert.ToBase64String(Encoding.UTF8.GetBytes(kind)); + + string entry = InvokeWriteManifestEntryWithEncodedKind(path, encodedKind); + + Assert.HasCount(2, entry.Split('\t')); + (string encodedPath, string encodedKindOrNullSentinel) = SplitManifestEntry(entry); + Assert.AreEqual(encodedKind, encodedKindOrNullSentinel); + Assert.AreEqual(path, DecodeManifestPath(encodedPath)); + Assert.AreEqual(kind, DecodeManifestKind(encodedKindOrNullSentinel)); + } + [TestMethod] public void CollectRecoveredArtifacts_OversizedLine_IsRejectedAndManifestIsDeleted() { @@ -1303,7 +1347,42 @@ private static ServiceProvider CreateServiceProvider(params IArtifactPostProcess } private static string CreateManifestLine(string path, string? kind) - => $"{Convert.ToBase64String(Encoding.UTF8.GetBytes(path))}\t{(kind is null ? "-" : Convert.ToBase64String(Encoding.UTF8.GetBytes(kind)))}"; + => InvokeWriteManifestEntry(path, kind); + + private static string InvokeWriteManifestEntry(string path, string? kind) + => (string)GetRetryArtifactManifestType() + .GetMethod("WriteEntry", BindingFlags.Static | BindingFlags.Public)! + .Invoke(null, [path, kind])!; + + private static string InvokeWriteManifestEntryWithEncodedKind(string path, string encodedKindOrNullSentinel) + => (string)GetRetryArtifactManifestType() + .GetMethod("WriteEntryWithEncodedKind", BindingFlags.Static | BindingFlags.Public)! + .Invoke(null, [path, encodedKindOrNullSentinel])!; + + private static (string EncodedPath, string EncodedKindOrNullSentinel) SplitManifestEntry(string entry) + { + object?[] arguments = [entry, null, null]; + bool wasSplit = (bool)GetRetryArtifactManifestType() + .GetMethod("TrySplitEntry", BindingFlags.Static | BindingFlags.Public)! + .Invoke(null, arguments)!; + + Assert.IsTrue(wasSplit); + return ((string)arguments[1]!, (string)arguments[2]!); + } + + private static string DecodeManifestPath(string encodedPath) + => (string)GetRetryArtifactManifestType() + .GetMethod("DecodePath", BindingFlags.Static | BindingFlags.Public)! + .Invoke(null, [encodedPath])!; + + private static string? DecodeManifestKind(string encodedKindOrNullSentinel) + => (string?)GetRetryArtifactManifestType() + .GetMethod("DecodeKind", BindingFlags.Static | BindingFlags.Public)! + .Invoke(null, [encodedKindOrNullSentinel]); + + private static Type GetRetryArtifactManifestType() + => typeof(RetryOrchestrator).Assembly + .GetType("Microsoft.Testing.Extensions.RetryArtifactManifest")!; private static void InvokeCollectRecoveredArtifacts( IFileSystem fileSystem,