mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
Merge main into feat/durable_task and resolve conflicts
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,94 @@
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
|
||||
using Microsoft.Extensions.AI;
|
||||
|
||||
namespace Microsoft.Agents.AI.DurableTask.UnitTests;
|
||||
|
||||
/// <summary>
|
||||
/// Unit tests for the <see cref="DurableAgentRunOptions"/> class.
|
||||
/// </summary>
|
||||
public sealed class DurableAgentRunOptionsTests
|
||||
{
|
||||
[Fact]
|
||||
public void CloneReturnsNewInstanceWithSameValues()
|
||||
{
|
||||
// Arrange
|
||||
DurableAgentRunOptions options = new()
|
||||
{
|
||||
EnableToolCalls = false,
|
||||
EnableToolNames = new List<string> { "tool1", "tool2" },
|
||||
IsFireAndForget = true,
|
||||
AllowBackgroundResponses = true,
|
||||
ContinuationToken = ResponseContinuationToken.FromBytes(new byte[] { 1, 2, 3 }),
|
||||
AdditionalProperties = new AdditionalPropertiesDictionary
|
||||
{
|
||||
["key1"] = "value1",
|
||||
["key2"] = 42
|
||||
},
|
||||
ResponseFormat = ChatResponseFormat.Json
|
||||
};
|
||||
|
||||
// Act
|
||||
AgentRunOptions cloneAsBase = options.Clone();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(cloneAsBase);
|
||||
Assert.IsType<DurableAgentRunOptions>(cloneAsBase);
|
||||
DurableAgentRunOptions clone = (DurableAgentRunOptions)cloneAsBase;
|
||||
Assert.NotSame(options, clone);
|
||||
Assert.Equal(options.EnableToolCalls, clone.EnableToolCalls);
|
||||
Assert.NotNull(clone.EnableToolNames);
|
||||
Assert.NotSame(options.EnableToolNames, clone.EnableToolNames);
|
||||
Assert.Equal(2, clone.EnableToolNames.Count);
|
||||
Assert.Contains("tool1", clone.EnableToolNames);
|
||||
Assert.Contains("tool2", clone.EnableToolNames);
|
||||
Assert.Equal(options.IsFireAndForget, clone.IsFireAndForget);
|
||||
Assert.Equal(options.AllowBackgroundResponses, clone.AllowBackgroundResponses);
|
||||
Assert.Same(options.ContinuationToken, clone.ContinuationToken);
|
||||
Assert.NotNull(clone.AdditionalProperties);
|
||||
Assert.NotSame(options.AdditionalProperties, clone.AdditionalProperties);
|
||||
Assert.Equal("value1", clone.AdditionalProperties["key1"]);
|
||||
Assert.Equal(42, clone.AdditionalProperties["key2"]);
|
||||
Assert.Same(options.ResponseFormat, clone.ResponseFormat);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CloneCreatesIndependentEnableToolNamesList()
|
||||
{
|
||||
// Arrange
|
||||
DurableAgentRunOptions options = new()
|
||||
{
|
||||
EnableToolNames = new List<string> { "tool1" }
|
||||
};
|
||||
|
||||
// Act
|
||||
DurableAgentRunOptions clone = (DurableAgentRunOptions)options.Clone();
|
||||
clone.EnableToolNames!.Add("tool2");
|
||||
|
||||
// Assert
|
||||
Assert.Equal(2, clone.EnableToolNames.Count);
|
||||
Assert.Single(options.EnableToolNames);
|
||||
Assert.DoesNotContain("tool2", options.EnableToolNames);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CloneCreatesIndependentAdditionalPropertiesDictionary()
|
||||
{
|
||||
// Arrange
|
||||
DurableAgentRunOptions options = new()
|
||||
{
|
||||
AdditionalProperties = new AdditionalPropertiesDictionary
|
||||
{
|
||||
["key1"] = "value1"
|
||||
}
|
||||
};
|
||||
|
||||
// Act
|
||||
DurableAgentRunOptions clone = (DurableAgentRunOptions)options.Clone();
|
||||
clone.AdditionalProperties!["key2"] = "value2";
|
||||
|
||||
// Assert
|
||||
Assert.True(clone.AdditionalProperties.ContainsKey("key2"));
|
||||
Assert.False(options.AdditionalProperties.ContainsKey("key2"));
|
||||
}
|
||||
}
|
||||
@@ -10,12 +10,12 @@ public sealed class DurableAgentSessionTests
|
||||
public void BuiltInSerialization()
|
||||
{
|
||||
AgentSessionId sessionId = AgentSessionId.WithRandomKey("test-agent");
|
||||
AgentSession session = new DurableAgentSession(sessionId);
|
||||
DurableAgentSession session = new(sessionId);
|
||||
|
||||
JsonElement serializedSession = session.Serialize();
|
||||
|
||||
// Expected format: "{\"sessionId\":\"@dafx-test-agent@<random-key>\"}"
|
||||
string expectedSerializedSession = $"{{\"sessionId\":\"@dafx-{sessionId.Name}@{sessionId.Key}\"}}";
|
||||
string expectedSerializedSession = $"{{\"sessionId\":\"@dafx-{sessionId.Name}@{sessionId.Key}\",\"stateBag\":{{}}}}";
|
||||
Assert.Equal(expectedSerializedSession, serializedSession.ToString());
|
||||
|
||||
DurableAgentSession deserializedSession = DurableAgentSession.Deserialize(serializedSession);
|
||||
@@ -33,11 +33,47 @@ public sealed class DurableAgentSessionTests
|
||||
string serializedSession = JsonSerializer.Serialize(session, typeof(DurableAgentSession));
|
||||
|
||||
// Expected format: "{\"sessionId\":\"@dafx-test-agent@<random-key>\"}"
|
||||
string expectedSerializedSession = $"{{\"sessionId\":\"@dafx-{sessionId.Name}@{sessionId.Key}\"}}";
|
||||
string expectedSerializedSession = $"{{\"sessionId\":\"@dafx-{sessionId.Name}@{sessionId.Key}\",\"stateBag\":{{}}}}";
|
||||
Assert.Equal(expectedSerializedSession, serializedSession);
|
||||
|
||||
DurableAgentSession? deserializedSession = JsonSerializer.Deserialize<DurableAgentSession>(serializedSession);
|
||||
Assert.NotNull(deserializedSession);
|
||||
Assert.Equal(sessionId, deserializedSession.SessionId);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void BuiltInSerialization_RoundTrip_PreservesStateBag()
|
||||
{
|
||||
// Arrange
|
||||
AgentSessionId sessionId = AgentSessionId.WithRandomKey("test-agent");
|
||||
DurableAgentSession session = new(sessionId);
|
||||
session.StateBag.SetValue("durableKey", "durableValue");
|
||||
|
||||
// Act
|
||||
JsonElement serializedSession = session.Serialize();
|
||||
DurableAgentSession deserializedSession = DurableAgentSession.Deserialize(serializedSession);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(sessionId, deserializedSession.SessionId);
|
||||
Assert.True(deserializedSession.StateBag.TryGetValue<string>("durableKey", out var value));
|
||||
Assert.Equal("durableValue", value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void STJSerialization_RoundTrip_PreservesStateBag()
|
||||
{
|
||||
// Arrange
|
||||
AgentSessionId sessionId = AgentSessionId.WithRandomKey("test-agent");
|
||||
DurableAgentSession session = new(sessionId);
|
||||
session.StateBag.SetValue("stjKey", "stjValue");
|
||||
|
||||
// Act
|
||||
string serializedSession = JsonSerializer.Serialize(session, typeof(DurableAgentSession));
|
||||
DurableAgentSession? deserializedSession = JsonSerializer.Deserialize<DurableAgentSession>(serializedSession);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(deserializedSession);
|
||||
Assert.True(deserializedSession.StateBag.TryGetValue<string>("stjKey", out var value));
|
||||
Assert.Equal("stjValue", value);
|
||||
}
|
||||
}
|
||||
|
||||
-1
@@ -3,7 +3,6 @@
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>$(TargetFrameworksCore)</TargetFrameworks>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<UserSecretsId>b7762d10-e29b-4bb1-8b74-b6d69a667dd4</UserSecretsId>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
Reference in New Issue
Block a user