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
25 changes: 21 additions & 4 deletions docs/RFCs/018-Artifact-Post-Processing.md
Original file line number Diff line number Diff line change
Expand Up @@ -376,8 +376,9 @@ foreach (PostProcessingJob job in plan.Jobs)
manifestPath: job.WriteManifest(),
onMergedArtifact: merged =>
{
// Re-enters the normal reporter path; collapse the consumed originals.
output.RemoveArtifacts(job.InputsFor(merged.Kind));
// Re-enters the normal reporter path; collapse only the inputs that
// the dispatcher reports as represented by this output.
output.RemoveArtifacts(job.Inputs.IntersectByPath(merged.InputArtifactPaths));
output.ArtifactAdded(outOfProcess: true, path: merged.Path, /* ... */);
},
onError: err => output.Warning($"Post-processing of {err.ProcessorUid}: {err.Message}"),
Expand All @@ -395,7 +396,16 @@ The relaunched host runs a **platform-owned dispatcher `ITool`** (`internal-merg
3. Reads the manifest and filters out processors that did not opt into its truncation state.
4. Routes inputs to eligible processors **by Kind first, then by file-extension fallback** for untagged inputs. An input is never routed to more than one processor.
5. Calls each matched processor's `ProcessAsync` once with the run context.
6. Reports each merged `ProcessedArtifact` back over the connected `dotnet-test` pipe as a `FileArtifactMessage`, and surfaces per-processor errors, then exits.
6. Reports each merged `ProcessedArtifact` back over the connected `dotnet-test` pipe as a
`FileArtifactMessage`. Its `InputArtifactPaths` field contains the original manifest path strings for
every input supplied to that processor invocation, copied verbatim, and the SDK removes exactly those
job inputs from the summary. The dispatcher surfaces per-processor errors, then exits.

A non-null `ProcessedArtifact` represents every input supplied to that processor invocation. A processor
that cannot produce one artifact representing the complete input set returns `null` or throws. This
all-or-nothing rule makes `InputArtifactPaths` authoritative without changing the processor API. A
processor that advertises both kinds and legacy extensions can receive the union of producer-kind matches
and untagged extension-fallback matches, so it must be able to represent that complete union.

The dispatcher tool is marked **internal** (a flag mirroring command-line `IsHidden`) so it is not listed under "Registered tools:" by `--info`. A user would never type `--tool internal-merge-artifacts --manifest ...`; the non-hidden manual value comes entirely from the per-extension user tools in §7.2, which ship regardless of this decision.

Expand Down Expand Up @@ -435,7 +445,13 @@ Manifest (orchestrator -> dispatcher):

`truncationReason` is an additive schema-1 field because the existing parser ignores unknown fields. An old dispatcher reading a new manifest therefore continues to fail closed at election time: an SDK must elect a host through the new truncated-run capability before it writes this field. A new dispatcher reading an old manifest treats the run as complete.

**Preferred result path: over the pipe.** In the recommended design the dispatcher reports each merged artifact back as a `FileArtifactMessage`, so there is no separate result file and no SDK-side result-JSON parsing. The SDK correlates the incoming merged artifact to the job it dispatched (it knows which inputs it sent) and collapses the originals.
**Preferred result path: over the pipe.** In the recommended design the dispatcher reports each merged
artifact back as a `FileArtifactMessage`, so there is no separate result file and no SDK-side result-JSON
parsing. Each dispatcher output includes the additive `InputArtifactPaths` field (field ID 8), containing
the original manifest path strings copied verbatim. The SDK intersects those strings with the job manifest
and collapses exactly the matching originals. Older readers skip the unknown field; newer readers treat its
absence as an old-host response and use a conservative fallback. No protocol-version bump or handshake
capability is required.

**Transitional result path: result JSON.** If the pipe-composition task in §7.6 is deferred, the dispatcher writes a result JSON (path supplied in the manifest) and the SDK performs the swap. This keeps the same typed contract and the same manifest; only the *return channel* changes. Keeping the manifest/result schema `schemaVersion`-versioned means the return channel can switch from files to the pipe without touching `IArtifactPostProcessor`.

Expand All @@ -456,6 +472,7 @@ Dispatcher exit codes (final values to be finalized so they don't overlap existi
| 5 modules, 5 TRX, all tag `microsoft.testing.trx` | 1 relaunch, 1 merged TRX, 5 originals on disk, 1 summary line. |
| 5 modules, mixed TRX + coverage, one app covers both | 1 relaunch (set-cover), 1 merged TRX + 1 merged coverage. |
| `.xml` artifacts: 3 JUnit (kind `junit.report`) + 2 NUnit3 (kind `nunit.report`) | Two distinct groups, two merges, no cross-contamination (would have collided under pure extension matching). |
| Tagged JUnit and untagged NUnit3 `.xml` artifacts route to different processors in one app | Per-output dispatcher provenance collapses each processor's inputs independently; if the fallback processor returns `null`, those legacy inputs remain listed. |
| Module lacks a processor for `playwright.trace` | Those files listed individually (today's behavior). |
| Older testfx with no `IArtifactPostProcessor` | No advertisements -> no relaunch -> today's behavior end-to-end. |
| New SDK + new platform + producer not tagging Kind yet | Orchestrator falls back to file extension; merge still happens. |
Expand Down
17 changes: 14 additions & 3 deletions docs/mstest-runner-protocol/004-protocol-dotnet-test-pipe.md
Original file line number Diff line number Diff line change
Expand Up @@ -561,9 +561,13 @@ currently running (rendered by non-IDE consumers as a "currently running tests"

Reports produced files (per-test artifacts, session artifacts, and standalone `FileArtifact`s). Each
`FileArtifactMessage`: `FullPath`(1), `DisplayName`(2), `Description`(3), `TestUid`(4),
`TestDisplayName`(5), `SessionUid`(6), `Kind`(7). `Kind` carries the producer-asserted artifact kind
used for post-processor routing. Test-scoped artifacts fill `TestUid`/`TestDisplayName`; session and
standalone artifacts leave them empty.
`TestDisplayName`(5), `SessionUid`(6), `Kind`(7), `InputArtifactPaths`(8, string list). `Kind` carries
the producer-asserted artifact kind used for post-processor routing. `InputArtifactPaths` is present
only on dispatcher-produced artifacts and contains the non-empty set of manifest input paths represented
by that output. The dispatcher preserves each path string exactly as received; consumers intersect it
with the paths from that job's manifest rather than independently normalizing it. Its absence means
provenance is unavailable, including messages from older hosts. Test-scoped artifacts fill
`TestUid`/`TestDisplayName`; session and standalone artifacts leave them empty.

### 9.6 `CommandLineOptionMessages` (ID 3)

Expand Down Expand Up @@ -604,6 +608,13 @@ agent.
| 1.3.0 | Adds `DisplayMessage` (ID 12). Host forwards warning/error host diagnostics (always). |
| 1.4.0 | Adds the reverse **server-control** channel (`WaitForServerControlRequest` ID 13, `ServerControlMessage` ID 14). Version is bumped so negotiated state advances in lockstep, but the feature itself is gated on the `ServerControlPipeName` handshake property, not on the version. **testfx-side / pending SDK support:** the current `dotnet/sdk` advertises only `1.0.0`–`1.3.0` and does not vendor serializers 13/14, so it cannot advertise `ServerControlPipeName` or drive the channel yet. In practice the negotiated version tops out at 1.3.0 until the coordinated SDK change lands (see §12). |

Additive fields on known messages do not require a protocol-version bump:

| MTP package version | Message field |
| --- | --- |
| 2.4.0 | `FileArtifactMessage.Kind` (7) |
| 2.4.0 | `FileArtifactMessage.InputArtifactPaths` (8) |

Compatibility rules / assumptions:

- Forwarding of 1.2.0/1.3.0 messages is **gated on the negotiated version** — the host never sends a
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#nullable enable
const Microsoft.Testing.Platform.Helpers.EnvironmentVariableConstants.TESTINGPLATFORM_DOTNETTEST_ATTEMPTNUMBER = "TESTINGPLATFORM_DOTNETTEST_ATTEMPTNUMBER" -> string!
const Microsoft.Testing.Platform.IPC.FileArtifactMessageFieldsId.InputArtifactPaths = 8 -> ushort
const Microsoft.Testing.Platform.IPC.FileArtifactMessageFieldsId.Kind = 7 -> ushort
const Microsoft.Testing.Platform.Helpers.EnvironmentVariableConstants.TESTINGPLATFORM_PIPE_DIRECTORY = "TESTINGPLATFORM_PIPE_DIRECTORY" -> string!
const Microsoft.Testing.Platform.IPC.NamedPipeServer.MaxUnixDomainSocketPathLengthInBytes = 103 -> int
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#nullable enable
const Microsoft.Testing.Platform.Helpers.EnvironmentVariableConstants.TESTINGPLATFORM_DOTNETTEST_ATTEMPTNUMBER = "TESTINGPLATFORM_DOTNETTEST_ATTEMPTNUMBER" -> string!
const Microsoft.Testing.Platform.IPC.FileArtifactMessageFieldsId.InputArtifactPaths = 8 -> ushort
const Microsoft.Testing.Platform.IPC.FileArtifactMessageFieldsId.Kind = 7 -> ushort
const Microsoft.Testing.Platform.Helpers.EnvironmentVariableConstants.TESTINGPLATFORM_PIPE_DIRECTORY = "TESTINGPLATFORM_PIPE_DIRECTORY" -> string!
const Microsoft.Testing.Platform.IPC.NamedPipeServer.MaxUnixDomainSocketPathLengthInBytes = 103 -> int
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#nullable enable
const Microsoft.Testing.Platform.Helpers.EnvironmentVariableConstants.TESTINGPLATFORM_DOTNETTEST_ATTEMPTNUMBER = "TESTINGPLATFORM_DOTNETTEST_ATTEMPTNUMBER" -> string!
const Microsoft.Testing.Platform.IPC.FileArtifactMessageFieldsId.InputArtifactPaths = 8 -> ushort
const Microsoft.Testing.Platform.IPC.FileArtifactMessageFieldsId.Kind = 7 -> ushort
const Microsoft.Testing.Platform.Helpers.EnvironmentVariableConstants.TESTINGPLATFORM_PIPE_DIRECTORY = "TESTINGPLATFORM_PIPE_DIRECTORY" -> string!
Microsoft.Testing.Platform.Helpers.ArgumentGuard
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Microsoft.Testing.Platform.Helpers.RuntimeFeatureHelper
static Microsoft.Testing.Platform.Helpers.RuntimeFeatureHelper.IsMultiThreaded.get -> bool
const Microsoft.Testing.Platform.Helpers.EnvironmentVariableConstants.TESTINGPLATFORM_DOTNETTEST_ATTEMPTNUMBER = "TESTINGPLATFORM_DOTNETTEST_ATTEMPTNUMBER" -> string!
const Microsoft.Testing.Extensions.TrxReport.Abstractions.TrxReportEngine.TrxArtifactKind = "microsoft.testing.trx" -> string!
const Microsoft.Testing.Platform.IPC.FileArtifactMessageFieldsId.InputArtifactPaths = 8 -> ushort
const Microsoft.Testing.Platform.IPC.FileArtifactMessageFieldsId.Kind = 7 -> ushort
static Microsoft.Testing.Extensions.TrxReport.Abstractions.TrxReportEngine.Merge(System.Collections.Generic.IReadOnlyList<System.Xml.Linq.XDocument!>! inputReports, System.Guid runId, string! runName) -> System.Xml.Linq.XDocument!
static Microsoft.Testing.Extensions.TrxReport.Abstractions.TrxReportEngine.MergeToFileAsync(System.Collections.Generic.IReadOnlyList<string!>! inputPaths, string! outputPath, System.Guid runId, string! runName, System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ .. _processors.Where(processor => !manifest.Context.IsTruncated || processor.Sup
await WarnAboutProcessorConflictsAsync(eligibleProcessors, cancellationToken).ConfigureAwait(false);

List<InputArtifact> unmatchedInputs = [.. manifest.Inputs];
List<ProcessedArtifact> outputs = [];
List<FileArtifactMessage> outputs = [];
bool failed = false;
foreach (IArtifactPostProcessor processor in eligibleProcessors)
{
Expand All @@ -91,7 +91,16 @@ .. _processors.Where(processor => !manifest.Context.IsTruncated || processor.Sup
manifest.Context,
cancellationToken).ConfigureAwait(false) is { } output)
{
outputs.Add(ValidateProcessedArtifact(output, manifest.OutputDirectory, matchingInputs));
ProcessedArtifact validatedOutput = ValidateProcessedArtifact(output, manifest.OutputDirectory, matchingInputs);
outputs.Add(new FileArtifactMessage(
validatedOutput.Path,
validatedOutput.DisplayName,
validatedOutput.Description,
TestUid: null,
TestDisplayName: null,
SessionUid: null,
validatedOutput.Kind,
[.. matchingInputs.Select(input => input.Path)]));
}
}
catch (OperationCanceledException) when (cancellationToken.IsCancellationRequested)
Expand All @@ -109,18 +118,10 @@ await DisplayWarningAsync(

if (outputs.Count > 0)
{
FileArtifactMessage[] messages = [.. outputs.Select(output => new FileArtifactMessage(
output.Path,
output.DisplayName,
output.Description,
TestUid: null,
TestDisplayName: null,
SessionUid: null,
output.Kind))];
await _protocol.SendMessageAsync(new FileArtifactMessages(
_environment.GetEnvironmentVariable(EnvironmentVariableConstants.TESTINGPLATFORM_DOTNETTEST_EXECUTIONID),
_protocol.InstanceId,
messages)).ConfigureAwait(false);
[.. outputs])).ConfigureAwait(false);
}

return failed ? (int)ExitCode.GenericFailure : (int)ExitCode.Success;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,16 @@ public interface IArtifactPostProcessor : IExtension
/// <param name="outputDirectory">The directory under which the processed artifact must be written.</param>
/// <param name="context">The context describing the test run that produced the artifacts.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>The processed artifact, or <see langword="null"/> when no processing is needed.</returns>
/// <returns>
/// The processed artifact representing all <paramref name="inputs"/>, or <see langword="null"/> when no
/// processing is needed.
/// </returns>
/// <remarks>
/// Implementations must be deterministic and idempotent because orchestrators may retry transient failures.
/// A non-<see langword="null"/> result must represent every supplied input. Implementations that cannot produce
/// one artifact representing the complete input set must return <see langword="null"/> or throw.
/// When a processor declares both kinds and legacy file extensions, <paramref name="inputs"/> can contain the
/// union of producer-kind matches and untagged extension-fallback matches.
/// </remarks>
Task<ProcessedArtifact?> ProcessAsync(
IReadOnlyList<InputArtifact> inputs,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,14 @@ Microsoft.Testing.Platform.OutputDevice.ProxyOutputDevice.Dispose() -> void
*REMOVED*Microsoft.Testing.Platform.Tools.IToolsManager.AddTool(System.Func<System.IServiceProvider!, Microsoft.Testing.Platform.Tools.ITool!>! toolFactory) -> void
*REMOVED*Microsoft.Testing.Platform.OutputDevice.Terminal.SimpleTerminal.RenderProgress(Microsoft.Testing.Platform.OutputDevice.Terminal.TestProgressState?[]! progress) -> void
const Microsoft.Testing.Platform.Helpers.EnvironmentVariableConstants.TESTINGPLATFORM_DOTNETTEST_ATTEMPTNUMBER = "TESTINGPLATFORM_DOTNETTEST_ATTEMPTNUMBER" -> string!
const Microsoft.Testing.Platform.IPC.FileArtifactMessageFieldsId.InputArtifactPaths = 8 -> ushort
const Microsoft.Testing.Platform.IPC.FileArtifactMessageFieldsId.Kind = 7 -> ushort
static Microsoft.Testing.Platform.IPC.DotnetTestDataConsumer.CreateFileArtifactMessages(string? executionId, Microsoft.Testing.Platform.Extensions.Messages.FileArtifact! fileArtifact) -> Microsoft.Testing.Platform.IPC.Models.FileArtifactMessages!
static Microsoft.Testing.Platform.IPC.DotnetTestDataConsumer.CreateFileArtifactMessages(string? executionId, Microsoft.Testing.Platform.Extensions.Messages.SessionFileArtifact! sessionFileArtifact) -> Microsoft.Testing.Platform.IPC.Models.FileArtifactMessages!
Microsoft.Testing.Platform.IPC.Models.FileArtifactMessage.Deconstruct(out string? FullPath, out string? DisplayName, out string? Description, out string? TestUid, out string? TestDisplayName, out string? SessionUid, out string? Kind) -> void
Microsoft.Testing.Platform.IPC.Models.FileArtifactMessage.FileArtifactMessage(string? FullPath, string? DisplayName, string? Description, string? TestUid, string? TestDisplayName, string? SessionUid, string? Kind) -> void
Microsoft.Testing.Platform.IPC.Models.FileArtifactMessage.Deconstruct(out string? FullPath, out string? DisplayName, out string? Description, out string? TestUid, out string? TestDisplayName, out string? SessionUid, out string? Kind, out string![]? InputArtifactPaths) -> void
Microsoft.Testing.Platform.IPC.Models.FileArtifactMessage.FileArtifactMessage(string? FullPath, string? DisplayName, string? Description, string? TestUid, string? TestDisplayName, string? SessionUid, string? Kind, string![]? InputArtifactPaths = null) -> void
Microsoft.Testing.Platform.IPC.Models.FileArtifactMessage.InputArtifactPaths.get -> string![]?
Microsoft.Testing.Platform.IPC.Models.FileArtifactMessage.InputArtifactPaths.init -> void
Microsoft.Testing.Platform.IPC.Models.FileArtifactMessage.Kind.get -> string?
Microsoft.Testing.Platform.IPC.Models.FileArtifactMessage.Kind.init -> void
*REMOVED*Microsoft.Testing.Platform.IPC.Models.FileArtifactMessage.Deconstruct(out string? FullPath, out string? DisplayName, out string? Description, out string? TestUid, out string? TestDisplayName, out string? SessionUid) -> void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@

namespace Microsoft.Testing.Platform.IPC.Models;

internal sealed record FileArtifactMessage(string? FullPath, string? DisplayName, string? Description, string? TestUid, string? TestDisplayName, string? SessionUid, string? Kind);
internal sealed record FileArtifactMessage(
string? FullPath,
string? DisplayName,
string? Description,
string? TestUid,
string? TestDisplayName,
string? SessionUid,
string? Kind,
string[]? InputArtifactPaths = null);

internal sealed record FileArtifactMessages(string? ExecutionId, string? InstanceId, FileArtifactMessage[] FileArtifacts) : IRequest;
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ internal static class FileArtifactMessageFieldsId
public const ushort TestDisplayName = 5;
public const ushort SessionUid = 6;
public const ushort Kind = 7;
public const ushort InputArtifactPaths = 8;
Comment thread
Evangelink marked this conversation as resolved.
Resolved
}

[Embedded]
Expand Down
Loading