-
Notifications
You must be signed in to change notification settings - Fork 350
Centralized Artifact Naming Service #15681
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
nohwnd
wants to merge
4
commits into
microsoft:main
Choose a base branch
from
nohwnd:artifact-naming-service
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+2,025
−14
Draft
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
228a6f1
Add centralized artifact naming service (Phase 1: Core)
nohwnd 14347d9
Add atomic ownership, drop fallback syntax, return ArtifactNameResult
nohwnd 534ded2
Add edge case tests, fix trailing dot sanitization
nohwnd 8caf601
Phase 0: Context propagation - plumb architecture, timestamp to loggers
nohwnd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
433 changes: 433 additions & 0 deletions
433
src/Microsoft.TestPlatform.Common/ArtifactNaming/ArtifactNameProvider.cs
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
src/Microsoft.TestPlatform.ObjectModel/ArtifactNaming/ArtifactNameRequest.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| // 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.Collections.Generic; | ||
|
|
||
| namespace Microsoft.VisualStudio.TestPlatform.ObjectModel.ArtifactNaming; | ||
|
|
||
| /// <summary> | ||
| /// Describes a request to resolve an artifact file name from a template. | ||
| /// </summary> | ||
| public sealed class ArtifactNameRequest | ||
| { | ||
| /// <summary> | ||
| /// Gets or sets the file name template (without directory, without extension). | ||
| /// Uses <c>{TokenName}</c> placeholders for token expansion. | ||
| /// </summary> | ||
| /// <example><c>{AssemblyName}_{Tfm}_{Architecture}</c></example> | ||
| public string FileTemplate { get; set; } = string.Empty; | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the file extension including the leading dot. | ||
| /// </summary> | ||
| /// <example><c>.trx</c>, <c>.xml</c>, <c>.coverage</c></example> | ||
| public string Extension { get; set; } = string.Empty; | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the token values available for template expansion. | ||
| /// </summary> | ||
| public IReadOnlyDictionary<string, string> Context { get; set; } = new Dictionary<string, string>(); | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the collision behavior when the resolved path already exists. | ||
| /// Defaults to <see cref="CollisionBehavior.AppendCounter"/>. | ||
| /// </summary> | ||
| public CollisionBehavior Collision { get; set; } = CollisionBehavior.AppendCounter; | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the optional directory template. When <see langword="null"/>, the value of | ||
| /// <see cref="ArtifactNameTokens.TestResultsDirectory"/> from <see cref="Context"/> is used. | ||
| /// </summary> | ||
| public string? DirectoryTemplate { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets an optional artifact kind tag for diagnostics (e.g., "trx", "coverage", "blame"). | ||
| /// </summary> | ||
| public string? ArtifactKind { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets an optional producer name for diagnostics (e.g., "TrxLogger", "BlameCollector"). | ||
| /// </summary> | ||
| public string? ProducerName { get; set; } | ||
| } |
45 changes: 45 additions & 0 deletions
45
src/Microsoft.TestPlatform.ObjectModel/ArtifactNaming/ArtifactNameResult.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| // 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.VisualStudio.TestPlatform.ObjectModel.ArtifactNaming; | ||
|
|
||
| /// <summary> | ||
| /// Result of resolving an artifact name. Contains the resolved path and metadata | ||
| /// about the resolution process (e.g., whether an existing file was detected). | ||
| /// </summary> | ||
| public sealed class ArtifactNameResult | ||
| { | ||
| /// <summary> | ||
| /// Gets the fully resolved, sanitized file path. | ||
| /// </summary> | ||
| public string FilePath { get; } | ||
|
|
||
| /// <summary> | ||
| /// Gets a value indicating whether the resolved path already existed before resolution. | ||
| /// When <see langword="true"/> with <see cref="CollisionBehavior.Overwrite"/>, the caller | ||
| /// should log a warning before writing. | ||
| /// </summary> | ||
| public bool IsOverwrite { get; } | ||
|
|
||
| /// <summary> | ||
| /// Gets a value indicating whether this process created (and therefore owns) the | ||
| /// output directory. When <see langword="false"/>, the directory was already present | ||
| /// (possibly created by another test host in the same run, or a previous run). | ||
| /// </summary> | ||
| public bool IsDirectoryOwner { get; } | ||
|
|
||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="ArtifactNameResult"/> class. | ||
| /// </summary> | ||
| public ArtifactNameResult(string filePath, bool isOverwrite, bool isDirectoryOwner) | ||
| { | ||
| FilePath = filePath; | ||
| IsOverwrite = isOverwrite; | ||
| IsDirectoryOwner = isDirectoryOwner; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Returns the resolved file path. | ||
| /// </summary> | ||
| public override string ToString() => FilePath; | ||
| } |
52 changes: 52 additions & 0 deletions
52
src/Microsoft.TestPlatform.ObjectModel/ArtifactNaming/ArtifactNameTokens.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| // 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.VisualStudio.TestPlatform.ObjectModel.ArtifactNaming; | ||
|
|
||
| /// <summary> | ||
| /// Well-known token names for artifact name templates. | ||
| /// </summary> | ||
| public static class ArtifactNameTokens | ||
| { | ||
| /// <summary>The test results output directory.</summary> | ||
| public const string TestResultsDirectory = "TestResultsDirectory"; | ||
|
|
||
| /// <summary>The target framework short name (e.g., "net8.0").</summary> | ||
| public const string Tfm = "Tfm"; | ||
|
|
||
| /// <summary>UTC timestamp in sortable ISO 8601 compact format with milliseconds: 20260415T105100.123</summary> | ||
| public const string Timestamp = "Timestamp"; | ||
|
|
||
| /// <summary>UTC date only: 2026-04-15</summary> | ||
| public const string Date = "Date"; | ||
|
|
||
| /// <summary>The machine name.</summary> | ||
| public const string MachineName = "MachineName"; | ||
|
|
||
| /// <summary>The current user name.</summary> | ||
| public const string UserName = "UserName"; | ||
|
|
||
| /// <summary>The current process ID.</summary> | ||
| public const string Pid = "Pid"; | ||
|
|
||
| /// <summary>Short 8-character hex prefix of the test run ID.</summary> | ||
| public const string RunId = "RunId"; | ||
|
|
||
| /// <summary>Full test session GUID.</summary> | ||
| public const string SessionId = "SessionId"; | ||
|
|
||
| /// <summary>The test assembly file name without extension.</summary> | ||
| public const string AssemblyName = "AssemblyName"; | ||
|
|
||
| /// <summary>The runtime architecture (e.g., "x64", "x86", "arm64").</summary> | ||
| public const string Architecture = "Architecture"; | ||
|
|
||
| /// <summary>The build configuration (e.g., "Debug", "Release").</summary> | ||
| public const string Configuration = "Configuration"; | ||
|
|
||
| /// <summary>The project name.</summary> | ||
| public const string ProjectName = "ProjectName"; | ||
|
|
||
| /// <summary>The test host index in parallel execution.</summary> | ||
| public const string HostId = "HostId"; | ||
| } |
77 changes: 77 additions & 0 deletions
77
src/Microsoft.TestPlatform.ObjectModel/ArtifactNaming/ArtifactNamingPresets.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| // 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.Collections.Generic; | ||
|
|
||
| namespace Microsoft.VisualStudio.TestPlatform.ObjectModel.ArtifactNaming; | ||
|
|
||
| /// <summary> | ||
| /// Built-in artifact naming presets that define directory and file template pairs. | ||
| /// </summary> | ||
| public static class ArtifactNamingPresets | ||
| { | ||
| /// <summary>CI preset: flat output folder, deterministic names, overwrite on rerun.</summary> | ||
| public const string CI = "ci"; | ||
|
|
||
| /// <summary>Local preset: per-run timestamped subfolder, deterministic file names.</summary> | ||
| public const string Local = "local"; | ||
|
|
||
| /// <summary>Detailed preset: per-run folder with run ID in file names.</summary> | ||
| public const string Detailed = "detailed"; | ||
|
|
||
| /// <summary>Flat preset: minimal file names, one per assembly.</summary> | ||
| public const string Flat = "flat"; | ||
|
|
||
| /// <summary> | ||
| /// Gets the directory and file templates for a named preset. | ||
| /// </summary> | ||
| /// <param name="presetName">The preset name (case-insensitive).</param> | ||
| /// <param name="directoryTemplate">The directory template for the preset.</param> | ||
| /// <param name="fileTemplate">The file template for the preset.</param> | ||
| /// <param name="collision">The collision behavior for the preset.</param> | ||
| /// <returns><see langword="true"/> if the preset was found; otherwise <see langword="false"/>.</returns> | ||
| public static bool TryGetPreset( | ||
| string presetName, | ||
| out string directoryTemplate, | ||
| out string fileTemplate, | ||
| out CollisionBehavior collision) | ||
| { | ||
| switch (presetName.ToLowerInvariant()) | ||
| { | ||
| case CI: | ||
| directoryTemplate = "{" + ArtifactNameTokens.TestResultsDirectory + "}"; | ||
| fileTemplate = "{" + ArtifactNameTokens.AssemblyName + "}_{" + ArtifactNameTokens.Tfm + "}_{" + ArtifactNameTokens.Architecture + "}"; | ||
| collision = CollisionBehavior.Overwrite; | ||
| return true; | ||
|
|
||
| case Local: | ||
| directoryTemplate = "{" + ArtifactNameTokens.TestResultsDirectory + "}/{" + ArtifactNameTokens.Timestamp + "}"; | ||
| fileTemplate = "{" + ArtifactNameTokens.AssemblyName + "}_{" + ArtifactNameTokens.Tfm + "}_{" + ArtifactNameTokens.Architecture + "}"; | ||
| collision = CollisionBehavior.AppendCounter; | ||
| return true; | ||
|
|
||
| case Detailed: | ||
| directoryTemplate = "{" + ArtifactNameTokens.TestResultsDirectory + "}/{" + ArtifactNameTokens.Timestamp + "}"; | ||
| fileTemplate = "{" + ArtifactNameTokens.AssemblyName + "}_{" + ArtifactNameTokens.Tfm + "}_{" + ArtifactNameTokens.Architecture + "}_{" + ArtifactNameTokens.RunId + "}"; | ||
| collision = CollisionBehavior.AppendCounter; | ||
| return true; | ||
|
|
||
| case Flat: | ||
| directoryTemplate = "{" + ArtifactNameTokens.TestResultsDirectory + "}"; | ||
| fileTemplate = "{" + ArtifactNameTokens.AssemblyName + "}"; | ||
| collision = CollisionBehavior.AppendCounter; | ||
| return true; | ||
|
|
||
| default: | ||
| directoryTemplate = string.Empty; | ||
| fileTemplate = string.Empty; | ||
| collision = CollisionBehavior.AppendCounter; | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Gets all known preset names. | ||
| /// </summary> | ||
| public static IReadOnlyList<string> All { get; } = new[] { CI, Local, Detailed, Flat }; | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TryGetPresetwill throw aNullReferenceExceptionwhenpresetNameisnullbecause it callsToLowerInvariant()unconditionally. Since this is a public API and follows a 'Try*' pattern, it should returnfalsefor null/empty input (and set outputs to safe defaults) rather than throwing.