-
Notifications
You must be signed in to change notification settings - Fork 293
Add artifact naming service with template support for consistent naming across extensions #6587
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
Changes from 9 commits
d51897b
eb60a65
32a3424
3f373e1
4d2d2f3
ca27413
3ee129e
042d74d
63a96be
9afa902
1de7408
f934d44
8e9c2a7
ef9e0ea
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| # Artifact Naming Service | ||
|
|
||
| The artifact naming service provides a standardized way to generate consistent names and paths for test artifacts across all extensions. | ||
|
|
||
| ## Features | ||
|
|
||
| ### Template-Based Naming | ||
|
Check failure on line 7 in docs/ArtifactNamingService.md
|
||
| Use placeholders in angle brackets to create dynamic file names: | ||
|
|
||
| ``` | ||
|
Check failure on line 10 in docs/ArtifactNamingService.md
|
||
|
Evangelink marked this conversation as resolved.
Outdated
|
||
| <pname>_<pid>_<id>_hang.dmp | ||
| ``` | ||
|
Check failure on line 12 in docs/ArtifactNamingService.md
|
||
|
Evangelink marked this conversation as resolved.
|
||
| Resolves to: `MyTests_12345_a1b2c3d4_hang.dmp` | ||
|
|
||
| ### Complex Path Templates | ||
|
Check failure on line 15 in docs/ArtifactNamingService.md
|
||
|
Evangelink marked this conversation as resolved.
|
||
| Create structured directory layouts: | ||
|
|
||
| ``` | ||
|
Check failure on line 18 in docs/ArtifactNamingService.md
|
||
| <root>/artifacts/<os>/<asm>/dumps/<pname>_<pid>_<tfm>_<time>.dmp | ||
| ``` | ||
|
Check failure on line 20 in docs/ArtifactNamingService.md
|
||
|
Evangelink marked this conversation as resolved.
|
||
| Resolves to: `c:/myproject/artifacts/linux/MyTests/dumps/my-child-process_10001_net9.0_2025-09-22T13:49:34.dmp` | ||
|
|
||
| ### Available Placeholders | ||
|
|
||
| | Placeholder | Description | Example | | ||
| |-------------|-------------|---------| | ||
| | `<pname>` | Name of the process | `MyTests` | | ||
| | `<pid>` | Process ID | `12345` | | ||
| | `<id>` | Short random identifier (8 chars) | `a1b2c3d4` | | ||
| | `<os>` | Operating system | `windows`, `linux`, `macos` | | ||
| | `<asm>` | Assembly name | `MyTests` | | ||
| | `<tfm>` | Target framework moniker | `net9.0`, `net8.0` | | ||
| | `<time>` | Timestamp (1-second precision) | `2025-09-22T13:49:34` | | ||
| | `<root>` | Project root directory | Found via solution/git/working dir | | ||
|
|
||
| ### Backward Compatibility | ||
|
Check failure on line 36 in docs/ArtifactNamingService.md
|
||
|
Evangelink marked this conversation as resolved.
|
||
| Legacy patterns are still supported: | ||
|
|
||
| ```csharp | ||
| // Old pattern | ||
| "myfile_%p.dmp" | ||
|
|
||
| // Works with legacy support | ||
| service.ResolveTemplateWithLegacySupport("myfile_%p.dmp", | ||
| legacyReplacements: new Dictionary<string, string> { ["%p"] = "12345" }); | ||
| ``` | ||
|
|
||
| ### Custom Replacements | ||
|
Check failure on line 48 in docs/ArtifactNamingService.md
|
||
|
Evangelink marked this conversation as resolved.
|
||
| Override default values for specific scenarios: | ||
|
|
||
| ```csharp | ||
| // When dumping a different process than the test host | ||
| var customReplacements = new Dictionary<string, string> | ||
| { | ||
| ["pname"] = "Notepad", | ||
| ["pid"] = "1111" | ||
| }; | ||
|
|
||
| string result = service.ResolveTemplate("<pname>_<pid>.dmp", customReplacements); | ||
| // Result: "Notepad_1111.dmp" | ||
| ``` | ||
|
|
||
| ## Usage in Extensions | ||
|
|
||
| Extensions can use the service through dependency injection: | ||
|
|
||
| ```csharp | ||
| public class MyExtension | ||
| { | ||
| private readonly IArtifactNamingService _artifactNamingService; | ||
|
|
||
| public MyExtension(IServiceProvider serviceProvider) | ||
| { | ||
| _artifactNamingService = serviceProvider.GetArtifactNamingService(); | ||
| } | ||
|
|
||
| public void CreateArtifact(string template) | ||
| { | ||
| string fileName = _artifactNamingService.ResolveTemplate(template); | ||
| // Use fileName for artifact creation | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ## Hang Dump Integration | ||
|
|
||
| The hang dump extension now uses the artifact naming service and supports both legacy and modern patterns: | ||
|
|
||
| ```bash | ||
| # Legacy pattern (still works) | ||
| --hangdump-filename "mydump_%p.dmp" | ||
|
|
||
| # New template pattern | ||
| --hangdump-filename "<pname>_<pid>_<id>_hang.dmp" | ||
|
|
||
| # Complex path template | ||
| --hangdump-filename "<root>/dumps/<os>/<pname>_<pid>_<time>.dmp" | ||
| ``` | ||
|
|
||
| This provides consistent artifact naming across all extensions while maintaining backward compatibility. | ||
|
Check failure on line 100 in docs/ArtifactNamingService.md
|
||
|
Evangelink marked this conversation as resolved.
Outdated
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -106,6 +106,10 @@ | |
| serviceProvider.TryAddService(systemMonitor); | ||
| SystemMonitorAsyncFactory systemMonitorAsyncFactory = new(); | ||
| serviceProvider.TryAddService(systemMonitorAsyncFactory); | ||
|
|
||
|
Check failure on line 109 in src/Platform/Microsoft.Testing.Platform/Hosts/TestHostBuilder.cs
|
||
|
Evangelink marked this conversation as resolved.
Outdated
|
||
| // Add artifact naming service | ||
| ArtifactNamingService artifactNamingService = new(_testApplicationModuleInfo, systemEnvironment, systemClock, processHandler); | ||
| serviceProvider.TryAddService(artifactNamingService); | ||
|
|
||
| PlatformInformation platformInformation = new(); | ||
| serviceProvider.AddService(platformInformation); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.