mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
Fix GetExecutorName to handle agent names with underscores
Split on last underscore instead of first, and validate that the suffix is a 32-char hex string (sanitized GUID) before stripping it. This prevents truncation of agent names like 'my_agent' when the executor ID is 'my_agent_<guid>'. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -63,8 +63,38 @@ internal static class WorkflowNamingHelper
|
||||
{
|
||||
ArgumentException.ThrowIfNullOrEmpty(executorId);
|
||||
|
||||
int separatorIndex = executorId.IndexOf(ExecutorIdSuffixSeparator);
|
||||
return separatorIndex > 0 ? executorId[..separatorIndex] : executorId;
|
||||
int separatorIndex = executorId.LastIndexOf(ExecutorIdSuffixSeparator);
|
||||
if (separatorIndex > 0)
|
||||
{
|
||||
ReadOnlySpan<char> suffix = executorId.AsSpan(separatorIndex + 1);
|
||||
if (IsGuidSuffix(suffix))
|
||||
{
|
||||
return executorId[..separatorIndex];
|
||||
}
|
||||
}
|
||||
|
||||
return executorId;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks whether the given span looks like a sanitized GUID (32 hex characters).
|
||||
/// </summary>
|
||||
private static bool IsGuidSuffix(ReadOnlySpan<char> value)
|
||||
{
|
||||
if (value.Length != 32)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach (char c in value)
|
||||
{
|
||||
if (!char.IsAsciiHexDigit(c))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static bool TryGetWorkflowName(string? orchestrationFunctionName, [NotNullWhen(true)] out string? workflowName)
|
||||
|
||||
+16
@@ -64,6 +64,22 @@ public sealed class WorkflowNamingHelperTests
|
||||
Assert.Equal("Physicist", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetExecutorName_NameWithUnderscoresAndGuidSuffix_ReturnsFullName()
|
||||
{
|
||||
string result = WorkflowNamingHelper.GetExecutorName("my_agent_8884e71021334ce49517fa2b17b1695b");
|
||||
|
||||
Assert.Equal("my_agent", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetExecutorName_NameWithUnderscoreButNoGuidSuffix_ReturnsSameName()
|
||||
{
|
||||
string result = WorkflowNamingHelper.GetExecutorName("my_custom_executor");
|
||||
|
||||
Assert.Equal("my_custom_executor", result);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(null)]
|
||||
[InlineData("")]
|
||||
|
||||
Reference in New Issue
Block a user