Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Sep 22, 2025

This PR introduces a comprehensive artifact naming service that provides consistent naming and placement for test artifacts across all extensions, with particular focus on the hang dump extension.

Overview

The new IArtifactNamingService allows users to define template-based patterns for artifact naming using placeholders like <process-name>, <pid>, <id>, <os>, <assembly>, <tfm>, <time>, and <root>.

Key Features

Template-Based Naming

Users can now specify patterns like:

<process-name>_<pid>_<id>_hang.dmp

Which resolves to:

MyTests_12345_a1b2c3d4_hang.dmp

Complex Path Templates

Support for structured directory layouts:

<root>/artifacts/<os>/<assembly>/dumps/<process-name>_<pid>_<tfm>_<time>.dmp

Resolves to:

c:/myproject/artifacts/linux/MyTests/dumps/testhost_10001_net9.0_2025-09-22T13:49:34.dmp

Available Placeholders

  • <process-name> - Name of the target process
  • <pid> - Process ID
  • <id> - Short random identifier (8 characters)
  • <os> - Operating system (windows/linux/macos)
  • <assembly> - Assembly name
  • <tfm> - Target framework moniker (net9.0, etc.)
  • <time> - UTC timestamp with 1-second precision
  • <root> - Project root directory (solution/git/working directory)

Backward Compatibility

Legacy patterns continue to work seamlessly through ResolveTemplateWithLegacySupport():

// Existing pattern still works
--hangdump-filename "mydump_%p.dmp"

// New template pattern
--hangdump-filename "<process-name>_<pid>_<id>_hang.dmp"

Implementation Details

Core Components

  • IArtifactNamingService - Service interface with template resolution methods
  • ArtifactNamingService - Implementation with regex-based placeholder replacement
  • Service registration in TestHostBuilder with proper dependency injection
  • Extension method GetArtifactNamingService() for easy access

Hang Dump Integration

The hang dump extension now uses the artifact naming service with:

  • Custom process replacements for the dumped process (not the test runner)
  • Legacy pattern support for %p<pid> mapping
  • Graceful fallback when process information is unavailable

Error Handling

  • Unknown placeholders are preserved in the output for debugging
  • Missing process information defaults to safe values
  • Case-insensitive placeholder matching

Testing

Unit Tests

Comprehensive test coverage in ArtifactNamingServiceTests.cs including:

  • Basic placeholder replacement
  • Custom replacement overrides
  • Legacy pattern compatibility
  • Complex template scenarios
  • Case-insensitive operations

Integration Tests

New test HangDump_TemplateFileName_CreateDump() validates:

  • End-to-end template resolution in real hang dump scenarios
  • Correct file name pattern generation
  • Process ID and random ID validation

Usage Example

# Legacy format (still supported)
dotnet test --hangdump --hangdump-filename "dump_%p.dmp"

# New template format
dotnet test --hangdump --hangdump-filename "<process-name>_<pid>_<id>_hang.dmp"

# Complex path template
dotnet test --hangdump --hangdump-filename "<root>/dumps/<os>/<assembly>/<process-name>_<time>.dmp"

This implementation provides the foundation for consistent artifact naming across all testing platform extensions while maintaining full backward compatibility.

Fixes #6586.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • 37cvsblobprodcus359.vsblob.vsassets.io
    • Triggering command: dotnet build src/Platform/Microsoft.Testing.Platform/Microsoft.Testing.Platform.csproj --no-restore (dns block)
  • 5dkvsblobprodcus355.vsblob.vsassets.io
    • Triggering command: dotnet build src/Platform/Microsoft.Testing.Platform/Microsoft.Testing.Platform.csproj --no-restore (dns block)
  • c50vsblobprodcus330.vsblob.vsassets.io
    • Triggering command: dotnet build src/Platform/Microsoft.Testing.Platform/Microsoft.Testing.Platform.csproj --no-restore (dns block)
  • fdpvsblobprodcus345.vsblob.vsassets.io
    • Triggering command: /home/REDACTED/work/testfx/testfx/.dotnet/dotnet msbuild /m /nologo /clp:Summary /v:minimal /nr:true /warnaserror /p:TreatWarningsAsErrors=true /p:ContinuousIntegrationBuild=false /home/REDACTED/work/testfx/testfx/artifacts/toolset/restore.proj /t:__WriteToolsetLocation /clp:ErrorsOnly;NoSummary /p:__ToolsetLocationOutputFile=/home/REDACTED/work/testfx/testfx/artifacts/toolset/11.0.0-beta.25469.3.txt (dns block)
    • Triggering command: dotnet build src/Platform/Microsoft.Testing.Platform/Microsoft.Testing.Platform.csproj --no-restore (dns block)
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node --enable-source-maps /home/REDACTED/work/_temp/copilot-developer-action-main/dist/index.js (dns block)
  • l49vsblobprodcus358.vsblob.vsassets.io
    • Triggering command: dotnet build src/Platform/Microsoft.Testing.Platform/Microsoft.Testing.Platform.csproj --no-restore (dns block)
  • pkvvsblobprodcus321.vsblob.vsassets.io
    • Triggering command: dotnet build src/Platform/Microsoft.Testing.Platform/Microsoft.Testing.Platform.csproj --no-restore (dns block)
  • yttvsblobprodcus357.vsblob.vsassets.io
    • Triggering command: dotnet build src/Platform/Microsoft.Testing.Platform/Microsoft.Testing.Platform.csproj --no-restore (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 4 commits September 22, 2025 12:09
Co-authored-by: nohwnd <5735905+nohwnd@users.noreply.github.com>
Co-authored-by: nohwnd <5735905+nohwnd@users.noreply.github.com>
…ssing imports

Co-authored-by: nohwnd <5735905+nohwnd@users.noreply.github.com>
Co-authored-by: nohwnd <5735905+nohwnd@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] Add artifact naming service Add artifact naming service with template support for consistent naming across extensions Sep 22, 2025
@Copilot Copilot AI requested a review from nohwnd September 22, 2025 12:22
Copilot finished work on behalf of nohwnd September 22, 2025 12:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add artifact naming service

2 participants